--- parser3/src/main/compile.tab.C 2009/04/17 12:19:34 1.125 +++ parser3/src/main/compile.tab.C 2010/10/08 13:16:36 1.152 @@ -129,10 +129,10 @@ /** @file Parser: compiler(lexical parser and grammar). - Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.tab.C,v 1.125 2009/04/17 12:19:34 misha Exp $ + $Id: compile.tab.C,v 1.152 2010/10/08 13:16:36 misha Exp $ */ /** @@ -171,6 +171,7 @@ #define OPTIONS_CONTROL_METHOD_NAME "OPTIONS" #define OPTION_ALL_VARS_LOCAL_NAME "locals" #define OPTION_PARTIAL_CLASS "partial" +#define REM_OPERATOR_NAME "rem" // forwards @@ -216,7 +217,7 @@ typedef int YYSTYPE; /* Line 214 of yacc.c. */ -#line 220 "compile.tab.C" +#line 221 "compile.tab.C" #if ! defined (yyoverflow) || YYERROR_VERBOSE @@ -455,24 +456,24 @@ static const short int yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const unsigned short int yyrline[] = { - 0, 131, 131, 138, 140, 140, 141, 143, 143, 145, - 246, 246, 247, 247, 248, 249, 249, 251, 251, 301, - 301, 302, 303, 303, 304, 304, 306, 306, 310, 310, - 312, 312, 313, 313, 314, 314, 314, 318, 325, 326, - 326, 327, 329, 330, 331, 353, 354, 354, 358, 363, - 364, 365, 366, 383, 388, 391, 392, 393, 395, 398, - 395, 406, 414, 421, 422, 423, 425, 431, 432, 432, - 436, 442, 445, 442, 461, 463, 463, 465, 466, 467, - 469, 472, 469, 475, 476, 478, 479, 482, 483, 486, - 487, 489, 493, 508, 513, 514, 515, 520, 520, 522, - 522, 523, 524, 532, 537, 540, 541, 542, 543, 545, - 549, 558, 561, 558, 569, 574, 574, 575, 581, 582, - 584, 596, 608, 610, 611, 612, 613, 614, 615, 616, - 617, 619, 620, 621, 622, 623, 624, 625, 626, 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, 657, 662, 671, 676, - 677, 678, 680 + 0, 132, 132, 139, 141, 141, 142, 144, 144, 146, + 253, 253, 254, 254, 255, 256, 256, 258, 258, 306, + 306, 307, 308, 308, 309, 309, 311, 311, 315, 315, + 317, 317, 318, 318, 319, 319, 319, 323, 364, 365, + 365, 366, 368, 369, 370, 423, 424, 424, 428, 441, + 442, 443, 444, 470, 475, 478, 479, 480, 482, 485, + 482, 493, 501, 508, 509, 510, 512, 518, 519, 519, + 523, 535, 538, 535, 582, 584, 584, 586, 587, 588, + 590, 593, 590, 596, 597, 599, 600, 603, 604, 607, + 608, 610, 613, 627, 632, 633, 634, 639, 639, 641, + 641, 642, 643, 651, 656, 659, 660, 661, 662, 664, + 668, 677, 680, 677, 688, 693, 693, 694, 700, 701, + 703, 716, 728, 730, 731, 732, 733, 734, 735, 736, + 737, 739, 740, 741, 742, 743, 744, 745, 746, 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, 777, 782, 803, 808, + 809, 810, 812 }; #endif @@ -1427,20 +1428,20 @@ yyreduce: switch (yyn) { case 2: -#line 131 "compile.y" +#line 132 "compile.y" { - Method& method=*new Method(Method::CT_ANY, + Method* method=new Method(Method::CT_ANY, 0, 0, /*min, max numbered_params_count*/ 0/*param_names*/, 0/*local_names*/, yyvsp[0]/*parser_code*/, 0/*native_code*/); - PC.cclass->add_method(PC.alias_method(main_method_name), method); + PC.cclass->set_method(PC.alias_method(main_method_name), method); ;} break; case 9: -#line 146 "compile.y" +#line 147 "compile.y" { - const String& command=*LA2S(*yyvsp[-2]); + const String& command=LA2S(*yyvsp[-2])->trim(String::TRIM_END); YYSTYPE strings_code=yyvsp[0]; if(strings_code->count()<1*OPERATIONS_PER_OPVALUE) { strcpy(PC.error, "@"); @@ -1451,7 +1452,7 @@ yyreduce: if(command==CLASS_NAME) { if(strings_code->count()==1*OPERATIONS_PER_OPVALUE) { // new class' name - const String& name=*LA2S(*strings_code); + const String& name=LA2S(*strings_code)->trim(String::TRIM_END); // creating the class VStateless_class* cclass=new VClass; PC.cclass_new=cclass; @@ -1462,7 +1463,7 @@ yyreduce: } } else if(command==USE_CONTROL_METHOD_NAME) { for(size_t i=0; icount(); i+=OPERATIONS_PER_OPVALUE) - PC.request.use_file(PC.request.main_class, *LA2S(*strings_code, i)); + PC.request.use_file(PC.request.main_class, LA2S(*strings_code, i)->trim(String::TRIM_END), PC.request.get_used_filename(PC.file_no)); } else if(command==BASE_NAME) { if(PC.append){ strcpy(PC.error, "can't set base while appending methods to class '"); @@ -1478,8 +1479,8 @@ yyreduce: YYERROR; } if(strings_code->count()==1*OPERATIONS_PER_OPVALUE) { - const String& base_name=*LA2S(*strings_code); - if(Value* base_class_value=PC.request.classes().get(base_name)) { + const String& base_name=LA2S(*strings_code)->trim(String::TRIM_END); + if(Value* base_class_value=PC.request.get_class(base_name)) { // @CLASS == @BASE sanity check if(VStateless_class *base_class=base_class_value->get_class()) { if(PC.cclass==base_class) { @@ -1503,7 +1504,7 @@ yyreduce: } } else if(command==OPTIONS_CONTROL_METHOD_NAME) { for(size_t i=0; icount(); i+=OPERATIONS_PER_OPVALUE) { - const String& option=*LA2S(*strings_code, i); + const String& option=LA2S(*strings_code, i)->trim(String::TRIM_END); if(option==OPTION_ALL_VARS_LOCAL_NAME){ PC.set_all_vars_local(); } else if(option==OPTION_PARTIAL_CLASS){ @@ -1516,18 +1517,24 @@ yyreduce: YYERROR; } } else { - // mark new class as partial. we can add methods to it later. + // marks the new class as partial. we will be able to add methods here later. PC.cclass_new->set_partial(); } } else { strcpy(PC.error, "'"OPTION_PARTIAL_CLASS"' option should be used straight after @"CLASS_NAME); YYERROR; } + } else if(option==method_call_type_static){ + PC.set_methods_call_type(Method::CT_STATIC); + } else if(option==method_call_type_dynamic){ + PC.set_methods_call_type(Method::CT_DYNAMIC); } else { strcpy(PC.error, "'"); strncat(PC.error, option.cstr(), MAX_STRING/2); strcat(PC.error, "' invalid option. valid options are " - "'"OPTION_PARTIAL_CLASS"' and '"OPTION_ALL_VARS_LOCAL_NAME"'"); + "'"OPTION_PARTIAL_CLASS"', '"OPTION_ALL_VARS_LOCAL_NAME"'" + ", '"METHOD_CALL_TYPE_STATIC"' and '"METHOD_CALL_TYPE_DYNAMIC"'" + ); YYERROR; } } @@ -1542,12 +1549,12 @@ yyreduce: break; case 13: -#line 247 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 254 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 17: -#line 251 "compile.y" +#line 258 "compile.y" { PC.class_add(); PC.explicit_result=false; @@ -1580,124 +1587,204 @@ yyreduce: Method* method=new Method( //name, - Method::CT_ANY, + GetMethodCallType(PC, *yyvsp[-4]), 0, 0/*min,max numbered_params_count*/, params_names, locals_names, 0/*to be filled later in next {} */, 0, all_vars_local); *reinterpret_cast(&yyval)=method; - - // todo: check [][;result;] ;} break; case 18: -#line 291 "compile.y" +#line 296 "compile.y" { - Method& method=*reinterpret_cast(yyvsp[-1]); + Method* method=reinterpret_cast(yyvsp[-1]); // fill in the code - method.parser_code=yyvsp[0]; + method->parser_code=yyvsp[0]; // register in class const String& name=*LA2S(*yyvsp[-6]); - PC.cclass->add_method(PC.alias_method(name), method); + PC.cclass->set_method(PC.alias_method(name), method); ;} break; case 21: -#line 302 "compile.y" - {yyval=yyvsp[-1];} +#line 307 "compile.y" + {yyval=yyvsp[-1];;} break; case 25: -#line 304 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} +#line 309 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); ;} break; case 31: -#line 312 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 317 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 37: -#line 318 "compile.y" +#line 323 "compile.y" { - yyval=yyvsp[0]; /* stack: resulting value */ - changetail_or_append(*yyval, - OP::OP_GET_ELEMENT, false, /*->*/OP::OP_GET_ELEMENT__WRITE, - /*or */OP::OP_WRITE_VALUE - ); /* value=pop; wcontext.write(value) */ + yyval=N(); + YYSTYPE code=yyvsp[0]; + size_t count=code->count(); + +#ifdef OPTIMIZE_BYTECODE_GET_ELEMENT + if( + count!=3 + || !maybe_change_first_opcode(*code, OP::OP_VALUE__GET_ELEMENT, /*=>*/OP::OP_VALUE__GET_ELEMENT__WRITE) + ) +#endif + +#ifdef OPTIMIZE_BYTECODE_GET_SELF_ELEMENT + if( + count!=3 + || !maybe_change_first_opcode(*code, OP::OP_WITH_SELF__VALUE__GET_ELEMENT, /*=>*/OP::OP_WITH_SELF__VALUE__GET_ELEMENT__WRITE) + ) +#endif + +#ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT + if( + count!=5 + || !maybe_change_first_opcode(*code, OP::OP_GET_OBJECT_ELEMENT, /*=>*/OP::OP_GET_OBJECT_ELEMENT__WRITE) + ) +#endif + +#ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT + if( + count!=5 + || !maybe_change_first_opcode(*code, OP::OP_GET_OBJECT_VAR_ELEMENT, /*=>*/OP::OP_GET_OBJECT_VAR_ELEMENT__WRITE) + ) +#endif + { + changetail_or_append(*code, + OP::OP_GET_ELEMENT, false, /*=>*/OP::OP_GET_ELEMENT__WRITE, + /*or */OP::OP_WRITE_VALUE + ); /* value=pop; wcontext.write(value) */ + } + + P(*yyval, *code); ;} break; case 38: -#line 325 "compile.y" - { yyval=yyvsp[0] ;} +#line 364 "compile.y" + { yyval=yyvsp[0]; ;} break; case 41: -#line 327 "compile.y" - { yyval=yyvsp[-1] ;} +#line 366 "compile.y" + { yyval=yyvsp[-1]; ;} break; case 44: -#line 331 "compile.y" +#line 370 "compile.y" { yyval=N(); - ArrayOperation* diving_code=yyvsp[0]; - const String* first_name=LA2S(*diving_code); - // self.xxx... -> xxx... - // OP_VALUE+origin+string+OP_GET_ELEMENT+... -> OP_WITH_SELF+... - if(first_name && *first_name==SELF_ELEMENT_NAME) { - O(*yyval, OP::OP_WITH_SELF); /* stack: starting context */ - P(*yyval, *diving_code, - /* skip over... */ - diving_code->count()>=4?4/*OP::OP_VALUE+origin+string+OP::OP_GET_ELEMENTx*/:3/*OP::OP_+origin+string*/); + YYSTYPE diving_code=yyvsp[0]; + size_t count=diving_code->count(); + + if(maybe_make_self(*yyval, *diving_code, count)) { + // $self. + } else + +#ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT + if(maybe_make_get_object_element(*yyval, *diving_code, count)){ + // optimization for $object.field + ^object.method[ + } else +#endif + +#ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT + if(maybe_make_get_object_var_element(*yyval, *diving_code, count)){ + // optimization for $object.$var + } else +#endif + +#ifdef OPTIMIZE_BYTECODE_GET_ELEMENT + if( + count>=4 + && (*diving_code)[0].code==OP::OP_VALUE + && (*diving_code)[3].code==OP::OP_GET_ELEMENT + ){ + // optimization + O(*yyval, + (PC.in_call_value && count==4) + ? OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR // ^object[ : OP_VALUE+origin+string+OP_GET_ELEMENT => OP_VALUE__GET_ELEMENT_OR_OPERATOR+origin+string + : OP::OP_VALUE__GET_ELEMENT // $object : OP_VALUE+origin+string+OP_GET_ELEMENT => OP_VALUE__GET_ELEMENT+origin+string + ); + P(*yyval, *diving_code, 1/*offset*/, 2/*limit*/); // copy origin+value + if(count>4) + P(*yyval, *diving_code, 4); // copy tail } else { O(*yyval, OP::OP_WITH_READ); /* stack: starting context */ + P(*yyval, *diving_code); + } +#else + { + O(*yyval, OP::OP_WITH_READ); /* stack: starting context */ - // ^if ELEMENT -> ^if ELEMENT_OR_OPERATOR - // OP_VALUE+origin+string+OP_GET_ELEMENT. -> OP_VALUE+origin+string+OP_GET_ELEMENT_OR_OPERATOR. - if(PC.in_call_value && diving_code->count()==4) - diving_code->put(4-1, OP::OP_GET_ELEMENT_OR_OPERATOR); + // ^if OP_ELEMENT => ^if OP_ELEMENT_OR_OPERATOR + // optimized OP_VALUE+origin+string+OP_GET_ELEMENT. => OP_VALUE+origin+string+OP_GET_ELEMENT_OR_OPERATOR. + if(PC.in_call_value && count==4) + diving_code->put(count-1, OP::OP_GET_ELEMENT_OR_OPERATOR); P(*yyval, *diving_code); } +#endif /* diving code; stack: current context */ ;} break; case 45: -#line 353 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 423 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 47: -#line 354 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 424 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 48: -#line 358 "compile.y" +#line 428 "compile.y" { - yyval=yyvsp[-1]; /* stack: context,name */ - P(*yyval, *yyvsp[0]); /* stack: context,name,constructor_value */ + yyval=N(); +#ifdef OPTIMIZE_BYTECODE_CONSTRUCT + if(maybe_optimize_construct(*yyval, *yyvsp[-1], *yyvsp[0])){ + // $a(expr), $.a(expr), $a[value], $.a[value], $self.a[value], $self.a(expr) + } else +#endif + { + P(*yyval, *yyvsp[-1]); /* stack: context,name */ + P(*yyval, *yyvsp[0]); /* stack: context,name,constructor_value */ + } ;} break; case 52: -#line 366 "compile.y" +#line 444 "compile.y" { yyval=N(); - ArrayOperation* diving_code=yyvsp[0]; - const String* first_name=LA2S(*diving_code); - // $self.xxx... -> $xxx... - // OP_VALUE+origin+string+OP_GET_ELEMENT+... -> OP_WITH_SELF+... - if(first_name && *first_name==SELF_ELEMENT_NAME) { - O(*yyval, OP::OP_WITH_SELF); /* stack: starting context */ - P(*yyval, *diving_code, - /* skip over... */ - diving_code->count()>=4?4/*OP::OP_VALUE+origin+string+OP::OP_GET_ELEMENTx*/:3/*OP::OP_+origin+string*/); - } else { + YYSTYPE diving_code=yyvsp[0]; + size_t count=diving_code->count(); + + if(maybe_make_self(*yyval, *diving_code, count)) { + // $self. + } else +#ifdef OPTIMIZE_BYTECODE_GET_ELEMENT + if( + count>=4 + && (*diving_code)[0].code==OP::OP_VALUE + && (*diving_code)[3].code==OP::OP_GET_ELEMENT + ){ + O(*yyval, OP::OP_WITH_ROOT__VALUE__GET_ELEMENT); + P(*yyval, *diving_code, 1/*offset*/, 2/*limit*/); // copy origin+value + if(count>4) + P(*yyval, *diving_code, 4); // tail + } else +#endif + { O(*yyval, OP::OP_WITH_ROOT); /* stack: starting context */ P(*yyval, *diving_code); } @@ -1706,7 +1793,7 @@ yyreduce: break; case 53: -#line 383 "compile.y" +#line 470 "compile.y" { yyval=N(); O(*yyval, OP::OP_WITH_WRITE); /* stack: starting context */ @@ -1715,12 +1802,12 @@ yyreduce: break; case 54: -#line 388 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 475 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 58: -#line 395 "compile.y" +#line 482 "compile.y" { // allow $result_or_other_variable[ letters here any time ] *reinterpret_cast(&yyval)=PC.explicit_result; PC.explicit_result=false; @@ -1728,14 +1815,14 @@ yyreduce: break; case 59: -#line 398 "compile.y" +#line 485 "compile.y" { PC.explicit_result=*reinterpret_cast(&yyvsp[-1]); ;} break; case 60: -#line 400 "compile.y" +#line 487 "compile.y" { // stack: context, name yyval=yyvsp[-2]; // stack: context, name, value @@ -1744,7 +1831,7 @@ yyreduce: break; case 61: -#line 406 "compile.y" +#line 493 "compile.y" { yyval=N(); O(*yyval, OP::OP_PREPARE_TO_EXPRESSION); @@ -1755,7 +1842,7 @@ yyreduce: break; case 62: -#line 414 "compile.y" +#line 501 "compile.y" { // stack: context, name yyval=N(); @@ -1764,7 +1851,7 @@ yyreduce: break; case 66: -#line 425 "compile.y" +#line 512 "compile.y" { yyval=N(); OA(*yyval, OP::OP_OBJECT_POOL, yyvsp[0]); /* stack: empty write context */ @@ -1774,57 +1861,91 @@ yyreduce: break; case 69: -#line 432 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 519 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 70: -#line 436 "compile.y" +#line 523 "compile.y" { - yyval=yyvsp[0]; /* stack: value */ - changetail_or_append(*yyval, - OP::OP_CALL, true, /*->*/ OP::OP_CALL__WRITE, - /*or */OP::OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */ +#ifdef OPTIMIZE_BYTECODE_CUT_REM_OPERATOR + if((*yyvsp[0]).count()) +#endif + { + yyval=yyvsp[0]; /* stack: value */ + if(!maybe_change_first_opcode(*yyval, OP::OP_CONSTRUCT_OBJECT, /*=>*/OP::OP_CONSTRUCT_OBJECT__WRITE)) + changetail_or_append(*yyval, + OP::OP_CALL, true, /*=>*/ OP::OP_CALL__WRITE, + /*or */OP::OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */ + } ;} break; case 71: -#line 442 "compile.y" +#line 535 "compile.y" { PC.in_call_value=true; ;} break; case 72: -#line 445 "compile.y" +#line 538 "compile.y" { PC.in_call_value=false; ;} break; case 73: -#line 448 "compile.y" +#line 541 "compile.y" { /* ^field.$method{vasya} */ - yyval=yyvsp[-3]; /* with_xxx,diving code; stack: context,method_junction */ +#ifdef OPTIMIZE_BYTECODE_CUT_REM_OPERATOR +#ifdef OPTIMIZE_BYTECODE_GET_ELEMENT + const String* operator_name=LA2S(*yyvsp[-3], 0, OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR); +#else + const String* operator_name=LA2S(*yyvsp[-3], 1); +#endif + if(operator_name && *operator_name==REM_OPERATOR_NAME){ + yyval=N(); + } else +#endif + { + YYSTYPE params_code=yyvsp[-1]; + if(params_code->count()==3) { // probably [] case. [OP::OP_VALUE+origin+Void] + if(Value* value=LA2V(*params_code)) // it is OP_VALUE+origin+value? + if(value->is_void()) // value is VVoid? + params_code=0; // ^zzz[] case. don't append lone empty param. + } + /* stack: context, method_junction */ - YYSTYPE params_code=yyvsp[-1]; - if(params_code->count()==4) { // probably [] case. [OP::OP_VALUE+origin+Void+STORE_PARAM] - if(Value* value=LA2V(*params_code)) // it is OP_VALUE+origin+value? - if(value->is_void()) // value is VVoid? - params_code=0; // ^zzz[] case. don't append lone empty param. - } - /* stack: context, method_junction */ - OA(*yyval, OP::OP_CALL, params_code); // method_frame=make frame(pop junction); ncontext=pop; call(ncontext,method_frame) stack: value + YYSTYPE var_code=yyvsp[-3]; + if( + var_code->count()==8 + && (*var_code)[0].code==OP::OP_VALUE__GET_CLASS + && (*var_code)[3].code==OP::OP_PREPARE_TO_CONSTRUCT_OBJECT + && (*var_code)[4].code==OP::OP_VALUE + && (*var_code)[7].code==OP::OP_GET_ELEMENT + ){ + yyval=N(); + O(*yyval, OP::OP_CONSTRUCT_OBJECT); + P(*yyval, *var_code, 1/*offset*/, 2/*limit*/); // class name + P(*yyval, *var_code, 5/*offset*/, 2/*limit*/); // constructor name + OA(*yyval, params_code); + } else + { + yyval=var_code; /* with_xxx,diving code; stack: context,method_junction */ + OA(*yyval, OP::OP_CALL, params_code); // method_frame=make frame(pop junction); ncontext=pop; call(ncontext,method_frame) stack: value + } + } ;} break; case 76: -#line 463 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 584 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 80: -#line 469 "compile.y" +#line 590 "compile.y" { // allow ^call[ letters here any time ] *reinterpret_cast(&yyval)=PC.explicit_result; PC.explicit_result=false; @@ -1832,60 +1953,58 @@ yyreduce: break; case 81: -#line 472 "compile.y" +#line 593 "compile.y" { PC.explicit_result=*reinterpret_cast(&yyvsp[-1]); ;} break; case 82: -#line 474 "compile.y" - {yyval=yyvsp[-2];} +#line 595 "compile.y" + {yyval=yyvsp[-2];;} break; case 83: -#line 475 "compile.y" - {yyval=yyvsp[-1];} +#line 596 "compile.y" + {yyval=yyvsp[-1];;} break; case 84: -#line 476 "compile.y" - {yyval=yyvsp[-1];} +#line 597 "compile.y" + {yyval=yyvsp[-1];;} break; case 86: -#line 479 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} +#line 600 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); ;} break; case 88: -#line 483 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} +#line 604 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); ;} break; case 90: -#line 487 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} +#line 608 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); ;} break; case 91: -#line 489 "compile.y" +#line 610 "compile.y" { yyval=yyvsp[0]; - O(*yyval, OP::OP_STORE_PARAM); ;} break; case 92: -#line 493 "compile.y" +#line 613 "compile.y" { YYSTYPE expr_code=yyvsp[0]; if(expr_code->count()==3 - && (*expr_code)[0].code==OP::OP_VALUE) { // optimizing (double/bool/incidently 'string' too) case. [OP::OP_VALUE+origin+Double] + && (*expr_code)[0].code==OP::OP_VALUE) { // optimizing (double/bool/incidently 'string' too) case. [OP::OP_VALUE+origin+Double]. no evaluating yyval=expr_code; - O(*yyval, OP::OP_STORE_PARAM); // no evaluating } else { - ArrayOperation* code=N(); + YYSTYPE code=N(); O(*code, OP::OP_PREPARE_TO_EXPRESSION); P(*code, *expr_code); O(*code, OP::OP_WRITE_EXPR_RESULT); @@ -1896,7 +2015,7 @@ yyreduce: break; case 93: -#line 508 "compile.y" +#line 627 "compile.y" { yyval=N(); OA(*yyval, OP::OP_CURLY_CODE__STORE_PARAM, yyvsp[0]); @@ -1904,17 +2023,17 @@ yyreduce: break; case 98: -#line 520 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 639 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 100: -#line 522 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 641 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 102: -#line 524 "compile.y" +#line 643 "compile.y" { // we know that name_advance1 not called from ^xxx context // so we'll not check for operator call possibility as we do in name_advance2 @@ -1926,7 +2045,7 @@ yyreduce: break; case 103: -#line 532 "compile.y" +#line 651 "compile.y" { /* stack: context */ yyval=yyvsp[0]; /* stack: context,name */ @@ -1935,7 +2054,7 @@ yyreduce: break; case 109: -#line 545 "compile.y" +#line 664 "compile.y" { yyval=yyvsp[0]; O(*yyval, OP::OP_GET_ELEMENT); @@ -1943,9 +2062,9 @@ yyreduce: break; case 110: -#line 549 "compile.y" +#line 668 "compile.y" { - ArrayOperation* code; + YYSTYPE code; { change_string_literal_to_write_string_literal(*(code=yyvsp[-1])); P(*code, *yyvsp[0]); @@ -1956,7 +2075,7 @@ yyreduce: break; case 111: -#line 558 "compile.y" +#line 677 "compile.y" { // allow $result_or_other_variable[ letters here any time ] *reinterpret_cast(&yyval)=PC.explicit_result; PC.explicit_result=false; @@ -1964,14 +2083,14 @@ yyreduce: break; case 112: -#line 561 "compile.y" +#line 680 "compile.y" { PC.explicit_result=*reinterpret_cast(&yyvsp[-1]); ;} break; case 113: -#line 563 "compile.y" +#line 682 "compile.y" { yyval=N(); OA(*yyval, OP::OP_OBJECT_POOL, yyvsp[-2]); /* stack: empty write context */ @@ -1981,7 +2100,7 @@ yyreduce: break; case 114: -#line 569 "compile.y" +#line 688 "compile.y" { yyval=N(); O(*yyval, OP::OP_WITH_READ); @@ -1990,12 +2109,12 @@ yyreduce: break; case 116: -#line 574 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 693 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 117: -#line 575 "compile.y" +#line 694 "compile.y" { yyval=yyvsp[0]; O(*yyval, OP::OP_GET_ELEMENT__WRITE); @@ -2003,7 +2122,7 @@ yyreduce: break; case 120: -#line 584 "compile.y" +#line 703 "compile.y" { yyval=yyvsp[-1]; // stack: class name string if(*LA2S(*yyval) == BASE_NAME) { // pseudo BASE class @@ -2014,12 +2133,13 @@ yyreduce: YYERROR; } } - O(*yyval, OP::OP_GET_CLASS); + // optimized OP_VALUE+origin+string+OP_GET_CLASS => OP_VALUE__GET_CLASS+origin+string + maybe_change_first_opcode(*yyval, OP::OP_VALUE, OP::OP_VALUE__GET_CLASS); ;} break; case 121: -#line 596 "compile.y" +#line 716 "compile.y" { yyval=yyvsp[-1]; if(!PC.in_call_value) { @@ -2031,246 +2151,258 @@ yyreduce: break; case 128: -#line 615 "compile.y" - { yyval = yyvsp[-1] ;} +#line 735 "compile.y" + { yyval = yyvsp[-1]; ;} break; case 129: -#line 616 "compile.y" - { yyval = yyvsp[-1] ;} +#line 736 "compile.y" + { yyval = yyvsp[-1]; ;} break; case 130: -#line 617 "compile.y" +#line 737 "compile.y" { yyval = yyvsp[-1]; ;} break; case 131: -#line 619 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP::OP_NEG) ;} +#line 739 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_NEG); ;} break; case 132: -#line 620 "compile.y" - { yyval=yyvsp[0] ;} +#line 740 "compile.y" + { yyval=yyvsp[0]; ;} break; case 133: -#line 621 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP::OP_INV) ;} +#line 741 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_INV); ;} break; case 134: -#line 622 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP::OP_NOT) ;} +#line 742 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_NOT); ;} break; case 135: -#line 623 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP::OP_DEF) ;} +#line 743 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_DEF); ;} break; case 136: -#line 624 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP::OP_IN) ;} +#line 744 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_IN); ;} break; case 137: -#line 625 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP::OP_FEXISTS) ;} +#line 745 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_FEXISTS); ;} break; case 138: -#line 626 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP::OP_DEXISTS) ;} +#line 746 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_DEXISTS); ;} break; case 139: -#line 628 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_SUB) ;} +#line 748 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_SUB); ;} break; case 140: -#line 629 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_ADD) ;} +#line 749 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_ADD); ;} break; case 141: -#line 630 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_MUL) ;} +#line 750 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_MUL); ;} break; case 142: -#line 631 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_DIV) ;} +#line 751 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_DIV); ;} break; case 143: -#line 632 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_MOD) ;} +#line 752 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_MOD); ;} break; case 144: -#line 633 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_INTDIV) ;} +#line 753 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_INTDIV); ;} break; case 145: -#line 634 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_BIN_SL) ;} +#line 754 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_BIN_SL); ;} break; case 146: -#line 635 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_BIN_SR) ;} +#line 755 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_BIN_SR); ;} break; case 147: -#line 636 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_BIN_AND) ;} +#line 756 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_BIN_AND); ;} break; case 148: -#line 637 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_BIN_OR) ;} +#line 757 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_BIN_OR); ;} break; case 149: -#line 638 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_BIN_XOR) ;} +#line 758 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_BIN_XOR); ;} break; case 150: -#line 639 "compile.y" - { yyval=yyvsp[-2]; OA(*yyval, OP::OP_NESTED_CODE, yyvsp[0]); O(*yyval, OP::OP_LOG_AND) ;} +#line 759 "compile.y" + { yyval=yyvsp[-2]; OA(*yyval, OP::OP_NESTED_CODE, yyvsp[0]); O(*yyval, OP::OP_LOG_AND); ;} break; case 151: -#line 640 "compile.y" - { yyval=yyvsp[-2]; OA(*yyval, OP::OP_NESTED_CODE, yyvsp[0]); O(*yyval, OP::OP_LOG_OR) ;} +#line 760 "compile.y" + { yyval=yyvsp[-2]; OA(*yyval, OP::OP_NESTED_CODE, yyvsp[0]); O(*yyval, OP::OP_LOG_OR); ;} break; case 152: -#line 641 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_LOG_XOR) ;} +#line 761 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_LOG_XOR); ;} break; case 153: -#line 642 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_LT) ;} +#line 762 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_LT); ;} break; case 154: -#line 643 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_GT) ;} +#line 763 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_GT); ;} break; case 155: -#line 644 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_LE) ;} +#line 764 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_LE); ;} break; case 156: -#line 645 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_GE) ;} +#line 765 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_GE); ;} break; case 157: -#line 646 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_EQ) ;} +#line 766 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_EQ); ;} break; case 158: -#line 647 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_NE) ;} +#line 767 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_NUM_NE); ;} break; case 159: -#line 648 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_LT) ;} +#line 768 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_LT); ;} break; case 160: -#line 649 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_GT) ;} +#line 769 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_GT); ;} break; case 161: -#line 650 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_LE) ;} +#line 770 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_LE); ;} break; case 162: -#line 651 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_GE) ;} +#line 771 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_GE); ;} break; case 163: -#line 652 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_EQ) ;} +#line 772 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_EQ); ;} break; case 164: -#line 653 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_NE) ;} +#line 773 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_STR_NE); ;} break; case 165: -#line 654 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_IS) ;} +#line 774 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_IS); ;} break; case 166: -#line 657 "compile.y" +#line 777 "compile.y" { - // optimized from OP_STRING->OP_VALUE for doubles + // optimized OP_STRING => OP_VALUE for doubles maybe_change_string_literal_to_double_literal(*(yyval=yyvsp[0])); ;} break; case 167: -#line 662 "compile.y" +#line 782 "compile.y" { +#ifdef OPTIMIZE_BYTECODE_STRING_POOL + // it brakes ^if(" 09 "){...} + YYSTYPE code=yyvsp[0]; + yyval=N(); + if(code->count()==3 && maybe_change_first_opcode(*code, OP::OP_STRING__WRITE, OP::OP_VALUE)){ + // optimized OP_STRING__WRITE+origin+value => OP_VALUE+origin+value without starting OP_STRING_POOL + P(*yyval, *code); + } else { + OA(*yyval, OP::OP_STRING_POOL, code); /* stack: empty write context */ + } +#else yyval=N(); OA(*yyval, OP::OP_STRING_POOL, yyvsp[0]); /* stack: empty write context */ +#endif /* some code that writes to that context */ /* context=pop; stack: context.get_string() */ ;} break; case 168: -#line 671 "compile.y" +#line 803 "compile.y" { - // optimized from OP_STRING+OP_WRITE_VALUE to OP_STRING__WRITE - change_string_literal_to_write_string_literal(*(yyval=yyvsp[0])) + // optimized OP_STRING+OP_WRITE_VALUE => OP_STRING__WRITE + change_string_literal_to_write_string_literal(*(yyval=yyvsp[0])); ;} break; case 169: -#line 676 "compile.y" - { yyval=VL(/*we know that we will not change it*/const_cast(&vvoid), 0, 0, 0) ;} +#line 808 "compile.y" + { yyval=VL(/*we know that we will not change it*/const_cast(&vvoid), 0, 0, 0); ;} break; case 170: -#line 677 "compile.y" - { yyval = VL(/*we know that we will not change it*/const_cast(&vtrue), 0, 0, 0) ;} +#line 809 "compile.y" + { yyval = VL(/*we know that we will not change it*/const_cast(&vtrue), 0, 0, 0); ;} break; case 171: -#line 678 "compile.y" - { yyval = VL(/*we know that we will not change it*/const_cast(&vfalse), 0, 0, 0) ;} +#line 810 "compile.y" + { yyval = VL(/*we know that we will not change it*/const_cast(&vfalse), 0, 0, 0); ;} break; case 172: -#line 680 "compile.y" - { yyval=N() ;} +#line 812 "compile.y" + { yyval=N(); ;} break; } /* Line 1010 of yacc.c. */ -#line 2274 "compile.tab.C" +#line 2406 "compile.tab.C" yyvsp -= yylen; yyssp -= yylen; @@ -2495,7 +2627,7 @@ yyreturn: } -#line 682 "compile.y" +#line 814 "compile.y" #endif @@ -3035,7 +3167,7 @@ default: case ']': case '}': case ')': case '"': case '\'': case '<': case '>': // these stand for HTML brackets AND expression binary ops - case '+': case '*': case '/': case '%': + case '+': case '*': case '/': case '\\': case '%': case '&': case '|': case '=': case '!': // common delimiters @@ -3265,12 +3397,9 @@ default: break2: if(end!=begin) { // there is last piece? - if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF? - // strip last \n - end--; - if(end!=begin && end[-1]=='\n') // allow one empty line before LS_DEF_NAME + if(c=='@' || c==0) // we are before LS_DEF_NAME or EOF? + while(end!=begin && end[-1]=='\n') // trim all empty lines before LS_DEF_NAME and EOF end--; - } if(end!=begin && pc.ls!=LS_USER_COMMENT) { // last piece still alive and not comment? if(!pc.string_start) pc.string_start=begin_pos;