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

greatly simplify variable access/storage in transpiler #968

Merged
merged 9 commits into from
Jun 15, 2021

Conversation

openorclose
Copy link
Contributor

@openorclose openorclose commented May 15, 2021

this should fix #538 too

old

first run:

let a = 1;
{
 const b = 1; // not stored
}

transpile->

let a = 1;
{
 const b = 1; // not stored
}
globals.set("a", {getValue = () => a, setValue: v=> a = v});

second run:

a = 2;

transpile->

globals.get("a").setValue(1); // basically need to replace all references to `a` with this

after this refactor

we expose a evaller function that gets replaced each time to close around the values

(evaller is simply eval the first time a program is run)
first run:

let a = 1;
{
 const b = 1; // not stored
}

transpile->

evaller = nextProgram => eval(nextProgram);
let a = 1;
{
 const b = 1; // not stored
}

second run:

a = 2;

transpile->

evaller = nextProgram => eval(nextProgram);
a = 2;

note that on the second run, this program is run in the scope of the previous program using the replaced evaller, so no complicated code is needed to transform top level vars into object accesses.

@coveralls
Copy link

coveralls commented May 15, 2021

Pull Request Test Coverage Report for Build 934160766

  • 41 of 42 (97.62%) changed or added relevant lines in 5 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.07%) to 83.728%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/transpiler/transpiler.ts 29 30 96.67%
Files with Coverage Reduction New Missed Lines %
src/transpiler/transpiler.ts 1 92.13%
src/utils/astCreator.ts 1 84.09%
Totals Coverage Status
Change from base Build 932954521: -0.07%
Covered Lines: 7331
Relevant Lines: 8472

💛 - Coveralls

@martin-henz martin-henz requested a review from thomastanck June 14, 2021 13:27
Copy link
Member

@thomastanck thomastanck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, theory checks out, tests pass, and coverage is good. Did a tiny bit of manual testing as well.

@martin-henz martin-henz merged commit f85225d into master Jun 15, 2021
@RichDom2185 RichDom2185 deleted the simplify_tranpspiler branch March 26, 2024 15:16
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.

Transpiler: Evaluation of toplevel statement sequences
4 participants