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 / libobjc.om

107 lines · 2164 bytes Raw Blame History
1target macos
2note libobjc: dlopen through libfn 0, then Objective-C messages. [[NSProcessInfo processInfo] processorCount]
3note must equal sysconf(57), the configured processors. Status 1; 2 to 6 name the step that failed.
4text s_fnd "/System/Library/Frameworks/Foundation.framework/Foundation"
5text s_gc "objc_getClass"
6text s_sr "sel_registerName"
7text s_ms "objc_msgSend"
8text s_sc "sysconf"
9text s_cls "NSProcessInfo"
10text s_pi "processInfo"
11text s_pc "processorCount"
12
13fn p64 b edit uchar 128 o ulong v ulong to void
14for i ulong 8
15put b add o i uchar and shr v mul i 8 255
16end
17end
18
19fn g64 b view uchar 128 o ulong to ulong
20v = ulong 0
21for i ulong 8
22v = or v shl ulong get b add o i mul i 8
23end
24ret v
25end
26
27note the address of the library function named by the n bytes of nm (nm is zero after them)
28fn sym rg edit uchar 128 nm edit uchar 64 to ulong
29p64 rg 0 18446744073709551614
30p64 rg 8 ulong libptr nm 0 64
31ret ulong libcall ulong libfn 1 rg 0 128
32end
33
34fn main to int
35rg = new uchar 128 0
36nm = new uchar 64 0
37for i ulong len s_fnd
38put nm i get s_fnd i
39end
40put nm len s_fnd 0
41p64 rg 0 ulong libptr nm 0 64
42p64 rg 8 2
43h = libcall ulong libfn 0 rg 0 128
44if eq h 0
45ret 2
46end
47for i ulong len s_gc
48put nm i get s_gc i
49end
50put nm len s_gc 0
51gc = sym rg nm
52for i ulong len s_sr
53put nm i get s_sr i
54end
55put nm len s_sr 0
56sr = sym rg nm
57for i ulong len s_ms
58put nm i get s_ms i
59end
60put nm len s_ms 0
61ms = sym rg nm
62for i ulong len s_sc
63put nm i get s_sc i
64end
65put nm len s_sc 0
66sc = sym rg nm
67if or or eq gc 0 eq sr 0 or eq ms 0 eq sc 0
68ret 3
69end
70for i ulong len s_cls
71put nm i get s_cls i
72end
73put nm len s_cls 0
74p64 rg 0 ulong libptr nm 0 64
75cls = libcall gc rg 0 128
76if eq cls 0
77ret 4
78end
79for i ulong len s_pi
80put nm i get s_pi i
81end
82put nm len s_pi 0
83p64 rg 0 ulong libptr nm 0 64
84sel = libcall sr rg 0 128
85p64 rg 0 g64 rg 0
86p64 rg 0 ulong cls
87p64 rg 8 ulong sel
88pi = libcall ms rg 0 128
89if eq pi 0
90ret 5
91end
92for i ulong len s_pc
93put nm i get s_pc i
94end
95put nm len s_pc 0
96p64 rg 0 ulong libptr nm 0 64
97sel = libcall sr rg 0 128
98p64 rg 0 ulong pi
99p64 rg 8 ulong sel
100n = libcall ms rg 0 128
101p64 rg 0 57
102c = libcall sc rg 0 128
103if or ne n c le n 0
104ret 6
105end
106ret 1
107end