Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/language/test_language_v0.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / language / test_language_v0.om` 1155 lines ยท 26366 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Omega Surface Language V0 (lane 3) test suite and golden verifier. It carries NO copy of 3 note the front end: the make rule (mk/visor-language.mk) concatenates the shipped 4 note src/visor/visor.om, the shared units, src/visor/visor_program.om and 5 note src/language/omega_lex.om, omega_parse.om, omega_lower.om (the sources `omega` is built 6 note from) ahead of this file, so every check below runs the shipped lexer, parser and lowering. 7 note This file holds only the vectors, the checks and a thin adapter over the shipped entry points. 8 om2 9 10 note ---- top-level texts ---- 11 text t_pass "PASS " 12 text t_fail "FAIL " 13 text t_slash "/" 14 text t_nl "\n" 15 text t_col_pfx "column " 16 text t_fail_pfx "FAIL check #" 17 text t_default_golden "tests/language/golden/v0.txt" 18 text t_hex "`0123456789abcdef`" 19 text t_kw_true "true" 20 text t_x "x" 21 text t_y "y" 22 text t_b "b" 23 24 note test vector texts 25 text s_7_u64 "7: u64" 26 text s_07_u64 "07: u64" 27 text s_0x07_u64 "0x07: u64" 28 text s_0b111_u64 "0b111: u64" 29 text s_p7_u64 "(7: u64)" 30 text s_0x7_sp_u64 "0x7 : u64" 31 text s_cmt_7_u64 "/* seven */ 7: u64 // done" 32 text s_7_u32 "7: u32" 33 text s_7_u8 "7: u8" 34 text s_let_x3 "let x: u64 = 3" 35 text s_let_y4 "let y: u64 = 4" 36 text s_xy_0 "x + y" 37 text s_xy_1 "x+y" 38 text s_xy_2 "x + /* c */ y" 39 text s_xy_3 " x\t+ y // trailing" 40 text s_xy_4 "(x) + (y)" 41 text s_xy_5 "(x + y)" 42 text s_xy_6 "(x + y : u64)" 43 text s_xy_7 "x + y: u64" 44 text s_let_a7 "let a: u64 = 7" 45 text s_let_b7 "let b: u64 = 7" 46 text s_let_zxy "let z: u64 = x + y" 47 text s_x_p_1 "x + 1" 48 text s_x_p_1u "x + (1: u64)" 49 text s_rebind_x "let x: u64 = x * 2" 50 text s_u_p_x "_ + x" 51 text s_det_0 "(3: u64) + 4 * 5" 52 text s_det_1 "(0xff: u32) & 0x0f | 1" 53 text s_det_2 "true" 54 text s_det_3 "(9: u16) / 3" 55 text s_prec_1 "(3: u64) + (4 * 5)" 56 text s_prec_2 "((3: u64) + 4) * 5" 57 text s_prec_3 "(1: u64) | 2 & 3" 58 text s_prec_4 "(1: u64) | (2 & 3)" 59 text s_let_seed "let seed: u64 = 1" 60 text s_cmt_only " // nothing" 61 text s_full_add "(100000: u64) + 100001" 62 text s_vv "v + v" 63 text s_fn_tr "fn transform(x: u64) -> u64 requires true ensures result >= 1 { x * 2 + 1 }" 64 text s_fn_tr1 "fn transform(y: u64) -> u64 requires true ensures result>=1 { y*2+1 }" 65 text s_fn_tr2 "fn transform(x: u64) -> u64 requires true ensures result >= 1 { 2 * x + 1 }" 66 text s_fn_tr3 "fn transform(x: u64) -> u64 requires /* pre */ true ensures result >= 0x1 { (x * 2) + 1 }" 67 text s_fn_tr4 "fn transform(x: u64) -> u64 requires true ensures result >= 1 { 1 + x * 2 }" 68 text s_fn_oth "fn other(x: u64) -> u64 requires true ensures result >= 1 { x * 2 + 1 }" 69 text s_fn_ens2 "fn transform(x: u64) -> u64 requires true ensures result >= 2 { x * 2 + 1 }" 70 text s_fn_redef "fn transform(x: u64) -> u64 requires true ensures result >= 1 { x * 3 + 1 }" 71 text s_fn_mask "fn m(x: u64) -> u64 { x & 0xff }" 72 text s_fn_sub "fn s(x: u64) -> u64 requires x < 10 ensures result == x - 1 { x - 1 }" 73 text s_fn_fill0 "fn fill0(x: u64) -> u64 { x + 0 }" 74 text s_fn_more "fn more(x: u64) -> u64 { x + 1000 }" 75 text s_pre_xlt10 "x < 10" 76 text s_post_res1 "result >= 1" 77 text s_post_reseq "result == x - 1" 78 79 note fail-closed test cases 80 text r_01 "7" 81 text r_02 "(7)" 82 text r_03 "1 + 2" 83 text r_04 "(1 + 2) * 3" 84 text r_05 "256: u8" 85 text r_06 "65536: u16" 86 text r_07 "`4294967296`: u32" 87 text r_08 "`18446744073709551616`: u64" 88 text r_09 "0x10000000000000000: u64" 89 text r_10 "let q: u8 = 300" 90 text r_11 "(1: u32) + (1: u64)" 91 text r_12 "let w: u32 = (1: u64)" 92 text r_13 "(true: u64)" 93 text r_14 "true + false" 94 text r_15 "(1: u64) + true" 95 text r_16 "let t: bool = 1" 96 text r_17 "let s: i64 = 1" 97 text r_18 "(1: i32)" 98 text r_19 "let f: f64 = 1" 99 text r_20 "\"hello\"" 100 text r_21 "[1, 2]" 101 text r_22 "-1" 102 text r_23 "!true" 103 text r_24 "(1: u64) == 1" 104 text r_25 "(1: u64) < 2" 105 text r_26 "(4: u64) / 0" 106 text r_27 "effect" 107 text r_28 "mint(1)" 108 text r_29 "let cap: u64 = 1" 109 text r_30 "publish + 1" 110 text r_31 "unknown_name + 1" 111 text r_32 "f(1)" 112 text r_33 "let u64: u64 = 1" 113 text r_34 "let x u64 = 7" 114 text r_35 "let x = 7" 115 text r_36 "(1: u64) +" 116 text r_37 ")" 117 text r_38 "(1: u64) (2: u64)" 118 text r_39 "7u64" 119 text r_40 "0x: u64" 120 text r_41 "0b2: u64" 121 text r_42 "/* open" 122 text r_43 "(1: u64" 123 text r_44 "let _: u64 = 1" 124 text r_45 "x;" 125 126 note bad fn test cases 127 text bf_01 "fn r(x: u64) -> u64 { r(x) }" 128 text bf_02 "fn r(x: u64) -> u64 { r + 1 }" 129 text bf_03 "fn g(x: u64) -> u64 { x * x }" 130 text bf_04 "fn g(x: u64) -> u64 { x * (2 + 1) }" 131 text bf_05 "fn g(x: u64) -> u64 { x / 2 }" 132 text bf_06 "fn g(x: u64) -> u64 { x + `4294967296` }" 133 text bf_07 "fn g(x: u64) -> u64 { x }" 134 text bf_08 "fn g(x: u64) -> u64 { 5 + 1 }" 135 text bf_09 "fn g(x: u32) -> u32 { x + 1 }" 136 text bf_10 "fn g(x: u64) -> u64 { 1 - x }" 137 text bf_11 "fn g(x: u64, y: u64) -> u64 { x + 1 }" 138 text bf_12 "fn g(x: u64) -> u64 { x + seed }" 139 text bf_13 "fn g(x: u64) -> u64 requires result > 0 { x + 1 }" 140 text bf_14 "fn g(x: u64) -> u64 requires z > 0 { x + 1 }" 141 text bf_15 "fn g(x: u64) -> u64 ensures result >= `1111111111` + `2222222222` + `3333333333` + `4444444444` + 55 { x + 1 }" 142 text bf_16 "fn g(x: u64) -> u64 { x == 1 }" 143 text bf_17 "fn g(x: u64) -> u64 { x + (2: u32) }" 144 text bf_18 "fn g(x: u64) -> u64 { (2: u32) * x }" 145 text bf_19 "fn g(x: u64) -> u64 { (x: u32) + 1 }" 146 text bf_20 "transform + 1" 147 text bf_21 "fn g(x: u64) -> u64 x + 1" 148 text bf_22 "fn g(x: u64) { x + 1 }" 149 150 151 note ---- test state ---- 152 global g_pass ulong 1 153 global g_total ulong 1 154 global g_numbuf uchar 32 155 global g_line uchar 4096 156 global g_line_len ulong 1 157 global g_filebuf uchar 32768 158 global g_pathbuf uchar 256 159 global g_id_a uchar 32 160 global g_id_b uchar 32 161 global g_id_c uchar 32 162 global g_hex_enc uchar 8192 163 global g_hex_id uchar 64 164 global g_sha_out uchar 32 165 note result of the last eval / fresh lowering, in the old numbering (1 expression, 2 binding, 3 program) 166 global g_res_kind ulong 1 167 global g_res_id uchar 32 168 global g_res_pidx long 1 169 global g_res_ttag ulong 1 170 global g_res_twid ulong 1 171 global g_res_nlen ulong 1 172 global g_res_name uchar 64 173 174 note ---- I/O helpers ---- 175 fn write_all s view uchar * n ulong to void 176 if eq n 0 177 ret 178 end 179 k = write 1 s 0 n 180 if lt k 0 181 ret 182 end 183 end 184 185 fn print_u64 v ulong to void 186 if eq v 0 187 put g_numbuf 0 uchar 48 188 k = write 1 g_numbuf 0 1 189 ret 190 end 191 x = v 192 cnt = ulong 0 193 while gt x 0 bound 24 194 d = rem x 10 195 put g_numbuf cnt uchar add d 48 196 cnt = add cnt 1 197 x = div x 10 198 end 199 i = ulong 0 200 j = sub cnt 1 201 while lt i j bound 24 202 a = get g_numbuf i 203 b = get g_numbuf j 204 put g_numbuf i b 205 put g_numbuf j a 206 i = add i 1 207 j = sub j 1 208 end 209 k = write 1 g_numbuf 0 cnt 210 end 211 212 fn chk ok bool to void 213 t = add get g_total 0 1 214 put g_total 0 t 215 if ok 216 put g_pass 0 add get g_pass 0 1 217 else 218 write_all t_fail_pfx len t_fail_pfx 219 print_u64 t 220 write_all t_nl len t_nl 221 end 222 end 223 224 225 note ---- adapter over the shipped front end ---- 226 fn session_reset to void 227 vs_init 228 end 229 230 fn graph_reset to void 231 og_reset 232 end 233 234 fn set_line s view uchar * to void 235 n = len s 236 for i ulong n bound 2048 237 put g_line i get s i 238 end 239 put g_line_len 0 n 240 end 241 242 note omega_language_eval_line on g_line: the shipped olw_eval_sbuf 243 fn eval_cur_line to long 244 put g_res_kind 0 0 245 put g_res_pidx 0 -1 246 put g_res_nlen 0 0 247 n = get g_line_len 0 248 for i ulong n bound 4096 249 put v_sbuf i get g_line i 250 end 251 rc = olw_eval_sbuf n 252 if ne rc 0 253 ret rc 254 end 255 k = get olw_rkind 0 256 if eq k 1 257 put g_res_kind 0 2 258 end 259 if eq k 2 260 put g_res_kind 0 1 261 end 262 if eq k 3 263 put g_res_kind 0 3 264 end 265 put g_res_pidx 0 get olw_rpidx 0 266 put g_res_ttag 0 get olw_rttag 0 267 put g_res_twid 0 get olw_rtwid 0 268 for i ulong 32 269 put g_res_id i get olw_rid i 270 end 271 if ne k 2 272 nl = get opr_nlen 0 273 put g_res_nlen 0 nl 274 for i ulong nl bound 64 275 put g_res_name i get opr_name i 276 end 277 end 278 ret 0 279 end 280 281 fn eval_txt s view uchar * to long 282 set_line s 283 ret eval_cur_line 284 end 285 286 note lex and parse g_line with the shipped olx_lex_line / opr_parse_line (the front of olw_eval_sbuf) 287 fn parse_line to long 288 put olx_elen 0 0 289 m = get g_line_len 0 290 if gt m 4096 291 m = 4096 292 end 293 for i ulong m bound 4096 294 put olx_line i get g_line i 295 end 296 put olx_llen 0 m 297 rc = olx_lex_line 298 if ne rc 0 299 ret rc 300 end 301 ret opr_parse_line 302 end 303 304 fn lower_program to long 305 ret olw_lower_program 306 end 307 308 note lower the parsed expression into the (reset) graph: the object index, or a negative rc 309 fn lower_expr_fresh to long 310 et = ulong 0 311 ew = ulong 0 312 he = false 313 if eq get opr_stmt 0 2 314 et = get opr_lttag 0 315 ew = get opr_ltwid 0 316 he = true 317 end 318 rc = olw_lower_expr ulong get opr_root 0 he et ew 319 if ne rc 0 320 ret rc 321 end 322 ret long get olw_lo_oi 0 323 end 324 325 fn lower_fresh_txt s view uchar * to long 326 set_line s 327 rc = parse_line 328 if lt rc 0 329 ret rc 330 end 331 graph_reset 332 oi = lower_expr_fresh 333 if lt oi 0 334 ret oi 335 end 336 ob = mul ulong oi 32 337 for i ulong 32 338 put g_res_id i get v_og_id add ob i 339 end 340 ret oi 341 end 342 343 fn bind_find_txt s view uchar * to long 344 n = v_copy_txt_sbuf s 345 ret vs_bind_find_sbuf n 346 end 347 348 fn build_type_uint w ulong to long 349 ret og_build_type_uint w 350 end 351 352 fn build_val_uint tidx ulong w ulong val ulong to long 353 ret og_build_val_uint tidx w val 354 end 355 356 note the id of a CONSTRAINT object carrying `s` as a constraint of kind `kind`, into g_sha_out 357 fn hct_copy_id idx ulong to void 358 ib = mul idx 32 359 for i ulong 32 360 put g_sha_out i get v_og_id add ib i 361 end 362 end 363 364 fn hash_constraint_txt kind ulong s view uchar * to void 365 c0 = get v_og_cnt 0 366 sc0 = get v_og_scratch 0 367 put v_og_scratch 0 1 368 si = og_add_object V_KIND_CONSTRAINT 369 put v_og_scratch 0 sc0 370 if ge si 0 371 n = v_copy_txt_sbuf s 372 cr = og_add_const_sbuf ulong si kind n 373 if ge cr 0 374 if ge og_finish ulong si 0 375 hct_copy_id ulong si 376 end 377 end 378 end 379 put v_og_cnt 0 c0 380 end 381 382 note omega_program_eval of the program just lowered (slot OLW_ACC) on x 383 fn cp_eval_u64 x ulong to ulong 384 if ne vpg_eval OLW_ACC x 0 385 ret 0 386 end 387 ret get vpg_ev 0 388 end 389 390 fn id_eq_a_res to bool 391 for i ulong 32 392 if ne get g_id_a i get g_res_id i 393 ret false 394 end 395 end 396 ret true 397 end 398 399 fn id_eq_a_b to bool 400 for i ulong 32 401 if ne get g_id_a i get g_id_b i 402 ret false 403 end 404 end 405 ret true 406 end 407 408 fn id_eq_b_c to bool 409 for i ulong 32 410 if ne get g_id_b i get g_id_c i 411 ret false 412 end 413 end 414 ret true 415 end 416 417 fn id_eq_a_obj idx ulong to bool 418 ob = mul idx 32 419 for i ulong 32 420 if ne get g_id_a i get v_og_id add ob i 421 ret false 422 end 423 end 424 ret true 425 end 426 427 fn save_res_to_a to void 428 for i ulong 32 429 put g_id_a i get g_res_id i 430 end 431 end 432 433 fn save_res_to_b to void 434 for i ulong 32 435 put g_id_b i get g_res_id i 436 end 437 end 438 439 fn save_res_to_c to void 440 for i ulong 32 441 put g_id_c i get g_res_id i 442 end 443 end 444 445 fn err_ok to bool 446 n = get olx_elen 0 447 if lt n 7 448 ret false 449 end 450 for i ulong 7 451 if ne get olx_err i get t_col_pfx i 452 ret false 453 end 454 end 455 for i ulong n bound 256 456 if eq ulong get olx_err i 10 457 ret false 458 end 459 end 460 ret true 461 end 462 463 note ---- Test 1: literal spellings ---- 464 fn test_literal_spellings to void 465 chk ge lower_fresh_txt s_7_u64 0 466 save_res_to_a 467 chk ge lower_fresh_txt s_07_u64 0 468 chk id_eq_a_res 469 chk ge lower_fresh_txt s_0x07_u64 0 470 chk id_eq_a_res 471 chk ge lower_fresh_txt s_0b111_u64 0 472 chk id_eq_a_res 473 chk ge lower_fresh_txt s_p7_u64 0 474 chk id_eq_a_res 475 chk ge lower_fresh_txt s_0x7_sp_u64 0 476 chk id_eq_a_res 477 chk ge lower_fresh_txt s_cmt_7_u64 0 478 chk id_eq_a_res 479 graph_reset 480 ti = build_type_uint 64 481 vi = build_val_uint ulong ti 64 7 482 chk id_eq_a_obj ulong vi 483 end 484 485 note ---- Test 2: width changes id ---- 486 fn test_width_changes_id to void 487 chk ge lower_fresh_txt s_7_u64 0 488 save_res_to_a 489 chk ge lower_fresh_txt s_7_u32 0 490 save_res_to_b 491 chk ge lower_fresh_txt s_7_u8 0 492 save_res_to_c 493 chk not id_eq_a_b 494 chk not id_eq_b_c 495 end 496 497 note ---- Test 3: whitespace, comments, and names ---- 498 fn test_whitespace_comments_and_names to void 499 session_reset 500 chk eq eval_txt s_let_x3 0 501 chk and eq get g_res_kind 0 2 and eq get g_res_nlen 0 1 and eq ulong get g_res_name 0 120 eq get g_res_twid 0 64 502 chk eq eval_txt s_let_y4 0 503 chk eq eval_txt s_xy_0 0 504 chk eq get g_res_kind 0 1 505 save_res_to_a 506 c1 = get v_og_cnt 0 507 chk eq eval_txt s_xy_1 0 508 chk id_eq_a_res 509 chk eq eval_txt s_xy_2 0 510 chk id_eq_a_res 511 chk eq eval_txt s_xy_3 0 512 chk id_eq_a_res 513 chk eq eval_txt s_xy_4 0 514 chk id_eq_a_res 515 chk eq eval_txt s_xy_5 0 516 chk id_eq_a_res 517 chk eq eval_txt s_xy_6 0 518 chk id_eq_a_res 519 chk eq eval_txt s_xy_7 0 520 chk id_eq_a_res 521 chk eq get v_og_cnt 0 c1 522 note Check against direct builders 523 before = get v_og_cnt 0 524 chk eq eval_txt s_let_a7 0 525 save_res_to_b 526 mid = get v_og_cnt 0 527 chk eq eval_txt s_let_b7 0 528 save_res_to_c 529 chk id_eq_b_c 530 chk and eq mid add before 1 eq get v_og_cnt 0 mid 531 bi = bind_find_txt t_b 532 chk and ge bi 0 eq get v_bind_kind ulong bi 1 533 chk eq eval_txt s_let_zxy 0 534 chk id_eq_a_res 535 chk eq eval_txt s_x_p_1 0 536 save_res_to_b 537 chk eq eval_txt s_x_p_1u 0 538 save_res_to_c 539 chk id_eq_b_c 540 chk eq eval_txt s_rebind_x 0 541 save_res_to_b 542 bx = bind_find_txt t_x 543 chk ge bx 0 544 note Set last = y and test _ + x 545 by = bind_find_txt t_y 546 yb = mul ulong by 32 547 for i ulong 32 548 put v_tmp_id i get v_bind_id add yb i 549 end 550 vs_set_last V_BIND_OBJECT -1 551 chk eq eval_txt s_u_p_x 0 552 end 553 554 note ---- Test 4: determinism & precedence ---- 555 fn test_determinism to void 556 chk ge lower_fresh_txt s_det_0 0 557 save_res_to_a 558 chk ge lower_fresh_txt s_det_0 0 559 chk id_eq_a_res 560 chk ge lower_fresh_txt s_det_1 0 561 save_res_to_a 562 chk ge lower_fresh_txt s_det_1 0 563 chk id_eq_a_res 564 chk ge lower_fresh_txt s_det_2 0 565 save_res_to_a 566 chk ge lower_fresh_txt s_det_2 0 567 chk id_eq_a_res 568 chk ge lower_fresh_txt s_det_3 0 569 save_res_to_a 570 chk ge lower_fresh_txt s_det_3 0 571 chk id_eq_a_res 572 chk ge lower_fresh_txt s_det_0 0 573 save_res_to_a 574 chk ge lower_fresh_txt s_prec_1 0 575 chk id_eq_a_res 576 chk ge lower_fresh_txt s_prec_2 0 577 chk not id_eq_a_res 578 chk ge lower_fresh_txt s_prec_3 0 579 save_res_to_a 580 chk ge lower_fresh_txt s_prec_4 0 581 chk id_eq_a_res 582 end 583 584 note ---- Test 5: fail closed ---- 585 fn chk_reject s view uchar * want long to void 586 no = get v_og_cnt 0 587 nb = get v_bind_cnt 0 588 np = get v_prog_cnt 0 589 rc = eval_txt s 590 chk eq rc want 591 ok = eq get v_og_cnt 0 no 592 if ne get v_bind_cnt 0 nb 593 ok = false 594 end 595 if ne get v_prog_cnt 0 np 596 ok = false 597 end 598 chk ok 599 chk err_ok 600 chk eq get g_res_kind 0 0 601 end 602 603 fn test_fail_closed to void 604 session_reset 605 chk eq eval_txt s_let_seed 0 606 chk_reject r_01 -2 607 chk_reject r_02 -2 608 chk_reject r_03 -2 609 chk_reject r_04 -2 610 chk_reject r_05 -2 611 chk_reject r_06 -2 612 chk_reject r_07 -2 613 chk_reject r_08 -2 614 chk_reject r_09 -2 615 chk_reject r_10 -2 616 chk_reject r_11 -2 617 chk_reject r_12 -2 618 chk_reject r_13 -2 619 chk_reject r_14 -2 620 chk_reject r_15 -2 621 chk_reject r_16 -2 622 chk_reject r_17 -2 623 chk_reject r_18 -2 624 chk_reject r_19 -2 625 chk_reject r_20 -2 626 chk_reject r_21 -2 627 chk_reject r_22 -2 628 chk_reject r_23 -2 629 chk_reject r_24 -2 630 chk_reject r_25 -2 631 chk_reject r_26 -2 632 chk_reject r_27 -2 633 chk_reject r_28 -2 634 chk_reject r_29 -2 635 chk_reject r_30 -2 636 chk_reject r_31 -2 637 chk_reject r_32 -2 638 chk_reject r_33 -2 639 chk_reject r_34 -1 640 chk_reject r_35 -1 641 chk_reject r_36 -1 642 chk_reject r_37 -1 643 chk_reject r_38 -1 644 chk_reject r_39 -1 645 chk_reject r_40 -1 646 chk_reject r_41 -1 647 chk_reject r_42 -1 648 chk_reject r_43 -1 649 chk_reject r_44 -1 650 chk_reject r_45 -1 651 chk and eq eval_txt s_cmt_only 0 eq get g_res_kind 0 0 652 end 653 654 note ---- Test 6: depth and capacity ---- 655 fn build_nested_7 depth ulong to void 656 pos = ulong 0 657 for i ulong depth bound 64 658 put g_line pos uchar 40 659 pos = add pos 1 660 end 661 for i ulong len s_7_u64 662 put g_line pos get s_7_u64 i 663 pos = add pos 1 664 end 665 for i ulong depth bound 64 666 put g_line pos uchar 41 667 pos = add pos 1 668 end 669 put g_line_len 0 pos 670 end 671 672 fn build_let_v_num n ulong to void 673 note "let v: u64 = N" 674 put g_line 0 uchar 108 675 put g_line 1 uchar 101 676 put g_line 2 uchar 116 677 put g_line 3 uchar 32 678 put g_line 4 uchar 118 679 put g_line 5 uchar 58 680 put g_line 6 uchar 32 681 put g_line 7 uchar 117 682 put g_line 8 uchar 54 683 put g_line 9 uchar 52 684 put g_line 10 uchar 32 685 put g_line 11 uchar 61 686 put g_line 12 uchar 32 687 pos = ulong 13 688 if eq n 0 689 put g_line pos uchar 48 690 pos = add pos 1 691 else 692 x = n 693 cnt = ulong 0 694 while gt x 0 bound 16 695 put g_numbuf cnt uchar add rem x 10 48 696 cnt = add cnt 1 697 x = div x 10 698 end 699 i = cnt 700 while gt i 0 bound 16 701 i = sub i 1 702 put g_line pos get g_numbuf i 703 pos = add pos 1 704 end 705 end 706 put g_line_len 0 pos 707 end 708 709 fn test_depth_and_capacity to void 710 build_nested_7 40 711 chk eq parse_line -3 712 build_nested_7 20 713 chk eq parse_line 0 714 graph_reset 715 oi = lower_expr_fresh 716 chk ge oi 0 717 ob = mul ulong oi 32 718 for i ulong 32 719 put g_id_a i get v_og_id add ob i 720 end 721 chk ge lower_fresh_txt s_7_u64 0 722 chk id_eq_a_res 723 note Too many tokens: (1: u64) + 140 copies of +1 724 pos = ulong 0 725 put g_line 0 uchar 40 726 put g_line 1 uchar 49 727 put g_line 2 uchar 58 728 put g_line 3 uchar 32 729 put g_line 4 uchar 117 730 put g_line 5 uchar 54 731 put g_line 6 uchar 52 732 put g_line 7 uchar 41 733 pos = 8 734 for i ulong 140 735 put g_line pos uchar 43 736 put g_line add pos 1 uchar 49 737 pos = add pos 2 738 end 739 put g_line_len 0 pos 740 chk eq parse_line -3 741 note Graph capacity rollback 742 session_reset 743 i = ulong 0 744 while lt get v_og_cnt 0 254 bound 300 745 build_let_v_num i 746 if ne eval_cur_line 0 747 break 748 end 749 i = add i 1 750 end 751 before = get v_og_cnt 0 752 chk eq before 254 753 chk eq eval_txt s_full_add -3 754 chk eq get v_og_cnt 0 before 755 chk eq eval_txt s_vv 0 756 end 757 758 note ---- Test 7: programs ---- 759 fn build_fn_fill idx ulong to void 760 note "fn fillN(x: u64) -> u64 { x + N }" 761 put g_line 0 uchar 102 762 put g_line 1 uchar 110 763 put g_line 2 uchar 32 764 put g_line 3 uchar 102 765 put g_line 4 uchar 105 766 put g_line 5 uchar 108 767 put g_line 6 uchar 108 768 pos = ulong 7 769 if eq idx 0 770 put g_line pos uchar 48 771 pos = add pos 1 772 else 773 x = idx 774 cnt = ulong 0 775 while gt x 0 bound 8 776 put g_numbuf cnt uchar add rem x 10 48 777 cnt = add cnt 1 778 x = div x 10 779 end 780 k = cnt 781 while gt k 0 bound 8 782 k = sub k 1 783 put g_line pos get g_numbuf k 784 pos = add pos 1 785 end 786 end 787 note "(x: u64) -> u64 { x + " 788 put g_line pos uchar 40 789 put g_line add pos 1 uchar 120 790 put g_line add pos 2 uchar 58 791 put g_line add pos 3 uchar 32 792 put g_line add pos 4 uchar 117 793 put g_line add pos 5 uchar 54 794 put g_line add pos 6 uchar 52 795 put g_line add pos 7 uchar 41 796 put g_line add pos 8 uchar 32 797 put g_line add pos 9 uchar 45 798 put g_line add pos 10 uchar 62 799 put g_line add pos 11 uchar 32 800 put g_line add pos 12 uchar 117 801 put g_line add pos 13 uchar 54 802 put g_line add pos 14 uchar 52 803 put g_line add pos 15 uchar 32 804 put g_line add pos 16 uchar 123 805 put g_line add pos 17 uchar 32 806 put g_line add pos 18 uchar 120 807 put g_line add pos 19 uchar 32 808 put g_line add pos 20 uchar 43 809 put g_line add pos 21 uchar 32 810 pos = add pos 22 811 if eq idx 0 812 put g_line pos uchar 48 813 pos = add pos 1 814 else 815 x = idx 816 cnt = ulong 0 817 while gt x 0 bound 8 818 put g_numbuf cnt uchar add rem x 10 48 819 cnt = add cnt 1 820 x = div x 10 821 end 822 k = cnt 823 while gt k 0 bound 8 824 k = sub k 1 825 put g_line pos get g_numbuf k 826 pos = add pos 1 827 end 828 end 829 put g_line pos uchar 32 830 put g_line add pos 1 uchar 125 831 put g_line_len 0 add pos 2 832 end 833 834 fn chk_prog_req pidx ulong s view uchar * to bool 835 if ne get v_prog_rlen pidx len s 836 ret false 837 end 838 nb = mul pidx 64 839 for i ulong len s bound 64 840 if ne get v_prog_req add nb i get s i 841 ret false 842 end 843 end 844 ret true 845 end 846 847 fn chk_prog_ens pidx ulong s view uchar * to bool 848 if ne get v_prog_elen pidx len s 849 ret false 850 end 851 nb = mul pidx 64 852 for i ulong len s bound 64 853 if ne get v_prog_ens add nb i get s i 854 ret false 855 end 856 end 857 ret true 858 end 859 860 fn chk_bad_fn s view uchar * want long to void 861 np = get v_prog_cnt 0 862 nb = get v_bind_cnt 0 863 no = get v_og_cnt 0 864 rc = eval_txt s 865 chk eq rc want 866 ok = eq get v_prog_cnt 0 np 867 if ne get v_bind_cnt 0 nb 868 ok = false 869 end 870 if ne get v_og_cnt 0 no 871 ok = false 872 end 873 chk ok 874 end 875 876 fn test_programs to void 877 session_reset 878 objs = get v_og_cnt 0 879 chk eq eval_txt s_fn_tr 0 880 chk and eq get g_res_kind 0 3 eq get g_res_pidx 0 0 881 chk eq get v_og_cnt 0 objs 882 chk eq get v_prog_cnt 0 1 883 save_res_to_a 884 chk chk_prog_req 0 t_kw_true 885 chk chk_prog_ens 0 s_post_res1 886 hash_constraint_txt 7 t_kw_true 887 pre_ok = true 888 for i ulong 32 889 if ne get v_prog_preid i get g_sha_out i 890 pre_ok = false 891 end 892 end 893 chk pre_ok 894 hash_constraint_txt 8 s_post_res1 895 post_ok = true 896 for i ulong 32 897 if ne get v_prog_postid i get g_sha_out i 898 post_ok = false 899 end 900 end 901 chk post_ok 902 note transform(5) == 11 903 chk eq cp_eval_u64 5 11 904 note Identity laws 905 chk eq eval_txt s_fn_tr1 0 906 chk id_eq_a_res 907 chk eq eval_txt s_fn_tr2 0 908 chk id_eq_a_res 909 chk eq eval_txt s_fn_tr3 0 910 chk id_eq_a_res 911 chk eq eval_txt s_fn_tr4 0 912 chk id_eq_a_res 913 chk eq eval_txt s_fn_oth 0 914 chk and id_eq_a_res eq get g_res_pidx 0 0 915 chk eq eval_txt s_fn_ens2 0 916 chk not id_eq_a_res 917 chk eq get v_prog_cnt 0 2 918 chk eq eval_txt s_fn_redef 0 919 chk and not id_eq_a_res eq get v_prog_cnt 0 3 920 chk eq eval_txt s_fn_mask 0 921 pi = ulong get g_res_pidx 0 922 chk and chk_prog_req pi t_kw_true chk_prog_ens pi t_kw_true 923 chk eq eval_txt s_fn_sub 0 924 pi = ulong get g_res_pidx 0 925 chk and chk_prog_req pi s_pre_xlt10 chk_prog_ens pi s_post_reseq 926 note Bad fn cases 927 chk_bad_fn bf_01 -2 928 chk_bad_fn bf_02 -2 929 chk_bad_fn bf_03 -2 930 chk_bad_fn bf_04 -2 931 chk_bad_fn bf_05 -2 932 chk_bad_fn bf_06 -2 933 chk_bad_fn bf_07 -2 934 chk_bad_fn bf_08 -2 935 chk_bad_fn bf_09 -2 936 chk_bad_fn bf_10 -2 937 chk_bad_fn bf_11 -2 938 chk_bad_fn bf_12 -2 939 chk_bad_fn bf_13 -2 940 chk_bad_fn bf_14 -2 941 chk_bad_fn bf_15 -2 942 chk_bad_fn bf_16 -2 943 chk_bad_fn bf_17 -2 944 chk_bad_fn bf_18 -2 945 chk_bad_fn bf_19 -2 946 chk_bad_fn bf_20 -2 947 chk_bad_fn bf_21 -1 948 chk_bad_fn bf_22 -1 949 note Fill program table to 16 950 i = ulong 0 951 while and lt get v_prog_cnt 0 16 lt i 64 bound 64 952 build_fn_fill i 953 if ne eval_cur_line 0 954 break 955 end 956 i = add i 1 957 end 958 chk eq get v_prog_cnt 0 16 959 chk and eq eval_txt s_fn_fill0 0 ge get g_res_pidx 0 0 960 chk eq eval_txt s_fn_more -3 961 end 962 963 note ---- Test 8: Golden vectors from tests/language/golden/v0.txt ---- 964 fn hex_from_obj idx ulong to ulong 965 el = ulong og_canonical_encode idx 966 for i ulong el bound 1024 967 b = ulong get v_enc i 968 put g_hex_enc mul i 2 get t_hex shr b 4 969 put g_hex_enc add mul i 2 1 get t_hex and b 15 970 end 971 ib = mul idx 32 972 for i ulong 32 973 b = ulong get v_og_id add ib i 974 put g_hex_id mul i 2 get t_hex shr b 4 975 put g_hex_id add mul i 2 1 get t_hex and b 15 976 end 977 ret mul el 2 978 end 979 980 fn hex_from_cp to ulong 981 cl = vro_g OLW_ACC VRO_CLEN 982 cb = mul OLW_ACC 4096 983 for i ulong cl bound 256 984 b = ulong get vro_code add cb i 985 put g_hex_enc mul i 2 get t_hex shr b 4 986 put g_hex_enc add mul i 2 1 get t_hex and b 15 987 end 988 pb = vpg_ib OLW_ACC 0 989 for i ulong 32 990 b = ulong get vpg_ids add pb i 991 put g_hex_id mul i 2 get t_hex shr b 4 992 put g_hex_id add mul i 2 1 get t_hex and b 15 993 end 994 ret mul cl 2 995 end 996 997 fn find_tab pos ulong lend ulong to ulong 998 p = pos 999 while lt p lend bound 2048 1000 if eq ulong get g_filebuf p 9 1001 ret p 1002 end 1003 p = add p 1 1004 end 1005 ret lend 1006 end 1007 1008 fn chk_golden_enc enc_len ulong woff ulong wlen ulong to void 1009 if ne enc_len wlen 1010 chk false 1011 ret 1012 end 1013 for i ulong enc_len bound 1024 1014 if ne get g_hex_enc i get g_filebuf add woff i 1015 chk false 1016 ret 1017 end 1018 end 1019 chk true 1020 end 1021 1022 fn chk_golden_id woff ulong wlen ulong to void 1023 if ne wlen 64 1024 chk false 1025 ret 1026 end 1027 for i ulong 64 1028 if ne get g_hex_id i get g_filebuf add woff i 1029 chk false 1030 ret 1031 end 1032 end 1033 chk true 1034 end 1035 1036 fn copy_golden_src off ulong slen ulong to void 1037 for i ulong slen bound 1024 1038 put g_line i get g_filebuf add off i 1039 end 1040 put g_line_len 0 slen 1041 end 1042 1043 fn check_golden_line start ulong lend ulong to bool 1044 if ge start lend 1045 ret false 1046 end 1047 kch = ulong get g_filebuf start 1048 if or eq kch 35 eq kch 10 1049 ret false 1050 end 1051 t1 = find_tab start lend 1052 t2 = find_tab add t1 1 lend 1053 t3 = find_tab add t2 1 lend 1054 if ge t3 lend 1055 chk false 1056 ret false 1057 end 1058 copy_golden_src add t1 1 sub t2 add t1 1 1059 rc = parse_line 1060 chk eq rc 0 1061 if ne rc 0 1062 ret false 1063 end 1064 enc_hex_len = ulong 0 1065 if eq kch 69 1066 graph_reset 1067 oi = lower_expr_fresh 1068 chk ge oi 0 1069 if lt oi 0 1070 ret false 1071 end 1072 enc_hex_len = hex_from_obj ulong oi 1073 else 1074 lrc = lower_program 1075 chk eq lrc 0 1076 if ne lrc 0 1077 ret false 1078 end 1079 enc_hex_len = hex_from_cp 1080 end 1081 chk_golden_enc enc_hex_len add t2 1 sub t3 add t2 1 1082 chk_golden_id add t3 1 sub lend add t3 1 1083 ret true 1084 end 1085 1086 fn test_golden plen ulong to void 1087 fd = fopen g_pathbuf 0 plen 0 0 1088 chk ge fd 0 1089 if lt fd 0 1090 ret 1091 end 1092 tot = ulong 0 1093 while lt tot 32768 bound 64 1094 k = read int fd g_filebuf tot sub 32768 tot 1095 if le k 0 1096 break 1097 end 1098 tot = add tot ulong k 1099 end 1100 u = fclose int fd 1101 pos = ulong 0 1102 vec_n = ulong 0 1103 while lt pos tot bound 256 1104 lend = pos 1105 while lt lend tot bound 4096 1106 if eq ulong get g_filebuf lend 10 1107 break 1108 end 1109 lend = add lend 1 1110 end 1111 if check_golden_line pos lend 1112 vec_n = add vec_n 1 1113 end 1114 pos = add lend 1 1115 end 1116 chk ge vec_n 20 1117 end 1118 1119 fn main to int 1120 sha_kinit 1121 plen = len t_default_golden 1122 for i ulong plen bound 256 1123 put g_pathbuf i get t_default_golden i 1124 end 1125 ac = argcnt 1126 if ge ac 2 1127 ar = argread 1 g_pathbuf 0 255 1128 if gt ar 0 1129 plen = ulong ar 1130 end 1131 end 1132 test_literal_spellings 1133 test_width_changes_id 1134 test_whitespace_comments_and_names 1135 test_determinism 1136 test_fail_closed 1137 test_depth_and_capacity 1138 test_programs 1139 test_golden plen 1140 p = get g_pass 0 1141 t = get g_total 0 1142 if eq p t 1143 write_all t_pass len t_pass 1144 else 1145 write_all t_fail len t_fail 1146 end 1147 print_u64 p 1148 write_all t_slash len t_slash 1149 print_u64 t 1150 write_all t_nl len t_nl 1151 if eq p t 1152 ret 0 1153 end 1154 ret 1 1155 end