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

155 lines · 3527 bytes Raw Blame History
1target macos
2note libbackobjc: an Objective-C class whose methods are Omega code. The program makes the class OmegaTarget
3note (objc_allocateClassPair), gives it the methods poke: (callback entry 0) and twice: (entry 3) with
4note class_addMethod, makes an object and sends both messages. libback must run once with k 0, the object, the
5note selector and the argument, then with k 3, and its result 2 * 21 must come back through objc_msgSend.
6note Status 1; 2 to 10 name the step that failed.
7text s_all "/System/Library/Frameworks/Foundation.framework/Foundationobjc_getClasssel_registerNameobjc_msgSendobjc_allocateClassPairclass_addMethodobjc_registerClassPairNSObjectOmegaTargetpoke:twice:v@:@Q@:QallocinitperformSelector:withObject:respondsToSelector:"
8global g_f ulong 6
9global g_b ulong 5
10
11fn p64 b edit uchar 128 o ulong v ulong to void
12for i ulong 8
13put b add o i uchar and shr v mul i 8 255
14end
15end
16
17fn g64 b view uchar 128 o ulong to ulong
18v = ulong 0
19for i ulong 8
20v = or v shl ulong get b add o i mul i 8
21end
22ret v
23end
24
25note the n bytes of s_all at o, then a zero byte, into nm
26fn ld nm edit uchar 256 o ulong n ulong to void
27for i ulong n
28put nm i get s_all add o i
29end
30put nm n 0
31end
32
33fn sym rg edit uchar 128 nm edit uchar 256 to ulong
34p64 rg 0 18446744073709551614
35p64 rg 8 ulong libptr nm 0 256
36lr = libcall ulong libfn 1 rg 0 128
37ret g64 rg 0
38end
39
40note library function w of g_f (0 objc_getClass, 1 sel_registerName) on the name at o
41fn one rg edit uchar 128 nm edit uchar 256 w ulong o ulong n ulong to ulong
42ld nm o n
43p64 rg 0 ulong libptr nm 0 256
44lr = libcall get g_f w rg 0 128
45ret g64 rg 0
46end
47
48note [obj s a b]; the answer is read from the register file (an object may have its top bit set)
49fn msg rg edit uchar 128 obj ulong s ulong a ulong b ulong to ulong
50p64 rg 0 obj
51p64 rg 8 s
52p64 rg 16 a
53p64 rg 24 b
54lr = libcall get g_f 2 rg 0 128
55ret g64 rg 0
56end
57
58fn libback k ulong a ulong b ulong c ulong d ulong e ulong to ulong
59put g_b 0 add get g_b 0 1
60put g_b 1 k
61put g_b 2 a
62put g_b 3 b
63put g_b 4 c
64if eq k 3
65ret mul c 2
66end
67ret 0
68end
69
70fn main to int
71rg = new uchar 128 0
72nm = new uchar 256 0
73nm2 = new uchar 256 0
74ld nm 0 58
75p64 rg 0 ulong libptr nm 0 256
76p64 rg 8 2
77lr = libcall ulong libfn 0 rg 0 128
78if eq g64 rg 0 0
79ret 2
80end
81ld nm 58 13
82put g_f 0 sym rg nm
83ld nm 71 16
84put g_f 1 sym rg nm
85ld nm 87 12
86put g_f 2 sym rg nm
87ld nm 99 22
88put g_f 3 sym rg nm
89ld nm 121 15
90put g_f 4 sym rg nm
91ld nm 136 22
92put g_f 5 sym rg nm
93for i ulong 6
94if eq get g_f i 0
95ret 3
96end
97end
98base = one rg nm 0 158 8
99ld nm 166 11
100p64 rg 0 base
101p64 rg 8 ulong libptr nm 0 256
102p64 rg 16 0
103lr = libcall get g_f 3 rg 0 128
104cl = g64 rg 0
105if eq cl 0
106ret 4
107end
108poke = one rg nm 1 177 5
109twice = one rg nm 1 182 6
110ld nm2 188 4
111p64 rg 0 cl
112p64 rg 8 poke
113p64 rg 16 ulong libfn 2
114p64 rg 24 ulong libptr nm2 0 256
115lr = libcall get g_f 4 rg 0 128
116if ne and g64 rg 0 255 1
117ret 5
118end
119ld nm2 192 4
120p64 rg 0 cl
121p64 rg 8 twice
122p64 rg 16 ulong libfn 5
123p64 rg 24 ulong libptr nm2 0 256
124lr = libcall get g_f 4 rg 0 128
125if ne and g64 rg 0 255 1
126ret 5
127end
128p64 rg 0 cl
129lr = libcall get g_f 5 rg 0 128
130s = one rg nm 1 196 5
131obj = msg rg cl s 0 0
132s = one rg nm 1 201 4
133obj = msg rg obj s 0 0
134if eq obj 0
135ret 6
136end
137s = one rg nm 1 205 27
138r = msg rg obj s poke obj
139if or ne get g_b 0 1 or ne get g_b 1 0 ne get g_b 2 obj
140ret 7
141end
142if or ne get g_b 3 poke ne get g_b 4 obj
143ret 8
144end
145r = msg rg obj twice 21 0
146if or ne r 42 or ne get g_b 0 2 ne get g_b 1 3
147ret 9
148end
149s = one rg nm 1 232 19
150r = and msg rg obj s twice 0 255
151if ne r 1
152ret 10
153end
154ret 1
155end