Skip to content

Commit 5969b7b

Browse files
hyperpolymathclaude
andcommitted
feat(stage6): Cadre Router — linear back-stack as affine resource
Tea_router.ml generates a Wasm 1.0 module encoding IDApTIK's screen back-stack as an affine resource. Push/pop consume the old stack linearly and produce a new one — navigation history as a linear type, making the typed-wasm paper claim real. RouterModel at offset 64 (screen_w, screen_h, stack_len, popup_tag, stack_data[8]). 11 exported functions covering push, pop, popup present/dismiss, resize, and five getters. All RouterMsg payload params annotated Linear in affinescript.ownership custom section. affinescript router-bridge subcommand added (mirrors tea-bridge). 8 new E2E tests: structure, export names, custom sections, Wasm magic, push/present_popup/resize ownership, tea_layout version. 113 total, 0 regressions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c9623b9 commit 5969b7b

4 files changed

Lines changed: 643 additions & 2 deletions

File tree

bin/main.ml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,32 @@ let tea_bridge_cmd_fn output =
354354
Format.printf "Custom sections: affinescript.ownership, affinescript.tea_layout@.";
355355
`Ok ()
356356

357+
(** Generate the Cadre Router Wasm module.
358+
359+
Produces a WebAssembly 1.0 module encoding IDApTIK's screen back-stack as
360+
an affine resource. Push/pop consume the old stack linearly and produce a
361+
new one — navigation history as a linear type.
362+
363+
No source file is needed — the module is generated directly from the router
364+
ABI specification. Write to a .wasm file, copy to IDApTIK's
365+
public/assets/wasm/ directory, and load via AffineTEARouter.load(). *)
366+
let router_bridge_cmd_fn output =
367+
let m = Affinescript.Tea_router.generate () in
368+
Affinescript.Wasm_encode.write_module_to_file output m;
369+
Format.printf "Router bridge written to %s@." output;
370+
Format.printf " affinescript_router_init() — initialise RouterModel@.";
371+
Format.printf " affinescript_router_push(screen_tag: i32) — push screen (Linear param)@.";
372+
Format.printf " affinescript_router_pop() — pop current screen@.";
373+
Format.printf " affinescript_router_present_popup(popup_tag: i32) — show popup (Linear param)@.";
374+
Format.printf " affinescript_router_dismiss_popup() — dismiss popup@.";
375+
Format.printf " affinescript_router_resize(w: i32, h: i32) — update screen dims (Linear)@.";
376+
Format.printf " affinescript_router_get_stack_top() -> i32 — current screen (−1 if empty)@.";
377+
Format.printf " affinescript_router_get_popup_tag() -> i32 — active popup (−1 if none)@.";
378+
Format.printf "Screen tags: 0=Title 1=CharacterSelect 2=WorldMap 3=Load 4=Game@.";
379+
Format.printf "Popup tags: 0=Settings 1=Inventory 2=Hacking@.";
380+
Format.printf "Custom sections: affinescript.ownership, affinescript.tea_layout@.";
381+
`Ok ()
382+
357383
(** Start the REPL *)
358384
let repl_cmd_fn () =
359385
(* TODO: Re-enable when REPL module is restored *)
@@ -652,6 +678,11 @@ let tea_bridge_cmd =
652678
let info = Cmd.info "tea-bridge" ~doc in
653679
Cmd.v info Term.(ret (const tea_bridge_cmd_fn $ output_arg))
654680

681+
let router_bridge_cmd =
682+
let doc = "Generate the AffineScript Cadre Router Wasm module for IDApTIK" in
683+
let info = Cmd.info "router-bridge" ~doc in
684+
Cmd.v info Term.(ret (const router_bridge_cmd_fn $ output_arg))
685+
655686
let repl_cmd =
656687
let doc = "Start the interactive REPL" in
657688
let info = Cmd.info "repl" ~doc in
@@ -862,7 +893,7 @@ let default_cmd =
862893
Cmd.group info ~default [
863894
lex_cmd; parse_cmd; check_cmd; eval_cmd; repl_cmd; compile_cmd;
864895
fmt_cmd; lint_cmd;
865-
tea_bridge_cmd;
896+
tea_bridge_cmd; router_bridge_cmd;
866897
hover_cmd; goto_def_cmd; complete_cmd; server_cmd;
867898
preview_python_cmd; preview_js_cmd; preview_pseudocode_cmd
868899
]

lib/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(name affinescript)
33
(public_name affinescript)
44
(modes byte native)
5-
(modules ast borrow codegen codegen_gc desugar_traits effect error error_collector error_formatter face formatter interp js_face julia_codegen json_output lexer linter lsp_server module_loader opt parse_driver parse parser parser_errors pseudocode_face python_face quantity resolve span symbol tea_bridge token trait typecheck types unify value wasm wasm_encode wasm_gc wasm_gc_encode wasi_runtime)
5+
(modules ast borrow codegen codegen_gc desugar_traits effect error error_collector error_formatter face formatter interp js_face julia_codegen json_output lexer linter lsp_server module_loader opt parse_driver parse parser parser_errors pseudocode_face python_face quantity resolve span symbol tea_bridge tea_router token trait typecheck types unify value wasm wasm_encode wasm_gc wasm_gc_encode wasi_runtime)
66
(libraries str unix sedlex fmt menhirLib yojson)
77
(preprocess
88
(pps ppx_deriving.show ppx_deriving.eq ppx_deriving.ord sedlex.ppx)))

0 commit comments

Comments
 (0)