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 / src / language / lang_core.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Pure seeded OM-2 core logic backing src/language/omega_lex.c: |
| 3 | note identifier/digit classification, 64-bit integer literal decoder (dec/0x/0b), |
| 4 | note keyword lookup, and punctuation/operator classifier. |
| 5 | om2 |
| 6 | |
| 7 | fn l_ident_start c ulong to ulong |
| 8 | if and ge c 97 le c 122 |
| 9 | ret 1 |
| 10 | end |
| 11 | if and ge c 65 le c 90 |
| 12 | ret 1 |
| 13 | end |
| 14 | if eq c 95 |
| 15 | ret 1 |
| 16 | end |
| 17 | ret 0 |
| 18 | end |
| 19 | |
| 20 | fn l_ident_char c ulong to ulong |
| 21 | if eq l_ident_start c 1 |
| 22 | ret 1 |
| 23 | end |
| 24 | if and ge c 48 le c 57 |
| 25 | ret 1 |
| 26 | end |
| 27 | ret 0 |
| 28 | end |
| 29 | |
| 30 | fn l_digit_val c ulong to ulong |
| 31 | if and ge c 48 le c 57 |
| 32 | ret sub c 48 |
| 33 | end |
| 34 | if and ge c 97 le c 102 |
| 35 | ret add sub c 97 10 |
| 36 | end |
| 37 | if and ge c 65 le c 70 |
| 38 | ret add sub c 65 10 |
| 39 | end |
| 40 | ret 99 |
| 41 | end |
| 42 | |
| 43 | export fn lang_om_is_ident_start c ulong to ulong |
| 44 | ret l_ident_start c |
| 45 | end |
| 46 | |
| 47 | export fn lang_om_is_ident_char c ulong to ulong |
| 48 | ret l_ident_char c |
| 49 | end |
| 50 | |
| 51 | export fn lang_om_digit_value c ulong to ulong |
| 52 | ret l_digit_val c |
| 53 | end |
| 54 | |
| 55 | export fn lang_om_lex_int src view uchar * slen ulong pos ulong dst edit ulong 3 to ulong |
| 56 | base = ulong 10 |
| 57 | p = pos |
| 58 | if lt add p 1 slen |
| 59 | if eq ulong get src p 48 |
| 60 | nx = ulong get src add p 1 |
| 61 | if eq nx 120 |
| 62 | base = 16 |
| 63 | p = add p 2 |
| 64 | else |
| 65 | if eq nx 98 |
| 66 | base = 2 |
| 67 | p = add p 2 |
| 68 | end |
| 69 | end |
| 70 | end |
| 71 | end |
| 72 | start = p |
| 73 | v = ulong 0 |
| 74 | ovf = ulong 0 |
| 75 | maxu = ulong 0xffffffffffffffff |
| 76 | while lt p slen |
| 77 | d = l_digit_val ulong get src p |
| 78 | if ge d base |
| 79 | break |
| 80 | end |
| 81 | if gt v div sub maxu d base |
| 82 | ovf = 1 |
| 83 | else |
| 84 | v = add mul v base d |
| 85 | end |
| 86 | p = add p 1 |
| 87 | end |
| 88 | put dst 0 p |
| 89 | put dst 1 v |
| 90 | put dst 2 base |
| 91 | if eq p start |
| 92 | ret 1 |
| 93 | end |
| 94 | if lt p slen |
| 95 | if eq l_ident_char ulong get src p 1 |
| 96 | put dst 2 add p 1 |
| 97 | ret 2 |
| 98 | end |
| 99 | end |
| 100 | if ne ovf 0 |
| 101 | ret 3 |
| 102 | end |
| 103 | ret 0 |
| 104 | end |
| 105 | |
| 106 | fn l_kw_short w view uchar * n ulong to ulong |
| 107 | if eq n 2 |
| 108 | if ne ulong get w 0 102 |
| 109 | ret 1 |
| 110 | end |
| 111 | if ne ulong get w 1 110 |
| 112 | ret 1 |
| 113 | end |
| 114 | ret 4 |
| 115 | end |
| 116 | if eq n 3 |
| 117 | if ne ulong get w 0 108 |
| 118 | ret 1 |
| 119 | end |
| 120 | if ne ulong get w 1 101 |
| 121 | ret 1 |
| 122 | end |
| 123 | if ne ulong get w 2 116 |
| 124 | ret 1 |
| 125 | end |
| 126 | ret 3 |
| 127 | end |
| 128 | if eq n 4 |
| 129 | if ne ulong get w 0 116 |
| 130 | ret 1 |
| 131 | end |
| 132 | if ne ulong get w 1 114 |
| 133 | ret 1 |
| 134 | end |
| 135 | if ne ulong get w 2 117 |
| 136 | ret 1 |
| 137 | end |
| 138 | if ne ulong get w 3 101 |
| 139 | ret 1 |
| 140 | end |
| 141 | ret 7 |
| 142 | end |
| 143 | if eq n 5 |
| 144 | if ne ulong get w 0 102 |
| 145 | ret 1 |
| 146 | end |
| 147 | if ne ulong get w 1 97 |
| 148 | ret 1 |
| 149 | end |
| 150 | if ne ulong get w 2 108 |
| 151 | ret 1 |
| 152 | end |
| 153 | if ne ulong get w 3 115 |
| 154 | ret 1 |
| 155 | end |
| 156 | if ne ulong get w 4 101 |
| 157 | ret 1 |
| 158 | end |
| 159 | ret 8 |
| 160 | end |
| 161 | ret 1 |
| 162 | end |
| 163 | |
| 164 | fn l_kw_long w view uchar * n ulong to ulong |
| 165 | if eq n 7 |
| 166 | if ne ulong get w 0 101 |
| 167 | ret 1 |
| 168 | end |
| 169 | if ne ulong get w 1 110 |
| 170 | ret 1 |
| 171 | end |
| 172 | if ne ulong get w 2 115 |
| 173 | ret 1 |
| 174 | end |
| 175 | if ne ulong get w 3 117 |
| 176 | ret 1 |
| 177 | end |
| 178 | if ne ulong get w 4 114 |
| 179 | ret 1 |
| 180 | end |
| 181 | if ne ulong get w 5 101 |
| 182 | ret 1 |
| 183 | end |
| 184 | if ne ulong get w 6 115 |
| 185 | ret 1 |
| 186 | end |
| 187 | ret 6 |
| 188 | end |
| 189 | if eq n 8 |
| 190 | if ne ulong get w 0 114 |
| 191 | ret 1 |
| 192 | end |
| 193 | if ne ulong get w 1 101 |
| 194 | ret 1 |
| 195 | end |
| 196 | if ne ulong get w 2 113 |
| 197 | ret 1 |
| 198 | end |
| 199 | if ne ulong get w 3 117 |
| 200 | ret 1 |
| 201 | end |
| 202 | if ne ulong get w 4 105 |
| 203 | ret 1 |
| 204 | end |
| 205 | if ne ulong get w 5 114 |
| 206 | ret 1 |
| 207 | end |
| 208 | if ne ulong get w 6 101 |
| 209 | ret 1 |
| 210 | end |
| 211 | if ne ulong get w 7 115 |
| 212 | ret 1 |
| 213 | end |
| 214 | ret 5 |
| 215 | end |
| 216 | ret 1 |
| 217 | end |
| 218 | |
| 219 | export fn lang_om_keyword w view uchar * n ulong to ulong |
| 220 | if le n 5 |
| 221 | ret l_kw_short w n |
| 222 | end |
| 223 | ret l_kw_long w n |
| 224 | end |
| 225 | |
| 226 | fn l_punct_single c ulong to ulong |
| 227 | if eq c 40 |
| 228 | ret 9 |
| 229 | end |
| 230 | if eq c 41 |
| 231 | ret 10 |
| 232 | end |
| 233 | if eq c 123 |
| 234 | ret 11 |
| 235 | end |
| 236 | if eq c 125 |
| 237 | ret 12 |
| 238 | end |
| 239 | if eq c 58 |
| 240 | ret 13 |
| 241 | end |
| 242 | if eq c 44 |
| 243 | ret 14 |
| 244 | end |
| 245 | if eq c 43 |
| 246 | ret 17 |
| 247 | end |
| 248 | if eq c 42 |
| 249 | ret 19 |
| 250 | end |
| 251 | if eq c 47 |
| 252 | ret 20 |
| 253 | end |
| 254 | if eq c 38 |
| 255 | ret 21 |
| 256 | end |
| 257 | if eq c 124 |
| 258 | ret 22 |
| 259 | end |
| 260 | ret 0 |
| 261 | end |
| 262 | |
| 263 | export fn lang_om_punct c ulong d ulong dst edit ulong 2 to ulong |
| 264 | s = l_punct_single c |
| 265 | if ne s 0 |
| 266 | put dst 0 s |
| 267 | put dst 1 1 |
| 268 | ret 0 |
| 269 | end |
| 270 | if eq c 45 |
| 271 | if eq d 62 |
| 272 | put dst 0 15 |
| 273 | put dst 1 2 |
| 274 | else |
| 275 | put dst 0 18 |
| 276 | put dst 1 1 |
| 277 | end |
| 278 | ret 0 |
| 279 | end |
| 280 | if eq c 61 |
| 281 | if eq d 61 |
| 282 | put dst 0 23 |
| 283 | put dst 1 2 |
| 284 | else |
| 285 | put dst 0 16 |
| 286 | put dst 1 1 |
| 287 | end |
| 288 | ret 0 |
| 289 | end |
| 290 | if eq c 33 |
| 291 | if eq d 61 |
| 292 | put dst 0 24 |
| 293 | put dst 1 2 |
| 294 | else |
| 295 | put dst 0 29 |
| 296 | put dst 1 1 |
| 297 | end |
| 298 | ret 0 |
| 299 | end |
| 300 | if eq c 60 |
| 301 | if eq d 61 |
| 302 | put dst 0 26 |
| 303 | put dst 1 2 |
| 304 | else |
| 305 | put dst 0 25 |
| 306 | put dst 1 1 |
| 307 | end |
| 308 | ret 0 |
| 309 | end |
| 310 | if eq c 62 |
| 311 | if eq d 61 |
| 312 | put dst 0 28 |
| 313 | put dst 1 2 |
| 314 | else |
| 315 | put dst 0 27 |
| 316 | put dst 1 1 |
| 317 | end |
| 318 | ret 0 |
| 319 | end |
| 320 | if or eq c 34 eq c 39 |
| 321 | ret 2 |
| 322 | end |
| 323 | if or eq c 91 eq c 93 |
| 324 | ret 3 |
| 325 | end |
| 326 | ret 1 |
| 327 | end |