-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Format of Function Identifiers
This proposal requires that function identifiers be stack items of length
0to7, inclusive. This range maximizes flexibility while ensuring that VM implementations can rely on a single 64-bit key for function table implementations (including both the identifier's length and value).Integer-based function identifiers are particularly appropriate given the existing design of the VM: specialized, number pushing opcodes occupy 18 codepoints in the instruction set (
OP_1NEGATEandOP_0toOP_16), enabling up to 18 unique function identifiers to be encoded using a single byte. However, function identifiers are not required to be minimally encoded numbers, avoiding numeric decoding overhead and enabling a wider variety of usage patterns – e.g. "namespaces" (like0x00through0xff), the single-byteOP_1NEGATE, and other identifiers which cannot be parsed as minimal VM numbers.Outperforming this proposal's approach (in terms of byte-efficiency per encoded invocation) would require reserving a range of user-definable
OP_INVOKE0toOP_INVOKE16(saving 1 byte per invocation). However, function definitions beyond that range would again require use of a genericOP_INVOKE(or generic multi-byte opcode range to specify through e.g.OP_INVOKE999). As single-byte codepoints are very limited, this proposal considers the two-codepointOP_DEFINE/OP_INVOKEapproach to be most prudent.