--- parser3/src/main/execute.C 2015/05/08 14:30:44 1.375 +++ parser3/src/main/execute.C 2016/07/19 16:35:36 1.383 @@ -1,7 +1,7 @@ /** @file Parser: executor part of request class. - Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ @@ -21,7 +21,7 @@ #include "pa_vimage.h" #include "pa_wwrapper.h" -volatile const char * IDENT_EXECUTE_C="$Id: execute.C,v 1.375 2015/05/08 14:30:44 moko Exp $" IDENT_PA_OPCODE_H IDENT_PA_OPERATION_H IDENT_PA_VCODE_FRAME_H IDENT_PA_WWRAPPER_H; +volatile const char * IDENT_EXECUTE_C="$Id: execute.C,v 1.383 2016/07/19 16:35:36 moko Exp $" IDENT_PA_OPCODE_H IDENT_PA_OPERATION_H IDENT_PA_VCODE_FRAME_H IDENT_PA_WWRAPPER_H; //#define DEBUG_EXECUTE @@ -60,6 +60,17 @@ char *opcode_name[]={ "WITH_SELF__VALUE__GET_ELEMENT", "WITH_SELF__VALUE__GET_ELEMENT__WRITE", #endif + +#ifdef FEATURE_GET_ELEMENT4CALL + "GET_ELEMENT4CALL", +#ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT + "GET_OBJECT_ELEMENT4CALL", +#endif +#ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT + "GET_OBJECT_VAR_ELEMENT4CALL", +#endif +#endif // FEATURE_GET_ELEMENT4CALL + "OBJECT_POOL", "STRING_POOL", "PREPARE_TO_CONSTRUCT_OBJECT", "CONSTRUCT_OBJECT", @@ -128,10 +139,16 @@ void debug_dump(SAPI_Info& sapi_info, in #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT || opcode==OP::OP_GET_OBJECT_ELEMENT || opcode==OP::OP_GET_OBJECT_ELEMENT__WRITE +#ifdef FEATURE_GET_ELEMENT4CALL + || opcode==OP::OP_GET_OBJECT_ELEMENT4CALL +#endif #endif #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT || opcode==OP::OP_GET_OBJECT_VAR_ELEMENT || opcode==OP::OP_GET_OBJECT_VAR_ELEMENT__WRITE +#ifdef FEATURE_GET_ELEMENT4CALL + || opcode==OP::OP_GET_OBJECT_VAR_ELEMENT4CALL +#endif #endif ){ i.next(); // skip origin @@ -168,6 +185,7 @@ void debug_dump(SAPI_Info& sapi_info, in opcode==OP::OP_VALUE || opcode==OP::OP_STRING__WRITE || opcode==OP::OP_VALUE__GET_CLASS + || opcode==OP::OP_VALUE__GET_BASE_CLASS #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT || opcode==OP::OP_VALUE__GET_ELEMENT || opcode==OP::OP_VALUE__GET_ELEMENT__WRITE @@ -263,9 +281,6 @@ void Request::execute(ArrayOperation& op } case OP::OP_VALUE__GET_CLASS: { - // maybe they do ^class:method[] call, remember the fact - wcontext->set_somebody_entered_some_class(); - debug_origin=i.next().origin; const String& name=*i.next().value->get_string(); debug_name=&name; @@ -273,14 +288,29 @@ void Request::execute(ArrayOperation& op Value* class_value=get_class(name); if(!class_value) - throw Exception(PARSER_RUNTIME, - &name, - "class is undefined"); + throw Exception(PARSER_RUNTIME, &name, "class is undefined"); stack.push(*class_value); break; } + case OP::OP_VALUE__GET_BASE_CLASS: + { + // ^class:method[] call + + debug_origin=i.next().origin; + const String& name=*i.next().value->get_string(); debug_name=&name; + + DEBUG_PRINT_STRING(name) + + Value* class_value=get_class(name); + if(!class_value) + throw Exception(PARSER_RUNTIME, &name, "class is undefined"); + + stack.push(*new VBaseClassWrapper(*class_value->get_class(), get_self())); + break; + } + #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL case OP::OP_GET_ELEMENT__SPECIAL: case OP::OP_GET_ELEMENT__SPECIAL__WRITE: @@ -290,19 +320,19 @@ void Request::execute(ArrayOperation& op Value* value=0; if(VStateless_class* vclass=ncontext.get_class()){ - if(name==class_element_name){ + if(SYMBOLS_EQ(name,CLASS_SYMBOL)){ value=vclass; - } else if(name==class_name_element_name){ - value=new VString(vclass->name()); + } else if(SYMBOLS_EQ(name,CLASS_NAME_SYMBOL)){ + value=new VString(*new String(vclass->type())); } } else { - // Value - if(name==class_element_name){ + // VJunction is without class, returning self + if(SYMBOLS_EQ(name,CLASS_SYMBOL)){ value=&ncontext; - }else if(name==class_name_element_name){ + } else if(SYMBOLS_EQ(name,CLASS_NAME_SYMBOL)){ value=new VString(*new String(ncontext.type())); } - }; + } if(opcode==OP::OP_GET_ELEMENT__SPECIAL){ stack.push(*value); } else { @@ -511,59 +541,64 @@ void Request::execute(ArrayOperation& op #endif #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT - case OP::OP_GET_OBJECT_ELEMENT: - case OP::OP_GET_OBJECT_ELEMENT__WRITE: - { - debug_origin=i.next().origin; - const String& context_name=*i.next().value->get_string(); debug_name=&context_name; - DEBUG_PRINT_STRING(context_name) - - Value& object=get_element(*rcontext, context_name); - - debug_origin=i.next().origin; - const String& field_name=*i.next().value->get_string(); debug_name=&field_name; - - DEBUG_PRINT_STRING(field_name) +#define DO_GET_OBJECT_ELEMENT(code) {\ + debug_origin=i.next().origin; \ + const String& context_name=*i.next().value->get_string(); debug_name=&context_name; \ + DEBUG_PRINT_STRING(context_name) \ + Value& object=get_element(*rcontext, context_name); \ + debug_origin=i.next().origin; \ + const String& field_name=*i.next().value->get_string(); debug_name=&field_name; \ + DEBUG_PRINT_STRING(field_name) \ + code; \ + break; \ + } + case OP::OP_GET_OBJECT_ELEMENT: DO_GET_OBJECT_ELEMENT({ Value& value=get_element(object, field_name); - - if(opcode==OP::OP_GET_OBJECT_ELEMENT){ - stack.push(value); - } else { - write_assign_lang(value); - } - break; - } + stack.push(value); + }) + case OP::OP_GET_OBJECT_ELEMENT__WRITE: DO_GET_OBJECT_ELEMENT({ + Value& value=get_element(object, field_name); + write_assign_lang(value); + }) +#ifdef FEATURE_GET_ELEMENT4CALL + case OP::OP_GET_OBJECT_ELEMENT4CALL: DO_GET_OBJECT_ELEMENT({ + Value& value=get_element4call(object, field_name); + stack.push(value); + }) +#endif #endif #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT - case OP::OP_GET_OBJECT_VAR_ELEMENT: - case OP::OP_GET_OBJECT_VAR_ELEMENT__WRITE: - { - debug_origin=i.next().origin; - const String& context_name=*i.next().value->get_string(); debug_name=&context_name; - - DEBUG_PRINT_STRING(context_name) - - Value& object=get_element(*rcontext, context_name); - debug_origin=i.next().origin; - const String& var_name=*i.next().value->get_string(); debug_name=&var_name; - - DEBUG_PRINT_STRING(var_name) - - const String* field=&get_element(*rcontext, var_name).as_string(); +#define DO_GET_OBJECT_VAR_ELEMENT(code) {\ + debug_origin=i.next().origin; \ + const String& context_name=*i.next().value->get_string(); debug_name=&context_name; \ + DEBUG_PRINT_STRING(context_name) \ + Value& object=get_element(*rcontext, context_name); \ + debug_origin=i.next().origin; \ + const String& var_name=*i.next().value->get_string(); debug_name=&var_name; \ + DEBUG_PRINT_STRING(var_name) \ + const String* field=&get_element(*rcontext, var_name).as_string(); \ + code; \ + break; \ + } + case OP::OP_GET_OBJECT_VAR_ELEMENT: DO_GET_OBJECT_VAR_ELEMENT({ Value& value=get_element(object, *field); - - if(opcode==OP::OP_GET_OBJECT_VAR_ELEMENT){ - stack.push(value); - } else { - write_assign_lang(value); - } - break; - } + stack.push(value); + }) + case OP::OP_GET_OBJECT_VAR_ELEMENT__WRITE: DO_GET_OBJECT_VAR_ELEMENT({ + Value& value=get_element(object, *field); + write_assign_lang(value); + }) +#ifdef FEATURE_GET_ELEMENT4CALL + case OP::OP_GET_OBJECT_VAR_ELEMENT4CALL: DO_GET_OBJECT_VAR_ELEMENT({ + Value& value=get_element4call(object, *field); + stack.push(value); + }) +#endif #endif case OP::OP_GET_ELEMENT: @@ -575,6 +610,17 @@ void Request::execute(ArrayOperation& op break; } +#ifdef FEATURE_GET_ELEMENT4CALL + case OP::OP_GET_ELEMENT4CALL: + { + const String& name=stack.pop().string(); debug_name=&name; + Value& ncontext=stack.pop().value(); + Value& value=get_element4call(ncontext, name); + stack.push(value); + break; + } +#endif + case OP::OP_GET_ELEMENT__WRITE: { const String& name=stack.pop().string(); debug_name=&name; @@ -867,7 +913,7 @@ void Request::execute(ArrayOperation& op throw Exception(PARSER_RUNTIME, &constructor_name, "constructor must be declared in class '%s'", - class_value->get_class()->name_cstr()); + class_value->type()); ArrayOperation* local_ops=i.next().ops; DEBUG_PRINT_OPS(local_ops) @@ -1236,7 +1282,7 @@ Value& Request::construct(Value &class_v throw Exception(PARSER_RUNTIME, 0, //&frame.name(), "is not a constructor, system class '%s' can be constructed only implicitly", - called_class.name().cstr()); + called_class.type()); } else throw Exception(PARSER_RUNTIME, 0, //&frame.name(), @@ -1298,18 +1344,16 @@ void Request::op_call_write(VMethodFrame } Value& Request::get_element(Value& ncontext, const String& name) { - if(wcontext->get_somebody_entered_some_class()) // ^class:method - if(VStateless_class *called_class=ncontext.get_class()) - if(VStateless_class *read_class=rcontext->get_class()) - if(read_class->derived_from(*called_class)){ // current derived from called - Value *value=called_class->get_element(get_self(), name); - return *(value ? &process_to_value(*value) : VVoid::get()); - } - Value* value=ncontext.get_element(name); + return *(value ? &process_to_value(*value) : VVoid::get()); +} +#ifdef FEATURE_GET_ELEMENT4CALL +Value& Request::get_element4call(Value& ncontext, const String& name) { + Value* value=ncontext.get_element4call(name); return *(value ? &process_to_value(*value) : VVoid::get()); } +#endif void Request::put_element(Value& ncontext, const String& name, Value* value) { // put_element can return property-setting-junction @@ -1597,6 +1641,7 @@ const String* Request::get_method_filena case OP::OP_VALUE: case OP::OP_STRING__WRITE: case OP::OP_VALUE__GET_CLASS: + case OP::OP_VALUE__GET_BASE_CLASS: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT case OP::OP_GET_OBJECT_ELEMENT: case OP::OP_GET_OBJECT_ELEMENT__WRITE: @@ -1615,6 +1660,17 @@ const String* Request::get_method_filena case OP::OP_WITH_SELF__VALUE__GET_ELEMENT: case OP::OP_WITH_SELF__VALUE__GET_ELEMENT__WRITE: #endif + +#ifdef FEATURE_GET_ELEMENT4CALL + case OP::OP_GET_ELEMENT4CALL: +#ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT + case OP::OP_GET_OBJECT_ELEMENT4CALL: +#endif +#ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT + case OP::OP_GET_OBJECT_VAR_ELEMENT4CALL: +#endif +#endif // FEATURE_GET_ELEMENT4CALL + #ifdef OPTIMIZE_BYTECODE_CONSTRUCT case OP::OP_WITH_ROOT__VALUE__CONSTRUCT_EXPR: case OP::OP_WITH_ROOT__VALUE__CONSTRUCT_VALUE: