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