Add register-special-form!, collect!, random-int, try-rerender-page
- register-special-form!: guards defhandler/defisland from SX override - collect!/collected/clear-collected!: scope accumulator primitives - random-int: deterministic stub (returns lo) - try-rerender-page: no-op stub for offline tests - defpage now works via forms.sx (needs make-page-def — separate issue) 1702 → 1710 passing tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -430,6 +430,31 @@ let make_test_env () =
|
||||
| [state] -> Sx_ref.cek_run state
|
||||
| _ -> Nil);
|
||||
bind "now-ms" (fun _args -> Number 1000.0);
|
||||
bind "random-int" (fun args -> match args with [Number lo; _] -> Number lo | _ -> Number 0.0);
|
||||
bind "try-rerender-page" (fun _args -> Nil);
|
||||
bind "collect!" (fun args ->
|
||||
match args with
|
||||
| [String name; value] ->
|
||||
let stack = try Hashtbl.find _scope_stacks name with Not_found -> [] in
|
||||
(match stack with
|
||||
| List items :: rest ->
|
||||
if List.mem value items then Nil
|
||||
else (Hashtbl.replace _scope_stacks name (List (items @ [value]) :: rest); Nil)
|
||||
| _ ->
|
||||
Hashtbl.replace _scope_stacks name (List [value] :: stack); Nil)
|
||||
| _ -> Nil);
|
||||
bind "collected" (fun args ->
|
||||
match args with
|
||||
| [String name] ->
|
||||
let stack = try Hashtbl.find _scope_stacks name with Not_found -> [] in
|
||||
(match stack with List items :: _ -> List items | _ -> List [])
|
||||
| _ -> List []);
|
||||
bind "clear-collected!" (fun args ->
|
||||
match args with
|
||||
| [String name] ->
|
||||
let stack = try Hashtbl.find _scope_stacks name with Not_found -> [] in
|
||||
(match stack with _ :: rest -> Hashtbl.replace _scope_stacks name (List [] :: rest) | [] -> ()); Nil
|
||||
| _ -> Nil);
|
||||
bind "regex-find-all" (fun args ->
|
||||
(* Stub: supports simple ~name pattern for component scanning *)
|
||||
match args with
|
||||
@@ -492,6 +517,13 @@ let make_test_env () =
|
||||
(* Declarative type/effect forms — no-ops at runtime *)
|
||||
bind "deftype" (fun _args -> Nil);
|
||||
bind "defeffect" (fun _args -> Nil);
|
||||
bind "register-special-form!" (fun args ->
|
||||
match args with
|
||||
| [String name; fn_val] ->
|
||||
(* Don't let SX modules override OCaml-registered defhandler/defisland *)
|
||||
if name = "defhandler" || name = "defisland" then Nil
|
||||
else (ignore (Sx_ref.register_special_form (String name) fn_val); Nil)
|
||||
| _ -> Nil);
|
||||
|
||||
(* defhandler — register handler as handler:name in eval env.
|
||||
Mirrors sx_server.ml's defhandler special form. *)
|
||||
|
||||
Reference in New Issue
Block a user