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

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

E-mail: