interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / evidence / SEED-0 / rung4-worksheet.sh

25 lines · 1408 bytes Raw Blame History
1#!/bin/sh
2# rung4-worksheet.sh -- the arithmetic behind om4's keyword table (seed/rung4/om4.s, label KWTAB).
3# A calculator only: for each keyword, its first 8 characters packed little-endian (first character in
4# the low byte) as two 32-bit halves, then the code om4 gives it, as asm2 lines.
5# Codes: 1..9 types, 33..50 ops, 51..58 the new values, 64.. statements, 77 = not in the subset.
6kw() { # word code
7 lo=0; hi=0; i=0
8 for c in $(printf '%s' "$1" | od -An -tu1); do
9 if [ $i -lt 4 ]; then lo=$((lo + (c << (8*i)))); else hi=$((hi + (c << (8*(i-4))))); fi
10 i=$((i+1))
11 done
12 printf ' .w 0x%08x\n .w 0x%08x\n .w %d\n .w 0\n' $lo $hi "$2"
13}
14set -f
15for t in "bool 1" "uchar 2" "u8 2" "ushort 3" "u16 3" "uint 4" "u32 4" "ulong 5" "u64 5" \
16 "byte 6" "i8 6" "short 7" "i16 7" "int 8" "i32 8" "long 9" "i64 9" \
17 "add 33" "sub 34" "mul 35" "div 36" "rem 37" "and 38" "or 39" "xor 40" "shl 41" "shr 42" \
18 "eq 43" "ne 44" "lt 45" "le 46" "gt 47" "ge 48" "neg 49" "not 50" \
19 "get 51" "len 52" "read 53" "write 54" "true 55" "false 56" "view 57" "edit 58" \
20 "fn 64" "to 65" "end 66" "if 67" "else 68" "while 69" "bound 70" "for 71" "ret 72" "= 73" \
21 "( 74" ") 75" "void 76" "global 78" "text 79" "put 80" "free 81" "exit 82" "note 83" "new 84" \
22 "break 77" "trap 77" "own 77"; do
23 kw $t
24done
25printf ' .w 0\n .w 0\n .w 0\n .w 0\n'