> >the op code is stored in network endian order and the interpreter will
> >always build a 16 bit int from the 2 bytes.
>
> Not network. Native. We can put a marker at the beginning of any bytecode 
> stream, and provide an endian-swapper. That way we're always running at 
> platform optimal encoding, and if we get bytecode from a platform with 
> different endianness we can run the utility to swap things for us.

Onther way would to have an 8-bit opcode, with extensions, eg
opcode 0xff imples that the next 16 bits is an extended opcode.
The most common opcodes would be 8-bit. This would also mean the initial
dispatch could be done without any range-checks even, as long as unused
entries in the 8-bit table pointed to an error function:

char *byte_ptr = BYTECODE_START;
while (byte_ptr) {
    byte_ptr = (dispatch_table8[*byte_ptr++])(byte_ptr, ....)
}

with the function at dispatch_table8[255] responsible for reading
the next 2 bytes, forming them into an int, checking the ranges, then
using another dispatch table.

Reply via email to