Annotation of parser3/src/main/execute.C, revision 1.427

1.117     paf         1: /** @file
1.118     paf         2:        Parser: executor part of request class.
                      3: 
1.425     moko        4:        Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com)
1.414     moko        5:        Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.243     paf         6: */
1.118     paf         7: 
1.152     paf         8: #include "pa_opcode.h"
1.8       paf         9: #include "pa_array.h" 
1.11      paf        10: #include "pa_request.h"
1.15      paf        11: #include "pa_vstring.h"
1.22      paf        12: #include "pa_vhash.h"
1.167     parser     13: #include "pa_vvoid.h"
1.145     paf        14: #include "pa_vcode_frame.h"
1.321     misha      15: #include "pa_vmethod_frame.h"
1.38      paf        16: #include "pa_vobject.h"
1.49      paf        17: #include "pa_vdouble.h"
1.54      paf        18: #include "pa_vbool.h"
1.94      paf        19: #include "pa_vtable.h"
1.132     paf        20: #include "pa_vfile.h"
1.144     paf        21: #include "pa_vimage.h"
1.421     moko       22: #include "pa_varray.h"
1.194     parser     23: #include "pa_wwrapper.h"
1.1       paf        24: 
1.427   ! moko       25: volatile const char * IDENT_EXECUTE_C="$Id: execute.C,v 1.426 2024/12/23 16:59:17 moko Exp $" IDENT_PA_OPCODE_H IDENT_PA_OPERATION_H IDENT_PA_VCODE_FRAME_H IDENT_PA_WWRAPPER_H;
1.368     moko       26: 
1.233     paf        27: //#define DEBUG_EXECUTE
1.157     parser     28: 
                     29: #ifdef DEBUG_EXECUTE
1.387     moko       30: const char *opcode_name[]={
1.49      paf        31:        // literals
1.109     paf        32:        "VALUE",  "CURLY_CODE__STORE_PARAM",  "EXPR_CODE__STORE_PARAM",
1.209     paf        33:        "NESTED_CODE",
1.49      paf        34: 
                     35:        // actions
1.187     parser     36:        "WITH_ROOT",    "WITH_SELF",    "WITH_READ",    "WITH_WRITE",
1.387     moko       37:        "VALUE__GET_CLASS", "VALUE__GET_BASE_CLASS",
1.421     moko       38:        "CONSTRUCT_VALUE", "CONSTRUCT_EXPR", "CURLY_CODE__CONSTRUCT", "CONSTRUCT_ARRAY",
1.108     paf        39:        "WRITE_VALUE",  "WRITE_EXPR_RESULT",  "STRING__WRITE",
1.328     misha      40: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT
                     41:        "VALUE__GET_ELEMENT_OR_OPERATOR",
                     42: #else
                     43:        "GET_ELEMENT_OR_OPERATOR",
                     44: #endif
                     45:        "GET_ELEMENT",
1.346     misha      46:        "GET_ELEMENT__WRITE",
                     47: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT
                     48:        "VALUE__GET_ELEMENT",
                     49:        "VALUE__GET_ELEMENT__WRITE",
1.347     misha      50:        "WITH_ROOT__VALUE__GET_ELEMENT",
1.346     misha      51: #endif
1.335     misha      52: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT
                     53:        "GET_OBJECT_ELEMENT",
                     54:        "GET_OBJECT_ELEMENT__WRITE",
                     55: #endif
                     56: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT
                     57:        "GET_OBJECT_VAR_ELEMENT",
                     58:        "GET_OBJECT_VAR_ELEMENT__WRITE",
1.334     misha      59: #endif
1.345     misha      60: #ifdef OPTIMIZE_BYTECODE_GET_SELF_ELEMENT
                     61:        "WITH_SELF__VALUE__GET_ELEMENT",
                     62:        "WITH_SELF__VALUE__GET_ELEMENT__WRITE",
                     63: #endif
1.376     moko       64: 
                     65: #ifdef FEATURE_GET_ELEMENT4CALL
                     66:        "GET_ELEMENT4CALL",
                     67: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT
                     68:        "GET_OBJECT_ELEMENT4CALL",
                     69: #endif
                     70: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT
                     71:        "GET_OBJECT_VAR_ELEMENT4CALL",
                     72: #endif
                     73: #endif // FEATURE_GET_ELEMENT4CALL
                     74: 
1.232     paf        75:        "OBJECT_POOL",  "STRING_POOL",
1.348     misha      76:        "PREPARE_TO_CONSTRUCT_OBJECT",
                     77:        "CONSTRUCT_OBJECT",
                     78:        "CONSTRUCT_OBJECT__WRITE",
1.232     paf        79:        "CALL", "CALL__WRITE",
1.49      paf        80: 
1.337     misha      81: #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
1.344     misha      82:        "WITH_ROOT__VALUE__CONSTRUCT_EXPR",
                     83:        "WITH_ROOT__VALUE__CONSTRUCT_VALUE",
                     84:        "WITH_WRITE__VALUE__CONSTRUCT_EXPR",
                     85:        "WITH_WRITE__VALUE__CONSTRUCT_VALUE",
1.345     misha      86:        "WITH_SELF__VALUE__CONSTRUCT_EXPR",
                     87:        "WITH_SELF__VALUE__CONSTRUCT_VALUE",
1.337     misha      88: #endif
                     89: 
1.372     misha      90: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL
                     91:        "GET_ELEMENT__SPECIAL",
                     92:        "GET_ELEMENT__SPECIAL__WRITE",
                     93: #endif
1.49      paf        94:        // expression ops: unary
1.148     paf        95:        "NEG", "INV", "NOT", "DEF", "IN", "FEXISTS", "DEXISTS",
1.49      paf        96:        // expression ops: binary
1.201     paf        97:        "SUB", "ADD", "MUL", "DIV", "MOD", "INTDIV",
1.275     paf        98:        "BIN_SL", "BIN_SR",
1.56      paf        99:        "BIN_AND", "BIN_OR", "BIN_XOR",
                    100:        "LOG_AND", "LOG_OR", "LOG_XOR",
1.49      paf       101:        "NUM_LT", "NUM_GT", "NUM_LE", "NUM_GE", "NUM_EQ", "NUM_NE",
1.103     paf       102:        "STR_LT", "STR_GT", "STR_LE", "STR_GE", "STR_EQ", "STR_NE",
                    103:        "IS"
1.1       paf       104: };
                    105: 
1.342     misha     106: const char* debug_value_to_cstr(Value& value){
                    107:        const String* string=value.get_string();
                    108: 
                    109:        if(string)
                    110:                return string->cstr();
                    111:        else
                    112:                if(value.is_bool())
1.386     moko      113:                        return value.as_bool() ? "<true>" : "<false>";
1.342     misha     114:                else
                    115:                        return "<value>";
                    116: }
                    117: 
1.297     paf       118: void va_debug_printf(SAPI_Info& sapi_info, const char* fmt,va_list args) {
1.127     paf       119:        char buf[MAX_STRING];
                    120:        vsnprintf(buf, MAX_STRING, fmt, args);
1.297     paf       121:        SAPI::log(sapi_info, "%s", buf);
1.107     paf       122: }
                    123: 
1.297     paf       124: void debug_printf(SAPI_Info& sapi_info, const char* fmt, ...) {
1.334     misha     125:        va_list args;
                    126:        va_start(args, fmt);
                    127:        va_debug_printf(sapi_info, fmt, args);
                    128:        va_end(args);
1.105     paf       129: }
                    130: 
1.297     paf       131: void debug_dump(SAPI_Info& sapi_info, int level, ArrayOperation& ops) {
1.419     moko      132:        for(Array_iterator<Operation> i(ops); i;) {
1.323     misha     133:                OP::OPCODE opcode=i.next().code;
1.1       paf       134: 
1.337     misha     135: #if defined(OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT) || defined(OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT)
1.334     misha     136:                if(
1.335     misha     137:                        1==0
                    138: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT
                    139:                        || opcode==OP::OP_GET_OBJECT_ELEMENT
                    140:                        || opcode==OP::OP_GET_OBJECT_ELEMENT__WRITE
1.376     moko      141: #ifdef FEATURE_GET_ELEMENT4CALL
                    142:                        || opcode==OP::OP_GET_OBJECT_ELEMENT4CALL
                    143: #endif
1.335     misha     144: #endif
                    145: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT
                    146:                        || opcode==OP::OP_GET_OBJECT_VAR_ELEMENT
                    147:                        || opcode==OP::OP_GET_OBJECT_VAR_ELEMENT__WRITE
1.376     moko      148: #ifdef FEATURE_GET_ELEMENT4CALL
                    149:                        || opcode==OP::OP_GET_OBJECT_VAR_ELEMENT4CALL
                    150: #endif
1.335     misha     151: #endif
1.334     misha     152:                ){
                    153:                        i.next(); // skip origin
                    154:                        Value& value1=*i.next().value;
                    155:                        i.next(); // skip origin
                    156:                        Value& value2=*i.next().value;
1.386     moko      157:                        debug_printf(sapi_info, "%*s%s \"%s\" \"%s\"", level*4, "", opcode_name[opcode], debug_value_to_cstr(value1), debug_value_to_cstr(value2));
1.334     misha     158:                        continue;
                    159:                }
                    160: #endif
1.348     misha     161:                if(
                    162:                        opcode==OP::OP_CONSTRUCT_OBJECT
                    163:                        || opcode==OP::OP_CONSTRUCT_OBJECT__WRITE
                    164:                ){
                    165:                        i.next(); // skip origin
                    166:                        Value& value1=*i.next().value;
                    167:                        i.next(); // skip origin
                    168:                        Value& value2=*i.next().value;
                    169:                        debug_printf(sapi_info, 
                    170:                                "%*s%s"
                    171:                                " \"%s\" \"%s\"", 
                    172:                                level*4, "", opcode_name[opcode],
                    173:                                debug_value_to_cstr(value1), debug_value_to_cstr(value2));
                    174: 
                    175:                        if(ArrayOperation* local_ops=i.next().ops)
                    176:                                debug_dump(sapi_info, level+1, *local_ops);
                    177:                        continue;
                    178:                }
1.328     misha     179:                if(
                    180:                        opcode==OP::OP_VALUE
                    181:                        || opcode==OP::OP_STRING__WRITE
                    182:                        || opcode==OP::OP_VALUE__GET_CLASS
1.383     moko      183:                        || opcode==OP::OP_VALUE__GET_BASE_CLASS
1.328     misha     184: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT
                    185:                        || opcode==OP::OP_VALUE__GET_ELEMENT
                    186:                        || opcode==OP::OP_VALUE__GET_ELEMENT__WRITE
                    187:                        || opcode==OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR
1.347     misha     188:                        || opcode==OP::OP_WITH_ROOT__VALUE__GET_ELEMENT
1.328     misha     189: #endif
1.345     misha     190: #ifdef OPTIMIZE_BYTECODE_GET_SELF_ELEMENT
                    191:                        || opcode==OP::OP_WITH_SELF__VALUE__GET_ELEMENT
                    192:                        || opcode==OP::OP_WITH_SELF__VALUE__GET_ELEMENT__WRITE
                    193: #endif
1.342     misha     194: #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
1.344     misha     195:                        || opcode==OP::OP_WITH_ROOT__VALUE__CONSTRUCT_EXPR
                    196:                        || opcode==OP::OP_WITH_ROOT__VALUE__CONSTRUCT_VALUE
                    197:                        || opcode==OP::OP_WITH_WRITE__VALUE__CONSTRUCT_EXPR
                    198:                        || opcode==OP::OP_WITH_WRITE__VALUE__CONSTRUCT_VALUE
1.345     misha     199:                        || opcode==OP::OP_WITH_SELF__VALUE__CONSTRUCT_EXPR
                    200:                        || opcode==OP::OP_WITH_SELF__VALUE__CONSTRUCT_VALUE
1.342     misha     201: #endif
1.328     misha     202:                ) {
1.297     paf       203:                        Operation::Origin origin=i.next().origin;
                    204:                        Value& value=*i.next().value;
1.342     misha     205: 
1.297     paf       206:                        debug_printf(sapi_info, 
1.133     paf       207:                                "%*s%s"
                    208:                                " \"%s\" %s", 
1.297     paf       209:                                level*4, "", opcode_name[opcode],
1.342     misha     210:                                debug_value_to_cstr(value), value.type());
1.133     paf       211:                        continue;
1.15      paf       212:                }
1.348     misha     213: 
1.297     paf       214:                debug_printf(sapi_info, "%*s%s", level*4, "", opcode_name[opcode]);
1.1       paf       215: 
1.297     paf       216:                switch(opcode) {
1.323     misha     217:                case OP::OP_CURLY_CODE__STORE_PARAM: 
                    218:                case OP::OP_EXPR_CODE__STORE_PARAM:
                    219:                case OP::OP_CURLY_CODE__CONSTRUCT:
                    220:                case OP::OP_NESTED_CODE:
1.346     misha     221:                case OP::OP_OBJECT_POOL:
1.323     misha     222:                case OP::OP_STRING_POOL:
1.421     moko      223:                case OP::OP_CONSTRUCT_ARRAY:
1.323     misha     224:                case OP::OP_CALL:
                    225:                case OP::OP_CALL__WRITE:
1.297     paf       226:                        if(ArrayOperation* local_ops=i.next().ops)
                    227:                                debug_dump(sapi_info, level+1, *local_ops);
1.1       paf       228:                }
                    229:        }
                    230: }
1.336     misha     231: #define DEBUG_PRINT_STR(str) debug_printf(sapi_info, str);
                    232: #define DEBUG_PRINT_STRING(value) debug_printf(sapi_info, " \"%s\" ", value.cstr());
1.342     misha     233: #define DEBUG_PRINT_VALUE_AND_TYPE(value) debug_printf(sapi_info, " \"%s\" %s", debug_value_to_cstr(value), value.type());
1.336     misha     234: #define DEBUG_PRINT_OPS(local_ops) \
                    235:                                        debug_printf(sapi_info, \
                    236:                                        " (%d)\n", local_ops?local_ops->count():0); \
                    237:                                        if(local_ops) debug_dump(sapi_info, 1, *local_ops);
                    238: 
                    239: #else
                    240: #define DEBUG_PRINT_STR(str)
                    241: #define DEBUG_PRINT_STRING(value)
1.342     misha     242: #define DEBUG_PRINT_VALUE_AND_TYPE(value)
1.336     misha     243: #define DEBUG_PRINT_OPS(local_ops)
1.157     parser    244: #endif
1.1       paf       245: 
1.297     paf       246: // Request
                    247: 
                    248: void Request::execute(ArrayOperation& ops) {
1.418     moko      249:        Stack<StackItem>& stack=this->stack; // helps a lot on MSVC: 'esi'
1.159     parser    250: 
1.304     paf       251:        const String* debug_name=0;  Operation::Origin debug_origin={0, 0, 0};
1.297     paf       252:        try{
1.157     parser    253: #ifdef DEBUG_EXECUTE
1.297     paf       254:        debug_printf(sapi_info, "source----------------------------\n");
                    255:        debug_dump(sapi_info, 0, ops);
                    256:        debug_printf(sapi_info, "execution-------------------------\n");
1.157     parser    257: #endif
1.419     moko      258:        for(Array_iterator<Operation> i(ops); i; ) {
1.322     misha     259:                OP::OPCODE opcode=i.next().code;
1.293     paf       260: 
1.157     parser    261: #ifdef DEBUG_EXECUTE
1.297     paf       262:                debug_printf(sapi_info, "%d:%s", stack.top_index()+1, opcode_name[opcode]);
1.157     parser    263: #endif
1.11      paf       264: 
1.297     paf       265:                switch(opcode) {
1.51      paf       266:                // param in next instruction
1.322     misha     267:                case OP::OP_VALUE:
1.32      paf       268:                        {
1.297     paf       269:                                debug_origin=i.next().origin;
                    270:                                Value& value=*i.next().value;
1.342     misha     271: 
                    272:                                DEBUG_PRINT_VALUE_AND_TYPE(value)
                    273: 
1.297     paf       274:                                stack.push(value);
1.32      paf       275:                                break;
                    276:                        }
1.328     misha     277:                case OP::OP_VALUE__GET_CLASS:
                    278:                        {
1.383     moko      279:                                debug_origin=i.next().origin;
                    280:                                const String& name=*i.next().value->get_string(); debug_name=&name;
                    281: 
                    282:                                DEBUG_PRINT_STRING(name)
                    283: 
1.413     moko      284:                                stack.push(get_class_ref(name));
1.383     moko      285:                                break;
                    286:                        }
                    287: 
                    288:                case OP::OP_VALUE__GET_BASE_CLASS:
                    289:                        {
                    290:                                // ^class:method[] call
1.328     misha     291: 
                    292:                                debug_origin=i.next().origin;
1.372     misha     293:                                const String& name=*i.next().value->get_string(); debug_name=&name;
1.328     misha     294: 
1.336     misha     295:                                DEBUG_PRINT_STRING(name)
1.328     misha     296: 
1.413     moko      297:                                stack.push(*new VBaseClassWrapper(get_class_ref(name), get_self()));
1.328     misha     298:                                break;
                    299:                        }
1.372     misha     300: 
                    301: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL
                    302:                case OP::OP_GET_ELEMENT__SPECIAL:
                    303:                case OP::OP_GET_ELEMENT__SPECIAL__WRITE:
                    304:                        {
                    305:                                const String& name=stack.pop().string();  debug_name=&name;
                    306:                                Value& ncontext=stack.pop().value();
                    307: 
                    308:                                Value* value=0;
                    309:                                if(VStateless_class* vclass=ncontext.get_class()){
1.382     moko      310:                                        if(SYMBOLS_EQ(name,CLASS_SYMBOL)){
1.372     misha     311:                                                value=vclass;
1.382     moko      312:                                        } else if(SYMBOLS_EQ(name,CLASS_NAME_SYMBOL)){
1.379     moko      313:                                                value=new VString(*new String(vclass->type()));
1.372     misha     314:                                        }
                    315:                                } else {
1.381     moko      316:                                        // VJunction is without class, returning self
1.382     moko      317:                                        if(SYMBOLS_EQ(name,CLASS_SYMBOL)){
1.381     moko      318:                                                value=&ncontext;
1.382     moko      319:                                        } else if(SYMBOLS_EQ(name,CLASS_NAME_SYMBOL)){
1.381     moko      320:                                                value=new VString(*new String(ncontext.type()));
                    321:                                        }
1.380     moko      322:                                }
1.372     misha     323:                                if(opcode==OP::OP_GET_ELEMENT__SPECIAL){
                    324:                                        stack.push(*value);
                    325:                                } else {
1.396     moko      326:                                        write(*value);
1.372     misha     327:                                }
                    328:                                break;
                    329:                        }
                    330: #endif
                    331: 
1.51      paf       332:                // OP_WITH
1.322     misha     333:                case OP::OP_WITH_ROOT:
1.187     parser    334:                        {
1.297     paf       335:                                stack.push(*method_frame);
1.187     parser    336:                                break;
                    337:                        }
1.336     misha     338:                case OP::OP_WITH_SELF:
1.37      paf       339:                        {
1.297     paf       340:                                stack.push(get_self());
1.37      paf       341:                                break;
                    342:                        }
1.336     misha     343:                case OP::OP_WITH_READ:
1.15      paf       344:                        {
1.297     paf       345:                                stack.push(*rcontext);
1.20      paf       346:                                break;
                    347:                        }
1.336     misha     348:                case OP::OP_WITH_WRITE:
1.20      paf       349:                        {
1.287     paf       350:                                if(wcontext==method_frame)
1.384     moko      351:                                        throw Exception(PARSER_RUNTIME, 0, "$.name outside of $name[...]");
1.287     paf       352: 
1.297     paf       353:                                stack.push(*wcontext);
1.20      paf       354:                                break;
                    355:                        }
1.37      paf       356:                        
1.51      paf       357:                // OTHER ACTIONS BUT WITHs
1.337     misha     358: 
                    359: #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
1.392     moko      360: #define DO_CONSTRUCT(context, vvalue) {                                                                 \
1.347     misha     361:                                debug_origin=i.next().origin;                                           \
                    362:                                const String& name=*i.next().value->get_string();  debug_name=&name;    \
                    363:                                DEBUG_PRINT_STRING(name)                                                \
                    364:                                Value& value=stack.pop().value();                                       \
                    365:                                put_element( context, name, vvalue );                                   \
1.403     moko      366:                                goto check_skip;                                                        \
1.347     misha     367:                }
                    368: #define DO_CONSTRUCT_VALUE(context) DO_CONSTRUCT(context, &value)
1.392     moko      369: #define DO_CONSTRUCT_EXPR(context) {                                                                    \
1.347     misha     370:                                DO_CONSTRUCT(context, &value.as_expr_result())                          \
                    371:                }
                    372: 
1.344     misha     373:                case OP::OP_WITH_WRITE__VALUE__CONSTRUCT_EXPR:
1.347     misha     374:                        {
                    375:                                if(wcontext==method_frame)
                    376:                                        throw Exception(PARSER_RUNTIME, 0, "$.name outside of $name[...]");
                    377:                                DO_CONSTRUCT_EXPR(*wcontext)
                    378:                        }
                    379: 
1.344     misha     380:                case OP::OP_WITH_WRITE__VALUE__CONSTRUCT_VALUE:
1.338     misha     381:                        {
                    382:                                if(wcontext==method_frame)
1.347     misha     383:                                        throw Exception(PARSER_RUNTIME, 0, "$.name outside of $name[...]");
                    384:                                DO_CONSTRUCT_VALUE(*wcontext)
1.338     misha     385:                        }
1.345     misha     386: 
1.347     misha     387:                case OP::OP_WITH_ROOT__VALUE__CONSTRUCT_EXPR:   DO_CONSTRUCT_EXPR(*method_frame)
1.337     misha     388: 
1.347     misha     389:                case OP::OP_WITH_ROOT__VALUE__CONSTRUCT_VALUE:  DO_CONSTRUCT_VALUE(*method_frame)
1.337     misha     390: 
1.347     misha     391:                case OP::OP_WITH_SELF__VALUE__CONSTRUCT_EXPR:   DO_CONSTRUCT_EXPR(get_self())
1.342     misha     392: 
1.347     misha     393:                case OP::OP_WITH_SELF__VALUE__CONSTRUCT_VALUE:  DO_CONSTRUCT_VALUE(get_self())
1.345     misha     394: 
1.340     misha     395: #endif // OPTIMIZE_BYTECODE_CONSTRUCT
1.337     misha     396: 
1.344     misha     397:                case OP::OP_CONSTRUCT_VALUE:
1.337     misha     398:                        {
1.344     misha     399: #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
                    400:                                const String& name=stack.pop().string();  debug_name=&name;
                    401:                                Value& ncontext=stack.pop().value();
                    402:                                Value& value=stack.pop().value();
                    403: #else
                    404:                                Value& value=stack.pop().value();
                    405:                                const String& name=stack.pop().string();  debug_name=&name;
                    406:                                Value& ncontext=stack.pop().value();
                    407: #endif
                    408:                                put_element(ncontext, name, &value);
1.403     moko      409:                                goto check_skip;
1.337     misha     410:                        }
                    411: 
1.322     misha     412:                case OP::OP_CONSTRUCT_EXPR:
1.80      paf       413:                        {
1.344     misha     414: #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
                    415:                                const String& name=stack.pop().string();  debug_name=&name;
                    416:                                Value& ncontext=stack.pop().value();
                    417:                                Value& expr=stack.pop().value();
                    418: #else
1.308     paf       419:                                Value& expr=stack.pop().value();
1.297     paf       420:                                const String& name=stack.pop().string();  debug_name=&name;
                    421:                                Value& ncontext=stack.pop().value();
1.344     misha     422: #endif
1.308     paf       423:                                Value& value=expr.as_expr_result();
1.329     misha     424:                                put_element(ncontext, name, &value);
1.403     moko      425:                                goto check_skip;
1.80      paf       426:                        }
1.337     misha     427: 
1.322     misha     428:                case OP::OP_CURLY_CODE__CONSTRUCT:
1.182     parser    429:                        {
1.297     paf       430:                                ArrayOperation& local_ops=*i.next().ops;
1.336     misha     431: 
                    432:                                DEBUG_PRINT_OPS((&local_ops))
                    433: 
1.326     misha     434:                                VJunction& value=*new VJunction(
1.297     paf       435:                                        get_self(), 0,
1.257     paf       436:                                        method_frame, 
1.240     paf       437:                                        rcontext, 
                    438:                                        wcontext, 
1.312     paf       439:                                        &local_ops);
1.238     paf       440: 
1.326     misha     441:                                wcontext->attach_junction(&value);
                    442: 
1.297     paf       443:                                const String& name=stack.pop().string();  debug_name=&name;
                    444:                                Value& ncontext=stack.pop().value();
1.426     moko      445:                                if(ncontext.put_element(name, &value))
1.422     moko      446:                                                throw Exception(PARSER_RUNTIME, 0, "property value cannot be code, use [] or () brackets");
1.403     moko      447: 
1.182     parser    448:                                break;
                    449:                        }
1.421     moko      450: 
                    451:                case OP::OP_CONSTRUCT_ARRAY:
                    452:                        {
                    453:                                ArrayOperation* local_ops=i.next().ops;
                    454: 
                    455:                                DEBUG_PRINT_OPS(local_ops)
                    456:                                DEBUG_PRINT_STR("->\n")
                    457: 
                    458:                                size_t first = stack.top_index();
                    459:                                execute(*local_ops);
                    460:                                Value *value=new VArray(stack.top_index()-first, (Value**)stack.ptr(first));
                    461:                                stack.set_top_index(first);
                    462: 
                    463: #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
                    464:                                const String& name=stack.pop().string();  debug_name=&name;
                    465:                                Value& ncontext=stack.pop().value();
                    466: #else
                    467:                                const String& name=stack.pop().string();  debug_name=&name;
                    468:                                Value& ncontext=stack.pop().value();
                    469: #endif
                    470:                                put_element(ncontext, name, value);
                    471: 
                    472:                                DEBUG_PRINT_STR("<-returned")
                    473:                                goto check_skip;
                    474:                        }
                    475: 
1.322     misha     476:                case OP::OP_NESTED_CODE:
1.209     paf       477:                        {
1.297     paf       478:                                ArrayOperation& local_ops=*i.next().ops;
1.336     misha     479: 
                    480:                                DEBUG_PRINT_OPS((&local_ops))
                    481: 
1.297     paf       482:                                stack.push(local_ops);
1.209     paf       483:                                break;
                    484:                        }
1.322     misha     485:                case OP::OP_WRITE_VALUE:
1.13      paf       486:                        {
1.297     paf       487:                                Value& value=stack.pop().value();
1.396     moko      488:                                write(value);
1.86      paf       489:                                break;
                    490:                        }
1.322     misha     491:                case OP::OP_WRITE_EXPR_RESULT:
1.108     paf       492:                        {
1.351     misha     493:                                Value& value=stack.pop().value();
                    494:                                wcontext->write(value.as_expr_result());
1.108     paf       495:                                break;
                    496:                        }
1.322     misha     497:                case OP::OP_STRING__WRITE:
1.86      paf       498:                        {
1.297     paf       499:                                i.next(); // ignore origin
                    500:                                Value* value=i.next().value;
1.336     misha     501: 
                    502:                                const String& string_value=*value->get_string();
                    503: 
                    504:                                DEBUG_PRINT_STRING(string_value)
                    505: 
1.396     moko      506:                                write(string_value);
1.13      paf       507:                                break;
1.14      paf       508:                        }
1.328     misha     509: 
                    510: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT
                    511:                case OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR:
                    512:                        {
                    513:                                debug_origin=i.next().origin;
                    514:                                const String& name=*i.next().value->get_string();  debug_name=&name;
                    515: 
1.336     misha     516:                                DEBUG_PRINT_STRING(name)
                    517: 
1.330     misha     518:                                if(Method* method=main_class.get_method(name)){ // looking operator of that name FIRST
1.427   ! moko      519:                                        stack.push(*method->get_vjunction(main_class));
1.330     misha     520:                                        break;
                    521:                                }
                    522:                                Value& value=get_element(*rcontext, name);
1.328     misha     523:                                stack.push(value);
1.403     moko      524:                                goto check_skip;
1.328     misha     525:                        }
                    526: #else
1.322     misha     527:                case OP::OP_GET_ELEMENT_OR_OPERATOR:
1.215     paf       528:                        {
1.297     paf       529:                                const String& name=stack.pop().string();  debug_name=&name;
                    530:                                Value& ncontext=stack.pop().value();
1.330     misha     531:                                if(Method* method=main_class.get_method(name)){ // looking operator of that name FIRST
1.427   ! moko      532:                                        stack.push(*method->get_vjunction(main_class));
1.330     misha     533:                                        break;
                    534:                                }
                    535:                                Value& value=get_element(ncontext, name);
1.297     paf       536:                                stack.push(value);
1.403     moko      537:                                goto check_skip;
1.215     paf       538:                        }
1.328     misha     539: #endif
                    540: 
1.335     misha     541: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT
1.336     misha     542: 
1.376     moko      543: #define DO_GET_OBJECT_ELEMENT(code) {\
                    544:                                debug_origin=i.next().origin;                                                           \
                    545:                                const String& context_name=*i.next().value->get_string();  debug_name=&context_name;    \
                    546:                                DEBUG_PRINT_STRING(context_name)                                                        \
                    547:                                Value& object=get_element(*rcontext, context_name);                                     \
                    548:                                debug_origin=i.next().origin;                                                           \
                    549:                                const String& field_name=*i.next().value->get_string();  debug_name=&field_name;        \
                    550:                                DEBUG_PRINT_STRING(field_name)                                                          \
                    551:                                code;                                                                                   \
1.403     moko      552:                                goto check_skip;                                                                        \
1.376     moko      553:                        }
1.336     misha     554: 
1.376     moko      555:                case OP::OP_GET_OBJECT_ELEMENT: DO_GET_OBJECT_ELEMENT({
                    556:                                Value& value=get_element(object, field_name);
                    557:                                stack.push(value);
                    558:                        })
                    559:                case OP::OP_GET_OBJECT_ELEMENT__WRITE: DO_GET_OBJECT_ELEMENT({
1.334     misha     560:                                Value& value=get_element(object, field_name);
1.396     moko      561:                                write(value);
1.376     moko      562:                        })
                    563: #ifdef FEATURE_GET_ELEMENT4CALL
                    564:                case OP::OP_GET_OBJECT_ELEMENT4CALL: DO_GET_OBJECT_ELEMENT({
                    565:                                Value& value=get_element4call(object, field_name);
                    566:                                stack.push(value);
                    567:                        })
                    568: #endif
1.335     misha     569: #endif
                    570: 
                    571: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT
1.336     misha     572: 
1.376     moko      573: #define DO_GET_OBJECT_VAR_ELEMENT(code) {\
                    574:                                debug_origin=i.next().origin;                                                           \
                    575:                                const String& context_name=*i.next().value->get_string();  debug_name=&context_name;    \
                    576:                                DEBUG_PRINT_STRING(context_name)                                                        \
                    577:                                Value& object=get_element(*rcontext, context_name);                                     \
                    578:                                debug_origin=i.next().origin;                                                           \
                    579:                                const String& var_name=*i.next().value->get_string();  debug_name=&var_name;            \
                    580:                                DEBUG_PRINT_STRING(var_name)                                                            \
                    581:                                const String* field=&get_element(*rcontext, var_name).as_string();                      \
                    582:                                code;                                                                                   \
1.403     moko      583:                                goto check_skip;                                                                        \
1.376     moko      584:                        }
1.335     misha     585: 
1.376     moko      586:                case OP::OP_GET_OBJECT_VAR_ELEMENT: DO_GET_OBJECT_VAR_ELEMENT({
                    587:                                Value& value=get_element(object, *field);
                    588:                                stack.push(value);
                    589:                        })
                    590:                case OP::OP_GET_OBJECT_VAR_ELEMENT__WRITE: DO_GET_OBJECT_VAR_ELEMENT({
1.335     misha     591:                                Value& value=get_element(object, *field);
1.396     moko      592:                                write(value);
1.376     moko      593:                        })
                    594: #ifdef FEATURE_GET_ELEMENT4CALL
                    595:                case OP::OP_GET_OBJECT_VAR_ELEMENT4CALL: DO_GET_OBJECT_VAR_ELEMENT({
                    596:                                Value& value=get_element4call(object, *field);
                    597:                                stack.push(value);
                    598:                        })
                    599: #endif
                    600: #endif
1.335     misha     601: 
1.376     moko      602:                case OP::OP_GET_ELEMENT:
                    603:                        {
                    604:                                const String& name=stack.pop().string();  debug_name=&name;
                    605:                                Value& ncontext=stack.pop().value();
                    606:                                Value& value=get_element(ncontext, name);
                    607:                                stack.push(value);
1.403     moko      608:                                goto check_skip;
1.334     misha     609:                        }
                    610: 
1.376     moko      611: #ifdef FEATURE_GET_ELEMENT4CALL
                    612:                case OP::OP_GET_ELEMENT4CALL:
1.11      paf       613:                        {
1.297     paf       614:                                const String& name=stack.pop().string();  debug_name=&name;
                    615:                                Value& ncontext=stack.pop().value();
1.376     moko      616:                                Value& value=get_element4call(ncontext, name);
1.297     paf       617:                                stack.push(value);
1.403     moko      618:                                goto check_skip;
1.17      paf       619:                        }
1.376     moko      620: #endif
1.17      paf       621: 
1.346     misha     622:                case OP::OP_GET_ELEMENT__WRITE:
                    623:                        {
                    624:                                const String& name=stack.pop().string();  debug_name=&name;
                    625:                                Value& ncontext=stack.pop().value();
                    626:                                Value& value=get_element(ncontext, name);
1.396     moko      627:                                write(value);
1.403     moko      628:                                goto check_skip;
1.346     misha     629:                        }
                    630: 
1.328     misha     631: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT
                    632:                case OP::OP_VALUE__GET_ELEMENT:
                    633:                        {
                    634:                                debug_origin=i.next().origin;
                    635:                                const String& name=*i.next().value->get_string(); debug_name=&name;
                    636: 
1.336     misha     637:                                DEBUG_PRINT_STRING(name)
1.328     misha     638: 
1.330     misha     639:                                Value& value=get_element(*rcontext, name);
1.328     misha     640:                                stack.push(value);
1.403     moko      641:                                goto check_skip;
1.328     misha     642:                        }
                    643: 
                    644:                case OP::OP_VALUE__GET_ELEMENT__WRITE:
                    645:                        {
                    646:                                debug_origin=i.next().origin;
                    647:                                const String& name=*i.next().value->get_string(); debug_name=&name;
                    648: 
1.336     misha     649:                                DEBUG_PRINT_STRING(name)
1.328     misha     650: 
1.330     misha     651:                                Value& value=get_element(*rcontext, name);
1.396     moko      652:                                write(value);
1.403     moko      653:                                goto check_skip;
1.328     misha     654:                        }
1.347     misha     655: 
                    656:                case OP::OP_WITH_ROOT__VALUE__GET_ELEMENT:
                    657:                        {
                    658:                                debug_origin=i.next().origin;
                    659:                                const String& name=*i.next().value->get_string(); debug_name=&name;
                    660: 
                    661:                                DEBUG_PRINT_STRING(name)
                    662: 
                    663:                                Value& value=get_element(*method_frame, name);
                    664:                                stack.push(value);
1.403     moko      665:                                goto check_skip;
1.347     misha     666:                        }
1.328     misha     667: #endif
1.32      paf       668: 
1.345     misha     669: #ifdef OPTIMIZE_BYTECODE_GET_SELF_ELEMENT
                    670:                case OP::OP_WITH_SELF__VALUE__GET_ELEMENT:
                    671:                case OP::OP_WITH_SELF__VALUE__GET_ELEMENT__WRITE:
                    672:                        {
                    673:                                debug_origin=i.next().origin;
                    674:                                const String& name=*i.next().value->get_string(); debug_name=&name;
                    675: 
                    676:                                DEBUG_PRINT_STRING(name)
                    677: 
                    678:                                Value& value=get_element(get_self(), name);
                    679: 
                    680:                                if(opcode==OP::OP_WITH_SELF__VALUE__GET_ELEMENT){
                    681:                                        stack.push(value);
                    682:                                } else {
1.396     moko      683:                                        write(value);
1.345     misha     684:                                }
1.403     moko      685:                                goto check_skip;
1.345     misha     686:                        }
                    687: #endif
                    688: 
1.322     misha     689:                case OP::OP_OBJECT_POOL:
1.17      paf       690:                        {
1.406     moko      691:                                debug_name=0;
                    692: 
1.297     paf       693:                                ArrayOperation& local_ops=*i.next().ops;
1.226     paf       694:                                
1.257     paf       695:                                WContext *saved_wcontext=wcontext;
1.348     misha     696: #ifdef OPTIMIZE_SINGLE_STRING_WRITE
1.351     misha     697:                                WObjectPoolWrapper local(wcontext);
1.348     misha     698: #else
1.351     misha     699:                                WWrapper local(wcontext);
1.348     misha     700: #endif
1.226     paf       701:                                wcontext=&local;
                    702: 
1.297     paf       703:                                execute(local_ops);
1.226     paf       704: 
1.400     moko      705:                                stack.push((Value&)wcontext->result());
1.403     moko      706: 
1.257     paf       707:                                wcontext=saved_wcontext;
1.403     moko      708:                                goto check_skip;
1.15      paf       709:                        }
1.13      paf       710:                        
1.322     misha     711:                case OP::OP_STRING_POOL:
1.49      paf       712:                        {
1.297     paf       713:                                ArrayOperation& local_ops=*i.next().ops;
1.226     paf       714: 
1.257     paf       715:                                WContext *saved_wcontext=wcontext;
1.351     misha     716:                                WWrapper local(wcontext);
1.226     paf       717:                                wcontext=&local;
                    718: 
1.297     paf       719:                                execute(local_ops);
1.226     paf       720: 
1.49      paf       721:                                // from "$a $b" part of expression taking only string value,
                    722:                                // ignoring any other content of wcontext
1.367     moko      723:                                const String* string=wcontext->get_string();
                    724:                                Value* value=string ? new VString(*string) : new VString();
1.297     paf       725:                                stack.push(*value);
                    726: 
1.257     paf       727:                                wcontext=saved_wcontext;
1.403     moko      728:                                goto check_skip;
1.49      paf       729:                        }
                    730: 
1.51      paf       731:                // CALL
1.322     misha     732:                case OP::OP_CURLY_CODE__STORE_PARAM:
                    733:                case OP::OP_EXPR_CODE__STORE_PARAM:
1.28      paf       734:                        {
1.237     paf       735:                                // code
1.297     paf       736:                                ArrayOperation& local_ops=*i.next().ops;
1.336     misha     737: 
                    738:                                DEBUG_PRINT_OPS((&local_ops))
                    739: 
1.237     paf       740:                                // when they evaluate expression parameter,
                    741:                                // the object expression result
                    742:                                // does not need to be written into calling frame
                    743:                                // it must go into any expressions using that parameter
                    744:                                // hence, we zero junction.wcontext here, and later
                    745:                                // in .process we would test that field 
                    746:                                // in decision "which wwrapper to use"
1.326     misha     747:                                VJunction& value=*new VJunction(
1.297     paf       748:                                        get_self(), 0,
1.257     paf       749:                                        method_frame, 
1.237     paf       750:                                        rcontext, 
1.322     misha     751:                                        opcode==OP::OP_EXPR_CODE__STORE_PARAM?0:wcontext, 
1.312     paf       752:                                        &local_ops);
1.343     misha     753: #ifndef USE_DESTRUCTORS
1.326     misha     754:                                if (opcode!=OP::OP_EXPR_CODE__STORE_PARAM)
1.343     misha     755:                                        wcontext->attach_junction(&value);
1.326     misha     756: #endif
1.237     paf       757:                                // store param
1.329     misha     758:                                stack.push(value);
1.29      paf       759:                                break;
                    760:                        }
                    761: 
1.397     moko      762: #define METHOD_PARAMS_ACTION(action)                                                                                   \
1.386     moko      763:                if(local_ops){                                                                                          \
                    764:                        size_t first = stack.top_index();                                                               \
                    765:                        execute(*local_ops);                                                                            \
1.403     moko      766:                        if(!fskip){                                                                                     \
                    767:                                frame.store_params((Value**)stack.ptr(first), stack.top_index()-first);                 \
                    768:                                action;                                                                                 \
                    769:                        }                                                                                               \
1.386     moko      770:                        stack.set_top_index(first);                                                                     \
                    771:                } else {                                                                                                \
                    772:                        frame.empty_params();                                                                           \
                    773:                        action;                                                                                         \
1.350     misha     774:                }
                    775: 
1.322     misha     776:                case OP::OP_CALL:
1.29      paf       777:                        {
1.297     paf       778:                                ArrayOperation* local_ops=i.next().ops;
1.237     paf       779: 
1.336     misha     780:                                DEBUG_PRINT_OPS(local_ops)
                    781:                                DEBUG_PRINT_STR("->\n")
                    782: 
1.297     paf       783:                                Value& value=stack.pop().value();
1.237     paf       784: 
1.297     paf       785:                                Junction* junction=value.get_junction();
                    786:                                if(!junction) {
1.420     moko      787:                                        if(dynamic_cast<VVoid*>(&value))
1.386     moko      788:                                                throw Exception(PARSER_RUNTIME, 0, "undefined method");
1.297     paf       789:                                        else
1.422     moko      790:                                                throw Exception(PARSER_RUNTIME, 0, "is '%s', not a method or junction, cannot call it", value.type());
1.297     paf       791:                                }
1.237     paf       792: 
1.370     moko      793:                                Value *result;
                    794:                                {
1.397     moko      795:                                        EXPRESSION_FRAME_ACTION(*junction->method, method_frame, junction->self, {
                    796:                                                METHOD_PARAMS_ACTION(call(frame));
                    797:                                                result=&frame.result();
                    798:                                                // desctructor deletes junctions in stack params here
                    799:                                        });
1.370     moko      800:                                }
                    801:                                stack.push(*result);
1.332     misha     802: 
1.336     misha     803:                                DEBUG_PRINT_STR("<-returned")
1.403     moko      804:                                goto check_skip;
1.332     misha     805:                        }
1.220     paf       806: 
1.332     misha     807:                case OP::OP_CALL__WRITE:
                    808:                        {
                    809:                                ArrayOperation* local_ops=i.next().ops;
                    810: 
1.336     misha     811:                                DEBUG_PRINT_OPS(local_ops)
                    812:                                DEBUG_PRINT_STR("->\n")
                    813: 
1.332     misha     814:                                Value& value=stack.pop().value();
                    815: 
                    816:                                Junction* junction=value.get_junction();
                    817:                                if(!junction) {
1.420     moko      818:                                        if(dynamic_cast<VVoid*>(&value))
1.386     moko      819:                                                throw Exception(PARSER_RUNTIME, 0, "undefined method");
1.332     misha     820:                                        else
1.422     moko      821:                                                throw Exception(PARSER_RUNTIME, 0, "is '%s', not a method or junction, cannot call it", value.type());
1.332     misha     822:                                }
                    823: 
1.391     moko      824:                                const Method& method=*junction->method;
1.332     misha     825: #ifdef OPTIMIZE_CALL
1.353     misha     826:                                if(method.call_optimization==Method::CO_WITHOUT_FRAME){
1.332     misha     827:                                        if(local_ops){ // store param code goes here
                    828:                                                size_t first = stack.top_index();
                    829:                                                execute(*local_ops);
                    830: 
1.403     moko      831:                                                if(!fskip){
                    832:                                                        MethodParams method_params;
                    833:                                                        method_params.store_params((Value**)stack.ptr(first), stack.top_index()-first);
                    834:                                                        method.check_actual_numbered_params(junction->self, &method_params);
                    835:                                                        method.native_code(*this, method_params); // execute it
                    836:                                                }
1.332     misha     837: 
                    838:                                                stack.set_top_index(first);
                    839:                                        } else {
                    840:                                                MethodParams method_params;
                    841:                                                method.check_actual_numbered_params(junction->self, &method_params);
                    842:                                                method.native_code(*this, method_params); // execute it
                    843:                                        }
1.353     misha     844:                                } else if(method.call_optimization==Method::CO_WITHOUT_WCONTEXT){
1.397     moko      845:                                        METHOD_FRAME_ACTION(method, method_frame, junction->self, {
                    846:                                                METHOD_PARAMS_ACTION(call_write(frame))
                    847:                                        });
1.332     misha     848:                                } else 
                    849: #endif // OPTIMIZE_CALL
                    850:                                {
1.397     moko      851:                                        METHOD_FRAME_ACTION(method, method_frame, junction->self, {
                    852:                                                METHOD_PARAMS_ACTION(call(frame));
                    853:                                                write(frame.result());
                    854:                                        });
1.332     misha     855:                                }
1.336     misha     856: 
                    857:                                DEBUG_PRINT_STR("<-returned")
1.403     moko      858:                                goto check_skip;
1.49      paf       859:                        }
                    860: 
1.348     misha     861:                case OP::OP_CONSTRUCT_OBJECT:
                    862:                case OP::OP_CONSTRUCT_OBJECT__WRITE:
                    863:                        {
                    864:                                debug_origin=i.next().origin;
                    865:                                Value& vclass_name=*i.next().value;
1.360     pretende  866:                                const String& class_name=*vclass_name.get_string(); debug_name=&class_name;
1.348     misha     867: 
                    868:                                DEBUG_PRINT_STRING(class_name)
                    869: 
1.413     moko      870:                                VStateless_class& vclass=get_class_ref(class_name);
1.348     misha     871: 
                    872:                                debug_origin=i.next().origin;
                    873:                                Value& vconstructor_name=*i.next().value;
                    874:                                const String& constructor_name=*vconstructor_name.get_string(); debug_name=&constructor_name;
                    875: 
                    876:                                DEBUG_PRINT_STRING(constructor_name)
                    877: 
1.424     moko      878:                                // not get_element4call for better error reporting
1.413     moko      879:                                Junction* constructor_junction=get_element(vclass, constructor_name).get_junction();
1.363     moko      880:                                if(!constructor_junction)
1.424     moko      881:                                        throw Exception(PARSER_RUNTIME, &constructor_name, "%s constructor not found", vclass.type());
1.350     misha     882: 
1.348     misha     883:                                ArrayOperation* local_ops=i.next().ops;
                    884:                                DEBUG_PRINT_OPS(local_ops)
                    885:                                DEBUG_PRINT_STR("->\n")
                    886: 
1.370     moko      887:                                Value *result;
                    888:                                {
1.413     moko      889:                                        Value& object=construct(vclass, *constructor_junction->method);
1.397     moko      890:                                        CONSTRUCTOR_FRAME_ACTION(*constructor_junction->method, method_frame, object, {
                    891:                                                METHOD_PARAMS_ACTION(call(frame));
                    892:                                                object.enable_default_setter();
                    893:                                                result=&frame.result();
                    894:                                                // desctructor deletes junctions in stack params here
                    895:                                        });
1.370     moko      896:                                }
1.355     misha     897: 
1.350     misha     898:                                if(opcode==OP::OP_CONSTRUCT_OBJECT)
1.370     moko      899:                                        stack.push(*result);
1.350     misha     900:                                else
1.396     moko      901:                                        write(*result);
1.348     misha     902: 
                    903:                                DEBUG_PRINT_STR("<-returned")
1.403     moko      904:                                goto check_skip;
1.348     misha     905:                        }
                    906: 
1.55      paf       907:                // expression ops: unary
1.322     misha     908:                case OP::OP_NEG:
1.55      paf       909:                        {
1.297     paf       910:                                Value& a=stack.pop().value();
                    911:                                Value& value=*new VDouble(-a.as_double());
                    912:                                stack.push(value);
1.55      paf       913:                                break;
                    914:                        }
1.322     misha     915:                case OP::OP_INV:
1.55      paf       916:                        {
1.297     paf       917:                                Value& a=stack.pop().value();
                    918:                                Value& value=*new VDouble(~a.as_int());
                    919:                                stack.push(value);
1.55      paf       920:                                break;
                    921:                        }
1.322     misha     922:                case OP::OP_NOT:
1.55      paf       923:                        {
1.297     paf       924:                                Value& a=stack.pop().value();
1.327     misha     925:                                Value& value=VBool::get(!a.as_bool());
1.297     paf       926:                                stack.push(value);
1.55      paf       927:                                break;
                    928:                        }
1.322     misha     929:                case OP::OP_DEF:
1.62      paf       930:                        {
1.297     paf       931:                                Value& a=stack.pop().value();
1.327     misha     932:                                Value& value=VBool::get(a.is_defined());
1.297     paf       933:                                stack.push(value);
1.62      paf       934:                                break;
                    935:                        }
1.322     misha     936:                case OP::OP_IN:
1.62      paf       937:                        {
1.297     paf       938:                                Value& a=stack.pop().value();
                    939:                                const String& path=a.as_string();
1.327     misha     940:                                Value& value=VBool::get(request_info.uri && *request_info.uri && path.this_starts(request_info.uri));
1.297     paf       941:                                stack.push(value);
1.62      paf       942:                                break;
                    943:                        }
1.322     misha     944:                case OP::OP_FEXISTS:
1.62      paf       945:                        {
1.297     paf       946:                                Value& a=stack.pop().value();
1.411     moko      947:                                Value& value=VBool::get(file_exist(full_disk_path(a.as_string())));
1.297     paf       948:                                stack.push(value);
1.148     paf       949:                                break;
                    950:                        }
1.322     misha     951:                case OP::OP_DEXISTS:
1.148     paf       952:                        {
1.297     paf       953:                                Value& a=stack.pop().value();
1.411     moko      954:                                Value& value=VBool::get(dir_exists(full_disk_path(a.as_string())));
1.297     paf       955:                                stack.push(value);
1.62      paf       956:                                break;
                    957:                        }
1.55      paf       958: 
                    959:                // expression ops: binary
1.415     moko      960:                case OP::OP_SUB:
1.53      paf       961:                        {
1.416     moko      962:                                volatile double b_double=stack.pop().value().as_double();
                    963:                                volatile double a_double=stack.pop().value().as_double();
1.415     moko      964: 
                    965:                                Value& value=*new VDouble(a_double - b_double);
1.297     paf       966:                                stack.push(value);
1.53      paf       967:                                break;
                    968:                        }
1.415     moko      969:                case OP::OP_ADD:
1.53      paf       970:                        {
1.416     moko      971:                                volatile double b_double=stack.pop().value().as_double();
                    972:                                volatile double a_double=stack.pop().value().as_double();
1.415     moko      973: 
                    974:                                Value& value=*new VDouble(a_double + b_double);
1.297     paf       975:                                stack.push(value);
1.53      paf       976:                                break;
                    977:                        }
1.415     moko      978:                case OP::OP_MUL:
1.49      paf       979:                        {
1.416     moko      980:                                volatile double b_double=stack.pop().value().as_double();
                    981:                                volatile double a_double=stack.pop().value().as_double();
1.415     moko      982: 
                    983:                                Value& value=*new VDouble(a_double * b_double);
1.297     paf       984:                                stack.push(value);
1.53      paf       985:                                break;
                    986:                        }
1.415     moko      987:                case OP::OP_DIV:
1.53      paf       988:                        {
1.416     moko      989:                                volatile double b_double=stack.pop().value().as_double();
                    990:                                volatile double a_double=stack.pop().value().as_double();
1.170     parser    991: 
1.171     parser    992:                                if(b_double == 0) {
1.297     paf       993:                                        //const String* problem_source=b.as_string();
1.386     moko      994:                                        throw Exception("number.zerodivision", 0, "Division by zero");
1.171     parser    995:                                }
1.170     parser    996: 
1.297     paf       997:                                Value& value=*new VDouble(a_double / b_double);
                    998:                                stack.push(value);
1.54      paf       999:                                break;
                   1000:                        }
1.415     moko     1001:                case OP::OP_MOD:
1.55      paf      1002:                        {
1.416     moko     1003:                                volatile double b_double=stack.pop().value().as_double();
                   1004:                                volatile double a_double=stack.pop().value().as_double();
1.170     parser   1005: 
1.173     parser   1006:                                if(b_double == 0) {
1.297     paf      1007:                                        //const String* problem_source=b.as_string();
1.386     moko     1008:                                        throw Exception("number.zerodivision", 0, "Modulus by zero");
1.171     parser   1009:                                }
1.170     parser   1010: 
1.297     paf      1011:                                Value& value=*new VDouble(fmod(a_double, b_double));
                   1012:                                stack.push(value);
1.201     paf      1013:                                break;
                   1014:                        }
1.322     misha    1015:                case OP::OP_INTDIV:
1.201     paf      1016:                        {
1.416     moko     1017:                                int b_int=stack.pop().value().as_int();
                   1018:                                int a_int=stack.pop().value().as_int();
1.201     paf      1019: 
                   1020:                                if(b_int == 0) {
1.297     paf      1021:                                        //const String* problem_source=b.as_string();
1.386     moko     1022:                                        throw Exception("number.zerodivision", 0, "Division by zero");
1.201     paf      1023:                                }
                   1024: 
1.297     paf      1025:                                Value& value=*new VInt(a_int / b_int);
                   1026:                                stack.push(value);
1.55      paf      1027:                                break;
                   1028:                        }
1.322     misha    1029:                case OP::OP_BIN_SL:
1.274     paf      1030:                        {
1.297     paf      1031:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                   1032:                                Value& value=*new VInt(
                   1033:                                        a.as_int() <<
                   1034:                                        b.as_int());
                   1035:                                stack.push(value);
1.274     paf      1036:                                break;
                   1037:                        }
1.322     misha    1038:                case OP::OP_BIN_SR:
1.274     paf      1039:                        {
1.297     paf      1040:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                   1041:                                Value& value=*new VInt(
                   1042:                                        a.as_int() >>
                   1043:                                        b.as_int());
                   1044:                                stack.push(value);
1.274     paf      1045:                                break;
                   1046:                        }
1.322     misha    1047:                case OP::OP_BIN_AND:
1.54      paf      1048:                        {
1.297     paf      1049:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                   1050:                                Value& value=*new VInt(
                   1051:                                        a.as_int() &
                   1052:                                        b.as_int());
                   1053:                                stack.push(value);
1.54      paf      1054:                                break;
                   1055:                        }
1.322     misha    1056:                case OP::OP_BIN_OR:
1.54      paf      1057:                        {
1.297     paf      1058:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                   1059:                                Value& value=*new VInt(
                   1060:                                        a.as_int() |
                   1061:                                        b.as_int());
                   1062:                                stack.push(value);
1.55      paf      1063:                                break;
                   1064:                        }
1.322     misha    1065:                case OP::OP_BIN_XOR:
1.56      paf      1066:                        {
1.297     paf      1067:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                   1068:                                Value& value=*new VInt(
                   1069:                                        a.as_int() ^
                   1070:                                        b.as_int());
                   1071:                                stack.push(value);
1.56      paf      1072:                                break;
                   1073:                        }
1.322     misha    1074:                case OP::OP_LOG_AND:
1.55      paf      1075:                        {
1.297     paf      1076:                                ArrayOperation& local_ops=stack.pop().ops();  Value& a=stack.pop().value();
1.263     paf      1077:                                bool result;
1.297     paf      1078:                                if(a.as_bool()) {
                   1079:                                        execute(local_ops);
                   1080:                                        Value& b=stack.pop().value();
                   1081:                                        result=b.as_bool();
1.209     paf      1082:                                } else
1.263     paf      1083:                                        result=false;
1.327     misha    1084:                                Value& value=VBool::get(result);
1.297     paf      1085:                                stack.push(value);
1.403     moko     1086:                                goto check_skip;
1.55      paf      1087:                        }
1.322     misha    1088:                case OP::OP_LOG_OR:
1.55      paf      1089:                        {
1.297     paf      1090:                                ArrayOperation& local_ops=stack.pop().ops();  Value& a=stack.pop().value();
1.263     paf      1091:                                bool result;
1.297     paf      1092:                                if(a.as_bool()) 
1.263     paf      1093:                                        result=true;
1.209     paf      1094:                                else {
1.297     paf      1095:                                        execute(local_ops);
                   1096:                                        Value& b=stack.pop().value();
                   1097:                                        result=b.as_bool();
1.209     paf      1098:                                }
1.327     misha    1099:                                Value& value=VBool::get(result);
1.297     paf      1100:                                stack.push(value);
1.403     moko     1101:                                goto check_skip;
1.56      paf      1102:                        }
1.322     misha    1103:                case OP::OP_LOG_XOR:
1.56      paf      1104:                        {
1.297     paf      1105:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
1.327     misha    1106:                                Value& value=VBool::get(a.as_bool() ^ b.as_bool());
1.297     paf      1107:                                stack.push(value);
1.55      paf      1108:                                break;
                   1109:                        }
1.322     misha    1110:                case OP::OP_NUM_LT: 
1.55      paf      1111:                        {
1.297     paf      1112:                                volatile double b_double=stack.pop().value().as_double();
                   1113:                                volatile double a_double=stack.pop().value().as_double();
1.327     misha    1114:                                Value& value=VBool::get(a_double<b_double);
1.297     paf      1115:                                stack.push(value);
1.55      paf      1116:                                break;
                   1117:                        }
1.322     misha    1118:                case OP::OP_NUM_GT: 
1.55      paf      1119:                        {
1.297     paf      1120:                                volatile double b_double=stack.pop().value().as_double();
                   1121:                                volatile double a_double=stack.pop().value().as_double();
1.327     misha    1122:                                Value& value=VBool::get(a_double>b_double);
1.297     paf      1123:                                stack.push(value);
1.55      paf      1124:                                break;
                   1125:                        }
1.322     misha    1126:                case OP::OP_NUM_LE: 
1.55      paf      1127:                        {
1.297     paf      1128:                                volatile double b_double=stack.pop().value().as_double();
                   1129:                                volatile double a_double=stack.pop().value().as_double();
1.327     misha    1130:                                Value& value=VBool::get(a_double<=b_double);
1.297     paf      1131:                                stack.push(value);
1.55      paf      1132:                                break;
                   1133:                        }
1.322     misha    1134:                case OP::OP_NUM_GE: 
1.55      paf      1135:                        {
1.297     paf      1136:                                volatile double b_double=stack.pop().value().as_double();
                   1137:                                volatile double a_double=stack.pop().value().as_double();
1.327     misha    1138:                                Value& value=VBool::get(a_double>=b_double);
1.297     paf      1139:                                stack.push(value);
1.55      paf      1140:                                break;
                   1141:                        }
1.322     misha    1142:                case OP::OP_NUM_EQ: 
1.55      paf      1143:                        {
1.297     paf      1144:                                volatile double b_double=stack.pop().value().as_double();
                   1145:                                volatile double a_double=stack.pop().value().as_double();
1.327     misha    1146:                                Value& value=VBool::get(a_double==b_double);
1.297     paf      1147:                                stack.push(value);
1.55      paf      1148:                                break;
                   1149:                        }
1.322     misha    1150:                case OP::OP_NUM_NE: 
1.55      paf      1151:                        {
1.297     paf      1152:                                volatile double b_double=stack.pop().value().as_double();
                   1153:                                volatile double a_double=stack.pop().value().as_double();
1.327     misha    1154:                                Value& value=VBool::get(a_double!=b_double);
1.297     paf      1155:                                stack.push(value);
1.54      paf      1156:                                break;
                   1157:                        }
1.322     misha    1158:                case OP::OP_STR_LT: 
1.58      paf      1159:                        {
1.297     paf      1160:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
1.327     misha    1161:                                Value& value=VBool::get(a.as_string() < b.as_string());
1.297     paf      1162:                                stack.push(value);
1.58      paf      1163:                                break;
                   1164:                        }
1.322     misha    1165:                case OP::OP_STR_GT: 
1.58      paf      1166:                        {
1.297     paf      1167:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
1.327     misha    1168:                                Value& value=VBool::get(a.as_string() > b.as_string());
1.297     paf      1169:                                stack.push(value);
1.58      paf      1170:                                break;
                   1171:                        }
1.322     misha    1172:                case OP::OP_STR_LE: 
1.58      paf      1173:                        {
1.297     paf      1174:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
1.327     misha    1175:                                Value& value=VBool::get(a.as_string() <= b.as_string());
1.297     paf      1176:                                stack.push(value);
1.58      paf      1177:                                break;
                   1178:                        }
1.322     misha    1179:                case OP::OP_STR_GE: 
1.54      paf      1180:                        {
1.297     paf      1181:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
1.327     misha    1182:                                Value& value=VBool::get(a.as_string() >= b.as_string());
1.297     paf      1183:                                stack.push(value);
1.58      paf      1184:                                break;
                   1185:                        }
1.322     misha    1186:                case OP::OP_STR_EQ: 
1.58      paf      1187:                        {
1.297     paf      1188:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
1.327     misha    1189:                                Value& value=VBool::get(a.as_string() == b.as_string());
1.297     paf      1190:                                stack.push(value);
1.58      paf      1191:                                break;
                   1192:                        }
1.322     misha    1193:                case OP::OP_STR_NE: 
1.58      paf      1194:                        {
1.297     paf      1195:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
1.327     misha    1196:                                Value& value=VBool::get(a.as_string() != b.as_string());
1.297     paf      1197:                                stack.push(value);
1.103     paf      1198:                                break;
                   1199:                        }
1.322     misha    1200:                case OP::OP_IS:
1.103     paf      1201:                        {
1.297     paf      1202:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
1.327     misha    1203:                                Value& value=VBool::get(a.is(b.as_string().cstr()));
1.297     paf      1204:                                stack.push(value);
1.28      paf      1205:                                break;
                   1206:                        }
1.11      paf      1207:                default:
1.403     moko     1208:                        {
                   1209:                                throw Exception(0, 0, "invalid opcode %d", opcode); 
                   1210:                        }
                   1211:                check_skip:
                   1212:                        {
                   1213:                                if(fskip){
                   1214:                                        if(fskip==Request::SKIP_INTERRUPTED){
                   1215:                                                set_skip(Request::SKIP_NOTHING);
                   1216:                                                throw Exception("parser.interrupted", 0, "execution stopped");
                   1217:                                        }
                   1218:                                        return;
                   1219:                                }
                   1220:                                break;
                   1221:                        }
1.11      paf      1222:                }
                   1223:        }
1.306     paf      1224:        } catch(const Exception&) {
1.297     paf      1225:                // record it to stack trace
1.301     paf      1226:                if(debug_name)
                   1227:                        exception_trace.push(Trace(debug_name, debug_origin));
1.297     paf      1228:                rethrow;
                   1229:        }
1.1       paf      1230: }
1.17      paf      1231: 
1.330     misha    1232: #define SAVE_CONTEXT                                                           \
1.386     moko     1233:        VMethodFrame *saved_method_frame=method_frame;                          \
                   1234:        Value* saved_rcontext=rcontext;                                         \
1.330     misha    1235:        WContext *saved_wcontext=wcontext;
                   1236: 
1.386     moko     1237: #define RESTORE_CONTEXT                                                                \
                   1238:        wcontext=saved_wcontext;                                                \
                   1239:        rcontext=saved_rcontext;                                                \
1.330     misha    1240:        method_frame=saved_method_frame;
                   1241: 
1.384     moko     1242: Value& Request::construct(VStateless_class &called_class, const Method &method){
1.363     moko     1243: 
                   1244:        if(method.call_type!=Method::CT_STATIC) {
                   1245:                // this is a constructor call
                   1246:                if(Value* result=called_class.create_new_value(fpool)) {
1.319     misha    1247:                                // some stateless_class creatable derivates
1.363     moko     1248:                                return *result;
                   1249:                } else 
1.401     moko     1250:                        throw Exception(PARSER_RUNTIME, method.name,
                   1251:                                "is not a constructor, system class '%s' can be constructed only implicitly", called_class.type());
1.363     moko     1252:        } else
1.422     moko     1253:                throw Exception(PARSER_RUNTIME, method.name, "method of '%s' is static and cannot be used as constructor", called_class.type());
1.363     moko     1254: }
1.319     misha    1255: 
1.330     misha    1256: Value& Request::get_element(Value& ncontext, const String& name) {
1.376     moko     1257:        Value* value=ncontext.get_element(name);
1.388     moko     1258:        return *(value ? &process(*value) : VVoid::get());
1.376     moko     1259: }
                   1260: 
1.383     moko     1261: #ifdef FEATURE_GET_ELEMENT4CALL
1.376     moko     1262: Value& Request::get_element4call(Value& ncontext, const String& name) {
                   1263:        Value* value=ncontext.get_element4call(name);
1.388     moko     1264:        return *(value ? &process(*value) : VVoid::get());
1.309     paf      1265: }
1.383     moko     1266: #endif
1.309     paf      1267: 
1.329     misha    1268: void Request::put_element(Value& ncontext, const String& name, Value* value) {
1.309     paf      1269:        // put_element can return property-setting-junction
1.407     moko     1270:        if(const VJunction* vjunction=ncontext.put_element(name, value)) {
                   1271:                const Junction& junction = vjunction->junction();
                   1272:                int param_count=junction.method->params_count;
                   1273: 
                   1274:                if(junction.auto_name) {
                   1275:                        // default setter
                   1276:                        if(param_count!=2)
                   1277:                                throw Exception(PARSER_RUNTIME, 0, "default setter method must have TWO parameters (has %d parameters)", param_count);
                   1278: 
                   1279:                        Value* params[2] = { new VString(*junction.auto_name), value };
                   1280: 
                   1281:                        CONSTRUCTOR_FRAME_ACTION(*junction.method, method_frame /*caller*/, junction.self, {
                   1282:                                frame.store_params(params, 2);
                   1283:                                Temp_disable_default_setter temp(junction.self);
                   1284:                                call(frame);
                   1285:                        });
                   1286:                } else {
                   1287:                        // setter
                   1288:                        if(param_count!=1)
                   1289:                                throw Exception(PARSER_RUNTIME, 0, "setter method must have ONE parameter (has %d parameters)", param_count);
                   1290: 
                   1291:                        CONSTRUCTOR_FRAME_ACTION(*junction.method, method_frame /*caller*/, junction.self, {
                   1292:                                frame.store_params(&value, 1);
                   1293:                                call(frame);
                   1294:                        });
1.364     moko     1295:                }
1.407     moko     1296:        }
1.364     moko     1297: }
                   1298: 
1.385     moko     1299: Value& Request::process_getter(Junction& junction) {
1.397     moko     1300:        int param_count=junction.method->params_count;
1.364     moko     1301: 
1.397     moko     1302:        if(junction.auto_name){
1.364     moko     1303:                // default getter
1.397     moko     1304:                if(param_count>1)
1.422     moko     1305:                        throw Exception(PARSER_RUNTIME, 0, "default getter method can't have more than 1 parameter (has %d parameters)", param_count);
1.397     moko     1306: 
1.364     moko     1307:                Value *param;
1.397     moko     1308:                METHOD_FRAME_ACTION(*junction.method, method_frame/*caller*/, junction.self, {
1.364     moko     1309: 
1.397     moko     1310:                        if(param_count){
                   1311:                                param=new VString(*junction.auto_name);
                   1312:                                frame.store_params(&param, 1);
                   1313:                        } // no need for else frame.empty_params()
                   1314: 
                   1315:                        Temp_disable_default_getter temp(junction.self);
                   1316:                        call(frame);
                   1317:                        return frame.result();
                   1318:                });
1.364     moko     1319:        } else {
                   1320:                // getter
1.397     moko     1321:                if(param_count>0)
1.386     moko     1322:                        throw Exception(PARSER_RUNTIME, 0, "getter method must have no parameters (has %d parameters)", param_count);
1.364     moko     1323:                
1.397     moko     1324:                METHOD_FRAME_ACTION(*junction.method, method_frame/*caller*/, junction.self, {
                   1325:                        // no need for frame.empty_params()
                   1326:                        call(frame);
                   1327:                        return frame.result();
                   1328:                });
1.364     moko     1329:        }
1.309     paf      1330: 
1.34      paf      1331: }
1.70      paf      1332: 
1.389     moko     1333: Value& Request::process(Value& input_value) {
1.297     paf      1334:        Junction* junction=input_value.get_junction();
1.307     paf      1335:        if(junction) {
                   1336:                if(junction->is_getter) { // is it a getter-junction?
1.389     moko     1337:                        return process(process_getter(*junction));
1.307     paf      1338:                }
                   1339: 
                   1340:                if(junction->code) { // is it a code-junction?
                   1341:                        // process it
1.385     moko     1342:                        ValueRef result;
1.336     misha    1343: 
                   1344:                        DEBUG_PRINT_STR("ja->\n")
1.238     paf      1345: 
1.307     paf      1346:                        if(!junction->method_frame)
1.386     moko     1347:                                throw Exception(PARSER_RUNTIME, 0, "junction used outside of context");
1.240     paf      1348: 
1.330     misha    1349:                        SAVE_CONTEXT
1.307     paf      1350: 
                   1351:                        method_frame=junction->method_frame;
                   1352:                        rcontext=junction->rcontext;
                   1353: 
1.389     moko     1354:                        // for code in [] and () wcontext is set 0
                   1355:                        // using the fact in decision "which wrapper to use"
1.399     moko     1356:                        if(junction->wcontext) {
1.389     moko     1357:                                // {} code wrapper
1.318     misha    1358:                                VCodeFrame local(*junction->wcontext);
1.307     paf      1359:                                wcontext=&local;
                   1360: 
                   1361:                                // execute it
1.423     moko     1362:                                recursion_checked_execute(*junction->code);
1.307     paf      1363: 
1.318     misha    1364:                                result=wcontext->result();
1.307     paf      1365:                        } else {
1.389     moko     1366:                                // [] or () code wrapper
1.351     misha    1367:                                WWrapper local(wcontext);
1.307     paf      1368:                                wcontext=&local;
                   1369: 
                   1370:                                // execute it
1.423     moko     1371:                                recursion_checked_execute(*junction->code);
1.307     paf      1372: 
                   1373:                                result=wcontext->result();
                   1374:                        }
                   1375: 
1.330     misha    1376:                        RESTORE_CONTEXT
1.207     paf      1377: 
1.336     misha    1378:                        DEBUG_PRINT_STR("<-ja returned")
                   1379: 
1.307     paf      1380:                        return result;
                   1381:                }
                   1382: 
1.422     moko     1383:                // then it is a method-junction, do not explode it
1.307     paf      1384:                // just return it as we do for usual objects
                   1385:        }       
                   1386: 
                   1387:        return input_value;
1.85      paf      1388: }
                   1389: 
1.332     misha    1390: void Request::process_write(Value& input_value) {
                   1391:        Junction* junction=input_value.get_junction();
                   1392:        if(junction) {
1.375     moko     1393:                // no getter-junction check as process_write is called
                   1394:                // to process method arguments, not from get_element
1.332     misha    1395: 
                   1396:                if(junction->code) { // is it a code-junction?
1.389     moko     1397:                        // process it
1.336     misha    1398: 
                   1399:                        DEBUG_PRINT_STR("ja->\n")
                   1400: 
1.332     misha    1401:                        if(!junction->method_frame)
1.386     moko     1402:                                throw Exception(PARSER_RUNTIME, 0, "junction used outside of context");
1.332     misha    1403: 
                   1404:                        SAVE_CONTEXT
                   1405: 
                   1406:                        method_frame=junction->method_frame;
                   1407:                        rcontext=junction->rcontext;
                   1408: 
1.389     moko     1409:                        // for code in [] and () wcontext is set 0
1.332     misha    1410:                        // using the fact in decision "which wwrapper to use"
                   1411: #ifdef OPTIMIZE_CALL
                   1412:                        if(wcontext==junction->wcontext){
                   1413:                                // no wrappers for wcontext
1.423     moko     1414:                                recursion_checked_execute(*junction->code);
1.332     misha    1415:                                RESTORE_CONTEXT
                   1416: 
                   1417:                        } else
                   1418: #endif
                   1419:                        if(junction->wcontext) {
1.389     moko     1420:                                // {} code wrapper
1.332     misha    1421:                                VCodeFrame local(*junction->wcontext);
                   1422:                                wcontext=&local;
                   1423: 
                   1424:                                // execute it
1.423     moko     1425:                                recursion_checked_execute(*junction->code);
1.332     misha    1426:                                RESTORE_CONTEXT
1.396     moko     1427:                                write(local.result());
1.332     misha    1428:                        } else {
1.389     moko     1429:                                // [] or () code wrapper
1.351     misha    1430:                                WWrapper local(wcontext);
1.332     misha    1431:                                wcontext=&local;
                   1432: 
                   1433:                                // execute it
1.423     moko     1434:                                recursion_checked_execute(*junction->code);
1.332     misha    1435:                                RESTORE_CONTEXT
1.396     moko     1436:                                write(local.result());
1.332     misha    1437:                        }
1.336     misha    1438: 
                   1439:                        DEBUG_PRINT_STR("<-ja returned")
                   1440: 
1.332     misha    1441:                        return;
                   1442:                }
                   1443: 
1.422     moko     1444:                // then it is a method-junction, do not explode it
1.332     misha    1445:                // just return it as we do for usual objects
                   1446:        }
                   1447: 
1.396     moko     1448:        write(input_value);
1.332     misha    1449: }
                   1450: 
1.408     moko     1451: const String* Request::execute_method(VStateless_class& aclass, const String& method_name, Value* optional_param) {
                   1452:        if(const Method *method=aclass.get_method(method_name)){
                   1453:                METHOD_FRAME_ACTION(*method, method_frame/*caller*/, aclass, {
1.317     misha    1454: 
1.408     moko     1455:                        if(optional_param && method->params_count>0) {
                   1456:                                frame.store_params(&optional_param, 1);
                   1457:                        } else {
                   1458:                                frame.empty_params();
                   1459:                        }
1.246     paf      1460: 
1.408     moko     1461:                        // prevent non-string writes for better error reporting
1.397     moko     1462:                        frame.write(frame);
1.408     moko     1463: 
                   1464:                        call(frame);
1.208     paf      1465:        
1.410     moko     1466:                        Value &result=frame.result();
                   1467:                        if(const String* sresult=result.get_string()){
                   1468:                                return sresult;
                   1469:                        }
                   1470:                        result.bark("is '%s', it has no string representation", &method_name);
1.408     moko     1471:                });
                   1472:        }
                   1473:        return 0;
1.242     paf      1474: }
                   1475: 
1.408     moko     1476: bool Request::execute_method_if_exists(VStateless_class& aclass, const String& method_name, Value* optional_param) {
                   1477:        if(const Method *method=aclass.get_method(method_name)){
                   1478:                METHOD_FRAME_ACTION(*method, method_frame/*caller*/, aclass, {
                   1479: 
                   1480:                        if(optional_param && method->params_count>0) {
                   1481:                                frame.store_params(&optional_param, 1);
                   1482:                        } else {
                   1483:                                frame.empty_params();
                   1484:                        }
1.99      paf      1485: 
1.408     moko     1486:                        call(frame);
                   1487:                });
                   1488:                return true;
                   1489:        }
                   1490:        return false;
1.176     parser   1491: }
1.362     misha    1492: 
1.417     moko     1493: bool Request::execute_auto_method_if_exists(VStateless_class& aclass, const String& method_name, Value* optional_param) {
                   1494:        if(const Method *method=aclass.get_method(method_name)){
                   1495:                METHOD_FRAME_ACTION(*method, method_frame/*caller*/, aclass, {
                   1496:                        Value* two_params[2];
                   1497: 
                   1498:                        if (optional_param && method->params_count>1) {
                   1499:                                two_params[0] = optional_param;
                   1500:                                two_params[1] = new VString(*new String(aclass.type()));
                   1501:                                frame.store_params(two_params, 2);
                   1502:                        } else if (optional_param && method->params_count>0) {
                   1503:                                frame.store_params(&optional_param, 1);
                   1504:                        } else {
                   1505:                                frame.empty_params();
                   1506:                        }
                   1507: 
                   1508:                        call(frame);
                   1509:                });
                   1510:                return true;
                   1511:        }
                   1512:        return false;
                   1513: }
                   1514: 
1.398     moko     1515: const String* Request::get_method_filespec(const Method* method){
1.404     moko     1516:        Operation::Origin origin=get_method_origin(method);
                   1517:        return origin.file_no ? get_used_filespec(origin.file_no) : NULL;
                   1518: }
                   1519: 
                   1520: const Operation::Origin Request::get_method_origin(const Method* method){
                   1521:        Operation::Origin origin={0, 0, 0};
                   1522: 
1.362     misha    1523:        if(ArrayOperation* code=method->parser_code)
                   1524:                if(code){
1.419     moko     1525:                        for(Array_iterator<Operation> i(*code); i; ){
1.362     misha    1526:                                switch( i.next().code ){
                   1527:                                        case OP::OP_CURLY_CODE__STORE_PARAM: 
                   1528:                                        case OP::OP_EXPR_CODE__STORE_PARAM:
                   1529:                                        case OP::OP_CURLY_CODE__CONSTRUCT:
                   1530:                                        case OP::OP_NESTED_CODE:
                   1531:                                        case OP::OP_OBJECT_POOL:
                   1532:                                        case OP::OP_STRING_POOL:
                   1533:                                        case OP::OP_CALL:
                   1534:                                        case OP::OP_CALL__WRITE:
                   1535:                                                {
                   1536:                                                        i.next(); // skip local ops
                   1537:                                                        i.next(); // skip next opcode
                   1538:                                                        // continue execution
                   1539:                                                }
                   1540:                                        case OP::OP_CONSTRUCT_OBJECT:
                   1541:                                        case OP::OP_CONSTRUCT_OBJECT__WRITE:
                   1542:                                        case OP::OP_VALUE:
                   1543:                                        case OP::OP_STRING__WRITE:
                   1544:                                        case OP::OP_VALUE__GET_CLASS:
1.383     moko     1545:                                        case OP::OP_VALUE__GET_BASE_CLASS:
1.362     misha    1546: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT
                   1547:                                        case OP::OP_GET_OBJECT_ELEMENT:
                   1548:                                        case OP::OP_GET_OBJECT_ELEMENT__WRITE:
                   1549: #endif
                   1550: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT
                   1551:                                        case OP::OP_GET_OBJECT_VAR_ELEMENT:
                   1552:                                        case OP::OP_GET_OBJECT_VAR_ELEMENT__WRITE:
                   1553: #endif
                   1554: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT
                   1555:                                        case OP::OP_VALUE__GET_ELEMENT:
                   1556:                                        case OP::OP_VALUE__GET_ELEMENT__WRITE:
                   1557:                                        case OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR:
                   1558:                                        case OP::OP_WITH_ROOT__VALUE__GET_ELEMENT:
                   1559: #endif
                   1560: #ifdef OPTIMIZE_BYTECODE_GET_SELF_ELEMENT
                   1561:                                        case OP::OP_WITH_SELF__VALUE__GET_ELEMENT:
                   1562:                                        case OP::OP_WITH_SELF__VALUE__GET_ELEMENT__WRITE:
                   1563: #endif
1.377     moko     1564: 
                   1565: #ifdef FEATURE_GET_ELEMENT4CALL
                   1566:                                        case OP::OP_GET_ELEMENT4CALL:
                   1567: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT
                   1568:                                        case OP::OP_GET_OBJECT_ELEMENT4CALL:
                   1569: #endif
                   1570: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT
                   1571:                                        case OP::OP_GET_OBJECT_VAR_ELEMENT4CALL:
                   1572: #endif
                   1573: #endif // FEATURE_GET_ELEMENT4CALL
                   1574: 
1.362     misha    1575: #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
                   1576:                                        case OP::OP_WITH_ROOT__VALUE__CONSTRUCT_EXPR:
                   1577:                                        case OP::OP_WITH_ROOT__VALUE__CONSTRUCT_VALUE:
                   1578:                                        case OP::OP_WITH_WRITE__VALUE__CONSTRUCT_EXPR:
                   1579:                                        case OP::OP_WITH_WRITE__VALUE__CONSTRUCT_VALUE:
                   1580:                                        case OP::OP_WITH_SELF__VALUE__CONSTRUCT_EXPR:
                   1581:                                        case OP::OP_WITH_SELF__VALUE__CONSTRUCT_VALUE:
                   1582: #endif
                   1583:                                                {
                   1584:                                                        origin=i.next().origin;
                   1585:                                                        break;
                   1586:                                                }
1.373     moko     1587:                                        default: break;
1.362     misha    1588:                                }
                   1589:                                if(origin.file_no)
1.404     moko     1590:                                        return origin;
1.362     misha    1591:                        }
                   1592:                }
1.404     moko     1593:        return origin;
1.362     misha    1594: }
                   1595: 

E-mail: