code wiki / _hdl_build / nx_clock_marker.nx
nx_clock_marker.nx source
↩ module page · 17 lines · 1089 B
1// nx_clock_marker.nx -- a trivial organ for nx_clock_dispatch_gate. Each RUN reads the counter in /tmp/clk_mark.txt,
2// increments it, and writes it back (proven sys_read_file + sys_openat_wr, no raw O_APPEND). So the number in the
3// file = how many times the clock's dispatcher actually executed this job. license_tier: ORIGINAL expect_exit: 0
4import "nx_syscalls.nx"
5
6func main(argc: i64, argv: *i64) -> i64 {
7 let lp: *i64 = sys_mmap(8) as *i64
8 let d: *u8 = sys_read_file("/tmp/clk_mark.txt" as *u8, lp)
9 var cnt: i64 = 0
10 if (d as i64) != 0 { var i: i64=0; while i<lp[0] { if d[i]>=(48 as u8) { if d[i]<=(57 as u8) { cnt = cnt*10 + (d[i]-(48 as u8)) as i64 } } i=i+1 } }
11 cnt = cnt + 1
12 let buf: *u8 = sys_mmap(24); var o: i64=0; var m: i64=cnt
13 if m==0 { buf[0]=48 as u8; o=1 } else { let t: *u8=sys_mmap(24); var k: i64=0; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} while o<k { buf[o]=t[k-1-o]; o=o+1 } }
14 let fd: i64 = sys_openat_wr("/tmp/clk_mark.txt" as *u8, 0x1a4); if fd>=0 { sys_write(fd, buf, o); sys_close(fd) }
15 sys_exit(0)
16 return 0
17}