Improving Nasal: Difference between revisions

Jump to navigation Jump to search
m
Line 30: Line 30:
</syntaxhighlight>
</syntaxhighlight>


Which basically means that we only need to worry about a single place when it comes to extending opcodes, which also translate into less assembly instructions that are actually run (2 CMP vs. ~12 per insn). Also, the bytecode interpreter routine itself could be simplified that way, too. In addition, it would make sense to augment the list of opcode enums by adding an OP_VERSION field that is incremented once opcodes are added/removed:
Which basically means that we only need to worry about a single place when it comes to extending opcodes (and checking in run() that these invalid opcodes aren't used), which also translates into less assembly instructions that are actually run (2 CMP vs. ~12 per insn). Also, the bytecode interpreter routine itself could be simplified that way, too. In addition, it would make sense to augment the list of opcode enums by adding an OP_VERSION field that is incremented once opcodes are added/removed:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
enum {
enum {
     OP_VERSION = 0x01,
     OP_VERSION = 0x01, // for serialization and versioning (e.g. caching bytecode)
     BEGIN_OPS=0xFF,    // reserve space for 255 opcode changes (should be plenty)
     BEGIN_OPS=0xFF,    // reserve space for 255 opcode changes (should be plenty)
     OP_NOT, OP_MUL, OP_PLUS, OP_MINUS, OP_DIV, OP_NEG, OP_CAT, OP_LT, OP_LTE,
     OP_NOT, OP_MUL, OP_PLUS, OP_MINUS, OP_DIV, OP_NEG, OP_CAT, OP_LT, OP_LTE,

Navigation menu