--- parser3/src/main/compile.tab.C 2009/05/19 13:47:21 1.132 +++ parser3/src/main/compile.tab.C 2010/10/12 21:59:08 1.153 @@ -132,7 +132,7 @@ Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.tab.C,v 1.132 2009/05/19 13:47:21 misha Exp $ + $Id: compile.tab.C,v 1.153 2010/10/12 21:59:08 moko Exp $ */ /** @@ -162,7 +162,6 @@ #include "pa_vobject.h" #include "pa_vdouble.h" #include "pa_globals.h" -#include "pa_vvoid.h" #include "pa_vmethod_frame.h" // defines @@ -181,7 +180,7 @@ static int yylex(YYSTYPE* lvalp, void* p static const VBool vfalse(false); static const VBool vtrue(true); -static const VVoid vvoid; +static const VString vempty; // local convinient inplace typecast & var #undef PC @@ -217,7 +216,7 @@ typedef int YYSTYPE; /* Line 214 of yacc.c. */ -#line 221 "compile.tab.C" +#line 220 "compile.tab.C" #if ! defined (yyoverflow) || YYERROR_VERBOSE @@ -456,24 +455,24 @@ static const short int yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const unsigned short int yyrline[] = { - 0, 132, 132, 139, 141, 141, 142, 144, 144, 146, - 247, 247, 248, 248, 249, 250, 250, 252, 252, 302, - 302, 303, 304, 304, 305, 305, 307, 307, 311, 311, - 313, 313, 314, 314, 315, 315, 315, 319, 360, 361, - 361, 362, 364, 365, 366, 428, 429, 429, 433, 438, - 439, 440, 441, 458, 463, 466, 467, 468, 470, 473, - 470, 481, 489, 496, 497, 498, 500, 506, 507, 507, - 511, 522, 525, 522, 549, 551, 551, 553, 554, 555, - 557, 560, 557, 563, 564, 566, 567, 570, 571, 574, - 575, 577, 580, 594, 599, 600, 601, 606, 606, 608, - 608, 609, 610, 618, 623, 626, 627, 628, 629, 631, - 635, 644, 647, 644, 655, 660, 660, 661, 667, 668, - 670, 687, 699, 701, 702, 703, 704, 705, 706, 707, - 708, 710, 711, 712, 713, 714, 715, 716, 717, 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, 748, 753, 774, 779, - 780, 781, 783 + 0, 131, 131, 138, 140, 140, 141, 143, 143, 145, + 252, 252, 253, 253, 254, 255, 255, 257, 257, 305, + 305, 306, 307, 307, 308, 308, 310, 310, 314, 314, + 316, 316, 317, 317, 318, 318, 318, 322, 363, 364, + 364, 365, 367, 368, 369, 422, 423, 423, 427, 440, + 441, 442, 443, 469, 474, 477, 478, 479, 481, 484, + 481, 492, 500, 507, 508, 509, 511, 517, 518, 518, + 522, 534, 537, 534, 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 @@ -516,7 +515,7 @@ static const char *const yytname[] = "subvar_ref_name_rdive", "subvar_get_writes", "subvar__get_write", "class_prefix", "class_static_prefix", "class_constructor_prefix", "expr_value", "expr", "double_or_STRING", "string_inside_quotes_value", - "write_string", "void_value", "true_value", "false_value", "empty", 0 + "write_string", "empty_value", "true_value", "false_value", "empty", 0 }; #endif @@ -1428,20 +1427,20 @@ yyreduce: switch (yyn) { case 2: -#line 132 "compile.y" +#line 131 "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 147 "compile.y" +#line 146 "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, "@"); @@ -1452,7 +1451,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; @@ -1463,7 +1462,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 '"); @@ -1479,8 +1478,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) { @@ -1504,7 +1503,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){ @@ -1517,18 +1516,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; } } @@ -1543,12 +1548,12 @@ yyreduce: break; case 13: -#line 248 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 253 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 17: -#line 252 "compile.y" +#line 257 "compile.y" { PC.class_add(); PC.explicit_result=false; @@ -1581,153 +1586,142 @@ 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 292 "compile.y" +#line 295 "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 303 "compile.y" - {yyval=yyvsp[-1];} +#line 306 "compile.y" + {yyval=yyvsp[-1];;} break; case 25: -#line 305 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} +#line 308 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); ;} break; case 31: -#line 313 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 316 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 37: -#line 319 "compile.y" +#line 322 "compile.y" { yyval=N(); YYSTYPE code=yyvsp[0]; + size_t count=code->count(); + #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT - if(!maybe_change_first_opcode(*code, OP::OP_VALUE__GET_ELEMENT, /*=>*/OP::OP_VALUE__GET_ELEMENT__WRITE)) + if( + count!=3 + || !maybe_change_first_opcode(*code, OP::OP_VALUE__GET_ELEMENT, /*=>*/OP::OP_VALUE__GET_ELEMENT__WRITE) + ) #endif - { - size_t count=code->count(); -#ifdef OPTIMIZE_BYTECODE_USE_TWO_OPERANDS_INSTRUCTIONS - size_t len=6; -#else - size_t len=7; + +#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==len - && maybe_change_first_opcode(*code, OP::OP_GET_OBJECT_ELEMENT, OP::OP_GET_ELEMENT, /*=>*/OP::OP_GET_OBJECT_ELEMENT__WRITE) - ){ - //P(*$$, *code, 0/*offset*/, count-1/*limit*/); // someday skip last OP_GET_ELEMENT - //break; - } else + 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==len - && maybe_change_first_opcode(*code, OP::OP_GET_OBJECT_VAR_ELEMENT, OP::OP_GET_ELEMENT, /*=>*/OP::OP_GET_OBJECT_VAR_ELEMENT__WRITE) - ){ - //P(*$$, *code, 0/*offset*/, count-1/*limit*/); // someday skip last OP_GET_ELEMENT - //break; - } else + 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) */ + } - 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 360 "compile.y" - { yyval=yyvsp[0] ;} +#line 363 "compile.y" + { yyval=yyvsp[0]; ;} break; case 41: -#line 362 "compile.y" - { yyval=yyvsp[-1] ;} +#line 365 "compile.y" + { yyval=yyvsp[-1]; ;} break; case 44: -#line 366 "compile.y" +#line 369 "compile.y" { yyval=N(); YYSTYPE diving_code=yyvsp[0]; - const String* first_name=LA2S(*diving_code); size_t count=diving_code->count(); - // 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... */ - count>=4?4/*OP_VALUE+origin+string+OP_GET_ELEMENTx*/:3/*OP::OP_+origin+string*/); - } + if(maybe_make_self(*yyval, *diving_code, count)) { + // $self. + } else #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT - else if( - count==8 - && append_2ops_opcode(*yyval, *diving_code, OP::OP_GET_OBJECT_ELEMENT, 5/*offset to next [OP_VALUE+]origin+value*/) - ){ - // optimisation for $object.field + ^object.method[ - // OP_VALUE+origin+value+OP_GET_ELEMENT+OP_VALUE+origin+value+OP_GET_ELEMENT => OP_GET_OBJECT_ELEMENT+origin+value+[OP_VALUE]+origin+value+OP_GET_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 - else if( - count==10 - && append_2ops_opcode(*yyval, *diving_code, OP::OP_GET_OBJECT_VAR_ELEMENT, 6/*offset to next [OP_VALUE+]origin+value*/) - ){ - // optimisation for $object.$var - // OP_VALUE+origin+value+OP_GET_ELEMENT+OP_WITH_READ+OP_VALUE+origin+value+OP_GET_ELEMENT+OP_GET_ELEMENT => OP_GET_OBJECT_VAR_ELEMENT+origin+value+[OP_VALUE]+origin+value+OP_GET_ELEMENT - } + if(maybe_make_get_object_var_element(*yyval, *diving_code, count)){ + // optimization for $object.$var + } else #endif - #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT - else if(count==4){ // optimization + 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) + (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 - else { + { O(*yyval, OP::OP_WITH_READ); /* stack: starting context */ // ^if OP_ELEMENT => ^if OP_ELEMENT_OR_OPERATOR @@ -1742,37 +1736,54 @@ yyreduce: break; case 45: -#line 428 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 422 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 47: -#line 429 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 423 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 48: -#line 433 "compile.y" +#line 427 "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 441 "compile.y" +#line 443 "compile.y" { yyval=N(); YYSTYPE 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 { + 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); } @@ -1781,7 +1792,7 @@ yyreduce: break; case 53: -#line 458 "compile.y" +#line 469 "compile.y" { yyval=N(); O(*yyval, OP::OP_WITH_WRITE); /* stack: starting context */ @@ -1790,12 +1801,12 @@ yyreduce: break; case 54: -#line 463 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 474 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 58: -#line 470 "compile.y" +#line 481 "compile.y" { // allow $result_or_other_variable[ letters here any time ] *reinterpret_cast(&yyval)=PC.explicit_result; PC.explicit_result=false; @@ -1803,14 +1814,14 @@ yyreduce: break; case 59: -#line 473 "compile.y" +#line 484 "compile.y" { PC.explicit_result=*reinterpret_cast(&yyvsp[-1]); ;} break; case 60: -#line 475 "compile.y" +#line 486 "compile.y" { // stack: context, name yyval=yyvsp[-2]; // stack: context, name, value @@ -1819,7 +1830,7 @@ yyreduce: break; case 61: -#line 481 "compile.y" +#line 492 "compile.y" { yyval=N(); O(*yyval, OP::OP_PREPARE_TO_EXPRESSION); @@ -1830,7 +1841,7 @@ yyreduce: break; case 62: -#line 489 "compile.y" +#line 500 "compile.y" { // stack: context, name yyval=N(); @@ -1839,7 +1850,7 @@ yyreduce: break; case 66: -#line 500 "compile.y" +#line 511 "compile.y" { yyval=N(); OA(*yyval, OP::OP_OBJECT_POOL, yyvsp[0]); /* stack: empty write context */ @@ -1849,70 +1860,92 @@ yyreduce: break; case 69: -#line 507 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 518 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 70: -#line 511 "compile.y" +#line 522 "compile.y" { #ifdef OPTIMIZE_BYTECODE_CUT_REM_OPERATOR if((*yyvsp[0]).count()) #endif { 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) */ + 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 522 "compile.y" +#line 534 "compile.y" { PC.in_call_value=true; ;} break; case 72: -#line 525 "compile.y" +#line 537 "compile.y" { PC.in_call_value=false; ;} break; case 73: -#line 528 "compile.y" +#line 540 "compile.y" { /* ^field.$method{vasya} */ #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); - if(operator_name && *operator_name == REM_OPERATOR_NAME){ +#else + const String* operator_name=LA2S(*yyvsp[-3], 1); +#endif + if(operator_name && *operator_name==REM_OPERATOR_NAME){ yyval=N(); } else #endif { - yyval=yyvsp[-3]; /* with_xxx,diving code; stack: context,method_junction */ - 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. + if(const String * string=value->get_string()) + if(string->is_empty()) // value is empty string? + 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 551 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 584 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 80: -#line 557 "compile.y" +#line 590 "compile.y" { // allow ^call[ letters here any time ] *reinterpret_cast(&yyval)=PC.explicit_result; PC.explicit_result=false; @@ -1920,51 +1953,51 @@ yyreduce: break; case 81: -#line 560 "compile.y" +#line 593 "compile.y" { PC.explicit_result=*reinterpret_cast(&yyvsp[-1]); ;} break; case 82: -#line 562 "compile.y" - {yyval=yyvsp[-2];} +#line 595 "compile.y" + {yyval=yyvsp[-2];;} break; case 83: -#line 563 "compile.y" - {yyval=yyvsp[-1];} +#line 596 "compile.y" + {yyval=yyvsp[-1];;} break; case 84: -#line 564 "compile.y" - {yyval=yyvsp[-1];} +#line 597 "compile.y" + {yyval=yyvsp[-1];;} break; case 86: -#line 567 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} +#line 600 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); ;} break; case 88: -#line 571 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} +#line 604 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); ;} break; case 90: -#line 575 "compile.y" - { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} +#line 608 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); ;} break; case 91: -#line 577 "compile.y" +#line 610 "compile.y" { yyval=yyvsp[0]; ;} break; case 92: -#line 580 "compile.y" +#line 613 "compile.y" { YYSTYPE expr_code=yyvsp[0]; if(expr_code->count()==3 @@ -1982,7 +2015,7 @@ yyreduce: break; case 93: -#line 594 "compile.y" +#line 627 "compile.y" { yyval=N(); OA(*yyval, OP::OP_CURLY_CODE__STORE_PARAM, yyvsp[0]); @@ -1990,17 +2023,17 @@ yyreduce: break; case 98: -#line 606 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 639 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 100: -#line 608 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 641 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 102: -#line 610 "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 @@ -2012,7 +2045,7 @@ yyreduce: break; case 103: -#line 618 "compile.y" +#line 651 "compile.y" { /* stack: context */ yyval=yyvsp[0]; /* stack: context,name */ @@ -2021,7 +2054,7 @@ yyreduce: break; case 109: -#line 631 "compile.y" +#line 664 "compile.y" { yyval=yyvsp[0]; O(*yyval, OP::OP_GET_ELEMENT); @@ -2029,7 +2062,7 @@ yyreduce: break; case 110: -#line 635 "compile.y" +#line 668 "compile.y" { YYSTYPE code; { @@ -2042,7 +2075,7 @@ yyreduce: break; case 111: -#line 644 "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; @@ -2050,14 +2083,14 @@ yyreduce: break; case 112: -#line 647 "compile.y" +#line 680 "compile.y" { PC.explicit_result=*reinterpret_cast(&yyvsp[-1]); ;} break; case 113: -#line 649 "compile.y" +#line 682 "compile.y" { yyval=N(); OA(*yyval, OP::OP_OBJECT_POOL, yyvsp[-2]); /* stack: empty write context */ @@ -2067,7 +2100,7 @@ yyreduce: break; case 114: -#line 655 "compile.y" +#line 688 "compile.y" { yyval=N(); O(*yyval, OP::OP_WITH_READ); @@ -2076,12 +2109,12 @@ yyreduce: break; case 116: -#line 660 "compile.y" - { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} +#line 693 "compile.y" + { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]); ;} break; case 117: -#line 661 "compile.y" +#line 694 "compile.y" { yyval=yyvsp[0]; O(*yyval, OP::OP_GET_ELEMENT__WRITE); @@ -2089,7 +2122,7 @@ yyreduce: break; case 120: -#line 670 "compile.y" +#line 703 "compile.y" { yyval=yyvsp[-1]; // stack: class name string if(*LA2S(*yyval) == BASE_NAME) { // pseudo BASE class @@ -2100,17 +2133,13 @@ yyreduce: YYERROR; } } -#ifdef OPTIMIZE_BYTECODE_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, true/*assert if top opcode != OP_VALUE*/) -#else - O(*yyval, OP::OP_GET_CLASS); -#endif + maybe_change_first_opcode(*yyval, OP::OP_VALUE, OP::OP_VALUE__GET_CLASS); ;} break; case 121: -#line 687 "compile.y" +#line 716 "compile.y" { yyval=yyvsp[-1]; if(!PC.in_call_value) { @@ -2122,197 +2151,197 @@ yyreduce: break; case 128: -#line 706 "compile.y" - { yyval = yyvsp[-1] ;} +#line 735 "compile.y" + { yyval = yyvsp[-1]; ;} break; case 129: -#line 707 "compile.y" - { yyval = yyvsp[-1] ;} +#line 736 "compile.y" + { yyval = yyvsp[-1]; ;} break; case 130: -#line 708 "compile.y" +#line 737 "compile.y" { yyval = yyvsp[-1]; ;} break; case 131: -#line 710 "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 711 "compile.y" - { yyval=yyvsp[0] ;} +#line 740 "compile.y" + { yyval=yyvsp[0]; ;} break; case 133: -#line 712 "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 713 "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 714 "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 715 "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 716 "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 717 "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 719 "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 720 "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 721 "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 722 "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 723 "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 724 "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 725 "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 726 "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 727 "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 728 "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 729 "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 730 "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 731 "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 732 "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 733 "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 734 "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 735 "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 736 "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 737 "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 738 "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 739 "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 740 "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 741 "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 742 "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 743 "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 744 "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 745 "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 748 "compile.y" +#line 777 "compile.y" { // optimized OP_STRING => OP_VALUE for doubles maybe_change_string_literal_to_double_literal(*(yyval=yyvsp[0])); @@ -2320,7 +2349,7 @@ yyreduce: break; case 167: -#line 753 "compile.y" +#line 782 "compile.y" { #ifdef OPTIMIZE_BYTECODE_STRING_POOL // it brakes ^if(" 09 "){...} @@ -2342,38 +2371,38 @@ yyreduce: break; case 168: -#line 774 "compile.y" +#line 803 "compile.y" { // optimized OP_STRING+OP_WRITE_VALUE => OP_STRING__WRITE - change_string_literal_to_write_string_literal(*(yyval=yyvsp[0])) + change_string_literal_to_write_string_literal(*(yyval=yyvsp[0])); ;} break; case 169: -#line 779 "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(&vempty), 0, 0, 0); ;} break; case 170: -#line 780 "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 781 "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 783 "compile.y" - { yyval=N() ;} +#line 812 "compile.y" + { yyval=N(); ;} break; } /* Line 1010 of yacc.c. */ -#line 2377 "compile.tab.C" +#line 2406 "compile.tab.C" yyvsp -= yylen; yyssp -= yylen; @@ -2598,7 +2627,7 @@ yyreturn: } -#line 785 "compile.y" +#line 814 "compile.y" #endif @@ -3138,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 @@ -3368,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;