about summary refs log tree commit diff stats
path: root/apps/mu.subx
diff options
context:
space:
mode:
Diffstat (limited to 'apps/mu.subx')
-rw-r--r--apps/mu.subx197
1 files changed, 129 insertions, 68 deletions
diff --git a/apps/mu.subx b/apps/mu.subx
index 0138bc30..dc60e213 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -6696,13 +6696,16 @@ $parse-mu-block:line-loop:
       # line = read-line-buffered(in)
       (clear-stream %ecx)
       (read-line-buffered *(ebp+8) %ecx)
-#?       (write-buffered Stderr "line: ")
-#?       (write-stream-data Stderr %ecx)
-#?       (write-buffered Stderr Newline)
-#?       (flush Stderr)
+      (write-buffered Stderr "line: ")
+      (write-stream-data Stderr %ecx)
+#?       (write-buffered Stderr Newline)  # line has its own newline
+      (flush Stderr)
+      (rewind-stream %ecx)
       # if (line->write == 0) break
       81 7/subop/compare *ecx 0/imm32
       0f 84/jump-if-= break/disp32
+      (write-buffered Stderr "vars:\n")
+      (dump-vars *(ebp+0xc))
       # word-slice = next-mu-token(line)
       (next-mu-token %ecx %edx)
 #?       (write-buffered Stderr "word: ")
@@ -7723,6 +7726,52 @@ $lookup-var-helper:error2:
     (stop *(ebp+0x18) 1)
     # never gets here
 
+dump-vars:  # vars: (addr stack live-var)
+    # pseudocode:
+    #   var curr: (addr handle var) = &vars->data[vars->top - 12]
+    #   var min = vars->data
+    #   while curr >= min
+    #     var v: (handle var) = *curr
+    #     print v
+    #     curr -= 12
+    #
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    52/push-edx
+    53/push-ebx
+    56/push-esi
+    # esi = vars
+    8b/-> *(ebp+8) 6/r32/esi
+    # ebx = vars->top
+    8b/-> *esi 3/r32/ebx
+    # var min/edx: (addr handle var) = vars->data
+    8d/copy-address *(esi+8) 2/r32/edx
+    # var curr/ebx: (addr handle var) = &vars->data[vars->top - 12]
+    8d/copy-address *(esi+ebx-4) 3/r32/ebx  # vars + 8 + vars->type - 12
+    {
+$dump-vars:loop:
+      # if (curr < min) return
+      39/compare %ebx 2/r32/edx
+      0f 82/jump-if-addr< break/disp32
+      #
+      (write-buffered Stderr "  var@")
+      (dump-var 2 %ebx)
+      # curr -= 12
+      81 5/subop/subtract %ebx 0xc/imm32
+      e9/jump loop/disp32
+    }
+$dump-vars:end:
+    # . restore registers
+    5e/pop-to-esi
+    5b/pop-to-ebx
+    5a/pop-to-edx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
 == data
 # Like Registers, but no esp or ebp
 Mu-registers:  # (addr stream {(handle array byte), int})
@@ -9336,91 +9385,103 @@ $dump-typeinfo:loop:
       (write-buffered Stderr Newline)
       (flush Stderr)
       (write-buffered Stderr "        input var@")
-      (print-int32-buffered Stderr *eax)
+      (dump-var 5 %eax)
+      (lookup *(ecx+8) *(ecx+0xc))
+      (write-buffered Stderr "        index: ")
+      (print-int32-buffered Stderr *(eax+8))
+      (write-buffered Stderr Newline)
+      (flush Stderr)
+      (write-buffered Stderr "        output var@")
+      8d/copy-address *(eax+0xc) 0/r32/eax  # Typeinfo-entry-output-var
+      (dump-var 5 %eax)
+      (flush Stderr)
+      # curr += row-size
+      81 0/subop/add %ecx 0x10/imm32  # Typeinfo-fields-row-size
+      #
+      e9/jump loop/disp32
+    }
+$dump-typeinfo:end:
+    # . restore registers
+    5f/pop-to-edi
+    5e/pop-to-esi
+    5b/pop-to-ebx
+    5a/pop-to-edx
+    59/pop-to-ecx
+    58/pop-to-eax
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+dump-var:  # indent: int, v: (addr handle var)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
+    53/push-ebx
+    # eax = v
+    8b/-> *(ebp+0xc) 0/r32/eax
+    #
+    (print-int32-buffered Stderr *eax)
+    (write-buffered Stderr ",")
+    (print-int32-buffered Stderr *(eax+4))
+    (write-buffered Stderr "->")
+    (lookup *eax *(eax+4))
+    (print-int32-buffered Stderr %eax)
+    (write-buffered Stderr Newline)
+    (flush Stderr)
+    {
+      3d/compare-eax-and 0/imm32
+      0f 84/jump-if-= break/disp32
+      (emit-indent Stderr *(ebp+8))
+      (write-buffered Stderr "name: ")
+      89/<- %ebx 0/r32/eax
+      (print-int32-buffered Stderr *ebx)  # Var-name
       (write-buffered Stderr ",")
-      (print-int32-buffered Stderr *(eax+4))
+      (print-int32-buffered Stderr *(ebx+4))  # Var-name
       (write-buffered Stderr "->")
-      (lookup *eax *(eax+4))  # Typeinfo-entry-input-var
+      (lookup *ebx *(ebx+4))  # Var-name
       (print-int32-buffered Stderr %eax)
       {
         3d/compare-eax-and 0/imm32
         74/jump-if-= break/disp8
-        (write-buffered Stderr " ")
-        # TODO
+        (write-buffered Stderr Space)
+        (write-buffered Stderr %eax)
       }
       (write-buffered Stderr Newline)
       (flush Stderr)
-      (lookup *(ecx+8) *(ecx+0xc))
-      (write-buffered Stderr "        index: ")
-      (print-int32-buffered Stderr *(eax+8))
+      (emit-indent Stderr *(ebp+8))
+      (write-buffered Stderr "block depth: ")
+      (print-int32-buffered Stderr *(ebx+0x10))  # Var-block-depth
       (write-buffered Stderr Newline)
       (flush Stderr)
-      (write-buffered Stderr "        output var@")
-      (print-int32-buffered Stderr *(eax+0xc))
+      (emit-indent Stderr *(ebp+8))
+      (write-buffered Stderr "stack offset: ")
+      (print-int32-buffered Stderr *(ebx+0x14))  # Var-offset
+      (write-buffered Stderr Newline)
+      (flush Stderr)
+      (emit-indent Stderr *(ebp+8))
+      (write-buffered Stderr "reg: ")
+      (print-int32-buffered Stderr *(ebx+0x18))  # Var-register
       (write-buffered Stderr ",")
-      (print-int32-buffered Stderr *(eax+0x10))
+      (print-int32-buffered Stderr *(ebx+0x1c))  # Var-register
       (write-buffered Stderr "->")
-      (lookup *(eax+0xc) *(eax+0x10))  # Typeinfo-entry-output-var
-      (print-int32-buffered Stderr %eax)
-      (write-buffered Stderr Newline)
       (flush Stderr)
+      (lookup *(ebx+0x18) *(ebx+0x1c))  # Var-register
+      (print-int32-buffered Stderr %eax)
       {
         3d/compare-eax-and 0/imm32
-        0f 84/jump-if-= break/disp32
-        (write-buffered Stderr "          name: ")
-        89/<- %ebx 0/r32/eax
-        (print-int32-buffered Stderr *ebx)  # Var-name
-        (write-buffered Stderr ",")
-        (print-int32-buffered Stderr *(ebx+4))  # Var-name
-        (write-buffered Stderr "->")
-        (lookup *ebx *(ebx+4))  # Var-name
-        (print-int32-buffered Stderr %eax)
-        {
-          3d/compare-eax-and 0/imm32
-          74/jump-if-= break/disp8
-          (write-buffered Stderr Space)
-          (write-buffered Stderr %eax)
-        }
-        (write-buffered Stderr Newline)
-        (flush Stderr)
-        (write-buffered Stderr "          block depth: ")
-        (print-int32-buffered Stderr *(ebx+0x10))  # Var-block-depth
-        (write-buffered Stderr Newline)
-        (flush Stderr)
-        (write-buffered Stderr "          stack offset: ")
-        (print-int32-buffered Stderr *(ebx+0x14))  # Var-offset
-        (write-buffered Stderr Newline)
-        (flush Stderr)
-        (write-buffered Stderr "          reg: ")
-        (print-int32-buffered Stderr *(ebx+0x18))  # Var-register
-        (write-buffered Stderr ",")
-        (print-int32-buffered Stderr *(ebx+0x1c))  # Var-register
-        (write-buffered Stderr "->")
-        (flush Stderr)
-        (lookup *(ebx+0x18) *(ebx+0x1c))  # Var-register
-        (print-int32-buffered Stderr %eax)
-        {
-          3d/compare-eax-and 0/imm32
-          74/jump-if-= break/disp8
-          (write-buffered Stderr Space)
-          (write-buffered Stderr %eax)
-        }
-        (write-buffered Stderr Newline)
-        (flush Stderr)
+        74/jump-if-= break/disp8
+        (write-buffered Stderr Space)
+        (write-buffered Stderr %eax)
       }
+      (write-buffered Stderr Newline)
       (flush Stderr)
-      # curr += row-size
-      81 0/subop/add %ecx 0x10/imm32  # Typeinfo-fields-row-size
-      #
-      e9/jump loop/disp32
     }
-$dump-typeinfo:end:
+$dump-var:end:
     # . restore registers
-    5f/pop-to-edi
-    5e/pop-to-esi
     5b/pop-to-ebx
-    5a/pop-to-edx
-    59/pop-to-ecx
     58/pop-to-eax
     # . epilogue
     89/<- %esp 5/r32/ebp
92' href='#n492'>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