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

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

E-mail: