boa-dev / boa

Boa is an embeddable and experimental Javascript engine written in Rust. Currently, it has support for some of the language.
MIT License
5.13k stars 402 forks source link

Make bytecode generation more typesafe #2561

Open nekevss opened 1 year ago

nekevss commented 1 year ago

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.

jedel1043 commented 1 year ago

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.