interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / ng / a64 / tests / macho / lib / libwrite.om

51 lines · 1141 bytes Raw Blame History
1target macos
2note libwrite: dlsym through libfn 1 and libcall, then write(1, msg, 35) through libcall. Status: the count that
3note write returned, 35; 2 when libfn gives a function for a number above 1. Stdout: the message.
4text s_write "write"
5text s_msg "hello from Omega through libSystem\n"
6
7fn p64 b edit uchar 128 o ulong v ulong to void
8for i ulong 8
9put b add o i uchar and shr v mul i 8 255
10end
11end
12
13fn g64 b view uchar 128 o ulong to ulong
14v = ulong 0
15for i ulong 8
16v = or v shl ulong get b add o i mul i 8
17end
18ret v
19end
20
21note the address of the library function named by the n bytes of nm (nm is zero after them)
22fn sym rg edit uchar 128 nm edit uchar 64 to ulong
23p64 rg 0 18446744073709551614
24p64 rg 8 ulong libptr nm 0 64
25ret ulong libcall ulong libfn 1 rg 0 128
26end
27
28fn main to int
29rg = new uchar 128 0
30nm = new uchar 64 0
31mb = new uchar 64 0
32for i ulong len s_msg
33put mb i get s_msg i
34end
35if ne libfn 2 0
36ret 2
37end
38if ne libfn 77 0
39ret 2
40end
41for i ulong len s_write
42put nm i get s_write i
43end
44put nm len s_write 0
45f = sym rg nm
46p64 rg 0 1
47p64 rg 8 ulong libptr mb 0 64
48p64 rg 16 len s_msg
49n = libcall f rg 0 128
50ret int n
51end