--- parser3/src/main/execute.C 2001/07/26 10:47:02 1.185 +++ parser3/src/main/execute.C 2001/09/26 10:32:26 1.192 @@ -2,10 +2,10 @@ Parser: executor part of request class. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: execute.C,v 1.192 2001/09/26 10:32:26 parser Exp $ */ -static const char *RCSId="$Id: execute.C,v 1.185 2001/07/26 10:47:02 parser Exp $"; #include "pa_opcode.h" #include "pa_array.h" @@ -24,7 +24,7 @@ static const char *RCSId="$Id: execute.C //#define DEBUG_EXECUTE -const uint ANTI_ENDLESS_EXECUTE_RECOURSION=500; +const uint ANTI_ENDLESS_EXECUTE_RECOURSION=400; #ifdef DEBUG_EXECUTE char *opcode_name[]={ @@ -32,7 +32,7 @@ char *opcode_name[]={ "VALUE", "CURLY_CODE__STORE_PARAM", "EXPR_CODE__STORE_PARAM", // actions - "WITH_SELF", "WITH_READ", "WITH_WRITE", + "WITH_ROOT", "WITH_SELF", "WITH_READ", "WITH_WRITE", "GET_CLASS", "CONSTRUCT_VALUE", "CONSTRUCT_EXPR", "CURLY_CODE__CONSTRUCT", "WRITE_VALUE", "WRITE_EXPR_RESULT", "STRING__WRITE", @@ -41,7 +41,7 @@ char *opcode_name[]={ "CREATE_SWPOOL", "REDUCE_SWPOOL", "GET_METHOD_FRAME", "STORE_PARAM", - "CALL_CONSTRUCTOR", "OP_CALL_METHOD", + "PREPARE_TO_CONSTRUCT_OBJECT", "CALL", // expression ops: unary "NEG", "INV", "NOT", "DEF", "IN", "FEXISTS", "DEXISTS", @@ -68,24 +68,13 @@ void debug_printf(Pool& pool, const char } void debug_dump(Pool& pool, int level, const Array& ops) { -/* { - int size=ops.quick_size(); - //debug_printf(pool, "size=%d\n", size); - for(int i=0; i(ops.quick_get(++i)); + Value *value=static_cast(i.next()); debug_printf(pool, "%*s%s" " \"%s\" %s", @@ -99,7 +88,7 @@ void debug_dump(Pool& pool, int level, c case OP_CURLY_CODE__STORE_PARAM: case OP_EXPR_CODE__STORE_PARAM: case OP_CURLY_CODE__CONSTRUCT: - const Array *local_ops=reinterpret_cast(ops.quick_get(++i)); + const Array *local_ops=reinterpret_cast(i.next()); debug_dump(pool, level+1, *local_ops); } } @@ -117,11 +106,10 @@ void Request::execute(const Array& ops) debug_printf(pool(), "execution-------------------------\n"); #endif - int size=ops.quick_size(); - //debug_printf(pool(), "size=%d\n", size); - for(int i=0; i(ops.quick_get(++i)); + Value *value=static_cast(i.next()); #ifdef DEBUG_EXECUTE debug_printf(pool(), " \"%s\" %s", value->get_string()->cstr(), value->type()); #endif @@ -142,7 +130,7 @@ void Request::execute(const Array& ops) { VMethodFrame *frame=static_cast(stack.top_value()); // code - const Array *local_ops=reinterpret_cast(ops.quick_get(++i)); + const Array *local_ops=reinterpret_cast(i.next()); #ifdef DEBUG_EXECUTE debug_printf(pool(), " (%d)\n", local_ops->size()); debug_dump(pool(), 1, *local_ops); @@ -184,6 +172,11 @@ void Request::execute(const Array& ops) } // OP_WITH + case OP_WITH_ROOT: + { + PUSH(root); + break; + } case OP_WITH_SELF: { PUSH(self); @@ -221,7 +214,7 @@ void Request::execute(const Array& ops) } case OP_CURLY_CODE__CONSTRUCT: { - const Array *local_ops=reinterpret_cast(ops.quick_get(++i)); + const Array *local_ops=reinterpret_cast(i.next()); #ifdef DEBUG_EXECUTE debug_printf(pool(), " (%d)\n", local_ops->size()); debug_dump(pool(), 1, *local_ops); @@ -258,7 +251,7 @@ void Request::execute(const Array& ops) } case OP_STRING__WRITE: { - VString *vstring=static_cast(ops.quick_get(++i)); + VString *vstring=static_cast(i.next()); #ifdef DEBUG_EXECUTE debug_printf(pool(), " \"%s\"", vstring->string().cstr()); #endif @@ -290,7 +283,7 @@ void Request::execute(const Array& ops) PUSH(wcontext); PUSH((void *)flang); flang=String::UL_PASS_APPENDED; - wcontext=NEW WWrapper(pool(), 0 /*empty*/, true /*constructing*/); + wcontext=NEW WWrapper(pool(), 0 /*empty*/); break; } case OP_REDUCE_EWPOOL: @@ -305,7 +298,7 @@ void Request::execute(const Array& ops) case OP_CREATE_SWPOOL: { PUSH(wcontext); - wcontext=NEW WWrapper(pool(), 0 /*empty*/, false /*not constructing*/); + wcontext=NEW WWrapper(pool(), 0 /*empty*/); break; } case OP_REDUCE_SWPOOL: @@ -350,8 +343,12 @@ void Request::execute(const Array& ops) break; } - case OP_CALL_METHOD: - case OP_CALL_CONSTRUCTOR: + case OP_PREPARE_TO_CONSTRUCT_OBJECT: + { + wcontext->constructing(true); + break; + } + case OP_CALL: { #ifdef DEBUG_EXECUTE debug_printf(pool(), "->\n"); @@ -364,7 +361,8 @@ void Request::execute(const Array& ops) PUSH(wcontext); VStateless_class *called_class=frame->junction.self.get_class(); - if(op.code==OP_CALL_CONSTRUCTOR) { + if(wcontext->constructing()) { + wcontext->constructing(false); if(frame->junction.method->call_type!=Method::CT_STATIC) { // this is a constructor call @@ -704,6 +702,7 @@ void Request::execute(const Array& ops) } case OP_IS: { + //_asm int 3; Value *b=POP(); Value *a=POP(); Value *value=NEW VBool(pool(), b->as_string() == a->type()); PUSH(value); @@ -726,7 +725,7 @@ Value *Request::get_element() { if(Method* method=OP.get_method(name)) { // maybe operator? // as if that method were in self and we have normal dynamic method here Junction& junction=*NEW Junction(pool(), - *self, self->get_class(), method, 0,0,0,0); + *root/*self*/, self->get_class(), method, 0,0,0,0); value=NEW VJunction(junction); } if(value) @@ -772,7 +771,7 @@ Value& Request::process(Value& value, co frame=NEW VCodeFrame(pool(), *junction->wcontext); } else { // plain wwrapper - frame=NEW WWrapper(pool(), 0/*empty*/, false/*not constructing*/); + frame=NEW WWrapper(pool(), 0/*empty*/); } //frame->set_name(value.name()); @@ -814,7 +813,7 @@ const String *Request::execute_method(Va // initialize contexts root=rcontext=self=&aself; - wcontext=NEW WWrapper(pool(), &aself, false /*not constructing*/); + wcontext=NEW WWrapper(pool(), &aself); // execute! execute(*method.parser_code); @@ -842,7 +841,7 @@ const String *Request::execute_virtual_m if(Junction *junction=value->get_junction()) if(const Method *method=junction->method) return execute_method(aself, *method, return_cstr); - + return 0; }