Add inline VM opcodes for hot primitives (OP_ADD through OP_DEC)
16 new opcodes (160-175) bypass the CALL_PRIM hashtable lookup for the most frequently called primitives: Arithmetic: OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_INC, OP_DEC, OP_NEG Comparison: OP_EQ, OP_LT, OP_GT, OP_NOT Collection: OP_LEN, OP_FIRST, OP_REST, OP_NTH, OP_CONS The compiler (compiler.sx) recognizes these names at compile time and emits the inline opcode instead of CALL_PRIM. The opcode is self- contained — no constant pool index, no argc byte. Each primitive is a single byte in the bytecode stream. Implementation in all three VMs: - OCaml (sx_vm.ml): direct pattern match, no allocation - SX spec (vm.sx): delegates to existing primitives - JS (transpiled): same as SX spec 66 new tests in spec/tests/vm-inline.sx covering arithmetic, comparison, collection ops, composition, and edge cases. Tests: 1314 JS (full), 1114 OCaml, 32 Playwright Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
// =========================================================================
|
||||
|
||||
var NIL = Object.freeze({ _nil: true, toString: function() { return "nil"; } });
|
||||
var SX_VERSION = "2026-03-24T19:19:01Z";
|
||||
var SX_VERSION = "2026-03-24T20:05:12Z";
|
||||
|
||||
function isNil(x) { return x === NIL || x === null || x === undefined; }
|
||||
function isSxTruthy(x) { return x !== false && !isNil(x); }
|
||||
|
||||
Reference in New Issue
Block a user