Step 3: IO registry — spec-level defio + io contract dispatch
Promotes defio from native OCaml special form to spec-level CEK evaluator feature. The IO registry is now the contract layer between evaluator and platform. Evaluator additions (spec/evaluator.sx): - *io-registry* mutable dict global (like *library-registry*) - io-register!, io-registered?, io-lookup, io-names accessors - defio-parse-kwargs! recursive keyword parser - sf-defio processes (defio "name" :category :data :params (...) ...) - "defio" dispatch in step-eval-list - step-sf-io: the contract function — validates against registry, then delegates to perform for IO suspension - "io" dispatch in step-eval-list Native OCaml defio handlers removed from: - sx_server.ml (~20 lines) - sx_browser.ml (~20 lines) - run_tests.ml (~18 lines) All replaced with __io-registry alias to spec's *io-registry*. IO accessor functions bound in run_tests.ml env so tests can call io-registered?, io-lookup, io-names. 10 new tests (spec/tests/test-io-registry.sx): - defio populates registry - io-lookup returns spec with name/category/returns/doc - io-registered?/io-names work correctly - kwargs parsing (batchable, cacheable, params) - io contract rejects unregistered ops - io contract passes validation for registered ops 2608/2608 tests passing (+10 new). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -610,24 +610,13 @@ let make_test_env () =
|
||||
island
|
||||
| _ -> Nil)));
|
||||
|
||||
(* defio — IO registry for platform suspension points *)
|
||||
let io_registry = Hashtbl.create 64 in
|
||||
ignore (Sx_types.env_bind env "__io-registry" (Dict io_registry));
|
||||
ignore (Sx_ref.register_special_form (String "defio") (NativeFn ("defio", fun sf_args ->
|
||||
let raw_args = match sf_args with
|
||||
| [List a; Env _] | [ListRef { contents = a }; Env _] -> a
|
||||
| _ -> [] in
|
||||
match raw_args with
|
||||
| String name :: rest ->
|
||||
let entry = Hashtbl.create 8 in
|
||||
let rec parse = function
|
||||
| Keyword k :: v :: rest -> Hashtbl.replace entry k v; parse rest
|
||||
| _ -> () in
|
||||
parse rest;
|
||||
Hashtbl.replace entry "name" (String name);
|
||||
Hashtbl.replace io_registry name (Dict entry);
|
||||
Dict entry
|
||||
| _ -> Nil)));
|
||||
(* IO registry — spec-level defio populates *io-registry* in evaluator.
|
||||
Bind accessor functions + __io-registry alias for backward compat. *)
|
||||
ignore (Sx_types.env_bind env "__io-registry" Sx_ref._io_registry_);
|
||||
bind "io-registered?" (fun args -> match args with [String n] -> Sx_ref.io_registered_p (String n) | _ -> Bool false);
|
||||
bind "io-lookup" (fun args -> match args with [String n] -> Sx_ref.io_lookup (String n) | _ -> Nil);
|
||||
bind "io-names" (fun _args -> Sx_ref.io_names ());
|
||||
bind "io-register!" (fun args -> match args with [String n; spec] -> Sx_ref.io_register_b (String n) spec | _ -> Nil);
|
||||
|
||||
(* --- Primitives for canonical.sx / content tests --- *)
|
||||
bind "contains-char?" (fun args ->
|
||||
|
||||
@@ -2007,26 +2007,9 @@ let http_setup_declarative_stubs env =
|
||||
noop "defaction";
|
||||
noop "defrelation";
|
||||
noop "defstyle";
|
||||
(* IO registry — starts empty, platforms extend via defio.
|
||||
defio is a special form that populates __io-registry with metadata
|
||||
about suspension points (IO ops that require platform resolution). *)
|
||||
let io_registry = Hashtbl.create 64 in
|
||||
ignore (env_bind env "__io-registry" (Dict io_registry));
|
||||
ignore (Sx_ref.register_special_form (String "defio") (NativeFn ("defio", fun sf_args ->
|
||||
let raw_args = match sf_args with
|
||||
| [List a; Env _] | [ListRef { contents = a }; Env _] -> a
|
||||
| _ -> [] in
|
||||
match raw_args with
|
||||
| String name :: rest ->
|
||||
let entry = Hashtbl.create 8 in
|
||||
let rec parse = function
|
||||
| Keyword k :: v :: rest -> Hashtbl.replace entry k v; parse rest
|
||||
| _ -> () in
|
||||
parse rest;
|
||||
Hashtbl.replace entry "name" (String name);
|
||||
Hashtbl.replace io_registry name (Dict entry);
|
||||
Dict entry
|
||||
| _ -> Nil)))
|
||||
(* IO registry — spec-level defio populates *io-registry* in evaluator.
|
||||
Alias as __io-registry for backward compat. *)
|
||||
ignore (env_bind env "__io-registry" Sx_ref._io_registry_)
|
||||
|
||||
let http_setup_platform_constructors env =
|
||||
(* Platform constructor functions expected by evaluator.sx.
|
||||
|
||||
Reference in New Issue
Block a user