--- parser3/src/main/execute.C 2002/10/16 08:22:14 1.285 +++ parser3/src/main/execute.C 2003/04/07 12:39:32 1.296 @@ -1,11 +1,11 @@ /** @file Parser: executor part of request class. - Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_EXECUTE_C="$Date: 2002/10/16 08:22:14 $"; +static const char* IDENT_EXECUTE_C="$Date: 2003/04/07 12:39:32 $"; #include "pa_opcode.h" #include "pa_array.h" @@ -123,6 +123,11 @@ void Request::execute(const Array& ops) Array_iter i(ops); while(i.has_next()) { + if(interrupted()) + throw Exception("parser.interrupted", + 0, + "execution stopped"); + Operation op; op.cast=i.next(); #ifdef DEBUG_EXECUTE @@ -177,6 +182,11 @@ void Request::execute(const Array& ops) } case OP_WITH_WRITE: { + if(wcontext==method_frame) + throw Exception("parser.runtime", + 0, + "$.name outside of $name[...]"); + PUSH(wcontext); break; } @@ -716,48 +726,54 @@ void Request::execute(const Array& ops) case OP_NUM_LT: { b=POP(); a=POP(); - double result=a->as_double() - b->as_double(); - value=NEW VBool(pool(), result < 0.0); + volatile double a_double=a->as_double(); + volatile double b_double=b->as_double(); + value=NEW VBool(pool(), a_doubleas_double() - b->as_double(); - value=NEW VBool(pool(), result > 0.0); + volatile double a_double=a->as_double(); + volatile double b_double=b->as_double(); + value=NEW VBool(pool(), a_double>b_double); PUSH(value); break; } case OP_NUM_LE: { b=POP(); a=POP(); - double result=a->as_double() - b->as_double(); - value=NEW VBool(pool(), result <= 0.0); + volatile double a_double=a->as_double(); + volatile double b_double=b->as_double(); + value=NEW VBool(pool(), a_double<=b_double); PUSH(value); break; } case OP_NUM_GE: { b=POP(); a=POP(); - double result=a->as_double() - b->as_double(); - value=NEW VBool(pool(), result >= 0.0); + volatile double a_double=a->as_double(); + volatile double b_double=b->as_double(); + value=NEW VBool(pool(), a_double>=b_double); PUSH(value); break; } case OP_NUM_EQ: { b=POP(); a=POP(); - double result=a->as_double() - b->as_double(); - value=NEW VBool(pool(), result == 0.0); + volatile double a_double=a->as_double(); + volatile double b_double=b->as_double(); + value=NEW VBool(pool(), a_double==b_double); PUSH(value); break; } case OP_NUM_NE: { b=POP(); a=POP(); - double result=a->as_double() - b->as_double(); - value=NEW VBool(pool(), result != 0.0); + volatile double a_double=a->as_double(); + volatile double b_double=b->as_double(); + value=NEW VBool(pool(), a_double!=b_double); PUSH(value); break; } @@ -819,14 +835,16 @@ void Request::execute(const Array& ops) } } -/// @test cache|prepare junctions +/** + @todo cache|prepare junctions + @bug ^superbase:method would dynamically call ^base:method if there is any +*/ Value *Request::get_element(const String *& remember_name, bool can_call_operator) { const String& name=POP_NAME(); remember_name=&name; Value *ncontext=POP(); Value *value=0; if(can_call_operator) { if(Method* method=main_class.get_method(name)) { // looking operator of that name FIRST - // as if that method were in self and we have normal dynamic method here Junction& junction=*NEW Junction(pool(), main_class, method, 0,0,0,0); value=NEW VJunction(junction); @@ -838,18 +856,26 @@ Value *Request::get_element(const String 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 - if(Value *base_object=get_self()->base_object()) { // doing DYNAMIC call - Temp_derived temp_derived(*base_object, 0); // temporarily prevent go-back-down virtual calls - value=base_object->get_element(name, base_object, false); // virtual-up lookup starting from parent - goto _void; + if(Value *base=get_self()->base()) { // doing DYNAMIC call + Temp_derived temp_derived(*base, 0); // temporarily prevent go-back-down virtual calls + value=base->get_element(name, *base, false); // virtual-up lookup starting from parent + goto value_ready; } } if(!value) - value=ncontext->get_element(name, ncontext, false); + value=ncontext->get_element(name, *ncontext, false); + + if(value && wcontext->get_constructing()) + if(Junction *junction=value->get_junction()) { + if(junction->self.get_class()!=ncontext) + throw Exception("parser.runtime", + &name, + "constructor must be declared in class %s", ncontext->get_class()->name_cstr()); + } -_void: +value_ready: if(value) - value=&process_to_value(*value); // process possible code-junction + value=&process_to_value(*value); // process possible code-junction else value=NEW VVoid(pool()); @@ -885,7 +911,6 @@ StringOrValue Request::process(Value& in Value *saved_rcontext=rcontext; WContext *saved_wcontext=wcontext; -//// self=&junction->self; method_frame=junction->method_frame; rcontext=junction->rcontext; @@ -936,7 +961,7 @@ const String& Request::execute_method(VM WContext *saved_wcontext=wcontext; // initialize contexts - /****self=*/rcontext=wcontext=method_frame=&amethod_frame; + rcontext=wcontext=method_frame=&amethod_frame; // execute! execute(*method.parser_code); @@ -1002,7 +1027,7 @@ void Request::execute_nonvirtual_method( const String *Request::execute_virtual_method(Value& aself, const String& method_name) { - if(Value *value=aself.get_element(method_name, &aself, false)) + if(Value *value=aself.get_element(method_name, aself, false)) if(Junction *junction=value->get_junction()) if(const Method *method=junction->method) { const String *result;