--- parser3/src/main/execute.C 2003/02/03 09:17:47 1.295.2.7 +++ parser3/src/main/execute.C 2003/02/17 10:44:55 1.295.2.11 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_EXECUTE_C="$Date: 2003/02/03 09:17:47 $"; +static const char* IDENT_EXECUTE_C="$Date: 2003/02/17 10:44:55 $"; #include "pa_opcode.h" #include "pa_array.h" @@ -62,35 +62,34 @@ char *opcode_name[]={ "IS" }; -void va_debug_printf(Pool& pool, const char* fmt,va_list args) { +void va_debug_printf(SAPI_Info& sapi_info, const char* fmt,va_list args) { char buf[MAX_STRING]; vsnprintf(buf, MAX_STRING, fmt, args); - SAPI::log(pool, "%s", buf); + SAPI::log(sapi_info, "%s", buf); } -void debug_printf(Pool& pool, const char* fmt, ...) { +void debug_printf(SAPI_Info& sapi_info, const char* fmt, ...) { va_list args; - va_start(args,fmt); - va_debug_printf(pool,fmt,args); + va_start(args, fmt); + va_debug_printf(sapi_info, fmt, args); va_end(args); } -void debug_dump(Pool& pool, int level, const Array& ops) { - Array_iterator i(ops); +void debug_dump(SAPI_Info& sapi_info, int level, ArrayOperation& ops) { + Array_iterator i(ops); while(i.has_next()) { - Operation op; - op.cast=i.next(); + Operation& op=i.next(); if(op.code==OP_VALUE || op.code==OP_STRING__WRITE) { - Value* value=i.next().value; - debug_printf(pool, + ValuePtr value=i.next().value; + debug_printf(sapi_info, "%*s%s" " \"%s\" %s", level*4, "", opcode_name[op.code], - value->get_string()->cstr(), value->type()); + value->get_string(0)->cstr().get(), value->type()); continue; } - debug_printf(pool, "%*s%s", level*4, "", opcode_name[op.code]); + debug_printf(sapi_info, "%*s%s", level*4, "", opcode_name[op.code]); switch(op.code) { case OP_CURLY_CODE__STORE_PARAM: @@ -100,8 +99,8 @@ void debug_dump(Pool& pool, int level, c case OP_OBJECT_POOL: case OP_STRING_POOL: case OP_CALL: - local_ops=i.next().ops; - debug_dump(pool, level+1, *local_ops); + ArrayOperation& local_ops=*i.next().ops; + debug_dump(sapi_info, level+1, local_ops); } } } @@ -119,9 +118,9 @@ void debug_dump(Pool& pool, int level, c void Request::execute(ArrayOperation& ops) { // _asm int 3; #ifdef DEBUG_EXECUTE - debug_printf("source----------------------------\n"); - debug_dump(0, ops); - debug_printf("execution-------------------------\n"); + debug_printf(sapi_info, "source----------------------------\n"); + debug_dump(sapi_info, 0, ops); + debug_printf(sapi_info, "execution-------------------------\n"); #endif StringPtr last_get_element_name(0); @@ -134,7 +133,7 @@ void Request::execute(ArrayOperation& op Operation& op=i.next(); #ifdef DEBUG_EXECUTE - debug_printf("%d:%s", stack.top_index()+1, opcode_name[op.code]); + debug_printf(sapi_info, "%d:%s", stack.top_index()+1, opcode_name[op.code]); #endif ValuePtr value; @@ -152,7 +151,7 @@ void Request::execute(ArrayOperation& op { value=i.next().value; #ifdef DEBUG_EXECUTE - debug_printf(" \"%s\" %s", value->get_string()->cstr(), value->type()); + debug_printf(sapi_info, " \"%s\" %s", value->get_string(0)->cstr().get(), value->type()); #endif stack.push(value); break; @@ -224,8 +223,8 @@ void Request::execute(ArrayOperation& op { local_ops=i.next().ops; #ifdef DEBUG_EXECUTE - debug_printf(" (%d)\n", local_ops->count()); - debug_dump(1, *local_ops); + debug_printf(sapi_info, " (%d)\n", local_ops->count()); + debug_dump(sapi_info, 1, *local_ops); #endif value=ValuePtr(new VJunction(JunctionPtr(new Junction( get_self(), 0, @@ -243,8 +242,8 @@ void Request::execute(ArrayOperation& op { local_ops=i.next().ops; #ifdef DEBUG_EXECUTE - debug_printf(" (%d)\n", local_ops->count()); - debug_dump(1, *local_ops); + debug_printf(sapi_info, " (%d)\n", local_ops->count()); + debug_dump(sapi_info, 1, *local_ops); #endif stack.push(local_ops); break; @@ -269,7 +268,7 @@ void Request::execute(ArrayOperation& op { value=i.next().value; #ifdef DEBUG_EXECUTE - debug_printf(" \"%s\"", value->get_string(0).cstr()); + debug_printf(sapi_info, " \"%s\"", value->get_string(0)->cstr().get()); #endif write_no_lang(*value->get_string(0)); break; @@ -353,8 +352,8 @@ void Request::execute(ArrayOperation& op local_ops=i.next().ops; VMethodFrame *frame=static_cast(stack.top_value().unknown); #ifdef DEBUG_EXECUTE - debug_printf(" (%d)\n", local_ops->count()); - debug_dump(1, *local_ops); + debug_printf(sapi_info, " (%d)\n", local_ops->count()); + debug_dump(sapi_info, 1, *local_ops); #endif // when they evaluate expression parameter, // the object expression result @@ -392,10 +391,10 @@ void Request::execute(ArrayOperation& op { local_ops=i.next().ops; #ifdef DEBUG_EXECUTE - debug_printf(" (%d)\n", local_ops->count()); - debug_dump(1, *local_ops); + debug_printf(sapi_info, " (%d)\n", local_ops->count()); + debug_dump(sapi_info, 1, *local_ops); - debug_printf("->\n"); + debug_printf(sapi_info, "->\n"); #endif value=stack.pop().value; @@ -443,7 +442,7 @@ void Request::execute(ArrayOperation& op throw Exception("parser.runtime", frame.name(), "is not a constructor, system class '%s' can be constructed only implicitly", - called_class->name()->cstr()); + (char*)called_class->name()->cstr()); frame.write(new_self, String::UL_CLEAN // not used, always an object, not string @@ -505,11 +504,11 @@ void Request::execute(ArrayOperation& op if(op.code==OP_CALL__WRITE) { write_assign_lang(result, last_get_element_name); } else { // OP_CALL - stack.push(&result.as_value()); + stack.push(result.as_value()); } #ifdef DEBUG_EXECUTE - debug_printf("<-returned"); + debug_printf(sapi_info, "<-returned"); #endif break; } @@ -895,7 +894,7 @@ StringOrValue Request::process(ValuePtr if(junction && junction->code) { // is it a code-junction? // process it #ifdef DEBUG_EXECUTE - debug_printf("ja->\n"); + debug_printf(sapi_info, "ja->\n"); #endif if(!junction->method_frame) @@ -943,7 +942,7 @@ StringOrValue Request::process(ValuePtr method_frame=saved_method_frame; #ifdef DEBUG_EXECUTE - debug_printf("<-ja returned"); + debug_printf(sapi_info, "<-ja returned"); #endif } else { result.set_value(input_value); @@ -988,10 +987,12 @@ StringPtr Request::execute_method(ValueP } local_frame.set_self(aself); rcontext=wcontext=method_frame=&local_frame; + // preventing local object from deletes + local_frame.ref(); // prevent non-string writes for better error reporting if(do_return_string) - wcontext->write(pool(), ValuePtr(new VVoid)); + wcontext->write(pool(), ValuePtr(&local_frame)); // execute! execute(*method.parser_code); @@ -1008,20 +1009,20 @@ StringPtr Request::execute_method(ValueP return result; } -StringPtr Request::execute_nonvirtual_method(VStateless_classPtr aclass, +StringPtr Request::execute_nonvirtual_method(VStateless_class& aclass, StringPtr method_name, VStringPtr optional_param, bool do_return_string, const Method **return_method) { - const Method *method=aclass->get_method(method_name); + const Method *method=aclass.get_method(method_name); StringPtr result(0); if(return_method) *return_method=method; if(method) - return execute_method(aclass, *method, optional_param, do_return_string); + return execute_method(ValuePtr(&aclass), *method, optional_param, do_return_string); else - return 0; + return StringPtr(0); } StringPtr Request::execute_virtual_method(ValuePtr aself, @@ -1031,5 +1032,5 @@ StringPtr Request::execute_virtual_metho if(const Method *method=junction->method) return execute_method(aself, *method, VStringPtr(0)/*no params*/, true); - return 0; + return StringPtr(0); }