--- parser3/src/main/compile.tab.C 2008/06/24 12:11:26 1.119 +++ parser3/src/main/compile.tab.C 2009/05/19 08:59:51 1.131 @@ -132,7 +132,7 @@ Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.tab.C,v 1.119 2008/06/24 12:11:26 misha Exp $ + $Id: compile.tab.C,v 1.131 2009/05/19 08:59:51 misha Exp $ */ /** @@ -170,7 +170,8 @@ #define USE_CONTROL_METHOD_NAME "USE" #define OPTIONS_CONTROL_METHOD_NAME "OPTIONS" #define OPTION_ALL_VARS_LOCAL_NAME "locals" -#define OPTION_APPEND_METHODS "append" +#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, - 245, 245, 246, 246, 247, 248, 248, 250, 250, 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, + 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, 348, 349, + 349, 350, 352, 353, 354, 410, 411, 411, 415, 420, + 421, 422, 423, 440, 445, 448, 449, 450, 452, 455, + 452, 463, 471, 478, 479, 480, 482, 488, 489, 489, + 493, 504, 507, 504, 531, 533, 533, 535, 536, 537, + 539, 542, 539, 545, 546, 548, 549, 552, 553, 556, + 557, 559, 562, 576, 581, 582, 583, 588, 588, 590, + 590, 591, 592, 600, 605, 608, 609, 610, 611, 613, + 617, 626, 629, 626, 637, 642, 642, 643, 649, 650, + 652, 669, 681, 683, 684, 685, 686, 687, 688, 689, + 690, 692, 693, 694, 695, 696, 697, 698, 699, 701, + 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, + 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, + 722, 723, 724, 725, 726, 727, 730, 735, 756, 761, + 762, 763, 765 }; #endif @@ -1427,7 +1428,7 @@ yyreduce: switch (yyn) { case 2: -#line 131 "compile.y" +#line 132 "compile.y" { Method& method=*new Method(Method::CT_ANY, 0, 0, /*min, max numbered_params_count*/ @@ -1438,7 +1439,7 @@ yyreduce: break; case 9: -#line 146 "compile.y" +#line 147 "compile.y" { const String& command=*LA2S(*yyvsp[-2]); YYSTYPE strings_code=yyvsp[0]; @@ -1456,11 +1457,6 @@ yyreduce: VStateless_class* cclass=new VClass; PC.cclass_new=cclass; PC.cclass_new->set_name(name); - /* - // append to request's classes - PC.request.classes().put(name, cclass); - *PC.cclasses+=cclass; - */ } else { strcpy(PC.error, "@"CLASS_NAME" must contain only one line with class name (contains more then one)"); YYERROR; @@ -1511,22 +1507,28 @@ yyreduce: const String& option=*LA2S(*strings_code, i); if(option==OPTION_ALL_VARS_LOCAL_NAME){ PC.set_all_vars_local(); - } else if(option==OPTION_APPEND_METHODS) { - if(!PC.class_reuse()){ - if(PC.cclass_new){ - strcpy(PC.error, "can't append methods to not existed class '"); - strncat(PC.error, PC.cclass_new->name().cstr(), MAX_STRING/2); - strcat(PC.error, "'"); + } else if(option==OPTION_PARTIAL_CLASS){ + if(PC.cclass_new){ + if(VStateless_class* existed=PC.get_existed_class(PC.cclass_new)){ + if(!PC.reuse_existed_class(existed)){ + strcpy(PC.error, "can't append methods to '"); + strncat(PC.error, PC.cclass_new->name().cstr(), MAX_STRING/2); + strcat(PC.error, "' - the class wasn't marked as partial"); + YYERROR; + } } else { - strcpy(PC.error, "'"OPTION_APPEND_METHODS"' option should be used straight after @"CLASS_NAME); + // mark new class as partial. we can add methods to it later. + PC.cclass_new->set_partial(); } + } else { + strcpy(PC.error, "'"OPTION_PARTIAL_CLASS"' option should be used straight after @"CLASS_NAME); YYERROR; } } else { strcpy(PC.error, "'"); strncat(PC.error, option.cstr(), MAX_STRING/2); strcat(PC.error, "' invalid option. valid options are " - "'"OPTION_APPEND_METHODS"' and '"OPTION_ALL_VARS_LOCAL_NAME"'"); + "'"OPTION_PARTIAL_CLASS"' and '"OPTION_ALL_VARS_LOCAL_NAME"'"); YYERROR; } } @@ -1541,14 +1543,13 @@ yyreduce: break; case 13: -#line 246 "compile.y" +#line 248 "compile.y" { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} break; case 17: -#line 250 "compile.y" +#line 252 "compile.y" { - PC.class_add(); PC.explicit_result=false; @@ -1575,9 +1576,8 @@ yyreduce: *locals_names+=local_name; } } - if(!all_vars_local && PC.cclass && PC.cclass->is_vars_local()){ + if(!all_vars_local && PC.cclass && PC.cclass->is_vars_local()) all_vars_local=true; - } Method* method=new Method( //name, @@ -1595,89 +1595,146 @@ yyreduce: case 18: #line 292 "compile.y" { - Method& method=*reinterpret_cast(yyvsp[-1]); - // fill in the code - method.parser_code=yyvsp[0]; - // register in class - const String& name=*LA2S(*yyvsp[-6]); - PC.cclass->add_method(PC.alias_method(name), method); + Method& method=*reinterpret_cast(yyvsp[-1]); + // fill in the code + method.parser_code=yyvsp[0]; + + // register in class + const String& name=*LA2S(*yyvsp[-6]); + PC.cclass->add_method(PC.alias_method(name), method); ;} break; case 21: -#line 302 "compile.y" +#line 303 "compile.y" {yyval=yyvsp[-1];} break; case 25: -#line 304 "compile.y" +#line 305 "compile.y" { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} break; case 31: -#line 312 "compile.y" +#line 313 "compile.y" { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} break; case 37: -#line 318 "compile.y" +#line 319 "compile.y" { - yyval=yyvsp[0]; /* stack: resulting value */ - changetail_or_append(*yyval, - OP_GET_ELEMENT, false, /*->*/OP_GET_ELEMENT__WRITE, - /*or */OP_WRITE_VALUE - ); /* value=pop; wcontext.write(value) */ + yyval=N(); + YYSTYPE code=yyvsp[0]; +#ifdef OPTIMIZE_BYTECODE_GET_ELEMENT + if(!replace_top_opcode(*code, OP::OP_VALUE__GET_ELEMENT, /*=>*/OP::OP_VALUE__GET_ELEMENT__WRITE)) +#endif + { +#ifdef OPTIMIZE_BYTECODE_GET_ELEMENT_FIELD + size_t count=code->count(); + if( +#ifdef OPTIMIZE_BYTECODE_USE_TWO_OPERANDS_INSTRUCTIONS + count==6 +#else + count==7 +#endif + && (*code)[count-1].code==OP::OP_GET_ELEMENT + && replace_top_opcode(*code, OP::OP_GET_ELEMENT_FIELD, /*=>*/OP::OP_GET_ELEMENT_FIELD__WRITE) + ){ + //P(*$$, *code, 0/*offset*/, count-1/*limit*/); // someday skip last OP_GET_ELEMENT + //break; + } else +#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" +#line 348 "compile.y" { yyval=yyvsp[0] ;} break; case 41: -#line 327 "compile.y" +#line 350 "compile.y" { yyval=yyvsp[-1] ;} break; case 44: -#line 331 "compile.y" +#line 354 "compile.y" { yyval=N(); - ArrayOperation* diving_code=yyvsp[0]; + YYSTYPE diving_code=yyvsp[0]; const String* first_name=LA2S(*diving_code); - // self.xxx... -> xxx... + // self.xxx... => xxx... // OP_VALUE+origin+string+OP_GET_ELEMENT+... -> OP_WITH_SELF+... if(first_name && *first_name==SELF_ELEMENT_NAME) { - O(*yyval, OP_WITH_SELF); /* stack: starting context */ + O(*yyval, OP::OP_WITH_SELF); /* stack: starting context */ P(*yyval, *diving_code, /* skip over... */ - diving_code->count()>=4?4/*OP_VALUE+origin+string+OP_GET_ELEMENTx*/:3/*OP_+origin+string*/); + diving_code->count()>=4?4/*OP::OP_VALUE+origin+string+OP::OP_GET_ELEMENTx*/:3/*OP::OP_+origin+string*/); } else { - O(*yyval, OP_WITH_READ); /* stack: starting context */ +#ifdef OPTIMIZE_BYTECODE_GET_ELEMENT + size_t count=diving_code->count(); + if(count==4){ // optimization + O(*yyval, + (PC.in_call_value) + ? 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 + } +#ifdef OPTIMIZE_BYTECODE_GET_ELEMENT_FIELD + else if( + count==8 + && (*diving_code)[7].code==OP::OP_GET_ELEMENT + && replace_top_opcode(*diving_code, OP::OP_VALUE, /*=>*/OP::OP_GET_ELEMENT_FIELD) + ){ + // optimisation for ^object.method[ + $object.field + // OP_VALUE+origin+value+OP_GET_ELEMENT+OP_VALUE+origin+value+OP_GET_ELEMENT => OP_GET_ELEMENT_FIELD+origin+value+OP_VALUE+origin+value+OP_GET_ELEMENT + // OP_VALUE+origin+value+OP_GET_ELEMENT+OP_VALUE+origin+value+OP_GET_ELEMENT + // offset 0 1 2 3 4 5 6 7 + P(*yyval, *diving_code, 0/*offset*/, 3/*limit*/); // copy OP_GET_ELEMENT_FIELD+origin+value (skip first OP_GET_ELEMENT) +#ifdef OPTIMIZE_BYTECODE_USE_TWO_OPERANDS_INSTRUCTIONS + P(*yyval, *diving_code, 5/*offset*/, 3/*limit*/); // copy origin+value+OP_GET_ELEMENT (last one is important!) +#else + P(*yyval, *diving_code, 4/*offset*/, 4/*limit*/); // copy OP_VALUE+origin+value+OP_GET_ELEMENT (last one is important!) +#endif + } +#endif + 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 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 && diving_code->count()==4) - diving_code->put(4-1, OP_GET_ELEMENT_OR_OPERATOR); + diving_code->put(4-1, OP::OP_GET_ELEMENT_OR_OPERATOR); P(*yyval, *diving_code); +#endif } /* diving code; stack: current context */ ;} break; case 45: -#line 353 "compile.y" +#line 410 "compile.y" { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} break; case 47: -#line 354 "compile.y" +#line 411 "compile.y" { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} break; case 48: -#line 358 "compile.y" +#line 415 "compile.y" { yyval=yyvsp[-1]; /* stack: context,name */ P(*yyval, *yyvsp[0]); /* stack: context,name,constructor_value */ @@ -1685,20 +1742,20 @@ yyreduce: break; case 52: -#line 366 "compile.y" +#line 423 "compile.y" { yyval=N(); - ArrayOperation* diving_code=yyvsp[0]; + 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+... + // $self.xxx... => $xxx... + // OP_VALUE+origin+string+OP_GET_ELEMENT+... => OP_WITH_SELF+... if(first_name && *first_name==SELF_ELEMENT_NAME) { - O(*yyval, OP_WITH_SELF); /* stack: starting context */ + O(*yyval, OP::OP_WITH_SELF); /* stack: starting context */ P(*yyval, *diving_code, /* skip over... */ - diving_code->count()>=4?4/*OP_VALUE+origin+string+OP_GET_ELEMENTx*/:3/*OP_+origin+string*/); + diving_code->count()>=4?4/*OP::OP_VALUE+origin+string+OP::OP_GET_ELEMENTx*/:3/*OP::OP_+origin+string*/); } else { - O(*yyval, OP_WITH_ROOT); /* stack: starting context */ + O(*yyval, OP::OP_WITH_ROOT); /* stack: starting context */ P(*yyval, *diving_code); } /* diving code; stack: current context */ @@ -1706,21 +1763,21 @@ yyreduce: break; case 53: -#line 383 "compile.y" +#line 440 "compile.y" { yyval=N(); - O(*yyval, OP_WITH_WRITE); /* stack: starting context */ + O(*yyval, OP::OP_WITH_WRITE); /* stack: starting context */ P(*yyval, *yyvsp[0]); /* diving code; stack: context,name */ ;} break; case 54: -#line 388 "compile.y" +#line 445 "compile.y" { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} break; case 58: -#line 395 "compile.y" +#line 452 "compile.y" { // allow $result_or_other_variable[ letters here any time ] *reinterpret_cast(&yyval)=PC.explicit_result; PC.explicit_result=false; @@ -1728,103 +1785,116 @@ yyreduce: break; case 59: -#line 398 "compile.y" +#line 455 "compile.y" { PC.explicit_result=*reinterpret_cast(&yyvsp[-1]); ;} break; case 60: -#line 400 "compile.y" +#line 457 "compile.y" { // stack: context, name yyval=yyvsp[-2]; // stack: context, name, value - O(*yyval, OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */ + O(*yyval, OP::OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */ ;} break; case 61: -#line 406 "compile.y" +#line 463 "compile.y" { yyval=N(); - O(*yyval, OP_PREPARE_TO_EXPRESSION); + O(*yyval, OP::OP_PREPARE_TO_EXPRESSION); // stack: context, name P(*yyval, *yyvsp[-1]); // stack: context, name, value - O(*yyval, OP_CONSTRUCT_EXPR); /* value=pop->as_expr_result; name=pop; context=pop; construct(context,name,value) */ + O(*yyval, OP::OP_CONSTRUCT_EXPR); /* value=pop->as_expr_result; name=pop; context=pop; construct(context,name,value) */ ;} break; case 62: -#line 414 "compile.y" +#line 471 "compile.y" { // stack: context, name yyval=N(); - OA(*yyval, OP_CURLY_CODE__CONSTRUCT, yyvsp[-1]); /* code=pop; name=pop; context=pop; construct(context,name,junction(code)) */ + OA(*yyval, OP::OP_CURLY_CODE__CONSTRUCT, yyvsp[-1]); /* code=pop; name=pop; context=pop; construct(context,name,junction(code)) */ ;} break; case 66: -#line 425 "compile.y" +#line 482 "compile.y" { yyval=N(); - OA(*yyval, OP_OBJECT_POOL, yyvsp[0]); /* stack: empty write context */ + OA(*yyval, OP::OP_OBJECT_POOL, yyvsp[0]); /* stack: empty write context */ /* some code that writes to that context */ /* context=pop; stack: context.value() */ ;} break; case 69: -#line 432 "compile.y" +#line 489 "compile.y" { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} break; case 70: -#line 436 "compile.y" +#line 493 "compile.y" { - yyval=yyvsp[0]; /* stack: value */ - changetail_or_append(*yyval, - OP_CALL, true, /*->*/ OP_CALL__WRITE, - /*or */OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */ +#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) */ + } ;} break; case 71: -#line 442 "compile.y" +#line 504 "compile.y" { PC.in_call_value=true; ;} break; case 72: -#line 445 "compile.y" +#line 507 "compile.y" { PC.in_call_value=false; ;} break; case 73: -#line 448 "compile.y" +#line 510 "compile.y" { /* ^field.$method{vasya} */ - yyval=yyvsp[-3]; /* with_xxx,diving code; stack: context,method_junction */ +#ifdef OPTIMIZE_BYTECODE_CUT_REM_OPERATOR + const String* operator_name=LA2S(*yyvsp[-3], 0, OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR); + 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()==4) { // probably [] case. [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_CALL, params_code); // method_frame=make frame(pop junction); ncontext=pop; call(ncontext,method_frame) stack: value + 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 */ + 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" +#line 533 "compile.y" { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} break; case 80: -#line 469 "compile.y" +#line 539 "compile.y" { // allow ^call[ letters here any time ] *reinterpret_cast(&yyval)=PC.explicit_result; PC.explicit_result=false; @@ -1832,131 +1902,129 @@ yyreduce: break; case 81: -#line 472 "compile.y" +#line 542 "compile.y" { PC.explicit_result=*reinterpret_cast(&yyvsp[-1]); ;} break; case 82: -#line 474 "compile.y" +#line 544 "compile.y" {yyval=yyvsp[-2];} break; case 83: -#line 475 "compile.y" +#line 545 "compile.y" {yyval=yyvsp[-1];} break; case 84: -#line 476 "compile.y" +#line 546 "compile.y" {yyval=yyvsp[-1];} break; case 86: -#line 479 "compile.y" +#line 549 "compile.y" { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} break; case 88: -#line 483 "compile.y" +#line 553 "compile.y" { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} break; case 90: -#line 487 "compile.y" +#line 557 "compile.y" { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]) ;} break; case 91: -#line 489 "compile.y" +#line 559 "compile.y" { yyval=yyvsp[0]; - O(*yyval, OP_STORE_PARAM); ;} break; case 92: -#line 493 "compile.y" +#line 562 "compile.y" { YYSTYPE expr_code=yyvsp[0]; if(expr_code->count()==3 - && (*expr_code)[0].code==OP_VALUE) { // optimizing (double/bool/incidently 'string' too) case. [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_STORE_PARAM); // no evaluating } else { - ArrayOperation* code=N(); - O(*code, OP_PREPARE_TO_EXPRESSION); + YYSTYPE code=N(); + O(*code, OP::OP_PREPARE_TO_EXPRESSION); P(*code, *expr_code); - O(*code, OP_WRITE_EXPR_RESULT); + O(*code, OP::OP_WRITE_EXPR_RESULT); yyval=N(); - OA(*yyval, OP_EXPR_CODE__STORE_PARAM, code); + OA(*yyval, OP::OP_EXPR_CODE__STORE_PARAM, code); } ;} break; case 93: -#line 508 "compile.y" +#line 576 "compile.y" { yyval=N(); - OA(*yyval, OP_CURLY_CODE__STORE_PARAM, yyvsp[0]); + OA(*yyval, OP::OP_CURLY_CODE__STORE_PARAM, yyvsp[0]); ;} break; case 98: -#line 520 "compile.y" +#line 588 "compile.y" { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} break; case 100: -#line 522 "compile.y" +#line 590 "compile.y" { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} break; case 102: -#line 524 "compile.y" +#line 592 "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 /* stack: context */ yyval=yyvsp[0]; /* stack: context,name */ - O(*yyval, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */ + O(*yyval, OP::OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */ ;} break; case 103: -#line 532 "compile.y" +#line 600 "compile.y" { /* stack: context */ yyval=yyvsp[0]; /* stack: context,name */ - O(*yyval, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */ + O(*yyval, OP::OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */ ;} break; case 109: -#line 545 "compile.y" +#line 613 "compile.y" { yyval=yyvsp[0]; - O(*yyval, OP_GET_ELEMENT); + O(*yyval, OP::OP_GET_ELEMENT); ;} break; case 110: -#line 549 "compile.y" +#line 617 "compile.y" { - ArrayOperation* code; + YYSTYPE code; { change_string_literal_to_write_string_literal(*(code=yyvsp[-1])); P(*code, *yyvsp[0]); } yyval=N(); - OA(*yyval, OP_STRING_POOL, code); + OA(*yyval, OP::OP_STRING_POOL, code); ;} break; case 111: -#line 558 "compile.y" +#line 626 "compile.y" { // allow $result_or_other_variable[ letters here any time ] *reinterpret_cast(&yyval)=PC.explicit_result; PC.explicit_result=false; @@ -1964,46 +2032,46 @@ yyreduce: break; case 112: -#line 561 "compile.y" +#line 629 "compile.y" { PC.explicit_result=*reinterpret_cast(&yyvsp[-1]); ;} break; case 113: -#line 563 "compile.y" +#line 631 "compile.y" { yyval=N(); - OA(*yyval, OP_OBJECT_POOL, yyvsp[-2]); /* stack: empty write context */ + OA(*yyval, OP::OP_OBJECT_POOL, yyvsp[-2]); /* stack: empty write context */ /* some code that writes to that context */ /* context=pop; stack: context.value() */ ;} break; case 114: -#line 569 "compile.y" +#line 637 "compile.y" { yyval=N(); - O(*yyval, OP_WITH_READ); + O(*yyval, OP::OP_WITH_READ); P(*yyval, *yyvsp[0]); ;} break; case 116: -#line 574 "compile.y" +#line 642 "compile.y" { yyval=yyvsp[-1]; P(*yyval, *yyvsp[0]) ;} break; case 117: -#line 575 "compile.y" +#line 643 "compile.y" { yyval=yyvsp[0]; - O(*yyval, OP_GET_ELEMENT__WRITE); + O(*yyval, OP::OP_GET_ELEMENT__WRITE); ;} break; case 120: -#line 584 "compile.y" +#line 652 "compile.y" { yyval=yyvsp[-1]; // stack: class name string if(*LA2S(*yyval) == BASE_NAME) { // pseudo BASE class @@ -2014,255 +2082,272 @@ yyreduce: YYERROR; } } - O(*yyval, OP_GET_CLASS); +#ifdef OPTIMIZE_BYTECODE_GET_CLASS + // optimized OP_VALUE+origin+string+OP_GET_CLASS => OP_VALUE__GET_CLASS+origin+string + replace_top_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 ;} break; case 121: -#line 596 "compile.y" +#line 669 "compile.y" { yyval=yyvsp[-1]; if(!PC.in_call_value) { strcpy(PC.error, ":: not allowed here"); YYERROR; } - O(*yyval, OP_PREPARE_TO_CONSTRUCT_OBJECT); + O(*yyval, OP::OP_PREPARE_TO_CONSTRUCT_OBJECT); ;} break; case 128: -#line 615 "compile.y" +#line 688 "compile.y" { yyval = yyvsp[-1] ;} break; case 129: -#line 616 "compile.y" +#line 689 "compile.y" { yyval = yyvsp[-1] ;} break; case 130: -#line 617 "compile.y" +#line 690 "compile.y" { yyval = yyvsp[-1]; ;} break; case 131: -#line 619 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP_NEG) ;} +#line 692 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_NEG) ;} break; case 132: -#line 620 "compile.y" +#line 693 "compile.y" { yyval=yyvsp[0] ;} break; case 133: -#line 621 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP_INV) ;} +#line 694 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_INV) ;} break; case 134: -#line 622 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP_NOT) ;} +#line 695 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_NOT) ;} break; case 135: -#line 623 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP_DEF) ;} +#line 696 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_DEF) ;} break; case 136: -#line 624 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP_IN) ;} +#line 697 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_IN) ;} break; case 137: -#line 625 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP_FEXISTS) ;} +#line 698 "compile.y" + { yyval=yyvsp[0]; O(*yyval, OP::OP_FEXISTS) ;} break; case 138: -#line 626 "compile.y" - { yyval=yyvsp[0]; O(*yyval, OP_DEXISTS) ;} +#line 699 "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_SUB) ;} +#line 701 "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_ADD) ;} +#line 702 "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_MUL) ;} +#line 703 "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_DIV) ;} +#line 704 "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_MOD) ;} +#line 705 "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_INTDIV) ;} +#line 706 "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_BIN_SL) ;} +#line 707 "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_BIN_SR) ;} +#line 708 "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_BIN_AND) ;} +#line 709 "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_BIN_OR) ;} +#line 710 "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_BIN_XOR) ;} +#line 711 "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_NESTED_CODE, yyvsp[0]); O(*yyval, OP_LOG_AND) ;} +#line 712 "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_NESTED_CODE, yyvsp[0]); O(*yyval, OP_LOG_OR) ;} +#line 713 "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_LOG_XOR) ;} +#line 714 "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_NUM_LT) ;} +#line 715 "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_NUM_GT) ;} +#line 716 "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_NUM_LE) ;} +#line 717 "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_NUM_GE) ;} +#line 718 "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_NUM_EQ) ;} +#line 719 "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_NUM_NE) ;} +#line 720 "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_STR_LT) ;} +#line 721 "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_STR_GT) ;} +#line 722 "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_STR_LE) ;} +#line 723 "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_STR_GE) ;} +#line 724 "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_STR_EQ) ;} +#line 725 "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_STR_NE) ;} +#line 726 "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_IS) ;} +#line 727 "compile.y" + { yyval=yyvsp[-2]; P(*yyval, *yyvsp[0]); O(*yyval, OP::OP_IS) ;} break; case 166: -#line 657 "compile.y" +#line 730 "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 735 "compile.y" { +#ifdef OPTIMIZE_BYTECODE_STRING_POOL + // it brakes ^if(" 09 "){...} + YYSTYPE code=yyvsp[0]; yyval=N(); - OA(*yyval, OP_STRING_POOL, yyvsp[0]); /* stack: empty write context */ + if(code->count()==3 && replace_top_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 756 "compile.y" { - // optimized from OP_STRING+OP_WRITE_VALUE to OP_STRING__WRITE + // 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" +#line 761 "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" +#line 762 "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" +#line 763 "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" +#line 765 "compile.y" { yyval=N() ;} break; @@ -2270,7 +2355,7 @@ yyreduce: } /* Line 1010 of yacc.c. */ -#line 2274 "compile.tab.C" +#line 2359 "compile.tab.C" yyvsp -= yylen; yyssp -= yylen; @@ -2495,7 +2580,7 @@ yyreturn: } -#line 682 "compile.y" +#line 767 "compile.y" #endif @@ -2588,7 +2673,7 @@ case LS_DEF_COMMENT: default: switch(*pc.source) { // ^escaping some punctuators - case '^': case '$': case ';': + case '^': case '$': case ';': case '@': case '(': case ')': case '[': case ']': case '{': case '}': @@ -2616,7 +2701,7 @@ default: pc.string.append_strdup_know_length(begin, end-begin); } // #HH ? - if(pc.source[0]=='#' && pc.source[1] && pc.source[2]) { + if(pc.source[1] && isxdigit(pc.source[1]) && pc.source[2] && isxdigit(pc.source[2])) { char c=(char)( hex_value[(unsigned char)pc.source[1]]*0x10+ hex_value[(unsigned char)pc.source[2]]); @@ -2635,7 +2720,14 @@ default: // skip analysis = forced literal continue; } - break; + // just escaped char + // reset piece 'begin' position & line + begin=pc.source; + begin_pos=pc.pos; + // skip over _ after ^ + pc.source++; pc.pos.col++; + // skip analysis = forced literal + continue; } break; }