vm-ext: phase C — extension-opcode-id SX primitive
Registers extension-opcode-id from sx_vm_extensions.ml module init. Lives downstream of both sx_primitives and sx_vm to avoid a build cycle. Accepts a string or symbol; returns Integer id when the opcode is registered, Nil otherwise. Compilers (lib/compiler.sx) call this to emit extension opcodes by name. Returning Nil rather than failing on unknown names lets a port's optimization opt in per-build — missing extensions degrade to slower correct execution. Tests: 5 new foundation cases — registered lookup, unknown → nil, symbol arg, zero-arg + integer-arg rejection. +5 pass vs Phase B baseline, no regressions across 11 conformance suites.
This commit is contained in:
@@ -87,3 +87,22 @@ let install_dispatch () =
|
||||
Sx_vm.extension_dispatch_ref := dispatch
|
||||
|
||||
let () = install_dispatch ()
|
||||
|
||||
(** Compiler-side opcode lookup: register the [extension-opcode-id]
|
||||
primitive. Compilers ([lib/compiler.sx]) call this to emit
|
||||
extension opcodes by name. Returns [Integer id] when registered,
|
||||
[Nil] otherwise — so missing extensions degrade to a fallback
|
||||
rather than failure. *)
|
||||
let () =
|
||||
Sx_primitives.register "extension-opcode-id" (fun args ->
|
||||
match args with
|
||||
| [Sx_types.String name] ->
|
||||
(match id_of_name name with
|
||||
| Some id -> Sx_types.Integer id
|
||||
| None -> Sx_types.Nil)
|
||||
| [Sx_types.Symbol name] ->
|
||||
(match id_of_name name with
|
||||
| Some id -> Sx_types.Integer id
|
||||
| None -> Sx_types.Nil)
|
||||
| _ -> raise (Sx_types.Eval_error
|
||||
"extension-opcode-id: expected one string or symbol"))
|
||||
|
||||
Reference in New Issue
Block a user