--- parser3/src/main/execute.C 2003/04/02 11:35:20 1.295.2.27.2.13 +++ parser3/src/main/execute.C 2003/04/03 09:18:46 1.295.2.27.2.17 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_EXECUTE_C="$Date: 2003/04/02 11:35:20 $"; +static const char* IDENT_EXECUTE_C="$Date: 2003/04/03 09:18:46 $"; #include "pa_opcode.h" #include "pa_array.h" @@ -24,7 +24,6 @@ static const char* IDENT_EXECUTE_C="$Dat #include "pa_wwrapper.h" //#define DEBUG_EXECUTE -#define LATER_STACK_TRACE #ifdef DEBUG_EXECUTE char *opcode_name[]={ @@ -71,20 +70,20 @@ 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()) { - Operation op=i.next(); + OPCODE opcode=i.next().code(); - if(op.code==OP_VALUE || op.code==OP_STRING__WRITE) { + if(opcode==OP_VALUE || opcode==OP_STRING__WRITE) { Value& value=*i.next().value; debug_printf(sapi_info, "%*s%s" " \"%s\" %s", - level*4, "", opcode_name[op.code], + level*4, "", opcode_name[opcode], value.get_string()->cstr(), value.type()); continue; } - debug_printf(sapi_info, "%*s%s", level*4, "", opcode_name[op.code]); + debug_printf(sapi_info, "%*s%s", level*4, "", opcode_name[opcode]); - switch(op.code) { + switch(opcode) { case OP_CURLY_CODE__STORE_PARAM: case OP_EXPR_CODE__STORE_PARAM: case OP_CURLY_CODE__CONSTRUCT: @@ -105,6 +104,8 @@ 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; + try{ #ifdef DEBUG_EXECUTE debug_printf(sapi_info, "source----------------------------\n"); debug_dump(sapi_info, 0, ops); @@ -117,15 +118,17 @@ void Request::execute(ArrayOperation& op 0, "execution stopped"); } - OPCODE opcode=i.next().code; + Operation::Info opinfo=i.next().info; + #ifdef DEBUG_EXECUTE - debug_printf(sapi_info, "%d:%s", stack.top_index()+1, opcode_name[opcode]); + debug_printf(sapi_info, "%d:%s", stack.top_index()+1, opcode_name[opinfo.code()]); #endif - switch(opcode) { + switch(opinfo.code()) { // param in next instruction case OP_VALUE: { + debug_info=opinfo; Value& value=*i.next().value; #ifdef DEBUG_EXECUTE debug_printf(sapi_info, " \"%s\" %s", value.get_string()->cstr(), value.type()); @@ -180,7 +183,7 @@ void Request::execute(ArrayOperation& op case OP_CONSTRUCT_VALUE: { Value& value=stack.pop().value(); - const String& name=stack.pop().string(); + const String& name=stack.pop().string(); debug_name=&name; Value& ncontext=stack.pop().value(); ncontext.put_element(name, &value, false); break; @@ -191,7 +194,7 @@ void Request::execute(ArrayOperation& op wcontext->set_in_expression(false); Value& value=stack.pop().value(); - const String& name=stack.pop().string(); + const String& name=stack.pop().string(); debug_name=&name; Value& ncontext=stack.pop().value(); ncontext.put_element(name, &value.as_expr_result(), false); break; @@ -210,7 +213,7 @@ void Request::execute(ArrayOperation& op wcontext, &local_ops)); - const String& name=stack.pop().string(); + const String& name=stack.pop().string(); debug_name=&name; Value& ncontext=stack.pop().value(); ncontext.put_element(name, &value, false); break; @@ -253,20 +256,26 @@ void Request::execute(ArrayOperation& op case OP_GET_ELEMENT_OR_OPERATOR: { - Value& value=get_element(true); + const String& name=stack.pop().string(); debug_name=&name; + Value& ncontext=stack.pop().value(); + Value& value=get_element(ncontext, name, true); stack.push(value); break; } case OP_GET_ELEMENT: { - Value& value=get_element(false); + const String& name=stack.pop().string(); debug_name=&name; + Value& ncontext=stack.pop().value(); + Value& value=get_element(ncontext, name, false); stack.push(value); break; } case OP_GET_ELEMENT__WRITE: { - Value& value=get_element(false); + const String& name=stack.pop().string(); debug_name=&name; + Value& ncontext=stack.pop().value(); + Value& value=get_element(ncontext, name, false); write_assign_lang(value); break; } @@ -343,7 +352,7 @@ void Request::execute(ArrayOperation& op get_self(), 0, method_frame, rcontext, - opcode==OP_EXPR_CODE__STORE_PARAM?0:wcontext, + opinfo.code()==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 @@ -366,6 +375,7 @@ void Request::execute(ArrayOperation& op case OP_CALL: case OP_CALL__WRITE: { + //is_debug_junction=true; ArrayOperation* local_ops=i.next().ops; #ifdef DEBUG_EXECUTE debug_printf(sapi_info, " (%d)\n", local_ops?local_ops->count():0); @@ -445,26 +455,16 @@ void Request::execute(ArrayOperation& op if( method.call_type==Method::CT_ANY || method.call_type==call_type) { // allowed call type? -#ifndef LATER_STACK_TRACE - try { -#endif - method_frame=&frame; - if(method.native_code) { // native code? - method.check_actual_numbered_params( - frame.junction.self, - /*frame.name(), */frame.numbered_params()); - method.native_code( - *this, - /*frame.name(), */frame.numbered_params()); // execute it - } else // parser code, execute it - recoursion_checked_execute(/*frame.name(), */*method.parser_code); -#ifndef LATER_STACK_TRACE - } catch(...) { - // record it to stack trace - exception_trace.push(frame.name()); - rethrow; - } -#endif + method_frame=&frame; + if(method.native_code) { // native code? + method.check_actual_numbered_params( + frame.junction.self, + /*frame.name(), */frame.numbered_params()); + method.native_code( + *this, + /*frame.name(), */frame.numbered_params()); // execute it + } else // parser code, execute it + recoursion_checked_execute(/*frame.name(), */*method.parser_code); } else throw Exception("parser.runtime", 0, //&frame.name(), @@ -478,7 +478,7 @@ void Request::execute(ArrayOperation& op rcontext=saved_rcontext; method_frame=saved_method_frame; - if(opcode==OP_CALL__WRITE) { + if(opinfo.code()==OP_CALL__WRITE) { write_assign_lang(result); } else { // OP_CALL stack.push(result.as_value()); @@ -487,6 +487,7 @@ void Request::execute(ArrayOperation& op #ifdef DEBUG_EXECUTE debug_printf(sapi_info, "<-returned"); #endif + //is_debug_junction=false; break; } @@ -800,18 +801,22 @@ void Request::execute(ArrayOperation& op default: throw Exception(0, 0, - "invalid opcode %d", opcode); + "invalid opcode %d", opinfo.code()); } } + } catch(...) { + // record it to stack trace + //if(is_debug_junction) + exception_trace.push(Trace(debug_name, debug_info)); + rethrow; + } } /** @todo cache|prepare junctions @bug ^superbase:method would dynamically call ^base:method if there is any */ -Value& Request::get_element(bool can_call_operator) { - const String& name=stack.pop().string(); //remember_name=name; - Value& ncontext=stack.pop().value(); +Value& Request::get_element(Value& ncontext, const String& name, bool can_call_operator) { Value* value=0; if(can_call_operator) { if(Method* method=main_class.get_method(name)) // looking operator of that name FIRST