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

Only build function environments once. #162

Open
mattbierner opened this issue Feb 10, 2014 · 1 comment
Open

Only build function environments once. #162

mattbierner opened this issue Feb 10, 2014 · 1 comment

Comments

@mattbierner
Copy link
Owner

Language currently create a new environment for each invocation.

This is not necessary, the function should just construct the environment when it is declared, save this environment, and then push and bind arguments on a copy of this environment when it is called.

createArgumentsBinding called in initFunction should just create placeholder bindings instead of binding the actual values.

@mattbierner
Copy link
Owner Author

Without additional logic, function declarations mess this up because they are inited before running code (unlike vars which just create empty bindings) and capture their unique local environment.

Function declarations in functions cannot capture the source environment of their parent, but need to capture the unique copy of it used for the invocation.

One solution may be the following binding initialization for functions:

  • id
  • args creation (empty bindings)
  • fun decl binding creation (empty bindings)
  • var decl bindings (empty bindings)
  • arguments object (empty binding)

Then for each call (in forked env):

  • Bind args to values
  • Bind function delcs to values
  • Bind arguments object to value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant