|
|
| version 1.40, 2001/11/05 11:46:26 | version 1.54.2.3, 2003/01/31 12:10:46 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: compiler support helper functions. | Parser: compiler support helper functions. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| $Id$ | |
| */ | */ |
| static const char* IDENT_COMPILE_TOOLS_C="$Date$"; | |
| #include "compile_tools.h" | #include "compile_tools.h" |
| #include "pa_string.h" | #include "pa_string.h" |
| #include "pa_array.h" | #include "pa_array.h" |
| Line 14 | Line 14 |
| #include "pa_vstring.h" | #include "pa_vstring.h" |
| #include "pa_vdouble.h" | #include "pa_vdouble.h" |
| void PV(Array/*<Operation>*/ *result, Value *value) { | ValuePtr LA2V(ArrayOperation& literal_string_array, int offset) { |
| // append OP_VALUE | return literal_string_array[offset+0].code==OP_VALUE?literal_string_array[offset+1].value |
| Operation op; op.code=OP_VALUE; | :ValuePtr(0); |
| *result+=op.cast; | } |
| // append 'value' | void change_string_literal_to_double_literal(ArrayOperation& literal_string_array) { |
| *result+=value; | if(literal_string_array[0].code==OP_VALUE) { |
| } | ValuePtr value=literal_string_array[1].value->as_expr_result(); |
| literal_string_array[1].value=value; | |
| void PCA(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array) { | } |
| // append OP_CODE | } |
| Operation op; op.code=OP_CURLY_CODE__STORE_PARAM; | |
| *result+=op.cast; | void change_string_literal_value(ArrayOperation& literal_string_array, StringPtr new_value) { |
| if(literal_string_array[0].code==OP_VALUE) { // extra safety | |
| // append 'vstring' | static_cast<VString&>(*literal_string_array[1].value).set_string(new_value); |
| *result+=code_array; | } |
| } | } |
| void PEA(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array) { | void changetail_or_append(ArrayOperation& opcodes, |
| // append OP_CODE | OPCODE find, bool with_argument, OPCODE replace, OPCODE notfound) { |
| Operation op; op.code=OP_EXPR_CODE__STORE_PARAM; | int tail=opcodes.count()-(with_argument?2:1); |
| *result+=op.cast; | if(tail>=0) { |
| Operation& op=opcodes[tail]; | |
| // append 'vstring' | if(op.code==find) |
| *result+=code_array; | op.code=replace; |
| } | } |
| void CCA(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array) { | |
| // append OP_CODE | |
| Operation op; op.code=OP_CURLY_CODE__CONSTRUCT; | |
| *result+=op.cast; | |
| // append 'vstring' | |
| *result+=code_array; | |
| } | |
| Array *VL(Value *value) { | |
| // empty ops array | |
| Array *result=N(value->pool()); | |
| // append 'value' to 'result' | |
| PV(result, value); | |
| return result; | opcodes+=Operation(notfound); |
| } | } |
| Value *LA2V(Array *literal_string_array, int offset) { | |
| Operation op; | |
| op.cast=literal_string_array->get(offset+0); | |
| if(op.code!=OP_VALUE) | |
| return 0; | |
| return static_cast<Value *>(literal_string_array->get(offset+1)); | |
| } | |
| void change_string_literal_to_double_literal(Array *literal_string_array) { | |
| VString *vstring=static_cast<VString *>(literal_string_array->get(1)); | |
| Value *value=vstring->as_expr_result(); | |
| literal_string_array->put(1, value); | |
| } | |
| void change_string_literal_to_write_string_literal(Array *literal_string_array) { | |
| Operation op; op.code=OP_STRING__WRITE; | |
| literal_string_array->put(0, op.cast); | |
| } | |
| void push_LS(parse_control& pc, lexical_state new_state) { | void push_LS(parse_control& pc, lexical_state new_state) { |
| if(pc.sp<MAX_LEXICAL_STATES) { | if(pc.ls_sp<MAX_LEXICAL_STATES) { |
| pc.stack[pc.sp++]=pc.ls; pc.ls=new_state; | pc.ls_stack[pc.ls_sp++]=pc.ls; |
| pc.ls=new_state; | |
| } else | } else |
| throw Exception(0, 0, 0, "push_LS: stack overflow"); | throw Exception(Exception::undefined_type, Exception::undefined_source, |
| "push_LS: ls_stack overflow"); | |
| } | } |
| void pop_LS(parse_control& pc) { | void pop_LS(parse_control& pc) { |
| if(--pc.sp>=0) | if(--pc.ls_sp>=0) |
| pc.ls=pc.stack[pc.sp]; | pc.ls=pc.ls_stack[pc.ls_sp]; |
| else | else |
| throw Exception(0, 0, 0, "pop_LS: stack underflow"); | throw Exception(Exception::undefined_type, Exception::undefined_source, |
| "pop_LS: ls_stack underflow"); | |
| } | } |