--- parser3/src/main/compile_tools.C 2008/08/15 15:26:14 1.60 +++ parser3/src/main/compile_tools.C 2009/05/23 05:23:03 1.65 @@ -1,11 +1,11 @@ /** @file 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 (http://paf.design.ru) */ -static const char * const IDENT_COMPILE_TOOLS_C="$Date: 2008/08/15 15:26:14 $"; +static const char * const IDENT_COMPILE_TOOLS_C="$Date: 2009/05/23 05:23:03 $"; #include "compile_tools.h" #include "pa_string.h" @@ -14,8 +14,8 @@ static const char * const IDENT_COMPILE_ #include "pa_vstring.h" #include "pa_vdouble.h" -Value* LA2V(ArrayOperation& literal_string_array, int offset) { - return literal_string_array[offset+0].code==OP::OP_VALUE?literal_string_array[offset+2/*skip opcode&origin*/].value +Value* LA2V(ArrayOperation& literal_string_array, int offset, OP::OPCODE code) { + return literal_string_array[offset+0].code==code?literal_string_array[offset+2/*skip opcode&origin*/].value :0; } @@ -46,6 +46,27 @@ 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; +} + + void push_LS(Parse_control& pc, lexical_state new_state) { if(pc.ls_sp