Changeset 332
- Timestamp:
- 02/28/15 03:42:40 (10 years ago)
- Location:
- cpp/frams/vm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/vm/framscript.l
r224 r332 33 33 \"\"\" {trctx.tmp=""; trctx.multilimit='\"'; BEGIN multiline;} 34 34 "'''" {trctx.tmp=""; trctx.multilimit='\''; BEGIN multiline;} 35 "@line "[0-9]+\n {trctx.line=atol(yytext+6); }36 "@file "[^\n\t\r]+\n {trctx.srcname=SString(yytext+6,yyleng-7); }35 "@line "[0-9]+\n {trctx.line=atol(yytext+6);trctx.linechanged=true;} 36 "@file "[^\n\t\r]+\n {trctx.srcname=SString(yytext+6,yyleng-7);trctx.namechanged=true;} 37 37 38 38 [a-zA-Z_][a-zA-Z0-9_]* { int t=lookupToken(yytext); … … 65 65 ">>" return RSHIFT; 66 66 67 <INITIAL,asmcode,asmcode2>\/\/.*\n {trctx.line++; } // komentarz jednoliniowy67 <INITIAL,asmcode,asmcode2>\/\/.*\n {trctx.line++;trctx.linechanged=true;} // komentarz jednoliniowy 68 68 <INITIAL,asmcode,asmcode2>\/\/[^\n]* ; // komentarz ale nie ma potem \n 69 69 70 70 <INITIAL>\/\* BEGIN comment; 71 <comment>\n {trctx.line++; }71 <comment>\n {trctx.line++;trctx.linechanged=true;} 72 72 <comment>\*\/ BEGIN 0; 73 73 <comment>. ; … … 85 85 trctx.tmp+=SString(yytext,yyleng); 86 86 } 87 <multiline>\n {trctx.line++; trctx. tmp+="\n";}87 <multiline>\n {trctx.line++; trctx.linechanged=true; trctx.tmp+="\n";} 88 88 [ \t\r\f] ; 89 \n {trctx.line++; }89 \n {trctx.line++; trctx.linechanged=true;} 90 90 . return yytext[0]; 91 91 … … 94 94 char *t=yytext; 95 95 while(t=strchr(t+1,'\n')) trctx.line++; 96 trctx.linechanged=true; 96 97 return ASM; 97 98 } 98 99 <asmcode>.*\n { 99 100 char *t=yytext; 100 trctx.line++; 101 trctx.line++; trctx.linechanged=true; 101 102 while ((*t==' ')||(*t=='\t')) t++; 102 103 if (*t=='}') {yyless((t-yytext)+1); BEGIN 0; return '}';} -
cpp/frams/vm/framscript.y
r286 r332 15 15 static void yyprint (FILE *file,int type,YYSTYPE value); 16 16 void handleTwoArg(YYSTYPE& result,const YYSTYPE& arg1,const YYSTYPE& arg2, 17 int optoken,const char* opname, bool logic, boolnegarg2, bool uniq);18 voidhandleCompare(YYSTYPE& result,const YYSTYPE& arg1,const YYSTYPE& arg2,19 int optoken,const char* opname);17 int optoken,const char* opname, bool negarg2, bool uniq); 18 bool handleCompare(YYSTYPE& result,const YYSTYPE& arg1,const YYSTYPE& arg2, 19 ExtValue::CmpOperator,const char* opname); 20 20 bool handleAssignOp(YYSTYPE& result,const YYSTYPE& var,const YYSTYPE& arg,const char* opname); 21 21 bool handleAssignOp2(YYSTYPE& result,const char *var,const YYSTYPE& arg,const char* opname,int stackpos,bool push); … … 46 46 %left NEG /* negation--unary minus */ 47 47 %left TYPEOF 48 %left INT 49 %left FLOAT 50 %left STRING 48 51 49 52 %token IDENT … … 65 68 66 69 %token TYPEOF "typeof" 70 %token INT "int" 71 %token FLOAT "float" 72 %token STRING "string" 67 73 68 74 %token ASM … … 111 117 | GLOBAL globaldeflist ';' 112 118 | IDENT ':' {trctx.out->printf(":%s\n",str($1));} 113 | expr ';' {if (!$1.constant) { trctx.out->printf("inc m0\n"); trstack.adjust(+1); } }119 | expr ';' {if (!$1.constant) { trctx.out->printf("inc m0\n"); trstack.adjust(+1); } trctx.emitLine(); } 114 120 | functiondef 115 121 | blok … … 138 144 { 139 145 #ifdef FRAMSCRIPT_GOTO 140 trctx.out->printf("jump :%s\n",str($2)); FMprintf("FramScriptCompiler","translate",FMLV_WARN,"goto is not recommended (%s line %d)",(const char*)trctx.srcname,trctx.line); 146 trctx.out->printf("jump :%s\n",str($2)); FMprintf("FramScriptCompiler","translate",FMLV_WARN,"goto is not recommended (%s line %d)",(const char*)trctx.srcname,trctx.line); trctx.emitLine(); 141 147 #else 142 148 trctx.err->printf("goto is not supported\n");return 1; … … 183 189 else 184 190 offset=trctx.functionstackpos-trstack.currentPos(); 191 trctx.emitLine(); 185 192 if (!offset) 186 193 trctx.out->printf("move invalid,s0\nreturn\n"); … … 194 201 ; 195 202 196 vardef: IDENT { trstack.addVariable($1.getString()); trctx.out->printf("push invalid\n");}197 | IDENT '=' stackexpr { trstack.adjust(1); trstack.addVariable($1.getString());}203 vardef: IDENT { trctx.emitLine(); trstack.addVariable($1.getString()); trctx.out->printf("push invalid\n");} 204 | IDENT '=' stackexpr { trctx.emitLine(); trstack.adjust(1); trstack.addVariable($1.getString());} 198 205 ; 199 206 … … 220 227 functiondef: FUNCTION funnamelist 221 228 { 229 trctx.emitLine(); 222 230 int pos=trstack.currentPos(); 223 231 $$.setInt(pos); … … 236 244 trctx.out->printf(":_skipfun_%d\n",trctx.functiontmplabel); 237 245 trctx.functiontmplabel=-1; 246 trctx.emitLine(); 238 247 }; 239 248 … … 241 250 | BREAK expr ';' 242 251 { 252 trctx.emitLine(); 243 253 if (!$2.constant) 244 254 {trctx.err->printf("break level must be a constant expression\n");return 1;} … … 247 257 {trctx.err->printf("break level must be a positive integer\n");return 1;} 248 258 if (!doBreak(level)) return 1; 259 trctx.emitLine(); 249 260 }; 250 261 … … 258 269 {trctx.err->printf("continue level must be a positive integer\n");return 1;} 259 270 if (!doContinue(level)) return 1; 271 trctx.emitLine(); 260 272 }; 261 273 262 274 while_statement: WHILE '(' 263 { int c=trctx.labelcounter++; $$.setInt(c); 275 { 276 int c=trctx.labelcounter++; $$.setInt(c); 264 277 $$.stack=trstack.currentPos(); 265 278 trstack.loops.addLoop(c,$$.stack); … … 273 286 else 274 287 { 275 trctx.out->printf("if m[m0++],==,0,:_loop_end_%d\n",c,c);288 trctx.out->printf("if ~=,m[m0++],:_loop_end_%d\n",c,c); 276 289 trstack.adjust(+1); 277 290 } 278 291 } 279 292 pseudoblok_statement 280 {trctx.out->printf("jump :_loop_%d\n:_loop_end_%d\n",$3.getInt(),$3.getInt()); 293 { 294 trctx.out->printf("jump :_loop_%d\n:_loop_end_%d\n",$3.getInt(),$3.getInt()); 281 295 trstack.adjust($3.stack-trstack.currentPos()); 282 296 trstack.loops.drop(); … … 285 299 286 300 dowhile_statement: DO 287 { int c=trctx.labelcounter++; $$.setInt(c); 301 { 302 trctx.emitLine(); 303 int c=trctx.labelcounter++; $$.setInt(c); 288 304 $$.stack=trstack.currentPos(); 289 305 trstack.loops.addLoop(c,$$.stack); … … 299 315 else 300 316 { 301 trctx.out->printf("if ! =,m[m0++],:_loop_%d\n",c);317 trctx.out->printf("if !~,m[m0++],:_loop_%d\n",c); 302 318 trstack.adjust(+1); 303 319 } … … 305 321 trstack.adjust($2.stack-trstack.currentPos()); 306 322 trstack.loops.drop(); 323 trctx.emitLine(); 307 324 } 308 325 ; 309 326 310 327 switch_statement: SWITCH '(' 311 {int c=trctx.labelcounter++; $1.setInt(c); 328 { 329 int c=trctx.labelcounter++; $1.setInt(c); 312 330 trstack.loops.addLoop(c,trstack.currentPos());} 313 331 stackexpr ')' 314 {trctx. out->printf("dec m0\n");trstack.adjust(-1);}332 {trctx.emitLine(); trctx.out->printf("dec m0\n"); trstack.adjust(-1);} 315 333 '{' inside_switch '}' 316 {int c=$1.getInt(); trctx.out->printf("add 2,m0\n:_loop_end_%d\n",c); trstack.adjust(+2); 317 trstack.loops.drop();} 334 { 335 trctx.emitLine(); 336 LoopInfo *li=trstack.loops.getLoop(0); 337 trctx.out->printf(":_case_after_%d_%d\n" 338 "add 2,m0\n" 339 ":_loop_end_%d\n", 340 li->id,li->casecounter, 341 li->id); 342 trstack.adjust(+2); 343 trstack.loops.drop(); 344 } 318 345 ; 319 346 … … 324 351 325 352 case_label: CASE expr ':' 326 {if (!$2.constant) {trctx.err->printf("case label must be a constant expression\n");return 1;} 327 int c=trctx.labelcounter++; $1.setInt(c); 328 trctx.out->printf("if s1,!=,%s,:_skip_%d\n",litstr($2),c); 353 { 354 LoopInfo *li=trstack.loops.getLoop(0); 355 if ($2.constant) 356 trctx.out->printf("if s1,!=,%s,:_case_before_%d_%d\n", 357 litstr($2), 358 li->id,li->casecounter+1); 359 else 360 { 361 trctx.out->printf("if s2,!=,m[m0++],:_case_before_%d_%d\n", 362 li->id,li->casecounter+1); 363 trstack.adjust(+1); 364 } 365 trctx.out->printf(":_case_after_%d_%d\n", 366 li->id,li->casecounter); 329 367 int pos=trstack.currentPos(); $$.setInt(pos); 330 368 } 331 369 recurcode 332 370 { 371 trctx.emitLine(); 372 LoopInfo *li=trstack.loops.getLoop(0); 333 373 int pos=$4.getInt(); 334 374 if (pos!=trstack.currentPos()) trctx.out->printf("add %d,m0\n",pos-trstack.currentPos()); 335 375 trstack.dropToPos(pos); 336 trctx.out->printf(":_skip_%d\n",$1.getInt()); 337 } 338 | DEFAULT ':' recurcode 376 li->casecounter++; 377 trctx.out->printf("jump :_case_after_%d_%d\n" 378 ":_case_before_%d_%d\n", 379 li->id,li->casecounter, 380 li->id,li->casecounter); 381 } 382 | DEFAULT ':' 383 { 384 LoopInfo *li=trstack.loops.getLoop(0); 385 trctx.out->printf(":_case_after_%d_%d\n",li->id,li->casecounter); 386 } 387 recurcode 388 { 389 LoopInfo *li=trstack.loops.getLoop(0); 390 li->casecounter++; 391 } 339 392 ; 340 393 … … 409 462 expr_or_objname ')' 410 463 {//6 464 trctx.emitLine(); 411 465 if ($4.constant) 412 466 {trctx.err->printf("%s can't be iterated\n",str($4)); return 1;} … … 439 493 for_statement_begin ';' 440 494 { //3 495 trctx.emitLine(); 441 496 //trctx.out->printf("# for_statement_begin pos=%d ident=%d var=%d\n",trstack.currentPos(),$1.ident,$1.var); 442 497 if ((!$1.var) && ($1.ident)) … … 460 515 expr_or_empty ';' 461 516 { //6 517 trctx.emitLine(); 462 518 int c=$1.counter; 463 519 warnTruthValue($4); … … 475 531 expr_or_empty ')' 476 532 { //9 533 trctx.emitLine(); 477 534 if (!$7.constant) { trctx.out->printf("inc m0\n"); trstack.adjust(+1); } 478 535 trctx.restoreOut(); … … 498 555 499 556 pseudoblok_statement: 500 {int pos=trstack.currentPos(); $$.setInt(pos); 501 } 557 {trctx.emitLine(); int pos=trstack.currentPos(); $$.setInt(pos);} 502 558 statement 503 559 { … … 505 561 if (pos!=trstack.currentPos()) trctx.out->printf("add %d,m0\n",pos-trstack.currentPos()); 506 562 trstack.dropToPos(pos); 563 trctx.emitLine(); 507 564 }; 508 565 … … 535 592 536 593 if_condition: IF 537 {$$.stack=trstack.currentPos(); }594 {$$.stack=trstack.currentPos();trctx.emitLine();} 538 595 539 596 '(' expr ')' 540 597 { 598 trctx.emitLine(); 541 599 int c=trctx.labelcounter++; 542 600 $$.setInt(c); … … 548 606 else 549 607 { 550 trctx.out->printf("if m[m0++],==,0,:_if_else_%d\n",c);608 trctx.out->printf("if ~=,m[m0++],:_if_else_%d\n",c); 551 609 trstack.adjust(+1); 552 610 } … … 585 643 else 586 644 {$$=$1; $$.ident=false;} 645 trctx.emitLine(); 587 646 } 588 647 ; … … 606 665 | plusminus IDENT 607 666 { 667 trctx.emitLine(); 608 668 $$.ident=0; 609 669 int loc; if (variableOk($$,$2,loc)) … … 619 679 | IDENT plusminus 620 680 { 681 trctx.emitLine(); 621 682 $$.ident=0; 622 683 int loc; if (variableOk($$,$1,loc)) … … 630 691 } 631 692 632 | IDENT assign_op expr { $$.ident=0;693 | IDENT assign_op expr { trctx.emitLine(); $$.ident=0; 633 694 if (!handleAssignOp($$,$1,$3,assign_op_names[$2.getInt()])) 634 695 if (globalOk($1)) {SString t="@"; t+=$1.getString(); … … 637 698 } 638 699 639 | TYPEOF expr {$$.ident=0;640 if ($ 2.constant)641 {$$.constant=1; $$=$ 2.getExtType();}700 | TYPEOF '(' expr ')' { trctx.emitLine(); $$.ident=0; 701 if ($3.constant) 702 {$$.constant=1; $$=$3.getExtType();} 642 703 else 643 704 {trctx.out->printf("type s0,s0\n");} 644 705 } 645 646 | expr '+' expr { handleTwoArg($$,$1,$3,'+',"add",0,0,1); } 647 | expr '-' expr { handleTwoArg($$,$1,$3,'-',"sub",0,0,0); } 648 | expr '*' expr { handleTwoArg($$,$1,$3,'*',"mul",0,0,1); } 649 | expr '/' expr { handleTwoArg($$,$1,$3,'/',"div",0,0,0); } 650 | expr '&' expr { handleTwoArg($$,$1,$3,'&',"and",0,0,0); } 651 | expr '|' expr { handleTwoArg($$,$1,$3,'|',"or",0,0,0); } 652 | expr '%' expr { handleTwoArg($$,$1,$3,'%',"mod",0,0,0); } 653 | expr LOGIC_AND expr { handleTwoArg($$,$1,$3,LOGIC_AND,"and",1,0,0); } 654 | expr LOGIC_OR expr { handleTwoArg($$,$1,$3,LOGIC_OR,"or",1,0,0); } 655 | expr LSHIFT expr { handleTwoArg($$,$1,$3,LSHIFT,"shift",0,0,0); } 656 | expr RSHIFT expr { handleTwoArg($$,$1,$3,RSHIFT,"shift",0,1,0); } 657 | expr EQUAL expr { handleCompare($$,$1,$3,EQUAL,"=="); } 658 | expr NOT_EQUAL expr { handleCompare($$,$1,$3,NOT_EQUAL,"!="); } 659 | expr GEQUAL expr { handleCompare($$,$1,$3,GEQUAL,">="); } 660 | expr LEQUAL expr { handleCompare($$,$1,$3,LEQUAL,"<="); } 661 | expr '>' expr { handleCompare($$,$1,$3,'>',">"); } 662 | expr '<' expr { handleCompare($$,$1,$3,'<',"<"); } 706 | INT '(' expr ')' { trctx.emitLine(); $$.ident=0; 707 if ($3.constant) 708 {$$.constant=1; $$=ExtValue($3.getInt());} 709 else 710 {trctx.out->printf("conv 1,s0\n");} 711 } 712 | FLOAT '(' expr ')' { trctx.emitLine(); $$.ident=0; 713 if ($3.constant) 714 {$$.constant=1; $$=ExtValue($3.getDouble());} 715 else 716 {trctx.out->printf("conv 2,s0\n");} 717 } 718 | STRING '(' expr ')' { trctx.emitLine(); $$.ident=0; 719 if ($3.constant) 720 {$$.constant=1; $$=ExtValue($3.getString());} 721 else 722 {trctx.out->printf("conv 3,s0\n");} 723 } 724 725 | expr '+' expr { handleTwoArg($$,$1,$3,'+',"add",0,1); } 726 | expr '-' expr { handleTwoArg($$,$1,$3,'-',"sub",0,0); } 727 | expr '*' expr { handleTwoArg($$,$1,$3,'*',"mul",0,1); } 728 | expr '/' expr { handleTwoArg($$,$1,$3,'/',"div",0,0); } 729 | expr '&' expr { handleTwoArg($$,$1,$3,'&',"and",0,0); } 730 | expr '|' expr { handleTwoArg($$,$1,$3,'|',"or",0,0); } 731 | expr '%' expr { handleTwoArg($$,$1,$3,'%',"mod",0,0); } 732 733 | expr LOGIC_AND 734 { 735 // a && b: 736 // push a 737 // if (a) 738 // pop; goto and_b 739 // else 740 // pop; push 0; goto and_end 741 // and_b: 742 // push b 743 // and_end: 744 trctx.emitLine(); 745 // trctx.out->printf("\n####### logic AND\n"); 746 int c=trctx.labelcounter++; 747 $$.setInt(c); 748 if ($1.constant) 749 { 750 int cond=$1.compare(ExtValue::zero()); 751 if ((cond==0)||(cond==2)) 752 { 753 $1.counter=0; 754 // no stack adjust - next tokens are processed in a different context 755 trctx.out->printf("push 0\njump :_and_end_%d\n",c); 756 } 757 else 758 $1.counter=1; 759 } 760 else 761 { 762 trstack.adjust(+1); // stack as if (a==true), b expr is processed 763 trctx.out->printf("if !~,m[m0++],:_and_b_%d\n" 764 "push 0\n" 765 "jump :_and_end_%d\n" 766 ":_and_b_%d\n" 767 ,c,c,c); 768 } 769 } 770 expr 771 { 772 $$.ident=false; 773 $$.constant=0; 774 if ($4.constant) 775 { 776 if (!($1.constant && $1.counter==0)) 777 { 778 int cond=$4.compare(ExtValue::zero()); 779 bool value=!((cond==0)||(cond==2)); 780 trstack.adjust(-1); 781 trctx.out->printf("push %d\n",value); 782 } 783 } 784 trctx.out->printf(":_and_end_%d\n",$3.getInt()); 785 // trctx.out->printf("#################\n\n"); 786 } 787 788 | expr LOGIC_OR 789 { 790 // a || b: 791 // push a 792 // if (!a) 793 // pop; goto and_b 794 // else 795 // pop; push 1; goto and_end 796 // and_b: 797 // push b 798 // and_end: 799 trctx.emitLine(); 800 // trctx.out->printf("\n####### logic AND\n"); 801 int c=trctx.labelcounter++; 802 $$.setInt(c); 803 if ($1.constant) 804 { 805 int cond=$1.compare(ExtValue::zero()); 806 if (!((cond==0)||(cond==2))) 807 { 808 $1.counter=1; 809 // no stack adjust - next tokens are processed in a different context 810 trctx.out->printf("push 1\njump :_or_end_%d\n",c); 811 } 812 else 813 $1.counter=0; 814 } 815 else 816 { 817 trstack.adjust(+1); // stack for (a==false) 818 trctx.out->printf("if ~=,m[m0++],:_or_b_%d\n" 819 "push 1\n" 820 "jump :_or_end_%d\n" 821 ":_or_b_%d\n" 822 ,c,c,c); 823 } 824 } 825 expr 826 { 827 $$.ident=false; 828 $$.constant=0; 829 if ($4.constant) 830 { 831 if (!($1.constant && $1.counter==1)) 832 { 833 int cond=$4.compare(ExtValue::zero()); 834 bool value=!((cond==0)||(cond==2)); 835 trstack.adjust(-1); 836 trctx.out->printf("push %d\n",value); 837 } 838 } 839 trctx.out->printf(":_or_end_%d\n",$3.getInt()); 840 // trctx.out->printf("#################\n\n"); 841 } 842 843 844 | expr LSHIFT expr { handleTwoArg($$,$1,$3,LSHIFT,"shift",0,0); } 845 | expr RSHIFT expr { handleTwoArg($$,$1,$3,RSHIFT,"shift",1,0); } 846 | expr EQUAL expr { if (!handleCompare($$,$1,$3,ExtValue::CmpEQ,"==")) return 1; } 847 | expr NOT_EQUAL expr { if (!handleCompare($$,$1,$3,ExtValue::CmpNE,"!=")) return 1; } 848 | expr GEQUAL expr { if (!handleCompare($$,$1,$3,ExtValue::CmpGE,">=")) return 1; } 849 | expr LEQUAL expr { if (!handleCompare($$,$1,$3,ExtValue::CmpLE,"<=")) return 1; } 850 | expr '>' expr { if (!handleCompare($$,$1,$3,ExtValue::CmpGT,">")) return 1; } 851 | expr '<' expr { if (!handleCompare($$,$1,$3,ExtValue::CmpLT,"<")) return 1; } 663 852 664 853 | '!' expr { 665 $$.assign=$2.assign; $$.parens=0; $$.ident=0;854 trctx.emitLine(); $$.assign=$2.assign; $$.parens=0; $$.ident=0; 666 855 if ($2.constant) 667 {$$.constant=1; $$.setInt(!$2.getInt());}856 {$$.constant=1; int res=$2.compare(ExtValue((paInt)0)); $$.setInt((res==0)||(res==2));} 668 857 else 669 {trctx.out->printf("setif ==,s0,s0\n");}858 {trctx.out->printf("setif ~=,s0,s0\n");} 670 859 } 671 860 672 861 | '-' expr %prec NEG { 673 $$.assign=$2.assign; $$.parens=0; $$.ident=0;862 trctx.emitLine(); $$.assign=$2.assign; $$.parens=0; $$.ident=0; 674 863 if ($2.constant) 675 864 { $$.constant=$2.constant; … … 685 874 } 686 875 687 | '(' expr ')' { $$ = $2; $$.assign=$2.assign?(!$2.parens):0; $$.parens=1; $$.ident=0; }876 | '(' expr ')' { trctx.emitLine(); $$ = $2; $$.assign=$2.assign?(!$2.parens):0; $$.parens=1; $$.ident=0; } 688 877 689 878 | OBJNAME '.' member { 690 $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t);879 trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t); 691 880 if ($3.constant) 692 881 { … … 700 889 701 890 | OBJNAME '.' member assign_op expr 702 { $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t);891 { trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t); 703 892 if ($3.constant) 704 893 { … … 716 905 717 906 | plusminus OBJNAME '.' member { 718 $$.constant=0; $$.ident=0; SString t=$2.getString(); t+="."; t+=$4.getString(); $$.setString(t);907 trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$2.getString(); t+="."; t+=$4.getString(); $$.setString(t); 719 908 if ($4.constant) 720 909 { … … 731 920 732 921 | OBJNAME '.' member plusminus { 733 $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t);922 trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t); 734 923 if ($3.constant) 735 924 { … … 746 935 747 936 | OBJNAME '.' '*' { 748 $$.constant=0; $$.ident=0; SString t=$1.getString(); t+=".*"; $$.setString(t);937 trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$1.getString(); t+=".*"; $$.setString(t); 749 938 trctx.out->printf("push %s.*\n",str($1)); trstack.adjust(-1); 750 939 } … … 752 941 753 942 | OBJNAME '.' member '=' expr { 754 $$=$5; $$.assign=1; $$.parens=0; $$.ident=0;943 trctx.emitLine(); $$=$5; $$.assign=1; $$.parens=0; $$.ident=0; 755 944 if ($3.constant) 756 945 { … … 779 968 | OBJNAME '.' member '(' arguments ')' 780 969 { 781 970 trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t); 782 971 int adj=0,adj2=0; 783 972 if ($5.getInt()==0) … … 799 988 800 989 | CALL expr '(' arguments ')' 801 { $$.constant=0; $$.ident=0; $$.setString($2.getString());990 { trctx.emitLine(); $$.constant=0; $$.ident=0; $$.setString($2.getString()); 802 991 short adj=0; 803 992 if ($4.getInt()==0) … … 815 1004 816 1005 | FUNCTION IDENT 817 { $$.constant=0; $$.ident=0; SString t=":"; t+=$1.getString(); $$.setString(t);1006 { trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=":"; t+=$1.getString(); $$.setString(t); 818 1007 trctx.out->printf("push :%s\n",(const char*)$2.getString()); 819 1008 trstack.adjust(-1); … … 821 1010 822 1011 | expr '.' member 823 { $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t);1012 { trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t); 824 1013 if ($3.constant) 825 1014 trctx.out->printf("move s0,m1\nmove [m1].%s,s0\n",str($3)); … … 830 1019 831 1020 | plusminus expr '.' member 832 { $$.constant=0; $$.ident=0; SString t=$2.getString(); t+="."; t+=$4.getString(); $$.setString(t);1021 { trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$2.getString(); t+="."; t+=$4.getString(); $$.setString(t); 833 1022 if ($4.constant) 834 1023 trctx.out->printf("move s0,m1\n%s [m1].%s\nmove [m1].%s,s0\n", … … 841 1030 842 1031 | expr '.' member plusminus 843 { $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t);1032 { trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t); 844 1033 if ($3.constant) 845 1034 trctx.out->printf("move s0,m1\nmove [m1].%s,s0\n%s [m1].%s\n", … … 852 1041 853 1042 | expr '.' member assign_op expr 854 { $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t);1043 { trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t); 855 1044 if ($3.constant) 856 1045 { … … 880 1069 881 1070 | expr '.' member '=' stackexpr 882 { $$=$5; $$.assign=1; $$.parens=0; $$.ident=0;1071 { trctx.emitLine(); $$=$5; $$.assign=1; $$.parens=0; $$.ident=0; 883 1072 if ($3.constant) 884 1073 { … … 894 1083 895 1084 | expr '.' member '(' arguments ')' 896 { $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t);1085 { trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$1.getString(); t+="."; t+=$3.getString(); $$.setString(t); 897 1086 int adj=0; 898 1087 if ($5.getInt()==0) … … 917 1106 918 1107 | expr '[' expr ']' '=' expr // shortcut: expr.set(expr,expr) 919 { $$=$6; $$.assign=1; $$.parens=0; $$.ident=0;1108 { trctx.emitLine(); $$=$6; $$.assign=1; $$.parens=0; $$.ident=0; 920 1109 if ($3.constant) 921 1110 { … … 935 1124 936 1125 | expr '[' expr ']' /* shortcut: expr.get(expr) */ 937 { $$.constant=0; $$.ident=0; SString t=$1.getString(); t+=".get"; $$.setString(t);1126 { trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$1.getString(); t+=".get"; $$.setString(t); 938 1127 if ($3.constant) 939 1128 { … … 947 1136 } 948 1137 949 | IDENT '=' expr { $$=$3; $$.assign=1; $$.ident=0;1138 | IDENT '=' expr { trctx.emitLine(); $$=$3; $$.assign=1; $$.ident=0; 950 1139 int loc=trstack.getVariableLocation($1.getString()); 951 1140 if (loc!=TranslatorStack::NOTFOUND) … … 963 1152 964 1153 | OBJNAME '[' expr ']' /* shortcut: OBJNAME.get(expr) */ 965 { $$.constant=0; $$.ident=0; SString t=$1.getString(); t+=".get"; $$.setString(t);1154 { trctx.emitLine(); $$.constant=0; $$.ident=0; SString t=$1.getString(); t+=".get"; $$.setString(t); 966 1155 if ($3.constant) 967 1156 { … … 977 1166 | IDENT '(' arguments ')' 978 1167 { 979 $$.constant=0; $$.ident=0; $$.setString("function call");1168 trctx.emitLine(); $$.constant=0; $$.ident=0; $$.setString("function call"); 980 1169 if ($3.getInt()==0) 981 1170 {trctx.out->printf("dec m0\n");trstack.adjust(-1);} … … 988 1177 } 989 1178 990 | '[' { $$.ident=0; trctx.out->printf("add -2,m0\ncall Vector.new\nmove s0,s1\n");trstack.adjust(-2);} // s1=vector, s0=nieuzywane ale zarezerwowane zeby nie przesuwac stosu przy kazdym elemencie (trafia tu wartosc zwracana przez add/set)1179 | '[' {trctx.emitLine(); $$.ident=0; trctx.out->printf("add -2,m0\ncall Vector.new\nmove s0,s1\n");trstack.adjust(-2);} // s1=vector, s0=nieuzywane ale zarezerwowane zeby nie przesuwac stosu przy kazdym elemencie (trafia tu wartosc zwracana przez add/set) 991 1180 v_elements ']' 992 1181 {$$.constant=0; trctx.out->printf("inc m0\n");trstack.adjust(1);} 993 1182 994 | '{' { $$.ident=0; trctx.out->printf("add -2,m0\ncall Dictionary.new\nmove s0,s1\n");trstack.adjust(-2);} // s1=dict, s0=nieuzywane ale zarezerwowane zeby nie przesuwac stosu przy kazdym elemencie (trafia tu wartosc zwracana przez add/set)1183 | '{' {trctx.emitLine(); $$.ident=0; trctx.out->printf("add -2,m0\ncall Dictionary.new\nmove s0,s1\n");trstack.adjust(-2);} // s1=dict, s0=nieuzywane ale zarezerwowane zeby nie przesuwac stosu przy kazdym elemencie (trafia tu wartosc zwracana przez add/set) 995 1184 d_elements '}' 996 1185 {$$.constant=0; trctx.out->printf("inc m0\n"); trstack.adjust(1);} … … 999 1188 1000 1189 | '&' IDENT { 1001 $$.ident=0;1190 trctx.emitLine(); $$.ident=0; 1002 1191 int loc=trstack.getVariableLocation($2.getString()); 1003 1192 if (loc!=TranslatorStack::NOTFOUND) … … 1014 1203 1015 1204 | '&' OBJNAME '.' member { 1016 $$.ident=0;1205 trctx.emitLine(); $$.ident=0; 1017 1206 if ($4.constant) 1018 1207 { … … 1027 1216 1028 1217 | '&' '(' stackexpr ')' '.' member { 1029 $$.ident=0;1218 trctx.emitLine(); $$.ident=0; 1030 1219 if ($6.constant) 1031 1220 { … … 1040 1229 1041 1230 | '(' stackexpr ',' stackexpr ',' stackexpr ')' { 1042 $$.ident=0;1231 trctx.emitLine(); $$.ident=0; 1043 1232 trctx.out->printf("call XYZ.new\nadd 2,m0\nmove s-2,s0\n");trstack.adjust(2);} 1044 1233 ; … … 1133 1322 1134 1323 void handleTwoArg(YYSTYPE& result,const YYSTYPE& arg1,const YYSTYPE& arg2, 1135 int optoken,const char* opname,bool logic,bool negarg2,bool uniq) 1136 { 1324 int optoken,const char* opname,bool negarg2,bool uniq) 1325 { 1326 trctx.emitLine(); 1137 1327 result.ident=false; 1138 1328 if (arg1.constant && arg2.constant) … … 1150 1340 case LSHIFT: result.setInt(arg1.getInt() << arg2.getInt()); break; 1151 1341 case RSHIFT: result.setInt(arg1.getInt() >> arg2.getInt()); break; 1152 case LOGIC_AND: result.setInt(arg1.getInt() && arg2.getInt()); break;1153 case LOGIC_OR: result.setInt(arg1.getInt() || arg2.getInt()); break;1154 1342 } 1155 1343 } … … 1164 1352 result.setString(opname); 1165 1353 if (arg1.constant) 1166 trctx.out->printf("move %s,m1\n%s%s%s s0,m1\nmove m1,s0\n",litstr(arg1), 1167 (logic?"setif !=,m1,m1\nsetif !=,s0,s0\n":""), 1354 trctx.out->printf("move %s,m1\n%s%s s0,m1\nmove m1,s0\n",litstr(arg1), 1168 1355 negarg2?"neg s0\n":"", 1169 1356 opname); 1170 1357 else if (arg2.constant) 1171 1358 { 1172 if (logic) 1173 trctx.out->printf("move %s,m1\nsetif !=,m1,m1\nsetif !=,s0,s0\n%s m1,s0\n", 1174 litstr(arg2),opname); 1359 if (negarg2) 1360 trctx.out->printf("%s %d,s0\n",opname,-arg2.getInt()); 1175 1361 else 1176 { 1177 if (negarg2) 1178 trctx.out->printf("%s %d,s0\n",opname,-arg2.getInt()); 1179 else 1180 trctx.out->printf("%s%s %s,s0\n",(uniq?"uniq s0\n":""),opname,litstr(arg2)); 1181 } 1362 trctx.out->printf("%s%s %s,s0\n",(uniq?"uniq s0\n":""),opname,litstr(arg2)); 1182 1363 } 1183 1364 else 1184 1365 { 1185 1366 trctx.out->printf("%s%s%s s0,s1\ninc m0\n", 1186 (logic?"setif !=,s0,s0\nsetif !=,s1,s1\n":(uniq?"uniq s1\n":"")),1367 uniq?"uniq s1\n":"", 1187 1368 negarg2?"neg s0\n":"", 1188 1369 opname); … … 1227 1408 } 1228 1409 1229 void handleCompare(YYSTYPE& result,const YYSTYPE& arg1,const YYSTYPE& arg2,int optoken,const char* opname) 1230 { 1410 class FramscriptCmpMessageHandler: public ExtValue::CmpMessageHandler 1411 { 1412 public: 1413 void cmpMessage(SString& msg) 1414 { 1415 FMprintf("FramScriptCompiler","translate",FMLV_WARN,"%s (%s line %d)",(const char*)msg,(const char*)trctx.srcname,trctx.line); 1416 //trctx.err->printf("%s",(const char*)msg); 1417 } 1418 }; 1419 1420 static FramscriptCmpMessageHandler framscript_cmp_messages; 1421 1422 bool handleCompare(YYSTYPE& result,const YYSTYPE& arg1,const YYSTYPE& arg2,ExtValue::CmpOperator op,const char* opname) 1423 { 1424 trctx.emitLine(); 1231 1425 result.ident=0; 1232 1426 if (arg1.constant && arg2.constant) 1233 1427 { 1234 1428 result.constant=1; 1235 switch(optoken) 1236 { 1237 case '>': result.setInt(arg1.compare(arg2) > 0); break; 1238 case '<': result.setInt(arg1.compare(arg2) < 0); break; 1239 case EQUAL: result.setInt(arg1.compare(arg2) == 0); break; 1240 case NOT_EQUAL: result.setInt(arg1.compare(arg2) != 0); break; 1241 case GEQUAL: result.setInt(arg1.compare(arg2) >= 0); break; 1242 case LEQUAL: result.setInt(arg1.compare(arg2) <= 0); break; 1243 } 1429 int cmp=arg1.compare(arg2); 1430 ExtValue::CmpContext context; 1431 context.v1=&arg1; 1432 context.v2=&arg2; 1433 context.handler=&framscript_cmp_messages; 1434 int ret=ExtValue::interpretCompare(op,cmp,&context); 1435 if (ret<0) 1436 result.setEmpty();//return false; 1437 else 1438 result.setInt(ret); 1439 return true; 1244 1440 } 1245 1441 else … … 1258 1454 trstack.adjust(+1); 1259 1455 } 1456 return true; 1260 1457 } 1261 1458 }
Note: See TracChangeset
for help on using the changeset viewer.