mattbierner / atum

Javascript Interpreter in Functional-Style Javascript
MIT License
19 stars 2 forks source link

Only build function environments once. #162

Open mattbierner opened 10 years ago

mattbierner commented 10 years ago

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 commented 10 years ago

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:

Then for each call (in forked env):