Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/ng/a64/tests/macho/lib/libwrite.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / ng / a64 / tests / macho / lib / libwrite.om` 51 lines ยท 1141 bytes Raw Blame History 1 target macos 2 note libwrite: dlsym through libfn 1 and libcall, then write(1, msg, 35) through libcall. Status: the count that 3 note write returned, 35; 2 when libfn gives a function for a number above 1. Stdout: the message. 4 text s_write "write" 5 text s_msg "hello from Omega through libSystem\n" 6 7 fn p64 b edit uchar 128 o ulong v ulong to void 8 for i ulong 8 9 put b add o i uchar and shr v mul i 8 255 10 end 11 end 12 13 fn g64 b view uchar 128 o ulong to ulong 14 v = ulong 0 15 for i ulong 8 16 v = or v shl ulong get b add o i mul i 8 17 end 18 ret v 19 end 20 21 note the address of the library function named by the n bytes of nm (nm is zero after them) 22 fn sym rg edit uchar 128 nm edit uchar 64 to ulong 23 p64 rg 0 `18446744073709551614` 24 p64 rg 8 ulong libptr nm 0 64 25 ret ulong libcall ulong libfn 1 rg 0 128 26 end 27 28 fn main to int 29 rg = new uchar 128 0 30 nm = new uchar 64 0 31 mb = new uchar 64 0 32 for i ulong len s_msg 33 put mb i get s_msg i 34 end 35 if ne libfn 2 0 36 ret 2 37 end 38 if ne libfn 77 0 39 ret 2 40 end 41 for i ulong len s_write 42 put nm i get s_write i 43 end 44 put nm len s_write 0 45 f = sym rg nm 46 p64 rg 0 1 47 p64 rg 8 ulong libptr mb 0 64 48 p64 rg 16 len s_msg 49 n = libcall f rg 0 128 50 ret int n 51 end