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

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

E-mail: