Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/omc/tests/nocaps/gen.sh # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / omc / tests / nocaps / gen.sh` 112 lines ยท 8381 bytes Raw Blame History 1 #!/bin/sh 2 # gen.sh DIR -- write the gate-nocaps units into DIR, one NAME.om each, with NAME.want holding the 3 # exit status the compiled program must give. Each unit is far past a capacity of omc `f4fa7951`. 4 set -eu 5 D=$1 6 mkdir -p "$D" 7 # texts100k: 100,000 texts (the old name table held 8192 names, texts and globals together). The answer 8 # reads the first and the last: 1 + 3 = 4. 9 awk 'BEGIN { print "text t0 \"a\""; for (i = 1; i < 99999; i++) printf "text t%d \"xy\"\n", i 10 print "text t99999 \"abc\""; print "fn main to int"; print "x = len t0"; print "y = len t99999" 11 print "ret int add x y"; print "end" }' > "$D/texts100k.om" 12 echo 4 > "$D/texts100k.want" 13 # globals100k: 100,000 global pools; the first and the last keep their values apart: 5 + 7 = 12. 14 awk 'BEGIN { for (i = 0; i < 100000; i++) printf "global g%d uint 1\n", i; print "fn main to int" 15 print "put g0 0 uint 5"; print "put g99999 0 uint 7"; print "ret int add get g0 0 get g99999 0"; print "end" }' > "$D/globals100k.om" 16 echo 12 > "$D/globals100k.want" 17 # calls100k: 100,000 calls in one OM-2 function (the old per-function emitted budget was 262144 bytes). 18 # 100000 mod 256 = 160. 19 awk 'BEGIN { print "om2"; print "fn inc x ulong to ulong"; print "ret add x 1"; print "end" 20 print "fn main to int"; print "x = ulong 0"; for (i = 0; i < 100000; i++) print "x = inc x" 21 print "ret int rem x 256"; print "end" }' > "$D/calls100k.om" 22 echo 160 > "$D/calls100k.want" 23 # view6553: the shape that failed at 6553 (omc `f4fa7951` accepts 6552): a call statement passing a text to 24 # an unsized view uchar * parameter, 40 bytes each, in one OM-2 body. 6553 * 5 = 32765; mod 256 = 253. 25 vuse() { awk -v n="$1" 'BEGIN { print "om2"; print "global cnt ulong 1"; print "text t \"hello\"" 26 print "fn vuse a view uchar * to void"; print "put cnt 0 add get cnt 0 len a"; print "ret"; print "end" 27 print "fn main to int"; for (i = 0; i < n; i++) print "vuse t"; print "ret int rem get cnt 0 256"; print "end" }'; } 28 vuse 6552 > "$D/view6552.om" 29 echo 248 > "$D/view6552.want" 30 vuse 6553 > "$D/view6553.om" 31 echo 253 > "$D/view6553.want" 32 # view100k: the same shape 100,000 times. 500000 mod 256 = 32. 33 vuse 100000 > "$D/view100k.om" 34 # vlen100k: 100,000 calls of a view uchar * function inside a value. 500000 mod 256 = 32. 35 awk 'BEGIN { print "om2"; print "text t \"hello\""; print "fn vlen a view uchar * to ulong"; print "ret len a" 36 print "end"; print "fn main to int"; print "s = ulong 0"; for (i = 0; i < 100000; i++) print "s = add s vlen t" 37 print "ret int rem s 256"; print "end" }' > "$D/vlen100k.om" 38 echo 32 > "$D/vlen100k.want" 39 echo 32 > "$D/view100k.want" 40 # traps100k: 100,000 trap sites in one plain (OM-1) function: each signed add can overflow (trap 1). 41 # 100000 mod 256 = 160. 42 awk 'BEGIN { print "fn main to int"; print "x = long 0"; for (i = 0; i < 100000; i++) print "x = add x long 1" 43 print "ret int rem x long 256"; print "end" }' > "$D/traps100k.om" 44 echo 160 > "$D/traps100k.want" 45 # trapmid / traplate: the same 100,000 sites, starting 50,000 / 99,990 below the largest long, so the 46 # signed add overflows at the 50,001st / 99,991st line and the program stops with trap 1 (exit 101): 47 # a branch to a trap stub placed by an island in the middle of the function, and one near its end. 48 for v in mid:`9223372036854725807` late:`9223372036854675817`; do 49 n=${v%%:*}; s=${v#*:} 50 awk -v s=$s 'BEGIN { print "fn main to int"; print "x = long " s; for (i = 0; i < 100000; i++) print "x = add x long 1" 51 print "ret int rem x long 256"; print "end" }' > "$D/trap$n.om" 52 echo 101 > "$D/trap$n.want" 53 done 54 # unroll57k / unrolltrap: 64 x 64 unrolled copies of 14 signed adds, 57,344 trap sites written by unrolled 55 # bodies (islands between their lines). From 5: 57349 mod 256 = 5. From 50,000 below the largest long: 56 # the 50,001st add overflows, trap 1, exit 101. 57 for v in 57k:5:5 trap:`9223372036854725807`:101; do 58 n=${v%%:*}; r=${v#*:}; s=${r%%:*}; w=${r#*:} 59 awk -v s=$s 'BEGIN { print "om2"; print "fn main to int"; print "x = long " s; print "for a ulong 64 unroll"; print "for b ulong 64 unroll" 60 for (i = 0; i < 14; i++) print "x = add x long 1"; print "end"; print "end"; print "ret int rem x long 256"; print "end" }' > "$D/unroll$n.om" 61 echo $w > "$D/unroll$n.want" 62 done 63 # fns50k: 50,000 functions; main calls the first and the last: 0 + 49999, mod 256 = 79. 64 awk 'BEGIN { for (i = 0; i < 50000; i++) printf "fn q%d to ulong\nret %d\nend\n", i, i 65 print "fn main to int"; print "a = q0"; print "b = q49999"; print "ret int rem add a b 256"; print "end" }' > "$D/fns50k.om" 66 echo 79 > "$D/fns50k.want" 67 # nest5000: blocks nested 5000 deep (the old block stack held 512); the innermost returns 9. 68 awk 'BEGIN { print "fn main to int"; print "x = ulong 1"; for (i = 0; i < 5000; i++) print "if eq x 1" 69 print "ret 9"; for (i = 0; i < 5000; i++) print "end"; print "ret 0"; print "end" }' > "$D/nest5000.om" 70 echo 9 > "$D/nest5000.want" 71 # breaks3000: 3000 loops in one function, each left by a break (the old break list held 1024 per 72 # function); every loop body runs once and x counts them: 3000 mod 256 = 184. 73 awk 'BEGIN { print "fn main to int"; print "x = ulong 0"; for (i = 0; i < 3000; i++) { print "while true"; print "x = add x 1"; print "break"; print "end" } 74 print "ret int rem x 256"; print "end" }' > "$D/breaks3000.om" 75 echo 184 > "$D/breaks3000.want" 76 # value30000: a value nested 30000 deep (the old limit was 1024): 30000 conversions of y, which is 7. 77 awk 'BEGIN { print "fn main to int"; print "y = ulong 7"; printf "x = "; for (i = 0; i < 30000; i++) printf "ulong " 78 print "y"; print "ret int rem x 256"; print "end" }' > "$D/value30000.om" 79 echo 7 > "$D/value30000.want" 80 # callnest10000: calls nested 10000 deep in one value: inc applied 10000 times to 0, mod 256 = 16. 81 awk 'BEGIN { print "fn inc a ulong to ulong"; print "ret add a 1"; print "end"; print "fn main to int"; print "y = ulong 0" 82 printf "x = "; for (i = 0; i < 10000; i++) printf "inc "; print "y"; print "ret int rem x 256"; print "end" }' > "$D/callnest10000.om" 83 echo 16 > "$D/callnest10000.want" 84 # longnames20k: 20,000 distinct names of 9..63 bytes (the old long-name table held 4096): 5 + 7 = 12. 85 awk 'BEGIN { for (i = 1; i <= 20000; i++) printf "global long_global_name_%05d uint 1\n", i 86 print "fn main to int"; print "put long_global_name_00001 0 uint 5"; print "put long_global_name_20000 0 uint 7" 87 print "ret int add get long_global_name_00001 0 get long_global_name_20000 0"; print "end" }' > "$D/longnames20k.om" 88 echo 12 > "$D/longnames20k.want" 89 # in64m: a 64 MiB input (the old input buffer held 8 MiB): note lines, then a program giving 42. 90 awk 'BEGIN { p = "note "; for (i = 0; i < 94; i++) p = p "p"; n = int((64 * `1048576` - 47) / 100) 91 for (i = 0; i < n; i++) print p; print "fn main to int"; print "x = int 41"; print "x = add x 1"; print "ret x"; print "end" }' > "$D/in64m.om" 92 echo 42 > "$D/in64m.want" 93 # inline65 / inline1000 / inline22k: 65, 1,000 and 22,000 inline edges and no call. L inline leaves b1..bL, 94 # a root inline a that expands every leaf, and M functions (main and g1..) that each expand the root: each of 95 # them records an edge to the root and to every leaf, and the root's own body one to every leaf, so 96 # (L + 1) * M + L edges (L, M = 5, 10; 12, 76; 48, 448). main returns the root, L (each leaf is 1). 97 # NAME.ie is the edge count the omc-use record must show (inledge=N). NAME.old is the status of the `f4fa7951` 98 # control when it is not error 14: its fixed edge table held 16384, so it compiles 65 and 1,000. NAME.c2 is 99 # the status of the second control, omc `1e628c80`: its inline-cycle check (rscan) read the calls table at 100 # each edge's index, past the calls table's room once the edges outnumbered it: trap 3, exit 103. 101 ie() { awk -v L=$1 -v M=$2 'BEGIN { print "om2"; for (i = 1; i <= L; i++) printf "fn b%d to int inline\nret 1\nend\n", i 102 print "fn a to int inline"; print "x = int 0"; for (i = 1; i <= L; i++) printf "x = add x b%d\n", i; print "ret x"; print "end" 103 for (j = 1; j < M; j++) printf "fn g%d to int\nret a\nend\n", j; print "fn main to int"; print "ret a"; print "end" }'; } 104 for v in 65:5:10 1000:12:76 22k:48:448; do 105 n=${v%%:*}; r=${v#*:}; l=${r%%:*}; m=${r#*:} 106 ie $l $m > "$D/inline$n.om" 107 echo $l > "$D/inline$n.want" 108 echo $(( (l + 1) * m + l )) > "$D/inline$n.ie" 109 echo 103 > "$D/inline$n.c2" 110 done 111 echo 0 > "$D/inline65.old" 112 echo 0 > "$D/inline1000.old"