boa
boa copied to clipboard
Make bytecode generation more typesafe
As mentioned in #2553, we currently use emit functions in the ByteCompiler to generate opcode and their arguments, which could lead to a bug if the emits are incorrectly ordered or removed. We could maybe generate emit functions for every opcode via a macro and/or trait e.g. Opcode::GetFunction::emit to stabilize the emitting of an opcode and it's required arguments.
Could be ideal to have a RawOp with the raw instruction set, then have an Instruction enum as our API to push instructions to the codeblock. This enum would then have a function like emit(&mut CodeBlock) that automatically pushes its RawOp representation and its operands to the code.