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

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

E-mail: