--- parser3/src/main/compile.y 2009/05/20 13:22:59 1.241 +++ parser3/src/main/compile.y 2009/06/02 10:08:40 1.244 @@ -5,7 +5,7 @@ Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.y,v 1.241 2009/05/20 13:22:59 misha Exp $ + $Id: compile.y,v 1.244 2009/06/02 10:08:40 misha Exp $ */ /** @@ -322,35 +322,27 @@ get: get_value { #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT if(!maybe_change_first_opcode(*code, OP::OP_VALUE__GET_ELEMENT, /*=>*/OP::OP_VALUE__GET_ELEMENT__WRITE)) #endif - { - size_t count=code->count(); - size_t len=6; #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( + code->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( + code->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(*$$, *code); }; get_value: '$' get_name_value { $$=$2 }; @@ -373,21 +365,18 @@ name_without_curly_rdive_read: name_with count>=4?4/*OP_VALUE+origin+string+OP_GET_ELEMENTx*/:3/*OP::OP_+origin+string*/); } - #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT else if(maybe_make_get_object_element(*$$, *diving_code, count)){ // optimisation for $object.field + ^object.method[ } #endif - #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT else if(maybe_make_get_object_var_element(*$$, *diving_code, count)){ // optimisation for $object.$var } #endif - #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT else if(count==4){ // optimization O(*$$, @@ -421,8 +410,8 @@ name_without_curly_rdive_code: name_adva put: '$' name_expr_wdive construct { $$=N(); #ifdef OPTIMIZE_BYTECODE_CONSTRUCT - if(maybe_make_root_or_write_construct(*$$, *$2, *$3)){ - // $a(1) or $.b(2) or $c[d] or $.e[f] + if(maybe_optimize_construct(*$$, *$2, *$3)){ + // $a(expr), $.a(expr), $a[value], $.a[value] } else #endif { @@ -458,7 +447,7 @@ name_expr_wdive_write: '.' name_expr_div }; name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P(*$$, *$2) }; -construct: +construct: construct_square | construct_round | construct_curly @@ -523,7 +512,11 @@ call_value: '^' { } store_params EON { /* ^field.$method{vasya} */ #ifdef OPTIMIZE_BYTECODE_CUT_REM_OPERATOR +#ifdef OPTIMIZE_BYTECODE_GET_ELEMENT const String* operator_name=LA2S(*$3, 0, OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR); +#else + const String* operator_name=LA2S(*$3, 1); +#endif if(operator_name && *operator_name == REM_OPERATOR_NAME){ $$=N(); } else