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

Optimize VM code complication #2

Open
nahkd123 opened this issue Feb 12, 2023 · 0 comments
Open

Optimize VM code complication #2

nahkd123 opened this issue Feb 12, 2023 · 0 comments

Comments

@nahkd123
Copy link
Contributor

Our VM code compiler can compiles to instructions to save a bit of memory, but further optimizations can be applied to make VM an attractive option for calling eval() repeatedly.

Our VM implementation is based on stack machine, so it should be easy to optimize arithmetic operations for constants. Something like this:

Original code for 12.5 + (23.5 * 18):
  push 12.5
  push 23.5
  push 18
  multiply
  add

Optimized code (first pass):
  push 12.5
  push 423 // push 23.5; push 18; multiply
  add

Optimized code (second pass):
  push 435.5

Optimized code (third pass):
  push 435.5

Because nothing is changed in the code in this pass, no further optimization will be applied.
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

No branches or pull requests

1 participant