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 / ONE-LAYER-2 / generations / smoke-dev01-a / prompts / bytes.system.txt

96 lines · 5181 bytes Raw Blame History
1You write a small program for the Omega machine. The task says which function to write: its name,
2its parameter types and its return type. You may add helper functions before it.
3
4Values and rules (the same whatever form you write the program in):
5
6- Types: bool, u8, u16, u32, u64 (unsigned), i8, i16, i32, i64 (signed, two's complement).
7- No implicit conversions: the two operands of an arithmetic, bitwise or comparison operation have
8 the same type (a shift amount may be any integer type). Convert explicitly.
9- Unsigned arithmetic wraps modulo 2^width.
10- Signed +, -, *, negation and << must give a representable result, otherwise the run stops with
11 trap 1 (overflow).
12- Division truncates toward zero; remainder has the sign of the dividend. A divisor of 0 stops the
13 run with trap 2 (division by zero). Signed MIN / -1 is trap 1.
14- An array index out of bounds is trap 3. A loop that runs past its bound is trap 4.
15- A conversion to a type that cannot hold the value is trap 5 (conversion out of range).
16- A shift amount outside 0..width-1 is trap 7.
17- A trap ends the whole run; it is the function's outcome. Only trap where the task asks for one.
18
19Answer with exactly one fenced code block (three backticks) that holds the complete program and
20nothing else. Text outside the block is ignored.
21
22REPRESENTATION: bytes
23
24Write the program as OSC binary IR (spec/one-layer-format.md), spelled as hexadecimal: two hex
25digits per byte (0-9, a-f or A-F); spaces and line breaks between bytes are ignored; nothing else
26is allowed. The bytes are read by a strict decoder: any byte out of place refuses the whole program.
27
28All integers are little-endian, no padding. Use format version 1 (no struct table).
29
30Unit:
31 7 bytes magic 4f 53 43 31 49 52 00
32 1 byte version: 01
33 2 bytes number of functions, 1..32, then each function record
34
35Function record:
36 1 + n name: length n (1..63), then n ASCII bytes [A-Za-z_][A-Za-z0-9_]*, unique in the unit
37 1 number of parameters P (0..6)
38 type return type
39 2 number of registers R (P..480), then R types: registers 0..P-1 are the parameters in
40 order, registers P..R-1 are locals
41 2 number of blocks B (1..512), then per block: 4 bytes index of its first instruction,
42 4 bytes instruction count. Blocks cover the instructions in order without gaps:
43 block 0 starts at 0, each next block starts where the previous ended. Block 0 is the entry.
44 4 number of instructions, then the instructions
45 2 00 00 (empty "requires" text)
46 2 00 00 (empty "ensures" text)
47
48Type: one byte: 0 void (return type only), 1 bool, 2 u8, 3 u16, 4 u32, 5 u64, 6 i8, 7 i16, 8 i32,
499 i64; or an array reference: 0a, then kind (1 own, 2 shared, 3 mut), element type byte (1..9),
502 bytes length (1..64).
51
52Instruction: one opcode byte, then its fields. r = 2-byte register / block / function index;
53ff ff means "none".
54 01 CONST r dst, 8 bytes value (the value as a 64-bit number: unsigned zero-extended, signed
55 sign-extended two's complement, bool 0 or 1)
56 02 MOV r dst, r a dst = a
57 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
58 04 UN 1 sub, r dst, r a sub: 1 neg 2 bitwise-not 3 logical-not (bool)
59 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
60 06 CAST r dst, r a dst = a converted to dst's integer type
61 07 ALLOC r dst, r a dst (own array) = new array, every element = a
62 08 RELEASE r a give back own array a
63 09 LOAD r dst, r a, r b dst = a[b]
64 0a STORE r a, r b, r c a[b] = c (a is own or mut)
65 0b CALL r dst (ff ff for a void callee), r function index (an EARLIER function), 1 nargs,
66 nargs x r arg
67 0c TRAP 1 code (1..14) stop with that trap
68 0d BR r block continue at block
69 0e CBR r a (bool), r then-block, r else-block
70 0f RET r a (ff ff in a void function)
71
72Rules: every block ends with exactly one BR, CBR or RET, and only its last instruction is one
73(a TRAP does not end a block). Types agree (BIN/CMP: a and b the same type; BIN and UN: dst the
74same type as a). Every register is read only after it is written on every path to the read
75(parameters count as written). No recursion: a function calls only functions before it.
76
77Example. Task: function clamp_sub, parameters u32 u32, returns u32: a - b when a >= b, else 0.
78Registers: 0 a (u32), 1 b (u32), 2 bool, 3 u32, 4 u32.
79
80```
814f5343314952000101000963 6c616d705f737562
8202 04 0500 04 04 01 04 04
830300 00000000 02000000 02000000 02000000 04000000 02000000
8406000000
8505 06 0200 0000 0100
860e 0200 0100 0200
8703 02 0300 0000 0100
880f 0300
8901 0400 0000000000000000
900f 0400
910000 0000
92```
93
94(Line by line: magic, version 1, one function, name "clamp_sub"; 2 params, returns u32,
955 registers u32 u32 bool u32 u32; 3 blocks at 0+2, 2+2, 4+2; 6 instructions; CMP ge r2 = r0 >= r1;
96CBR r2 -> block 1 else block 2; BIN sub r3 = r0 - r1; RET r3; CONST r4 = 0; RET r4; empty contracts.)