|
|
| version 1.61, 2009/05/19 08:41:45 | version 1.63, 2009/05/20 09:08:53 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: compiler support helper functions. | Parser: compiler support helper functions. |
| Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| Line 46 void changetail_or_append(ArrayOperation | Line 46 void changetail_or_append(ArrayOperation |
| } | } |
| bool maybe_change_first_opcode(ArrayOperation& opcodes, OP::OPCODE find, OP::OPCODE replace, bool strict) { | |
| if(opcodes[0].code==find){ | |
| opcodes.put(0, replace); | |
| return true; | |
| } | |
| if(strict) | |
| assert(opcodes[0].code==find); | |
| return false; | |
| } | |
| bool maybe_change_first_opcode(ArrayOperation& opcodes, OP::OPCODE find, OP::OPCODE last, OP::OPCODE replace) { | |
| if(opcodes[0].code==find && opcodes[opcodes.count()-1].code==last){ | |
| opcodes.put(0, replace); | |
| return true; | |
| } | |
| return false; | |
| } | |
| // 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 | |
| bool maybe_make_get_object_element(ArrayOperation& opcodes, ArrayOperation& diving_code, size_t divine_count){ | |
| if(divine_count!=8) | |
| return false; | |
| assert(diving_code[0].code==OP::OP_VALUE); | |
| if( | |
| diving_code[4].code==OP::OP_VALUE | |
| && diving_code[divine_count-1].code==OP::OP_GET_ELEMENT | |
| ){ | |
| O(opcodes, OP::OP_GET_OBJECT_ELEMENT); | |
| P(opcodes, diving_code, 1/*offset*/, 2/*limit*/); // copy origin+value | |
| P(opcodes, diving_code, | |
| #ifdef OPTIMIZE_BYTECODE_USE_TWO_OPERANDS_INSTRUCTIONS | |
| 5, 3 | |
| #else | |
| 4, 4 | |
| #endif | |
| ); // copy specified tail | |
| return true; | |
| } | |
| return false; | |
| } | |
| // 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 | |
| bool maybe_make_get_object_var_element(ArrayOperation& opcodes, ArrayOperation& diving_code, size_t divine_count){ | |
| if(divine_count!=10) | |
| return false; | |
| assert(diving_code[0].code==OP::OP_VALUE); | |
| if( | |
| diving_code[4].code==OP::OP_WITH_READ | |
| && diving_code[5].code==OP::OP_VALUE | |
| && diving_code[divine_count-1].code==OP::OP_GET_ELEMENT | |
| ){ | |
| O(opcodes, OP::OP_GET_OBJECT_VAR_ELEMENT); | |
| P(opcodes, diving_code, 1/*offset*/, 2/*limit*/); // copy origin+value | |
| P(opcodes, diving_code, | |
| #ifdef OPTIMIZE_BYTECODE_USE_TWO_OPERANDS_INSTRUCTIONS | |
| 6, 3 | |
| #else | |
| 5, 4 | |
| #endif | |
| ); // copy specified tail | |
| return true; | |
| } | |
| return false; | |
| } | |
| void push_LS(Parse_control& pc, lexical_state new_state) { | void push_LS(Parse_control& pc, lexical_state new_state) { |
| if(pc.ls_sp<MAX_LEXICAL_STATES) { | if(pc.ls_sp<MAX_LEXICAL_STATES) { |
| pc.ls_stack[pc.ls_sp++]=pc.ls; | pc.ls_stack[pc.ls_sp++]=pc.ls; |