Boa: Generate Bytecode

Created on 17 Oct 2019  Â·  11Comments  Â·  Source: boa-dev/boa

enhancement E-Hard

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

All 11 comments

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

There is currently a POC branch, with the aim to explore the different options we have.

The current implementation is based on the aforementioned example.

https://github.com/boa-dev/boa/pull/461 POC from @IovoslavIovchev
I've:

  1. Moved instructions into their own file
  2. Implemented Default for Realm (so that VM can implement Default)
  3. Looked into accumulators
  4. Implemented CodeGen for Node

Is this really closed?

Was this page helpful?
0 / 5 - 0 ratings