Skip to content

Optimize VM code complication #2

@nahkd123

Description

@nahkd123

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions