Annotation of parser3/src/main/compile_tools.C, revision 1.48

1.29      paf         1: /** @file
1.30      paf         2:        Parser: compiler support helper functions.
                      3: 
1.44      paf         4:        Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.45      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.30      paf         6: 
1.48    ! paf         7:        $Id: compile_tools.C,v 1.47 2002/04/15 06:45:58 paf Exp $
1.1       paf         8: */
                      9: 
                     10: #include "compile_tools.h"
                     11: #include "pa_string.h"
                     12: #include "pa_array.h"
                     13: #include "pa_exception.h"
1.9       paf        14: #include "pa_vstring.h"
1.15      paf        15: #include "pa_vdouble.h"
1.1       paf        16: 
1.27      paf        17: void PV(Array/*<Operation>*/ *result, Value *value) {
1.16      paf        18:        // append OP_VALUE
                     19:        Operation op; op.code=OP_VALUE;
1.6       paf        20:        *result+=op.cast;
1.1       paf        21: 
1.17      paf        22:        // append 'value'
                     23:        *result+=value;
1.12      paf        24: }
1.13      paf        25: 
1.27      paf        26: void PCA(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array) {
1.13      paf        27:        // append OP_CODE
1.28      paf        28:        Operation op; op.code=OP_CURLY_CODE__STORE_PARAM;
1.13      paf        29:        *result+=op.cast;
                     30: 
                     31:        // append 'vstring'
                     32:        *result+=code_array;
                     33: }
                     34: 
1.28      paf        35: void PEA(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array) {
                     36:        // append OP_CODE
                     37:        Operation op; op.code=OP_EXPR_CODE__STORE_PARAM;
1.37      parser     38:        *result+=op.cast;
                     39: 
                     40:        // append 'vstring'
                     41:        *result+=code_array;
                     42: }
                     43: 
                     44: void CCA(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array) {
                     45:        // append OP_CODE
                     46:        Operation op; op.code=OP_CURLY_CODE__CONSTRUCT;
1.28      paf        47:        *result+=op.cast;
                     48: 
                     49:        // append 'vstring'
                     50:        *result+=code_array;
                     51: }
1.41      paf        52: 
                     53: void PNC(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array) {
                     54:        // append OP_CODE
                     55:        Operation op; op.code=OP_NESTED_CODE;
                     56:        *result+=op.cast;
                     57: 
                     58:        // append 'vstring'
                     59:        *result+=code_array;
                     60: }
1.47      paf        61: 
                     62: void PJP(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array) {
                     63:        // append OP_CODE
                     64:        Operation op; op.code=OP_OBJECT_POOL;
                     65:        *result+=op.cast;
                     66: 
                     67:        // append 'vstring'
                     68:        *result+=code_array;
                     69: }
                     70: 
                     71: void PSP(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array) {
                     72:        // append OP_CODE
                     73:        Operation op; op.code=OP_STRING_POOL;
                     74:        *result+=op.cast;
                     75: 
                     76:        // append 'vstring'
                     77:        *result+=code_array;
                     78: }
                     79: 
1.41      paf        80: 
1.12      paf        81: 
1.17      paf        82: Array *VL(Value *value) {
1.12      paf        83:        // empty ops array
1.17      paf        84:        Array *result=N(value->pool());
1.12      paf        85: 
1.17      paf        86:        // append 'value' to 'result'
                     87:        PV(result, value);
1.14      paf        88: 
                     89:        return result;
                     90: }
1.1       paf        91: 
1.33      paf        92: Value *LA2V(Array *literal_string_array, int offset) {
1.11      paf        93:        Operation op;
                     94:        op.cast=literal_string_array->get(offset+0);
1.43      paf        95:        return op.code==OP_VALUE?
                     96:                static_cast<Value *>(literal_string_array->get(offset+1))
                     97:                :0;
1.15      paf        98: }
                     99: 
                    100: void change_string_literal_to_double_literal(Array *literal_string_array) {
                    101:        VString *vstring=static_cast<VString *>(literal_string_array->get(1));
1.32      paf       102:        Value *value=vstring->as_expr_result();
1.22      paf       103:        literal_string_array->put(1, value);
1.1       paf       104: }
1.24      paf       105: void change_string_literal_to_write_string_literal(Array *literal_string_array) {
                    106:        Operation op; op.code=OP_STRING__WRITE;
                    107:        literal_string_array->put(0, op.cast);
                    108: }
1.48    ! paf       109: void changetail_or_append(Array *opcodes, OPCODE find, OPCODE replace, OPCODE notfound) {
        !           110:        if(int tail=opcodes->size()) {
        !           111:                --tail;
        !           112:                Operation op;
        !           113:                op.cast=opcodes->get(tail);
        !           114:                if(op.code==find) {
        !           115:                        op.code=replace;
        !           116:                        opcodes->put(tail, op.cast);
        !           117:                        return;
        !           118:                }
        !           119:        }
        !           120: 
        !           121:        Operation op; op.code=notfound;
        !           122:        *opcodes+=op.cast;
        !           123: }
        !           124: 
1.1       paf       125: 
1.31      paf       126: void push_LS(parse_control& pc, lexical_state new_state) { 
1.42      paf       127:        if(pc.ls_sp<MAX_LEXICAL_STATES) {
                    128:                pc.ls_stack[pc.ls_sp++]=pc.ls;  
                    129:                pc.ls=new_state;
1.1       paf       130:        } else
1.46      paf       131:                throw Exception(0, 0, "push_LS: ls_stack overflow");
1.1       paf       132: }
1.31      paf       133: void pop_LS(parse_control& pc) {
1.42      paf       134:        if(--pc.ls_sp>=0)
                    135:                pc.ls=pc.ls_stack[pc.ls_sp];
1.1       paf       136:        else
1.46      paf       137:                throw Exception(0, 0, "pop_LS: ls_stack underflow");
1.1       paf       138: }

E-mail: