Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement group manipulation #3

Open
dbarowy opened this issue Aug 2, 2018 · 0 comments
Open

Implement group manipulation #3

dbarowy opened this issue Aug 2, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@dbarowy
Copy link
Contributor

dbarowy commented Aug 2, 2018

Group manipulation wraps code in a function. This is not as complicated as it sounds, but it does entail many steps.
For example, the code:

print("hello world");
print(ellipse(100,100));

will produce two objects on screen: a StringEffect and an EllipseEffect. If the user:

  1. Group-selects both objects, and then
  2. Issues the Group command

the code should be updated to:

fun f1() {
  print("hello world");
  print(ellipse(100,100));
}

How does this work? Here's a first pass on the algorithm:

  1. The dmGroup manipulation function should take an array es of Effect objects to group.
  2. For each Effect e in es
    a. Find parent Node p of e.
    b. Recursively find data dependencies of p; let's call these "effect roots" roots.
    c. Transitively create a sequence rootseq of roots.
    d. Create a funDef f and make rootseq the body.
    e. Remove roots from the original AST.
    f. Substitute f into program.
    g. Append a funApp of f to the end of the program (i.e., create a new seq, put the whole program on the left, and the funApp on the right).
  3. Return the new AST.
  4. eval the new AST.

The output should look exactly the same as the original, but the code will now be function-abstracted.

@dbarowy dbarowy added the enhancement New feature or request label Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant