_system.abc 31.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
.comp 920 01011101101
.code 0 0 0
.start _nostart_
.endinfo

.module m__system "_system"

.implab	e_system_nind e_system_eaind

.export	_channel_code

12
.export	EMPTY INT BOOL CHAR REAL FILE _STRING_ _ARRAY_ ARRAY INT32 REAL32
13 14 15 16 17 18
.export	_reserve _cycle_in_spine _hnf 
.export	_type_error _match_error selector_m_error index_error
.export	_print_graph _eval_to_nf
.export	_Tuple
.export	_Select _select_code
.export	_Nil _Cons
19
.export e__predef_d_Unit
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

.export	e_system_dAP e_system_nAP e_system_eaAP e_system_dind
.export	e_system_dif e_system_lif e_system_sif e_system_nif e_system_eaif
.export	_HnfReducer _hnf_reducer
.export	_Defer _defer_code

.export	d_S.1 d_S.2 d_S.3 d_S.4 d_S.5 d_S.6
.export	n_S.1 n_S.2 n_S.3 n_S.4 n_S.5 n_S.6
.export	ea_S.1 ea_S.2 ea_S.3 ea_S.4 ea_S.5 ea_S.6

.export	d_Sr.1 d_Sr.2 d_Sr.3 d_Sr.4 d_Sr.5 d_Sr.6
.export	n_Sr.1 n_Sr.2 n_Sr.3 n_Sr.4 n_Sr.5 n_Sr.6
.export	ea_Sr.1 ea_Sr.2 ea_Sr.3 ea_Sr.4 ea_Sr.5 ea_Sr.6

|| don't change the order of the following 9 descriptors

|.desc CHANNEL	_channel_code	_hnf	1	""
.desc GRAPH	_hnf	_hnf	0 0	""
.desc _ARRAY_	_hnf	_hnf	0 0	"_ARRAY_"
.desc _STRING_	_hnf	_hnf	0 0	"_STRING_"
.desc REAL	_hnf	_hnf	0 0	"REAL"
41
.desc INT	_hnf	_hnf	0 0	"INT"
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
.desc REAL32	_hnf	_hnf	0 0	"REAL32"
.desc INT32		_hnf	_hnf	0 0	"INT32"
.desc BOOL	_hnf	_hnf	0 0	"BOOL"
.desc CHAR	_hnf	_hnf	0 0	"CHAR"

.desc EMPTY	_reserve	_hnf	0 0	"EMPTY"

.desc _Tuple	_hnf	_hnf	32 0	"_Tuple"
.desc _Select	_hnf	_hnf	2 0	"_Select"
.desc _Nil	_hnf	_hnf	0	0 "Nil"

.desc _Cons	_hnf	l_Cons	2	0 "Cons"

.record FILE ii 0 2 "File"

57 58
.desc e__predef_d_Unit _hnf _hnf 0 0 "_Unit"

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
.desc e_system_dAP	_hnf	e_system_lAP	2 0	"AP"
.desc e_system_dif	e_system_nif	e_system_lif	3 0	"if"

.desc e_system_dind	e_system_nind	_hnf	0 0	"_ind"

.desc _Defer	_defer_code	_hnf	0 0	"_Defer"

.desc ARRAY	_hnf	_hnf	1 0	"ARRAY"

.desc _HnfReducer	_hnf_reducer	_hnf_reducer	0 0	"HnfReducer"
| .desc _NfReducer	_nf_reducer	_nf_reducer	0 0	"NfReducer"

.export e__system_kFinalizer
.record e__system_kFinalizer diii 0 3 "Finalizer"
.export e__system_kFinalizerGCTemp
.record e__system_kFinalizerGCTemp daii 1 2 "FinalizerGCTemp"

.o 0 2 i i
_match_error
	print	"Run time error, rule \'"
	printD
	print	"\' in module \'"
	printD
	print	"\' does not match\n"
	halt

.o 0 0
selector_m_error
	print	"Run time error, selector does not match"
	halt

.n 0 _Defer
.o 1 0
_defer_code
	print	"Error: defer code entered"
	halt

.a 2 ea_Cons
.o 2 0
l_Cons
	push_args 0 1 1
	update_a 2 1
	create
	update_a 0 3
	pop_a 1
	fill _Cons 2 _hnf 2
.d 1 0
	rtn

.export _Conss n_Conss ea_Conss
.desc _Conss n_Conss l_Conss 2 0 "Cons!"

.a 2 ea_Conss
.o 2 0
l_Conss
	push_args 0 1 1
	update_a 2 1
	create
	update_a 0 3
	pop_a 1
	jsr_eval 0
	fill _Cons 2 _hnf 2
.d 1 0
	rtn

.o 3 0
ea_Cons
	fill _Cons 2 _hnf 2
.d 1 0
	rtn

.n 2 _Conss ea_Conss
.o 1 0
n_Conss
	push_node _cycle_in_spine 2
.o 3 0
ea_Conss
	jsr_eval 0
	fill _Cons 2 _hnf 2
.d 1 0
	rtn

.export _Consts n_Consts ea_Consts
.desc _Consts n_Consts l_Consts 2 0 "Cons!"

.a 2 ea_Consts
.o 2 0
l_Consts
	push_args 0 1 1
	update_a 2 1
	create
	update_a 0 3
	pop_a 1
	jsr_eval 1
	fill _Cons 2 _hnf 2
.d 1 0
	rtn

.n 2 _Consts ea_Consts
.o 1 0
n_Consts
	push_node _cycle_in_spine 2
.o 3 0
ea_Consts
	jsr_eval 1
	fill _Cons 2 _hnf 2
.d 1 0
	rtn

.export _Conssts n_Conssts ea_Conssts
.desc _Conssts n_Conssts l_Conssts 2 0 "Cons!!"

.a 2 ea_Conssts
.o 2 0
l_Conssts
	push_args 0 1 1
	update_a 2 1
	create
	update_a 0 3
	pop_a 1
	jsr_eval 1
	jsr_eval 0
	fill _Cons 2 _hnf 2
.d 1 0
	rtn

.n 2 _Conssts ea_Conssts
.o 1 0
n_Conssts
	push_node _cycle_in_spine 2
.o 3 0
ea_Conssts
	jsr_eval 1
	jsr_eval 0
	fill _Cons 2 _hnf 2
.d 1 0
	rtn

.export _Consi _Consr _Consc _Consb _Consf
.record _Consi lia 1 1 "[#Int]"
199
.record _Consr lra 1 1 "[#Real]"
200 201 202 203 204 205
.record _Consc lca 1 1 "[#Char]"
.record _Consb lba 1 1 "[#Bool]"
.record _Consf lfa 1 2 "[#File]"

.export _Consits _Consrts _Conscts _Consbts _Consfts
.record _Consits lia 1 1 "[#Int!]"
206
.record _Consrts lra 1 1 "[#Real!]"
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926
.record _Conscts lca 1 1 "[#Char!]"
.record _Consbts lba 1 1 "[#Bool!]"
.record _Consfts lfa 1 2 "[#File!]"

.export _Consa
.record _Consa laa 2 0 "[#{}]"

.descs d_S.1 n_S.1 _ 1 0 "_S.1"
.pb "_S.1"
.n -1 d_S.1 ea_S.1
.o 1 0
n_S.1
	push_node _reserve 1
	jsr_eval 0
	get_node_arity 0
	pushI 1
	push_arg_b 0
	update_a 0 1
	pop_a 1
	jsr_eval 0
	getWL 1
	fill_a 0 1
	release
	pop_a 1
.d 1 0
	rtn
.o 2 0
ea_S.1
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0
	get_node_arity	0
	pushI	1
	push_arg_b	0
	update_a	0 1
	pop_a	1
	jmp_eval_upd
.pe

.o 1 0
o_S.1
	get_node_arity	0
	pushI	1
	push_arg_b	0
	update_a	0 1
	pop_a	1
.d 1 0
	rtn

.descs d_S.2 n_S.2 _ 2 0 "_S.2"
.pb "_S.2"
.n -1 d_S.2 ea_S.2
.o 1 0
n_S.2
	push_node _reserve 1
	jsr_eval 0
	get_node_arity 0
	eqI_b 2 0
	jmp_false n_S.2_
	pop_b 1
	repl_arg 2 2
	jsr_eval 0
	getWL 1
	fill_a 0 1
	release
	pop_a 1
.d 1 0
	rtn
n_S.2_
	pop_b 1
	repl_arg 3 2
	jsr_eval 0
	getWL 1
	fill_a 0 1
	release
	pop_a 1
.d 1 0
	rtn
.o 2 0
ea_S.2
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0
	get_node_arity	0
	eqI_b 2 0
	jmp_false ea_S.2_
	pop_b 1
	repl_arg 2 2
	jmp_eval_upd
ea_S.2_
	repl_arg 3 2
	pop_b 1
	jmp_eval_upd
.pe

.o 1 0
o_S.2
	get_node_arity	0
	eqI_b 2 0
	jmp_false o_S.2_
	pop_b 1
	repl_arg 2 2
.d 1 0
	rtn
o_S.2_
	repl_arg 3 2
	pop_b 1
.d 1 0
	rtn

.descs d_S.3 n_S.3 _ 4 0 "_S.3"
.pb "_S.3"
.n -1 d_S.3 ea_S.3
.o 1 0
n_S.3
	push_node _reserve 1
	jsr_eval 0
	get_node_arity 0
	pushI 3
	push_arg_b 0
	jsr_eval 0
	getWL 2
	fill_a 0 2
	release
	pop_a 2
.d 1 0
	rtn

.o 2 0
ea_S.3
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0
	get_node_arity	0
	pushI	3
	push_arg_b	0
	update_a	0 1
	pop_a	1
	jmp_eval_upd
.pe

.o 1 0
o_S.3
	get_node_arity	0
	pushI	3
	push_arg_b	0
	update_a	0 1
	pop_a	1
.d 1 0
	rtn

.descs d_S.4 n_S.4 _ 5 0 "_S.4"
.n -1 d_S.4 ea_S.4
.o 1 0
n_S.4
	push_node _reserve 1
	jsr_eval 0
	get_node_arity 0
	pushI 4
	push_arg_b 0
	jsr_eval 0
	getWL 2
	fill_a 0 2
	release
	pop_a 2
.d 1 0
	rtn

.o 2 0
ea_S.4
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0
	get_node_arity	0
	pushI	4
	push_arg_b	0
	update_a	0 1
	pop_a	1
	jmp_eval_upd

.o 1 0
o_S.4
	get_node_arity	0
	pushI	4
	push_arg_b	0
	update_a	0 1
	pop_a	1
.d 1 0
	rtn

.descs d_S.5 n_S.5 _ 6 0 "_S.5"
.n -1 d_S.5 ea_S.5
.o 1 0
n_S.5
	push_node _reserve 1
	jsr_eval 0
	get_node_arity 0
	pushI 5
	push_arg_b 0
	jsr_eval 0
	getWL 2
	fill_a 0 2
	release
	pop_a 2
.d 1 0
	rtn

.o 2 0
ea_S.5
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0
	get_node_arity	0
	pushI	5
	push_arg_b	0
	update_a	0 1
	pop_a	1
	jmp_eval_upd

.o 1 0
o_S.5
	get_node_arity	0
	pushI	5
	push_arg_b	0
	update_a	0 1
	pop_a	1
.d 1 0
	rtn

.descs d_S.6 n_S.6 _ 7 0 "_S.6"
.n -1 d_S.6 ea_S.6
.o 1 0
n_S.6
	push_node _reserve 1
	jsr_eval 0
	get_node_arity 0
	pushI 6
	push_arg_b 0
	jsr_eval 0
	getWL 2
	fill_a 0 2
	release
	pop_a 2
.d 1 0
	rtn

.o 2 0
ea_S.6
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0
	get_node_arity	0
	pushI	6
	push_arg_b	0
	update_a	0 1
	pop_a	1
	jmp_eval_upd


.o 1 0
o_S.6
	get_node_arity	0
	pushI	6
	push_arg_b	0
	update_a	0 1
	pop_a	1
.d 1 0
	rtn



.desc d_Sr.1 n_Sr.1 o_Sr.1 1 0 "_Sr.1"
.pb "_Sr.1"
.n -1 d_Sr.1 ea_Sr.1
.o 1 0
n_Sr.1
	push_node _reserve 1
	jsr_eval 0

	push_args_u 0 1 1
	buildh _Nil 0
	fill1 _Tuple 1 2 01
.keep 1 0

	jsr_eval 0
	getWL 2
	fill_a 0 2
	release
	pop_a 2
.d 1 0
	rtn

.o 2 0
ea_Sr.1
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0

	push_args_u 0 1 1
	buildh _Nil 0
	fill1 _Tuple 1 2 01
.keep 1 0

	update_a	0 1
	pop_a	1
	jmp_eval_upd
.pe

.o 1 0
o_Sr.1
	push_args_u 0 1 1
	buildh _Nil 0
	fill1 _Tuple 1 2 01
.keep 1 0

	update_a	0 1
	pop_a	1
.d 1 0
	rtn

.desc d_Sr.2 n_Sr.2 o_Sr.2 1 0 "_Sr.2"
.pb "_Sr.2"
.n -1 d_Sr.2 ea_Sr.2
.o 1 0
n_Sr.2
	push_node _reserve 1
	jsr_eval 0
	get_node_arity 0
	eqI_b 2 0
	update_b 0 1
	pop_b 1
	jmp_false n_Sr.2_

	push_args_u 0 2 2
	pop_a 1
	buildh _Nil 0
	fill1 _Tuple 2 2 001
.keep 1 0
	update_a 0 1
	pop_a 1

	jsr_eval 0
	getWL 1
	fill_a 0 1
	release
	pop_a 1
.d 1 0
	rtn

n_Sr.2_
	push_args_u 0 3 2
	pop_a 1
	buildh _Nil 0
	fill2 _Tuple 3 2 0010
.keep 1 0
	update_a 0 1
	pop_a 1

	jsr_eval 0
	getWL 1
	fill_a 0 1
	release
	pop_a 1
.d 1 0
	rtn
.o 2 0
ea_Sr.2
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0
	get_node_arity	0
	eqI_b 2 0
	update_b 0 1
	pop_b 1
	jmp_false ea_Sr.2_

	push_args_u 0 2 2
	pop_a 1
	buildh _Nil 0
	fill1 _Tuple 2 2 001
.keep 1 0
	update_a 0 1
	pop_a 1

	jmp_eval_upd

ea_Sr.2_
	push_args_u 0 3 2
	pop_a 1
	buildh _Nil 0
	fill2 _Tuple 3 2 0010
.keep 1 0
	update_a 0 1
	pop_a 1

	jmp_eval_upd
.pe

.o 1 0
o_Sr.2
	get_node_arity	0
	eqI_b 2 0
	update_b 0 1
	pop_b 1
	jmp_false o_Sr.2_

	push_args_u 0 2 2
	pop_a 1
	buildh _Nil 0
	fill1 _Tuple 2 2 001
.keep 1 0
	update_a 0 1
	pop_a 1

.d 1 0
	rtn

o_Sr.2_
	push_args_u 0 3 2
	pop_a 1
	buildh _Nil 0
	fill2 _Tuple 3 2 0010
.keep 1 0
	update_a 0 1
	pop_a 1

.d 1 0
	rtn

.desc d_Sr.3 n_Sr.3 o_Sr.3 1 0 "_Sr.3"
.pb "_Sr.3"
.n -1 d_Sr.3 ea_Sr.3
.o 1 0
n_Sr.3
	push_node _reserve 1
	jsr_eval 0

	push_args_u 0 3 3
	pop_a 2
	buildh _Nil 0
	fill2 _Tuple 3 2 0001
.keep 1 0

	jsr_eval 0
	getWL 2
	fill_a 0 2
	release
	pop_a 2
.d 1 0
	rtn

.o 2 0
ea_Sr.3
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0

	push_args_u 0 3 3
	pop_a 2
	buildh _Nil 0
	fill2 _Tuple 3 2 0001
.keep 1 0

	update_a	0 1
	pop_a	1
	jmp_eval_upd
.pe

.o 1 0
o_Sr.3
	push_args_u 0 3 3
	pop_a 2
	buildh _Nil 0
	fill2 _Tuple 3 2 0001
.keep 1 0

	update_a	0 1
	pop_a	1
.d 1 0
	rtn

.desc d_Sr.4 n_Sr.4 o_Sr.4 1 0 "_Sr.4"
.n -1 d_Sr.4 ea_Sr.4
.o 1 0
n_Sr.4
	push_node _reserve 1
	jsr_eval 0

	push_args_u 0 4 4
	pop_a 3
	buildh _Nil 0
	fill2 _Tuple 4 2 00001
.keep 1 0

	jsr_eval 0
	getWL 2
	fill_a 0 2
	release
	pop_a 2
.d 1 0
	rtn

.o 1 0
o_Sr.4
	push_args_u 0 4 4
	pop_a 3
	buildh _Nil 0
	fill2 _Tuple 4 2 00001
.keep 1 0

	update_a	0 1
	pop_a	1
.d 1 0
	rtn

.o 2 0
ea_Sr.4
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0

	push_args_u 0 4 4
	pop_a 3
	buildh _Nil 0
	fill2 _Tuple 4 2 00001
.keep 1 0

	update_a	0 1
	pop_a	1
	jmp_eval_upd


.desc d_Sr.5 n_Sr.5 o_Sr.5 1 0 "_Sr.5"
.n -1 d_Sr.5 ea_Sr.5
.o 1 0
n_Sr.5
	push_node _reserve 1
	jsr_eval 0

	push_args_u 0 5 5
	pop_a 4
	buildh _Nil 0
	fill2 _Tuple 5 2 000001
.keep 1 0

	jsr_eval 0
	getWL 2
	fill_a 0 2
	release
	pop_a 2
.d 1 0
	rtn

.o 1 0
o_Sr.5
	push_args_u 0 5 5
	pop_a 4
	buildh _Nil 0
	fill2 _Tuple 5 2 000001
.keep 1 0

	update_a	0 1
	pop_a	1
.d 1 0
	rtn

.o 2 0
ea_Sr.5
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0

	push_args_u 0 5 5
	pop_a 4
	buildh _Nil 0
	fill2 _Tuple 5 2 000001
.keep 1 0

	update_a	0 1
	pop_a	1
	jmp_eval_upd


.desc d_Sr.6 n_Sr.6 o_Sr.6 1 0 "_Sr.6"
.n -1 d_Sr.6 ea_Sr.6
.o 1 0
n_Sr.6
	push_node _reserve 1
	jsr_eval 0

	push_args_u 0 6 6
	pop_a 5
	buildh _Nil 0
	fill2 _Tuple 6 2 0000001
.keep 1 0

	jsr_eval 0
	getWL 2
	fill_a 0 2
	release
	pop_a 2
.d 1 0
	rtn

.o 1 0
o_Sr.6
	push_args_u 0 6 6
	pop_a 5
	buildh _Nil 0
	fill2 _Tuple 6 2 0000001
.keep 1 0

	update_a	0 1
	pop_a	1
.d 1 0
	rtn

.o 2 0
ea_Sr.6
	push_arg	0 1 1
	push_a	2
.keep 1 0
	fill	e_system_dind -2 e_system_nind 2
.keep 1 0
	update_a	0 1
	pop_a	1
	jsr_eval 0

	push_args_u 0 6 6
	pop_a 5
	buildh _Nil 0
	fill2 _Tuple 6 2 0000001
.keep 1 0

	update_a	0 1
	pop_a	1
	jmp_eval_upd





.n 2 _Select
.o 1 0
_select_code
	print	"Error: select code entered"
	halt

.o 0 0
e_system_lAP
	print	"Error: lazy entry of AP entered"
	halt

.o 3 0
e_system_eaAP
.d 2 0
	jmp	ea_AP

.n 2 e_system_dAP e_system_eaAP
.o 1 0
e_system_nAP
	push_node	_reserve 2
.o 2 0
ea_AP
	jsr_eval 0
927
	jsr_ap 1
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
	fill_a	0 1
	pop_a	1
.d 1 0
	rtn

.o 2 0
e_system_lif
	repl_args 2 2
.d 3 0
	jmp eval_args_if

.n 3 e_system_dif e_system_eaif
.o 1 0
e_system_nif
	push_node _reserve 3
.d 3 0
	jsr eval_args_if
.o 1 0
	getWL 1
	fill_a 0 1
	release
	pop_a 1
.d 1 0
	rtn

.o 3 0
eval_args_if
	jsr_eval 0
	pushB_a 0
	pop_a 1
.o 2 1 b
e_system_sif
	jmp_false ifelse
	update_a 0 1
	pop_a 1
	jmp_eval
ifelse
	pop_a 1
	jmp_eval

.o 4 0
e_system_eaif
	jsr_eval 0
	pushB_a 0
	pop_a 1
	jmp_false eaifelse
	update_a 0 1
	pop_a 1
	jmp_eval_upd
eaifelse
	pop_a 1
	jmp_eval_upd

.n 0 _Nil
.o 1 0			
_hnf
.d 1 0
	rtn

.n 0 EMPTY
.o 1 0
_cycle_in_spine
.o 1 0
_reserve
	print	"Run Time Warning: cycle in spine detected\n"
	halt

|.n 0 EMPTY
|.o 1 0
|_reserve
|	setwait	0
|	suspend
|.d 1 0
|	rtn

.o 0 0
_hnf_reducer
.o 0 0
_channel_code
	halt
|	jsr_eval 0
|	stop_reducer

|.o 1 0
|_nf_reduce:	jsr_eval 0
|	get_node_arity	0
|	eqI_b	0 0	| check if arity is zero
|	jmp_true	_last1
|	push_b	0	| replace the node by
|	push_b	0
|	repl_args_b		| its arguments
|.o 0 1 i
|_reduce_args
|	eqI_b	0 0	| check nr of args to do
|	jmp_true	_last
|.d 1 0
|	jsr	_nf_reduce
|.o 0 0
|	decI
|	jmp	_reduce_args
|_last1:	pop_a	1
|_last:	pop_b	1
|.d 0 0
|	rtn

|.o 0 0
|_nf_reducer
|.d 1 0
|	jsr	_nf_reduce
|.o 0 0
|	stop_reducer

.o 0 0
_type_error
	print	"Run Time Error: type error\n"
	halt

.o 0 0
index_error
	print	"Run Time Error: index out of range\n"
	halt

.o 1 0
_print_graph
.d 1 0
	jsr	_print
.o 0 0
	print_sc	"\n"
.d 0 0
	rtn

.o 1 0
_print	
	pushI	0	| push the bracket count
_continue_print
	jsr_eval	0
.o 1 1 i
_print2
	is_record	0
	jmp_true	_print_record
	eq_nulldesc	_Tuple 0
	jmp_true	_print_tuple

	get_node_arity	0
	eqI_b	0 0
	jmp_true	_print_last

	eq_desc	_Cons 2 0
	jmp_true	_print_list
	eq_desc	ARRAY 1 0
	jmp_true	_print_array

	print_sc	"("
	print_symbol_sc	0
	push_b	0
	push_b	0	| replace the node by
	repl_args_b		| leave arity on b-stack
_print_args
	print_sc	" "
	eqI_b	1 0	| check if last argument
	jmp_true	_print_last_arg
.d 1 0
	jsr	_print
.o 0 0
	decI		| decrease argument count
	jmp	_print_args
_print_last_arg
	pop_b	1	| remove argument count
	incI		| increment bracket count
	jmp	_continue_print	| optimised tail recursion!
_print_last
	pop_b	1	| remove arity
	eq_desc	_Nil 0 0
	jmp_true	_print_nil
	eq_desc	_ARRAY_ 0 0
	jmp_true	_print__array_
	eq_desc	_STRING_ 0 0
	jmp_true	_print_char_array
1106 1107
	eq_desc	e__predef_d_Unit 0 0
	jmp_true	_print_unit
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
	print_symbol_sc	0
	pop_a	1	| remove node
_print_brackets
	eqI_b	0 0	| stop printing brackets if
	jmp_true	_exit_brackets	| bracket count is zero
	print_sc	")"
	decI		| decrement bracket count
	jmp	_print_brackets
_exit_brackets
	pop_b	1	| remove bracket count
.d 0 0
	rtn

_print_list
	pop_b	1
	print_sc	"["
_print_rest_list
	repl_args	2 2
.d 1 0
	jsr	_print
.o 0 0
	jsr_eval 0
	eq_desc	_Nil 0 0
	jmp_true	_print_last_list
	print_sc	","
	jmp	_print_rest_list
_print_last_list
	print_sc	"]"
	pop_a	1
	jmp	_print_brackets




_print_unboxed_list
	print_sc	"["

_print_unboxed_list_lp0
	incI
	push_r_arg_t
	eqC_b	'R' 0
	updatepop_b 0 1
	jmp_true _print_ul_record

	push_t_r_args

_print_unboxed_list_lp1
	incI
	push_b	0
	push_r_arg_t
_print_unboxed_list_lp2
	eqC_b	'i' 0
	jmp_true	_print_ul_integer
	eqC_b	'c' 0
	jmp_true	_print_ul_char
	eqC_b	'r' 0
	jmp_true	_print_ul_real
	eqC_b	'b' 0
	jmp_true	_print_ul_bool
	eqC_b	'f' 0
	jmp_true	_print_ul_file
	eqC_b	'a' 0
	jmp_true	_print_ul_graph
	halt

_print_ul_integer
	pop_b	1
	push_b	1
	update_b	1 2
	updatepop_b	0 1

	print_int

	jmp	_print_rest_unboxed_list

_print_ul_char
	pop_b	1
	push_b	1
	update_b	1 2
	updatepop_b	0 1

	print_sc "'"
	print_char
	print_sc "'"

	jmp	_print_rest_unboxed_list

_print_ul_real
	pop_b	1
1197 1198 1199
	push_b	1
	update_b	1 2
	updatepop_b	0 1
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274

	print_real

	jmp	_print_rest_unboxed_list

_print_ul_bool
	pop_b	1
	push_b	1
	update_b	1 2
	updatepop_b	0 1
.d 0 1 b
	jsr	_print_bool
.o 0 0
	jmp	_print_rest_unboxed_list

_print_ul_file
	pop_b	1
	updatepop_b	0 2

	print	"File"

	jmp	_print_rest_unboxed_list

_print_ul_graph
	pop_b	1

	jsr_eval 0

	pushI	0
.d 1 1 i
	jsr	_print2
.o 0 0
	jmp	_print_rest_unboxed_list

_print_rest_unboxed_list
	incI
	push_b 0
	push_r_arg_t
	eqC_b	'a' 0
	jmp_false _print_ul_next_field

	push_b 1
	incI
	push_r_arg_t
	eqI_b	0 0
	updatepop_b 0 1
	jmp_false	_print_ul_next_field

	pop_b 2

	jsr_eval 0
	eq_desc	_Nil 0 0
	jmp_true	_print_last_unboxed_list

	print_sc	","

	push_t_r_a 0

	push_b	0
	push_r_arg_t
	eqC_b	'l' 0
	updatepop_b 0 1
	jmp_true	_print_unboxed_list_lp0
	halt

_print_last_unboxed_list
	pop_a	1
	print_sc	"]"
	jmp	_print_brackets

_print_ul_next_field
	eqC_b	',' 0
	jmp_true _print_ul_comma_next_field
	eqC_b	'(' 0
	jmp_true _print_ul_open_tuple_next_field
1275 1276
	eqC_b	'{' 0
	jmp_true _print_ul_open_record_next_field
1277
	eqC_b	')' 0
1278 1279 1280
	jmp_true _print_ul_close_tuple_or_record_next_field
	eqC_b	'}' 0
	jmp_true _print_ul_close_tuple_or_record_next_field
1281 1282 1283 1284 1285 1286 1287 1288
	print_sc " "
	jmp	_print_unboxed_list_lp2

_print_ul_open_tuple_next_field
	pop_b 1
	print_sc " ("
	jmp	_print_ul_next_field_without_space

1289 1290 1291 1292 1293
_print_ul_open_record_next_field
	pop_b 1
	print_sc " ("
	jmp	_print_ul_unboxed_record

1294 1295 1296 1297 1298 1299 1300 1301
_print_ul_comma_next_field
	pop_b 1
	print_sc ","
_print_ul_next_field_without_space
	incI
	push_b	0
	push_r_arg_t
	eqC_b	'(' 0
1302 1303
	jmp_true _print_ul_next_field_without_space_tuple
	eqC_b	'{' 0
1304
	jmp_false _print_unboxed_list_lp2
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343

_print_ul_next_field_without_space_record
	pop_b 1
	print_sc "("

_print_ul_unboxed_record
	pushI 0
	push_b 1
count_ul_unboxed_records
	incI
	push_b 0
	push_r_arg_t
	eqC_b	'{' 0
	jmp_true count_ul_unboxed_record
	eqI_b	0 0
	updatepop_b 0 1
	jmp_false count_ul_unboxed_records

	incI
	push_r_arg_D

	pushI 2
	addI
	printD

	incI
	push_b	0
	push_r_arg_t
	jmp	_print_ul_next_field

count_ul_unboxed_record
	pop_b 1
	push_b 1
	incI
	update_b 0 2
	pop_b 1
	jmp count_ul_unboxed_records

_print_ul_next_field_without_space_tuple
1344 1345 1346 1347
	pop_b 1
	print_sc "("
	jmp	_print_ul_next_field_without_space

1348
_print_ul_close_tuple_or_record_next_field
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
	pop_b 1
	print_sc ")"
	jmp	_print_rest_unboxed_list

_print_ul_record
	pushD_a 0
.d 0 1 i
	jsr DtoAC
.o 1 0
	push_a 0
	pushI 2
	push_arraysize CHAR 0 1
	subI
	pushI 2
.d 1 2 ii
	jsr sliceAC
.o 1 0
.d 1 0
	jsr	print_chars_sc
.o 0 0

	print_sc " "
	push_t_r_args
	incI
	jmp	_print_ul_next_field_without_space


_print__array_
.d 1 1 i
	jmp	_print__array2

_print_array
	pop_b	1
	pushA_a	0
	update_a	0 1
	pop_a	1
.o 1 1 i
_print__array
	eq_desc	_STRING_ 0 0
	jmp_true	_print_char_array
_print__array2
	push_r_args_b	0 0 2 2 1

	print_sc	"{"

	push_b	0
	eq_desc_b	BOOL 0
	jmp_true	_print_bool_array

	push_b	0
1399
	eq_desc_b	INT 0
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469
	jmp_true	_print_int_array

	push_b	0
	eq_desc_b	REAL 0
	jmp_true	_print_real_array

	pushI	0

	push_a	0
	push_arraysize	_ 0 1

	push_b	2
	update_b	2 3
	update_b	1 2
	update_b	0 1
	pop_b	1

	pushI	0
	eqI
	jmp_false	_print_record_array

	jmp	_print_array_lp2
.o 1 2 i i
_print_array_lp1
	eqI_b	0 1
	jmp_true	_no_comma_0
	print_sc	","
_no_comma_0
	push_b	1
	push_a	0
	select	_ 0 1
.d 1 0
	jsr	_print
.o 0 0
	push_b	1
	incI
	update_b	0 2
	pop_b 1
	decI
_print_array_lp2
	eqI_b	0 0
	jmp_false	_print_array_lp1
	pop_a	1
	pop_b	2
	print_sc	"}"
	jmp	_print_brackets

_print_record_array
	jmp	_print_record_array_lp2
.o 1 2 i i
_print_record_array_lp1
	eqI_b	0 1
	jmp_true	_no_comma_ar
	print_sc	","
_no_comma_ar
	push_r_args_b	0 0 2 2 1
	printD

	push_b	1
	push_a	0
	push_a_r_args

_print_a_record_lp
	push_b	0
	push_r_arg_t
	eqI_b	0 0
	jmp_true	_end_print_a_record
	eqC_b	',' 0
	jmp_true	_print_ar_tuple_comma
	eqC_b	')' 0
1470 1471 1472
	jmp_true	_print_ar_close_tuple_or_record_char
	eqC_b	'}' 0
	jmp_true	_print_ar_close_tuple_or_record_char
1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
	print_sc	" "
_print_a_record_lp__
	eqC_b	'r' 0
	jmp_true	_print_ar_real
	eqC_b	'i' 0
	jmp_true	_print_ar_integer
	eqC_b	'c' 0
	jmp_true	_print_ar_char
	eqC_b	'b' 0
	jmp_true	_print_ar_bool
	eqC_b	'f' 0
	jmp_true	_print_ar_file
	eqC_b	'a' 0
	jmp_true	_print_ar_graph
	eqC_b	'(' 0
	jmp_true	_print_ar_open_tuple_char
1489 1490
	eqC_b	'{' 0
	jmp_true	_print_ar_open_record_char
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520
	halt

_print_ar_integer
	pop_b	1
	push_b	1
	update_b	1 2
	update_b	0 1
	pop_b	1

	print_int

	incI
	jmp	_print_a_record_lp

_print_ar_char
	pop_b	1
	push_b	1
	update_b	1 2
	update_b	0 1
	pop_b	1

	print_sc "'"
	print_char
	print_sc "'"

	incI
	jmp	_print_a_record_lp

_print_ar_real
	pop_b	1
1521 1522 1523 1524
	push_b	1
	update_b	1 2
	update_b	0 1
	pop_b	1
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585

	print_real

	incI
	jmp	_print_a_record_lp

_print_ar_bool
	pop_b	1
	push_b	1
	update_b	1 2
	update_b	0 1
	pop_b	1
	jmp_true	_print_ar_true
	
	print	"False"
	incI
	jmp	_print_a_record_lp	

_print_ar_true
	print	"True"
	incI
	jmp	_print_a_record_lp	

_print_ar_file
	pop_b	1
	update_b	0 2
	pop_b	2

	print	"File"

	incI
	jmp	_print_a_record_lp

_print_ar_graph
	pop_b	1

	jsr_eval 0
	pushI	0
	eq_desc	_ARRAY_ 0 0
	jmp_true	_print_a_array
.d 1 1 i
	jsr	_print2
.o 0 0
	incI
	jmp	_print_a_record_lp

_print_a_array
.d 1 1 i
	jsr	_print__array
.o 0 0
	incI
	jmp	_print_a_record_lp

_print_ar_open_tuple_char
	pop_b 1
	incI
	print_sc "("
_print_ar_record_lp_no_space
	push_b	0
	push_r_arg_t
	eqC_b	')' 0
1586
	jmp_true	_print_ar_close_tuple_or_record_char
1587 1588 1589 1590
	eqI_b	0 0
	jmp_false	_print_a_record_lp__
	jmp	_end_print_a_record

1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624
_print_ar_open_record_char
	pop_b 1
	print_sc "("

	pushI 0
	push_b 1
count_ar_unboxed_records
	incI
	push_b 0
	push_r_arg_t
	eqC_b	'{' 0
	jmp_true count_ar_unboxed_record
	eqI_b	0 0
	updatepop_b 0 1
	jmp_false count_ar_unboxed_records

	incI
	push_r_arg_D

	pushI 2
	addI
	printD

	incI
	jmp	_print_a_record_lp

count_ar_unboxed_record
	pop_b 1
	push_b 1
	incI
	update_b 0 2
	pop_b 1
	jmp count_ar_unboxed_records

1625 1626 1627 1628 1629 1630
_print_ar_tuple_comma
	pop_b 1
	incI
	print_sc ","
	jmp	_print_ar_record_lp_no_space

1631
_print_ar_close_tuple_or_record_char
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763
	pop_b 1
	incI
	print_sc ")"
	jmp	_print_a_record_lp

_end_print_a_record
	pop_b	2

	push_b	1
	incI
	update_b	0 2
	pop_b 1
	decI
_print_record_array_lp2
	eqI_b	0 0
	jmp_false	_print_record_array_lp1
	pop_a	1
	pop_b	2
	print_sc	"}"
	jmp	_print_brackets

_print_char_array
	print_sc	"\""
.d 1 0
	jsr	print_string_
.o 0 0
	print_sc	"\""
	jmp	_print_brackets

_print_bool_array
	pop_b	1
	pushI	0
	push_a	0
	push_arraysize	BOOL 0 1
	jmp	_print_bool_array_lp2
.o 1 2 i i
_print_bool_array_lp1
	eqI_b	0 1
	jmp_true	_no_comma_1
	print_sc	","
_no_comma_1
	push_b	1
	push_a	0
	select	BOOL 0 1
.d 0 1 b	
	jsr	_print_bool
.o 0 0
	push_b	1
	incI
	update_b	0 2
	pop_b 1
	decI
_print_bool_array_lp2
	eqI_b	0 0
	jmp_false	_print_bool_array_lp1

	pop_a	1
	pop_b	2
	print_sc	"}"
	jmp	_print_brackets

_print_int_array
	pop_b	1
	pushI	0
	push_a	0
	push_arraysize	INT 0 1
	jmp	_print_int_array_lp2
.o 1 2 i i
_print_int_array_lp1
	eqI_b	0 1
	jmp_true	_no_comma_2
	print_sc	","
_no_comma_2
	push_b	1
	push_a	0
	select	INT 0 1
	print_int

	push_b	1
	incI
	update_b	0 2
	pop_b 1
	decI
_print_int_array_lp2
	eqI_b	0 0
	jmp_false	_print_int_array_lp1

	pop_a	1
	pop_b	2
	print_sc	"}"
	jmp	_print_brackets

_print_real_array
	pop_b	1
	push_a	0
	pushI	0
	push_arraysize	REAL 0 2
	jmp	_print_real_array_lp2
.o 1 2 i i
_print_real_array_lp1
	eqI_b	0 1
	jmp_true	_no_comma_3
	print_sc	","
_no_comma_3
	push_b	1
	push_a	0
	select	REAL 0 2

	create
	fillR_b	0 0
	pop_b	1
	print_symbol_sc	0
	pop_a	1

	push_b	1
	incI
	update_b	0 2
	pop_b 1
	decI
_print_real_array_lp2
	eqI_b	0 0
	jmp_false	_print_real_array_lp1
	pop_a	1
	pop_b	2
	print_sc	"}"
	jmp	_print_brackets
					
_print_nil
	print_sc	"[]"
	pop_a	1
	jmp	_print_brackets

1764 1765 1766 1767 1768
_print_unit
	print_sc	"()"
	pop_a	1
	jmp	_print_brackets

1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821
_print_tuple
	print_sc	"("
	get_node_arity	0
	push_b	0
	push_b	0
	repl_args_b
_print_rest_tuple
.d 1 0
	jsr	_print
.o 0 0
	decI
	eqI_b	0 0
	jmp_true	_exit_print_tuple
	print_sc	","
	jmp	_print_rest_tuple
_exit_print_tuple
	pop_b	1
	print_sc	")"
	jmp	_print_brackets

_print_record
	push_t_r_a 0

	push_b 0
	push_r_arg_t
	eqC_b	'l' 0
	updatepop_b 0 1
	jmp_true	_print_unboxed_list

	pop_b 1

	print_sc	"("
	print_symbol_sc	0

	push_t_r_args

	push_b	0
	push_r_arg_t
	eqC_b	'd' 0
	jmp_false	_print_record_lp_

	pop_b	1

_print_record_lp
	incI
	push_b	0
	push_r_arg_t
_print_record_lp_
	eqI_b	0 0
	jmp_true	_end_print_record
	eqC_b	',' 0
	jmp_true	_print_tuple_comma
	eqC_b	')' 0
1822 1823 1824
	jmp_true	_print_close_tuple_or_record_char
	eqC_b	'}' 0
	jmp_true	_print_close_tuple_or_record_char
1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840
	print_sc	" "
_print_record_lp__
	eqC_b	'i' 0
	jmp_true	_print_r_integer
	eqC_b	'c' 0
	jmp_true	_print_r_char
	eqC_b	'r' 0
	jmp_true	_print_r_real
	eqC_b	'b' 0
	jmp_true	_print_r_bool
	eqC_b	'f' 0
	jmp_true	_print_r_file
	eqC_b	'a' 0
	jmp_true	_print_r_graph
	eqC_b	'(' 0
	jmp_true	_print_open_tuple_char
1841 1842
	eqC_b	'{' 0
	jmp_true	_print_open_record_char
1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870
	halt

_print_r_integer
	pop_b	1
	push_b	1
	update_b	1 2
	update_b	0 1
	pop_b	1

	print_int

	jmp	_print_record_lp

_print_r_char
	pop_b	1
	push_b	1
	update_b	1 2
	update_b	0 1
	pop_b	1

	print_sc "'"
	print_char
	print_sc "'"

	jmp	_print_record_lp

_print_r_real
	pop_b	1
1871 1872 1873 1874
	push_b	1
	update_b	1 2
	update_b	0 1
	pop_b	1
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939

	print_real

	jmp	_print_record_lp

_print_r_bool
	pop_b	1
	push_b	1
	update_b	1 2
	update_b	0 1
	pop_b	1
.d 0 1 b
	jsr	_print_bool
.o 0 0
	jmp	_print_record_lp	

.o 0 1 b
_print_bool
	jmp_true	_print_r_true
	
	print	"False"
.d 0 0
	rtn
_print_r_true
	print	"True"
.d 0 0
	rtn

_print_r_file
	pop_b	1
	update_b	0 2
	pop_b	2

	print	"File"

	jmp	_print_record_lp

_print_r_graph
	pop_b	1

	jsr_eval 0
	eq_desc	_ARRAY_ 0 0
	jmp_true	_print_r_array

	push_b	0
	incI
	push_r_arg_t
	pushI	0
	eqI
	jmp_true	_print_last_record_arg

	pushI	0
.d 1 1 i
	jsr	_print2
.o 0 0
	jmp	_print_record_lp

_print_open_tuple_char
	pop_b 1
	print_sc "("
_print_record_lp_no_space
	incI
	push_b	0
	push_r_arg_t
	eqC_b	')' 0
1940
	jmp_true	_print_close_tuple_or_record_char
1941 1942 1943 1944
	eqI_b	0 0
	jmp_false	_print_record_lp__
	jmp	_end_print_record

1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977
_print_open_record_char
	pop_b 1
	print_sc "("

	pushI 0
	push_b 1
count_unboxed_records
	incI
	push_b 0
	push_r_arg_t
	eqC_b	'{' 0
	jmp_true count_unboxed_record
	eqI_b	0 0
	updatepop_b 0 1
	jmp_false count_unboxed_records

	incI
	push_r_arg_D

	pushI 2
	addI
	printD

	jmp	_print_record_lp

count_unboxed_record
	pop_b 1
	push_b 1
	incI
	update_b 0 2
	pop_b 1
	jmp count_unboxed_records

1978 1979 1980 1981 1982
_print_tuple_comma
	pop_b 1
	print_sc ","
	jmp	_print_record_lp_no_space

1983
_print_close_tuple_or_record_char
1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015
	pop_b 1
	print_sc ")"
	jmp	_print_record_lp

_print_last_record_arg
	pop_b	1
	incI
	jmp	_print2

_print_r_array
	pushI	0
.d 1 1 i
	jsr	_print__array
.o 0 0
	jmp	_print_record_lp

_end_print_record
	pop_b	2
	incI
	jmp	_print_brackets
	
.o 1 0
_eval_to_nf
.d 1 0
	jsr	_eval
.o 0 0
.d 0 0
	rtn

.o 1 0
_eval
	jsr_eval	0
2016
.o 1 0
2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
_eval2
	is_record	0
	jmp_true	_eval_record

	get_node_arity	0
	eqI_b	0 0		| check if arity is zero
	jmp_true	_eval_last

	eq_desc	_Cons 2 0
	jmp_true	_eval_list
	eq_desc	ARRAY 1 0
	jmp_true	_eval_array
	push_b	0
	push_b	0		| replace the node by
2031
	repl_args_b		| leave arity on b-stack
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041
_eval_args
	eqI_b	1 0		| check if last argument
	jmp_true	_eval_last_arg
.d 1 0
	jsr	_eval
.o 0 0
	decI			| decrease argument count
	jmp	_eval_args
_eval_last_arg
	pop_b	1		| remove argument count
2042
	jmp	_eval		| optimised tail recursion!
2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059
_eval_last
	pop_b	1		| remove arity
	eq_desc	_ARRAY_ 0 0
	jmp_true	_eval__array_
	pop_a	1		| remove node
.d 0 0
	rtn

_eval_list
	pop_b	1
_eval_rest_list
	repl_args	2 2
.d 1 0
	jsr	_eval
.o 0 0
	jsr_eval 0
	eq_desc	_Nil 0 0
2060
	jmp_false	_eval_rest_list
2061
	pop_a	1
2062 2063
.d 0 0
	rtn
2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096

_eval_unboxed_list
	pop_b 1
	jmp	_eval_unboxed_list_

_eval_unboxed_list_lp0
	push_t_r_args

	push_b	0
	push_r_arg_t
	eqC_b	'l' 0
	updatepop_b 0 1
	jmp_true	_eval_unboxed_list_
	halt

_eval_unboxed_list_
	push_b 0
	incI
	push_r_arg_t
	eqC_b	'R' 0
	updatepop_b 0 1
	jmp_false _eval_unboxed_list_lp1

_eval_ul_record
	incI

_eval_unboxed_list_lp1
	incI
	push_b	0
	push_r_arg_t
_eval_ul_next_field
_eval_unboxed_list_lp2
	eqC_b	'i' 0
2097
	jmp_true	_eval_ul_int_char_bool_or_real
2098
	eqC_b	'c' 0
2099
	jmp_true	_eval_ul_int_char_bool_or_real
2100
	eqC_b	'r' 0
2101
	jmp_true	_eval_ul_int_char_bool_or_real
2102
	eqC_b	'b' 0
2103
	jmp_true	_eval_ul_int_char_bool_or_real
2104
	eqC_b	'f' 0
2105
	jmp_true	_eval_ul_file
2106 2107
	eqC_b	'a' 0
	jmp_true	_eval_ul_graph
2108 2109
	pop_b 1
	jmp	_eval_rest_unboxed_list
2110

2111
_eval_ul_int_char_bool_or_real
2112 2113 2114 2115
	pop_b	1
	updatepop_b	0 1
	jmp	_eval_rest_unboxed_list

2116
_eval_ul_file
2117 2118 2119 2120 2121 2122 2123 2124
	pop_b	1
	updatepop_b	0 2
	jmp	_eval_rest_unboxed_list

_eval_ul_graph
	pop_b	1

	jsr_eval 0
2125
.d 1 0
2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151
	jsr	_eval2
.o 0 0
	jmp	_eval_rest_unboxed_list

_eval_rest_unboxed_list
	incI
	push_b 0
	push_r_arg_t
	eqC_b	'a' 0
	jmp_false _eval_ul_next_field

	push_b 1
	incI
	push_r_arg_t
	eqI_b	0 0
	updatepop_b 0 1
	jmp_false	_eval_ul_next_field

	pop_b 2

	jsr_eval 0
	eq_desc	_Nil 0 0
	jmp_false _eval_unboxed_list_lp0

_eval_last_unboxed_list
	pop_a	1
2152 2153
.d 0 0
	rtn
2154 2155

_eval__array_
2156
.d 1 0
2157 2158 2159 2160 2161 2162 2163
	jmp	_eval__array2

_eval_array
	pop_b	1
	pushA_a	0
	update_a	0 1
	pop_a	1
2164
.o 1 0
2165 2166 2167
_eval__array
	eq_desc	_STRING_ 0 0
	jmp_true	_eval_char_array
2168
.o 1 0
2169 2170 2171 2172 2173 2174 2175 2176
_eval__array2
	push_r_args_b	0 0 2 2 1

	push_b	0
	eq_desc_b	BOOL 0
	jmp_true	_eval_bool_array

	push_b	0
2177
	eq_desc_b	INT 0
2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217
	jmp_true	_eval_int_array

	push_b	0
	eq_desc_b	REAL 0
	jmp_true	_eval_real_array

	pushI	0

	push_a	0
	push_arraysize	_ 0 1

	push_b	2
	update_b	2 3
	update_b	1 2
	update_b	0 1
	pop_b	1

	pushI	0
	eqI
	jmp_false	_eval_record_array

	jmp	_eval_array_lp2
.o 1 2 i i
_eval_array_lp1
	push_b	1
	push_a	0
	select	_ 0 1
.d 1 0
	jsr	_eval
.o 0 0
	push_b	1
	incI
	update_b	0 2
	pop_b 1
	decI
_eval_array_lp2
	eqI_b	0 0
	jmp_false	_eval_array_lp1
	pop_a	1
	pop_b	2
2218 2219
.d 0 0
	rtn
2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245

_eval_record_array
	jmp	_eval_record_array_lp2
.o 1 2 i i
_eval_record_array_lp1
	push_b	1
	push_a	0
	push_a_r_args

_eval_a_record_lp
	push_b	0
	push_r_arg_t
	eqI_b	0 0
	jmp_true	_end_eval_a_record
	eqC_b	'i' 0
	jmp_true	_eval_ar_integer
	eqC_b	'c' 0
	jmp_true	_eval_ar_char
	eqC_b	'r' 0
	jmp_true	_eval_ar_real
	eqC_b	'b' 0
	jmp_true	_eval_ar_bool
	eqC_b	'f' 0
	jmp_true	_eval_ar_file
	eqC_b	'a' 0
	jmp_true	_eval_ar_graph
2246 2247 2248
	pop_b	1
	incI
	jmp	_eval_a_record_lp
2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274

_eval_ar_bool
_eval_ar_char
_eval_ar_integer
	pop_b	1
	update_b	0 1
	pop_b	1

	incI
	jmp	_eval_a_record_lp

_eval_ar_file
_eval_ar_real
	pop_b	1
	update_b	0 2
	pop_b	2

	incI
	jmp	_eval_a_record_lp

_eval_ar_graph
	pop_b	1

	jsr_eval	0
	eq_desc	_ARRAY_ 0 0
	jmp_true	_eval_a_array
2275
.d 1 0
2276 2277 2278 2279 2280 2281
	jsr	_eval2
.o 0 0
	incI
	jmp	_eval_a_record_lp

_eval_a_array
2282
.d 1 0
2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300
	jsr	_eval__array
.o 0 0
	incI
	jmp	_eval_a_record_lp

_end_eval_a_record
	pop_b	2

	push_b	1
	incI
	update_b	0 2
	pop_b 1
	decI
_eval_record_array_lp2
	eqI_b	0 0
	jmp_false	_eval_record_array_lp1
	pop_a	1
	pop_b	2
2301 2302
.d 0 0
	rtn
2303 2304 2305

_eval_char_array
	pop_a	1
2306 2307
.d 0 0
	rtn
2308 2309 2310 2311 2312 2313

_eval_real_array
_eval_bool_array
_eval_int_array
	pop_b	1
	pop_a	1
2314 2315
.d 0 0
	rtn
2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347
					
_eval_record
	push_t_r_args

	push_b	0
	push_r_arg_t
	eqC_b	'l' 0
	jmp_true	_eval_unboxed_list
	eqC_b	'd' 0
	jmp_false	_eval_record_lp_

	pop_b	1
	incI

_eval_record_lp
	push_b	0
	push_r_arg_t
_eval_record_lp_
	eqI_b	0 0
	jmp_true	_end_eval_record
	eqC_b	'r' 0
	jmp_true	_eval_r_real
	eqC_b	'i' 0
	jmp_true	_eval_r_integer
	eqC_b	'c' 0
	jmp_true	_eval_r_char
	eqC_b	'b' 0
	jmp_true	_eval_r_bool
	eqC_b	'f' 0
	jmp_true	_eval_r_file
	eqC_b	'a' 0
	jmp_true	_eval_r_graph
2348 2349 2350
	pop_b	1
	incI
	jmp	_eval_record_lp
2351 2352 2353 2354

_eval_r_char
_eval_r_bool
_eval_r_integer
2355
_eval_r_real
2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382
	pop_b	1
	update_b	0 1
	pop_b	1
	incI
	jmp	_eval_record_lp

_eval_r_file
	pop_b	1
	update_b	0 2
	pop_b	2
	incI
	jmp	_eval_record_lp

_eval_r_graph
	pop_b	1

	jsr_eval 0
	eq_desc	_ARRAY_ 0 0
	jmp_true	_eval_r_array

	push_b	0
	incI
	push_r_arg_t
	pushI	0
	eqI
	jmp_true	_eval_last_record_arg

2383
.d 1 0
2384 2385 2386 2387 2388 2389 2390 2391 2392 2393
	jsr	_eval2
.o 0 0
	incI
	jmp	_eval_record_lp

_eval_last_record_arg
	pop_b	1
	jmp	_eval2

_eval_r_array
2394
.d 1 0
2395 2396 2397 2398 2399 2400 2401
	jsr	_eval__array
.o 0 0
	incI
	jmp	_eval_record_lp

_end_eval_record
	pop_b	2
2402 2403
.d 0 0
	rtn
2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443

.export d_Sel n_Sel

.descn d_Sel n_Sel 1 0 "_Sel"
.pb "_Sel"
.n 1 d_Sel _
.o 1 0
n_Sel
	push_node _ 1
	jsr_eval 0
	pop_a 1
	jmp_eval
.pe

.export d_indirection n_indirection

.descn d_indirection n_indirection 1 0 "_indirection"
.pb "_indirection"
.n -2 d_indirection ea_indirection
.o 1 0
n_indirection
	push_node _cycle_in_spine 1
	jsr_eval 0
	fill_a 0 1
	pop_a 1
.d 1 0
	rtn

.o 2 0
ea_indirection
	push_node _cycle_in_spine 1
	jsr_eval 0
	fill_a 0 1
	fill_a 0 2
.keep 1 2
	pop_a 2
.d 1 0
	rtn
.pe