interplane.Get Omega
Read in your language

sovereign-intelligence

Front door to Drake Stapleton's sovereign stack.

Brought by drakestapleton

branch main Branches Tags History

sovereign-intelligence / harness / skills / writing-omega / SKILL.md

418 lines · 29663 bytes Raw Blame History Source

name: writing-omega description: Portable guide to writing Omega (.om) programs that the seeded omc compiler accepts and runs correctly: program shape, types, words, traps, compiler errors 1..30, common mistakes with the exact refusal, and tested examples. Use before writing or reviewing any .om program on any machine.


Writing Omega programs

This guide is for any agent or person writing .om on any machine. It needs only a clone of aien-dev/omega-mv and of this repository. Every rule below was observed with a program at the pin in the table; the programs are in examples/ and examples/gate.sh reruns all of them. For compiler internals, register rules, wire formats and the reasons behind each rule, read skills/omega-encoding/SKILL.md.

PinValue
omega-mv commitf4df82394e35893dcf1354dda69a2fe028d94bc1
compiler seed/out/omcsha256 3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
language referencedocs/one_layer/OMEGESE.md at that commit
hostLinux AArch64 only; omc writes a static AArch64 Linux ELF

The language reference is normative. Where this guide and OMEGESE disagree, the compiler at the pin decides; this guide records the known disagreements.

1. Compile and run

git clone rad://z6do9WDBhuSnvopDkgFdFr1yWA62 omega-mv && cd omega-mv
git checkout f4df82394e35893dcf1354dda69a2fe028d94bc1
sha256sum seed/out/omc      # must print the pinned hash
sh seed/omega-from-seed.sh  # optional: rebuild omc from the 408-byte loader
seed/out/omc < prog.om > prog; echo "compile $?"
chmod +x prog && ./prog; echo "exit $?"

2. Program shape

note hello: the smallest complete program
text msg "hello, world\n"
fn main to int
k = write 1 msg 0 len msg
if ne k long len msg
ret 1
end
ret 0
end

(examples/hello.om). The rules it shows:

Every declaration and statement form at the pin (OMEGESE sections 9 to 12 are the full rules):

FormWhereNotes
note ANY TEXTany linea comment line
om2, om2 debug, om2 release, om2 diag, om2 diag debug, om2 diag releasefirst line that is not blank or noteopts the unit into OM-2 (section 9); release erases contract checks, diag adds a machine-readable stderr record
om2 fmtthe first line, at byte 0prints the canonical text of the rest of the input instead of compiling it
text NAME "bytes"top levela read-only uchar array
global NAME T Ntop level, program modezero-filled array, never an argument
const NAME T LITERALtop levelan integer or float value, visible after its line
struct S f1 T1 f2 T2 ... endtop level, before the first fnone line; a field f T N is an array of 1..64
layout NAME SIZE, field F T [COUNT] at OFF little/big lines, endOM-2, top level, before the first fnan external byte layout of SIZE 1..4096 bytes
abstract NAME T [ops W ...], holds NAME dup32OM-2, top level, before the first fnT uint or ulong; W from rotr rotl and or xor
fn NAME p1 T1 ... to R ... endtop levelinline after R in OM-2; export fn marks an OM-2 function-mode entry
parameter p Tfn linea scalar
parameter a view T N / a edit T Nfn linea sized array, read-only or writable
parameter a view T * / a edit T *fn line, OM-2an array of any length
parameter s edit T N freshfn line, OM-2scratch: every element written before it is read
parameter p view S / p edit Sfn linea struct, or an OM-2 layout
parameter o out T Nfn line, OM-2written by the unit; the calling host copies it out after status 0
name = valuefunction bodythe first assignment creates the name
put A i v, put p f vfunction bodystore into an array element or a field
f v1 v2 ...function bodya call to a void function
if C ... else ... endfunction bodyelse is optional; no else if
while C bound N ... endfunction bodyN 1..9223372036854775807 (IR mode 1..1000000)
for i T K ... endfunction bodyunroll after K in OM-2, K 1..64
break, continueinside a loop
ret, ret vfunction bodyret v in a function with a result
exit N, trap Nfunction bodyexit status N; trap N 1..14 exits 100+N
requires C, ensures COM-2, the first lines of a functionresult names the returned value
invariant COM-2, the first line of a loop body

3. Types and values

TypeMeaning
booltrue / false, the result of comparisons
uchar, ushort, uint, ulongunsigned 8, 16, 32, 64 bit (also spelled u8 u16 u32 u64)
byte, short, int, longsigned 8, 16, 32, 64 bit (also spelled i8 i16 i32 i64); byte is signed, and char is not a type (error 3)
f32, f64IEEE binary32, binary64
voidno result (function result only)

4. Words

KindWords
arithmeticadd sub mul div rem neg
bitsand or xor not shl shr (rotr rotl in OM-2)
compare (give bool)eq ne lt le gt ge
floatadd sub mul div neg, fsqrt fabs fmin fmax
arraysnew, get A i, put A i v, len A
structsnew S v1 v2 ..., get p f, put p f v
controlif / else / end, while COND bound N, for i T K, break, continue, ret, exit, trap N
conversionthe type words, bitcast T v
I/Oread fd A off n, write fd A off n, pread / pwrite fd A off n pos, and the 67 host words of section 10

5. Traps: what stops a running program

A trap ends the process with exit status 100 + N. Output already written stays written.

CauseTrapExitExample
signed overflow in add sub mul neg1101examples/trap1_overflow.om
div or rem by zero, and signed minimum divided by -12102trap2_divzero.om
array index or I/O slice out of bounds3103trap3_bounds.om
a loop past its bound4104trap4_loop.om
an integer conversion whose value does not fit5105trap5_conv.om
stack exhausted (8 MiB) by calls or local arrays6106trap6_stack.om
shift or rotate amount outside 0..width-17107trap7_shift.om
a contract check that fails (OM-2)9, 10109, 110contract_requires.om, contract_ensures.om
trap N, N 1..14N100+Ntrap_code.om (trap 14, exit 114)

6. Loops and bounds

7. Arrays, texts, globals, structs

8. Names and limits

9. OM-2 units

A unit whose first line that is not blank or note is exactly om2 is an OM-2 unit. OM-1 code keeps its meaning inside it. OM-2 adds:

Examples: om2_tour.om, om2_views.om, om2_hex_rotr.om, contracts_ok.om.

10. Host I/O

The 67 host words at the pin, with their values (OMEGESE section 10 has each one's exact contract). A and B are uchar arrays, off, n and capacity are ulong, and descriptors, flags, modes and ids are int. A path is the slice A off n; a packed list is a u16 count, then u16-length records. Each word is reserved: using it as a name is error 16 at the pin, while an unreserved name in the same program compiles.

AreaWords
filesfopen A off n flags mode, fclose fd, fsync fd, fdsync fd, syncfs fd, memfd A off n flags, fseek fd offset whence, ftrunc fd length, flock fd op, fstat fd A off n, getdnts fd A off n
pathschmod A off n mode, fchmod fd mode, chown A off n uid gid, faccess A off n mode, truncate A off n length, unlink A off n, makedir A off n mode, rmdir A off n, cwd A off capacity, chdir A off n, fchdir fd, readlnk A off n B off capacity, stat A off n B off capacity, lstat A off n B off capacity, renames A off n flags, link A off n, symlnk A off n, umask mask
processesgetpid, getppid, getuid, geteuid, getgid, getegid, setsid, getpgid pid, getsid pid, setpgid pid pgid, fork, killpid pid signal, waitpid pid A off n options, pipefds A off n flags, dupfd fd target flags, execprog A off n
arguments, environment, randomnessargcnt, argread index A off capacity, envcnt, envread index A off capacity, random A off n flags
timemonons, realns, sleepns interval
socketssocknew domain kind protocol, bind fd A off n, connect fd A off n, listen fd backlog, accept fd flags, sockname fd A off n, sockopt fd level option A off n, recv fd A off n flags, send fd A off n flags, sendmsg fd A off n flags, shutdown fd how, waitio fd events interval, pollfds A off n interval, peercred fd A off capacity

11. Compiler errors

Exit status = error number. The only message is the one stderr line omc: line N: error K, where N is the line being read (0 when no line was read). One refusal per code is in examples/errNN_*.om with its exact stderr line in the matching .expect, except 24, which needs a generated program.

CodeMeaningExampleFix
1omc could not read its inputerr01_input (stdin is a directory)give omc a readable file on stdin
2omc could not write its outputerr02_output (stdout is /dev/full)send stdout to a writable file with space
3unknown name, field or functionerr03_unknown_nameassign the name before use; check the spelling
4the line ends before the statement is completeerr04_line_endsgive every word all of its values
5words left after a complete statementerr05_extra_wordscount each word's values; there is no infix
6malformed numbererr06_bad_numberdecimal digits; hex only in OM-2, lowercase
7type mismatcherr07_type_mismatchconvert with a type word: add int 1 int u
8number out of rangeerr08_out_of_rangea literal that fits its type; a bound 1..9223372036854775807 (IR mode 1..1000000); a trap code 1..14
9a word in a place where it is not allowederr09_disallowedmove it: new only in a function's outermost block, struct before the first fn
10duplicate nameerr10_duplicatechoose a name that is not visible, not a function, not a struct
11a number with nothing to give it a typeerr11_ambiguousx = uint 5
12register pool exhausted (16 per function)err12_registersfewer live names, a helper function, shorter expressions (section 8)
13name too longerr13_long_nameat most 8 characters (function names 63)
14compiler capacity: names, functions, exports, expansionerr14_capacitysplit the function or the unit
15the input ends inside an open blockerr15_missing_endclose every block with end
16syntax: unknown word or misplaced formerr16_syntaxstart each line with a statement word; comments are note lines
17a line after ret, break, continue, trap or exit in the same blockerr17_after_pathdelete the line or move it above
18a function with a result whose end is reachableerr18_missing_retend every path with ret v
19a global as an argument, or one array twice in a callerr19_global_argname the global inside the function; pass distinct arrays
20writing to a text or a viewerr20_readonlyan edit parameter, or a local copy
21a literal index outside the arrayerr21_const_indexan index 0..N-1
22a text escape other than \n \t \\ \"err22_text_escapebuild other bytes with put
23array or pool size limiterr23_sizesmaller arrays (section 8 limits)
24a conditional branch farther than 1 MiB of codegenerated, belowmove long bodies into functions
25unknown target name, an AArch64-only path on another target, or (with omega-mv#1015) an x86efi refusalerr25_targetomit target for AArch64, or name a target the unit fits (target x86linux and target x86efi with fn main compile). omega-mv#1015 (head 19ee7e99, merged as d3d1b1bc, the pin, omc b4f45121…) adds the x86efi backend; its error 25 is a bare unit (no fn main), a Linux host word, or an efi OP literal outside 0..13 (0..14 with omega-mv#1022, open); a non-literal OP is error 16 and efi under target x86linux is error 3. See omega-encoding
26never emitted at the pinnonenone
27OM-2 fresh element read before it is writtenerr27_freshput every element before the get
28OM-2 seal outside the constructorerr28_sealseal only as the whole body of fn NAMEmk ... to NAME
29OM-2 layout field past the size or overlappingerr29_layoutkeep every field inside SIZE and apart
30OM-2 contract clause not allowederr30_contractinteger words on parameters only (and result in ensures); no calls, floats or host words

How the emitted set was established at the pin: in seed/omc/omc.om, fn fail (line 324) writes the stderr line and exits with the code (exit int code, line 356). The only other exits are exit int 0 and exit 0, so every refusal goes through fail. Its callers pass the literals 1..25 and 27..30, or forward a literal 3, 4, 6, 8, 13 or 16 through lenval, nfail and unkfail. No caller passes 26, so that code is never emitted (the registry seed/omc/error-codes.reg lists it as "no emitting site"). Code 25 comes from the target checks (fail 25 in fn emit and six other sites). A trap inside omc itself would exit 100 + N, which is not an error code.

Error 24 needs more than 1 MiB of code inside one loop. This program, with 270000 copies of the line x = add x 1 (4 bytes of code each), was refused with omc: line 270006: error 24, the line of the loop's end; with 140000 copies it compiled:

{ printf 'fn main to int\nx = ulong 0\nc = true\nwhile c bound 1\n'
  yes 'x = add x 1' | head -n 270000
  printf 'c = false\nend\nret int and x 1\nend\n'; } > e24.om
seed/out/omc < e24.om > e24; echo "compile $?"   # compile 24

12. Common mistakes

Each row is a program in examples/ with its observed refusal.

MistakeWrite insteadRefusalExample
y = x + 1y = add x 1error 5mistake_infix.om
f(1, 2)f 1 2error 6mistake_c_call.om
if x > 0if gt x 0error 7mistake_compare_operator.om
'A'uchar 65error 3mistake_char_literal.om
// commentnote commenterror 16mistake_slash_comment.om
x = 1;x = uint 1error 6mistake_semicolon.om
return xret xerror 18 (silent assignment)mistake_return.om
else if celse, then a nested if cerror 5mistake_else_if.om
fn main argc int to intargcnt, argreaderror 9mistake_main_args.om
while c bound 9223372036854775808 (or bound 0)a bound 1..9223372036854775807error 8mistake_bound_range.om
ir unit with while c bound 1000001an IR bound 1..1000000error 8mistake_ir_bound.om
a = new uchar n 0a literal or const lengtherror 16mistake_new_var_len.om
free anothing: no heaperror 9mistake_free.om
len = ...another nameerror 16mistake_reserved_name.om
neg = ... or text neg "a"another name: neg is the negation worderror 16mistake_neg_name.om
a bare call f 1 with a resultv = f 1error 7mistake_value_stmt.om
a 7th parametera struct or an arrayerror 9mistake_seven_params.om
2 view T * plus 3 scalars (7 slots)a sized view, a struct, or fewer scalarserror 9mistake_om2_param_slots.om
emit buf with buf a globalname the global inside the functionerror 19err19_global_arg.om
a view uchar 8 given a 16-element arraythe exact length, or OM-2 view uchar *error 7mistake_param_length.om
trap 15trap 1 .. trap 14error 8mistake_trap_range.om
struct after a fnevery struct before the first fnerror 9mistake_struct_after_fn.om
rotr or hex without om2an om2 first lineerror 3mistake_om1_rotr.om
0X10 or 0xFF0x10, 0xfferror 6mistake_om2_upper_hex.om
int 0xffffffffint -1error 8mistake_om2_int_hex.om
part of a globalpart of a localerror 19mistake_om2_part_global.om
part to a sized parameteran unsized view T * parametererror 7mistake_om2_part_sized.om
s = part a 0 2part only as an argumenterror 9mistake_om2_part_statement.om
if and lt i n eq get a i 0 (C short circuit)an outer if lt i ntrap 3, exit 103mistake_short_circuit.om

13. Known compiler defects at the pin

14. Example index

All in examples/; each NAME.om has NAME.expect (compile status, exit status or stderr line) and, when it prints, NAME.stdout with the exact bytes. Wolfram checks of the arithmetic expectations are in examples/WOLFRAM.md.