--- parser3/src/main/execute.C 2003/04/03 10:48:25 1.295.2.27.2.19 +++ parser3/src/main/execute.C 2004/07/30 10:01:14 1.306 @@ -1,11 +1,11 @@ /** @file Parser: executor part of request class. - Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_EXECUTE_C="$Date: 2003/04/03 10:48:25 $"; +static const char * const IDENT_EXECUTE_C="$Date: 2004/07/30 10:01:14 $"; #include "pa_opcode.h" #include "pa_array.h" @@ -70,9 +70,10 @@ void debug_printf(SAPI_Info& sapi_info, void debug_dump(SAPI_Info& sapi_info, int level, ArrayOperation& ops) { Array_iterator i(ops); while(i.has_next()) { - OPCODE opcode=i.next().code(); + OPCODE opcode=i.next().code; if(opcode==OP_VALUE || opcode==OP_STRING__WRITE) { + Operation::Origin origin=i.next().origin; Value& value=*i.next().value; debug_printf(sapi_info, "%*s%s" @@ -104,7 +105,7 @@ void debug_dump(SAPI_Info& sapi_info, in void Request::execute(ArrayOperation& ops) { register Stack& stack=this->stack; // helps a lot on MSVC: 'esi' - const String* debug_name=0; Operation::Info debug_info; //bool is_debug_junction=false; + const String* debug_name=0; Operation::Origin debug_origin={0, 0, 0}; try{ #ifdef DEBUG_EXECUTE debug_printf(sapi_info, "source----------------------------\n"); @@ -118,17 +119,17 @@ void Request::execute(ArrayOperation& op 0, "execution stopped"); } - Operation::Info opinfo=i.next().info; + OPCODE opcode=i.next().code; #ifdef DEBUG_EXECUTE - debug_printf(sapi_info, "%d:%s", stack.top_index()+1, opcode_name[opinfo.code()]); + debug_printf(sapi_info, "%d:%s", stack.top_index()+1, opcode_name[opcode]); #endif - switch(opinfo.code()) { + switch(opcode) { // param in next instruction case OP_VALUE: { - debug_info=opinfo; + debug_origin=i.next().origin; Value& value=*i.next().value; #ifdef DEBUG_EXECUTE debug_printf(sapi_info, " \"%s\" %s", value.get_string()->cstr(), value.type()); @@ -246,6 +247,7 @@ void Request::execute(ArrayOperation& op } case OP_STRING__WRITE: { + i.next(); // ignore origin Value* value=i.next().value; #ifdef DEBUG_EXECUTE debug_printf(sapi_info, " \"%s\"", value->get_string()->cstr()); @@ -352,7 +354,7 @@ void Request::execute(ArrayOperation& op get_self(), 0, method_frame, rcontext, - opinfo.code()==OP_EXPR_CODE__STORE_PARAM?0:wcontext, + opcode==OP_EXPR_CODE__STORE_PARAM?0:wcontext, &local_ops)); // store param // this op is executed from CALL local_ops only, so can not check method_frame_to_fill==0 @@ -429,7 +431,7 @@ void Request::execute(ArrayOperation& op if(frame.junction.method->call_type!=Method::CT_STATIC) { // this is a constructor call - if(Value* value=called_class.create_new_value()) { + if(Value* value=called_class.create_new_value(fpool)) { // some stateless_class creatable derivates new_self=value; } else @@ -484,7 +486,7 @@ void Request::execute(ArrayOperation& op rcontext=saved_rcontext; method_frame=saved_method_frame; - if(opinfo.code()==OP_CALL__WRITE) { + if(opcode==OP_CALL__WRITE) { write_assign_lang(result); } else { // OP_CALL stack.push(result.as_value()); @@ -708,49 +710,49 @@ void Request::execute(ArrayOperation& op } case OP_NUM_LT: { - Value& b=stack.pop().value(); Value& a=stack.pop().value(); - double result=a.as_double() - b.as_double(); - Value& value=*new VBool(result < 0.0); + volatile double b_double=stack.pop().value().as_double(); + volatile double a_double=stack.pop().value().as_double(); + Value& value=*new VBool(a_double 0.0); + volatile double b_double=stack.pop().value().as_double(); + volatile double a_double=stack.pop().value().as_double(); + Value& value=*new VBool(a_double>b_double); stack.push(value); break; } case OP_NUM_LE: { - Value& b=stack.pop().value(); Value& a=stack.pop().value(); - double result=a.as_double() - b.as_double(); - Value& value=*new VBool(result <= 0.0); + volatile double b_double=stack.pop().value().as_double(); + volatile double a_double=stack.pop().value().as_double(); + Value& value=*new VBool(a_double<=b_double); stack.push(value); break; } case OP_NUM_GE: { - Value& b=stack.pop().value(); Value& a=stack.pop().value(); - double result=a.as_double() - b.as_double(); - Value& value=*new VBool(result >= 0.0); + volatile double b_double=stack.pop().value().as_double(); + volatile double a_double=stack.pop().value().as_double(); + Value& value=*new VBool(a_double>=b_double); stack.push(value); break; } case OP_NUM_EQ: { - Value& b=stack.pop().value(); Value& a=stack.pop().value(); - double result=a.as_double() - b.as_double(); - Value& value=*new VBool(result == 0.0); + volatile double b_double=stack.pop().value().as_double(); + volatile double a_double=stack.pop().value().as_double(); + Value& value=*new VBool(a_double==b_double); stack.push(value); break; } case OP_NUM_NE: { - Value& b=stack.pop().value(); Value& a=stack.pop().value(); - double result=a.as_double() - b.as_double(); - Value& value=*new VBool(result != 0.0); + volatile double b_double=stack.pop().value().as_double(); + volatile double a_double=stack.pop().value().as_double(); + Value& value=*new VBool(a_double!=b_double); stack.push(value); break; } @@ -807,14 +809,13 @@ void Request::execute(ArrayOperation& op default: throw Exception(0, 0, - "invalid opcode %d", opinfo.code()); + "invalid opcode %d", opcode); } } - } catch(...) { + } catch(const Exception&) { // record it to stack trace - //if(is_debug_junction) - if(debug_name) - exception_trace.push(Trace(debug_name, debug_info)); + if(debug_name) + exception_trace.push(Trace(debug_name, debug_origin)); rethrow; } } @@ -906,7 +907,7 @@ StringOrValue Request::process(Value& in wcontext=&local; // execute it - recoursion_checked_execute(/*0/*result_name* /, */ *junction->code); + recoursion_checked_execute(*junction->code); // CodeFrame soul: // string writes were intercepted @@ -918,7 +919,7 @@ StringOrValue Request::process(Value& in wcontext=&local; // execute it - recoursion_checked_execute(/*0/*result_name* /, */ *junction->code); + recoursion_checked_execute(*junction->code); result=wcontext->result(); } @@ -936,7 +937,7 @@ StringOrValue Request::process(Value& in return result; } -const String& Request::execute_method(VMethodFrame& amethod_frame, const Method& method) { +StringOrValue Request::execute_method(VMethodFrame& amethod_frame, const Method& method) { VMethodFrame *saved_method_frame=method_frame; Value* saved_rcontext=rcontext; WContext *saved_wcontext=wcontext; @@ -948,7 +949,7 @@ const String& Request::execute_method(VM execute(*method.parser_code); // result - const String& result=wcontext->result().as_string(); + StringOrValue result=wcontext->result(); wcontext=saved_wcontext; rcontext=saved_rcontext; @@ -959,14 +960,14 @@ const String& Request::execute_method(VM } const String* Request::execute_method(Value& aself, - const Method& method, VString* optional_param, - bool do_return_string) { + const Method& method, VString* optional_param, + bool do_return_string) { VMethodFrame *saved_method_frame=method_frame; Value* saved_rcontext=rcontext; WContext *saved_wcontext=wcontext; Junction local_junction(aself, &method, 0,0,0, 0); - VMethodFrame local_frame(/*method.name, */local_junction, method_frame/*caller*/); + VMethodFrame local_frame(local_junction, method_frame/*caller*/); if(optional_param && local_frame.can_store_param()) { local_frame.store_param(*optional_param); local_frame.fill_unspecified_params();