boa icon indicating copy to clipboard operation
boa copied to clipboard

Make bytecode generation more typesafe

Open nekevss opened this issue 3 years ago • 1 comments

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.

nekevss avatar Jan 24 '23 18:01 nekevss

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.

jedel1043 avatar Jan 24 '23 19:01 jedel1043