nx_craft_emit_static_argv_gate.nx source
↩ module page · 44 lines · 3537 B
1// ORIGINAL. Inspects canonical emitter's build arguments without running it.
2import "nx_craft_emit.nx"
3import "nx_gate_verdict.nx"
4func ceg_eq(a: *u8,b: *u8) -> i64 {
5 var i: i64 = 0
6 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 }; i = i+1 }
7 if b[i] != (0 as u8) { return 0 }
8 return 1
9}
10func main() -> i64 {
11 let ctr: *i64 = gv_ctr()
12 gv_head("craft compiler source-owned static reservation argv" as *u8)
13 let argv: *i64 = sys_mmap((CE_COMPILE_ARG_WORDS+1)*8) as *i64
14 let floor: *u8 = sys_mmap(32); let limit: *u8 = sys_mmap(32)
15 if (argv as i64) <= 0 { return 3 }
16 if (floor as i64) <= 0 { return 3 }; if (limit as i64) <= 0 { return 3 }
17 gv_check_eq("null argv rejected before writes" as *u8,ce_compiler_argv(CE_WAT,0 as *u8,0 as *i64,CE_COMPILE_ARG_WORDS,floor,limit),0-1,ctr)
18 gv_check_eq("null floor buffer rejected before writes" as *u8,ce_compiler_argv(CE_WAT,0 as *u8,argv,CE_COMPILE_ARG_WORDS,0 as *u8,limit),0-1,ctr)
19 gv_check_eq("null limit buffer rejected before writes" as *u8,ce_compiler_argv(CE_WAT,0 as *u8,argv,CE_COMPILE_ARG_WORDS,floor,0 as *u8),0-1,ctr)
20 argv[0] = 771; argv[CE_COMPILE_ARG_WORDS] = 889
21 gv_check_eq("undersized argv refuses before publication" as *u8,ce_compiler_argv(CE_WAT,0 as *u8,argv,CE_COMPILE_ARG_WORDS-1,floor,limit),0-1,ctr)
22 gv_check_eq("undersized argv keeps prior first word" as *u8,argv[0],771,ctr)
23 gv_check_eq("plain compiler receives seven arguments including executable" as *u8,ce_compiler_argv(CE_WAT,0 as *u8,argv,CE_COMPILE_ARG_WORDS,floor,limit),7,ctr)
24 gv_check_eq("plain executable stays canonical" as *u8,argv[0],CE_CWAT as i64,ctr)
25 gv_check("plain explicit arena flag" as *u8,ceg_eq(argv[1] as *u8,"--arena-pages" as *u8)==1,ctr)
26 gv_check("plain explicit static limit flag" as *u8,ceg_eq(argv[3] as *u8,"--static-limit-pages" as *u8)==1,ctr)
27 gv_check("current verified source floor emitted as decimal" as *u8,ceg_eq(argv[2] as *u8,"364" as *u8)==1,ctr)
28 gv_check("current one-page reservation ceiling emitted as decimal" as *u8,ceg_eq(argv[4] as *u8,"365" as *u8)==1,ctr)
29 gv_check_eq("plain source path retained" as *u8,argv[5],CE_SRC as i64,ctr)
30 gv_check_eq("plain output path retained" as *u8,argv[6],CE_WAT as i64,ctr)
31 gv_check_eq("plain argv terminated" as *u8,argv[7],0,ctr)
32 let max: *u8 = "730" as *u8
33 gv_check_eq("shared compiler receives ten arguments including executable" as *u8,ce_compiler_argv(CE_WAT_MT,max,argv,CE_COMPILE_ARG_WORDS,floor,limit),10,ctr)
34 gv_check("shared uses identical source arena floor" as *u8,ceg_eq(argv[2] as *u8,"364" as *u8)==1,ctr)
35 gv_check("shared uses identical static ceiling" as *u8,ceg_eq(argv[4] as *u8,"365" as *u8)==1,ctr)
36 gv_check_eq("shared flag follows explicit boundary flags" as *u8,argv[5],CE_SHARED as i64,ctr)
37 gv_check("shared preserves source floor semantics" as *u8,ceg_eq(argv[6] as *u8,"source" as *u8)==1,ctr)
38 gv_check_eq("shared existing capacity argument passed untouched" as *u8,argv[7],max as i64,ctr)
39 gv_check_eq("shared same canonical source" as *u8,argv[8],CE_SRC as i64,ctr)
40 gv_check_eq("shared output path retained" as *u8,argv[9],CE_WAT_MT as i64,ctr)
41 gv_check_eq("shared argv terminated" as *u8,argv[10],0,ctr)
42 gv_check_eq("one-past-argv guard retained" as *u8,argv[CE_COMPILE_ARG_WORDS],889,ctr)
43 return gv_verdict("NX-CRAFT-EMIT-STATIC-ARGV" as *u8,ctr,"no compiler or emitter launched; actual paired compilation and runtime acceptance remain required" as *u8)
44}