question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ast is being modified by hoist

See original GitHub issue

Is there a way to avoid ast modification? Because my code runs pretty slow because of multiple acorn.parse, so I created a single ast by running acorn.parse one time and run the same ast multiple times. That’s what I do in JS-Interpreter and is pretty viable as ast is not modified in any way, but keeping all the state in a different object (which I delete or recycle, depending on situations).

I like this interpreter a lot, but I’m having problems implementing it as it always need a new ast, which I create with another acorn.parse, because the ast is modified while running, so here “ast caching” is not viable. This makes this interpreter way way slower than JS-Interpreter (actually sval is way faster when interpreting the JS (about 8 times), but globally is slower if you do a lot of runs with the same code).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Siubaakcommented, Jul 4, 2019

Yes, sval will modify ast when hoisting, but just move the function declarations to the top of the scope. No any other changes on ast except this.

After finish compile_ir branch, I will expose APIs for caching the bytecodes. Then you can just parse the code once, get the bytecodes, and run the bytecodes multiple times, like:

const interpreter = new Sval
const bytecodes = interpreter.compile('...')
interpreter.run(bytecodes) // this will skip parsing
interpreter.run(bytecodes) // this will skip parsing
interpreter.run(bytecodes) // this will skip parsing

interpreter.run('...') // you can still run code as string
0reactions
jifeoncommented, May 4, 2020

That’s amazing! Thank you!

I have one related question: in my project I have a case where I need to evaluate just part of ast and get result of it. run accepts Program (hoist requires it at least) and can provide output only via export. Probably you can give me an advice how can I evaluate part of code and get latest values from the stack?

Currently for MVP I used very hacked solution:

const result = sval.runAST(node).state.shift();

where runAST skips hoist. In near future I will need to rewrite it into more robust solution, so if you can give an advice it would be awesome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ts-jest does not hoist variables beginning with mock #1088
Issue : Jest docs describe that all variables that begin with mock are hoisted to the top of the file, above any jest.mock...
Read more >
Association of Altered Liver Enzymes With Alzheimer Disease ...
This finding is concordant with our observation that increased AST to ALT ratio values and lower levels of ALT showed a consistent significant ......
Read more >
1926.1412 - Inspections.
The inspection must assure that the modifications or additions have been done in accordance with the approval obtained pursuant to § 1926.1434 (Equipment ......
Read more >
AST Test: MedlinePlus Medical Test
An AST blood test is used to diagnose liver disorders. AST is a liver enzyme that's released in the blood when the liver...
Read more >
Writing a TypeScript Custom AST Transformer (Part 3)
Scope Modification/Injection. While the inline mod is very handy, there're cases where you can optimize your code like hoisting variable to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found