condense9 / hark-lang

A serverless virtual machine
https://guide.condense9.com
Apache License 2.0
108 stars 8 forks source link

Optimise Bind-Pop-PushB bytecode sequences #15

Open rmhsilva opened 4 years ago

rmhsilva commented 4 years ago

In many cases, the following bytecode is generated by the naïve compiler:

....
 |   10 | BIND     x
 |   11 | POP
 |   12 | PUSHB    x
...

The last two instructions cancel each other out, and can be deleted entirely. This is a great simple optimisation to add!

Background reading: https://teal-book.condense9.com/vm/source-to-success-compilation.html#compile

Brief implementation thoughts: