Issue here to keep track of.
At some point generating bytecode would be needed.
Example from Rapidus:
https://github.com/maekawatoshiki/rapidus/blob/new-gen/src/bytecode_gen.rs#L474-L558
Spidermonkey:
https://dxr.mozilla.org/mozilla-central/source/js/src/vm/Opcodes.h
V8:
https://github.com/v8/v8/blob/master/src/compiler/opcodes.h
Has any work been done on this?
@IovoslavIovchev Nope not yet
This will require a fundamental change on how the interpreter works, but it would be very useful to cache bytecode in the future, and to implement an optimization pass (or multiple optimization passes). Some overview on how V8 does this can be found here: https://v8.dev/blog/ignition-interpreter
My guess is a new interpreter would be created along side the current one which reads the AST and generates bytecode, there would most likely be a switch for a while ‘—bytecode’
Design doc for ignition
https://docs.google.com/document/d/11T2CRex9hXxoJwbYqVQ32yIPMh0uouUZLdyrtmMoL44/mobilebasic#h.z0c1oogsbnnq
Do we want to come up with a set of instructions that would work for us, that would get the ball rolling
@jasonwilliams are there any ideas for the VM design/any work done? Are we aiming for a register-based VM? I reckon we need to have some idea what the VM is going to be like before we come up with the instruction set.
Are we aiming for a register-based VM?
Yes i would imagine it being similar to the V8 VM with registers and an accumulator
Will attempt to base of Jason’s example here:
https://github.com/jorendorff/boa/commit/266319fbee93ef0e2467a384e237ecd5b0ac9c51#diff-8a4e02ddeeda9cccf194eab4892b1c1cR162-R167
There is an issue here though.
Operations on Values have been promoted to the Value level, so the stack needs to either use Values (which isn’t efficient because it will point to the heap for everything) or each instruction will need to box to a Value do the operation then come back down.
For now we will need to do the former, but in future we may have to refactor Values again, so that they’re not so coupled with the Gc.
Similar to the Executable trait we will need a CodeGen trait that each node implements
https://github.com/boa-dev/boa/pull/461 POC from @IovoslavIovchev
I've:
Realm (so that VM can implement Default)CodeGen for NodeIs this really closed?
Most helpful comment
My guess is a new interpreter would be created along side the current one which reads the AST and generates bytecode, there would most likely be a switch for a while ‘—bytecode’
Design doc for ignition
https://docs.google.com/document/d/11T2CRex9hXxoJwbYqVQ32yIPMh0uouUZLdyrtmMoL44/mobilebasic#h.z0c1oogsbnnq