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

1.117     paf         1: /** @file
1.118     paf         2:        Parser: executor part of request class.
                      3: 
1.305     paf         4:        Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)
1.218     paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.243     paf         6: */
1.118     paf         7: 
1.309.2.3! paf         8: static const char * const IDENT_EXECUTE_C="$Date: 2005/07/27 09:18:33 $";
1.1       paf         9: 
1.152     paf        10: #include "pa_opcode.h"
1.8       paf        11: #include "pa_array.h" 
1.11      paf        12: #include "pa_request.h"
1.15      paf        13: #include "pa_vstring.h"
1.22      paf        14: #include "pa_vhash.h"
1.167     parser     15: #include "pa_vvoid.h"
1.145     paf        16: #include "pa_vcode_frame.h"
                     17: #include "pa_vmethod_frame.h"
1.38      paf        18: #include "pa_vobject.h"
1.49      paf        19: #include "pa_vdouble.h"
1.54      paf        20: #include "pa_vbool.h"
1.94      paf        21: #include "pa_vtable.h"
1.132     paf        22: #include "pa_vfile.h"
1.144     paf        23: #include "pa_vimage.h"
1.194     parser     24: #include "pa_wwrapper.h"
1.1       paf        25: 
1.233     paf        26: //#define DEBUG_EXECUTE
1.157     parser     27: 
                     28: #ifdef DEBUG_EXECUTE
1.1       paf        29: char *opcode_name[]={
1.49      paf        30:        // literals
1.109     paf        31:        "VALUE",  "CURLY_CODE__STORE_PARAM",  "EXPR_CODE__STORE_PARAM",
1.209     paf        32:        "NESTED_CODE",
1.49      paf        33: 
                     34:        // actions
1.187     parser     35:        "WITH_ROOT",    "WITH_SELF",    "WITH_READ",    "WITH_WRITE",
1.66      paf        36:        "GET_CLASS",
1.182     parser     37:        "CONSTRUCT_VALUE", "CONSTRUCT_EXPR", "CURLY_CODE__CONSTRUCT",
1.108     paf        38:        "WRITE_VALUE",  "WRITE_EXPR_RESULT",  "STRING__WRITE",
1.284     paf        39:        "GET_ELEMENT_OR_OPERATOR", "GET_ELEMENT",       "GET_ELEMENT__WRITE",
1.232     paf        40:        "OBJECT_POOL",  "STRING_POOL",
1.1       paf        41:        "STORE_PARAM",
1.232     paf        42:        "PREPARE_TO_CONSTRUCT_OBJECT",  "PREPARE_TO_EXPRESSION", 
                     43:        "CALL", "CALL__WRITE",
1.49      paf        44: 
                     45:        // expression ops: unary
1.148     paf        46:        "NEG", "INV", "NOT", "DEF", "IN", "FEXISTS", "DEXISTS",
1.49      paf        47:        // expression ops: binary
1.201     paf        48:        "SUB", "ADD", "MUL", "DIV", "MOD", "INTDIV",
1.275     paf        49:        "BIN_SL", "BIN_SR",
1.56      paf        50:        "BIN_AND", "BIN_OR", "BIN_XOR",
                     51:        "LOG_AND", "LOG_OR", "LOG_XOR",
1.49      paf        52:        "NUM_LT", "NUM_GT", "NUM_LE", "NUM_GE", "NUM_EQ", "NUM_NE",
1.103     paf        53:        "STR_LT", "STR_GT", "STR_LE", "STR_GE", "STR_EQ", "STR_NE",
                     54:        "IS"
1.1       paf        55: };
                     56: 
1.297     paf        57: void va_debug_printf(SAPI_Info& sapi_info, const char* fmt,va_list args) {
1.127     paf        58:        char buf[MAX_STRING];
                     59:        vsnprintf(buf, MAX_STRING, fmt, args);
1.297     paf        60:        SAPI::log(sapi_info, "%s", buf);
1.107     paf        61: }
                     62: 
1.297     paf        63: void debug_printf(SAPI_Info& sapi_info, const char* fmt, ...) {
1.107     paf        64:     va_list args;
1.297     paf        65:     va_start(args, fmt);
                     66:     va_debug_printf(sapi_info, fmt, args);
1.107     paf        67:     va_end(args);
1.105     paf        68: }
                     69: 
1.297     paf        70: void debug_dump(SAPI_Info& sapi_info, int level, ArrayOperation& ops) {
                     71:        Array_iterator<Operation> i(ops);
1.190     parser     72:        while(i.has_next()) {
1.297     paf        73:                OPCODE opcode=i.next().code;
1.1       paf        74: 
1.297     paf        75:                if(opcode==OP_VALUE || opcode==OP_STRING__WRITE) {
                     76:                        Operation::Origin origin=i.next().origin;
                     77:                        Value& value=*i.next().value;
                     78:                        debug_printf(sapi_info, 
1.133     paf        79:                                "%*s%s"
                     80:                                " \"%s\" %s", 
1.297     paf        81:                                level*4, "", opcode_name[opcode],
                     82:                                value.get_string()->cstr(), value.type());
1.133     paf        83:                        continue;
1.15      paf        84:                }
1.297     paf        85:                debug_printf(sapi_info, "%*s%s", level*4, "", opcode_name[opcode]);
1.1       paf        86: 
1.297     paf        87:                switch(opcode) {
1.184     parser     88:                case OP_CURLY_CODE__STORE_PARAM: 
                     89:                case OP_EXPR_CODE__STORE_PARAM:
                     90:                case OP_CURLY_CODE__CONSTRUCT:
1.209     paf        91:                case OP_NESTED_CODE:
1.226     paf        92:                case OP_OBJECT_POOL:  
                     93:                case OP_STRING_POOL:
1.237     paf        94:                case OP_CALL:
1.297     paf        95:                case OP_CALL__WRITE:
                     96:                        if(ArrayOperation* local_ops=i.next().ops)
                     97:                                debug_dump(sapi_info, level+1, *local_ops);
1.1       paf        98:                }
                     99:        }
                    100: }
1.157     parser    101: #endif
1.1       paf       102: 
1.297     paf       103: // Request
                    104: 
                    105: void Request::execute(ArrayOperation& ops) {
                    106:        register Stack<StackItem>& stack=this->stack; // helps a lot on MSVC: 'esi'
1.159     parser    107: 
1.304     paf       108:        const String* debug_name=0;  Operation::Origin debug_origin={0, 0, 0};
1.297     paf       109:        try{
1.157     parser    110: #ifdef DEBUG_EXECUTE
1.297     paf       111:        debug_printf(sapi_info, "source----------------------------\n");
                    112:        debug_dump(sapi_info, 0, ops);
                    113:        debug_printf(sapi_info, "execution-------------------------\n");
1.157     parser    114: #endif
1.297     paf       115:        for(Array_iterator<Operation> i(ops); i.has_next(); ) {
                    116:                if(get_interrupted()) {
                    117:                        set_interrupted(false);
1.293     paf       118:                        throw Exception("parser.interrupted",
                    119:                                0,
                    120:                                "execution stopped");
1.297     paf       121:                }
                    122:                OPCODE opcode=i.next().code;
1.293     paf       123: 
1.157     parser    124: #ifdef DEBUG_EXECUTE
1.297     paf       125:                debug_printf(sapi_info, "%d:%s", stack.top_index()+1, opcode_name[opcode]);
1.157     parser    126: #endif
1.11      paf       127: 
1.297     paf       128:                switch(opcode) {
1.51      paf       129:                // param in next instruction
1.52      paf       130:                case OP_VALUE:
1.32      paf       131:                        {
1.297     paf       132:                                debug_origin=i.next().origin;
                    133:                                Value& value=*i.next().value;
1.157     parser    134: #ifdef DEBUG_EXECUTE
1.297     paf       135:                                debug_printf(sapi_info, " \"%s\" %s", value.get_string()->cstr(), value.type());
1.157     parser    136: #endif
1.297     paf       137:                                stack.push(value);
1.32      paf       138:                                break;
                    139:                        }
1.66      paf       140:                case OP_GET_CLASS:
1.38      paf       141:                        {
1.130     paf       142:                                // maybe they do ^class:method[] call, remember the fact
1.215     paf       143:                                wcontext->set_somebody_entered_some_class();
1.98      paf       144: 
1.297     paf       145:                                const String& name=stack.pop().string();
                    146:                                Value* value=classes().get(name);
1.120     paf       147:                                if(!value) 
1.223     paf       148:                                        throw Exception("parser.runtime",
1.66      paf       149:                                                &name,
1.143     paf       150:                                                "class is undefined"); 
1.66      paf       151: 
1.297     paf       152:                                stack.push(*value);
1.38      paf       153:                                break;
                    154:                        }
1.32      paf       155:                        
1.51      paf       156:                // OP_WITH
1.187     parser    157:                case OP_WITH_ROOT:
                    158:                        {
1.297     paf       159:                                stack.push(*method_frame);
1.187     parser    160:                                break;
                    161:                        }
1.37      paf       162:                case OP_WITH_SELF: 
                    163:                        {
1.297     paf       164:                                stack.push(get_self());
1.37      paf       165:                                break;
                    166:                        }
1.15      paf       167:                case OP_WITH_READ: 
                    168:                        {
1.297     paf       169:                                stack.push(*rcontext);
1.20      paf       170:                                break;
                    171:                        }
1.37      paf       172:                case OP_WITH_WRITE: 
1.20      paf       173:                        {
1.287     paf       174:                                if(wcontext==method_frame)
                    175:                                        throw Exception("parser.runtime",
                    176:                                                0,
                    177:                                                "$.name outside of $name[...]");
                    178: 
1.297     paf       179:                                stack.push(*wcontext);
1.20      paf       180:                                break;
                    181:                        }
1.37      paf       182:                        
1.51      paf       183:                // OTHER ACTIONS BUT WITHs
1.80      paf       184:                case OP_CONSTRUCT_VALUE:
1.20      paf       185:                        {
1.297     paf       186:                                Value& value=stack.pop().value();
                    187:                                const String& name=stack.pop().string();  debug_name=&name;
                    188:                                Value& ncontext=stack.pop().value();
1.309     paf       189:                                put_element(ncontext, name, value);
1.308     paf       190: 
1.213     paf       191:                                break;
                    192:                        }
1.80      paf       193:                case OP_CONSTRUCT_EXPR:
                    194:                        {
1.219     paf       195:                                // see OP_PREPARE_TO_EXPRESSION
                    196:                                wcontext->set_in_expression(false);
                    197: 
1.308     paf       198:                                Value& expr=stack.pop().value();
1.297     paf       199:                                const String& name=stack.pop().string();  debug_name=&name;
                    200:                                Value& ncontext=stack.pop().value();
1.308     paf       201:                                Value& value=expr.as_expr_result();
1.309     paf       202:                                put_element(ncontext, name, value);
1.80      paf       203:                                break;
                    204:                        }
1.182     parser    205:                case OP_CURLY_CODE__CONSTRUCT:
                    206:                        {
1.297     paf       207:                                ArrayOperation& local_ops=*i.next().ops;
1.182     parser    208: #ifdef DEBUG_EXECUTE
1.297     paf       209:                                debug_printf(sapi_info, " (%d)\n", local_ops.count());
                    210:                                debug_dump(sapi_info, 1, local_ops);
1.182     parser    211: #endif                         
1.297     paf       212:                                Value& value=*new VJunction(new Junction( 
                    213:                                        get_self(), 0,
1.257     paf       214:                                        method_frame, 
1.240     paf       215:                                        rcontext, 
                    216:                                        wcontext, 
1.297     paf       217:                                        &local_ops));
1.238     paf       218: 
1.297     paf       219:                                const String& name=stack.pop().string();  debug_name=&name;
                    220:                                Value& ncontext=stack.pop().value();
1.309.2.3! paf       221:                                if(const Junction* junction=ncontext.put_element(ncontext, name, &value))
1.308     paf       222:                                        if(junction!=PUT_ELEMENT_REPLACED_ELEMENT)
                    223:                                                throw Exception("parser.runtime",
                    224:                                                        0,
                    225:                                                        "property value can not be code, use [] or () brackets");
                    226:                                        
1.182     parser    227:                                break;
                    228:                        }
1.209     paf       229:                case OP_NESTED_CODE:
                    230:                        {
1.297     paf       231:                                ArrayOperation& local_ops=*i.next().ops;
1.209     paf       232: #ifdef DEBUG_EXECUTE
1.297     paf       233:                                debug_printf(sapi_info, " (%d)\n", local_ops.count());
                    234:                                debug_dump(sapi_info, 1, local_ops);
1.209     paf       235: #endif                         
1.297     paf       236:                                stack.push(local_ops);
1.209     paf       237:                                break;
                    238:                        }
1.108     paf       239:                case OP_WRITE_VALUE:
1.13      paf       240:                        {
1.297     paf       241:                                Value& value=stack.pop().value();
                    242:                                write_assign_lang(value);
1.86      paf       243:                                break;
                    244:                        }
1.108     paf       245:                case OP_WRITE_EXPR_RESULT:
                    246:                        {
1.297     paf       247:                                Value& value=stack.pop().value();
                    248:                                write_no_lang(value.as_expr_result());
1.230     paf       249: 
                    250:                                // must be after write(result) and 
1.219     paf       251:                                // see OP_PREPARE_TO_EXPRESSION
                    252:                                wcontext->set_in_expression(false);
1.108     paf       253:                                break;
                    254:                        }
1.86      paf       255:                case OP_STRING__WRITE:
                    256:                        {
1.297     paf       257:                                i.next(); // ignore origin
                    258:                                Value* value=i.next().value;
1.157     parser    259: #ifdef DEBUG_EXECUTE
1.297     paf       260:                                debug_printf(sapi_info, " \"%s\"", value->get_string()->cstr());
1.157     parser    261: #endif
1.297     paf       262:                                write_no_lang(*value->get_string());
1.13      paf       263:                                break;
1.14      paf       264:                        }
1.13      paf       265:                        
1.215     paf       266:                case OP_GET_ELEMENT_OR_OPERATOR:
                    267:                        {
1.297     paf       268:                                const String& name=stack.pop().string();  debug_name=&name;
                    269:                                Value& ncontext=stack.pop().value();
                    270:                                Value& value=get_element(ncontext, name, true);
                    271:                                stack.push(value);
1.215     paf       272:                                break;
                    273:                        }
1.15      paf       274:                case OP_GET_ELEMENT:
1.11      paf       275:                        {
1.297     paf       276:                                const String& name=stack.pop().string();  debug_name=&name;
                    277:                                Value& ncontext=stack.pop().value();
                    278:                                Value& value=get_element(ncontext, name, false);
                    279:                                stack.push(value);
1.17      paf       280:                                break;
                    281:                        }
                    282: 
1.18      paf       283:                case OP_GET_ELEMENT__WRITE:
1.17      paf       284:                        {
1.297     paf       285:                                const String& name=stack.pop().string();  debug_name=&name;
                    286:                                Value& ncontext=stack.pop().value();
                    287:                                Value& value=get_element(ncontext, name, false);
                    288:                                write_assign_lang(value);
1.17      paf       289:                                break;
                    290:                        }
                    291: 
1.32      paf       292: 
1.226     paf       293:                case OP_OBJECT_POOL:
1.17      paf       294:                        {
1.297     paf       295:                                ArrayOperation& local_ops=*i.next().ops;
1.226     paf       296:                                
1.257     paf       297:                                WContext *saved_wcontext=wcontext;
1.297     paf       298:                                String::Language saved_lang=flang;
                    299:                                flang=String::L_PASS_APPENDED;
                    300:                                WWrapper local(0/*empty*/, wcontext);
1.226     paf       301:                                wcontext=&local;
                    302: 
1.297     paf       303:                                execute(local_ops);
1.226     paf       304: 
1.297     paf       305:                                stack.push(wcontext->result().as_value());
1.257     paf       306:                                flang=saved_lang;
                    307:                                wcontext=saved_wcontext;
1.13      paf       308:                                break;
1.15      paf       309:                        }
1.13      paf       310:                        
1.226     paf       311:                case OP_STRING_POOL:
1.49      paf       312:                        {
1.297     paf       313:                                ArrayOperation& local_ops=*i.next().ops;
1.226     paf       314: 
1.257     paf       315:                                WContext *saved_wcontext=wcontext;
1.297     paf       316:                                WWrapper local(0 /*empty*/, wcontext);
1.226     paf       317:                                wcontext=&local;
                    318: 
1.297     paf       319:                                execute(local_ops);
1.226     paf       320: 
1.297     paf       321:                                Value* value;
1.49      paf       322:                                // from "$a $b" part of expression taking only string value,
                    323:                                // ignoring any other content of wcontext
1.297     paf       324:                                if(const String* string=wcontext->get_string())
                    325:                                        value=new VString(*string);
1.80      paf       326:                                else
1.297     paf       327:                                        value=new VVoid;
                    328:                                stack.push(*value);
                    329: 
1.257     paf       330:                                wcontext=saved_wcontext;
1.49      paf       331:                                break;
                    332:                        }
                    333: 
1.51      paf       334:                // CALL
1.237     paf       335:                case OP_STORE_PARAM:
1.28      paf       336:                        {
1.297     paf       337:                                Value& value=stack.pop().value();
1.299     paf       338:                                VMethodFrame& frame=stack.top_value().method_frame();
1.297     paf       339:                                // this op is executed from CALL local_ops only, so may skip the check "method_frame_to_fill==0"
                    340:                                frame.store_param(value);
1.28      paf       341:                                break;
                    342:                        }
1.237     paf       343:                case OP_CURLY_CODE__STORE_PARAM:
                    344:                case OP_EXPR_CODE__STORE_PARAM:
1.28      paf       345:                        {
1.237     paf       346:                                // code
1.297     paf       347:                                ArrayOperation& local_ops=*i.next().ops;
1.299     paf       348:                                VMethodFrame& frame=stack.top_value().method_frame();
1.237     paf       349: #ifdef DEBUG_EXECUTE
1.297     paf       350:                                debug_printf(sapi_info, " (%d)\n", local_ops.count());
                    351:                                debug_dump(sapi_info, 1, local_ops);
1.237     paf       352: #endif                         
                    353:                                // when they evaluate expression parameter,
                    354:                                // the object expression result
                    355:                                // does not need to be written into calling frame
                    356:                                // it must go into any expressions using that parameter
                    357:                                // hence, we zero junction.wcontext here, and later
                    358:                                // in .process we would test that field 
                    359:                                // in decision "which wwrapper to use"
1.297     paf       360:                                Value& value=*new VJunction(new Junction(
                    361:                                        get_self(), 0,
1.257     paf       362:                                        method_frame, 
1.237     paf       363:                                        rcontext, 
1.297     paf       364:                                        opcode==OP_EXPR_CODE__STORE_PARAM?0:wcontext, 
                    365:                                        &local_ops));
1.237     paf       366:                                // store param
                    367:                                // this op is executed from CALL local_ops only, so can not check method_frame_to_fill==0
1.297     paf       368:                                frame.store_param(value);
1.29      paf       369:                                break;
                    370:                        }
                    371: 
1.186     parser    372:                case OP_PREPARE_TO_CONSTRUCT_OBJECT:
                    373:                        {
1.200     paf       374:                                wcontext->set_constructing(true);
1.186     parser    375:                                break;
                    376:                        }
1.219     paf       377: 
                    378:                case OP_PREPARE_TO_EXPRESSION:
                    379:                        {
                    380:                                wcontext->set_in_expression(true);
                    381:                                break;
                    382:                        }
                    383: 
1.186     parser    384:                case OP_CALL:
1.232     paf       385:                case OP_CALL__WRITE:
1.29      paf       386:                        {
1.297     paf       387:                                //is_debug_junction=true;
                    388:                                ArrayOperation* local_ops=i.next().ops;
1.157     parser    389: #ifdef DEBUG_EXECUTE
1.297     paf       390:                                debug_printf(sapi_info, " (%d)\n", local_ops?local_ops->count():0);
                    391:                                if(local_ops)
                    392:                                        debug_dump(sapi_info, 1, *local_ops);
1.237     paf       393: 
1.297     paf       394:                                debug_printf(sapi_info, "->\n");
1.157     parser    395: #endif
1.297     paf       396:                                Value& value=stack.pop().value();
1.237     paf       397: 
1.297     paf       398:                                Junction* junction=value.get_junction();
                    399:                                if(!junction) {
                    400:                                        if(value.is("void"))
                    401:                                                throw Exception("parser.runtime",
                    402:                                                        0,
                    403:                                                        "undefined method");
                    404:                                        else
                    405:                                                throw Exception("parser.runtime",
                    406:                                                        0,
                    407:                                                        "is '%s', not a method or junction, can not call it",
                    408:                                                                value.type());
                    409:                                }
1.282     paf       410:                                /* no check needed, code compiled the way that that's impossible
1.276     paf       411:                                // check: 
                    412:                                //      that this is method-junction, not a code-junction
1.278     paf       413:                                // [disabling these contstructions:]
                    414:                                // $junction{code}
                    415:                                //  ^junction[]
1.276     paf       416:                                if(!junction->method)
                    417:                                        throw Exception("parser.runtime",
1.297     paf       418:                                                
                    419:                                                "is '%s', it is code junction, can not call it",
                    420:                                                        value.type());
1.282     paf       421:                                */
1.237     paf       422: 
1.297     paf       423:                                VMethodFrame frame(*junction, method_frame/*caller*/);
1.237     paf       424:                                if(local_ops){ // store param code goes here
1.297     paf       425:                                        stack.push(frame); // argument for *STORE_PARAM ops
1.237     paf       426:                                        execute(*local_ops);
1.297     paf       427:                                        stack.pop().value();
1.237     paf       428:                                }
                    429:                                frame.fill_unspecified_params();
1.257     paf       430:                                VMethodFrame *saved_method_frame=method_frame;
1.297     paf       431:                                Value* saved_rcontext=rcontext;
1.257     paf       432:                                WContext *saved_wcontext=wcontext;
1.45      paf       433:                                
1.297     paf       434:                                VStateless_class& called_class=*frame.junction.self.get_class();
1.307     paf       435:                                Value* new_self;
1.200     paf       436:                                if(wcontext->get_constructing()) {
                    437:                                        wcontext->set_constructing(false);
1.307     paf       438:                                        new_self=&get_self();
1.237     paf       439:                                        if(frame.junction.method->call_type!=Method::CT_STATIC) {
1.138     paf       440:                                                // this is a constructor call
1.185     parser    441: 
1.309.2.2  paf       442:                                                HashStringValue& new_object_fields=*new HashStringValue();
1.309.2.1  paf       443:                                                if(Value* value=called_class.create_new_value(fpool, new_object_fields)) {
1.204     paf       444:                                                        // some stateless_class creatable derivates
1.285     paf       445:                                                        new_self=value;
1.204     paf       446:                                                } else 
1.223     paf       447:                                                        throw Exception("parser.runtime",
1.297     paf       448:                                                                0, //&frame.name(),
1.204     paf       449:                                                                "is not a constructor, system class '%s' can be constructed only implicitly", 
1.297     paf       450:                                                                        called_class.name().cstr());
1.204     paf       451: 
1.285     paf       452:                                                frame.write(*new_self, 
1.297     paf       453:                                                        String::L_CLEAN  // not used, always an object, not string
1.83      paf       454:                                                );
1.185     parser    455:                                        } else
1.223     paf       456:                                                throw Exception("parser.runtime",
1.297     paf       457:                                                        0, //&frame.name(),
1.185     parser    458:                                                        "method is static and can not be used as constructor");
1.249     paf       459:                                } else
1.285     paf       460:                                        new_self=&frame.junction.self;
1.75      paf       461: 
1.285     paf       462:                                frame.set_self(*new_self);
1.219     paf       463: 
                    464:                                // see OP_PREPARE_TO_EXPRESSION
1.237     paf       465:                                frame.set_in_expression(wcontext->get_in_expression());
1.219     paf       466:                                
1.237     paf       467:                                rcontext=wcontext=&frame;
1.47      paf       468:                                {
1.237     paf       469:                                        const Method& method=*frame.junction.method;
1.134     paf       470:                                        Method::Call_type call_type=
1.297     paf       471:                                                &called_class==new_self ? Method::CT_STATIC : Method::CT_DYNAMIC;
1.134     paf       472:                                        if(
                    473:                                                method.call_type==Method::CT_ANY ||
1.197     parser    474:                                                method.call_type==call_type) { // allowed call type?
1.297     paf       475:                                                method_frame=&frame;
                    476:                                                if(method.native_code) { // native code?
                    477:                                                        method.check_actual_numbered_params(
                    478:                                                                frame.junction.self, 
                    479:                                                                /*frame.name(), */frame.numbered_params());
                    480:                                                        method.native_code(
                    481:                                                                *this, 
                    482:                                                                *frame.numbered_params()); // execute it
                    483:                                                } else // parser code, execute it
1.307     paf       484:                                                        recoursion_checked_execute(*method.parser_code);
1.197     parser    485:                                        } else
1.223     paf       486:                                                throw Exception("parser.runtime",
1.297     paf       487:                                                        0, //&frame.name(),
1.134     paf       488:                                                        "is not allowed to be called %s", 
                    489:                                                                call_type==Method::CT_STATIC?"statically":"dynamically");
                    490: 
1.47      paf       491:                                }
1.232     paf       492:                                StringOrValue result=wcontext->result();
1.45      paf       493: 
1.257     paf       494:                                wcontext=saved_wcontext;
                    495:                                rcontext=saved_rcontext;
                    496:                                method_frame=saved_method_frame;
1.220     paf       497: 
1.297     paf       498:                                if(opcode==OP_CALL__WRITE) {
                    499:                                        write_assign_lang(result);
1.232     paf       500:                                } else { // OP_CALL
1.297     paf       501:                                        stack.push(result.as_value());
1.232     paf       502:                                }
                    503:                                
1.157     parser    504: #ifdef DEBUG_EXECUTE
1.297     paf       505:                                debug_printf(sapi_info, "<-returned");
1.157     parser    506: #endif
1.297     paf       507:                                //is_debug_junction=false;
1.49      paf       508:                                break;
                    509:                        }
                    510: 
1.55      paf       511:                // expression ops: unary
                    512:                case OP_NEG:
                    513:                        {
1.297     paf       514:                                Value& a=stack.pop().value();
                    515:                                Value& value=*new VDouble(-a.as_double());
                    516:                                stack.push(value);
1.55      paf       517:                                break;
                    518:                        }
                    519:                case OP_INV:
                    520:                        {
1.297     paf       521:                                Value& a=stack.pop().value();
                    522:                                Value& value=*new VDouble(~a.as_int());
                    523:                                stack.push(value);
1.55      paf       524:                                break;
                    525:                        }
                    526:                case OP_NOT:
                    527:                        {
1.297     paf       528:                                Value& a=stack.pop().value();
                    529:                                Value& value=*new VBool(!a.as_bool());
                    530:                                stack.push(value);
1.55      paf       531:                                break;
                    532:                        }
1.62      paf       533:                case OP_DEF:
                    534:                        {
1.297     paf       535:                                Value& a=stack.pop().value();
                    536:                                Value& value=*new VBool(a.is_defined());
                    537:                                stack.push(value);
1.62      paf       538:                                break;
                    539:                        }
                    540:                case OP_IN:
                    541:                        {
1.297     paf       542:                                Value& a=stack.pop().value();
                    543:                                const String& path=a.as_string();
                    544:                                Value& value=*new VBool(request_info.uri && *request_info.uri && path.this_starts(request_info.uri));
                    545:                                stack.push(value);
1.62      paf       546:                                break;
                    547:                        }
                    548:                case OP_FEXISTS:
                    549:                        {
1.297     paf       550:                                Value& a=stack.pop().value();
                    551:                                Value& value=*new VBool(file_readable(absolute(a.as_string())));
                    552:                                stack.push(value);
1.148     paf       553:                                break;
                    554:                        }
                    555:                case OP_DEXISTS:
                    556:                        {
1.297     paf       557:                                Value& a=stack.pop().value();
                    558:                                Value& value=*new VBool(dir_readable(absolute(a.as_string())));
                    559:                                stack.push(value);
1.62      paf       560:                                break;
                    561:                        }
1.55      paf       562: 
                    563:                // expression ops: binary
                    564:                case OP_SUB: 
1.53      paf       565:                        {
1.297     paf       566:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    567:                                Value& value=*new VDouble(a.as_double() - b.as_double());
                    568:                                stack.push(value);
1.53      paf       569:                                break;
                    570:                        }
1.55      paf       571:                case OP_ADD: 
1.53      paf       572:                        {
1.297     paf       573:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    574:                                Value& value=*new VDouble(a.as_double() + b.as_double());
                    575:                                stack.push(value);
1.53      paf       576:                                break;
                    577:                        }
1.49      paf       578:                case OP_MUL: 
                    579:                        {
1.297     paf       580:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    581:                                Value& value=*new VDouble(a.as_double() * b.as_double());
                    582:                                stack.push(value);
1.53      paf       583:                                break;
                    584:                        }
                    585:                case OP_DIV: 
                    586:                        {
1.297     paf       587:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
1.170     parser    588: 
1.297     paf       589:                                double a_double=a.as_double();
                    590:                                double b_double=b.as_double();
1.170     parser    591: 
1.171     parser    592:                                if(b_double == 0) {
1.297     paf       593:                                        //const String* problem_source=b.as_string();
1.223     paf       594:                                        throw Exception("number.zerodivision",
1.297     paf       595:                                                0, //problem_source,
1.170     parser    596:                                                "Division by zero");
1.171     parser    597:                                }
1.170     parser    598: 
1.297     paf       599:                                Value& value=*new VDouble(a_double / b_double);
                    600:                                stack.push(value);
1.54      paf       601:                                break;
                    602:                        }
1.55      paf       603:                case OP_MOD: 
                    604:                        {
1.297     paf       605:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
1.170     parser    606: 
1.297     paf       607:                                double a_double=a.as_double();
                    608:                                double b_double=b.as_double();
1.170     parser    609: 
1.173     parser    610:                                if(b_double == 0) {
1.297     paf       611:                                        //const String* problem_source=b.as_string();
1.223     paf       612:                                        throw Exception("number.zerodivision",
1.297     paf       613:                                                0, //problem_source,
1.170     parser    614:                                                "Modulus by zero");
1.171     parser    615:                                }
1.170     parser    616: 
1.297     paf       617:                                Value& value=*new VDouble(fmod(a_double, b_double));
                    618:                                stack.push(value);
1.201     paf       619:                                break;
                    620:                        }
                    621:                case OP_INTDIV:
                    622:                        {
1.297     paf       623:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
1.201     paf       624: 
1.297     paf       625:                                int a_int=a.as_int();
                    626:                                int b_int=b.as_int();
1.201     paf       627: 
                    628:                                if(b_int == 0) {
1.297     paf       629:                                        //const String* problem_source=b.as_string();
1.223     paf       630:                                        throw Exception("number.zerodivision",
1.297     paf       631:                                                0, //problem_source,
1.201     paf       632:                                                "Division by zero");
                    633:                                }
                    634: 
1.297     paf       635:                                Value& value=*new VInt(a_int / b_int);
                    636:                                stack.push(value);
1.55      paf       637:                                break;
                    638:                        }
1.274     paf       639:                case OP_BIN_SL:
                    640:                        {
1.297     paf       641:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    642:                                Value& value=*new VInt(
                    643:                                        a.as_int() <<
                    644:                                        b.as_int());
                    645:                                stack.push(value);
1.274     paf       646:                                break;
                    647:                        }
                    648:                case OP_BIN_SR:
                    649:                        {
1.297     paf       650:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    651:                                Value& value=*new VInt(
                    652:                                        a.as_int() >>
                    653:                                        b.as_int());
                    654:                                stack.push(value);
1.274     paf       655:                                break;
                    656:                        }
1.55      paf       657:                case OP_BIN_AND:
1.54      paf       658:                        {
1.297     paf       659:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    660:                                Value& value=*new VInt(
                    661:                                        a.as_int() &
                    662:                                        b.as_int());
                    663:                                stack.push(value);
1.54      paf       664:                                break;
                    665:                        }
1.55      paf       666:                case OP_BIN_OR:
1.54      paf       667:                        {
1.297     paf       668:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    669:                                Value& value=*new VInt(
                    670:                                        a.as_int() |
                    671:                                        b.as_int());
                    672:                                stack.push(value);
1.55      paf       673:                                break;
                    674:                        }
1.56      paf       675:                case OP_BIN_XOR:
                    676:                        {
1.297     paf       677:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    678:                                Value& value=*new VInt(
                    679:                                        a.as_int() ^
                    680:                                        b.as_int());
                    681:                                stack.push(value);
1.56      paf       682:                                break;
                    683:                        }
1.55      paf       684:                case OP_LOG_AND:
                    685:                        {
1.297     paf       686:                                ArrayOperation& local_ops=stack.pop().ops();  Value& a=stack.pop().value();
1.263     paf       687:                                bool result;
1.297     paf       688:                                if(a.as_bool()) {
                    689:                                        execute(local_ops);
                    690:                                        Value& b=stack.pop().value();
                    691:                                        result=b.as_bool();
1.209     paf       692:                                } else
1.263     paf       693:                                        result=false;
1.297     paf       694:                                Value& value=*new VBool(result);
                    695:                                stack.push(value);
1.55      paf       696:                                break;
                    697:                        }
                    698:                case OP_LOG_OR:
                    699:                        {
1.297     paf       700:                                ArrayOperation& local_ops=stack.pop().ops();  Value& a=stack.pop().value();
1.263     paf       701:                                bool result;
1.297     paf       702:                                if(a.as_bool()) 
1.263     paf       703:                                        result=true;
1.209     paf       704:                                else {
1.297     paf       705:                                        execute(local_ops);
                    706:                                        Value& b=stack.pop().value();
                    707:                                        result=b.as_bool();
1.209     paf       708:                                }
1.297     paf       709:                                Value& value=*new VBool(result);
                    710:                                stack.push(value);
1.56      paf       711:                                break;
                    712:                        }
                    713:                case OP_LOG_XOR:
                    714:                        {
1.297     paf       715:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    716:                                Value& value=*new VBool(a.as_bool() ^ b.as_bool());
                    717:                                stack.push(value);
1.55      paf       718:                                break;
                    719:                        }
                    720:                case OP_NUM_LT: 
                    721:                        {
1.297     paf       722:                                volatile double b_double=stack.pop().value().as_double();
                    723:                                volatile double a_double=stack.pop().value().as_double();
                    724:                                Value& value=*new VBool(a_double<b_double);
                    725:                                stack.push(value);
1.55      paf       726:                                break;
                    727:                        }
                    728:                case OP_NUM_GT: 
                    729:                        {
1.297     paf       730:                                volatile double b_double=stack.pop().value().as_double();
                    731:                                volatile double a_double=stack.pop().value().as_double();
                    732:                                Value& value=*new VBool(a_double>b_double);
                    733:                                stack.push(value);
1.55      paf       734:                                break;
                    735:                        }
                    736:                case OP_NUM_LE: 
                    737:                        {
1.297     paf       738:                                volatile double b_double=stack.pop().value().as_double();
                    739:                                volatile double a_double=stack.pop().value().as_double();
                    740:                                Value& value=*new VBool(a_double<=b_double);
                    741:                                stack.push(value);
1.55      paf       742:                                break;
                    743:                        }
                    744:                case OP_NUM_GE: 
                    745:                        {
1.297     paf       746:                                volatile double b_double=stack.pop().value().as_double();
                    747:                                volatile double a_double=stack.pop().value().as_double();
                    748:                                Value& value=*new VBool(a_double>=b_double);
                    749:                                stack.push(value);
1.55      paf       750:                                break;
                    751:                        }
                    752:                case OP_NUM_EQ: 
                    753:                        {
1.297     paf       754:                                volatile double b_double=stack.pop().value().as_double();
                    755:                                volatile double a_double=stack.pop().value().as_double();
                    756:                                Value& value=*new VBool(a_double==b_double);
                    757:                                stack.push(value);
1.55      paf       758:                                break;
                    759:                        }
                    760:                case OP_NUM_NE: 
                    761:                        {
1.297     paf       762:                                volatile double b_double=stack.pop().value().as_double();
                    763:                                volatile double a_double=stack.pop().value().as_double();
                    764:                                Value& value=*new VBool(a_double!=b_double);
                    765:                                stack.push(value);
1.54      paf       766:                                break;
                    767:                        }
1.58      paf       768:                case OP_STR_LT: 
                    769:                        {
1.297     paf       770:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    771:                                Value& value=*new VBool(a.as_string() < b.as_string());
                    772:                                stack.push(value);
1.58      paf       773:                                break;
                    774:                        }
                    775:                case OP_STR_GT: 
                    776:                        {
1.297     paf       777:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    778:                                Value& value=*new VBool(a.as_string() > b.as_string());
                    779:                                stack.push(value);
1.58      paf       780:                                break;
                    781:                        }
1.55      paf       782:                case OP_STR_LE: 
1.58      paf       783:                        {
1.297     paf       784:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    785:                                Value& value=*new VBool(a.as_string() <= b.as_string());
                    786:                                stack.push(value);
1.58      paf       787:                                break;
                    788:                        }
1.55      paf       789:                case OP_STR_GE: 
1.54      paf       790:                        {
1.297     paf       791:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    792:                                Value& value=*new VBool(a.as_string() >= b.as_string());
                    793:                                stack.push(value);
1.58      paf       794:                                break;
                    795:                        }
                    796:                case OP_STR_EQ: 
                    797:                        {
1.297     paf       798:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    799:                                Value& value=*new VBool(a.as_string() == b.as_string());
                    800:                                stack.push(value);
1.58      paf       801:                                break;
                    802:                        }
                    803:                case OP_STR_NE: 
                    804:                        {
1.297     paf       805:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    806:                                Value& value=*new VBool(a.as_string() != b.as_string());
                    807:                                stack.push(value);
1.103     paf       808:                                break;
                    809:                        }
                    810:                case OP_IS:
                    811:                        {
1.297     paf       812:                                Value& b=stack.pop().value();  Value& a=stack.pop().value();
                    813:                                Value& value=*new VBool(a.is(b.as_string().cstr()));
                    814:                                stack.push(value);
1.28      paf       815:                                break;
                    816:                        }
                    817: 
1.11      paf       818:                default:
1.223     paf       819:                        throw Exception(0,
1.67      paf       820:                                0,
1.297     paf       821:                                "invalid opcode %d", opcode); 
1.11      paf       822:                }
                    823:        }
1.306     paf       824:        } catch(const Exception&) {
1.297     paf       825:                // record it to stack trace
1.301     paf       826:                if(debug_name)
                    827:                        exception_trace.push(Trace(debug_name, debug_origin));
1.297     paf       828:                rethrow;
                    829:        }
1.1       paf       830: }
1.17      paf       831: 
1.292     paf       832: /**
                    833:        @todo cache|prepare junctions
                    834:        @bug ^superbase:method would dynamically call ^base:method if there is any
                    835: */
1.297     paf       836: Value& Request::get_element(Value& ncontext, const String& name, bool can_call_operator) {
                    837:        Value* value=0;
1.249     paf       838:        if(can_call_operator) {
1.297     paf       839:                if(Method* method=main_class.get_method(name)) // looking operator of that name FIRST
1.307     paf       840:                        value=new VJunction(new Junction(main_class, method));
1.249     paf       841:        }
                    842:        if(!value) {
                    843:                if(!wcontext->get_constructing() // not constructing
                    844:                        && wcontext->get_somebody_entered_some_class() ) // ^class:method
1.297     paf       845:                        if(VStateless_class *called_class=ncontext.get_class())
1.249     paf       846:                                if(VStateless_class *read_class=rcontext->get_class())
                    847:                                        if(read_class->derived_from(*called_class)) // current derived from called
1.297     paf       848:                                                if(Value* base=get_self().base()) { // doing DYNAMIC call
1.290     paf       849:                                                        Temp_derived temp_derived(*base, 0); // temporarily prevent go-back-down virtual calls
                    850:                                                        value=base->get_element(name, *base, false); // virtual-up lookup starting from parent
1.289     paf       851:                                                        goto value_ready;
1.249     paf       852:                                                }
                    853:        }
1.216     paf       854:        if(!value)
1.297     paf       855:                value=ncontext.get_element(name, ncontext, false);
1.291     paf       856: 
                    857:        if(value && wcontext->get_constructing())
1.297     paf       858:                if(Junction* junction=value->get_junction()) {
                    859:                        if(junction->self.get_class()!=&ncontext)
1.291     paf       860:                                throw Exception("parser.runtime",
                    861:                                        &name,
1.297     paf       862:                                        "constructor must be declared in class '%s'", 
                    863:                                                ncontext.get_class()->name_cstr());
1.291     paf       864:                }
1.249     paf       865: 
1.289     paf       866: value_ready:
1.284     paf       867:        if(value)
1.294     paf       868:                value=&process_to_value(*value); // process possible code-junction
1.284     paf       869:        else
1.297     paf       870:                value=new VVoid;
1.63      paf       871: 
1.297     paf       872:        return *value;
1.309     paf       873: }
                    874: 
                    875: void Request::put_element(Value& ncontext, const String& name, Value& value) {
                    876:        // put_element can return property-setting-junction
1.309.2.3! paf       877:        if(const Junction* junction=ncontext.put_element(ncontext, name, &value))
1.309     paf       878:                if(junction!=PUT_ELEMENT_REPLACED_ELEMENT) {
                    879:                        // process it
                    880:                        ArrayString* params_names=junction->method->params_names;
                    881:                        int param_count=params_names? params_names->count(): 0;
                    882:                        if(param_count!=1)
                    883:                                throw Exception("parser.runtime",
                    884:                                        0,
                    885:                                        "setter method must have ONE parameter (has %d parameters)", param_count);
                    886: 
                    887:                        VMethodFrame frame(*junction, method_frame/*caller*/);
                    888:                        frame.store_param(value);
                    889: 
                    890:                        frame.set_self(frame.junction.self);
                    891: 
                    892:                        VMethodFrame *saved_method_frame=method_frame;
                    893:                        Value* saved_rcontext=rcontext;
                    894:                        WContext *saved_wcontext=wcontext;
                    895: 
                    896:                        rcontext=wcontext=&frame;
                    897:                        method_frame=&frame;
                    898: 
                    899:                        // prevent non-string writes for better error reporting
                    900:                        wcontext->write(*method_frame);
                    901: 
                    902:                        recoursion_checked_execute(*frame.junction.method->parser_code); // parser code, execute it
                    903:                        // we don't need it StringOrValue result=wcontext->result();
                    904: 
                    905:                        method_frame=saved_method_frame;
                    906:                        wcontext=saved_wcontext;
                    907:                        rcontext=saved_rcontext;
                    908:                }
1.34      paf       909: }
1.70      paf       910: 
1.162     parser    911: /**    @param intercept_string
1.116     paf       912:        - true:
                    913:                they want result=string value, 
                    914:                possible object result goes to wcontext
                    915:        - false:
                    916:                they want any result[string|object]
                    917:                nothing goes to wcontext.
1.125     paf       918:                used in @c (expression) params evaluation
1.224     paf       919: 
                    920:     using the fact it's either string_ or value_ result requested to speed up checkes
1.116     paf       921: */
1.229     paf       922: StringOrValue Request::process(Value& input_value, bool intercept_string) {
1.297     paf       923:        Junction* junction=input_value.get_junction();
1.307     paf       924:        if(junction) {
                    925:                if(junction->is_getter) { // is it a getter-junction?
                    926:                        // process it
                    927: 
                    928:                        VMethodFrame frame(*junction, method_frame/*caller*/);
                    929:                        if(junction->method->params_names)
                    930:                                throw Exception("parser.runtime",
                    931:                                        0,
                    932:                                        "getter method must have no parameters");
                    933: 
                    934:                        frame.set_self(frame.junction.self);
                    935: 
                    936:                        VMethodFrame *saved_method_frame=method_frame;
                    937:                        Value* saved_rcontext=rcontext;
                    938:                        WContext *saved_wcontext=wcontext;
                    939: 
                    940:                        rcontext=wcontext=&frame;
                    941:                        method_frame=&frame;
                    942: 
                    943:                        recoursion_checked_execute(*frame.junction.method->parser_code); // parser code, execute it
                    944:                        StringOrValue result=wcontext->result();
                    945: 
                    946:                        method_frame=saved_method_frame;
                    947:                        wcontext=saved_wcontext;
                    948:                        rcontext=saved_rcontext;
                    949: 
                    950:                        return result;
                    951:                }
                    952: 
                    953:                if(junction->code) { // is it a code-junction?
                    954:                        // process it
                    955:                        StringOrValue result;
1.157     parser    956: #ifdef DEBUG_EXECUTE
1.307     paf       957:                        debug_printf(sapi_info, "ja->\n");
1.157     parser    958: #endif
1.238     paf       959: 
1.307     paf       960:                        if(!junction->method_frame)
                    961:                                throw Exception("parser.runtime",
1.240     paf       962:                                0,
                    963:                                "junction used outside of context");
                    964: 
1.307     paf       965:                        VMethodFrame *saved_method_frame=method_frame;  
                    966:                        Value* saved_rcontext=rcontext;  
                    967:                        WContext *saved_wcontext=wcontext;
                    968: 
                    969:                        method_frame=junction->method_frame;
                    970:                        rcontext=junction->rcontext;
                    971: 
                    972:                        // for expression method params
                    973:                        // wcontext is set 0
                    974:                        // using the fact in decision "which wwrapper to use"
                    975:                        bool using_code_frame=intercept_string && junction->wcontext;
                    976:                        if(using_code_frame) {
                    977:                                // almost plain wwrapper about junction wcontext, 
                    978:                                // BUT intercepts string writes
                    979:                                VCodeFrame local(*junction->wcontext, junction->wcontext);
                    980:                                wcontext=&local;
                    981: 
                    982:                                // execute it
                    983:                                recoursion_checked_execute(*junction->code);
                    984: 
                    985:                                // CodeFrame soul:
                    986:                                //   string writes were intercepted
                    987:                                //   returning them as the result of getting code-junction
                    988:                                result.set_string(*wcontext->get_string());
                    989:                        } else {
                    990:                                // plain wwrapper
                    991:                                WWrapper local(0/*empty*/, wcontext);
                    992:                                wcontext=&local;
                    993: 
                    994:                                // execute it
                    995:                                recoursion_checked_execute(*junction->code);
                    996: 
                    997:                                result=wcontext->result();
                    998:                        }
                    999: 
                   1000:                        wcontext=saved_wcontext;
                   1001:                        rcontext=saved_rcontext;
                   1002:                        method_frame=saved_method_frame;
1.207     paf      1003: 
1.157     parser   1004: #ifdef DEBUG_EXECUTE
1.307     paf      1005:                        debug_printf(sapi_info, "<-ja returned");
1.157     parser   1006: #endif
1.307     paf      1007:                        return result;
                   1008:                }
                   1009: 
                   1010:                // it is then method-junction, do not explode it
                   1011:                // just return it as we do for usual objects
                   1012:        }       
                   1013: 
                   1014:        return input_value;
1.85      paf      1015: }
                   1016: 
1.298     paf      1017: StringOrValue Request::execute_method(VMethodFrame& amethod_frame, const Method& method) {
1.257     paf      1018:        VMethodFrame *saved_method_frame=method_frame;  
1.297     paf      1019:        Value* saved_rcontext=rcontext;  
1.257     paf      1020:        WContext *saved_wcontext=wcontext;
1.99      paf      1021:        
                   1022:        // initialize contexts
1.286     paf      1023:        rcontext=wcontext=method_frame=&amethod_frame;
1.99      paf      1024:        
                   1025:        // execute!     
                   1026:        execute(*method.parser_code);
                   1027:        
                   1028:        // result
1.298     paf      1029:        StringOrValue result=wcontext->result();
1.208     paf      1030:        
1.257     paf      1031:        wcontext=saved_wcontext;
                   1032:        rcontext=saved_rcontext;
                   1033:        method_frame=saved_method_frame;
1.242     paf      1034:        
                   1035:        // return
                   1036:        return result;
1.208     paf      1037: }
                   1038: 
1.297     paf      1039: const String* Request::execute_method(Value& aself, 
                   1040:                                      const Method& method, VString* optional_param,
                   1041:                                      bool do_return_string) {
1.257     paf      1042:        VMethodFrame *saved_method_frame=method_frame;  
1.297     paf      1043:        Value* saved_rcontext=rcontext;  
1.257     paf      1044:        WContext *saved_wcontext=wcontext;
1.208     paf      1045:        
1.307     paf      1046:        Junction local_junction(aself, &method);
1.297     paf      1047:        VMethodFrame local_frame(local_junction, method_frame/*caller*/);
1.242     paf      1048:        if(optional_param && local_frame.can_store_param()) {
1.297     paf      1049:                local_frame.store_param(*optional_param);
1.242     paf      1050:                local_frame.fill_unspecified_params();
                   1051:        }
1.285     paf      1052:        local_frame.set_self(aself);
1.257     paf      1053:        rcontext=wcontext=method_frame=&local_frame; 
1.246     paf      1054: 
                   1055:        // prevent non-string writes for better error reporting
1.297     paf      1056:        if(do_return_string)
1.246     paf      1057:                wcontext->write(local_frame);
1.208     paf      1058:        
                   1059:        // execute!     
                   1060:        execute(*method.parser_code);
                   1061:        
                   1062:        // result
1.297     paf      1063:        const String* result=0;
                   1064:        if(do_return_string)
                   1065:                result=&wcontext->result().as_string();
1.99      paf      1066:        
1.257     paf      1067:        wcontext=saved_wcontext;
                   1068:        rcontext=saved_rcontext;
                   1069:        method_frame=saved_method_frame;
1.297     paf      1070: 
                   1071:        return result;
1.242     paf      1072: }
                   1073: 
1.297     paf      1074: Request::Execute_nonvirtual_method_result 
                   1075: Request::execute_nonvirtual_method(VStateless_class& aclass, 
                   1076:                                   const String& method_name, VString* optional_param,
                   1077:                                   bool do_return_string) {
                   1078:        Execute_nonvirtual_method_result result;
                   1079:        result.method=aclass.get_method(method_name);
                   1080:        if(result.method)
                   1081:                result.string=execute_method(aclass, *result.method, optional_param, 
                   1082:                        do_return_string);
                   1083:        return result;
1.99      paf      1084: }
                   1085: 
1.297     paf      1086: const String* Request::execute_virtual_method(Value& aself, 
                   1087:                                              const String& method_name) {
                   1088:        if(Value* value=aself.get_element(method_name, aself, false))
                   1089:                if(Junction* junction=value->get_junction())
                   1090:                        if(const Method *method=junction->method) 
                   1091:                                return execute_method(aself, *method, 0/*no params*/, true);
1.188     parser   1092:                        
1.176     parser   1093:        return 0;
                   1094: }

E-mail: