omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / src / native.om
| 1 | note native.om: omega-bridge native call ABI v1 binding generator (docs/NATIVE-ABI.md). |
| 2 | note Input on stdin, one or more units: the unit's .om source, a 0 byte, its code length as 8 decimal |
| 3 | note digits, then the function-mode machine code the seeded compiler wrote for that source. |
| 4 | note One argument names the output: c is the library source, one C file that embeds each code |
| 5 | note unchanged and exports uint32_t omega_<name>(uint64_t *result, ...) per unit; h, python, rust, |
| 6 | note zig and go are that library's declarations for those languages, written from the same |
| 7 | note signatures (tools/native runs all six). Output on stdout, only after every unit is accepted. |
| 8 | note The bound function is the unit's last one, which is where the compiler enters function-mode |
| 9 | note code (word 0 branches to it); earlier functions are private helpers with any types. The bound |
| 10 | note function's default parameters are ulong or long scalars, or edit/view arrays of ulong, uchar, f32 or |
| 11 | note ushort; its result is ulong, long or void. An f32 array is 4-byte aligned binary32 and a ushort |
| 12 | note array is 2-byte aligned. Rust and Zig declarations type those two as byte pointers; the C library |
| 13 | note enforces element size and alignment. Python ctypes uses c_float and c_uint16. An array length is |
| 14 | note a decimal number or the name of an earlier "const NAME ulong DIGITS" line of the unit. |
| 15 | note The explicit float/fhost hosted profile also admits f32/f64 scalar parameters and results by raw bit-copy. |
| 16 | note trap 10 (exit 110) and no output. |
| 17 | global inb uchar 16777216 |
| 18 | global outb uchar 16777216 |
| 19 | global outc uchar 16777216 |
| 20 | global st ulong 16 |
| 21 | global md uchar 8 |
| 22 | global tks ulong 40 |
| 23 | global tke ulong 40 |
| 24 | global pk ulong 6 |
| 25 | global pl ulong 6 |
| 26 | global ps ulong 6 |
| 27 | global pe ulong 6 |
| 28 | global dg uchar 24 |
| 29 | global us ulong 1024 |
| 30 | global ue ulong 1024 |
| 31 | text hx "0123456789abcdef" |
| 32 | global xt ulong 1 |
| 33 | text xtname "x86linux" |
| 34 | note Host words (docs/NATIVE-ABI.md, host words): hok is 1 when the generator's second argument is host, |
| 35 | note hm[k] marks a host word used by the current unit. hw follows the omc keyword table; the nine |
| 36 | note file/identity words, three clocks and ten device words pass only for OM-2 with host. |
| 37 | global hok ulong 1 |
| 38 | global fok ulong 1 |
| 39 | global hm uchar 84 |
| 40 | global mdev ulong 1 |
| 41 | global munit ulong 1 |
| 42 | text mappin "6d1b1cf5a44803389a831b67f750ea4cd1c9f53edfde9d6d9241d7352887f1f8" |
| 43 | text xmappin "c5ac9979232afd0d750e1d5088af69692032997136f761e585a25aa9a1cfc87e" |
| 44 | text ctxparts "ctx_~(omega_native_context *context, uint64_t *result~ if (ombr2_overlap(sp, ns))\n return OMEGA_BAD_ARG;\n return ombr2_run(context, ombr2_entry_~#ifndef OMEGA_NATIVE_CONTEXT_DECL\n#define OMEGA_NATIVE_CONTEXT_DECL\n#define OMEGA_CONTEXT_BUSY 36u\ntypedef struct omega_native_context omega_native_context;\nuint32_t omega_native_context_create(uint64_t capacity, omega_native_context **out);\nuint32_t omega_native_context_destroy(omega_native_context *context);\n#endif\n" |
| 45 | text hname "host" |
| 46 | text xhname "x86host" |
| 47 | text hpre " host=" |
| 48 | text hw "|fclose|fopen|fstat|stat|getuid|geteuid|getgid|getegid|lstat|fsync|fchmod|fseek|socknew|listen|accept|fork|dupfd|monons|unlink|makedir|getdnts|connect|bind|waitpid|recv|send|sleepns|argcnt|argread|waitio|execprog|renames|rmdir|killpid|pipefds|getpid|realns|sockname|cwd|readlnk|sockopt|random|envcnt|envread|chdir|ftrunc|link|symlnk|chmod|faccess|truncate|chown|fchdir|getppid|umask|fdsync|memfd|setsid|getpgid|setpgid|pread|pwrite|getsid|syncfs|shutdown|devctl|mapnew|mapdrop|mapread|mapwrite|devcall|uvmctl|mapaddr|mapget|mapset|maphold|mapbind|flock|execpure|peercred|pollfds|sendmsg|peername|" |
| 49 | text xjmp ") \":\\nendbr64\\njmp \" OMBR_SYM(ombr_code_~) \":\\nendbr64\\njmp \" OMBR_SYM(ombr2_code_" |
| 50 | text xasm "/* SysV AMD64 adapter to the pinned private Omega frame ABI. R12 anchors the native\n * stack, R14 the runtime table, R15 the owned-stack floor. Hosted device helpers and legacy read/write preserve these reserved registers;\n * the selected hosted compiler also restores its R13 argument-stack scratch.\n * CET shadow-stack enforcement is not supported by the nonlocal trap return. */\n__asm__(\".text\\n.balign 16\\n.local ombr_enter\\n.hidden ombr_enter\\n.type ombr_enter,@function\\nombr_enter:\\n\"\n \"endbr64\\npush %rbx\\npush %rbp\\npush %r12\\npush %r13\\npush %r14\\npush %r15\\npush %rcx\\n\"\n \"mov %rsp,%r12\\nmov %rdx,%r14\\nmov %r9,%r15\\nmov %rdi,%r10\\n\"\n \"mov %r8,%rbp\\nmov %r8,%rsp\\nsub $256,%rsp\\n\"\n \"mov 0(%rsi),%rax\\nmov %rax,-8(%rbp)\\nmov 8(%rsi),%rax\\nmov %rax,-16(%rbp)\\n\"\n \"mov 16(%rsi),%rax\\nmov %rax,-24(%rbp)\\nmov 24(%rsi),%rax\\nmov %rax,-32(%rbp)\\n\"\n \"mov 32(%rsi),%rax\\nmov %rax,-40(%rbp)\\nmov 40(%rsi),%rax\\nmov %rax,-48(%rbp)\\n\"\n \"call *%r10\\nmov %r12,%rsp\\nmov (%rsp),%rcx\\nmov %rax,(%rcx)\\nxor %eax,%eax\\n\"\n \"ombr_leave:\\nadd $8,%rsp\\npop %r15\\npop %r14\\npop %r13\\npop %r12\\npop %rbp\\npop %rbx\\nret\\n\"\n \".size ombr_enter,.-ombr_enter\\n.local ombr_trap\\n.hidden ombr_trap\\n.type ombr_trap,@function\\nombr_trap:\\n\"\n \"endbr64\\nmov %r12,%rsp\\nlea -1(%rsi),%eax\\ncmp $13,%eax\\nmov $34,%eax\\ncmovbe %esi,%eax\\njmp ombr_leave\\n\"\n \".size ombr_trap,.-ombr_trap\\n.local ombr_no_entry\\n.hidden ombr_no_entry\\n.type ombr_no_entry,@function\\nombr_no_entry:\\n\"\n \"endbr64\\nmov %r12,%rsp\\nmov $34,%eax\\njmp ombr_leave\\n.size ombr_no_entry,.-ombr_no_entry\\n\");\nuint32_t ombr_xenter(const void *code, const uint64_t *args, const ombr_rt *rt, uint64_t *out, void *top, void *floor) __asm__(\"ombr_enter\") __attribute__((visibility(\"hidden\")));\n/* The true mapping floor must not move when ABI-v2 out buffers lower top. */\n#define ombr_enter(code,args,rt,out,top) ombr_xenter(code,args,rt,out,top,ombr_stk - OMBR_STACK)\n" |
| 51 | text xs "/* ombr_enter" |
| 52 | text xe "static void ombr_free" |
| 53 | text fxs "/* ombr_enter saves" |
| 54 | text fxe "static const ombr_rt ombr_rt_table" |
| 55 | text xqd "\\n.quad " |
| 56 | text xby "\\n.byte " |
| 57 | text xfasm "/* SysV AMD64 adapter to the pinned private Omega frame ABI on the caller's stack. ombr_enter saves\n * the callee-saved registers there, keeps that stack pointer in R12, points R14 at the runtime table\n * and sets the owned-stack floor R15 to 0, so, as in the AArch64 binding, the pure scalar code runs on\n * the caller's stack with no bound check. A normal return stores RAX through out and returns 0. A\n * runtime entry restores the stack pointer from R12 and returns a status; out is not written.\n * CET shadow-stack enforcement is not supported by the nonlocal trap return. */\n__asm__(\".text\\n.balign 16\\n.local ombr_enter\\n.hidden ombr_enter\\n.type ombr_enter,@function\\nombr_enter:\\n\"\n \"endbr64\\npush %rbx\\npush %rbp\\npush %r12\\npush %r13\\npush %r14\\npush %r15\\npush %rcx\\n\"\n \"mov %rsp,%r12\\nmov %rdx,%r14\\nxor %r15d,%r15d\\nmov %rdi,%r10\\n\"\n \"mov %rsp,%rbp\\nsub $256,%rsp\\n\"\n \"mov 0(%rsi),%rax\\nmov %rax,-8(%rbp)\\nmov 8(%rsi),%rax\\nmov %rax,-16(%rbp)\\n\"\n \"mov 16(%rsi),%rax\\nmov %rax,-24(%rbp)\\nmov 24(%rsi),%rax\\nmov %rax,-32(%rbp)\\n\"\n \"mov 32(%rsi),%rax\\nmov %rax,-40(%rbp)\\nmov 40(%rsi),%rax\\nmov %rax,-48(%rbp)\\n\"\n \"call *%r10\\nmov %r12,%rsp\\nmov (%rsp),%rcx\\nmov %rax,(%rcx)\\nxor %eax,%eax\\n\"\n \"ombr_leave:\\nadd $8,%rsp\\npop %r15\\npop %r14\\npop %r13\\npop %r12\\npop %rbp\\npop %rbx\\nret\\n\"\n \".size ombr_enter,.-ombr_enter\\n.local ombr_trap\\n.hidden ombr_trap\\n.type ombr_trap,@function\\nombr_trap:\\n\"\n \"endbr64\\nmov %r12,%rsp\\nlea -1(%rsi),%eax\\ncmp $13,%eax\\nmov $34,%eax\\ncmovbe %esi,%eax\\njmp ombr_leave\\n\"\n \".size ombr_trap,.-ombr_trap\\n.local ombr_no_entry\\n.hidden ombr_no_entry\\n.type ombr_no_entry,@function\\nombr_no_entry:\\n\"\n \"endbr64\\nmov %r12,%rsp\\nmov $34,%eax\\njmp ombr_leave\\n.size ombr_no_entry,.-ombr_no_entry\\n\");\n" |
| 58 | text kw "toeditviewulonglongucharvoidmainf32ushortconstf64" |
| 59 | text fr "__asm__(OMBR_CODE_SECTION \".balign 4\\n\" OMBR_LOCAL(ombr_code_~) OMBR_HIDDEN(ombr_code_~) OMBR_SYM(ombr_code_~) \":\\n.byte ~) \"\\n\" OMBR_PREVIOUS);\nextern const unsigned char ombr_entry_~[] __attribute__((visibility(\"hidden\")));\n__attribute__((visibility(\"default\"))) uint32_t omega_~(uint64_t *result~, uint64_t o_~, void *o_~, const void *o_~_len~)\n{\n ombr_span sp[7] = {{0}};\n unsigned ns = 0;\n uint64_t a[6] = {0};\n if (ombr_span_add(sp, &ns, result, 1u, 1u, 8u, 1))\n return OMEGA_BAD_ARG;\n~ if (ombr_span_add(sp, &ns, o_~, o_~_len, ~u, ~))\n return OMEGA_BAD_ARG;\n a[~] = (uint64_t)(uintptr_t)o_~;\n~ a[~] = o_~ if (ombr_overlap(sp, ns))\n return OMEGA_BAD_ARG;\n return ombr_run(ombr_entry_~, a, result, ~);\n}\n~\\n\" OMBR_LOCAL(ombr_entry_~) OMBR_HIDDEN(ombr_entry_~) OMBR_SYM(ombr_entry_~) \":\\nhint #34\\nb \" OMBR_SYM(ombr_code_~#if defined(__APPLE__)\n#error \"omega-bridge native binding: unit ~ makes Linux system calls (Omega host words), which macOS does not run\"\n#endif\n" |
| 60 | text pre "/* Generated by omega-bridge src/native.om: native call ABI v1 (docs/NATIVE-ABI.md).\n * The Omega machine code below is embedded byte for byte as the seeded compiler wrote it.\n * This file only adapts the C calling convention to it. Regenerate it; do not edit it. */\n#include <pthread.h>\n#include <signal.h>\n#include <stdint.h>\n#include <sys/mman.h>\n#define OMEGA_OK 0u\n#define OMEGA_BAD_ARG 32u\n#define OMEGA_REENTRY 33u\n#define OMEGA_BAD_RT 34u\n#define OMEGA_NO_STACK 35u\n#define OMBR_STACK (8u << 20)\n#define OMBR_GUARD (8u << 20)\n/* entry[2] is the trap entry (OSC-1 section 7). */\ntypedef struct ombr_rt { const void *entry[32]; } ombr_rt;\ntypedef struct ombr_span { uintptr_t lo, hi; int w; } ombr_span;\nstatic _Thread_local volatile sig_atomic_t ombr_active;\nstatic _Thread_local unsigned char *ombr_stk;\nstatic pthread_key_t ombr_key;\nstatic int ombr_keyok;\nstatic pthread_once_t ombr_once = PTHREAD_ONCE_INIT;\nuint32_t ombr_enter(const void *code, const uint64_t *args, const ombr_rt *rt, uint64_t *out, void *top)\n __attribute__((visibility(\"hidden\")));\nextern const unsigned char ombr_trap[] __attribute__((visibility(\"hidden\")));\nextern const unsigned char ombr_no_entry[] __attribute__((visibility(\"hidden\")));\n/* The object format's spelling of the embedded code and runtime symbols. ELF keeps them local and hidden\n * in .text.omega_bridge. Mach-O (macOS) prefixes C symbol names with an underscore and keeps them local\n * by not declaring them .globl; .alt_entry keeps the runtime entries in ombr_enter's atom. */\n#if defined(__APPLE__) && defined(__MACH__)\n#define OMBR_SYM(n) \"_\" #n\n#define OMBR_LOCAL(n) \"\"\n#define OMBR_HIDDEN(n) \"\"\n#define OMBR_FUNC(n) \"\"\n#define OMBR_ALT(n) \".alt_entry _\" #n \"\\n\"\n#define OMBR_SIZE(n) \"\"\n#define OMBR_LEAVE \"Lombr_leave\"\n#define OMBR_CODE_SECTION \".section __TEXT,__text,regular,pure_instructions\\n\"\n#define OMBR_PREVIOUS \"\"\n#elif defined(__ELF__)\n#define OMBR_SYM(n) #n\n#define OMBR_LOCAL(n) \".local \" #n \"\\n\"\n#define OMBR_HIDDEN(n) \".hidden \" #n \"\\n\"\n#define OMBR_FUNC(n) \".type \" #n \",%function\\n\"\n#define OMBR_ALT(n) OMBR_FUNC(n)\n#define OMBR_SIZE(n) \".size \" #n \",.-\" #n \"\\n\"\n#define OMBR_LEAVE \"ombr_leave\"\n#define OMBR_CODE_SECTION \".section .text.omega_bridge,\\\"ax\\\",@progbits\\n\"\n#define OMBR_PREVIOUS \".previous\\n\"\n#else\n#error \"omega-bridge native binding: ELF or Mach-O objects only\"\n#endif\n/* ombr_enter saves the callee-saved registers on the caller's stack, keeps that stack pointer in x19 and\n * runs the code on the binding's own stack. A normal return stores x0 through out and\n * returns 0. A runtime entry restores the stack pointer from x19 and returns a status; out is not\n * written. A unit's code must not write x18, x19 or x29 and must keep sp balanced; it may write x0..x17,\n * x20..x28 and v0..v31 (x20..x28 and d8..d15 are restored here). Runtime entries are reached by blr/br, so they start with bti jc. */\n#if !defined(__aarch64__)\n#error \"omega-bridge native binding: the embedded code is AArch64\"\n#endif\n__asm__(\".text\\n.balign 4\\n\" OMBR_LOCAL(ombr_enter) OMBR_HIDDEN(ombr_enter) OMBR_FUNC(ombr_enter)\n OMBR_SYM(ombr_enter) \":\\n\"\n \"hint #34\\nstp x29,x30,[sp,#-176]!\\nmov x29,sp\\nstp x19,x20,[sp,#16]\\nstp x21,x22,[sp,#32]\\n\"\n \"stp x23,x24,[sp,#48]\\nstp x25,x26,[sp,#64]\\nstp x27,x28,[sp,#80]\\nstp d8,d9,[sp,#96]\\n\"\n \"stp d10,d11,[sp,#112]\\nstp d12,d13,[sp,#128]\\nstp d14,d15,[sp,#144]\\nstr x3,[sp,#160]\\n\"\n \"mov x19,sp\\nmov x16,x0\\nmov x17,x1\\nmov x7,x2\\nmov sp,x4\\n\"\n \"ldp x0,x1,[x17]\\nldp x2,x3,[x17,#16]\\nldp x4,x5,[x17,#32]\\nblr x16\\n\"\n \"mov sp,x19\\nldr x9,[sp,#160]\\nstr x0,[x9]\\nmov w0,#0\\n\"\n OMBR_LEAVE \":\\nldp d14,d15,[sp,#144]\\nldp d12,d13,[sp,#128]\\nldp d10,d11,[sp,#112]\\n\"\n \"ldp d8,d9,[sp,#96]\\nldp x27,x28,[sp,#80]\\nldp x25,x26,[sp,#64]\\nldp x23,x24,[sp,#48]\\n\"\n \"ldp x21,x22,[sp,#32]\\nldp x19,x20,[sp,#16]\\nldp x29,x30,[sp],#176\\nret\\n\" OMBR_SIZE(ombr_enter)\n OMBR_LOCAL(ombr_trap) OMBR_HIDDEN(ombr_trap) OMBR_ALT(ombr_trap) OMBR_SYM(ombr_trap) \":\\nhint #38\\n\"\n \"mov sp,x19\\nsub x2,x1,#1\\nmov w3,#34\\ncmp x2,#13\\ncsel w0,w1,w3,ls\\nb \" OMBR_LEAVE \"\\n\"\n OMBR_SIZE(ombr_trap)\n OMBR_LOCAL(ombr_no_entry) OMBR_HIDDEN(ombr_no_entry) OMBR_ALT(ombr_no_entry) OMBR_SYM(ombr_no_entry) \":\\nhint #38\\n\"\n \"mov sp,x19\\nmov w0,#34\\nb \" OMBR_LEAVE \"\\n\" OMBR_SIZE(ombr_no_entry));\nstatic void ombr_free(void *p)\n{\n munmap(p, OMBR_STACK + OMBR_GUARD);\n}\nstatic void ombr_init(void)\n{\n ombr_keyok = pthread_key_create(&ombr_key, ombr_free) == 0;\n}\n/* The thread's Omega stack: OMBR_STACK usable bytes above an OMBR_GUARD no-access region. A function-mode\n * unit has no call cycles and at most 4 MiB of local arrays per function (OMEGESE, local arrays), so a frame that\n * would pass the bottom starts inside the guard and faults there; nothing below the guard is touched. */\nstatic unsigned char *ombr_stack(void)\n{\n if (ombr_stk)\n return ombr_stk;\n pthread_once(&ombr_once, ombr_init);\n if (!ombr_keyok)\n return 0;\n unsigned char *p = mmap(0, OMBR_STACK + OMBR_GUARD, PROT_READ | PROT_WRITE,\n MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);\n if (p == MAP_FAILED)\n return 0;\n if (mprotect(p, OMBR_GUARD, PROT_NONE) != 0 || pthread_setspecific(ombr_key, p) != 0) {\n munmap(p, OMBR_STACK + OMBR_GUARD);\n return 0;\n }\n ombr_stk = p + OMBR_GUARD + OMBR_STACK;\n return ombr_stk;\n}\nstatic int ombr_span_add(ombr_span *sp, unsigned *ns, const void *p, uint64_t n, uint64_t want, uint64_t es, int w)\n{\n uintptr_t lo = (uintptr_t)p;\n if (!p || n != want || lo % es != 0u || n > (UINTPTR_MAX - lo) / es)\n return 1;\n sp[*ns].lo = lo;\n sp[*ns].hi = lo + n * es;\n sp[*ns].w = w;\n (*ns)++;\n return 0;\n}\nstatic int ombr_overlap(const ombr_span *sp, unsigned ns)\n{\n for (unsigned i = 0; i < ns; i++)\n for (unsigned j = i + 1; j < ns; j++)\n if ((sp[i].w || sp[j].w) && sp[i].lo < sp[j].hi && sp[j].lo < sp[i].hi)\n return 1;\n return 0;\n}\n/* One read-only runtime table for every call and thread: the code only reads it (a write would fault). */\nstatic const ombr_rt ombr_rt_table = {{ ombr_no_entry, ombr_no_entry, ombr_trap, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry }};\nstatic uint32_t ombr_run(const void *code, const uint64_t *args, uint64_t *result, int has_value)\n{\n if (ombr_active)\n return OMEGA_REENTRY;\n ombr_active = 1;\n unsigned char *top = ombr_stack();\n if (!top) {\n ombr_active = 0;\n return OMEGA_NO_STACK;\n }\n uint64_t v = 0;\n uint32_t s = ombr_enter(code, args, &ombr_rt_table, &v, top);\n ombr_active = 0;\n if (s == OMEGA_OK)\n *result = has_value ? v : 0u;\n return s;\n}\n" |
| 61 | text predev "#define OMBR_USES_MAPS 1\n/* Generated by omega-bridge src/native.om: native call ABI v1 (docs/NATIVE-ABI.md).\n * The Omega machine code below is embedded byte for byte as the seeded compiler wrote it.\n * This file only adapts the C calling convention to it. Regenerate it; do not edit it. */\n#include <pthread.h>\n#include <signal.h>\n#include <stdint.h>\n#include <stdlib.h>\n#include <sys/mman.h>\n#define OMEGA_OK 0u\n#define OMEGA_BAD_ARG 32u\n#define OMEGA_REENTRY 33u\n#define OMEGA_BAD_RT 34u\n#define OMEGA_NO_STACK 35u\n#define OMBR_STACK (8u << 20)\n#define OMBR_GUARD (8u << 20)\n/* entry[2] is the trap entry (OSC-1 section 7). */\ntypedef struct ombr_rt { const void *entry[32]; } ombr_rt;\ntypedef struct ombr_span { uintptr_t lo, hi; int w; } ombr_span;\n#define OMEGA_CONTEXT_BUSY 36u\ntypedef struct omega_native_context {\n pthread_mutex_t lock;\n uint64_t *maps;\n const ombr_rt *rt;\n} omega_native_context;\nstatic _Alignas(16) uint64_t ombr_maps[516];\nstatic omega_native_context ombr_default = { .lock = PTHREAD_MUTEX_INITIALIZER, .maps = ombr_maps };\nstatic _Thread_local volatile sig_atomic_t ombr_active;\nstatic _Thread_local unsigned char *ombr_stk;\nstatic pthread_key_t ombr_key;\nstatic int ombr_keyok;\nstatic pthread_once_t ombr_once = PTHREAD_ONCE_INIT;\nuint32_t ombr_enter(const void *code, const uint64_t *args, const ombr_rt *rt, uint64_t *out, void *top)\n __attribute__((visibility(\"hidden\")));\nextern const unsigned char ombr_trap[] __attribute__((visibility(\"hidden\")));\nextern const unsigned char ombr_no_entry[] __attribute__((visibility(\"hidden\")));\n/* The object format's spelling of the embedded code and runtime symbols. ELF keeps them local and hidden\n * in .text.omega_bridge. Mach-O (macOS) prefixes C symbol names with an underscore and keeps them local\n * by not declaring them .globl; .alt_entry keeps the runtime entries in ombr_enter's atom. */\n#if defined(__APPLE__) && defined(__MACH__)\n#define OMBR_SYM(n) \"_\" #n\n#define OMBR_LOCAL(n) \"\"\n#define OMBR_HIDDEN(n) \"\"\n#define OMBR_FUNC(n) \"\"\n#define OMBR_ALT(n) \".alt_entry _\" #n \"\\n\"\n#define OMBR_SIZE(n) \"\"\n#define OMBR_LEAVE \"Lombr_leave\"\n#define OMBR_CODE_SECTION \".section __TEXT,__text,regular,pure_instructions\\n\"\n#define OMBR_PREVIOUS \"\"\n#elif defined(__ELF__)\n#define OMBR_SYM(n) #n\n#define OMBR_LOCAL(n) \".local \" #n \"\\n\"\n#define OMBR_HIDDEN(n) \".hidden \" #n \"\\n\"\n#define OMBR_FUNC(n) \".type \" #n \",%function\\n\"\n#define OMBR_ALT(n) OMBR_FUNC(n)\n#define OMBR_SIZE(n) \".size \" #n \",.-\" #n \"\\n\"\n#define OMBR_LEAVE \"ombr_leave\"\n#define OMBR_CODE_SECTION \".section .text.omega_bridge,\\\"ax\\\",@progbits\\n\"\n#define OMBR_PREVIOUS \".previous\\n\"\n#else\n#error \"omega-bridge native binding: ELF or Mach-O objects only\"\n#endif\n/* ombr_enter saves the callee-saved registers on the caller's stack, keeps that stack pointer in x19 and\n * runs the code on the binding's own stack. A normal return stores x0 through out and\n * returns 0. A runtime entry restores the stack pointer from x19 and returns a status; out is not\n * written. A unit's code must not write x18, x19 or x29 and must keep sp balanced; it may write x0..x17,\n * x20..x28 and v0..v31 (x20..x28 and d8..d15 are restored here). Runtime entries are reached by blr/br, so they start with bti jc. */\n#if !defined(__aarch64__)\n#error \"omega-bridge native binding: the embedded code is AArch64\"\n#endif\n__asm__(\".text\\n.balign 4\\n\" OMBR_LOCAL( ombr_enter ) OMBR_HIDDEN(ombr_enter) OMBR_FUNC(ombr_enter)\n OMBR_SYM(ombr_enter) \":\\n\"\n \"hint #34\\nstp x29,x30,[sp,#-176]!\\nmov x29,sp\\nstp x19,x20,[sp,#16]\\nstp x21,x22,[sp,#32]\\n\"\n \"stp x23,x24,[sp,#48]\\nstp x25,x26,[sp,#64]\\nstp x27,x28,[sp,#80]\\nstp d8,d9,[sp,#96]\\n\"\n \"stp d10,d11,[sp,#112]\\nstp d12,d13,[sp,#128]\\nstp d14,d15,[sp,#144]\\nstr x3,[sp,#160]\\n\"\n \"mov x19,sp\\nmov x16,x0\\nmov x17,x1\\nmov x7,x2\\nmov sp,x4\\n\"\n \"ldp x0,x1,[x17]\\nldp x2,x3,[x17,#16]\\nldp x4,x5,[x17,#32]\\nblr x16\\n\"\n \"mov sp,x19\\nldr x9,[sp,#160]\\nstr x0,[x9]\\nmov w0,#0\\n\"\n OMBR_LEAVE \":\\nldp d14,d15,[sp,#144]\\nldp d12,d13,[sp,#128]\\nldp d10,d11,[sp,#112]\\n\"\n \"ldp d8,d9,[sp,#96]\\nldp x27,x28,[sp,#80]\\nldp x25,x26,[sp,#64]\\nldp x23,x24,[sp,#48]\\n\"\n \"ldp x21,x22,[sp,#32]\\nldp x19,x20,[sp,#16]\\nldp x29,x30,[sp],#176\\nret\\n\" OMBR_SIZE(ombr_enter)\n OMBR_LOCAL(ombr_trap) OMBR_HIDDEN(ombr_trap) OMBR_ALT(ombr_trap) OMBR_SYM(ombr_trap) \":\\nhint #38\\n\"\n \"mov sp,x19\\nsub x2,x1,#1\\nmov w3,#34\\ncmp x2,#13\\ncsel w0,w1,w3,ls\\nb \" OMBR_LEAVE \"\\n\"\n OMBR_SIZE(ombr_trap)\n OMBR_LOCAL(ombr_no_entry) OMBR_HIDDEN(ombr_no_entry) OMBR_ALT(ombr_no_entry) OMBR_SYM(ombr_no_entry) \":\\nhint #38\\n\"\n \"mov sp,x19\\nmov w0,#34\\nb \" OMBR_LEAVE \"\\n\" OMBR_SIZE(ombr_no_entry));\nstatic void ombr_free(void *p)\n{\n munmap(p, OMBR_STACK + OMBR_GUARD);\n}\nstatic void ombr_init(void)\n{\n ombr_keyok = pthread_key_create(&ombr_key, ombr_free) == 0;\n}\n/* The thread's Omega stack: OMBR_STACK usable bytes above an OMBR_GUARD no-access region. A function-mode\n * unit has no call cycles and at most 4 MiB of local arrays per function (OMEGESE, local arrays), so a frame that\n * would pass the bottom starts inside the guard and faults there; nothing below the guard is touched. */\nstatic unsigned char *ombr_stack(void)\n{\n if (ombr_stk)\n return ombr_stk;\n pthread_once(&ombr_once, ombr_init);\n if (!ombr_keyok)\n return 0;\n unsigned char *p = mmap(0, OMBR_STACK + OMBR_GUARD, PROT_READ | PROT_WRITE,\n MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);\n if (p == MAP_FAILED)\n return 0;\n if (mprotect(p, OMBR_GUARD, PROT_NONE) != 0 || pthread_setspecific(ombr_key, p) != 0) {\n munmap(p, OMBR_STACK + OMBR_GUARD);\n return 0;\n }\n ombr_stk = p + OMBR_GUARD + OMBR_STACK;\n return ombr_stk;\n}\nstatic int ombr_span_add(ombr_span *sp, unsigned *ns, const void *p, uint64_t n, uint64_t want, uint64_t es, int w)\n{\n uintptr_t lo = (uintptr_t)p;\n if (!p || n != want || lo % es != 0u || n > (UINTPTR_MAX - lo) / es)\n return 1;\n sp[*ns].lo = lo;\n sp[*ns].hi = lo + n * es;\n sp[*ns].w = w;\n (*ns)++;\n return 0;\n}\nstatic int ombr_overlap(const ombr_span *sp, unsigned ns)\n{\n for (unsigned i = 0; i < ns; i++)\n for (unsigned j = i + 1; j < ns; j++)\n if ((sp[i].w || sp[j].w) && sp[i].lo < sp[j].hi && sp[j].lo < sp[i].hi)\n return 1;\n return 0;\n}\n/* One read-only runtime table for every call and thread: the code only reads it (a write would fault). */\nstatic const ombr_rt ombr_rt_table = {{ ombr_no_entry, ombr_no_entry, ombr_trap, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_maps }};\n/* Explicit C ABI contexts: compatibility-runtime ownership, not driver policy. */\nstatic pthread_once_t ombr_map_once = PTHREAD_ONCE_INIT;\nstatic pthread_mutex_t ombr_id_lock = PTHREAD_MUTEX_INITIALIZER;\nstatic uint64_t ombr_next_context = 2;\nstatic void ombr_map_init(void)\n{\n ombr_maps[0] = 128;\n ombr_maps[1] = 67108864;\n ombr_maps[2] = 134217727;\n for (unsigned i = 0; i < 128; i++)\n ombr_maps[4 + i * 4 + 2] = ombr_maps[1];\n ombr_default.rt = &ombr_rt_table;\n}\n__attribute__((visibility(\"default\"))) uint32_t omega_native_context_create(uint64_t capacity,\n omega_native_context **out)\n{\n if (!out || capacity == 0 || capacity > 4098)\n return OMEGA_BAD_ARG;\n if (ombr_active)\n return OMEGA_REENTRY;\n if (pthread_mutex_lock(&ombr_id_lock) != 0)\n return OMEGA_BAD_RT;\n uint64_t id = ombr_next_context;\n if (id <= 16777215)\n ombr_next_context++;\n int unlock_error = pthread_mutex_unlock(&ombr_id_lock);\n if (unlock_error || id > 16777215)\n return OMEGA_BAD_RT;\n omega_native_context *c = calloc(1, sizeof *c);\n if (!c)\n return OMEGA_BAD_RT;\n c->maps = calloc((size_t)capacity + 1u, 32u);\n if (!c->maps) {\n free(c);\n return OMEGA_BAD_RT;\n }\n if (pthread_mutex_init(&c->lock, 0) != 0) {\n free(c->maps);\n free(c);\n return OMEGA_BAD_RT;\n }\n ombr_rt *rt = mmap(0, sizeof *rt, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n if (rt == MAP_FAILED) {\n pthread_mutex_destroy(&c->lock);\n free(c->maps);\n free(c);\n return OMEGA_BAD_RT;\n }\n *rt = ombr_rt_table;\n rt->entry[31] = c->maps;\n if (mprotect(rt, sizeof *rt, PROT_READ) != 0) {\n munmap(rt, sizeof *rt);\n pthread_mutex_destroy(&c->lock);\n free(c->maps);\n free(c);\n return OMEGA_BAD_RT;\n }\n c->rt = rt;\n c->maps[0] = capacity;\n c->maps[1] = id << 26;\n c->maps[2] = ((id + 1u) << 26) - 1u;\n for (uint64_t i = 0; i < capacity; i++)\n c->maps[4 + i * 4 + 2] = c->maps[1];\n *out = c;\n return OMEGA_OK;\n}\n__attribute__((visibility(\"default\"))) uint32_t omega_native_context_destroy(omega_native_context *c)\n{\n if (!c || c == &ombr_default)\n return OMEGA_BAD_ARG;\n if (ombr_active)\n return OMEGA_REENTRY;\n /* Caller has joined/drained users and waiters before entering destruction. */\n if (pthread_mutex_lock(&c->lock) != 0)\n return OMEGA_BAD_RT;\n for (uint64_t i = 0; i < c->maps[0]; i++) {\n if (c->maps[4 + i * 4] != 0) {\n if (pthread_mutex_unlock(&c->lock) != 0)\n return OMEGA_BAD_RT;\n return OMEGA_CONTEXT_BUSY;\n }\n }\n if (pthread_mutex_unlock(&c->lock) != 0 || pthread_mutex_destroy(&c->lock) != 0)\n return OMEGA_BAD_RT;\n int failed = munmap((void *)c->rt, sizeof *c->rt) != 0;\n free(c->maps);\n free(c);\n return failed ? OMEGA_BAD_RT : OMEGA_OK;\n}\nstatic uint32_t ombr_context_lock(omega_native_context *c)\n{\n if (!c)\n return OMEGA_BAD_ARG;\n if (ombr_active)\n return OMEGA_REENTRY;\n ombr_active = 1;\n if (c == &ombr_default && pthread_once(&ombr_map_once, ombr_map_init) != 0) {\n ombr_active = 0;\n return OMEGA_BAD_RT;\n }\n if (pthread_mutex_lock(&c->lock) != 0) {\n ombr_active = 0;\n return OMEGA_BAD_RT;\n }\n return OMEGA_OK;\n}\nstatic uint32_t ombr_context_unlock(omega_native_context *c, uint32_t status)\n{\n int failed = pthread_mutex_unlock(&c->lock);\n ombr_active = 0;\n return failed ? OMEGA_BAD_RT : status;\n}\nstatic uint32_t ombr_run(const void *code, const uint64_t *args, uint64_t *result, int has_value)\n{\n omega_native_context *context = &ombr_default;\n uint32_t s = ombr_context_lock(context);\n if (s != OMEGA_OK)\n return s;\n unsigned char *top = ombr_stack();\n if (!top)\n return ombr_context_unlock(context, OMEGA_NO_STACK);\n uint64_t v = 0;\n s = ombr_enter(code, args, context->rt, &v, top);\n if (s == OMEGA_OK)\n *result = has_value ? v : 0u;\n return ombr_context_unlock(context, s);\n}\n" |
| 62 | note mo: the output names; tb: the binding texts, fragments separated by ~ (byte 126): 0-11 h, |
| 63 | note 12-21 python, 22-34 rust, 35-46 zig, 47-64 go (its C preamble includes the generated header). |
| 64 | text mo "chpythonrustziggoapihapicfreestidentfapic" |
| 65 | text tb "/* Generated by omega-bridge src/native.om: native call ABI v1 (docs/NATIVE-ABI.md).\n * C and C++ declarations for libomega_native. Regenerate it; do not edit it.\n * Status: 0 done; 1..14 the Omega trap code; 32 argument refused (null, wrong length, misaligned,\n * overlap); 33 reentry; 34 bad runtime entry; 35 no stack. The result is written only on status 0.\n * A long is its two's-complement bits; an array is its address then its element count.\n * Parameter names carry o_ so no language's reserved words collide. */\n#ifndef OMEGA_NATIVE_H\n#define OMEGA_NATIVE_H\n#include <stdint.h>\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n#define OMEGA_OK 0u\n#define OMEGA_BAD_ARG 32u\n#define OMEGA_REENTRY 33u\n#define OMEGA_BAD_RT 34u\n#define OMEGA_NO_STACK 35u\n~/* ~ */\nuint32_t omega_~(uint64_t *result~, uint64_t o_~, void *o_~, const void *o_~, void *o_~, const void *o_~_len~);\n~#ifdef __cplusplus\n}\n#endif\n#endif\n~# Generated by omega-bridge src/native.om: native call ABI v1 (docs/NATIVE-ABI.md).\n# ctypes declarations for libomega_native.so beside this file. Regenerate it; do not edit it.\n# Status: 0 done; 1..14 the Omega trap code; 32 argument refused (None, wrong length, misaligned,\n# overlap); 33 reentry; 34 bad runtime entry; 35 no stack. The result (a ctypes.c_uint64 passed with\n# ctypes.byref) is written only on status 0. A scalar is an int in 0 .. 2**64-1 (a long is passed as its\n# two's-complement bits); anything else raises ctypes.ArgumentError, nothing is truncated. An array is a\n# ctypes array of its element type (bytes for a view uchar, c_float for f32, c_uint16 for ushort) then its element count; an edit array must\n# be writable, so bytes are refused there.\nimport ctypes, os, sys\nOMEGA_OK, OMEGA_BAD_ARG, OMEGA_REENTRY, OMEGA_BAD_RT, OMEGA_NO_STACK = 0, 32, 33, 34, 35\nlib = ctypes.CDLL(os.path.join(os.path.dirname(os.path.abspath(__file__)),\n \"libomega_native.dylib\" if sys.platform == \"darwin\" else \"libomega_native.so\"))\nclass _u64:\n @classmethod\n def from_param(cls, v):\n if type(v) is not int or v < 0 or v > 18446744073709551615:\n raise ValueError(\"omega scalar: an int in 0 .. 2**64-1 expected, got %r\" % (v,))\n return ctypes.c_uint64(v)\n_res = ctypes.POINTER(ctypes.c_uint64)\n_a3 = ctypes.POINTER(ctypes.c_uint64) # edit ulong: a writable ctypes array of c_uint64\n_a4 = ctypes.POINTER(ctypes.c_uint64) # view ulong: a ctypes array of c_uint64\n_a5 = ctypes.POINTER(ctypes.c_ubyte) # edit uchar: a writable ctypes array of c_ubyte\n_a6 = ctypes.c_char_p # view uchar: bytes, or a ctypes array of c_char\n_a7 = ctypes.POINTER(ctypes.c_float) # edit f32: a writable ctypes array of c_float\n_a8 = ctypes.POINTER(ctypes.c_float) # view f32: a ctypes array of c_float\n_a9 = ctypes.POINTER(ctypes.c_uint16) # edit ushort: a writable ctypes array of c_uint16\n_a10 = ctypes.POINTER(ctypes.c_uint16) # view ushort: a ctypes array of c_uint16\n~# ~\nomega_~ = lib.omega_~\nomega_~.argtypes = [_res~, _u64~, _a~]\nomega_~.restype = ctypes.c_uint32\n~// Generated by omega-bridge src/native.om: native call ABI v1 (docs/NATIVE-ABI.md).\n// Declarations for libomega_native (build with -L <its directory>; Rust 1.82 or later). Regenerate it; do not edit it.\n// Status: 0 done; 1..14 the Omega trap code; 32 argument refused (null, wrong length, misaligned,\n// overlap); 33 reentry; 34 bad runtime entry; 35 no stack. The result is written only on status 0.\n// A long is its two's-complement bits (an i64 as u64); an array is its pointer then its element count.\n#[allow(dead_code)]\npub const OMEGA_OK: u32 = 0;\n#[allow(dead_code)]\npub const OMEGA_BAD_ARG: u32 = 32;\n#[allow(dead_code)]\npub const OMEGA_REENTRY: u32 = 33;\n#[allow(dead_code)]\npub const OMEGA_BAD_RT: u32 = 34;\n#[allow(dead_code)]\npub const OMEGA_NO_STACK: u32 = 35;\n#[allow(dead_code)]\n#[link(name = \"omega_native\")]\nunsafe extern \"C\" {\n~ // ~\n pub fn omega_~(result: *mut u64~, o_~: u64~: *mut u64~: *const u64~: *mut u8~: *const u8~_len: u64~) -> u32;\n~}\n~// Generated by omega-bridge src/native.om: native call ABI v1 (docs/NATIVE-ABI.md).\n// Declarations for libomega_native (build with -L<its directory> -lomega_native -lc). Regenerate it; do not edit it.\n// Status: 0 done; 1..14 the Omega trap code; 32 argument refused (null, wrong length, misaligned,\n// overlap); 33 reentry; 34 bad runtime entry; 35 no stack. The result is written only on status 0.\n// A long is its two's-complement bits (@bitCast); an array is its pointer then its element count.\npub const OMEGA_OK: u32 = 0;\npub const OMEGA_BAD_ARG: u32 = 32;\npub const OMEGA_REENTRY: u32 = 33;\npub const OMEGA_BAD_RT: u32 = 34;\npub const OMEGA_NO_STACK: u32 = 35;\n~// ~\npub extern fn omega_~(result: ?*u64~, o_~: u64~: ?[*]u64~: ?[*]const u64~: ?[*]u8~: ?[*]const u8~_len: u64~) u32;\n~// Generated by omega-bridge src/native.om: native call ABI v1 (docs/NATIVE-ABI.md).\n// cgo package omeganative: this file, omega_native.h and libomega_native.so in one folder. Regenerate it;\n// do not edit it. No run-time path is baked in: the program's build names the folder (CGO_LDFLAGS set to\n// -Wl,-rpath,<folder>), or LD_LIBRARY_PATH does.\n// Status: 0 done; 1..14 the Omega trap code; 32 argument refused (nil, wrong length, misaligned,\n// overlap); 33 reentry; 34 bad runtime entry; 35 no stack. The result is written only on status 0.\n// A long is its two's-complement bits (an int64 as uint64); an array is an unsafe.Pointer to memory\n// holding no Go pointers, then its element count.\npackage omeganative\n\n/*\n#cgo CFLAGS: -I${SRCDIR}\n#cgo LDFLAGS: -L${SRCDIR} -lomega_native\n#include \"omega_native.h\"\n*/\nimport \"C\"\n\nimport \"unsafe\"\n\nconst (\n\tOmegaOK uint32 = 0\n\tOmegaBadArg uint32 = 32\n\tOmegaReentry uint32 = 33\n\tOmegaBadRt uint32 = 34\n\tOmegaNoStack uint32 = 35\n)\n~\n// ~\nfunc Omega_~(result *uint64~, o_~ uint64~ unsafe.Pointer~ unsafe.Pointer~ unsafe.Pointer~ unsafe.Pointer~_len uint64~) uint32 {\n\treturn uint32(C.omega_~((*C.uint64_t)(unsafe.Pointer(result))~, C.uint64_t(o_~)~, o_~_len)~))\n}\n" |
| 66 | note Freestanding output accepts pure units only: no storage (global, text), host words or input. |
| 67 | note An OM-1 unit has integer scalars only (no arrays or floats). Words after # in fw are OM-2 only: |
| 68 | note views, layouts, out parameters, local arrays, part, unroll, inline, rotations and private f32/f64. |
| 69 | note Public parameters and results stay integer-only; private floats require enabled hardware FP and inherit its control state. |
| 70 | global fns ulong 1024 |
| 71 | global fne ulong 1024 |
| 72 | global fnc ulong 1 |
| 73 | global fo2 ulong 1 |
| 74 | text fw "|note|fn|to|ret|if|else|end|for|while|bound|break|continue|trap|requires|ensures|invariant|result|const|bool|uchar|ushort|uint|ulong|byte|short|int|long|true|false|add|sub|mul|div|rem|and|or|xor|shl|shr|neg|not|eq|ne|lt|le|gt|ge|bitcast|(|)|=|void|#|om2|export|layout|field|out|at|little|big|edit|view|fresh|get|put|len|new|part|unroll|inline|rotr|rotl|*|f64|f32|" |
| 75 | text fp "/* Generated pure integer-scalar freestanding native ABI v1 binding. */\n#include <stdint.h>\n#if !defined(__ELF__)\n#error \"omega-bridge freestanding binding: ELF objects only\"\n#endif\n#define OMBR_SYM(n) #n\n#define OMBR_LOCAL(n) \".local \" #n \"\\n\"\n#define OMBR_HIDDEN(n) \".hidden \" #n \"\\n\"\n#define OMBR_CODE_SECTION \".section .text.omega_bridge,\\\"ax\\\",@progbits\\n\"\n#define OMBR_PREVIOUS \".previous\\n\"\n#define OMEGA_OK 0u\n#define OMEGA_BAD_ARG 32u\n#define OMEGA_BAD_RT 34u\ntypedef struct ombr_rt { const void *entry[32]; } ombr_rt;\nuint32_t ombr_enter(const void *code, const uint64_t *args, const ombr_rt *rt, uint64_t *out, void *top)\n __attribute__((visibility(\"hidden\")));\nextern const unsigned char ombr_trap[] __attribute__((visibility(\"hidden\")));\nextern const unsigned char ombr_no_entry[] __attribute__((visibility(\"hidden\")));\n/* ombr_enter saves the callee-saved registers on the caller's stack, keeps that stack pointer in x19 and\n * runs the pure scalar code on the caller's stack. A normal return stores x0 through out and\n * returns 0. A runtime entry restores the stack pointer from x19 and returns a status; out is not\n * written. A unit's code must not write x18, x19 or x29 and must keep sp balanced; it may write\n * x0..x17, x20..x28 and v0..v31 (x20..x28 and d8..d15 are restored here). Runtime entries are reached by blr/br, so they\n * start with bti jc. */\n__asm__(\".text\\n.balign 4\\n.local ombr_enter\\n.hidden ombr_enter\\n.type ombr_enter,%function\\nombr_enter:\\n\"\n \"hint #34\\nstp x29,x30,[sp,#-176]!\\nmov x29,sp\\nstp x19,x20,[sp,#16]\\nstp x21,x22,[sp,#32]\\n\"\n \"stp x23,x24,[sp,#48]\\nstp x25,x26,[sp,#64]\\nstp x27,x28,[sp,#80]\\nstp d8,d9,[sp,#96]\\n\"\n \"stp d10,d11,[sp,#112]\\nstp d12,d13,[sp,#128]\\nstp d14,d15,[sp,#144]\\nstr x3,[sp,#160]\\n\"\n \"mov x19,sp\\nmov x16,x0\\nmov x17,x1\\nmov x7,x2\\n\"\n \"ldp x0,x1,[x17]\\nldp x2,x3,[x17,#16]\\nldp x4,x5,[x17,#32]\\nblr x16\\n\"\n \"mov sp,x19\\nldr x9,[sp,#160]\\nstr x0,[x9]\\nmov w0,#0\\n\"\n \"ombr_leave:\\nldp d14,d15,[sp,#144]\\nldp d12,d13,[sp,#128]\\nldp d10,d11,[sp,#112]\\n\"\n \"ldp d8,d9,[sp,#96]\\nldp x27,x28,[sp,#80]\\nldp x25,x26,[sp,#64]\\nldp x23,x24,[sp,#48]\\n\"\n \"ldp x21,x22,[sp,#32]\\nldp x19,x20,[sp,#16]\\nldp x29,x30,[sp],#176\\nret\\n.size ombr_enter,.-ombr_enter\\n\"\n \".local ombr_trap\\n.hidden ombr_trap\\n.type ombr_trap,%function\\nombr_trap:\\nhint #38\\n\"\n \"mov sp,x19\\nsub x2,x1,#1\\nmov w3,#34\\ncmp x2,#13\\ncsel w0,w1,w3,ls\\nb ombr_leave\\n\"\n \".size ombr_trap,.-ombr_trap\\n\"\n \".local ombr_no_entry\\n.hidden ombr_no_entry\\n.type ombr_no_entry,%function\\nombr_no_entry:\\nhint #38\\n\"\n \"mov sp,x19\\nmov w0,#34\\nb ombr_leave\\n.size ombr_no_entry,.-ombr_no_entry\\n\");\nstatic const ombr_rt ombr_rt_table = {{ ombr_no_entry, ombr_no_entry, ombr_trap, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry, ombr_no_entry }};\nstatic uint32_t ombr_run(const void *code, const uint64_t *args, uint64_t *result, int has_value)\n{\n uint64_t v = 0;\n uint32_t status = ombr_enter(code, args, &ombr_rt_table, &v, 0);\n if (status == OMEGA_OK)\n *result = has_value ? v : 0u;\n return status;\n}\n" |
| 76 | text fb ")\n{\n uint64_t a[6] = {0};\n if (!result || (uintptr_t)result % 8u != 0u || (uintptr_t)result > UINTPTR_MAX - 8u)\n return OMEGA_BAD_ARG;\n~ return ombr_run(ombr_entry_" |
| 77 | fn fword k ulong to ulong |
| 78 | i = ulong 0 |
| 79 | while lt add i 1 len fw |
| 80 | if eq get fw i 124 |
| 81 | if and eq get fw add i 1 35 eq get fo2 0 0 |
| 82 | ret 0 |
| 83 | end |
| 84 | j = add i 1 |
| 85 | while and lt j len fw ne get fw j 124 |
| 86 | j = add j 1 |
| 87 | end |
| 88 | if eq fis k add i 1 sub j add i 1 1 |
| 89 | ret 1 |
| 90 | end |
| 91 | i = j |
| 92 | else |
| 93 | i = add i 1 |
| 94 | end |
| 95 | end |
| 96 | ret 0 |
| 97 | end |
| 98 | fn fmatch k ulong s ulong e ulong to ulong |
| 99 | ret samenm get tks k get tke k s e |
| 100 | end |
| 101 | fn fadd k ulong to void |
| 102 | n = get fnc 0 |
| 103 | for j ulong n |
| 104 | if eq fmatch k get fns j get fne j 1 |
| 105 | ret |
| 106 | end |
| 107 | end |
| 108 | if ge n len fns |
| 109 | trap 10 |
| 110 | end |
| 111 | put fns n get tks k |
| 112 | put fne n get tke k |
| 113 | put fnc 0 add n 1 |
| 114 | end |
| 115 | fn fis k ulong off ulong n ulong to ulong |
| 116 | s = get tks k |
| 117 | e = get tke k |
| 118 | if ne sub e s n |
| 119 | ret 0 |
| 120 | end |
| 121 | for j ulong n |
| 122 | if ne get inb add s j get fw add off j |
| 123 | ret 0 |
| 124 | end |
| 125 | end |
| 126 | ret 1 |
| 127 | end |
| 128 | fn fnum k ulong to ulong |
| 129 | s = get tks k |
| 130 | e = get tke k |
| 131 | if ge s e |
| 132 | ret 0 |
| 133 | end |
| 134 | if eq get inb s 45 |
| 135 | s = add s 1 |
| 136 | else |
| 137 | if and eq get fo2 0 1 gt sub e s 2 |
| 138 | if and eq get inb s 48 eq get inb add s 1 120 |
| 139 | for j ulong sub e add s 2 |
| 140 | b = get inb add add s 2 j |
| 141 | if and or lt b 48 gt b 57 or lt b 97 gt b 102 |
| 142 | ret 0 |
| 143 | end |
| 144 | end |
| 145 | ret 1 |
| 146 | end |
| 147 | end |
| 148 | end |
| 149 | a = s |
| 150 | while lt s e |
| 151 | b = get inb s |
| 152 | if or lt b 48 gt b 57 |
| 153 | break |
| 154 | end |
| 155 | s = add s 1 |
| 156 | end |
| 157 | if eq s a |
| 158 | ret 0 |
| 159 | end |
| 160 | if eq get fo2 0 0 |
| 161 | if eq s e |
| 162 | ret 1 |
| 163 | end |
| 164 | ret 0 |
| 165 | end |
| 166 | if lt s e |
| 167 | if eq get inb s 46 |
| 168 | s = add s 1 |
| 169 | a = s |
| 170 | while lt s e |
| 171 | b = get inb s |
| 172 | if or lt b 48 gt b 57 |
| 173 | break |
| 174 | end |
| 175 | s = add s 1 |
| 176 | end |
| 177 | if eq s a |
| 178 | ret 0 |
| 179 | end |
| 180 | end |
| 181 | end |
| 182 | if lt s e |
| 183 | if or eq get inb s 101 eq get inb s 69 |
| 184 | s = add s 1 |
| 185 | if lt s e |
| 186 | if or eq get inb s 43 eq get inb s 45 |
| 187 | s = add s 1 |
| 188 | end |
| 189 | end |
| 190 | a = s |
| 191 | while lt s e |
| 192 | b = get inb s |
| 193 | if or lt b 48 gt b 57 |
| 194 | break |
| 195 | end |
| 196 | s = add s 1 |
| 197 | end |
| 198 | if eq s a |
| 199 | ret 0 |
| 200 | end |
| 201 | end |
| 202 | end |
| 203 | if lt s e |
| 204 | if ne sub e s 3 |
| 205 | ret 0 |
| 206 | end |
| 207 | if ne get inb s 102 |
| 208 | ret 0 |
| 209 | end |
| 210 | b = get inb add s 1 |
| 211 | if eq b 54 |
| 212 | if ne get inb add s 2 52 |
| 213 | ret 0 |
| 214 | end |
| 215 | else |
| 216 | if ne b 51 |
| 217 | ret 0 |
| 218 | end |
| 219 | if ne get inb add s 2 50 |
| 220 | ret 0 |
| 221 | end |
| 222 | end |
| 223 | s = add s 3 |
| 224 | end |
| 225 | if eq s e |
| 226 | ret 1 |
| 227 | end |
| 228 | ret 0 |
| 229 | end |
| 230 | fn fknown k ulong to ulong |
| 231 | if eq fword k 1 |
| 232 | ret 1 |
| 233 | end |
| 234 | if eq fnum k 1 |
| 235 | ret 1 |
| 236 | end |
| 237 | for j ulong get fnc 0 |
| 238 | if eq fmatch k get fns j get fne j 1 |
| 239 | ret 1 |
| 240 | end |
| 241 | end |
| 242 | ret 0 |
| 243 | end |
| 244 | note fextent recognizes a literal, *, or an earlier positive ulong constant without registering |
| 245 | note an arbitrary identifier as a parameter name. cline is shared with public extent resolution. |
| 246 | fn fextent k ulong p ulong q ulong to ulong |
| 247 | if or eq fnum k 1 eq tvis k 83 1 1 |
| 248 | ret 1 |
| 249 | end |
| 250 | i = p |
| 251 | while lt i q |
| 252 | if gt cline i q get tks k get tke k 0 |
| 253 | ret 1 |
| 254 | end |
| 255 | while and lt i q ne get inb i 10 |
| 256 | i = add i 1 |
| 257 | end |
| 258 | i = add i 1 |
| 259 | end |
| 260 | ret 0 |
| 261 | end |
| 262 | note fdecl2 registers only function/parameter names, not signature types. Treating every unknown |
| 263 | note signature token as a name would admit an unsupported private type such as f128. |
| 264 | note A layout/field line declares its second token. fw offsets: export 254, layout 261, field 268. |
| 265 | fn fdecl2 nt ulong p ulong q ulong to void |
| 266 | b = ulong 0 |
| 267 | if eq fis 0 254 6 1 |
| 268 | b = 1 |
| 269 | end |
| 270 | if and gt nt b eq fis b 6 2 1 |
| 271 | if ge add b 1 nt |
| 272 | trap 10 |
| 273 | end |
| 274 | fadd add b 1 |
| 275 | k = add b 2 |
| 276 | while lt k nt |
| 277 | if eq fis k 9 2 1 |
| 278 | break |
| 279 | end |
| 280 | if ge add k 1 nt |
| 281 | trap 10 |
| 282 | end |
| 283 | fadd k |
| 284 | ty = add k 1 |
| 285 | if or or eq tkis ty 2 4 1 eq tkis ty 6 4 1 eq tvis ty 8 3 1 |
| 286 | if ge add k 2 nt |
| 287 | trap 10 |
| 288 | end |
| 289 | k = add k 3 |
| 290 | if lt k nt |
| 291 | if eq fextent k p q 1 |
| 292 | k = add k 1 |
| 293 | end |
| 294 | end |
| 295 | if lt k nt |
| 296 | if eq fis k 302 5 1 |
| 297 | if or or ne tkis ty 2 4 1 eq fextent sub k 1 p q 0 eq tvis sub k 1 83 1 1 |
| 298 | trap 10 |
| 299 | end |
| 300 | k = add k 1 |
| 301 | end |
| 302 | end |
| 303 | else |
| 304 | k = add k 2 |
| 305 | end |
| 306 | end |
| 307 | end |
| 308 | if and ge nt 2 or eq fis 0 261 6 1 eq fis 0 268 5 1 |
| 309 | fadd 1 |
| 310 | end |
| 311 | end |
| 312 | fn fcheck p ulong q ulong to void |
| 313 | put fnc 0 0 |
| 314 | for pass ulong 2 |
| 315 | i = p |
| 316 | while lt i q |
| 317 | nt = tokln i q |
| 318 | next = add get st 7 1 |
| 319 | if gt nt 0 |
| 320 | if eq fis 0 1 4 0 |
| 321 | if eq pass 0 |
| 322 | if eq get fo2 0 1 |
| 323 | fdecl2 nt p i |
| 324 | else |
| 325 | if eq fis 0 6 2 1 |
| 326 | if lt nt 4 |
| 327 | trap 10 |
| 328 | end |
| 329 | fadd 1 |
| 330 | k = ulong 2 |
| 331 | while lt add k 1 nt |
| 332 | if eq fis k 9 2 1 |
| 333 | break |
| 334 | end |
| 335 | fadd k |
| 336 | k = add k 2 |
| 337 | end |
| 338 | end |
| 339 | end |
| 340 | if ge nt 2 |
| 341 | if or eq fis 0 28 3 1 eq fis 0 98 5 1 |
| 342 | fadd 1 |
| 343 | end |
| 344 | if eq fis 1 241 1 1 |
| 345 | fadd 0 |
| 346 | end |
| 347 | end |
| 348 | else |
| 349 | for k ulong nt |
| 350 | if eq fknown k 0 |
| 351 | trap 10 |
| 352 | end |
| 353 | end |
| 354 | end |
| 355 | end |
| 356 | end |
| 357 | i = next |
| 358 | end |
| 359 | end |
| 360 | end |
| 361 | note fpre: the fixed freestanding runtime; for x86linux only its assembly block becomes xfasm. |
| 362 | fn fpre to void |
| 363 | i = ulong 0 |
| 364 | while lt i len fp |
| 365 | if and eq get xt 0 1 fxbegin i |
| 366 | for j ulong len xfasm |
| 367 | ob get xfasm j |
| 368 | end |
| 369 | while not fxend i |
| 370 | i = add i 1 |
| 371 | if ge i len fp |
| 372 | trap 10 |
| 373 | end |
| 374 | end |
| 375 | end |
| 376 | ob get fp i |
| 377 | i = add i 1 |
| 378 | end |
| 379 | end |
| 380 | fn fbody to void |
| 381 | for i ulong len fb |
| 382 | if eq get fb i 126 |
| 383 | break |
| 384 | end |
| 385 | ob get fb i |
| 386 | end |
| 387 | for j ulong get st 2 |
| 388 | if gt get pk j 2 |
| 389 | trap 10 |
| 390 | end |
| 391 | ofr 19 |
| 392 | odec j |
| 393 | ofr 20 |
| 394 | opn j |
| 395 | ofr 18 |
| 396 | end |
| 397 | skip = ulong 1 |
| 398 | for i ulong len fb |
| 399 | if eq skip 0 |
| 400 | ob get fb i |
| 401 | end |
| 402 | if eq get fb i 126 |
| 403 | skip = 0 |
| 404 | end |
| 405 | end |
| 406 | oname 1 |
| 407 | ofr 22 |
| 408 | odec get st 3 |
| 409 | ofr 23 |
| 410 | end |
| 411 | note ob: append one byte to the output pools, outb then outc (trap 6 when both are full). |
| 412 | fn ob b uchar to void |
| 413 | n = get st 1 |
| 414 | if lt n len outb |
| 415 | put outb n b |
| 416 | else |
| 417 | k = sub n len outb |
| 418 | if ge k len outc |
| 419 | trap 6 |
| 420 | end |
| 421 | put outc k b |
| 422 | end |
| 423 | put st 1 add n 1 |
| 424 | end |
| 425 | note orng: copy input bytes s .. e-1 to the output. |
| 426 | fn orng s ulong e ulong to void |
| 427 | i = s |
| 428 | while lt i e |
| 429 | ob get inb i |
| 430 | i = add i 1 |
| 431 | end |
| 432 | end |
| 433 | note odec: v in decimal. |
| 434 | fn odec v ulong to void |
| 435 | x = v |
| 436 | n = ulong 0 |
| 437 | put dg n uchar add rem x 10 48 |
| 438 | n = add n 1 |
| 439 | x = div x 10 |
| 440 | while ne x 0 |
| 441 | put dg n uchar add rem x 10 48 |
| 442 | n = add n 1 |
| 443 | x = div x 10 |
| 444 | end |
| 445 | while gt n 0 |
| 446 | n = sub n 1 |
| 447 | ob get dg n |
| 448 | end |
| 449 | end |
| 450 | note ohex: one byte as 0xNN. |
| 451 | fn ohex b uchar to void |
| 452 | ob uchar 48 |
| 453 | ob uchar 120 |
| 454 | ob get hx shr b 4 |
| 455 | ob get hx and b 15 |
| 456 | end |
| 457 | fn plen to ulong |
| 458 | if eq get mdev 0 1 |
| 459 | ret len predev |
| 460 | end |
| 461 | ret len pre |
| 462 | end |
| 463 | fn pbyte i ulong to uchar |
| 464 | if eq get mdev 0 1 |
| 465 | ret get predev i |
| 466 | end |
| 467 | ret get pre i |
| 468 | end |
| 469 | note Match only the assembly boundary markers, leaving the shared C runtime byte-identical. |
| 470 | fn xbegin i ulong to bool |
| 471 | if gt add i len xs plen |
| 472 | ret false |
| 473 | end |
| 474 | for j ulong len xs |
| 475 | if ne pbyte add i j get xs j |
| 476 | ret false |
| 477 | end |
| 478 | end |
| 479 | ret true |
| 480 | end |
| 481 | fn xend i ulong to bool |
| 482 | if gt add i len xe plen |
| 483 | ret false |
| 484 | end |
| 485 | for j ulong len xe |
| 486 | if ne pbyte add i j get xe j |
| 487 | ret false |
| 488 | end |
| 489 | end |
| 490 | ret true |
| 491 | end |
| 492 | note The same marker match for the freestanding runtime fp. |
| 493 | fn fxbegin i ulong to bool |
| 494 | if gt add i len fxs len fp |
| 495 | ret false |
| 496 | end |
| 497 | for j ulong len fxs |
| 498 | if ne get fp add i j get fxs j |
| 499 | ret false |
| 500 | end |
| 501 | end |
| 502 | ret true |
| 503 | end |
| 504 | fn fxend i ulong to bool |
| 505 | if gt add i len fxe len fp |
| 506 | ret false |
| 507 | end |
| 508 | for j ulong len fxe |
| 509 | if ne get fp add i j get fxe j |
| 510 | ret false |
| 511 | end |
| 512 | end |
| 513 | ret true |
| 514 | end |
| 515 | note opre: the fixed runtime part of the C file. |
| 516 | fn opre to void |
| 517 | i = ulong 0 |
| 518 | while lt i plen |
| 519 | if and eq get xt 0 1 xbegin i |
| 520 | for j ulong len xasm |
| 521 | ob get xasm j |
| 522 | end |
| 523 | while not xend i |
| 524 | i = add i 1 |
| 525 | if ge i plen |
| 526 | trap 10 |
| 527 | end |
| 528 | end |
| 529 | end |
| 530 | ob pbyte i |
| 531 | i = add i 1 |
| 532 | end |
| 533 | end |
| 534 | note xbranch: architecture-specific private entry veneer; code bytes stay unchanged. |
| 535 | fn xbranch k ulong to void |
| 536 | c = ulong 0 |
| 537 | for i ulong len xjmp |
| 538 | b = get xjmp i |
| 539 | if eq b 126 |
| 540 | c = add c 1 |
| 541 | else |
| 542 | if eq c k |
| 543 | ob b |
| 544 | end |
| 545 | end |
| 546 | end |
| 547 | end |
| 548 | note ofr: fragment k of fr (fragments are separated by ~, byte 126). |
| 549 | fn ofr k ulong to void |
| 550 | if and eq get xt 0 1 eq k 27 |
| 551 | xbranch 0 |
| 552 | ret |
| 553 | end |
| 554 | c = ulong 0 |
| 555 | for i ulong len fr |
| 556 | b = get fr i |
| 557 | if eq b 126 |
| 558 | c = add c 1 |
| 559 | else |
| 560 | if eq c k |
| 561 | ob b |
| 562 | end |
| 563 | end |
| 564 | end |
| 565 | end |
| 566 | note ofb: fragment k of tb. |
| 567 | fn ofb k ulong to void |
| 568 | c = ulong 0 |
| 569 | for i ulong len tb |
| 570 | b = get tb i |
| 571 | if eq b 126 |
| 572 | c = add c 1 |
| 573 | else |
| 574 | if eq c k |
| 575 | ob b |
| 576 | end |
| 577 | end |
| 578 | end |
| 579 | end |
| 580 | note mdis: 1 when the argument in md (its length in st 8) is mo[o .. o+n-1], else 0. |
| 581 | fn mdis o ulong n ulong to ulong |
| 582 | if ne get st 8 n |
| 583 | ret 0 |
| 584 | end |
| 585 | for j ulong n |
| 586 | if ne get md j get mo add o j |
| 587 | ret 0 |
| 588 | end |
| 589 | end |
| 590 | ret 1 |
| 591 | end |
| 592 | note hostarg: 1 when the second argument (z bytes, read into md) is host. |
| 593 | fn hostarg z long to ulong |
| 594 | if ne z 4 |
| 595 | ret 0 |
| 596 | end |
| 597 | for j ulong 4 |
| 598 | if ne get md j get hname j |
| 599 | ret 0 |
| 600 | end |
| 601 | end |
| 602 | ret 1 |
| 603 | end |
| 604 | note rmode: the first argument as an output number: 1 c, 2 h, 3 python, 4 rust, 5 zig, 6 go, 7 api, |
| 605 | note 8 apih, 9 apic, 10 freest, 11 ident (each OM-2 unit's identity, one line each). An optional second |
| 606 | note argument is x86linux, host, x86host, float or fhost (explicit hosted float profile, with host words). |
| 607 | fn rmode to ulong |
| 608 | if or lt argcnt 2 gt argcnt 3 |
| 609 | trap 10 |
| 610 | end |
| 611 | if eq argcnt 3 |
| 612 | z = argread 2 md 0 8 |
| 613 | flag = fltarg z |
| 614 | if ne flag 0 |
| 615 | put fok 0 1 |
| 616 | put hok 0 sub flag 1 |
| 617 | else |
| 618 | if eq hostarg z 1 |
| 619 | put hok 0 1 |
| 620 | else |
| 621 | if eq z 7 |
| 622 | for j ulong 7 |
| 623 | if ne get md j get xhname j |
| 624 | trap 10 |
| 625 | end |
| 626 | end |
| 627 | put xt 0 1 |
| 628 | put hok 0 1 |
| 629 | else |
| 630 | if ne z 8 |
| 631 | trap 10 |
| 632 | end |
| 633 | for j ulong 8 |
| 634 | if ne get md j get xtname j |
| 635 | trap 10 |
| 636 | end |
| 637 | end |
| 638 | put xt 0 1 |
| 639 | end |
| 640 | end |
| 641 | end |
| 642 | end |
| 643 | k = argread 1 md 0 8 |
| 644 | if lt k 0 |
| 645 | trap 10 |
| 646 | end |
| 647 | put st 8 ulong k |
| 648 | m = ulong 0 |
| 649 | if eq mdis 0 1 1 |
| 650 | m = 1 |
| 651 | end |
| 652 | if eq mdis 1 1 1 |
| 653 | m = 2 |
| 654 | end |
| 655 | if eq mdis 2 6 1 |
| 656 | m = 3 |
| 657 | end |
| 658 | if eq mdis 8 4 1 |
| 659 | m = 4 |
| 660 | end |
| 661 | if eq mdis 12 3 1 |
| 662 | m = 5 |
| 663 | end |
| 664 | if eq mdis 15 2 1 |
| 665 | m = 6 |
| 666 | end |
| 667 | if eq mdis 17 3 1 |
| 668 | m = 7 |
| 669 | end |
| 670 | if eq mdis 17 4 1 |
| 671 | m = 8 |
| 672 | end |
| 673 | if eq mdis 21 4 1 |
| 674 | m = 9 |
| 675 | end |
| 676 | if eq mdis 25 6 1 |
| 677 | m = 10 |
| 678 | end |
| 679 | if eq mdis 31 5 1 |
| 680 | m = 11 |
| 681 | end |
| 682 | if eq mdis 36 5 1 |
| 683 | m = 12 |
| 684 | end |
| 685 | if and eq get hok 0 1 or eq m 10 eq m 12 |
| 686 | trap 10 |
| 687 | end |
| 688 | if eq m 0 |
| 689 | trap 10 |
| 690 | end |
| 691 | ret m |
| 692 | end |
| 693 | note tkis: 1 when token k is the keyword kw[o .. o+n-1], else 0. |
| 694 | fn tkis k ulong o ulong n ulong to ulong |
| 695 | s = get tks k |
| 696 | e = get tke k |
| 697 | if ne sub e s n |
| 698 | ret 0 |
| 699 | end |
| 700 | for j ulong n |
| 701 | if ne get inb add s j get kw add o j |
| 702 | ret 0 |
| 703 | end |
| 704 | end |
| 705 | ret 1 |
| 706 | end |
| 707 | note tknum: token k as a decimal number of 1 .. 8 digits. |
| 708 | fn tknum k ulong to ulong |
| 709 | s = get tks k |
| 710 | e = get tke k |
| 711 | if or eq s e gt sub e s 8 |
| 712 | trap 10 |
| 713 | end |
| 714 | v = ulong 0 |
| 715 | for j ulong sub e s |
| 716 | c = get inb add s j |
| 717 | if or lt c 48 gt c 57 |
| 718 | trap 10 |
| 719 | end |
| 720 | v = add mul v 10 ulong sub c 48 |
| 721 | end |
| 722 | ret v |
| 723 | end |
| 724 | note tokln: split the line that starts at p (ending at a newline or at q) into tokens at spaces. |
| 725 | fn tokln p ulong q ulong to ulong |
| 726 | e = p |
| 727 | while and lt e q ne get inb e 10 |
| 728 | e = add e 1 |
| 729 | end |
| 730 | put st 7 e |
| 731 | n = ulong 0 |
| 732 | s = p |
| 733 | i = p |
| 734 | while lt i e |
| 735 | if eq get inb i 32 |
| 736 | if gt i s |
| 737 | put tks n s |
| 738 | put tke n i |
| 739 | n = add n 1 |
| 740 | end |
| 741 | s = add i 1 |
| 742 | end |
| 743 | i = add i 1 |
| 744 | end |
| 745 | if gt e s |
| 746 | put tks n s |
| 747 | put tke n e |
| 748 | n = add n 1 |
| 749 | end |
| 750 | ret n |
| 751 | end |
| 752 | note oname: the name of token k. |
| 753 | fn oname k ulong to void |
| 754 | orng get tks k get tke k |
| 755 | end |
| 756 | note opn: the name of parameter j. |
| 757 | fn opn j ulong to void |
| 758 | orng get ps j get pe j |
| 759 | end |
| 760 | note osig: the unit's signature line (st 6 .. st 7), the comment each binding carries. |
| 761 | fn osig to void |
| 762 | orng get st 6 get st 7 |
| 763 | end |
| 764 | note sepat: where the 0 byte after the source starting at p is. |
| 765 | fn sepat p ulong to ulong |
| 766 | t = get st 0 |
| 767 | q = p |
| 768 | while and lt q t ne get inb q 0 |
| 769 | q = add q 1 |
| 770 | end |
| 771 | if ge q t |
| 772 | trap 10 |
| 773 | end |
| 774 | ret q |
| 775 | end |
| 776 | note isfn: 1 when the bytes at i are "fn ". |
| 777 | fn isfn i ulong to ulong |
| 778 | if ne get inb i 102 |
| 779 | ret 0 |
| 780 | end |
| 781 | if ne get inb add i 1 110 |
| 782 | ret 0 |
| 783 | end |
| 784 | if ne get inb add i 2 32 |
| 785 | ret 0 |
| 786 | end |
| 787 | ret 1 |
| 788 | end |
| 789 | note sigln: the start of the last line in p .. q-1 that begins with "fn " (the compiler's entry). |
| 790 | fn sigln p ulong q ulong to ulong |
| 791 | fl = ulong 0 |
| 792 | nf = ulong 0 |
| 793 | ls = p |
| 794 | i = p |
| 795 | while lt i q |
| 796 | if eq i ls |
| 797 | if eq isfn i 1 |
| 798 | fl = i |
| 799 | nf = add nf 1 |
| 800 | end |
| 801 | end |
| 802 | if eq get inb i 10 |
| 803 | ls = add i 1 |
| 804 | end |
| 805 | i = add i 1 |
| 806 | end |
| 807 | if eq nf 0 |
| 808 | trap 10 |
| 809 | end |
| 810 | ret fl |
| 811 | end |
| 812 | note pkind: the kind of the parameter whose type starts at token ty: 1 ulong, 2 long, 3 edit ulong, |
| 813 | note 4 view ulong, 5 edit uchar, 6 view uchar, 7 edit f32, 8 view f32, 9 edit ushort, 10 view ushort; |
| 814 | note 0 when refused. Odd array kinds are writable. |
| 815 | fn pkind ty ulong nt ulong to ulong |
| 816 | if eq tkis ty 32 3 1 |
| 817 | ret 11 |
| 818 | end |
| 819 | if eq tkis ty 46 3 1 |
| 820 | ret 12 |
| 821 | end |
| 822 | if eq tkis ty 10 5 1 |
| 823 | ret 1 |
| 824 | end |
| 825 | if eq tkis ty 15 4 1 |
| 826 | ret 2 |
| 827 | end |
| 828 | w = ulong 0 |
| 829 | if eq tkis ty 6 4 1 |
| 830 | w = 1 |
| 831 | else |
| 832 | if ne tkis ty 2 4 1 |
| 833 | ret 0 |
| 834 | end |
| 835 | end |
| 836 | if ge add ty 2 nt |
| 837 | ret 0 |
| 838 | end |
| 839 | el = add ty 1 |
| 840 | if eq tkis el 10 5 1 |
| 841 | ret add 3 w |
| 842 | end |
| 843 | if eq tkis el 19 5 1 |
| 844 | ret add 5 w |
| 845 | end |
| 846 | if eq tkis el 32 3 1 |
| 847 | ret add 7 w |
| 848 | end |
| 849 | if eq tkis el 35 6 1 |
| 850 | ret add 9 w |
| 851 | end |
| 852 | ret 0 |
| 853 | end |
| 854 | note Typed float scalars marshal by bit-copy in each ABI-v1 language binding. |
| 855 | global fret ulong 1 |
| 856 | text flopt "floatfhost" |
| 857 | fn fltarg z long to ulong |
| 858 | if ne z 5 |
| 859 | ret 0 |
| 860 | end |
| 861 | for i ulong 2 |
| 862 | same = true |
| 863 | for j ulong 5 |
| 864 | if ne get md j get flopt add mul i 5 j |
| 865 | same = false |
| 866 | end |
| 867 | end |
| 868 | if same |
| 869 | ret add i 1 |
| 870 | end |
| 871 | end |
| 872 | ret 0 |
| 873 | end |
| 874 | text nflo "float~double~uint64_t~uint32_t omega_~ *result~, ~ *~);\n~)\n{\n ombr_span sp[7] = {{0}}; unsigned ns=0; uint64_t a[6]={0}, r=0;\n if(ombr_span_add(sp,&ns,result,1,1,~u,1))return OMEGA_BAD_ARG;\n~ memcpy(&a[~], &o_~, ~);\n~ if(ombr_overlap(sp,ns))return OMEGA_BAD_ARG;\n uint32_t status=ombr_run(ombr_entry_~,a,&r,~);\n if(!status)memcpy(result,&r,~);\n return status;\n}\n~#include <string.h>\n~ o_~const void *o_~void *o_~[] __attribute__((visibility(\"hidden\")));\n~/* Omega: ~ */\n" |
| 875 | fn oflo k ulong to void |
| 876 | c = ulong 0 |
| 877 | for i ulong len nflo |
| 878 | b = get nflo i |
| 879 | if eq b 126 |
| 880 | c = add c 1 |
| 881 | else |
| 882 | if eq c k |
| 883 | ob b |
| 884 | end |
| 885 | end |
| 886 | end |
| 887 | end |
| 888 | fn fscalar k ulong to bool |
| 889 | ret or le k 2 and ge k 11 le k 12 |
| 890 | end |
| 891 | fn hasfloat to bool |
| 892 | if ne get fret 0 0 |
| 893 | ret true |
| 894 | end |
| 895 | for j ulong get st 2 |
| 896 | if and ge get pk j 11 le get pk j 12 |
| 897 | ret true |
| 898 | end |
| 899 | end |
| 900 | ret false |
| 901 | end |
| 902 | fn nftype k ulong to void |
| 903 | if eq k 11 |
| 904 | oflo 0 |
| 905 | else |
| 906 | if eq k 12 |
| 907 | oflo 1 |
| 908 | else |
| 909 | oflo 2 |
| 910 | end |
| 911 | end |
| 912 | end |
| 913 | fn nfsize k ulong to ulong |
| 914 | if eq k 11 |
| 915 | ret 4 |
| 916 | end |
| 917 | ret 8 |
| 918 | end |
| 919 | fn nfsig to void |
| 920 | oflo 3 |
| 921 | oname 1 |
| 922 | ob uchar 40 |
| 923 | nftype get fret 0 |
| 924 | oflo 4 |
| 925 | for j ulong get st 2 |
| 926 | oflo 5 |
| 927 | x = get pk j |
| 928 | if fscalar x |
| 929 | nftype x |
| 930 | oflo 19 |
| 931 | opn j |
| 932 | else |
| 933 | if eq rem x 2 0 |
| 934 | oflo 20 |
| 935 | else |
| 936 | oflo 21 |
| 937 | end |
| 938 | opn j |
| 939 | ofr 7 |
| 940 | opn j |
| 941 | ofr 10 |
| 942 | end |
| 943 | end |
| 944 | end |
| 945 | fn nfloat to void |
| 946 | m = get st 5 |
| 947 | if eq m 3 |
| 948 | nfpy |
| 949 | ret |
| 950 | end |
| 951 | if or eq m 4 eq m 5 |
| 952 | nfdecl m |
| 953 | ret |
| 954 | end |
| 955 | if eq m 6 |
| 956 | nfgo |
| 957 | ret |
| 958 | end |
| 959 | if and ne m 1 ne m 2 |
| 960 | trap 10 |
| 961 | end |
| 962 | if eq m 1 |
| 963 | oflo 18 |
| 964 | end |
| 965 | oflo 23 |
| 966 | osig |
| 967 | oflo 24 |
| 968 | nfsig |
| 969 | if eq m 2 |
| 970 | oflo 7 |
| 971 | ret |
| 972 | end |
| 973 | oflo 8 |
| 974 | odec nfsize get fret 0 |
| 975 | oflo 9 |
| 976 | for j ulong get st 2 |
| 977 | x = get pk j |
| 978 | if fscalar x |
| 979 | if le x 2 |
| 980 | ofr 19 |
| 981 | odec j |
| 982 | ofr 20 |
| 983 | opn j |
| 984 | ofr 18 |
| 985 | else |
| 986 | oflo 10 |
| 987 | odec j |
| 988 | oflo 11 |
| 989 | opn j |
| 990 | oflo 12 |
| 991 | odec nfsize x |
| 992 | oflo 13 |
| 993 | end |
| 994 | else |
| 995 | earr j x |
| 996 | end |
| 997 | end |
| 998 | oflo 14 |
| 999 | oname 1 |
| 1000 | oflo 15 |
| 1001 | odec get st 3 |
| 1002 | oflo 16 |
| 1003 | odec nfsize get fret 0 |
| 1004 | oflo 17 |
| 1005 | end |
| 1006 | text nbind ".argtypes = [ctypes.POINTER(~)~, ~_u64~_a~(result: *mut ~(result: ?*~, o_~: ~: *mut ~: *const ~: ?[*]~: ?[*]const ~_len: u64~(result *~ ~ unsafe.Pointer~_len uint64~) uint32 {\n\treturn uint32(C.omega_~((*C.~)(unsafe.Pointer(result))~, C.~(o_~)~, o_~_len)~))\n}\n" |
| 1007 | text nftypes "float~double~uint64_t~ctypes.c_float~ctypes.c_double~ctypes.c_uint64~f32~f64~u64~f32~f64~u64~float32~float64~uint64~float~double~uint64_t" |
| 1008 | fn onbind k ulong to void |
| 1009 | c = ulong 0 |
| 1010 | for i ulong len nbind |
| 1011 | b = get nbind i |
| 1012 | if eq b 126 |
| 1013 | c = add c 1 |
| 1014 | else |
| 1015 | if eq c k |
| 1016 | ob b |
| 1017 | end |
| 1018 | end |
| 1019 | end |
| 1020 | end |
| 1021 | fn ntype k ulong base ulong to void |
| 1022 | n = add base 2 |
| 1023 | if eq k 11 |
| 1024 | n = base |
| 1025 | end |
| 1026 | if eq k 12 |
| 1027 | n = add base 1 |
| 1028 | end |
| 1029 | c = ulong 0 |
| 1030 | for i ulong len nftypes |
| 1031 | b = get nftypes i |
| 1032 | if eq b 126 |
| 1033 | c = add c 1 |
| 1034 | else |
| 1035 | if eq c n |
| 1036 | ob b |
| 1037 | end |
| 1038 | end |
| 1039 | end |
| 1040 | end |
| 1041 | fn nfpy to void |
| 1042 | ofb 13 |
| 1043 | osig |
| 1044 | ofb 14 |
| 1045 | oname 1 |
| 1046 | ofb 15 |
| 1047 | oname 1 |
| 1048 | ofb 16 |
| 1049 | oname 1 |
| 1050 | onbind 0 |
| 1051 | ntype get fret 0 3 |
| 1052 | onbind 1 |
| 1053 | for j ulong get st 2 |
| 1054 | onbind 2 |
| 1055 | x = get pk j |
| 1056 | if fscalar x |
| 1057 | if le x 2 |
| 1058 | onbind 3 |
| 1059 | else |
| 1060 | ntype x 3 |
| 1061 | end |
| 1062 | else |
| 1063 | onbind 4 |
| 1064 | odec x |
| 1065 | onbind 2 |
| 1066 | onbind 3 |
| 1067 | end |
| 1068 | end |
| 1069 | ofb 20 |
| 1070 | oname 1 |
| 1071 | ofb 21 |
| 1072 | end |
| 1073 | fn nfdecl m ulong to void |
| 1074 | if eq m 4 |
| 1075 | ofb 23 |
| 1076 | osig |
| 1077 | ofb 24 |
| 1078 | else |
| 1079 | ofb 36 |
| 1080 | osig |
| 1081 | ofb 37 |
| 1082 | end |
| 1083 | oname 1 |
| 1084 | if eq m 4 |
| 1085 | onbind 5 |
| 1086 | else |
| 1087 | onbind 6 |
| 1088 | end |
| 1089 | ntype get fret 0 6 |
| 1090 | for j ulong get st 2 |
| 1091 | onbind 7 |
| 1092 | opn j |
| 1093 | x = get pk j |
| 1094 | if fscalar x |
| 1095 | onbind 8 |
| 1096 | ntype x 6 |
| 1097 | else |
| 1098 | if eq m 4 |
| 1099 | if eq rem x 2 1 |
| 1100 | onbind 9 |
| 1101 | else |
| 1102 | onbind 10 |
| 1103 | end |
| 1104 | else |
| 1105 | if eq rem x 2 1 |
| 1106 | onbind 11 |
| 1107 | else |
| 1108 | onbind 12 |
| 1109 | end |
| 1110 | end |
| 1111 | if le x 4 |
| 1112 | ntype 1 6 |
| 1113 | else |
| 1114 | ob uchar 117 |
| 1115 | ob uchar 56 |
| 1116 | end |
| 1117 | onbind 7 |
| 1118 | opn j |
| 1119 | onbind 13 |
| 1120 | end |
| 1121 | end |
| 1122 | if eq m 4 |
| 1123 | ofb 33 |
| 1124 | else |
| 1125 | ofb 46 |
| 1126 | end |
| 1127 | end |
| 1128 | fn nfgo to void |
| 1129 | ofb 48 |
| 1130 | osig |
| 1131 | ofb 49 |
| 1132 | oname 1 |
| 1133 | onbind 14 |
| 1134 | ntype get fret 0 12 |
| 1135 | for j ulong get st 2 |
| 1136 | onbind 7 |
| 1137 | opn j |
| 1138 | x = get pk j |
| 1139 | if fscalar x |
| 1140 | onbind 15 |
| 1141 | ntype x 12 |
| 1142 | else |
| 1143 | onbind 16 |
| 1144 | onbind 7 |
| 1145 | opn j |
| 1146 | onbind 17 |
| 1147 | end |
| 1148 | end |
| 1149 | onbind 18 |
| 1150 | oname 1 |
| 1151 | onbind 19 |
| 1152 | ntype get fret 0 15 |
| 1153 | onbind 20 |
| 1154 | for j ulong get st 2 |
| 1155 | x = get pk j |
| 1156 | if fscalar x |
| 1157 | onbind 21 |
| 1158 | ntype x 15 |
| 1159 | onbind 22 |
| 1160 | opn j |
| 1161 | onbind 23 |
| 1162 | else |
| 1163 | onbind 24 |
| 1164 | opn j |
| 1165 | onbind 21 |
| 1166 | ntype 1 15 |
| 1167 | onbind 22 |
| 1168 | opn j |
| 1169 | onbind 25 |
| 1170 | end |
| 1171 | end |
| 1172 | onbind 26 |
| 1173 | end |
| 1174 | |
| 1175 | |
| 1176 | note cidr: 1 when bytes s .. e-1 form a C identifier ([A-Za-z_][A-Za-z0-9_]*), else 0. |
| 1177 | fn cidr s ulong e ulong to ulong |
| 1178 | if ge s e |
| 1179 | ret 0 |
| 1180 | end |
| 1181 | for j ulong sub e s |
| 1182 | c = get inb add s j |
| 1183 | ok = ulong 0 |
| 1184 | if eq c 95 |
| 1185 | ok = 1 |
| 1186 | end |
| 1187 | if and ge c 97 le c 122 |
| 1188 | ok = 1 |
| 1189 | end |
| 1190 | if and ge c 65 le c 90 |
| 1191 | ok = 1 |
| 1192 | end |
| 1193 | if and gt j 0 and ge c 48 le c 57 |
| 1194 | ok = 1 |
| 1195 | end |
| 1196 | if eq ok 0 |
| 1197 | ret 0 |
| 1198 | end |
| 1199 | end |
| 1200 | ret 1 |
| 1201 | end |
| 1202 | note lensuf: 1 when bytes s .. e-1 end in "_len" (the binding names an array length o_<name>_len). |
| 1203 | fn lensuf s ulong e ulong to ulong |
| 1204 | if lt sub e s 4 |
| 1205 | ret 0 |
| 1206 | end |
| 1207 | b = sub e 4 |
| 1208 | if ne get inb b 95 |
| 1209 | ret 0 |
| 1210 | end |
| 1211 | if ne get inb add b 1 108 |
| 1212 | ret 0 |
| 1213 | end |
| 1214 | if ne get inb add b 2 101 |
| 1215 | ret 0 |
| 1216 | end |
| 1217 | if ne get inb add b 3 110 |
| 1218 | ret 0 |
| 1219 | end |
| 1220 | ret 1 |
| 1221 | end |
| 1222 | note pname: refuse a parameter name that is not a C identifier or ends in "_len". |
| 1223 | fn pname s ulong e ulong to void |
| 1224 | if eq cidr s e 0 |
| 1225 | trap 10 |
| 1226 | end |
| 1227 | if eq lensuf s e 1 |
| 1228 | trap 10 |
| 1229 | end |
| 1230 | end |
| 1231 | note samenm: 1 when bytes a .. b-1 equal bytes c .. d-1. |
| 1232 | fn samenm a ulong b ulong c ulong d ulong to ulong |
| 1233 | if ne sub b a sub d c |
| 1234 | ret 0 |
| 1235 | end |
| 1236 | for j ulong sub b a |
| 1237 | if ne get inb add a j get inb add c j |
| 1238 | ret 0 |
| 1239 | end |
| 1240 | end |
| 1241 | ret 1 |
| 1242 | end |
| 1243 | note isat: 1 when input bytes i .. i+n-1 lie before q and equal kw bytes o .. o+n-1, else 0. |
| 1244 | fn isat i ulong o ulong n ulong q ulong to ulong |
| 1245 | if gt add i n q |
| 1246 | ret 0 |
| 1247 | end |
| 1248 | for j ulong n |
| 1249 | if ne get inb add i j get kw add o j |
| 1250 | ret 0 |
| 1251 | end |
| 1252 | end |
| 1253 | ret 1 |
| 1254 | end |
| 1255 | note spat: 1 when byte a lies before q and is a space, else 0. |
| 1256 | fn spat a ulong q ulong to ulong |
| 1257 | if ge a q |
| 1258 | ret 0 |
| 1259 | end |
| 1260 | if ne get inb a 32 |
| 1261 | ret 0 |
| 1262 | end |
| 1263 | ret 1 |
| 1264 | end |
| 1265 | note cline: the value on the line at i when it is exactly "const NAME ulong DIGITS" and NAME is the |
| 1266 | note bytes s .. e-1; 0 when it is another line. A matching line whose value is not 1 .. 8 digits, or |
| 1267 | note is 0, is refused. |
| 1268 | fn cline i ulong q ulong s ulong e ulong to ulong |
| 1269 | if eq isat i 41 5 q 0 |
| 1270 | ret 0 |
| 1271 | end |
| 1272 | a = add i 5 |
| 1273 | if eq spat a q 0 |
| 1274 | ret 0 |
| 1275 | end |
| 1276 | a = add a 1 |
| 1277 | n = sub e s |
| 1278 | if gt add a n q |
| 1279 | ret 0 |
| 1280 | end |
| 1281 | if eq samenm a add a n s e 0 |
| 1282 | ret 0 |
| 1283 | end |
| 1284 | a = add a n |
| 1285 | if eq spat a q 0 |
| 1286 | ret 0 |
| 1287 | end |
| 1288 | a = add a 1 |
| 1289 | if eq isat a 10 5 q 0 |
| 1290 | ret 0 |
| 1291 | end |
| 1292 | a = add a 5 |
| 1293 | if eq spat a q 0 |
| 1294 | ret 0 |
| 1295 | end |
| 1296 | a = add a 1 |
| 1297 | v = ulong 0 |
| 1298 | d = ulong 0 |
| 1299 | while and lt a q ne get inb a 10 |
| 1300 | c = get inb a |
| 1301 | if or lt c 48 gt c 57 |
| 1302 | trap 10 |
| 1303 | end |
| 1304 | if ge d 8 |
| 1305 | trap 10 |
| 1306 | end |
| 1307 | v = add mul v 10 ulong sub c 48 |
| 1308 | d = add d 1 |
| 1309 | a = add a 1 |
| 1310 | end |
| 1311 | if or eq d 0 eq v 0 |
| 1312 | trap 10 |
| 1313 | end |
| 1314 | ret v |
| 1315 | end |
| 1316 | note cval: the value of the integer constant named by bytes s .. e-1, defined on a line of the unit |
| 1317 | note before its signature line (st 9 is the unit start, st 6 the signature line); refused when absent. |
| 1318 | fn cval s ulong e ulong to ulong |
| 1319 | p = get st 9 |
| 1320 | q = get st 6 |
| 1321 | ls = p |
| 1322 | i = p |
| 1323 | while lt i q |
| 1324 | if eq i ls |
| 1325 | v = cline i q s e |
| 1326 | if gt v 0 |
| 1327 | ret v |
| 1328 | end |
| 1329 | end |
| 1330 | if eq get inb i 10 |
| 1331 | ls = add i 1 |
| 1332 | end |
| 1333 | i = add i 1 |
| 1334 | end |
| 1335 | trap 10 |
| 1336 | end |
| 1337 | note tklen: an array length token: decimal digits, or the name of an integer constant (cval). |
| 1338 | fn tklen k ulong to ulong |
| 1339 | s = get tks k |
| 1340 | e = get tke k |
| 1341 | if eq s e |
| 1342 | trap 10 |
| 1343 | end |
| 1344 | c = get inb s |
| 1345 | if and ge c 48 le c 57 |
| 1346 | ret tknum k |
| 1347 | end |
| 1348 | ret cval s e |
| 1349 | end |
| 1350 | note uname: refuse a unit name (token 1) that is not a C identifier or repeats an earlier unit name. |
| 1351 | fn uname to void |
| 1352 | s = get tks 1 |
| 1353 | e = get tke 1 |
| 1354 | if eq cidr s e 0 |
| 1355 | trap 10 |
| 1356 | end |
| 1357 | n = get st 4 |
| 1358 | if ge n len us |
| 1359 | trap 10 |
| 1360 | end |
| 1361 | for j ulong n |
| 1362 | if eq samenm s e get us j get ue j 1 |
| 1363 | trap 10 |
| 1364 | end |
| 1365 | end |
| 1366 | put us n s |
| 1367 | put ue n e |
| 1368 | put st 4 add n 1 |
| 1369 | end |
| 1370 | note pparam: record the parameter at token k in slot st 2; return the token after it. |
| 1371 | fn pparam k ulong nt ulong to ulong |
| 1372 | np = get st 2 |
| 1373 | if ge np 6 |
| 1374 | trap 10 |
| 1375 | end |
| 1376 | put ps np get tks k |
| 1377 | put pe np get tke k |
| 1378 | ki = pkind add k 1 nt |
| 1379 | if eq ki 0 |
| 1380 | trap 10 |
| 1381 | end |
| 1382 | put pk np ki |
| 1383 | pname get tks k get tke k |
| 1384 | put st 2 add np 1 |
| 1385 | if fscalar ki |
| 1386 | ret add k 2 |
| 1387 | end |
| 1388 | ln = tklen add k 3 |
| 1389 | if or eq ln 0 gt ln 16777216 |
| 1390 | trap 10 |
| 1391 | end |
| 1392 | put pl np ln |
| 1393 | ret add k 4 |
| 1394 | end |
| 1395 | note parse: read the signature line at fl; parameters into ps pe pk pl, their count into st 2, |
| 1396 | note 1 or 0 into st 3 for a function with or without a value. |
| 1397 | fn parse fl ulong q ulong to void |
| 1398 | put st 6 fl |
| 1399 | nt = tokln fl q |
| 1400 | if lt nt 4 |
| 1401 | trap 10 |
| 1402 | end |
| 1403 | if eq tkis 1 28 4 1 |
| 1404 | trap 10 |
| 1405 | end |
| 1406 | uname |
| 1407 | put fret 0 0 |
| 1408 | put st 2 0 |
| 1409 | k = ulong 2 |
| 1410 | while eq tkis k 0 2 0 |
| 1411 | if ge add k 1 nt |
| 1412 | trap 10 |
| 1413 | end |
| 1414 | k = pparam k nt |
| 1415 | if ge k nt |
| 1416 | trap 10 |
| 1417 | end |
| 1418 | end |
| 1419 | if ne add k 2 nt |
| 1420 | trap 10 |
| 1421 | end |
| 1422 | r = add k 1 |
| 1423 | hv = ulong 2 |
| 1424 | if or eq tkis r 10 5 1 eq tkis r 15 4 1 |
| 1425 | hv = 1 |
| 1426 | end |
| 1427 | if eq tkis r 32 3 1 |
| 1428 | hv = 1 |
| 1429 | put fret 0 11 |
| 1430 | end |
| 1431 | if eq tkis r 46 3 1 |
| 1432 | hv = 1 |
| 1433 | put fret 0 12 |
| 1434 | end |
| 1435 | if eq tkis r 24 4 1 |
| 1436 | hv = 0 |
| 1437 | end |
| 1438 | if eq hv 2 |
| 1439 | trap 10 |
| 1440 | end |
| 1441 | put st 3 hv |
| 1442 | if and hasfloat eq get fok 0 0 |
| 1443 | trap 10 |
| 1444 | end |
| 1445 | end |
| 1446 | note codelen: the 8-digit code length after the 0 byte at q, checked against the input. |
| 1447 | fn codelen q ulong to ulong |
| 1448 | t = get st 0 |
| 1449 | c0 = add q 9 |
| 1450 | if gt c0 t |
| 1451 | trap 10 |
| 1452 | end |
| 1453 | cl = ulong 0 |
| 1454 | for j ulong 8 |
| 1455 | d = get inb add add q 1 j |
| 1456 | if or lt d 48 gt d 57 |
| 1457 | trap 10 |
| 1458 | end |
| 1459 | cl = add mul cl 10 ulong sub d 48 |
| 1460 | end |
| 1461 | if eq cl 0 |
| 1462 | trap 10 |
| 1463 | end |
| 1464 | if and eq get xt 0 0 ne rem cl 4 0 |
| 1465 | trap 10 |
| 1466 | end |
| 1467 | if gt cl sub t c0 |
| 1468 | trap 10 |
| 1469 | end |
| 1470 | ret cl |
| 1471 | end |
| 1472 | note xcode: x86linux code bytes as ") ":" (closing the OMBR_SYM label), then .quad words (byte 8q+7 is the high |
| 1473 | note digit pair, so the little-endian assembler lays down the compiler's bytes in order), then any tail as .byte. |
| 1474 | fn xcode c0 ulong cl ulong to void |
| 1475 | ob uchar 41 |
| 1476 | ob uchar 32 |
| 1477 | ob uchar 34 |
| 1478 | ob uchar 58 |
| 1479 | nq = div cl 8 |
| 1480 | if gt nq 0 |
| 1481 | for j ulong len xqd |
| 1482 | ob get xqd j |
| 1483 | end |
| 1484 | end |
| 1485 | for q ulong nq |
| 1486 | if gt q 0 |
| 1487 | ob uchar 44 |
| 1488 | end |
| 1489 | ob uchar 48 |
| 1490 | ob uchar 120 |
| 1491 | for k ulong 8 |
| 1492 | b = get inb add add c0 mul q 8 sub 7 k |
| 1493 | ob get hx shr b 4 |
| 1494 | ob get hx and b 15 |
| 1495 | end |
| 1496 | end |
| 1497 | r = mul nq 8 |
| 1498 | if lt r cl |
| 1499 | for j ulong len xby |
| 1500 | ob get xby j |
| 1501 | end |
| 1502 | end |
| 1503 | for j ulong sub cl r |
| 1504 | if gt j 0 |
| 1505 | ob uchar 44 |
| 1506 | end |
| 1507 | ohex get inb add c0 add r j |
| 1508 | end |
| 1509 | end |
| 1510 | note hassvc: 1 when a code word is an svc (bytes x1 xx x0 d4 under the mask 1f 00 e0 ff): a host word's |
| 1511 | note Linux system call, which macOS numbers differently; the C file then refuses to build on macOS. |
| 1512 | fn hassvc c0 ulong cl ulong to ulong |
| 1513 | j = ulong 0 |
| 1514 | while lt j cl |
| 1515 | p = add c0 j |
| 1516 | if eq get inb add p 3 212 |
| 1517 | if eq and get inb add p 2 224 0 |
| 1518 | if eq and get inb p 31 1 |
| 1519 | ret 1 |
| 1520 | end |
| 1521 | end |
| 1522 | end |
| 1523 | j = add j 4 |
| 1524 | end |
| 1525 | ret 0 |
| 1526 | end |
| 1527 | note ecode: the embedded machine code, unchanged (x86linux packs it as little-endian .quad words). |
| 1528 | fn ecode c0 ulong cl ulong to void |
| 1529 | if ne get xt 0 1 |
| 1530 | if eq hassvc c0 cl 1 |
| 1531 | ofr 28 |
| 1532 | oname 1 |
| 1533 | ofr 29 |
| 1534 | end |
| 1535 | end |
| 1536 | ofr 0 |
| 1537 | oname 1 |
| 1538 | ofr 1 |
| 1539 | oname 1 |
| 1540 | ofr 2 |
| 1541 | oname 1 |
| 1542 | if eq get xt 0 1 |
| 1543 | xcode c0 cl |
| 1544 | else |
| 1545 | ofr 3 |
| 1546 | for j ulong cl |
| 1547 | if gt j 0 |
| 1548 | ob uchar 44 |
| 1549 | end |
| 1550 | ohex get inb add c0 j |
| 1551 | end |
| 1552 | end |
| 1553 | ofr 24 |
| 1554 | oname 1 |
| 1555 | ofr 25 |
| 1556 | oname 1 |
| 1557 | ofr 26 |
| 1558 | oname 1 |
| 1559 | ofr 27 |
| 1560 | oname 1 |
| 1561 | ofr 4 |
| 1562 | oname 1 |
| 1563 | if hasfloat |
| 1564 | oflo 22 |
| 1565 | else |
| 1566 | ofr 5 |
| 1567 | oname 1 |
| 1568 | end |
| 1569 | end |
| 1570 | note esig: the exported C parameter list. |
| 1571 | fn esig to void |
| 1572 | ofr 6 |
| 1573 | for j ulong get st 2 |
| 1574 | x = get pk j |
| 1575 | if le x 2 |
| 1576 | ofr 7 |
| 1577 | opn j |
| 1578 | else |
| 1579 | if eq rem x 2 1 |
| 1580 | ofr 8 |
| 1581 | else |
| 1582 | ofr 9 |
| 1583 | end |
| 1584 | opn j |
| 1585 | ofr 7 |
| 1586 | opn j |
| 1587 | ofr 10 |
| 1588 | end |
| 1589 | end |
| 1590 | end |
| 1591 | note earr: the checks and argument word for array parameter j of kind x. |
| 1592 | fn earr j ulong x ulong to void |
| 1593 | ofr 12 |
| 1594 | opn j |
| 1595 | ofr 13 |
| 1596 | opn j |
| 1597 | ofr 14 |
| 1598 | odec get pl j |
| 1599 | ofr 15 |
| 1600 | if le x 4 |
| 1601 | odec 8 |
| 1602 | else |
| 1603 | if le x 6 |
| 1604 | odec 1 |
| 1605 | else |
| 1606 | if le x 8 |
| 1607 | odec 4 |
| 1608 | else |
| 1609 | odec 2 |
| 1610 | end |
| 1611 | end |
| 1612 | end |
| 1613 | ofr 15 |
| 1614 | odec rem x 2 |
| 1615 | ofr 16 |
| 1616 | odec j |
| 1617 | ofr 17 |
| 1618 | opn j |
| 1619 | ofr 18 |
| 1620 | end |
| 1621 | note ebody: argument words, overlap check and the call. |
| 1622 | fn ebody to void |
| 1623 | ofr 11 |
| 1624 | for j ulong get st 2 |
| 1625 | x = get pk j |
| 1626 | if le x 2 |
| 1627 | ofr 19 |
| 1628 | odec j |
| 1629 | ofr 20 |
| 1630 | opn j |
| 1631 | ofr 18 |
| 1632 | else |
| 1633 | earr j x |
| 1634 | end |
| 1635 | end |
| 1636 | ofr 21 |
| 1637 | oname 1 |
| 1638 | ofr 22 |
| 1639 | odec get st 3 |
| 1640 | ofr 23 |
| 1641 | end |
| 1642 | note edeclC: a declaration with the type before the name (h): the comment |
| 1643 | note fragments at cb (open, close + head) and the type fragments at tb (result, scalar, writable |
| 1644 | note void*, readonly const void*, two unused old kind slots, the length suffix, close). Writable |
| 1645 | note arrays, including f32 and ushort, use the void* fragment; readonly arrays use const void*. |
| 1646 | fn edeclC cb ulong tp ulong to void |
| 1647 | ofb cb |
| 1648 | osig |
| 1649 | ofb add cb 1 |
| 1650 | oname 1 |
| 1651 | ofb tp |
| 1652 | for j ulong get st 2 |
| 1653 | x = get pk j |
| 1654 | if le x 2 |
| 1655 | ofb add tp 1 |
| 1656 | opn j |
| 1657 | else |
| 1658 | if eq rem x 2 1 |
| 1659 | ofb add tp 2 |
| 1660 | else |
| 1661 | ofb add tp 3 |
| 1662 | end |
| 1663 | opn j |
| 1664 | ofb add tp 1 |
| 1665 | opn j |
| 1666 | ofb add tp 6 |
| 1667 | end |
| 1668 | end |
| 1669 | ofb add tp 7 |
| 1670 | end |
| 1671 | note edeclR: a declaration with the name before the type (rust, zig, the go wrapper head): the |
| 1672 | note type fragments at tp are result, the name prefix, scalar, the four array kinds, length, close. |
| 1673 | note Kinds above 6 (f32, ushort) reuse the uchar pointer fragment of the same writability, so Rust |
| 1674 | note and Zig see a byte pointer; the C library still checks the element size. |
| 1675 | fn edeclR cb ulong tp ulong to void |
| 1676 | ofb cb |
| 1677 | osig |
| 1678 | ofb add cb 1 |
| 1679 | oname 1 |
| 1680 | ofb tp |
| 1681 | for j ulong get st 2 |
| 1682 | x = get pk j |
| 1683 | ofb add tp 1 |
| 1684 | opn j |
| 1685 | if le x 2 |
| 1686 | ofb add tp 2 |
| 1687 | else |
| 1688 | ax = x |
| 1689 | if gt x 6 |
| 1690 | ax = rem x 2 |
| 1691 | ax = sub 6 ax |
| 1692 | end |
| 1693 | ofb add tp ax |
| 1694 | ofb add tp 1 |
| 1695 | opn j |
| 1696 | ofb add tp 7 |
| 1697 | end |
| 1698 | end |
| 1699 | ofb add tp 8 |
| 1700 | end |
| 1701 | note epy: the python declaration: the function, its argument types, its result type. |
| 1702 | fn epy to void |
| 1703 | ofb 13 |
| 1704 | osig |
| 1705 | ofb 14 |
| 1706 | oname 1 |
| 1707 | ofb 15 |
| 1708 | oname 1 |
| 1709 | ofb 16 |
| 1710 | oname 1 |
| 1711 | ofb 17 |
| 1712 | for j ulong get st 2 |
| 1713 | if le get pk j 2 |
| 1714 | ofb 18 |
| 1715 | else |
| 1716 | ofb 19 |
| 1717 | odec get pk j |
| 1718 | ofb 18 |
| 1719 | end |
| 1720 | end |
| 1721 | ofb 20 |
| 1722 | oname 1 |
| 1723 | ofb 21 |
| 1724 | end |
| 1725 | note ecall: the go wrapper's call of the C function and its end. |
| 1726 | fn ecall to void |
| 1727 | oname 1 |
| 1728 | ofb 59 |
| 1729 | for j ulong get st 2 |
| 1730 | if le get pk j 2 |
| 1731 | ofb 60 |
| 1732 | opn j |
| 1733 | ofb 61 |
| 1734 | else |
| 1735 | ofb 62 |
| 1736 | opn j |
| 1737 | ofb 60 |
| 1738 | opn j |
| 1739 | ofb 63 |
| 1740 | end |
| 1741 | end |
| 1742 | ofb 64 |
| 1743 | end |
| 1744 | note emit: the parsed unit in the output named by st 5. |
| 1745 | fn emit c0 ulong cl ulong to void |
| 1746 | m = get st 5 |
| 1747 | if hasfloat |
| 1748 | if eq m 1 |
| 1749 | ecode c0 cl |
| 1750 | end |
| 1751 | nfloat |
| 1752 | ret |
| 1753 | end |
| 1754 | if eq m 10 |
| 1755 | ecode c0 cl |
| 1756 | esig |
| 1757 | fbody |
| 1758 | end |
| 1759 | if eq m 1 |
| 1760 | ecode c0 cl |
| 1761 | esig |
| 1762 | ebody |
| 1763 | end |
| 1764 | if eq m 2 |
| 1765 | edeclC 1 3 |
| 1766 | end |
| 1767 | if eq m 3 |
| 1768 | epy |
| 1769 | end |
| 1770 | if eq m 4 |
| 1771 | edeclR 23 25 |
| 1772 | end |
| 1773 | if eq m 5 |
| 1774 | edeclR 36 38 |
| 1775 | end |
| 1776 | if eq m 6 |
| 1777 | edeclR 48 50 |
| 1778 | ecall |
| 1779 | end |
| 1780 | end |
| 1781 | note ======== ABI v2: OM-2 units (docs/NATIVE-ABI.md, ABI v2) ======== |
| 1782 | note An OM-2 unit (its first line that is not a note is exactly om2) is bound as omega2_<name>, one symbol |
| 1783 | note per `export fn` (in source order; without any export, the last fn as in v1), and carries its |
| 1784 | note identity. Its frame is the v1 frame followed by the line `omega-unit NAME OMC`, NAME the unit's C |
| 1785 | note name and OMC the sha256 of the compiler that wrote the code (64 hex digits), both supplied by |
| 1786 | note tools/native. The source sha256 is computed here from the unit's exact bytes. A parameter is a |
| 1787 | note ulong or long scalar (one slot), a sized array `view|edit T N` (one slot), an unsized view |
| 1788 | note `view|edit T *` (two slots: pointer, element count), a layout `view|edit L` (one slot) or |
| 1789 | note `out T N` (one slot), T any of uchar ushort uint ulong byte short int long; at most 6 slots; the |
| 1790 | note result is ulong, long or void. s2: 0 the C prelude written, 1 2 the unit name, 3 the omc digest, |
| 1791 | note 4 the export count, 5 slots used, 6 7 the source, 8 has a value, 9 out bytes, 10 layouts, |
| 1792 | note 11 unit names, 12 the entry index, 13 14 the code, 16 17 the bound name, 18 the result type. |
| 1793 | note q*: per parameter class (1 scalar, 2 sized array, 3 unsized view, 4 layout, 5 out), mode (0 view, |
| 1794 | note 1 edit), element type, count (or layout size), first slot, layout index. |
| 1795 | global s2 ulong 32 |
| 1796 | global qk ulong 6 |
| 1797 | global qm ulong 6 |
| 1798 | global qt ulong 6 |
| 1799 | global qn ulong 6 |
| 1800 | global qs ulong 6 |
| 1801 | global ql ulong 6 |
| 1802 | global lys ulong 32 |
| 1803 | global lye ulong 32 |
| 1804 | global lyz ulong 32 |
| 1805 | global lyl ulong 32 |
| 1806 | global lcs ulong 32 |
| 1807 | global lce ulong 32 |
| 1808 | global uns ulong 1024 |
| 1809 | global une ulong 1024 |
| 1810 | global exl ulong 32 |
| 1811 | global fds ulong 256 |
| 1812 | global fde ulong 256 |
| 1813 | global fdt ulong 256 |
| 1814 | global fdc ulong 256 |
| 1815 | global fdo ulong 256 |
| 1816 | global fdb ulong 256 |
| 1817 | global fdu ulong 256 |
| 1818 | global shk ulong 72 |
| 1819 | global shw ulong 64 |
| 1820 | global shh ulong 8 |
| 1821 | global shv ulong 8 |
| 1822 | global shb uchar 64 |
| 1823 | note kv: the OM-2 words: export 0, fn 6, out 8, om2 11, ushort 14, uint 20, byte 24, short 28, int 33, |
| 1824 | note layout 36, field 42, end 47, note 50, bridge 54, c-type 60, c-define 66, little 74, big 80, * 83, |
| 1825 | note at 84, omega-unit 86. |
| 1826 | text kv "exportfnoutom2ushortuintbyteshortintlayoutfieldendnotebridgec-typec-definelittlebig*atomega-unit" |
| 1827 | note fv: the v2 output fragments, separated by ~ (byte 126): 0 the C prelude, 1-10 the code and the |
| 1828 | note identity, 11-13 the identity text, 14-20 an entry stub, 21-24 the C function head, 25-30 a C |
| 1829 | note parameter, 31-50 the C body, 51-56 h, 57-75 and 155 python, 76-88 rust, 89-98 zig, 99-117 go, |
| 1830 | note 118-154 the api header. tn: the element type names, 8 per language: C, ctypes, rust and zig, cgo. |
| 1831 | text fv "/* ABI v2 (docs/NATIVE-ABI.md, ABI v2): OM-2 units, bound as omega2_<export>. An unsized view is its\n * pointer and its element count; a layout is a pointer to its fixed bytes; an out parameter is written\n * to a buffer the binding owns and copied to the caller only after status 0. */\n#include <string.h>\ntypedef struct ombr2_out { unsigned slot; uint64_t n; void *dst; } ombr2_out;\n/* A library of OM-2 units alone calls neither of the ABI v1 helpers. */\n__attribute__((unused)) static void ombr2_keep(void)\n{\n (void)ombr_overlap;\n (void)ombr_run;\n}\n/* An unsized view of n elements of es bytes. n == 0 is the empty view whatever the pointer (it adds no\n * range, so it overlaps nothing). Otherwise refused: a null pointer, a pointer not aligned to es,\n * n * es over 64 bits, or an end past the top of the address space. */\n__attribute__((unused)) static int ombr2_view(ombr_span *sp, unsigned *ns, const void *p, uint64_t n, uint64_t es, int w)\n{\n uintptr_t lo = (uintptr_t)p;\n if (n == 0u)\n return 0;\n if (!p || lo % es != 0u || n > UINT64_MAX / es || n * es > UINTPTR_MAX - lo)\n return 1;\n sp[*ns].lo = lo;\n sp[*ns].hi = lo + n * es;\n sp[*ns].w = w;\n (*ns)++;\n return 0;\n}\n/* A fixed range of nb > 0 bytes (a layout or an out parameter) aligned to es. */\n__attribute__((unused)) static int ombr2_fixed(ombr_span *sp, unsigned *ns, const void *p, uint64_t nb, uint64_t es,\n int w)\n{\n uintptr_t lo = (uintptr_t)p;\n if (!p || lo % es != 0u || nb > UINTPTR_MAX - lo)\n return 1;\n sp[*ns].lo = lo;\n sp[*ns].hi = lo + nb;\n sp[*ns].w = w;\n (*ns)++;\n return 0;\n}\n/* w: 0 view, 1 edit or the result, 2 out. Refused: an edit or the result overlapping any other range,\n * or two out ranges overlapping. An out may overlap a view: it is written only after the code returns. */\nstatic int ombr2_overlap(const ombr_span *sp, unsigned ns)\n{\n for (unsigned i = 0; i < ns; i++)\n for (unsigned j = i + 1; j < ns; j++)\n if ((sp[i].w == 1 || sp[j].w == 1 || (sp[i].w == 2 && sp[j].w == 2))\n && sp[i].lo < sp[j].hi && sp[j].lo < sp[i].hi)\n return 1;\n return 0;\n}\n/* As ombr_run, and each out buffer is carved from the top of the thread's Omega stack (16-byte aligned,\n * zero-filled), passed in its slot and copied to the caller with memmove only after status 0. */\nstatic uint32_t ombr2_run(const void *code, uint64_t *args, uint64_t *result, int has_value, const ombr2_out *o,\n unsigned no)\n{\n if (ombr_active)\n return OMEGA_REENTRY;\n ombr_active = 1;\n unsigned char *top = ombr_stack();\n if (!top) {\n ombr_active = 0;\n return OMEGA_NO_STACK;\n }\n unsigned char *buf[6] = {0};\n for (unsigned i = 0; i < no; i++) {\n top -= (o[i].n + 15u) / 16u * 16u;\n memset(top, 0, o[i].n);\n buf[i] = top;\n args[o[i].slot] = (uint64_t)(uintptr_t)top;\n }\n uint64_t v = 0;\n uint32_t s = ombr_enter(code, args, &ombr_rt_table, &v, top);\n if (s == OMEGA_OK) {\n for (unsigned i = 0; i < no; i++)\n memmove(o[i].dst, buf[i], o[i].n);\n *result = has_value ? v : 0u;\n }\n ombr_active = 0;\n return s;\n}\n~__asm__(OMBR_CODE_SECTION \".balign 4\\n\" OMBR_LOCAL(ombr2_code_~) OMBR_HIDDEN(ombr2_code_~) OMBR_SYM(ombr2_code_~) \":\\n.byte ~\\n\" OMBR_PREVIOUS);\n~static const char ombr2_ident_~[] = \"~\";\n__attribute__((visibility(\"default\"))) const char *omega2_ident_~(void)\n{\n return ombr2_ident_~;\n}\n~omega-ident 1 unit=~ abi=2 profile=OM-2 src=~ omc=~__asm__(OMBR_CODE_SECTION \".balign 4\\n\" OMBR_LOCAL(ombr2_entry_~) OMBR_HIDDEN(ombr2_entry_~) OMBR_SYM(ombr2_entry_~) \":\\nhint #34\\nb \" OMBR_SYM(ombr2_code_~) \"+~\\n\" OMBR_PREVIOUS);\nextern const unsigned char ombr2_entry_~[] __attribute__((visibility(\"hidden\")));\n~/* ~ */\n__attribute__((visibility(\"default\"))) uint32_t omega2_~(uint64_t *result~)\n{\n ombr_span sp[7] = {{0}};\n unsigned ns = 0;\n uint64_t a[6] = {0};\n ombr2_out ou[6] = {{0, 0, 0}};\n unsigned no = 0;\n if (ombr_span_add(sp, &ns, result, 1u, 1u, 8u, 1))\n return OMEGA_BAD_ARG;\n~, uint64_t o_~, ~const ~ *o_~, uint64_t o_~_len~ if (ombr_span_add(sp, &ns, o_~, o_~_len, ~u, ~))\n return OMEGA_BAD_ARG;\n~ a[~] = (uint64_t)(uintptr_t)o_~;\n~] = o_~ if (ombr2_view(sp, &ns, o_~ if (ombr2_fixed(sp, &ns, o_~_len;\n~2))\n return OMEGA_BAD_ARG;\n ou[no].slot = ~u;\n ou[no].n = ~u;\n ou[no].dst = o_~;\n no++;\n~1u, ~ if (ombr2_overlap(sp, ns))\n return OMEGA_BAD_ARG;\n return ombr2_run(ombr2_entry_~, a, result, ~, ou, no);\n}\n~#define OMEGA2_IDENT_~ \"~\"\nconst char *omega2_ident_~(void);\n~ */\nuint32_t omega2_~);\n~# ~\nomega2_~ = lib.omega2_~.argtypes = [_res~]\nomega2_~.restype = ctypes.c_uint32\n~, _u64~, ctypes.c_char_p~, ctypes.POINTER(ctypes.~)~omega2_ident_~.argtypes = []\nomega2_ident_~.restype = ctypes.c_char_p\nOMEGA2_IDENT_~ = b\"~\"\nif omega2_ident_~() != OMEGA2_IDENT_~:\n raise ImportError(\"libomega_native.so is not the library this binding was generated with: the identity of unit ~ differs\")\n~\n~ // ~\n pub fn omega2_~(result: *mut u64~) -> u32;\n~, o_~: u64~: *const ~: *mut ~_len: u64~ pub fn omega2_ident_~() -> *const u8;\n}\n#[allow(dead_code, non_upper_case_globals)]\npub const OMEGA2_IDENT_~: &str = \"~\";\n#[allow(dead_code)]\n#[link(name = \"omega_native\")]\nunsafe extern \"C\" {\n~// ~\npub extern fn omega2_~(result: ?*u64~) u32;\n~: ?[*]const ~: ?[*]~pub const OMEGA2_IDENT_~ = \"~\";\npub extern fn omega2_ident_~() [*:0]const u8;\n~\n// ~\nfunc Omega2_~(result *uint64~) uint32 {\n\treturn uint32(C.omega2_~((*C.uint64_t)(unsafe.Pointer(result))~))\n}\n~ uint64~ unsafe.Pointer~_len uint64~, C.uint64_t(o_~)~, (*C.~)(o_~_len)~\nconst Omega2Ident_~ = \"~\"\n\nfunc Omega2_ident_~() string {\n\treturn C.GoString(C.omega2_ident_~())\n}\n~/* Generated by omega-bridge src/native.om: the C API of the ABI v2 units in libomega_native\n * (docs/NATIVE-ABI.md, ABI v2). Each function calls omega2_<name> and calls abort() on a nonzero status.\n * Regenerate it; do not edit it. */\n#ifndef OMEGA_API_H\n#define OMEGA_API_H\n#include <stddef.h>\n#include <stdint.h>\n#include <stdlib.h>\n#include \"omega_native.h\"\n#ifdef __cplusplus\n#define OMBR_ASSERT static_assert\nextern \"C\" {\n#else\n#define OMBR_ASSERT _Static_assert\n#endif\n~#ifdef __cplusplus\n}\n#endif\n#endif\n~#define ~ ~typedef struct {\n~} ~;\nOMBR_ASSERT(sizeof(~) == ~, \"layout ~ size\");\n~OMBR_ASSERT(offsetof(~, ~ field ~\");\n~ ~[~];\n~ uint8_t ombr_pad~ */\nstatic inline ~void~uint64_t~int64_t~(~)\n{\n uint64_t r = 0;\n if (omega2_~(&r~) != OMEGA_OK)\n abort();\n~ (void)r;\n}\n~ return r;\n}\n~ return (int64_t)r;\n}\n~, ~ o_~ *o_~, size_t o_~, (uint8_t *)o_~, (const uint8_t *)o_~, (uint64_t)o_~]~ = lib." |
| 1832 | text fvdev "/* ABI v2 (docs/NATIVE-ABI.md, ABI v2): OM-2 units, bound as omega2_<export>. An unsized view is its\n * pointer and its element count; a layout is a pointer to its fixed bytes; an out parameter is written\n * to a buffer the binding owns and copied to the caller only after status 0. */\n#include <string.h>\ntypedef struct ombr2_out { unsigned slot; uint64_t n; void *dst; } ombr2_out;\n/* A library of OM-2 units alone calls neither of the ABI v1 helpers. */\n__attribute__((unused)) static void ombr2_keep(void)\n{\n (void)ombr_overlap;\n (void)ombr_run;\n}\n/* An unsized view of n elements of es bytes. n == 0 is the empty view whatever the pointer (it adds no\n * range, so it overlaps nothing). Otherwise refused: a null pointer, a pointer not aligned to es,\n * n * es over 64 bits, or an end past the top of the address space. */\n__attribute__((unused)) static int ombr2_view(ombr_span *sp, unsigned *ns, const void *p, uint64_t n, uint64_t es, int w)\n{\n uintptr_t lo = (uintptr_t)p;\n if (n == 0u)\n return 0;\n if (!p || lo % es != 0u || n > UINT64_MAX / es || n * es > UINTPTR_MAX - lo)\n return 1;\n sp[*ns].lo = lo;\n sp[*ns].hi = lo + n * es;\n sp[*ns].w = w;\n (*ns)++;\n return 0;\n}\n/* A fixed range of nb > 0 bytes (a layout or an out parameter) aligned to es. */\n__attribute__((unused)) static int ombr2_fixed(ombr_span *sp, unsigned *ns, const void *p, uint64_t nb, uint64_t es,\n int w)\n{\n uintptr_t lo = (uintptr_t)p;\n if (!p || lo % es != 0u || nb > UINTPTR_MAX - lo)\n return 1;\n sp[*ns].lo = lo;\n sp[*ns].hi = lo + nb;\n sp[*ns].w = w;\n (*ns)++;\n return 0;\n}\n/* w: 0 view, 1 edit or the result, 2 out. Refused: an edit or the result overlapping any other range,\n * or two out ranges overlapping. An out may overlap a view: it is written only after the code returns. */\nstatic int ombr2_overlap(const ombr_span *sp, unsigned ns)\n{\n for (unsigned i = 0; i < ns; i++)\n for (unsigned j = i + 1; j < ns; j++)\n if ((sp[i].w == 1 || sp[j].w == 1 || (sp[i].w == 2 && sp[j].w == 2))\n && sp[i].lo < sp[j].hi && sp[j].lo < sp[i].hi)\n return 1;\n return 0;\n}\n/* As ombr_run, and each out buffer is carved from the top of the thread's Omega stack (16-byte aligned,\n * zero-filled), passed in its slot and copied to the caller with memmove only after status 0. */\nstatic uint32_t ombr2_run(omega_native_context *context, const void *code, uint64_t *args, uint64_t *result, int has_value, const ombr2_out *o,\n unsigned no)\n{\n uint32_t s = ombr_context_lock(context);\n if (s != OMEGA_OK)\n return s;\n unsigned char *top = ombr_stack();\n if (!top)\n return ombr_context_unlock(context, OMEGA_NO_STACK);\n unsigned char *buf[6] = {0};\n for (unsigned i = 0; i < no; i++) {\n top -= (o[i].n + 15u) / 16u * 16u;\n memset(top, 0, o[i].n);\n buf[i] = top;\n args[o[i].slot] = (uint64_t)(uintptr_t)top;\n }\n uint64_t v = 0;\n s = ombr_enter(code, args, context->rt, &v, top);\n if (s == OMEGA_OK) {\n for (unsigned i = 0; i < no; i++)\n memmove(o[i].dst, buf[i], o[i].n);\n *result = has_value ? v : 0u;\n }\n return ombr_context_unlock(context, s);\n}\n~__asm__(OMBR_CODE_SECTION \".balign 4\\n\" OMBR_LOCAL(ombr2_code_~) OMBR_HIDDEN(ombr2_code_~) OMBR_SYM(ombr2_code_~) \":\\n.byte ~\\n\" OMBR_PREVIOUS);\n~static const char ombr2_ident_~[] = \"~\";\n__attribute__((visibility(\"default\"))) const char *omega2_ident_~(void)\n{\n return ombr2_ident_~;\n}\n~omega-ident 1 unit=~ abi=2 profile=OM-2 src=~ omc=~__asm__(OMBR_CODE_SECTION \".balign 4\\n\" OMBR_LOCAL(ombr2_entry_~) OMBR_HIDDEN(ombr2_entry_~) OMBR_SYM(ombr2_entry_~) \":\\nhint #34\\nb \" OMBR_SYM(ombr2_code_~) \"+~\\n\" OMBR_PREVIOUS);\nextern const unsigned char ombr2_entry_~[] __attribute__((visibility(\"hidden\")));\n~/* ~ */\n__attribute__((visibility(\"default\"))) uint32_t omega2_~(uint64_t *result~)\n{\n ombr_span sp[7] = {{0}};\n unsigned ns = 0;\n uint64_t a[6] = {0};\n ombr2_out ou[6] = {{0, 0, 0}};\n unsigned no = 0;\n if (ombr_span_add(sp, &ns, result, 1u, 1u, 8u, 1))\n return OMEGA_BAD_ARG;\n~, uint64_t o_~, ~const ~ *o_~, uint64_t o_~_len~ if (ombr_span_add(sp, &ns, o_~, o_~_len, ~u, ~))\n return OMEGA_BAD_ARG;\n~ a[~] = (uint64_t)(uintptr_t)o_~;\n~] = o_~ if (ombr2_view(sp, &ns, o_~ if (ombr2_fixed(sp, &ns, o_~_len;\n~2))\n return OMEGA_BAD_ARG;\n ou[no].slot = ~u;\n ou[no].n = ~u;\n ou[no].dst = o_~;\n no++;\n~1u, ~ if (ombr2_overlap(sp, ns))\n return OMEGA_BAD_ARG;\n return ombr2_run(&ombr_default, ombr2_entry_~, a, result, ~, ou, no);\n}\n~#define OMEGA2_IDENT_~ \"~\"\nconst char *omega2_ident_~(void);\n~ */\nuint32_t omega2_~);\n~# ~\nomega2_~ = lib.omega2_~.argtypes = [_res~]\nomega2_~.restype = ctypes.c_uint32\n~, _u64~, ctypes.c_char_p~, ctypes.POINTER(ctypes.~)~omega2_ident_~.argtypes = []\nomega2_ident_~.restype = ctypes.c_char_p\nOMEGA2_IDENT_~ = b\"~\"\nif omega2_ident_~() != OMEGA2_IDENT_~:\n raise ImportError(\"libomega_native.so is not the library this binding was generated with: the identity of unit ~ differs\")\n~\n~ // ~\n pub fn omega2_~(result: *mut u64~) -> u32;\n~, o_~: u64~: *const ~: *mut ~_len: u64~ pub fn omega2_ident_~() -> *const u8;\n}\n#[allow(dead_code, non_upper_case_globals)]\npub const OMEGA2_IDENT_~: &str = \"~\";\n#[allow(dead_code)]\n#[link(name = \"omega_native\")]\nunsafe extern \"C\" {\n~// ~\npub extern fn omega2_~(result: ?*u64~) u32;\n~: ?[*]const ~: ?[*]~pub const OMEGA2_IDENT_~ = \"~\";\npub extern fn omega2_ident_~() [*:0]const u8;\n~\n// ~\nfunc Omega2_~(result *uint64~) uint32 {\n\treturn uint32(C.omega2_~((*C.uint64_t)(unsafe.Pointer(result))~))\n}\n~ uint64~ unsafe.Pointer~_len uint64~, C.uint64_t(o_~)~, (*C.~)(o_~_len)~\nconst Omega2Ident_~ = \"~\"\n\nfunc Omega2_ident_~() string {\n\treturn C.GoString(C.omega2_ident_~())\n}\n~/* Generated by omega-bridge src/native.om: the C API of the ABI v2 units in libomega_native\n * (docs/NATIVE-ABI.md, ABI v2). Each function calls omega2_<name> and calls abort() on a nonzero status.\n * Regenerate it; do not edit it. */\n#ifndef OMEGA_API_H\n#define OMEGA_API_H\n#include <stddef.h>\n#include <stdint.h>\n#include <stdlib.h>\n#include \"omega_native.h\"\n#ifdef __cplusplus\n#define OMBR_ASSERT static_assert\nextern \"C\" {\n#else\n#define OMBR_ASSERT _Static_assert\n#endif\n~#ifdef __cplusplus\n}\n#endif\n#endif\n~#define ~ ~typedef struct {\n~} ~;\nOMBR_ASSERT(sizeof(~) == ~, \"layout ~ size\");\n~OMBR_ASSERT(offsetof(~, ~ field ~\");\n~ ~[~];\n~ uint8_t ombr_pad~ */\nstatic inline ~void~uint64_t~int64_t~(~)\n{\n uint64_t r = 0;\n if (omega2_~(&r~) != OMEGA_OK)\n abort();\n~ (void)r;\n}\n~ return r;\n}\n~ return (int64_t)r;\n}\n~, ~ o_~ *o_~, size_t o_~, (uint8_t *)o_~, (const uint8_t *)o_~, (uint64_t)o_~]~ = lib." |
| 1833 | text tn "uint8_t~uint16_t~uint32_t~uint64_t~int8_t~int16_t~int32_t~int64_t~c_uint8~c_uint16~c_uint32~c_uint64~c_int8~c_int16~c_int32~c_int64~u8~u16~u32~u64~i8~i16~i32~i64~uint8_t~uint16_t~uint32_t~uint64_t~int8_t~int16_t~int32_t~int64_t" |
| 1834 | note shx: SHA-256 (FIPS 180-4) K[0..63] then H0[0..7], 8 hex digits each. |
| 1835 | text shx "428a2f9871374491b5c0fbcfe9b5dba53956c25b59f111f1923f82a4ab1c5ed5d807aa9812835b01243185be550c7dc372be5d7480deb1fe9bdc06a7c19bf174e49b69c1efbe47860fc19dc6240ca1cc2de92c6f4a7484aa5cb0a9dc76f988da983e5152a831c66db00327c8bf597fc7c6e00bf3d5a7914706ca63511429296727b70a852e1b21384d2c6dfc53380d13650a7354766a0abb81c2c92e92722c85a2bfe8a1a81a664bc24b8b70c76c51a3d192e819d6990624f40e3585106aa07019a4c1161e376c082748774c34b0bcb5391c0cb34ed8aa4a5b9cca4f682e6ff3748f82ee78a5636f84c878148cc7020890befffaa4506cebbef9a3f7c67178f26a09e667bb67ae853c6ef372a54ff53a510e527f9b05688c1f83d9ab5be0cd19" |
| 1836 | note fa: the out-of-line API fragments (outputs apih and apic), separated by ~: 0 the close of a |
| 1837 | note signature comment, 1 the end of a prototype, 2 the apih header's start, 3 the apic file's start. |
| 1838 | text fa " */\n~);\n~/* Generated by omega-bridge src/native.om: the C API of the ABI v2 units in libomega_native\n * (docs/NATIVE-ABI.md, ABI v2), declarations only (output apih). The definitions are the generated C\n * file of output apic: each calls omega2_<name> and calls abort() on a nonzero status. Including this\n * header references no C library function. Regenerate it; do not edit it. */\n#ifndef OMEGA_API_DECL_H\n#define OMEGA_API_DECL_H\n#include <stddef.h>\n#include <stdint.h>\n#include \"omega_native.h\"\n#ifdef __cplusplus\n#define OMBR_ASSERT static_assert\nextern \"C\" {\n#else\n#define OMBR_ASSERT _Static_assert\n#endif\n~/* Generated by omega-bridge src/native.om: the definitions of the C API declared in\n * omega_api_decl.h (output apic). Each calls omega2_<name> and calls abort() on a nonzero status.\n * Regenerate it; do not edit it. */\n#include <stdlib.h>\n#include \"omega_api_decl.h\"\n" |
| 1839 | fn ofa k ulong to void |
| 1840 | c = ulong 0 |
| 1841 | for i ulong len fa |
| 1842 | b = get fa i |
| 1843 | if eq b 126 |
| 1844 | c = add c 1 |
| 1845 | else |
| 1846 | if eq c k |
| 1847 | ob b |
| 1848 | end |
| 1849 | end |
| 1850 | end |
| 1851 | end |
| 1852 | note fq: the freestanding v2 fragments (outputs freest and fapic), separated by ~: 0 the runtime, 1-2 the |
| 1853 | note out buffer in an entry's frame, 3-4 the end of an entry, 5 the trap of a refused call, 6 the fapic |
| 1854 | note file's start. |
| 1855 | text fq "/* ABI v2, freestanding (docs/NATIVE-ABI.md, ABI v2, output freest): OM-2 units on the caller's stack. The\n * argument checks are those of output c. Each out parameter is written to a buffer in the calling\n * function's frame (16-byte aligned, zero-filled) and copied to the caller only after status 0. No\n * thread-local state, heap or stack mapping; no C library calls are required. */\ntypedef struct ombr_span { uintptr_t lo, hi; int w; } ombr_span;\ntypedef struct ombr2_out { unsigned slot; uint64_t n; void *dst; } ombr2_out;\n/* A binding of OM-2 units alone does not call the ABI v1 helper. */\n__attribute__((unused)) static void ombr2_keep(void)\n{\n (void)ombr_run;\n}\nstatic int ombr_span_add(ombr_span *sp, unsigned *ns, const void *p, uint64_t n, uint64_t want, uint64_t es, int w)\n{\n uintptr_t lo = (uintptr_t)p;\n if (!p || n != want || lo % es != 0u || n > (UINTPTR_MAX - lo) / es)\n return 1;\n sp[*ns].lo = lo;\n sp[*ns].hi = lo + n * es;\n sp[*ns].w = w;\n (*ns)++;\n return 0;\n}\n/* An unsized view of n elements of es bytes, as in output c. */\n__attribute__((unused)) static int ombr2_view(ombr_span *sp, unsigned *ns, const void *p, uint64_t n, uint64_t es, int w)\n{\n uintptr_t lo = (uintptr_t)p;\n if (n == 0u)\n return 0;\n if (!p || lo % es != 0u || n > UINT64_MAX / es || n * es > UINTPTR_MAX - lo)\n return 1;\n sp[*ns].lo = lo;\n sp[*ns].hi = lo + n * es;\n sp[*ns].w = w;\n (*ns)++;\n return 0;\n}\n/* A fixed range of nb > 0 bytes (a layout or an out parameter) aligned to es. */\n__attribute__((unused)) static int ombr2_fixed(ombr_span *sp, unsigned *ns, const void *p, uint64_t nb, uint64_t es,\n int w)\n{\n uintptr_t lo = (uintptr_t)p;\n if (!p || lo % es != 0u || nb > UINTPTR_MAX - lo)\n return 1;\n sp[*ns].lo = lo;\n sp[*ns].hi = lo + nb;\n sp[*ns].w = w;\n (*ns)++;\n return 0;\n}\n/* w: 0 view, 1 edit or the result, 2 out; refused overlaps as in output c. */\nstatic int ombr2_overlap(const ombr_span *sp, unsigned ns)\n{\n for (unsigned i = 0; i < ns; i++)\n for (unsigned j = i + 1; j < ns; j++)\n if ((sp[i].w == 1 || sp[j].w == 1 || (sp[i].w == 2 && sp[j].w == 2))\n && sp[i].lo < sp[j].hi && sp[j].lo < sp[i].hi)\n return 1;\n return 0;\n}\n/* Byte transport only: volatile stores prevent libc idiom substitution. The copy source is\n * this entry's private out frame, disjoint from caller buffers checked by the wrapper. */\nstatic void ombr2_zero_bytes(unsigned char *p, uint64_t n) {\n volatile unsigned char *d = p;\n for (uint64_t i = 0; i < n; i++) d[i] = 0;\n}\nstatic void ombr2_copy_bytes(void *p, const unsigned char *s, uint64_t n) {\n volatile unsigned char *d = p;\n for (uint64_t i = 0; i < n; i++) d[i] = s[i];\n}\n/* As ombr_run; each out buffer is carved from ob (the entry's frame, 16-byte aligned, each buffer rounded\n * up to 16 bytes), zero-filled, passed in its slot and copied to the caller only after status 0. */\nstatic uint32_t ombr2_run(const void *code, uint64_t *args, uint64_t *result, int has_value, const ombr2_out *o,\n unsigned no, unsigned char *ob)\n{\n unsigned char *buf[6] = {0};\n for (unsigned i = 0; i < no; i++) {\n ombr2_zero_bytes(ob, o[i].n);\n buf[i] = ob;\n args[o[i].slot] = (uint64_t)(uintptr_t)ob;\n ob += (o[i].n + 15u) / 16u * 16u;\n }\n uint64_t v = 0;\n uint32_t s = ombr_enter(code, args, &ombr_rt_table, &v, 0);\n if (s == OMEGA_OK) {\n for (unsigned i = 0; i < no; i++)\n ombr2_copy_bytes(o[i].dst, buf[i], o[i].n);\n *result = has_value ? v : 0u;\n }\n return s;\n}\n~ _Alignas(16) unsigned char ob[~];\n~, ou, no, ob);\n}\n~, ou, no, 0);\n}\n~) != OMEGA_OK)\n __builtin_trap();\n~/* Generated by omega-bridge src/native.om: the freestanding definitions of the C API declared in\n * omega_api_decl.h (output fapic), for the freestanding binding (output freest). Each calls\n * omega2_<name> and executes a trap instruction (__builtin_trap) on a nonzero status; it calls no C\n * library function. Regenerate it; do not edit it. */\n#include \"omega_api_decl.h\"\n" |
| 1856 | fn ofq k ulong to void |
| 1857 | c = ulong 0 |
| 1858 | for i ulong len fq |
| 1859 | b = get fq i |
| 1860 | if eq b 126 |
| 1861 | c = add c 1 |
| 1862 | else |
| 1863 | if eq c k |
| 1864 | ob b |
| 1865 | end |
| 1866 | end |
| 1867 | end |
| 1868 | end |
| 1869 | note ofv / otn: fragment k of fv / tn. |
| 1870 | fn ofvd k ulong to void |
| 1871 | c = ulong 0 |
| 1872 | for i ulong len fvdev |
| 1873 | b = get fvdev i |
| 1874 | if eq b 126 |
| 1875 | c = add c 1 |
| 1876 | else |
| 1877 | if eq c k |
| 1878 | ob b |
| 1879 | end |
| 1880 | end |
| 1881 | end |
| 1882 | end |
| 1883 | fn ofv k ulong to void |
| 1884 | if and eq get xt 0 1 eq k 17 |
| 1885 | xbranch 1 |
| 1886 | ret |
| 1887 | end |
| 1888 | if eq get mdev 0 1 |
| 1889 | ofvd k |
| 1890 | ret |
| 1891 | end |
| 1892 | c = ulong 0 |
| 1893 | for i ulong len fv |
| 1894 | b = get fv i |
| 1895 | if eq b 126 |
| 1896 | c = add c 1 |
| 1897 | else |
| 1898 | if eq c k |
| 1899 | ob b |
| 1900 | end |
| 1901 | end |
| 1902 | end |
| 1903 | end |
| 1904 | fn otn k ulong to void |
| 1905 | c = ulong 0 |
| 1906 | for i ulong len tn |
| 1907 | b = get tn i |
| 1908 | if eq b 126 |
| 1909 | c = add c 1 |
| 1910 | else |
| 1911 | if eq c k |
| 1912 | ob b |
| 1913 | end |
| 1914 | end |
| 1915 | end |
| 1916 | end |
| 1917 | note ---- SHA-256 of the unit's source bytes (the identity's src) ---- |
| 1918 | note rr: a 32-bit value rotated right by n (1 .. 31). |
| 1919 | fn rr x ulong n ulong to ulong |
| 1920 | ret and or shr x n shl x sub 32 n 4294967295 |
| 1921 | end |
| 1922 | fn sg0 a ulong to ulong |
| 1923 | ret xor xor rr a 2 rr a 13 rr a 22 |
| 1924 | end |
| 1925 | fn sg1 e ulong to ulong |
| 1926 | ret xor xor rr e 6 rr e 11 rr e 25 |
| 1927 | end |
| 1928 | fn chf e ulong f ulong g ulong to ulong |
| 1929 | ret xor and e f and xor e 4294967295 g |
| 1930 | end |
| 1931 | fn mjf a ulong b ulong c ulong to ulong |
| 1932 | ret xor xor and a b and a c and b c |
| 1933 | end |
| 1934 | note shkin: K and the initial hash value from shx. |
| 1935 | fn shkin to void |
| 1936 | for i ulong 72 |
| 1937 | v = ulong 0 |
| 1938 | for j ulong 8 |
| 1939 | c = ulong get shx add mul i 8 j |
| 1940 | if lt c 58 |
| 1941 | v = or shl v 4 sub c 48 |
| 1942 | else |
| 1943 | v = or shl v 4 sub c 87 |
| 1944 | end |
| 1945 | end |
| 1946 | put shk i v |
| 1947 | end |
| 1948 | for i ulong 8 |
| 1949 | put shh i get shk add 64 i |
| 1950 | end |
| 1951 | end |
| 1952 | note shsch: the message schedule shw of the block in shb. |
| 1953 | fn shsch to void |
| 1954 | for i ulong 16 |
| 1955 | j = mul i 4 |
| 1956 | v = shl ulong get shb j 24 |
| 1957 | v = or v shl ulong get shb add j 1 16 |
| 1958 | v = or v shl ulong get shb add j 2 8 |
| 1959 | v = or v ulong get shb add j 3 |
| 1960 | put shw i v |
| 1961 | end |
| 1962 | for i ulong 48 |
| 1963 | t = add i 16 |
| 1964 | x = get shw sub t 15 |
| 1965 | y = get shw sub t 2 |
| 1966 | s0 = xor xor rr x 7 rr x 18 shr x 3 |
| 1967 | s1 = xor xor rr y 17 rr y 19 shr y 10 |
| 1968 | x = and add get shw sub t 16 s0 4294967295 |
| 1969 | put shw t and add add x get shw sub t 7 s1 4294967295 |
| 1970 | end |
| 1971 | end |
| 1972 | note shrnd: round i on the working words shv (a .. h): the words move down one place, e and a get |
| 1973 | note the new values. |
| 1974 | fn shrnd i ulong to void |
| 1975 | e = get shv 4 |
| 1976 | t1 = add add get shv 7 sg1 e chf e get shv 5 get shv 6 |
| 1977 | t1 = and add add t1 get shk i get shw i 4294967295 |
| 1978 | a = get shv 0 |
| 1979 | t2 = and add sg0 a mjf a get shv 1 get shv 2 4294967295 |
| 1980 | for j ulong 7 |
| 1981 | k = sub 7 j |
| 1982 | put shv k get shv sub k 1 |
| 1983 | end |
| 1984 | put shv 4 and add get shv 4 t1 4294967295 |
| 1985 | put shv 0 and add t1 t2 4294967295 |
| 1986 | end |
| 1987 | note shblk: one 64-byte block of shb into the hash value shh. |
| 1988 | fn shblk to void |
| 1989 | shsch |
| 1990 | for i ulong 8 |
| 1991 | put shv i get shh i |
| 1992 | end |
| 1993 | for i ulong 64 |
| 1994 | shrnd i |
| 1995 | end |
| 1996 | for i ulong 8 |
| 1997 | put shh i and add get shh i get shv i 4294967295 |
| 1998 | end |
| 1999 | end |
| 2000 | note shpad: byte k of the padded message inb[p .. p+n): the bytes, 0x80, zeros, then from lb the bit |
| 2001 | note length, big endian. |
| 2002 | fn shpad p ulong n ulong k ulong lb ulong to ulong |
| 2003 | if lt k n |
| 2004 | ret ulong get inb add p k |
| 2005 | end |
| 2006 | if eq k n |
| 2007 | ret 128 |
| 2008 | end |
| 2009 | if ge k lb |
| 2010 | ret and shr mul n 8 mul sub 7 sub k lb 8 255 |
| 2011 | end |
| 2012 | ret 0 |
| 2013 | end |
| 2014 | note shsrc: the SHA-256 of inb[p .. q) into shh. |
| 2015 | fn shsrc p ulong q ulong to void |
| 2016 | shkin |
| 2017 | n = sub q p |
| 2018 | nb = div add n 72 64 |
| 2019 | lb = sub mul nb 64 8 |
| 2020 | for bk ulong nb |
| 2021 | for i ulong 64 |
| 2022 | put shb i uchar shpad p n add mul bk 64 i lb |
| 2023 | end |
| 2024 | shblk |
| 2025 | end |
| 2026 | end |
| 2027 | note ohx8: shh as 64 lowercase hex digits. |
| 2028 | fn ohx8 to void |
| 2029 | for i ulong 8 |
| 2030 | w = get shh i |
| 2031 | for j ulong 8 |
| 2032 | ob get hx and shr w sub 28 mul j 4 15 |
| 2033 | end |
| 2034 | end |
| 2035 | end |
| 2036 | note ---- reading OM-2 units ---- |
| 2037 | note tvis: 1 when token k is the OM-2 word kv[o .. o+n-1], else 0. |
| 2038 | fn tvis k ulong o ulong n ulong to ulong |
| 2039 | s = get tks k |
| 2040 | e = get tke k |
| 2041 | if ne sub e s n |
| 2042 | ret 0 |
| 2043 | end |
| 2044 | for j ulong n |
| 2045 | if ne get inb add s j get kv add o j |
| 2046 | ret 0 |
| 2047 | end |
| 2048 | end |
| 2049 | ret 1 |
| 2050 | end |
| 2051 | note atkv: 1 when the bytes at i (below q) are kv[o .. o+n-1], else 0. |
| 2052 | fn atkv i ulong q ulong o ulong n ulong to ulong |
| 2053 | if gt add i n q |
| 2054 | ret 0 |
| 2055 | end |
| 2056 | for j ulong n |
| 2057 | if ne get inb add i j get kv add o j |
| 2058 | ret 0 |
| 2059 | end |
| 2060 | end |
| 2061 | ret 1 |
| 2062 | end |
| 2063 | note atsp: 1 when the byte at i (below q) is a space, else 0. |
| 2064 | fn atsp i ulong q ulong to ulong |
| 2065 | if ge i q |
| 2066 | ret 0 |
| 2067 | end |
| 2068 | if ne get inb i 32 |
| 2069 | ret 0 |
| 2070 | end |
| 2071 | ret 1 |
| 2072 | end |
| 2073 | note lend: where the line starting at i ends (its newline, or q). |
| 2074 | fn lend i ulong q ulong to ulong |
| 2075 | e = i |
| 2076 | while and lt e q ne get inb e 10 |
| 2077 | e = add e 1 |
| 2078 | end |
| 2079 | ret e |
| 2080 | end |
| 2081 | note isexp / islay / isbrn: the line at i starts with "export fn " / "layout " / "note bridge ". |
| 2082 | fn isexp i ulong q ulong to ulong |
| 2083 | if and eq atkv i q 0 6 1 eq atsp add i 6 q 1 |
| 2084 | if and eq atkv add i 7 q 6 2 1 eq atsp add i 9 q 1 |
| 2085 | ret 1 |
| 2086 | end |
| 2087 | end |
| 2088 | ret 0 |
| 2089 | end |
| 2090 | fn islay i ulong q ulong to ulong |
| 2091 | if and eq atkv i q 36 6 1 eq atsp add i 6 q 1 |
| 2092 | ret 1 |
| 2093 | end |
| 2094 | ret 0 |
| 2095 | end |
| 2096 | fn isbrn i ulong q ulong to ulong |
| 2097 | if and eq atkv i q 50 4 1 eq atsp add i 4 q 1 |
| 2098 | if and eq atkv add i 5 q 54 6 1 eq atsp add i 11 q 1 |
| 2099 | ret 1 |
| 2100 | end |
| 2101 | end |
| 2102 | ret 0 |
| 2103 | end |
| 2104 | note prof: 1 when the unit p .. q-1 is OM-2: its first line that is not a note (a line whose first word |
| 2105 | note is note) is exactly om2; else 0. A first such line that starts with the word om2 but is not exactly |
| 2106 | note om2 (om2 diag, om2 fmt) is refused: that unit is not compiled to code. |
| 2107 | fn prof p ulong q ulong to ulong |
| 2108 | i = p |
| 2109 | while lt i q |
| 2110 | e = lend i q |
| 2111 | s = i |
| 2112 | while and lt s e eq get inb s 32 |
| 2113 | s = add s 1 |
| 2114 | end |
| 2115 | nt = ulong 0 |
| 2116 | if eq atkv s e 50 4 1 |
| 2117 | if or eq add s 4 e eq atsp add s 4 e 1 |
| 2118 | nt = 1 |
| 2119 | end |
| 2120 | end |
| 2121 | if eq nt 0 |
| 2122 | if and eq s i eq sub e i 3 |
| 2123 | if eq atkv i e 11 3 1 |
| 2124 | ret 1 |
| 2125 | end |
| 2126 | end |
| 2127 | if eq atkv s e 11 3 1 |
| 2128 | if or eq add s 3 e eq atsp add s 3 e 1 |
| 2129 | trap 10 |
| 2130 | end |
| 2131 | end |
| 2132 | ret 0 |
| 2133 | end |
| 2134 | i = add e 1 |
| 2135 | end |
| 2136 | ret 0 |
| 2137 | end |
| 2138 | note ismain: 1 when bytes s .. e-1 are main. |
| 2139 | fn ismain s ulong e ulong to ulong |
| 2140 | if ne sub e s 4 |
| 2141 | ret 0 |
| 2142 | end |
| 2143 | for j ulong 4 |
| 2144 | if ne get inb add s j get kw add 28 j |
| 2145 | ret 0 |
| 2146 | end |
| 2147 | end |
| 2148 | ret 1 |
| 2149 | end |
| 2150 | note bname: refuse a bound name that is not a C identifier, is main, or repeats an earlier bound name |
| 2151 | note (v1 unit names and v2 exports share one table: their symbols and wrappers must not collide). |
| 2152 | fn bname s ulong e ulong to void |
| 2153 | if eq cidr s e 0 |
| 2154 | trap 10 |
| 2155 | end |
| 2156 | if eq ismain s e 1 |
| 2157 | trap 10 |
| 2158 | end |
| 2159 | n = get st 4 |
| 2160 | if ge n len us |
| 2161 | trap 10 |
| 2162 | end |
| 2163 | for j ulong n |
| 2164 | if eq samenm s e get us j get ue j 1 |
| 2165 | trap 10 |
| 2166 | end |
| 2167 | end |
| 2168 | put us n s |
| 2169 | put ue n e |
| 2170 | put st 4 add n 1 |
| 2171 | end |
| 2172 | note tyix: token k as an element type: 0 uchar, 1 ushort, 2 uint, 3 ulong, 4 byte, 5 short, 6 int, 7 long; |
| 2173 | note 8 when it is none of them. Its size is 1 << (type and 3). |
| 2174 | fn tyix k ulong to ulong |
| 2175 | if eq tkis k 19 5 1 |
| 2176 | ret 0 |
| 2177 | end |
| 2178 | if eq tvis k 14 6 1 |
| 2179 | ret 1 |
| 2180 | end |
| 2181 | if eq tvis k 20 4 1 |
| 2182 | ret 2 |
| 2183 | end |
| 2184 | if eq tkis k 10 5 1 |
| 2185 | ret 3 |
| 2186 | end |
| 2187 | if eq tvis k 24 4 1 |
| 2188 | ret 4 |
| 2189 | end |
| 2190 | if eq tvis k 28 5 1 |
| 2191 | ret 5 |
| 2192 | end |
| 2193 | if eq tvis k 33 3 1 |
| 2194 | ret 6 |
| 2195 | end |
| 2196 | if eq tkis k 15 4 1 |
| 2197 | ret 7 |
| 2198 | end |
| 2199 | ret 8 |
| 2200 | end |
| 2201 | fn tsize t ulong to ulong |
| 2202 | ret shl 1 and t 3 |
| 2203 | end |
| 2204 | note lyfind: the index of the unit's layout named by token k (s2 10 when there is none). |
| 2205 | fn lyfind k ulong to ulong |
| 2206 | n = get s2 10 |
| 2207 | for j ulong n |
| 2208 | if eq samenm get tks k get tke k get lys j get lye j 1 |
| 2209 | ret j |
| 2210 | end |
| 2211 | end |
| 2212 | ret n |
| 2213 | end |
| 2214 | note lays: the unit's layouts (`layout NAME SIZE` lines) and their C names (`note bridge c-type L CNAME`, |
| 2215 | note else L); a `note bridge` line that is neither c-type nor c-define is refused. |
| 2216 | fn lays p ulong q ulong to void |
| 2217 | put s2 10 0 |
| 2218 | i = p |
| 2219 | while lt i q |
| 2220 | e = lend i q |
| 2221 | if eq islay i q 1 |
| 2222 | if ne tokln i q 3 |
| 2223 | trap 10 |
| 2224 | end |
| 2225 | n = get s2 10 |
| 2226 | if ge n 32 |
| 2227 | trap 10 |
| 2228 | end |
| 2229 | if eq cidr get tks 1 get tke 1 0 |
| 2230 | trap 10 |
| 2231 | end |
| 2232 | if lt lyfind 1 n |
| 2233 | trap 10 |
| 2234 | end |
| 2235 | z = tknum 2 |
| 2236 | if gt z 4096 |
| 2237 | trap 10 |
| 2238 | end |
| 2239 | put lys n get tks 1 |
| 2240 | put lye n get tke 1 |
| 2241 | put lcs n get tks 1 |
| 2242 | put lce n get tke 1 |
| 2243 | put lyz n z |
| 2244 | put lyl n i |
| 2245 | put s2 10 add n 1 |
| 2246 | end |
| 2247 | i = add e 1 |
| 2248 | end |
| 2249 | i = p |
| 2250 | while lt i q |
| 2251 | e = lend i q |
| 2252 | if eq isbrn i q 1 |
| 2253 | if ne tokln i q 5 |
| 2254 | trap 10 |
| 2255 | end |
| 2256 | if eq cidr get tks 3 get tke 3 0 |
| 2257 | trap 10 |
| 2258 | end |
| 2259 | if eq tvis 2 60 6 1 |
| 2260 | li = lyfind 3 |
| 2261 | if ge li get s2 10 |
| 2262 | trap 10 |
| 2263 | end |
| 2264 | if eq cidr get tks 4 get tke 4 0 |
| 2265 | trap 10 |
| 2266 | end |
| 2267 | put lcs li get tks 4 |
| 2268 | put lce li get tke 4 |
| 2269 | else |
| 2270 | if eq tvis 2 66 8 0 |
| 2271 | trap 10 |
| 2272 | end |
| 2273 | x = tknum 4 |
| 2274 | end |
| 2275 | end |
| 2276 | i = add e 1 |
| 2277 | end |
| 2278 | end |
| 2279 | note exps: the starts of the unit's `export fn` lines, in source order, into exl; their count into s2 4. |
| 2280 | fn exps p ulong q ulong to ulong |
| 2281 | n = ulong 0 |
| 2282 | ls = p |
| 2283 | i = p |
| 2284 | while lt i q |
| 2285 | if eq i ls |
| 2286 | if eq isexp i q 1 |
| 2287 | if ge n 32 |
| 2288 | trap 10 |
| 2289 | end |
| 2290 | put exl n i |
| 2291 | n = add n 1 |
| 2292 | end |
| 2293 | end |
| 2294 | if eq get inb i 10 |
| 2295 | ls = add i 1 |
| 2296 | end |
| 2297 | i = add i 1 |
| 2298 | end |
| 2299 | put s2 4 n |
| 2300 | ret n |
| 2301 | end |
| 2302 | note trail: the line `omega-unit NAME OMC` at i; the unit name must be new. Returns where the next unit |
| 2303 | note starts. |
| 2304 | fn trail i ulong to ulong |
| 2305 | t = get st 0 |
| 2306 | if ge i t |
| 2307 | trap 10 |
| 2308 | end |
| 2309 | if ne tokln i t 3 |
| 2310 | trap 10 |
| 2311 | end |
| 2312 | e = get st 7 |
| 2313 | if ge e t |
| 2314 | trap 10 |
| 2315 | end |
| 2316 | if eq tvis 0 86 10 0 |
| 2317 | trap 10 |
| 2318 | end |
| 2319 | s = get tks 1 |
| 2320 | x = get tke 1 |
| 2321 | if eq cidr s x 0 |
| 2322 | trap 10 |
| 2323 | end |
| 2324 | n = get s2 11 |
| 2325 | if ge n len uns |
| 2326 | trap 10 |
| 2327 | end |
| 2328 | for j ulong n |
| 2329 | if eq samenm s x get uns j get une j 1 |
| 2330 | trap 10 |
| 2331 | end |
| 2332 | end |
| 2333 | put uns n s |
| 2334 | put une n x |
| 2335 | put s2 11 add n 1 |
| 2336 | put s2 1 s |
| 2337 | put s2 2 x |
| 2338 | h = get tks 2 |
| 2339 | if ne sub get tke 2 h 64 |
| 2340 | trap 10 |
| 2341 | end |
| 2342 | for j ulong 64 |
| 2343 | c = get inb add h j |
| 2344 | if and or lt c 48 gt c 57 or lt c 97 gt c 102 |
| 2345 | trap 10 |
| 2346 | end |
| 2347 | end |
| 2348 | put s2 3 h |
| 2349 | ret add e 1 |
| 2350 | end |
| 2351 | note pparam2: record the OM-2 parameter at token k as parameter st 2; return the token after it. |
| 2352 | fn pparam2 k ulong nt ulong to ulong |
| 2353 | np = get st 2 |
| 2354 | if ge np 6 |
| 2355 | trap 10 |
| 2356 | end |
| 2357 | if ge add k 1 nt |
| 2358 | trap 10 |
| 2359 | end |
| 2360 | put ps np get tks k |
| 2361 | put pe np get tke k |
| 2362 | pname get tks k get tke k |
| 2363 | put st 2 add np 1 |
| 2364 | sl = get s2 5 |
| 2365 | put qs np sl |
| 2366 | put qm np 0 |
| 2367 | ty = add k 1 |
| 2368 | x = tyix ty |
| 2369 | if or eq x 3 eq x 7 |
| 2370 | put qk np 1 |
| 2371 | put qt np x |
| 2372 | put s2 5 add sl 1 |
| 2373 | ret add k 2 |
| 2374 | end |
| 2375 | if ge add k 3 nt |
| 2376 | trap 10 |
| 2377 | end |
| 2378 | if eq tvis ty 8 3 1 |
| 2379 | t = tyix add k 2 |
| 2380 | if eq t 8 |
| 2381 | trap 10 |
| 2382 | end |
| 2383 | n = tknum add k 3 |
| 2384 | if or eq n 0 gt n 65536 |
| 2385 | trap 10 |
| 2386 | end |
| 2387 | ob2 = add get s2 9 mul n tsize t |
| 2388 | if gt ob2 65536 |
| 2389 | trap 10 |
| 2390 | end |
| 2391 | put s2 9 ob2 |
| 2392 | put qk np 5 |
| 2393 | put qm np 1 |
| 2394 | put qt np t |
| 2395 | put qn np n |
| 2396 | put s2 5 add sl 1 |
| 2397 | ret add k 4 |
| 2398 | end |
| 2399 | m = ulong 2 |
| 2400 | if eq tkis ty 2 4 1 |
| 2401 | m = 1 |
| 2402 | end |
| 2403 | if eq tkis ty 6 4 1 |
| 2404 | m = 0 |
| 2405 | end |
| 2406 | if eq m 2 |
| 2407 | trap 10 |
| 2408 | end |
| 2409 | put qm np m |
| 2410 | t = tyix add k 2 |
| 2411 | if eq t 8 |
| 2412 | li = lyfind add k 2 |
| 2413 | if ge li get s2 10 |
| 2414 | trap 10 |
| 2415 | end |
| 2416 | put qk np 4 |
| 2417 | put ql np li |
| 2418 | put qn np get lyz li |
| 2419 | put s2 5 add sl 1 |
| 2420 | ret add k 3 |
| 2421 | end |
| 2422 | if ge add k 3 nt |
| 2423 | trap 10 |
| 2424 | end |
| 2425 | put qt np t |
| 2426 | if eq tvis add k 3 83 1 1 |
| 2427 | put qk np 3 |
| 2428 | put s2 5 add sl 2 |
| 2429 | ret add k 4 |
| 2430 | end |
| 2431 | n = tknum add k 3 |
| 2432 | if or eq n 0 gt n 16777216 |
| 2433 | trap 10 |
| 2434 | end |
| 2435 | put qk np 2 |
| 2436 | put qn np n |
| 2437 | put s2 5 add sl 1 |
| 2438 | ret add k 4 |
| 2439 | end |
| 2440 | note parse2: the OM-2 signature line at fl (`export fn NAME ...` or `fn NAME ...`): its parameters into |
| 2441 | note ps pe q*, their count into st 2, slots s2 5, has a value s2 8, result type s2 18, name s2 16 17. |
| 2442 | fn parse2 fl ulong q ulong to void |
| 2443 | put st 6 fl |
| 2444 | nt = tokln fl q |
| 2445 | ni = ulong 1 |
| 2446 | if eq tvis 0 0 6 1 |
| 2447 | if eq tvis 1 6 2 0 |
| 2448 | trap 10 |
| 2449 | end |
| 2450 | ni = 2 |
| 2451 | end |
| 2452 | if lt nt add ni 3 |
| 2453 | trap 10 |
| 2454 | end |
| 2455 | bname get tks ni get tke ni |
| 2456 | put s2 16 get tks ni |
| 2457 | put s2 17 get tke ni |
| 2458 | put st 2 0 |
| 2459 | put s2 5 0 |
| 2460 | put s2 9 0 |
| 2461 | k = add ni 1 |
| 2462 | while eq tkis k 0 2 0 |
| 2463 | k = pparam2 k nt |
| 2464 | if ge k nt |
| 2465 | trap 10 |
| 2466 | end |
| 2467 | end |
| 2468 | if ne add k 2 nt |
| 2469 | trap 10 |
| 2470 | end |
| 2471 | if gt get s2 5 6 |
| 2472 | trap 10 |
| 2473 | end |
| 2474 | r = add k 1 |
| 2475 | put s2 8 1 |
| 2476 | put s2 18 3 |
| 2477 | if eq tkis r 15 4 1 |
| 2478 | put s2 18 7 |
| 2479 | else |
| 2480 | if eq tkis r 24 4 1 |
| 2481 | put s2 8 0 |
| 2482 | put s2 18 9 |
| 2483 | else |
| 2484 | if eq tkis r 10 5 0 |
| 2485 | trap 10 |
| 2486 | end |
| 2487 | end |
| 2488 | end |
| 2489 | end |
| 2490 | note ---- writing OM-2 units ---- |
| 2491 | fn oun to void |
| 2492 | orng get s2 1 get s2 2 |
| 2493 | end |
| 2494 | fn oen to void |
| 2495 | orng get s2 16 get s2 17 |
| 2496 | end |
| 2497 | note oid: the identity: omega-ident 1 unit=NAME abi=2 profile=OM-2 src=SHA256 omc=SHA256. |
| 2498 | fn oid to void |
| 2499 | ofv 11 |
| 2500 | oun |
| 2501 | ofv 12 |
| 2502 | ohx8 |
| 2503 | ofv 13 |
| 2504 | h = get s2 3 |
| 2505 | orng h add h 64 |
| 2506 | ohost |
| 2507 | end |
| 2508 | note ohost: " host=W,W" naming the host words the unit uses (hm) in hw order; nothing when it uses none. |
| 2509 | fn ohost to void |
| 2510 | c = ulong 0 |
| 2511 | for k ulong len hm |
| 2512 | c = add c ulong get hm k |
| 2513 | end |
| 2514 | if eq c 0 |
| 2515 | ret |
| 2516 | end |
| 2517 | for j ulong len hpre |
| 2518 | ob get hpre j |
| 2519 | end |
| 2520 | c = ulong 0 |
| 2521 | k = ulong 0 |
| 2522 | i = ulong 1 |
| 2523 | while lt k 83 |
| 2524 | j = i |
| 2525 | while ne get hw j 124 |
| 2526 | j = add j 1 |
| 2527 | end |
| 2528 | if ne get hm k 0 |
| 2529 | if gt c 0 |
| 2530 | ob uchar 44 |
| 2531 | end |
| 2532 | for x ulong sub j i |
| 2533 | ob get hw add i x |
| 2534 | end |
| 2535 | c = add c 1 |
| 2536 | end |
| 2537 | k = add k 1 |
| 2538 | i = add j 1 |
| 2539 | end |
| 2540 | end |
| 2541 | fn esz j ulong to ulong |
| 2542 | ret tsize get qt j |
| 2543 | end |
| 2544 | note hasln: 1 when parameter j carries a count (a sized or unsized array). |
| 2545 | fn hasln j ulong to ulong |
| 2546 | if or eq get qk j 2 eq get qk j 3 |
| 2547 | ret 1 |
| 2548 | end |
| 2549 | ret 0 |
| 2550 | end |
| 2551 | note cpar: the C parameter list (the library and the header). |
| 2552 | fn cpar to void |
| 2553 | for j ulong get st 2 |
| 2554 | x = get qk j |
| 2555 | if eq x 1 |
| 2556 | ofv 25 |
| 2557 | opn j |
| 2558 | else |
| 2559 | ofv 26 |
| 2560 | if eq get qm j 0 |
| 2561 | ofv 27 |
| 2562 | end |
| 2563 | if eq x 4 |
| 2564 | otn 0 |
| 2565 | else |
| 2566 | otn get qt j |
| 2567 | end |
| 2568 | ofv 28 |
| 2569 | opn j |
| 2570 | if eq hasln j 1 |
| 2571 | ofv 29 |
| 2572 | opn j |
| 2573 | ofv 30 |
| 2574 | end |
| 2575 | end |
| 2576 | end |
| 2577 | end |
| 2578 | note cslot: " a[S] = (uint64_t)(uintptr_t)o_N;" |
| 2579 | fn cslot j ulong to void |
| 2580 | ofv 36 |
| 2581 | odec get qs j |
| 2582 | ofv 37 |
| 2583 | opn j |
| 2584 | ofv 38 |
| 2585 | end |
| 2586 | note cbody: the checks of each parameter, in order, and its slot words. |
| 2587 | fn cbody to void |
| 2588 | for j ulong get st 2 |
| 2589 | x = get qk j |
| 2590 | if eq x 1 |
| 2591 | ofv 36 |
| 2592 | odec get qs j |
| 2593 | ofv 39 |
| 2594 | opn j |
| 2595 | ofv 38 |
| 2596 | end |
| 2597 | if eq x 2 |
| 2598 | ofv 31 |
| 2599 | opn j |
| 2600 | ofv 32 |
| 2601 | opn j |
| 2602 | ofv 33 |
| 2603 | odec get qn j |
| 2604 | ofv 34 |
| 2605 | odec esz j |
| 2606 | ofv 34 |
| 2607 | odec get qm j |
| 2608 | ofv 35 |
| 2609 | cslot j |
| 2610 | end |
| 2611 | if eq x 3 |
| 2612 | ofv 40 |
| 2613 | opn j |
| 2614 | ofv 32 |
| 2615 | opn j |
| 2616 | ofv 33 |
| 2617 | odec esz j |
| 2618 | ofv 34 |
| 2619 | odec get qm j |
| 2620 | ofv 35 |
| 2621 | cslot j |
| 2622 | ofv 36 |
| 2623 | odec add get qs j 1 |
| 2624 | ofv 39 |
| 2625 | opn j |
| 2626 | ofv 42 |
| 2627 | end |
| 2628 | if eq x 4 |
| 2629 | ofv 41 |
| 2630 | opn j |
| 2631 | ofv 26 |
| 2632 | odec get qn j |
| 2633 | ofv 34 |
| 2634 | ofv 47 |
| 2635 | odec get qm j |
| 2636 | ofv 35 |
| 2637 | cslot j |
| 2638 | end |
| 2639 | if eq x 5 |
| 2640 | ofv 41 |
| 2641 | opn j |
| 2642 | ofv 26 |
| 2643 | odec mul get qn j esz j |
| 2644 | ofv 34 |
| 2645 | odec esz j |
| 2646 | ofv 34 |
| 2647 | ofv 43 |
| 2648 | odec get qs j |
| 2649 | ofv 44 |
| 2650 | odec mul get qn j esz j |
| 2651 | ofv 45 |
| 2652 | opn j |
| 2653 | ofv 46 |
| 2654 | end |
| 2655 | end |
| 2656 | end |
| 2657 | note ecode2: the unit's code, embedded unchanged, at ombr2_code_<unit>. |
| 2658 | fn ecode2 to void |
| 2659 | if ne get xt 0 1 |
| 2660 | if eq hassvc get s2 13 get s2 14 1 |
| 2661 | ofr 28 |
| 2662 | oun |
| 2663 | ofr 29 |
| 2664 | end |
| 2665 | end |
| 2666 | ofv 1 |
| 2667 | oun |
| 2668 | ofv 2 |
| 2669 | oun |
| 2670 | ofv 3 |
| 2671 | oun |
| 2672 | c0 = get s2 13 |
| 2673 | if eq get xt 0 1 |
| 2674 | xcode c0 get s2 14 |
| 2675 | else |
| 2676 | ofv 4 |
| 2677 | for j ulong get s2 14 |
| 2678 | if gt j 0 |
| 2679 | ob uchar 44 |
| 2680 | end |
| 2681 | ohex get inb add c0 j |
| 2682 | end |
| 2683 | end |
| 2684 | ofv 5 |
| 2685 | ofv 6 |
| 2686 | oun |
| 2687 | ofv 7 |
| 2688 | oid |
| 2689 | ofv 8 |
| 2690 | oun |
| 2691 | ofv 9 |
| 2692 | oun |
| 2693 | ofv 10 |
| 2694 | end |
| 2695 | note cfsend: the end of an entry in output freest: its out buffers in the entry's own frame (each rounded up |
| 2696 | note to 16 bytes, as ombr2_run carves them), then the call of ombr2_run with that buffer. |
| 2697 | fn cfsend to void |
| 2698 | nb = ulong 0 |
| 2699 | for j ulong get st 2 |
| 2700 | if eq get qk j 5 |
| 2701 | nb = add nb mul div add mul get qn j tsize get qt j 15 16 16 |
| 2702 | end |
| 2703 | end |
| 2704 | if gt nb 0 |
| 2705 | ofq 1 |
| 2706 | odec nb |
| 2707 | ofq 2 |
| 2708 | end |
| 2709 | ofv 48 |
| 2710 | oen |
| 2711 | ofv 49 |
| 2712 | odec get s2 8 |
| 2713 | if gt nb 0 |
| 2714 | ofq 3 |
| 2715 | else |
| 2716 | ofq 4 |
| 2717 | end |
| 2718 | end |
| 2719 | fn oc k ulong to void |
| 2720 | c = ulong 0 |
| 2721 | for i ulong len ctxparts |
| 2722 | b = get ctxparts i |
| 2723 | if eq b 126 |
| 2724 | c = add c 1 |
| 2725 | else |
| 2726 | if eq c k |
| 2727 | ob b |
| 2728 | end |
| 2729 | end |
| 2730 | end |
| 2731 | end |
| 2732 | fn ccore ctx ulong to void |
| 2733 | ofv 21 |
| 2734 | osig |
| 2735 | ofv 22 |
| 2736 | if eq ctx 1 |
| 2737 | oc 0 |
| 2738 | end |
| 2739 | oen |
| 2740 | if eq ctx 1 |
| 2741 | oc 1 |
| 2742 | else |
| 2743 | ofv 23 |
| 2744 | end |
| 2745 | cpar |
| 2746 | ofv 24 |
| 2747 | cbody |
| 2748 | if eq get st 5 10 |
| 2749 | cfsend |
| 2750 | else |
| 2751 | if eq ctx 1 |
| 2752 | oc 2 |
| 2753 | else |
| 2754 | ofv 48 |
| 2755 | end |
| 2756 | oen |
| 2757 | ofv 49 |
| 2758 | odec get s2 8 |
| 2759 | ofv 50 |
| 2760 | end |
| 2761 | end |
| 2762 | note cone: one entry in C: its stub (bti c, a branch to word k of the code) and its function. |
| 2763 | fn cone to void |
| 2764 | ofv 14 |
| 2765 | oen |
| 2766 | ofv 15 |
| 2767 | oen |
| 2768 | ofv 16 |
| 2769 | oen |
| 2770 | ofv 17 |
| 2771 | oun |
| 2772 | ofv 18 |
| 2773 | stride = ulong 4 |
| 2774 | if eq get xt 0 1 |
| 2775 | stride = 6 |
| 2776 | end |
| 2777 | odec mul get s2 12 stride |
| 2778 | ofv 19 |
| 2779 | oen |
| 2780 | ofv 20 |
| 2781 | ccore 0 |
| 2782 | if eq get mdev 0 1 |
| 2783 | ccore 1 |
| 2784 | end |
| 2785 | end |
| 2786 | fn hone to void |
| 2787 | ofv 21 |
| 2788 | osig |
| 2789 | ofv 55 |
| 2790 | oen |
| 2791 | ofv 23 |
| 2792 | cpar |
| 2793 | ofv 56 |
| 2794 | if eq get mdev 0 1 |
| 2795 | ofv 21 |
| 2796 | osig |
| 2797 | ofv 55 |
| 2798 | oc 0 |
| 2799 | oen |
| 2800 | oc 1 |
| 2801 | cpar |
| 2802 | ofv 56 |
| 2803 | end |
| 2804 | end |
| 2805 | fn hid to void |
| 2806 | ofv 51 |
| 2807 | oun |
| 2808 | ofv 52 |
| 2809 | oid |
| 2810 | ofv 53 |
| 2811 | oun |
| 2812 | ofv 54 |
| 2813 | end |
| 2814 | note pyty: the ctypes type of the pointer of parameter j (a view of uchar takes bytes, as in v1). |
| 2815 | fn pyty j ulong to void |
| 2816 | x = get qk j |
| 2817 | t = get qt j |
| 2818 | if eq x 4 |
| 2819 | t = 0 |
| 2820 | end |
| 2821 | if and eq get qm j 0 eq t 0 |
| 2822 | ofv 64 |
| 2823 | else |
| 2824 | ofv 65 |
| 2825 | otn add 8 t |
| 2826 | ofv 66 |
| 2827 | end |
| 2828 | end |
| 2829 | fn pyone to void |
| 2830 | ofv 57 |
| 2831 | osig |
| 2832 | ofv 58 |
| 2833 | oen |
| 2834 | ofv 59 |
| 2835 | oen |
| 2836 | ofv 58 |
| 2837 | oen |
| 2838 | ofv 60 |
| 2839 | for j ulong get st 2 |
| 2840 | if eq get qk j 1 |
| 2841 | ofv 63 |
| 2842 | else |
| 2843 | pyty j |
| 2844 | if eq hasln j 1 |
| 2845 | ofv 63 |
| 2846 | end |
| 2847 | end |
| 2848 | end |
| 2849 | ofv 61 |
| 2850 | oen |
| 2851 | ofv 62 |
| 2852 | end |
| 2853 | fn pyid to void |
| 2854 | ofv 67 |
| 2855 | oun |
| 2856 | ofv 155 |
| 2857 | ofv 67 |
| 2858 | oun |
| 2859 | ofv 75 |
| 2860 | ofv 67 |
| 2861 | oun |
| 2862 | ofv 68 |
| 2863 | oun |
| 2864 | ofv 69 |
| 2865 | oun |
| 2866 | ofv 70 |
| 2867 | oid |
| 2868 | ofv 71 |
| 2869 | oun |
| 2870 | ofv 72 |
| 2871 | oun |
| 2872 | ofv 73 |
| 2873 | oun |
| 2874 | ofv 74 |
| 2875 | end |
| 2876 | note rzpar: the rust (z 0) or zig (z 1) parameter list. |
| 2877 | fn rzpar z ulong to void |
| 2878 | for j ulong get st 2 |
| 2879 | x = get qk j |
| 2880 | ofv 80 |
| 2881 | opn j |
| 2882 | if eq x 1 |
| 2883 | ofv 81 |
| 2884 | else |
| 2885 | if eq get qm j 0 |
| 2886 | if eq z 0 |
| 2887 | ofv 82 |
| 2888 | else |
| 2889 | ofv 93 |
| 2890 | end |
| 2891 | else |
| 2892 | if eq z 0 |
| 2893 | ofv 83 |
| 2894 | else |
| 2895 | ofv 94 |
| 2896 | end |
| 2897 | end |
| 2898 | t = get qt j |
| 2899 | if eq x 4 |
| 2900 | t = 0 |
| 2901 | end |
| 2902 | otn add 16 t |
| 2903 | if eq hasln j 1 |
| 2904 | ofv 80 |
| 2905 | opn j |
| 2906 | ofv 84 |
| 2907 | end |
| 2908 | end |
| 2909 | end |
| 2910 | end |
| 2911 | fn rsone to void |
| 2912 | ofv 76 |
| 2913 | osig |
| 2914 | ofv 77 |
| 2915 | oen |
| 2916 | ofv 78 |
| 2917 | rzpar 0 |
| 2918 | ofv 79 |
| 2919 | end |
| 2920 | fn rsid to void |
| 2921 | ofv 85 |
| 2922 | oun |
| 2923 | ofv 86 |
| 2924 | oun |
| 2925 | ofv 87 |
| 2926 | oid |
| 2927 | ofv 88 |
| 2928 | end |
| 2929 | fn zgone to void |
| 2930 | ofv 89 |
| 2931 | osig |
| 2932 | ofv 90 |
| 2933 | oen |
| 2934 | ofv 91 |
| 2935 | rzpar 1 |
| 2936 | ofv 92 |
| 2937 | end |
| 2938 | fn zgid to void |
| 2939 | ofv 95 |
| 2940 | oun |
| 2941 | ofv 96 |
| 2942 | oid |
| 2943 | ofv 97 |
| 2944 | oun |
| 2945 | ofv 98 |
| 2946 | end |
| 2947 | fn goone to void |
| 2948 | ofv 99 |
| 2949 | osig |
| 2950 | ofv 100 |
| 2951 | oen |
| 2952 | ofv 101 |
| 2953 | for j ulong get st 2 |
| 2954 | ofv 80 |
| 2955 | opn j |
| 2956 | if eq get qk j 1 |
| 2957 | ofv 105 |
| 2958 | else |
| 2959 | ofv 106 |
| 2960 | if eq hasln j 1 |
| 2961 | ofv 80 |
| 2962 | opn j |
| 2963 | ofv 107 |
| 2964 | end |
| 2965 | end |
| 2966 | end |
| 2967 | ofv 102 |
| 2968 | oen |
| 2969 | ofv 103 |
| 2970 | for j ulong get st 2 |
| 2971 | if eq get qk j 1 |
| 2972 | ofv 108 |
| 2973 | opn j |
| 2974 | ofv 109 |
| 2975 | else |
| 2976 | ofv 110 |
| 2977 | t = get qt j |
| 2978 | if eq get qk j 4 |
| 2979 | t = 0 |
| 2980 | end |
| 2981 | otn add 24 t |
| 2982 | ofv 111 |
| 2983 | opn j |
| 2984 | ofv 109 |
| 2985 | if eq hasln j 1 |
| 2986 | ofv 108 |
| 2987 | opn j |
| 2988 | ofv 112 |
| 2989 | end |
| 2990 | end |
| 2991 | end |
| 2992 | ofv 104 |
| 2993 | end |
| 2994 | fn goid to void |
| 2995 | ofv 113 |
| 2996 | oun |
| 2997 | ofv 114 |
| 2998 | oid |
| 2999 | ofv 115 |
| 3000 | oun |
| 3001 | ofv 116 |
| 3002 | oun |
| 3003 | ofv 117 |
| 3004 | end |
| 3005 | note ---- the api header (output api): layouts as C structs, exports as C functions ---- |
| 3006 | note adefs: `note bridge c-define NAME VALUE` lines as #define NAME VALUE. |
| 3007 | fn adefs p ulong q ulong to void |
| 3008 | i = p |
| 3009 | while lt i q |
| 3010 | e = lend i q |
| 3011 | if eq isbrn i q 1 |
| 3012 | x = tokln i q |
| 3013 | if eq tvis 2 66 8 1 |
| 3014 | ofv 120 |
| 3015 | oname 3 |
| 3016 | ofv 121 |
| 3017 | oname 4 |
| 3018 | ofv 75 |
| 3019 | end |
| 3020 | end |
| 3021 | i = add e 1 |
| 3022 | end |
| 3023 | end |
| 3024 | note afield: the field line just tokenized (nt tokens) into field slot n of a layout of z bytes: |
| 3025 | note field F T [COUNT] at OFF little|big; COUNT omitted is a scalar (fdc 0), given is an array. |
| 3026 | fn afield n ulong z ulong nt ulong to void |
| 3027 | o = ulong 3 |
| 3028 | put fdc n 0 |
| 3029 | if eq nt 7 |
| 3030 | c = tknum 3 |
| 3031 | if or eq c 0 gt c 4096 |
| 3032 | trap 10 |
| 3033 | end |
| 3034 | put fdc n c |
| 3035 | o = 4 |
| 3036 | else |
| 3037 | if ne nt 6 |
| 3038 | trap 10 |
| 3039 | end |
| 3040 | end |
| 3041 | if eq cidr get tks 1 get tke 1 0 |
| 3042 | trap 10 |
| 3043 | end |
| 3044 | t = tyix 2 |
| 3045 | if eq t 8 |
| 3046 | trap 10 |
| 3047 | end |
| 3048 | if eq tvis o 84 2 0 |
| 3049 | trap 10 |
| 3050 | end |
| 3051 | off = tknum add o 1 |
| 3052 | put fdb n 2 |
| 3053 | if eq tvis add o 2 74 6 1 |
| 3054 | put fdb n 0 |
| 3055 | end |
| 3056 | if eq tvis add o 2 80 3 1 |
| 3057 | put fdb n 1 |
| 3058 | end |
| 3059 | if eq get fdb n 2 |
| 3060 | trap 10 |
| 3061 | end |
| 3062 | c = get fdc n |
| 3063 | if eq c 0 |
| 3064 | c = 1 |
| 3065 | end |
| 3066 | if gt add off mul c tsize t z |
| 3067 | trap 10 |
| 3068 | end |
| 3069 | put fds n get tks 1 |
| 3070 | put fde n get tke 1 |
| 3071 | put fdt n t |
| 3072 | put fdo n off |
| 3073 | put fdu n 0 |
| 3074 | end |
| 3075 | note afpad: an explicit padding member for bytes a .. b-1. |
| 3076 | fn afpad a ulong b ulong to void |
| 3077 | if lt a b |
| 3078 | ofv 135 |
| 3079 | odec a |
| 3080 | ofv 133 |
| 3081 | odec sub b a |
| 3082 | ofv 134 |
| 3083 | end |
| 3084 | end |
| 3085 | note afmem: the member of field n: its type and count, or bytes when big-endian or misaligned. |
| 3086 | fn afmem n ulong to void |
| 3087 | t = get fdt n |
| 3088 | c = get fdc n |
| 3089 | z = tsize t |
| 3090 | ofv 132 |
| 3091 | if or eq get fdb n 1 ne rem get fdo n z 0 |
| 3092 | otn 0 |
| 3093 | ofv 121 |
| 3094 | orng get fds n get fde n |
| 3095 | ofv 133 |
| 3096 | if eq c 0 |
| 3097 | odec z |
| 3098 | else |
| 3099 | odec mul c z |
| 3100 | end |
| 3101 | ofv 134 |
| 3102 | else |
| 3103 | otn t |
| 3104 | ofv 121 |
| 3105 | orng get fds n get fde n |
| 3106 | if eq c 0 |
| 3107 | ofv 38 |
| 3108 | else |
| 3109 | ofv 133 |
| 3110 | odec c |
| 3111 | ofv 134 |
| 3112 | end |
| 3113 | end |
| 3114 | end |
| 3115 | note alrd: the field lines of layout li (up to its `end` line) into the field slots; returns their count. |
| 3116 | fn alrd li ulong to ulong |
| 3117 | z = get lyz li |
| 3118 | q = get s2 7 |
| 3119 | i = add lend get lyl li q 1 |
| 3120 | n = ulong 0 |
| 3121 | go = ulong 1 |
| 3122 | while eq go 1 |
| 3123 | if ge i q |
| 3124 | trap 10 |
| 3125 | end |
| 3126 | e = lend i q |
| 3127 | x = tokln i q |
| 3128 | if eq x 0 |
| 3129 | trap 10 |
| 3130 | end |
| 3131 | if eq tvis 0 47 3 1 |
| 3132 | if ne x 1 |
| 3133 | trap 10 |
| 3134 | end |
| 3135 | go = 0 |
| 3136 | else |
| 3137 | if eq tvis 0 42 5 0 |
| 3138 | trap 10 |
| 3139 | end |
| 3140 | if ge n 256 |
| 3141 | trap 10 |
| 3142 | end |
| 3143 | afield n z x |
| 3144 | n = add n 1 |
| 3145 | end |
| 3146 | i = add e 1 |
| 3147 | end |
| 3148 | ret n |
| 3149 | end |
| 3150 | note fdmin: the unused field (of n) with the lowest offset. |
| 3151 | fn fdmin n ulong to ulong |
| 3152 | b = ulong 256 |
| 3153 | for j ulong n |
| 3154 | if eq get fdu j 0 |
| 3155 | if eq b 256 |
| 3156 | b = j |
| 3157 | else |
| 3158 | if lt get fdo j get fdo b |
| 3159 | b = j |
| 3160 | end |
| 3161 | end |
| 3162 | end |
| 3163 | end |
| 3164 | put fdu b 1 |
| 3165 | ret b |
| 3166 | end |
| 3167 | note alay: layout li as a C struct with its members at their offsets (fields may be listed in any order; |
| 3168 | note an overlap is refused), then its size and every field offset checked by the C compiler. |
| 3169 | fn alay li ulong to void |
| 3170 | n = alrd li |
| 3171 | ofv 122 |
| 3172 | cur = ulong 0 |
| 3173 | for r ulong n |
| 3174 | b = fdmin n |
| 3175 | if lt get fdo b cur |
| 3176 | trap 10 |
| 3177 | end |
| 3178 | afpad cur get fdo b |
| 3179 | afmem b |
| 3180 | c = get fdc b |
| 3181 | if eq c 0 |
| 3182 | c = 1 |
| 3183 | end |
| 3184 | cur = add get fdo b mul c tsize get fdt b |
| 3185 | end |
| 3186 | afpad cur get lyz li |
| 3187 | ofv 123 |
| 3188 | orng get lcs li get lce li |
| 3189 | ofv 124 |
| 3190 | orng get lcs li get lce li |
| 3191 | ofv 125 |
| 3192 | odec get lyz li |
| 3193 | ofv 126 |
| 3194 | orng get lys li get lye li |
| 3195 | ofv 127 |
| 3196 | for j ulong n |
| 3197 | ofv 128 |
| 3198 | orng get lcs li get lce li |
| 3199 | ofv 129 |
| 3200 | orng get fds j get fde j |
| 3201 | ofv 125 |
| 3202 | odec get fdo j |
| 3203 | ofv 126 |
| 3204 | orng get lys li get lye li |
| 3205 | ofv 130 |
| 3206 | orng get fds j get fde j |
| 3207 | ofv 131 |
| 3208 | end |
| 3209 | end |
| 3210 | note apone: one export as a C function that aborts on a nonzero status: static inline in output api; |
| 3211 | note in apih its prototype only; in apic its out-of-line definition. |
| 3212 | fn apone to void |
| 3213 | ofv 21 |
| 3214 | osig |
| 3215 | if eq get st 5 7 |
| 3216 | ofv 136 |
| 3217 | else |
| 3218 | ofa 0 |
| 3219 | end |
| 3220 | if eq get s2 8 0 |
| 3221 | ofv 137 |
| 3222 | else |
| 3223 | if eq get s2 18 7 |
| 3224 | ofv 139 |
| 3225 | else |
| 3226 | ofv 138 |
| 3227 | end |
| 3228 | end |
| 3229 | ofv 121 |
| 3230 | oen |
| 3231 | ofv 140 |
| 3232 | if eq get st 2 0 |
| 3233 | ofv 137 |
| 3234 | end |
| 3235 | for j ulong get st 2 |
| 3236 | if gt j 0 |
| 3237 | ofv 147 |
| 3238 | end |
| 3239 | x = get qk j |
| 3240 | if eq x 1 |
| 3241 | otn get qt j |
| 3242 | ofv 148 |
| 3243 | opn j |
| 3244 | else |
| 3245 | if and eq get qm j 0 ne x 5 |
| 3246 | ofv 27 |
| 3247 | end |
| 3248 | if eq x 4 |
| 3249 | orng get lcs get ql j get lce get ql j |
| 3250 | else |
| 3251 | otn get qt j |
| 3252 | end |
| 3253 | if or eq x 3 eq x 4 |
| 3254 | ofv 149 |
| 3255 | opn j |
| 3256 | if eq x 3 |
| 3257 | ofv 150 |
| 3258 | opn j |
| 3259 | ofv 30 |
| 3260 | end |
| 3261 | else |
| 3262 | ofv 148 |
| 3263 | opn j |
| 3264 | ofv 133 |
| 3265 | odec get qn j |
| 3266 | ofv 154 |
| 3267 | end |
| 3268 | end |
| 3269 | end |
| 3270 | if eq get st 5 8 |
| 3271 | ofa 1 |
| 3272 | ret |
| 3273 | end |
| 3274 | ofv 141 |
| 3275 | oen |
| 3276 | ofv 142 |
| 3277 | for j ulong get st 2 |
| 3278 | x = get qk j |
| 3279 | if eq x 1 |
| 3280 | ofv 153 |
| 3281 | opn j |
| 3282 | end |
| 3283 | if or eq x 2 eq x 3 |
| 3284 | ofv 32 |
| 3285 | opn j |
| 3286 | if eq x 2 |
| 3287 | ofv 147 |
| 3288 | odec get qn j |
| 3289 | else |
| 3290 | ofv 32 |
| 3291 | opn j |
| 3292 | ofv 30 |
| 3293 | end |
| 3294 | end |
| 3295 | if eq x 4 |
| 3296 | if eq get qm j 0 |
| 3297 | ofv 152 |
| 3298 | else |
| 3299 | ofv 151 |
| 3300 | end |
| 3301 | opn j |
| 3302 | end |
| 3303 | if eq x 5 |
| 3304 | ofv 32 |
| 3305 | opn j |
| 3306 | end |
| 3307 | end |
| 3308 | if eq get st 5 12 |
| 3309 | ofq 5 |
| 3310 | else |
| 3311 | ofv 143 |
| 3312 | end |
| 3313 | if eq get s2 8 0 |
| 3314 | ofv 144 |
| 3315 | else |
| 3316 | if eq get s2 18 7 |
| 3317 | ofv 146 |
| 3318 | else |
| 3319 | ofv 145 |
| 3320 | end |
| 3321 | end |
| 3322 | end |
| 3323 | note eone2: the bound entry just parsed, in the output st 5. |
| 3324 | fn eone2 to void |
| 3325 | if eq get mdev 0 1 |
| 3326 | s = get s2 16 |
| 3327 | if ge sub get s2 17 s 4 |
| 3328 | if eq get inb s 99 |
| 3329 | if eq get inb add s 1 116 |
| 3330 | if eq get inb add s 2 120 |
| 3331 | if eq get inb add s 3 95 |
| 3332 | trap 10 |
| 3333 | end |
| 3334 | end |
| 3335 | end |
| 3336 | end |
| 3337 | end |
| 3338 | end |
| 3339 | m = get st 5 |
| 3340 | if or eq m 1 eq m 10 |
| 3341 | cone |
| 3342 | end |
| 3343 | if eq m 2 |
| 3344 | hone |
| 3345 | end |
| 3346 | if eq m 3 |
| 3347 | pyone |
| 3348 | end |
| 3349 | if eq m 4 |
| 3350 | rsone |
| 3351 | end |
| 3352 | if eq m 5 |
| 3353 | zgone |
| 3354 | end |
| 3355 | if eq m 6 |
| 3356 | goone |
| 3357 | end |
| 3358 | if or and ge m 7 le m 9 eq m 12 |
| 3359 | apone |
| 3360 | end |
| 3361 | end |
| 3362 | note unit2: accept the OM-2 unit p .. q-1 (q its 0 byte), emit it, return where the next unit starts. |
| 3363 | fn unit2 p ulong q ulong to ulong |
| 3364 | put s2 6 p |
| 3365 | put s2 7 q |
| 3366 | lays p q |
| 3367 | cl = codelen q |
| 3368 | c0 = add q 9 |
| 3369 | put s2 13 c0 |
| 3370 | put s2 14 cl |
| 3371 | nx = trail add c0 cl |
| 3372 | if eq get munit 0 1 |
| 3373 | h = get s2 3 |
| 3374 | for j ulong 64 |
| 3375 | b = get mappin j |
| 3376 | if eq get xt 0 1 |
| 3377 | b = get xmappin j |
| 3378 | end |
| 3379 | if ne get inb add h j b |
| 3380 | trap 10 |
| 3381 | end |
| 3382 | end |
| 3383 | end |
| 3384 | shsrc p q |
| 3385 | nex = exps p q |
| 3386 | stride = ulong 4 |
| 3387 | if eq get xt 0 1 |
| 3388 | stride = 6 |
| 3389 | end |
| 3390 | if gt mul nex stride cl |
| 3391 | trap 10 |
| 3392 | end |
| 3393 | m = get st 5 |
| 3394 | if or eq m 1 eq m 10 |
| 3395 | if eq get s2 0 0 |
| 3396 | if eq m 10 |
| 3397 | ofq 0 |
| 3398 | else |
| 3399 | ofv 0 |
| 3400 | end |
| 3401 | put s2 0 1 |
| 3402 | end |
| 3403 | ecode2 |
| 3404 | end |
| 3405 | if eq m 2 |
| 3406 | hid |
| 3407 | end |
| 3408 | if eq m 3 |
| 3409 | pyid |
| 3410 | end |
| 3411 | if eq m 5 |
| 3412 | zgid |
| 3413 | end |
| 3414 | if eq m 6 |
| 3415 | goid |
| 3416 | end |
| 3417 | if or eq m 7 eq m 8 |
| 3418 | adefs p q |
| 3419 | for li ulong get s2 10 |
| 3420 | alay li |
| 3421 | end |
| 3422 | end |
| 3423 | if eq nex 0 |
| 3424 | put s2 12 0 |
| 3425 | parse2 sigln p q q |
| 3426 | eone2 |
| 3427 | else |
| 3428 | for k ulong nex |
| 3429 | put s2 12 k |
| 3430 | parse2 get exl k q |
| 3431 | eone2 |
| 3432 | end |
| 3433 | end |
| 3434 | if eq m 4 |
| 3435 | rsid |
| 3436 | end |
| 3437 | if eq m 11 |
| 3438 | oid |
| 3439 | ob uchar 10 |
| 3440 | end |
| 3441 | ret nx |
| 3442 | end |
| 3443 | note hsep: 1 when byte b separates words for omc (space, tab, carriage return, newline, ( or )). |
| 3444 | fn hsep b uchar to ulong |
| 3445 | if eq hblank b 1 |
| 3446 | ret 1 |
| 3447 | end |
| 3448 | if or or eq b 10 eq b 40 eq b 41 |
| 3449 | ret 1 |
| 3450 | end |
| 3451 | ret 0 |
| 3452 | end |
| 3453 | note hblank: 1 when byte b is a blank for omc (space, tab, carriage return). |
| 3454 | fn hblank b uchar to ulong |
| 3455 | if or or eq b 32 eq b 9 eq b 13 |
| 3456 | ret 1 |
| 3457 | end |
| 3458 | ret 0 |
| 3459 | end |
| 3460 | note hwfind: k when bytes s .. x-1 are word k (from 1) of hw, else 0. |
| 3461 | fn hwfind s ulong x ulong to ulong |
| 3462 | n = sub x s |
| 3463 | k = ulong 0 |
| 3464 | i = ulong 1 |
| 3465 | while lt i len hw |
| 3466 | j = i |
| 3467 | while ne get hw j 124 |
| 3468 | j = add j 1 |
| 3469 | end |
| 3470 | k = add k 1 |
| 3471 | if eq sub j i n |
| 3472 | if eq hweq s i n 1 |
| 3473 | ret k |
| 3474 | end |
| 3475 | end |
| 3476 | i = add j 1 |
| 3477 | end |
| 3478 | ret 0 |
| 3479 | end |
| 3480 | fn hweq s ulong o ulong n ulong to ulong |
| 3481 | for j ulong n |
| 3482 | if ne get inb add s j get hw add o j |
| 3483 | ret 0 |
| 3484 | end |
| 3485 | end |
| 3486 | ret 1 |
| 3487 | end |
| 3488 | note hword: admit the nine file/identity words, clocks and device words only for hosted OM-2. |
| 3489 | fn hword k ulong v2 ulong to void |
| 3490 | if eq get hok 0 0 |
| 3491 | trap 10 |
| 3492 | end |
| 3493 | ok = ulong 0 |
| 3494 | if or or le k 9 eq k 18 eq k 27 |
| 3495 | ok = 1 |
| 3496 | end |
| 3497 | if or eq k 37 and ge k 66 le k 77 |
| 3498 | ok = 1 |
| 3499 | end |
| 3500 | if or eq ok 0 eq v2 0 |
| 3501 | trap 10 |
| 3502 | end |
| 3503 | put hm sub k 1 1 |
| 3504 | if or and ge k 67 le k 70 and ge k 73 le k 77 |
| 3505 | put mdev 0 1 |
| 3506 | put munit 0 1 |
| 3507 | end |
| 3508 | end |
| 3509 | note hline: every word of bytes s .. e-1 through hwfind and hword. |
| 3510 | fn hline s ulong e ulong v2 ulong to void |
| 3511 | i = s |
| 3512 | while lt i e |
| 3513 | if eq hsep get inb i 1 |
| 3514 | i = add i 1 |
| 3515 | else |
| 3516 | x = i |
| 3517 | while and lt x e eq hsep get inb x 0 |
| 3518 | x = add x 1 |
| 3519 | end |
| 3520 | k = hwfind i x |
| 3521 | if gt k 0 |
| 3522 | hword k v2 |
| 3523 | end |
| 3524 | i = x |
| 3525 | end |
| 3526 | end |
| 3527 | end |
| 3528 | note hscan: the host words of the unit at p .. q-1, split as omc splits words. A line whose first |
| 3529 | note blank-separated word is exactly note is skipped; a host word inside a text literal refuses the unit |
| 3530 | note too (fail closed). |
| 3531 | fn hscan p ulong q ulong v2 ulong to void |
| 3532 | put munit 0 0 |
| 3533 | for k ulong len hm |
| 3534 | put hm k 0 |
| 3535 | end |
| 3536 | i = p |
| 3537 | while lt i q |
| 3538 | e = lend i q |
| 3539 | s = i |
| 3540 | while and lt s e eq hblank get inb s 1 |
| 3541 | s = add s 1 |
| 3542 | end |
| 3543 | x = s |
| 3544 | while and lt x e eq hblank get inb x 0 |
| 3545 | x = add x 1 |
| 3546 | end |
| 3547 | nt = ulong 0 |
| 3548 | if eq sub x s 4 |
| 3549 | nt = atkv s e 50 4 |
| 3550 | end |
| 3551 | if eq nt 0 |
| 3552 | hline s e v2 |
| 3553 | end |
| 3554 | i = add e 1 |
| 3555 | end |
| 3556 | end |
| 3557 | note unit: accept the unit at p, emit it, return where the next unit starts. |
| 3558 | fn unit p ulong to ulong |
| 3559 | q = sepat p |
| 3560 | if eq get st 5 10 |
| 3561 | put fo2 0 prof p q |
| 3562 | fcheck p q |
| 3563 | end |
| 3564 | v = prof p q |
| 3565 | hscan p q v |
| 3566 | if eq v 1 |
| 3567 | ret unit2 p q |
| 3568 | end |
| 3569 | fl = sigln p q |
| 3570 | put st 9 p |
| 3571 | parse fl q |
| 3572 | cl = codelen q |
| 3573 | c0 = add q 9 |
| 3574 | emit c0 cl |
| 3575 | ret add c0 cl |
| 3576 | end |
| 3577 | note slurp: all of stdin into inb; refuse input that fills the pool. |
| 3578 | fn slurp to ulong |
| 3579 | t = ulong 0 |
| 3580 | k = read 0 inb 0 len inb |
| 3581 | while gt k 0 |
| 3582 | t = add t ulong k |
| 3583 | k = long 0 |
| 3584 | if lt t len inb |
| 3585 | k = read 0 inb t sub len inb t |
| 3586 | end |
| 3587 | end |
| 3588 | if lt k 0 |
| 3589 | trap 11 |
| 3590 | end |
| 3591 | if ge t len inb |
| 3592 | trap 6 |
| 3593 | end |
| 3594 | ret t |
| 3595 | end |
| 3596 | fn main to int |
| 3597 | m = rmode |
| 3598 | t = slurp |
| 3599 | put st 0 t |
| 3600 | put st 1 0 |
| 3601 | put st 4 0 |
| 3602 | put st 5 m |
| 3603 | if or eq m 1 eq m 2 |
| 3604 | p = ulong 0 |
| 3605 | while lt p t |
| 3606 | q = sepat p |
| 3607 | v = prof p q |
| 3608 | if eq get hok 0 1 |
| 3609 | hscan p q prof p q |
| 3610 | end |
| 3611 | p = add add q 9 codelen q |
| 3612 | if eq v 1 |
| 3613 | p = add lend p t 1 |
| 3614 | end |
| 3615 | end |
| 3616 | end |
| 3617 | if eq m 10 |
| 3618 | fpre |
| 3619 | end |
| 3620 | if eq m 1 |
| 3621 | opre |
| 3622 | else |
| 3623 | if eq m 2 |
| 3624 | ofb 0 |
| 3625 | if eq get mdev 0 1 |
| 3626 | oc 3 |
| 3627 | end |
| 3628 | end |
| 3629 | if eq m 3 |
| 3630 | ofb 12 |
| 3631 | end |
| 3632 | if eq m 4 |
| 3633 | ofb 22 |
| 3634 | end |
| 3635 | if eq m 5 |
| 3636 | ofb 35 |
| 3637 | end |
| 3638 | if eq m 6 |
| 3639 | ofb 47 |
| 3640 | end |
| 3641 | if eq m 7 |
| 3642 | ofv 118 |
| 3643 | end |
| 3644 | if eq m 8 |
| 3645 | ofa 2 |
| 3646 | end |
| 3647 | if eq m 9 |
| 3648 | ofa 3 |
| 3649 | end |
| 3650 | if eq m 12 |
| 3651 | ofq 6 |
| 3652 | end |
| 3653 | end |
| 3654 | p = ulong 0 |
| 3655 | nu = ulong 0 |
| 3656 | while lt p t |
| 3657 | p = unit p |
| 3658 | nu = add nu 1 |
| 3659 | end |
| 3660 | if eq nu 0 |
| 3661 | trap 10 |
| 3662 | end |
| 3663 | if eq m 2 |
| 3664 | ofb 11 |
| 3665 | end |
| 3666 | if eq m 4 |
| 3667 | ofb 34 |
| 3668 | end |
| 3669 | if or eq m 7 eq m 8 |
| 3670 | ofv 119 |
| 3671 | end |
| 3672 | o = ulong 0 |
| 3673 | m = get st 1 |
| 3674 | e = m |
| 3675 | if gt e len outb |
| 3676 | e = len outb |
| 3677 | end |
| 3678 | while lt o e |
| 3679 | w = write 1 outb o sub e o |
| 3680 | if le w 0 |
| 3681 | ret 1 |
| 3682 | end |
| 3683 | o = add o ulong w |
| 3684 | end |
| 3685 | o = ulong 0 |
| 3686 | e = sub m e |
| 3687 | while lt o e |
| 3688 | w = write 1 outc o sub e o |
| 3689 | if le w 0 |
| 3690 | ret 1 |
| 3691 | end |
| 3692 | o = add o ulong w |
| 3693 | end |
| 3694 | ret 0 |
| 3695 | end |