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 / aienux / allen / context.om
| 1 | note Restored note catalog and bounded model-job context. No storage provider. |
| 2 | note Cx declared count,visited count,ready,damaged,loading. Damaged notes stay gone. |
| 3 | global Cx ulong 5 |
| 4 | global Ctxtext uchar 65536 |
| 5 | global Ctxlen ulong 512 |
| 6 | global Ctxgone uchar 512 |
| 7 | global Ctxseen uchar 512 |
| 8 | global Ctxstart ulong 512 |
| 9 | global Meta uchar 4096 |
| 10 | global Mx ulong 2 |
| 11 | global Mdigits uchar 20 |
| 12 | text Mtself "\tself=" |
| 13 | text Mtname "\tname=" |
| 14 | text Mtstart "\tstarts=" |
| 15 | text Mtfact "\tfact " |
| 16 | text Mtis " is " |
| 17 | text Mtare " are " |
| 18 | text Mtnote "\tnote " |
| 19 | fn ctxidle to bool |
| 20 | if ne get R 1 0 |
| 21 | ret false |
| 22 | end |
| 23 | ret and eq get Tx 0 0 eq get Nt 0 0 |
| 24 | end |
| 25 | fn ctxbegin to bool |
| 26 | if not ctxidle |
| 27 | ret false |
| 28 | end |
| 29 | n = mem32 36 |
| 30 | if gt n 512 |
| 31 | ret false |
| 32 | end |
| 33 | for i ulong 512 |
| 34 | put Ctxlen i 0 |
| 35 | put Ctxgone i 1 |
| 36 | put Ctxseen i 0 |
| 37 | put Ctxstart i 0 |
| 38 | end |
| 39 | put Cx 0 n |
| 40 | put Cx 1 0 |
| 41 | put Cx 2 0 |
| 42 | put Cx 3 0 |
| 43 | put Cx 4 1 |
| 44 | if eq n 0 |
| 45 | put Cx 2 1 |
| 46 | put Cx 4 0 |
| 47 | end |
| 48 | ret true |
| 49 | end |
| 50 | note Returns0 refused without visit,1 valid record retained,2 damaged visit retained. |
| 51 | fn ctxtake index ulong to ulong |
| 52 | if not ctxidle |
| 53 | ret 0 |
| 54 | end |
| 55 | if or eq get Cx 4 0 ge index get Cx 0 |
| 56 | ret 0 |
| 57 | end |
| 58 | if ne get Ctxseen index 0 |
| 59 | ret 0 |
| 60 | end |
| 61 | status = ulong 2 |
| 62 | if notedec index |
| 63 | n = get Ns 0 |
| 64 | for i ulong n |
| 65 | put Ctxtext add mul index 128 i get Note i |
| 66 | end |
| 67 | put Ctxlen index n |
| 68 | put Ctxgone index uchar get Ns 3 |
| 69 | put Ctxstart index get Ns 2 |
| 70 | status = 1 |
| 71 | else |
| 72 | put Cx 3 add get Cx 3 1 |
| 73 | end |
| 74 | put Ctxseen index 1 |
| 75 | put Cx 1 add get Cx 1 1 |
| 76 | if eq get Cx 1 get Cx 0 |
| 77 | put Cx 2 1 |
| 78 | put Cx 4 0 |
| 79 | end |
| 80 | ret status |
| 81 | end |
| 82 | fn mtemit c uchar to void |
| 83 | if ne get Mx 1 0 |
| 84 | ret |
| 85 | end |
| 86 | n = get Mx 0 |
| 87 | if ge n 4096 |
| 88 | put Mx 1 1 |
| 89 | ret |
| 90 | end |
| 91 | put Meta n c |
| 92 | put Mx 0 add n 1 |
| 93 | end |
| 94 | fn mtnum v ulong to void |
| 95 | n = ulong 0 |
| 96 | while gt v 9 |
| 97 | put Mdigits n uchar rem v 10 |
| 98 | v = div v 10 |
| 99 | n = add n 1 |
| 100 | end |
| 101 | put Mdigits n uchar v |
| 102 | n = add n 1 |
| 103 | for i ulong n |
| 104 | mtemit add uchar 48 get Mdigits sub sub n 1 i |
| 105 | end |
| 106 | end |
| 107 | note Memory fields are length-bounded; require a terminator and printable bytes. |
| 108 | fn mtfield off ulong cap ulong to bool |
| 109 | for i ulong cap |
| 110 | c = get Mem add off i |
| 111 | if eq c 0 |
| 112 | if eq i 0 |
| 113 | put Mx 1 1 |
| 114 | ret false |
| 115 | end |
| 116 | ret true |
| 117 | end |
| 118 | if or lt c 32 gt c 126 |
| 119 | put Mx 1 1 |
| 120 | ret false |
| 121 | end |
| 122 | mtemit c |
| 123 | end |
| 124 | put Mx 1 1 |
| 125 | ret false |
| 126 | end |
| 127 | fn mtfacts count ulong to bool |
| 128 | for k ulong count |
| 129 | off = add 40 mul k 113 |
| 130 | for i ulong len Mtfact |
| 131 | mtemit get Mtfact i |
| 132 | end |
| 133 | if not mtfield off 48 |
| 134 | ret false |
| 135 | end |
| 136 | are = get Mem add off 112 |
| 137 | if gt are 1 |
| 138 | put Mx 1 1 |
| 139 | ret false |
| 140 | end |
| 141 | if eq are 1 |
| 142 | for i ulong len Mtare |
| 143 | mtemit get Mtare i |
| 144 | end |
| 145 | else |
| 146 | for i ulong len Mtis |
| 147 | mtemit get Mtis i |
| 148 | end |
| 149 | end |
| 150 | if not mtfield add off 48 64 |
| 151 | ret false |
| 152 | end |
| 153 | end |
| 154 | ret eq get Mx 1 0 |
| 155 | end |
| 156 | fn mtnotes count ulong limit ulong to void |
| 157 | given = ulong 0 |
| 158 | for k ulong count |
| 159 | index = sub sub count 1 k |
| 160 | if and eq get Ctxgone index 0 lt given limit |
| 161 | for i ulong len Mtnote |
| 162 | mtemit get Mtnote i |
| 163 | end |
| 164 | for i ulong get Ctxlen index |
| 165 | mtemit get Ctxtext add mul index 128 i |
| 166 | end |
| 167 | given = add given 1 |
| 168 | end |
| 169 | end |
| 170 | end |
| 171 | fn ctxmeta limit ulong to bool |
| 172 | put Mx 0 0 |
| 173 | put Mx 1 1 |
| 174 | facts = mem32 32 |
| 175 | notes = mem32 36 |
| 176 | if or gt facts 32 gt notes 512 |
| 177 | ret false |
| 178 | end |
| 179 | if gt limit 512 |
| 180 | ret false |
| 181 | end |
| 182 | if gt notes 0 |
| 183 | if or eq get Cx 2 0 ne get Cx 0 notes |
| 184 | ret false |
| 185 | end |
| 186 | end |
| 187 | put Mx 1 0 |
| 188 | for i ulong len Mtself |
| 189 | mtemit get Mtself i |
| 190 | end |
| 191 | off = add 40 mul facts 113 |
| 192 | if eq get Mem off 0 |
| 193 | for i ulong len Allen |
| 194 | mtemit get Allen i |
| 195 | end |
| 196 | else |
| 197 | if not mtfield off 24 |
| 198 | ret false |
| 199 | end |
| 200 | end |
| 201 | if ne get Mem 8 0 |
| 202 | for i ulong len Mtname |
| 203 | mtemit get Mtname i |
| 204 | end |
| 205 | if not mtfield 8 24 |
| 206 | ret false |
| 207 | end |
| 208 | end |
| 209 | for i ulong len Mtstart |
| 210 | mtemit get Mtstart i |
| 211 | end |
| 212 | mtnum mem32 0 |
| 213 | if not mtfacts facts |
| 214 | ret false |
| 215 | end |
| 216 | mtnotes notes limit |
| 217 | ret eq get Mx 1 0 |
| 218 | end |
| 219 | note Publish all metadata or none; preserve outgoing bytes/length/error on refusal. |
| 220 | fn ctxappend to bool |
| 221 | if or ne get Mx 1 0 ne get Err 0 0 |
| 222 | ret false |
| 223 | end |
| 224 | n = get Outlen 0 |
| 225 | size = get Mx 0 |
| 226 | if or gt n 4096 gt size 4096 |
| 227 | ret false |
| 228 | end |
| 229 | if gt add n size 4096 |
| 230 | ret false |
| 231 | end |
| 232 | for i ulong size |
| 233 | put Outb add n i get Meta i |
| 234 | end |
| 235 | put Outlen 0 add n size |
| 236 | ret true |
| 237 | end |