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

Add non-local scoping #138

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open

Add non-local scoping #138

wants to merge 45 commits into from

Conversation

BobVarioa
Copy link
Contributor

@BobVarioa BobVarioa commented Jul 26, 2024

Currently:

Caveats:

  • Breaks delete for variables and builtin vars, which already had limited support
  • Slows down compile time by a bit, mainly because of lifting up names (we have to traverse the ast twice).

Also, this is a somewhat broken implementation, but for good reasons in my opinion. For example, take this:

function test() { 
  let a = 1; 
  return () => a++;
} 
let b = test(); 
b();
test();
b(); // should return 2, returns 1 currently

And well, that's not how that is supposed to work at all, but adding that requires runtime allocation, and binding certain values to functions. I will follow up this PR implementing them both, but I felt that they were somewhat out of scope of this PR.

To do:

  • Fix some Test262 issues (+0.54 🎉)
  • Make sure precompile works
  • Throw reference errors earlier instead of later
  • Lift vars out of nested scopes

compiler/codegen.js Outdated Show resolved Hide resolved
@BobVarioa BobVarioa changed the title [DRAFT] Add scoping logic Add basic scoping logic Jul 28, 2024
@BobVarioa BobVarioa marked this pull request as ready for review July 29, 2024 21:57
@BobVarioa
Copy link
Contributor Author

BobVarioa commented Jul 29, 2024

Still not quite ready to merge, but changes from here will be relatively minor.

@BobVarioa BobVarioa changed the title Add basic scoping logic Add non-local scoping Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested scopes don't seem to capture references [meta] Implement globalThis var and this semantics
2 participants