Changeset 846
- Timestamp:
- 01/06/19 02:44:47 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/vm/framscript.y
r836 r846 479 479 } 480 480 } 481 $$.stack=trstack.currentPos(); 481 482 } 482 483 expr_or_objname ')' … … 506 507 trctx.out->printf(":_loop_end_%d\n",$1.counter); 507 508 trstack.loops.drop(); 508 if ($1.stack != trstack.currentPos()) 509 trctx.out->printf("add %d,m0\n",$1.stack-trstack.currentPos()); 510 trstack.adjust($1.stack-trstack.currentPos()); 509 if ($4.constant) 510 trstack.adjust($3.stack-trstack.currentPos()); 511 int adj=$1.stack-trstack.currentPos(); 512 trstack.adjust(adj); 513 if (adj!=0) 514 trctx.out->printf("add %d,m0\n",adj); 511 515 } 512 516 … … 769 773 // pop; goto and_b 770 774 // else 771 // pop; push 0;goto and_end775 // goto and_end 772 776 // and_b: 773 777 // push b … … 776 780 // trctx.out->printf("\n####### logic AND\n"); 777 781 int c=trctx.labelcounter++; 778 $$. setInt(c);782 $$.counter=c; 779 783 if ($1.constant) 780 784 { … … 783 787 { 784 788 $1.counter=0; 785 // no stack adjust - next tokens are processed in a different context 786 trctx.out->printf("push 0\njump :_and_end_%d\n",c); 789 trctx.out->printf("jump :_and_end_%d\n",c); 787 790 } 788 791 else … … 791 794 else 792 795 { 793 trstack.adjust(+1); // stack as if (a==true), b expr is processed 794 trctx.out->printf("if !~,m[m0++],:_and_b_%d\n" 795 "push 0\n" 796 trctx.out->printf("if !~,m[m0],:_and_b_%d\n" // skip to b if a!~=false, "a" stays on top 796 797 "jump :_and_end_%d\n" 797 798 ":_and_b_%d\n" … … 801 802 expr 802 803 { 803 $$.ident=false; 804 $$.constant=0; 805 if ($4.constant) 804 if ($1.constant) 806 805 { 807 if ( !($1.constant && $1.counter==0))806 if ($1.counter==0) 808 807 { 809 ExtValue::CompareResult cond=$4.compare(ExtValue::zero()); 810 bool value=!resultIsRelaxedEqual(cond); 811 trstack.adjust(-1); 812 trctx.out->printf("push %d\n",value); 808 $$=$1; 809 if (!$4.constant) 810 trstack.adjust(+1); 811 } 812 else 813 $$=$4; 814 } 815 else 816 { 817 $$.ident=false; 818 $$.constant=0; 819 if ($4.constant) 820 { 821 trctx.out->printf("inc m0\n" 822 "push %s\n",litstr($4)); 823 } 824 else 825 { 826 trstack.adjust(+1); 827 trctx.out->printf("move m[m0],m[m0+1]\n" 828 "inc m0\n"); //drop "a" 813 829 } 814 830 } 815 trctx.out->printf(":_and_end_%d\n",$3. getInt());831 trctx.out->printf(":_and_end_%d\n",$3.counter); 816 832 // trctx.out->printf("#################\n\n"); 817 833 } … … 822 838 // push a 823 839 // if (!a) 824 // pop; goto and_b840 // pop; goto or_b 825 841 // else 826 // pop; push 1; goto and_end827 // and_b:842 // goto or_end 843 // or_b: 828 844 // push b 829 // and_end:845 // or_end: 830 846 trctx.emitLine(); 831 // trctx.out->printf("\n####### logic AND\n");847 // trctx.out->printf("\n####### logic OR\n"); 832 848 int c=trctx.labelcounter++; 833 $$. setInt(c);849 $$.counter=c; 834 850 if ($1.constant) 835 851 { … … 838 854 { 839 855 $1.counter=1; 840 // no stack adjust - next tokens are processed in a different context 841 trctx.out->printf("push 1\njump :_or_end_%d\n",c); 856 trctx.out->printf("jump :_or_end_%d\n",c); 842 857 } 843 858 else … … 846 861 else 847 862 { 848 trstack.adjust(+1); // stack for (a==false) 849 trctx.out->printf("if ~=,m[m0++],:_or_b_%d\n" 850 "push 1\n" 863 trctx.out->printf("if ~=,m[m0],:_or_b_%d\n" // skip to b if a~=false, "a" stays on top 851 864 "jump :_or_end_%d\n" 852 865 ":_or_b_%d\n" … … 856 869 expr 857 870 { 858 $$.ident=false; 859 $$.constant=0; 860 if ($4.constant) 871 if ($1.constant) 861 872 { 862 if ( !($1.constant && $1.counter==1))873 if ($1.counter==1) 863 874 { 864 ExtValue::CompareResult cond=$4.compare(ExtValue::zero()); 865 bool value=!resultIsRelaxedEqual(cond); 866 trstack.adjust(-1); 867 trctx.out->printf("push %d\n",value); 875 $$=$1; 876 if (!$4.constant) 877 trstack.adjust(+1); 878 } 879 else 880 $$=$4; 881 } 882 else 883 { 884 $$.ident=false; 885 $$.constant=0; 886 if ($4.constant) 887 { 888 trctx.out->printf("inc m0\n" 889 "push %s\n",litstr($4)); 890 } 891 else 892 { 893 trstack.adjust(+1); 894 trctx.out->printf("move m[m0],m[m0+1]\n" 895 "inc m0\n"); //drop "a" 868 896 } 869 897 } 870 trctx.out->printf(":_or_end_%d\n",$3. getInt());898 trctx.out->printf(":_or_end_%d\n",$3.counter); 871 899 // trctx.out->printf("#################\n\n"); 872 900 }
Note: See TracChangeset
for help on using the changeset viewer.