--- parser3/src/main/execute.C 2009/05/20 13:22:59 1.337 +++ parser3/src/main/execute.C 2009/06/04 09:31:38 1.345 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_EXECUTE_C="$Date: 2009/05/20 13:22:59 $"; +static const char * const IDENT_EXECUTE_C="$Date: 2009/06/04 09:31:38 $"; #include "pa_opcode.h" #include "pa_array.h" @@ -61,13 +61,21 @@ char *opcode_name[]={ #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT "VALUE__GET_ELEMENT__WRITE", #endif +#ifdef OPTIMIZE_BYTECODE_GET_SELF_ELEMENT + "WITH_SELF__VALUE__GET_ELEMENT", + "WITH_SELF__VALUE__GET_ELEMENT__WRITE", +#endif "OBJECT_POOL", "STRING_POOL", "PREPARE_TO_CONSTRUCT_OBJECT", "PREPARE_TO_EXPRESSION", "CALL", "CALL__WRITE", #ifdef OPTIMIZE_BYTECODE_CONSTRUCT - "ROOT_CONSTRUCT_EXPR", "ROOT_CONSTRUCT_VALUE", - "WRITE_CONSTRUCT_EXPR", "WRITE_CONSTRUCT_VALUE", + "WITH_ROOT__VALUE__CONSTRUCT_EXPR", + "WITH_ROOT__VALUE__CONSTRUCT_VALUE", + "WITH_WRITE__VALUE__CONSTRUCT_EXPR", + "WITH_WRITE__VALUE__CONSTRUCT_VALUE", + "WITH_SELF__VALUE__CONSTRUCT_EXPR", + "WITH_SELF__VALUE__CONSTRUCT_VALUE", #endif // expression ops: unary @@ -82,6 +90,18 @@ char *opcode_name[]={ "IS" }; +const char* debug_value_to_cstr(Value& value){ + const String* string=value.get_string(); + + if(string) + return string->cstr(); + else + if(value.is_bool()) + return value.as_bool()?"":""; + else + return ""; +} + void va_debug_printf(SAPI_Info& sapi_info, const char* fmt,va_list args) { char buf[MAX_STRING]; vsnprintf(buf, MAX_STRING, fmt, args); @@ -111,12 +131,6 @@ void debug_dump(SAPI_Info& sapi_info, in || opcode==OP::OP_GET_OBJECT_VAR_ELEMENT || opcode==OP::OP_GET_OBJECT_VAR_ELEMENT__WRITE #endif -#ifdef OPTIMIZE_BYTECODE_CONSTRUCT - || opcode==OP::OP_ROOT_CONSTRUCT_EXPR - || opcode==OP::OP_ROOT_CONSTRUCT_VALUE - || opcode==OP::OP_WRITE_CONSTRUCT_EXPR - || opcode==OP::OP_WRITE_CONSTRUCT_VALUE -#endif ){ i.next(); // skip origin Value& value1=*i.next().value; @@ -126,7 +140,7 @@ void debug_dump(SAPI_Info& sapi_info, in "%*s%s" " \"%s\" \"%s\"", level*4, "", opcode_name[opcode], - value1.get_string()->cstr(), value2.get_string()->cstr()); + debug_value_to_cstr(value1), debug_value_to_cstr(value2)); continue; } #endif @@ -141,14 +155,27 @@ void debug_dump(SAPI_Info& sapi_info, in || opcode==OP::OP_VALUE__GET_ELEMENT__WRITE || opcode==OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR #endif +#ifdef OPTIMIZE_BYTECODE_GET_SELF_ELEMENT + || opcode==OP::OP_WITH_SELF__VALUE__GET_ELEMENT + || opcode==OP::OP_WITH_SELF__VALUE__GET_ELEMENT__WRITE +#endif +#ifdef OPTIMIZE_BYTECODE_CONSTRUCT + || opcode==OP::OP_WITH_ROOT__VALUE__CONSTRUCT_EXPR + || opcode==OP::OP_WITH_ROOT__VALUE__CONSTRUCT_VALUE + || opcode==OP::OP_WITH_WRITE__VALUE__CONSTRUCT_EXPR + || opcode==OP::OP_WITH_WRITE__VALUE__CONSTRUCT_VALUE + || opcode==OP::OP_WITH_SELF__VALUE__CONSTRUCT_EXPR + || opcode==OP::OP_WITH_SELF__VALUE__CONSTRUCT_VALUE +#endif ) { Operation::Origin origin=i.next().origin; Value& value=*i.next().value; + debug_printf(sapi_info, "%*s%s" " \"%s\" %s", level*4, "", opcode_name[opcode], - value.get_string()->cstr(), value.type()); + debug_value_to_cstr(value), value.type()); continue; } debug_printf(sapi_info, "%*s%s", level*4, "", opcode_name[opcode]); @@ -169,6 +196,7 @@ void debug_dump(SAPI_Info& sapi_info, in } #define DEBUG_PRINT_STR(str) debug_printf(sapi_info, str); #define DEBUG_PRINT_STRING(value) debug_printf(sapi_info, " \"%s\" ", value.cstr()); +#define DEBUG_PRINT_VALUE_AND_TYPE(value) debug_printf(sapi_info, " \"%s\" %s", debug_value_to_cstr(value), value.type()); #define DEBUG_PRINT_OPS(local_ops) \ debug_printf(sapi_info, \ " (%d)\n", local_ops?local_ops->count():0); \ @@ -177,6 +205,7 @@ void debug_dump(SAPI_Info& sapi_info, in #else #define DEBUG_PRINT_STR(str) #define DEBUG_PRINT_STRING(value) +#define DEBUG_PRINT_VALUE_AND_TYPE(value) #define DEBUG_PRINT_OPS(local_ops) #endif @@ -206,9 +235,9 @@ void Request::execute(ArrayOperation& op { 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()); -#endif + + DEBUG_PRINT_VALUE_AND_TYPE(value) + stack.push(value); break; } @@ -279,98 +308,76 @@ void Request::execute(ArrayOperation& op } // OTHER ACTIONS BUT WITHs - case OP::OP_CONSTRUCT_VALUE: - { - Value& value=stack.pop().value(); - const String& name=stack.pop().string(); debug_name=&name; - Value& ncontext=stack.pop().value(); - put_element(ncontext, name, &value); - - break; - } #ifdef OPTIMIZE_BYTECODE_CONSTRUCT - case OP::OP_ROOT_CONSTRUCT_EXPR: - { - debug_origin=i.next().origin; - const String& name=*i.next().value->get_string(); debug_name=&name; - - i.next(); // skip origin - Value& expr=*i.next().value; - - DEBUG_PRINT_STRING(name) - - wcontext->set_in_expression(true); - - Value& value=expr.as_expr_result(); - put_element(*method_frame, name, &value); - break; - } - - case OP::OP_WRITE_CONSTRUCT_EXPR: + case OP::OP_WITH_WRITE__VALUE__CONSTRUCT_EXPR: + case OP::OP_WITH_WRITE__VALUE__CONSTRUCT_VALUE: { if(wcontext==method_frame) throw Exception(PARSER_RUNTIME, 0, "$.name outside of $name[...]"); + // don't stop here. continue in the next block + } + case OP::OP_WITH_ROOT__VALUE__CONSTRUCT_EXPR: + case OP::OP_WITH_ROOT__VALUE__CONSTRUCT_VALUE: + case OP::OP_WITH_SELF__VALUE__CONSTRUCT_EXPR: + case OP::OP_WITH_SELF__VALUE__CONSTRUCT_VALUE: + { + bool is_expr=(opcode==OP::OP_WITH_WRITE__VALUE__CONSTRUCT_EXPR + || opcode==OP::OP_WITH_ROOT__VALUE__CONSTRUCT_EXPR + || opcode==OP::OP_WITH_SELF__VALUE__CONSTRUCT_EXPR); + + if(is_expr) + wcontext->set_in_expression(false); debug_origin=i.next().origin; const String& name=*i.next().value->get_string(); debug_name=&name; - - i.next(); // skip origin - Value& expr=*i.next().value; - DEBUG_PRINT_STRING(name) - wcontext->set_in_expression(true); - - Value& value=expr.as_expr_result(); - put_element(*wcontext, name, &value); - break; - } - - case OP::OP_ROOT_CONSTRUCT_VALUE: - { - debug_origin=i.next().origin; - const String& name=*i.next().value->get_string(); debug_name=&name; + Value& value=stack.pop().value(); - i.next(); // skip origin - Value& value=*i.next().value; + put_element( + (opcode==OP::OP_WITH_ROOT__VALUE__CONSTRUCT_EXPR || opcode==OP::OP_WITH_ROOT__VALUE__CONSTRUCT_VALUE)?*method_frame: + (opcode==OP::OP_WITH_SELF__VALUE__CONSTRUCT_EXPR || opcode==OP::OP_WITH_SELF__VALUE__CONSTRUCT_VALUE)?get_self():*wcontext, + name, + is_expr?&value.as_expr_result():/*value.is_void()?new VString():*/&value + ); - DEBUG_PRINT_STRING(name) - - put_element(*method_frame, name, &value); break; } +#endif // OPTIMIZE_BYTECODE_CONSTRUCT - case OP::OP_WRITE_CONSTRUCT_VALUE: + case OP::OP_CONSTRUCT_VALUE: { - if(wcontext==method_frame) - throw Exception(PARSER_RUNTIME, - 0, - "$.name outside of $name[...]"); - - debug_origin=i.next().origin; - const String& name=*i.next().value->get_string(); debug_name=&name; - - i.next(); // skip origin - Value& value=*i.next().value; - - DEBUG_PRINT_STRING(name) +#ifdef OPTIMIZE_BYTECODE_CONSTRUCT + const String& name=stack.pop().string(); debug_name=&name; + Value& ncontext=stack.pop().value(); + Value& value=stack.pop().value(); +#else + Value& value=stack.pop().value(); + const String& name=stack.pop().string(); debug_name=&name; + Value& ncontext=stack.pop().value(); +#endif + put_element(ncontext, name, &value); - put_element(*wcontext, name, &value); break; } -#endif case OP::OP_CONSTRUCT_EXPR: { // see OP_PREPARE_TO_EXPRESSION wcontext->set_in_expression(false); +#ifdef OPTIMIZE_BYTECODE_CONSTRUCT + const String& name=stack.pop().string(); debug_name=&name; + Value& ncontext=stack.pop().value(); + Value& expr=stack.pop().value(); +#else Value& expr=stack.pop().value(); const String& name=stack.pop().string(); debug_name=&name; Value& ncontext=stack.pop().value(); +#endif Value& value=expr.as_expr_result(); put_element(ncontext, name, &value); break; @@ -490,8 +497,6 @@ void Request::execute(ArrayOperation& op Value& value=get_element(object, field_name); - i.next(); // skip last OP_GET_ELEMENT - if(opcode==OP::OP_GET_OBJECT_ELEMENT){ stack.push(value); } else { @@ -521,8 +526,6 @@ void Request::execute(ArrayOperation& op Value& value=get_element(object, *field); - i.next(); // skip last OP_GET_ELEMENT - if(opcode==OP::OP_GET_OBJECT_VAR_ELEMENT){ stack.push(value); } else { @@ -579,6 +582,26 @@ void Request::execute(ArrayOperation& op } #endif +#ifdef OPTIMIZE_BYTECODE_GET_SELF_ELEMENT + case OP::OP_WITH_SELF__VALUE__GET_ELEMENT: + case OP::OP_WITH_SELF__VALUE__GET_ELEMENT__WRITE: + { + debug_origin=i.next().origin; + const String& name=*i.next().value->get_string(); debug_name=&name; + + DEBUG_PRINT_STRING(name) + + Value& value=get_element(get_self(), name); + + if(opcode==OP::OP_WITH_SELF__VALUE__GET_ELEMENT){ + stack.push(value); + } else { + write_assign_lang(value); + } + break; + } +#endif + case OP::OP_OBJECT_POOL: { ArrayOperation& local_ops=*i.next().ops; @@ -642,12 +665,10 @@ void Request::execute(ArrayOperation& op rcontext, opcode==OP::OP_EXPR_CODE__STORE_PARAM?0:wcontext, &local_ops); -#ifdef USE_DESTRUCTORS - value.set_temporal(true); -#else +#ifndef USE_DESTRUCTORS if (opcode!=OP::OP_EXPR_CODE__STORE_PARAM) + wcontext->attach_junction(&value); #endif - wcontext->attach_junction(&value); // store param stack.push(value); break;