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

1.1       paf         1: /*
1.82    ! paf         2:   $Id: execute.C,v 1.81 2001/03/09 08:28:34 paf Exp $
1.1       paf         3: */
                      4: 
1.8       paf         5: #include "pa_array.h" 
1.1       paf         6: #include "code.h"
1.11      paf         7: #include "pa_request.h"
1.15      paf         8: #include "pa_vstring.h"
1.22      paf         9: #include "pa_vhash.h"
1.23      paf        10: #include "pa_vunknown.h"
1.34      paf        11: #include "pa_vcframe.h"
                     12: #include "pa_vmframe.h"
1.38      paf        13: #include "pa_vobject.h"
1.49      paf        14: #include "pa_vdouble.h"
1.54      paf        15: #include "pa_vbool.h"
1.1       paf        16: 
                     17: #include <stdio.h>
                     18: 
1.24      paf        19: #define PUSH(value) stack.push(value)
                     20: #define POP() static_cast<Value *>(stack.pop())
1.32      paf        21: #define POP_NAME() static_cast<Value *>(stack.pop())->as_string()
1.24      paf        22: 
1.11      paf        23: 
1.1       paf        24: char *opcode_name[]={
1.49      paf        25:        // literals
1.66      paf        26:        "VALUE",  "CODE__STORE_PARAM",
1.49      paf        27: 
                     28:        // actions
1.51      paf        29:        "WITH_SELF",    "WITH_ROOT",    "WITH_READ",    "WITH_WRITE",
1.66      paf        30:        "GET_CLASS",
1.80      paf        31:        "CONSTRUCT_VALUE",  "CONSTRUCT_DOUBLE",
1.18      paf        32:        "WRITE",
                     33:        "GET_ELEMENT",  "GET_ELEMENT__WRITE",
1.1       paf        34:        "CREATE_EWPOOL",        "REDUCE_EWPOOL",
                     35:        "CREATE_RWPOOL",        "REDUCE_RWPOOL",
1.49      paf        36:        "CREATE_SWPOOL",        "REDUCE_SWPOOL",
1.1       paf        37:        "GET_METHOD_FRAME",
                     38:        "STORE_PARAM",
1.51      paf        39:        "CALL",
1.49      paf        40: 
                     41:        // expression ops: unary
                     42:        "NEG", "INV", "NOT", "DEF", "IN", "FEXISTS",
                     43:        // expression ops: binary
                     44:        "SUB", "ADD", "MUL", "DIV", "MOD",
1.56      paf        45:        "BIN_AND", "BIN_OR", "BIN_XOR",
                     46:        "LOG_AND", "LOG_OR", "LOG_XOR",
1.49      paf        47:        "NUM_LT", "NUM_GT", "NUM_LE", "NUM_GE", "NUM_EQ", "NUM_NE",
1.55      paf        48:        "STR_LT", "STR_GT", "STR_LE", "STR_GE", "STR_EQ", "STR_NE"
1.1       paf        49: };
                     50: 
1.9       paf        51: void dump(int level, const Array& ops) {
1.23      paf        52:        if(0){
                     53:                int size=ops.size();
1.46      paf        54:                //fprintf(stderr, "size=%d\n", size);
1.23      paf        55:                for(int i=0; i<size; i++) {
                     56:                        Operation op;
                     57:                        op.cast=ops.quick_get(i);
1.46      paf        58:                        fprintf(stderr, "%8X\n", op.cast);
1.23      paf        59:                }
                     60:        }
                     61: 
1.9       paf        62:        int size=ops.size();
1.46      paf        63:        //fprintf(stderr, "size=%d\n", size);
1.1       paf        64:        for(int i=0; i<size; i++) {
1.23      paf        65:                Operation op;
                     66:                op.cast=ops.quick_get(i);
1.46      paf        67:                fprintf(stderr, "%*s%s", level*4, "", opcode_name[op.code]);
1.1       paf        68: 
1.52      paf        69:                if(op.code==OP_VALUE) {
                     70:                        Value *value=static_cast<Value *>(ops.quick_get(++i));
                     71:                        fprintf(stderr, " \"%s\" %s", value->get_string()->cstr(), value->type());
1.15      paf        72:                }
1.46      paf        73:                fprintf(stderr, "\n");
1.1       paf        74: 
1.65      paf        75:                if(op.code==OP_CODE__STORE_PARAM) {
1.10      paf        76:                        const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i));
1.9       paf        77:                        dump(level+1, *local_ops);
1.1       paf        78:                }
                     79:        }
1.60      paf        80:        fflush(stderr);
1.1       paf        81: }
                     82: 
1.32      paf        83: void Request::execute(const Array& ops) {
1.30      paf        84:        if(1) {
1.51      paf        85:                fputs("source----------------------------\n", stderr);
1.12      paf        86:                dump(0, ops);
1.51      paf        87:                fputs("execution-------------------------\n", stderr);
1.12      paf        88:        }
                     89: 
1.11      paf        90:        int size=ops.size();
1.46      paf        91:        //fprintf(stderr, "size=%d\n", size);
1.11      paf        92:        for(int i=0; i<size; i++) {
1.23      paf        93:                Operation op;
                     94:                op.cast=ops.quick_get(i);
1.80      paf        95:                fprintf(stderr, "%d:%s", stack.top_index()+1, opcode_name[op.code]); fflush(stderr);
1.11      paf        96: 
1.23      paf        97:                switch(op.code) {
1.51      paf        98:                // param in next instruction
1.52      paf        99:                case OP_VALUE:
1.32      paf       100:                        {
1.52      paf       101:                                Value *value=static_cast<Value *>(ops.quick_get(++i));
                    102:                                fprintf(stderr, " \"%s\" %s", value->get_string()->cstr(), value->type());
                    103:                                PUSH(value);
1.32      paf       104:                                break;
                    105:                        }
1.65      paf       106:                case OP_CODE__STORE_PARAM:
1.32      paf       107:                        {
1.73      paf       108:                                VMethodFrame *frame=static_cast<VMethodFrame *>(stack.top_value());
1.65      paf       109:                                // code
1.32      paf       110:                                const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i));
1.46      paf       111:                                fprintf(stderr, " (%d)\n", local_ops->size());
1.38      paf       112:                                dump(1, *local_ops);
1.63      paf       113:                                
1.32      paf       114:                                Junction& j=*NEW Junction(pool(), 
1.45      paf       115:                                        *self, 0, 0,
1.64      paf       116:                                        root, frame, frame, local_ops);
1.32      paf       117:                                
                    118:                                Value *value=NEW VJunction(j);
1.81      paf       119:                                ///value->set_name(frame->name());
1.65      paf       120: 
                    121:                                // store param
                    122:                                frame->store_param(value);
1.32      paf       123:                                break;
                    124:                        }
1.66      paf       125:                case OP_GET_CLASS:
1.38      paf       126:                        {
1.82    ! paf       127:                                const String& name=POP_NAME();
1.66      paf       128:                                VClass *vclass=static_cast<VClass *>(classes().get(name));
                    129:                                if(!vclass) 
                    130:                                        THROW(0,0,
                    131:                                                &name,
                    132:                                                ": undefined class"); 
                    133: 
                    134:                                PUSH(vclass);
1.38      paf       135:                                break;
                    136:                        }
1.32      paf       137:                        
1.51      paf       138:                // OP_WITH
1.37      paf       139:                case OP_WITH_SELF: 
                    140:                        {
                    141:                                PUSH(self);
                    142:                                break;
                    143:                        }
                    144:                case OP_WITH_ROOT: 
1.11      paf       145:                        {
1.37      paf       146:                                PUSH(root);
1.13      paf       147:                                break;
1.11      paf       148:                        }
1.15      paf       149:                case OP_WITH_READ: 
                    150:                        {
1.24      paf       151:                                PUSH(rcontext);
1.20      paf       152:                                break;
                    153:                        }
1.37      paf       154:                case OP_WITH_WRITE: 
1.20      paf       155:                        {
1.37      paf       156:                                PUSH(wcontext);
1.20      paf       157:                                break;
                    158:                        }
1.37      paf       159:                        
1.51      paf       160:                // OTHER ACTIONS BUT WITHs
1.80      paf       161:                case OP_CONSTRUCT_VALUE:
1.20      paf       162:                        {
1.37      paf       163:                                Value *value=POP();
1.82    ! paf       164:                                const String& name=POP_NAME();
1.37      paf       165:                                Value *ncontext=POP();
1.81      paf       166:                                ncontext->put_element(name, value);
1.37      paf       167:                                value->set_name(name);
1.15      paf       168:                                break;
                    169:                        }
1.80      paf       170:                case OP_CONSTRUCT_EXPR:
                    171:                        {
                    172:                                Value *value=POP();
1.82    ! paf       173:                                const String& name=POP_NAME();
1.80      paf       174:                                Value *ncontext=POP();
1.81      paf       175:                                ncontext->put_element(name, value->get_expr_result());
1.80      paf       176:                                value->set_name(name);
                    177:                                break;
                    178:                        }
1.18      paf       179:                case OP_WRITE:
1.13      paf       180:                        {
1.24      paf       181:                                Value *value=POP();
1.70      paf       182:                                wcontext->write(*value);
1.13      paf       183:                                break;
1.14      paf       184:                        }
1.13      paf       185:                        
1.15      paf       186:                case OP_GET_ELEMENT:
1.11      paf       187:                        {
1.17      paf       188:                                Value *value=get_element();
1.24      paf       189:                                PUSH(value);
1.17      paf       190:                                break;
                    191:                        }
                    192: 
1.18      paf       193:                case OP_GET_ELEMENT__WRITE:
1.17      paf       194:                        {
                    195:                                Value *value=get_element();
1.70      paf       196:                                wcontext->write(*value);
1.17      paf       197:                                break;
                    198:                        }
                    199: 
1.32      paf       200: 
1.17      paf       201:                case OP_CREATE_EWPOOL:
                    202:                        {
1.24      paf       203:                                PUSH(wcontext);
1.43      paf       204:                                wcontext=NEW WWrapper(pool(), 0 /* empty */, true /* constructing */);
1.17      paf       205:                                break;
                    206:                        }
                    207:                case OP_REDUCE_EWPOOL:
                    208:                        {
1.36      paf       209:                                Value *value=wcontext->result();
1.25      paf       210:                                wcontext=static_cast<WContext *>(POP());
1.24      paf       211:                                PUSH(value);
1.13      paf       212:                                break;
1.15      paf       213:                        }
1.13      paf       214:                        
1.26      paf       215:                case OP_CREATE_RWPOOL:
                    216:                        {
                    217:                                Value *ncontext=POP();
                    218:                                PUSH(rcontext);
                    219:                                rcontext=ncontext;
                    220:                                PUSH(wcontext);
1.43      paf       221:                                wcontext=NEW WWrapper(pool(), ncontext, false /* not constructing */);
1.26      paf       222:                                break;
                    223:                        }
                    224:                case OP_REDUCE_RWPOOL:
                    225:                        {
1.82    ! paf       226:                                const String *string=wcontext->get_string();
1.80      paf       227:                                Value *value;
                    228:                                if(string)
                    229:                                        value=NEW VString(*string);
                    230:                                else
                    231:                                        value=NEW VUnknown(pool());
1.26      paf       232:                                wcontext=static_cast<WContext *>(POP());
                    233:                                rcontext=POP();
                    234:                                PUSH(value);
                    235:                                break;
                    236:                        }
1.49      paf       237:                case OP_CREATE_SWPOOL:
                    238:                        {
                    239:                                PUSH(wcontext);
1.50      paf       240:                                wcontext=NEW WWrapper(pool(), 0 /* empty */, false /* not constructing */);
1.49      paf       241:                                break;
                    242:                        }
                    243:                case OP_REDUCE_SWPOOL:
                    244:                        {
                    245:                                // from "$a $b" part of expression taking only string value,
                    246:                                // ignoring any other content of wcontext
1.82    ! paf       247:                                const String *string=wcontext->get_string();
1.80      paf       248:                                Value *value;
                    249:                                if(string)
                    250:                                        value=NEW VString(*string);
                    251:                                else
                    252:                                        NEW VUnknown(pool());
1.50      paf       253:                                wcontext=static_cast<WContext *>(POP());
1.49      paf       254:                                PUSH(value);
                    255:                                break;
                    256:                        }
                    257: 
1.51      paf       258:                // CALL
1.28      paf       259:                case OP_GET_METHOD_FRAME:
                    260:                        {
1.32      paf       261:                                Value *value=POP();
1.70      paf       262:                                // info: this one's always method-junction, not a code-junction
1.32      paf       263:                                Junction *junction=value->get_junction();
1.31      paf       264:                                if(!junction)
1.28      paf       265:                                        THROW(0,0,
1.42      paf       266:                                                &value->name(),
1.39      paf       267:                                                "type is '%s', can not call it (must be method or junction)",
1.38      paf       268:                                                        value->type()); 
1.70      paf       269: 
1.34      paf       270:                                VMethodFrame *frame=NEW VMethodFrame(pool(), *junction);
1.63      paf       271:                                frame->set_name(junction->self.name());
1.28      paf       272:                                PUSH(frame);
                    273:                                break;
                    274:                        }
                    275:                case OP_STORE_PARAM:
                    276:                        {
                    277:                                Value *value=POP();
1.73      paf       278:                                VMethodFrame *frame=static_cast<VMethodFrame *>(stack.top_value());
1.28      paf       279:                                frame->store_param(value);
1.29      paf       280:                                break;
                    281:                        }
                    282: 
                    283:                case OP_CALL:
                    284:                        {
1.46      paf       285:                                fprintf(stderr, "->\n");
1.34      paf       286:                                VMethodFrame *frame=static_cast<VMethodFrame *>(POP());
                    287:                                frame->fill_unspecified_params();
1.45      paf       288:                                PUSH(self);  
                    289:                                PUSH(root);  
                    290:                                PUSH(rcontext);  
                    291:                                PUSH(wcontext); 
                    292:                                
1.38      paf       293:                                VClass *called_class=frame->junction.self.get_class();
1.74      paf       294:                                // is context object or class & is it my class or my parent's class?
                    295:                                VClass *read_class=rcontext->get_class();
                    296:                                if(read_class && read_class->is_or_derived_from(*called_class)) // yes
                    297:                                        self=rcontext; // class dynamic call
1.75      paf       298:                                else // no, not me or relative of mine (total stranger)
                    299:                                        if(wcontext->constructing()) {  // constructing?
                    300:                                                // yes, constructor call: $some(^class:method(..))
1.80      paf       301:                                                self=NEW VObject(pool(), *called_class);
1.74      paf       302:                                                frame->write(*self);
1.75      paf       303:                                        } else 
                    304:                                                self=&frame->junction.self; // no, static or simple dynamic call
                    305: 
1.45      paf       306:                                frame->set_self(*self);
1.29      paf       307:                                root=rcontext=wcontext=frame;
1.47      paf       308:                                {
1.48      paf       309:                                        // take object or class from any wrappers
                    310:                                        VAliased *aliased=self->get_aliased();
                    311:                                        // substitute class alias to the class they are called AS
1.47      paf       312:                                        Temp_alias temp_alias(*aliased, *frame->junction.vclass);
1.68      paf       313: 
1.69      paf       314:                                        Method& method=*frame->junction.method;
1.80      paf       315:                                        if(method.native_code) { // native code?
                    316:                                                method.check_actual_numbered_params(frame->numbered_params());
1.70      paf       317:                                                (*method.native_code)(*this, frame->numbered_params()); // execute it
1.80      paf       318:                                        } else // parser code
1.69      paf       319:                                                execute(*method.parser_code); // execute it
1.47      paf       320:                                }
1.36      paf       321:                                Value *value=wcontext->result();
1.45      paf       322: 
                    323:                                wcontext=static_cast<WContext *>(POP());  
                    324:                                rcontext=POP();  
                    325:                                root=POP();  
                    326:                                self=static_cast<VAliased *>(POP());
1.62      paf       327: 
1.61      paf       328:                                PUSH(value);
1.46      paf       329:                                fprintf(stderr, "<-returned");
1.49      paf       330:                                break;
                    331:                        }
                    332: 
1.55      paf       333:                // expression ops: unary
                    334:                case OP_NEG:
                    335:                        {
                    336:                                Value *operand=POP();
1.80      paf       337:                                Value *value=NEW VDouble(pool(), -operand->get_double());
1.55      paf       338:                                PUSH(value);
                    339:                                break;
                    340:                        }
                    341:                case OP_INV:
                    342:                        {
                    343:                                Value *operand=POP();
1.80      paf       344:                                Value *value=NEW VDouble(pool(), ~static_cast<int>(operand->get_double()));
1.55      paf       345:                                PUSH(value);
                    346:                                break;
                    347:                        }
                    348:                case OP_NOT:
                    349:                        {
                    350:                                Value *operand=POP();
1.78      paf       351:                                Value *value=NEW VBool(pool(), !operand->get_bool());
1.55      paf       352:                                PUSH(value);
                    353:                                break;
                    354:                        }
1.62      paf       355:                case OP_DEF:
                    356:                        {
                    357:                                Value *operand=POP();
1.78      paf       358:                                Value *value=NEW VBool(pool(), operand->get_defined());
1.62      paf       359:                                PUSH(value);
                    360:                                break;
                    361:                        }
                    362:                case OP_IN:
                    363:                        {
                    364:                                Value *operand=POP();
1.78      paf       365:                                Value *value=NEW VBool(pool(), true/*TODO*/);
1.62      paf       366:                                PUSH(value);
                    367:                                break;
                    368:                        }
                    369:                case OP_FEXISTS:
                    370:                        {
                    371:                                Value *operand=POP();
1.78      paf       372:                                Value *value=NEW VBool(pool(), true/*TODO*/);
1.62      paf       373:                                PUSH(value);
                    374:                                break;
                    375:                        }
1.55      paf       376: 
                    377:                // expression ops: binary
                    378:                case OP_SUB: 
1.53      paf       379:                        {
1.61      paf       380:                                Value *b=POP();  Value *a=POP();
1.80      paf       381:                                Value *value=NEW VDouble(pool(), a->get_double() - b->get_double());
1.53      paf       382:                                PUSH(value);
                    383:                                break;
                    384:                        }
1.55      paf       385:                case OP_ADD: 
1.53      paf       386:                        {
1.61      paf       387:                                Value *b=POP();  Value *a=POP();
1.80      paf       388:                                Value *value=NEW VDouble(pool(), a->get_double() + b->get_double());
1.53      paf       389:                                PUSH(value);
                    390:                                break;
                    391:                        }
1.49      paf       392:                case OP_MUL: 
                    393:                        {
1.61      paf       394:                                Value *b=POP();  Value *a=POP();
1.80      paf       395:                                Value *value=NEW VDouble(pool(), a->get_double() * b->get_double());
1.53      paf       396:                                PUSH(value);
                    397:                                break;
                    398:                        }
                    399:                case OP_DIV: 
                    400:                        {
1.61      paf       401:                                Value *b=POP();  Value *a=POP();
1.80      paf       402:                                Value *value=NEW VDouble(pool(), a->get_double() / b->get_double());
1.54      paf       403:                                PUSH(value);
                    404:                                break;
                    405:                        }
1.55      paf       406:                case OP_MOD: 
                    407:                        {
1.61      paf       408:                                Value *b=POP();  Value *a=POP();
1.78      paf       409:                                Value *value=NEW VDouble(pool(), 
1.55      paf       410:                                        static_cast<int>(a->get_double()) %
1.78      paf       411:                                        static_cast<int>(b->get_double()));
1.55      paf       412:                                PUSH(value);
                    413:                                break;
                    414:                        }
                    415:                case OP_BIN_AND:
1.54      paf       416:                        {
1.61      paf       417:                                Value *b=POP();  Value *a=POP();
1.78      paf       418:                                Value *value=NEW VDouble(pool(), 
1.55      paf       419:                                        static_cast<int>(a->get_double()) &
1.78      paf       420:                                        static_cast<int>(b->get_double()));
1.54      paf       421:                                PUSH(value);
                    422:                                break;
                    423:                        }
1.55      paf       424:                case OP_BIN_OR:
1.54      paf       425:                        {
1.61      paf       426:                                Value *b=POP();  Value *a=POP();
1.78      paf       427:                                Value *value=NEW VDouble(pool(), 
1.55      paf       428:                                        static_cast<int>(a->get_double()) |
1.78      paf       429:                                        static_cast<int>(b->get_double()));
1.55      paf       430:                                PUSH(value);
                    431:                                break;
                    432:                        }
1.56      paf       433:                case OP_BIN_XOR:
                    434:                        {
1.61      paf       435:                                Value *b=POP();  Value *a=POP();
1.78      paf       436:                                Value *value=NEW VDouble(pool(), 
1.56      paf       437:                                        static_cast<int>(a->get_double()) ^
1.78      paf       438:                                        static_cast<int>(b->get_double()));
1.56      paf       439:                                PUSH(value);
                    440:                                break;
                    441:                        }
1.55      paf       442:                case OP_LOG_AND:
                    443:                        {
1.61      paf       444:                                Value *b=POP();  Value *a=POP();
1.78      paf       445:                                Value *value=NEW VBool(pool(), a->get_bool() && b->get_bool());
1.55      paf       446:                                PUSH(value);
                    447:                                break;
                    448:                        }
                    449:                case OP_LOG_OR:
                    450:                        {
1.61      paf       451:                                Value *b=POP();  Value *a=POP();
1.78      paf       452:                                Value *value=NEW VBool(pool(), a->get_bool() || b->get_bool());
1.56      paf       453:                                PUSH(value);
                    454:                                break;
                    455:                        }
                    456:                case OP_LOG_XOR:
                    457:                        {
1.61      paf       458:                                Value *b=POP();  Value *a=POP();
1.78      paf       459:                                Value *value=NEW VBool(pool(), a->get_bool() ^ b->get_bool());
1.55      paf       460:                                PUSH(value);
                    461:                                break;
                    462:                        }
                    463:                case OP_NUM_LT: 
                    464:                        {
1.61      paf       465:                                Value *b=POP();  Value *a=POP();
1.78      paf       466:                                Value *value=NEW VBool(pool(), a->get_double() < b->get_double());
1.55      paf       467:                                PUSH(value);
                    468:                                break;
                    469:                        }
                    470:                case OP_NUM_GT: 
                    471:                        {
1.61      paf       472:                                Value *b=POP();  Value *a=POP();
1.78      paf       473:                                Value *value=NEW VBool(pool(), a->get_double() > b->get_double());
1.55      paf       474:                                PUSH(value);
                    475:                                break;
                    476:                        }
                    477:                case OP_NUM_LE: 
                    478:                        {
1.61      paf       479:                                Value *b=POP();  Value *a=POP();
1.78      paf       480:                                Value *value=NEW VBool(pool(), a->get_double() <= b->get_double());
1.55      paf       481:                                PUSH(value);
                    482:                                break;
                    483:                        }
                    484:                case OP_NUM_GE: 
                    485:                        {
1.61      paf       486:                                Value *b=POP();  Value *a=POP();
1.78      paf       487:                                Value *value=NEW VBool(pool(), a->get_double() >= b->get_double());
1.55      paf       488:                                PUSH(value);
                    489:                                break;
                    490:                        }
                    491:                case OP_NUM_EQ: 
                    492:                        {
1.61      paf       493:                                Value *b=POP();  Value *a=POP();
1.78      paf       494:                                Value *value=NEW VBool(pool(), a->get_double() == b->get_double());
1.55      paf       495:                                PUSH(value);
                    496:                                break;
                    497:                        }
                    498:                case OP_NUM_NE: 
                    499:                        {
1.61      paf       500:                                Value *b=POP();  Value *a=POP();
1.78      paf       501:                                Value *value=NEW VBool(pool(), a->get_double() != b->get_double());
1.54      paf       502:                                PUSH(value);
                    503:                                break;
                    504:                        }
1.58      paf       505:                case OP_STR_LT: 
                    506:                        {
1.61      paf       507:                                Value *b=POP();  Value *a=POP();
1.78      paf       508:                                Value *value=NEW VBool(pool(), a->as_string() < b->as_string());
1.58      paf       509:                                PUSH(value);
                    510:                                break;
                    511:                        }
                    512:                case OP_STR_GT: 
                    513:                        {
1.61      paf       514:                                Value *b=POP();  Value *a=POP();
1.78      paf       515:                                Value *value=NEW VBool(pool(), a->as_string() > b->as_string());
1.58      paf       516:                                PUSH(value);
                    517:                                break;
                    518:                        }
1.55      paf       519:                case OP_STR_LE: 
1.58      paf       520:                        {
1.61      paf       521:                                Value *b=POP();  Value *a=POP();
1.78      paf       522:                                Value *value=NEW VBool(pool(), a->as_string() <= b->as_string());
1.58      paf       523:                                PUSH(value);
                    524:                                break;
                    525:                        }
1.55      paf       526:                case OP_STR_GE: 
1.54      paf       527:                        {
1.61      paf       528:                                Value *b=POP();  Value *a=POP();
1.78      paf       529:                                Value *value=NEW VBool(pool(), a->as_string() >= b->as_string());
1.58      paf       530:                                PUSH(value);
                    531:                                break;
                    532:                        }
                    533:                case OP_STR_EQ: 
                    534:                        {
1.61      paf       535:                                Value *b=POP();  Value *a=POP();
1.78      paf       536:                                Value *value=NEW VBool(pool(), a->as_string() == b->as_string());
1.58      paf       537:                                PUSH(value);
                    538:                                break;
                    539:                        }
                    540:                case OP_STR_NE: 
                    541:                        {
1.61      paf       542:                                Value *b=POP();  Value *a=POP();
1.78      paf       543:                                Value *value=NEW VBool(pool(), a->as_string() != b->as_string());
1.49      paf       544:                                PUSH(value);
1.28      paf       545:                                break;
                    546:                        }
                    547: 
1.11      paf       548:                default:
1.67      paf       549:                        THROW(0,0,
                    550:                                0,
                    551:                                "unhandled '%s' opcode", opcode_name[op.code]); 
1.11      paf       552:                }
1.46      paf       553:                fprintf(stderr, "\n");
1.11      paf       554:        }
1.1       paf       555: }
1.17      paf       556: 
                    557: Value *Request::get_element() {
1.82    ! paf       558:        const String& name=POP_NAME();
1.24      paf       559:        Value *ncontext=POP();
1.32      paf       560:        Value *value=ncontext->get_element(name);
1.21      paf       561: 
1.76      paf       562:        if(value)
                    563:                value=&autocalc(*value); // autocalc possible code-junction
                    564:        else {
                    565:                value=NEW VUnknown(pool());
                    566:                value->set_name(name);
                    567:        }
1.63      paf       568: 
1.17      paf       569:        return value;
1.34      paf       570: }
1.70      paf       571: 
1.71      paf       572: Value& Request::autocalc(Value& value, bool make_string) {
1.70      paf       573:        Junction *junction=value.get_junction();
                    574:        if(junction && junction->code) { // is it a code-junction?
                    575:                // autocalc it
                    576:                fprintf(stderr, "ja->\n");
                    577:                PUSH(self);  
                    578:                PUSH(root);  
                    579:                PUSH(rcontext);  
                    580:                PUSH(wcontext);
                    581:                
1.71      paf       582:                WContext *frame;
                    583:                if(make_string) {
                    584:                        // almost plain wwrapper about junction wcontext, 
                    585:                        // BUT intercepts string writes
                    586:                        frame=NEW VCodeFrame(pool(), *junction->wcontext);  
                    587:                } else {
                    588:                        // plain wwrapper
                    589:                        frame=NEW WWrapper(pool(), 0 /* empty */, false /*not constructing*/);
                    590:                }
                    591:                
                    592:                wcontext=frame;
1.70      paf       593:                self=&junction->self;
                    594:                root=junction->root;
                    595:                rcontext=junction->rcontext;
                    596:                execute(*junction->code);
1.71      paf       597:                Value *result;
                    598:                if(make_string) {
                    599:                        // CodeFrame soul:
                    600:                        //   string writes were intercepted
                    601:                        //   returning them as the result of getting code-junction
                    602:                        result=NEW VString(*frame->get_string());
                    603:                } else 
                    604:                        result=frame->result();
1.70      paf       605:                
                    606:                wcontext=static_cast<WContext *>(POP());  
                    607:                rcontext=POP();  
                    608:                root=POP();  
                    609:                self=static_cast<VAliased *>(POP());
                    610:                
                    611:                fprintf(stderr, "<-ja returned");
1.71      paf       612:                return *result;
1.70      paf       613:        } else
                    614:                return value;
                    615: }

E-mail: