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 / tools / exp445 / arms / bytes.md

75 lines · 3872 bytes Raw Blame History Rendered
1REPRESENTATION: bytes
2
3Write the program as OSC binary IR (spec/one-layer-format.md), spelled as hexadecimal: two hex
4digits per byte (0-9, a-f or A-F); spaces and line breaks between bytes are ignored; nothing else
5is allowed. The bytes are read by a strict decoder: any byte out of place refuses the whole program.
6
7All integers are little-endian, no padding. Use format version 1 (no struct table).
8
9Unit:
10 7 bytes magic 4f 53 43 31 49 52 00
11 1 byte version: 01
12 2 bytes number of functions, 1..32, then each function record
13
14Function record:
15 1 + n name: length n (1..63), then n ASCII bytes [A-Za-z_][A-Za-z0-9_]*, unique in the unit
16 1 number of parameters P (0..6)
17 type return type
18 2 number of registers R (P..480), then R types: registers 0..P-1 are the parameters in
19 order, registers P..R-1 are locals
20 2 number of blocks B (1..512), then per block: 4 bytes index of its first instruction,
21 4 bytes instruction count. Blocks cover the instructions in order without gaps:
22 block 0 starts at 0, each next block starts where the previous ended. Block 0 is the entry.
23 4 number of instructions, then the instructions
24 2 00 00 (empty "requires" text)
25 2 00 00 (empty "ensures" text)
26
27Type: one byte: 0 void (return type only), 1 bool, 2 u8, 3 u16, 4 u32, 5 u64, 6 i8, 7 i16, 8 i32,
289 i64; or an array reference: 0a, then kind (1 own, 2 shared, 3 mut), element type byte (1..9),
292 bytes length (1..64).
30
31Instruction: one opcode byte, then its fields. r = 2-byte register / block / function index;
32ff ff means "none".
33 01 CONST r dst, 8 bytes value (the value as a 64-bit number: unsigned zero-extended, signed
34 sign-extended two's complement, bool 0 or 1)
35 02 MOV r dst, r a dst = a
36 03 BIN 1 sub, r dst, r a, r b sub: 1 add 2 sub 3 mul 4 div 5 rem 6 and 7 or 8 xor 9 shl 10 shr
37 04 UN 1 sub, r dst, r a sub: 1 neg 2 bitwise-not 3 logical-not (bool)
38 05 CMP 1 sub, r dst, r a, r b sub: 1 eq 2 ne 3 lt 4 le 5 gt 6 ge; dst is bool
39 06 CAST r dst, r a dst = a converted to dst's integer type
40 07 ALLOC r dst, r a dst (own array) = new array, every element = a
41 08 RELEASE r a give back own array a
42 09 LOAD r dst, r a, r b dst = a[b]
43 0a STORE r a, r b, r c a[b] = c (a is own or mut)
44 0b CALL r dst (ff ff for a void callee), r function index (an EARLIER function), 1 nargs,
45 nargs x r arg
46 0c TRAP 1 code (1..14) stop with that trap
47 0d BR r block continue at block
48 0e CBR r a (bool), r then-block, r else-block
49 0f RET r a (ff ff in a void function)
50
51Rules: every block ends with exactly one BR, CBR or RET, and only its last instruction is one
52(a TRAP does not end a block). Types agree (BIN/CMP: a and b the same type; BIN and UN: dst the
53same type as a). Every register is read only after it is written on every path to the read
54(parameters count as written). No recursion: a function calls only functions before it.
55
56Example. Task: function clamp_sub, parameters u32 u32, returns u32: a - b when a >= b, else 0.
57Registers: 0 a (u32), 1 b (u32), 2 bool, 3 u32, 4 u32.
58
59```
604f5343314952000101000963 6c616d705f737562
6102 04 0500 04 04 01 04 04
620300 00000000 02000000 02000000 02000000 04000000 02000000
6306000000
6405 06 0200 0000 0100
650e 0200 0100 0200
6603 02 0300 0000 0100
670f 0300
6801 0400 0000000000000000
690f 0400
700000 0000
71```
72
73(Line by line: magic, version 1, one function, name "clamp_sub"; 2 params, returns u32,
745 registers u32 u32 bool u32 u32; 3 blocks at 0+2, 2+2, 4+2; 6 instructions; CMP ge r2 = r0 >= r1;
75CBR r2 -> block 1 else block 2; BIN sub r3 = r0 - r1; RET r3; CONST r4 = 0; RET r4; empty contracts.)