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

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

E-mail: