--- parser3/src/main/execute.C 2005/07/26 12:43:05 1.308 +++ parser3/src/main/execute.C 2005/08/09 08:14:51 1.313 @@ -1,11 +1,11 @@ /** @file Parser: executor part of request class. - Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_EXECUTE_C="$Date: 2005/07/26 12:43:05 $"; +static const char * const IDENT_EXECUTE_C="$Date: 2005/08/09 08:14:51 $"; #include "pa_opcode.h" #include "pa_array.h" @@ -186,41 +186,7 @@ void Request::execute(ArrayOperation& op Value& value=stack.pop().value(); const String& name=stack.pop().string(); debug_name=&name; Value& ncontext=stack.pop().value(); - - // put_element can return property-setting-junction - if(const Junction* junction=ncontext.put_element(name, &value, false)) - if(junction!=PUT_ELEMENT_REPLACED_ELEMENT) { - // process it - ArrayString* params_names=junction->method->params_names; - int param_count=params_names? params_names->count(): 0; - if(param_count!=1) - throw Exception("parser.runtime", - 0, - "setter method must have one parameter (has %d parameters)", param_count); - - // TODO: move that to this::execute_method [fix it's param types] - VMethodFrame frame(*junction, method_frame/*caller*/); - frame.store_param(value); - - frame.set_self(frame.junction.self); - - VMethodFrame *saved_method_frame=method_frame; - Value* saved_rcontext=rcontext; - WContext *saved_wcontext=wcontext; - - rcontext=wcontext=&frame; - method_frame=&frame; - - // prevent non-string writes for better error reporting - wcontext->write(*method_frame); - - recoursion_checked_execute(*frame.junction.method->parser_code); // parser code, execute it - // we don't need it StringOrValue result=wcontext->result(); - - method_frame=saved_method_frame; - wcontext=saved_wcontext; - rcontext=saved_rcontext; - } + put_element(ncontext, name, value); break; } @@ -233,12 +199,7 @@ void Request::execute(ArrayOperation& op const String& name=stack.pop().string(); debug_name=&name; Value& ncontext=stack.pop().value(); Value& value=expr.as_expr_result(); - if(const Junction* junction=ncontext.put_element(name, &value, false)) - if(junction!=PUT_ELEMENT_REPLACED_ELEMENT) { - throw Exception("parser.runtime", - 0, - "TODO:paf -- $property(value)"); - } + put_element(ncontext, name, value); break; } case OP_CURLY_CODE__CONSTRUCT: @@ -248,17 +209,17 @@ void Request::execute(ArrayOperation& op debug_printf(sapi_info, " (%d)\n", local_ops.count()); debug_dump(sapi_info, 1, local_ops); #endif - Value& value=*new VJunction(new Junction( + Value& value=*new VJunction( get_self(), 0, method_frame, rcontext, wcontext, - &local_ops)); + &local_ops); const String& name=stack.pop().string(); debug_name=&name; Value& ncontext=stack.pop().value(); - if(const Junction* junction=ncontext.put_element(name, &value, false)) - if(junction!=PUT_ELEMENT_REPLACED_ELEMENT) + if(const VJunction* vjunction=ncontext.put_element(ncontext, name, &value, false)) + if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) throw Exception("parser.runtime", 0, "property value can not be code, use [] or () brackets"); @@ -396,12 +357,12 @@ void Request::execute(ArrayOperation& op // hence, we zero junction.wcontext here, and later // in .process we would test that field // in decision "which wwrapper to use" - Value& value=*new VJunction(new Junction( + Value& value=*new VJunction( get_self(), 0, method_frame, rcontext, opcode==OP_EXPR_CODE__STORE_PARAM?0:wcontext, - &local_ops)); + &local_ops); // store param // this op is executed from CALL local_ops only, so can not check method_frame_to_fill==0 frame.store_param(value); @@ -478,7 +439,8 @@ 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(fpool)) { + HashStringValue& new_object_fields=*new HashStringValue(); + if(Value* value=called_class.create_new_value(fpool, new_object_fields)) { // some stateless_class creatable derivates new_self=value; } else @@ -875,7 +837,7 @@ Value& Request::get_element(Value& ncont Value* value=0; if(can_call_operator) { if(Method* method=main_class.get_method(name)) // looking operator of that name FIRST - value=new VJunction(new Junction(main_class, method)); + value=new VJunction(main_class, method); } if(!value) { if(!wcontext->get_constructing() // not constructing @@ -910,6 +872,43 @@ value_ready: return *value; } +void Request::put_element(Value& ncontext, const String& name, Value& value) { + // put_element can return property-setting-junction + if(const VJunction* vjunction=ncontext.put_element(ncontext, name, &value, false)) + if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) { + const Junction& junction=vjunction->junction(); + // process it + ArrayString* params_names=junction.method->params_names; + int param_count=params_names? params_names->count(): 0; + if(param_count!=1) + throw Exception("parser.runtime", + 0, + "setter method must have ONE parameter (has %d parameters)", param_count); + + VMethodFrame frame(junction, method_frame/*caller*/); + frame.store_param(value); + + frame.set_self(frame.junction.self); + + VMethodFrame *saved_method_frame=method_frame; + Value* saved_rcontext=rcontext; + WContext *saved_wcontext=wcontext; + + rcontext=wcontext=&frame; + method_frame=&frame; + + // prevent non-string writes for better error reporting [setters are not expected to return anything] + wcontext->write(*method_frame); + + recoursion_checked_execute(*frame.junction.method->parser_code); // parser code, execute it + // we don't need it StringOrValue result=wcontext->result(); + + method_frame=saved_method_frame; + wcontext=saved_wcontext; + rcontext=saved_rcontext; + } +} + /** @param intercept_string - true: they want result=string value,