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

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

E-mail: