Diff for /parser3/src/main/execute.C between versions 1.349 and 1.352

version 1.349, 2009/06/14 00:34:04 version 1.352, 2009/06/29 09:25:29
Line 451  void Request::execute(ArrayOperation& op Line 451  void Request::execute(ArrayOperation& op
                         }                          }
                 case OP::OP_WRITE_EXPR_RESULT:                  case OP::OP_WRITE_EXPR_RESULT:
                         {                          {
                                 Value& value=stack.pop().value();  
                                 write_no_lang(value.as_expr_result());  
   
                                 // must be after write(result) and   
                                 // see OP_PREPARE_TO_EXPRESSION                                  // see OP_PREPARE_TO_EXPRESSION
                                 wcontext->set_in_expression(false);                                  wcontext->set_in_expression(false);
   
                                   Value& value=stack.pop().value();
                                   wcontext->write(value.as_expr_result());
                                 break;                                  break;
                         }                          }
                 case OP::OP_STRING__WRITE:                  case OP::OP_STRING__WRITE:
Line 645  void Request::execute(ArrayOperation& op Line 644  void Request::execute(ArrayOperation& op
                                 String::Language saved_lang=flang;                                  String::Language saved_lang=flang;
                                 flang=String::L_PASS_APPENDED;                                  flang=String::L_PASS_APPENDED;
 #ifdef OPTIMIZE_SINGLE_STRING_WRITE  #ifdef OPTIMIZE_SINGLE_STRING_WRITE
                                 WObjectPoolWrapper local(0/*empty*/, wcontext);                                  WObjectPoolWrapper local(wcontext);
 #else  #else
                                 WWrapper local(0/*empty*/, wcontext);                                  WWrapper local(wcontext);
 #endif  #endif
                                 wcontext=&local;                                  wcontext=&local;
   
Line 664  void Request::execute(ArrayOperation& op Line 663  void Request::execute(ArrayOperation& op
                                 ArrayOperation& local_ops=*i.next().ops;                                  ArrayOperation& local_ops=*i.next().ops;
   
                                 WContext *saved_wcontext=wcontext;                                  WContext *saved_wcontext=wcontext;
                                 WWrapper local(0 /*empty*/, wcontext);                                  WWrapper local(wcontext);
                                 wcontext=&local;                                  wcontext=&local;
   
                                 execute(local_ops);                                  execute(local_ops);
Line 716  void Request::execute(ArrayOperation& op Line 715  void Request::execute(ArrayOperation& op
 #ifndef OPTIMIZE_BYTECODE_CONSTRUCT_OBJECT  #ifndef OPTIMIZE_BYTECODE_CONSTRUCT_OBJECT
                 case OP::OP_PREPARE_TO_CONSTRUCT_OBJECT:                  case OP::OP_PREPARE_TO_CONSTRUCT_OBJECT:
                         {                          {
                                 wcontext->set_constructing(true);                                  SET_CONSTRUCTING(wcontext,true)
                                 break;                                  break;
                         }                          }
 #endif  #endif
Line 727  void Request::execute(ArrayOperation& op Line 726  void Request::execute(ArrayOperation& op
                                 break;                                  break;
                         }                          }
   
   #define METHOD_FRAME_ACTION(action)                                                                                                     \
                   if(local_ops){                                                                                                                          \
                           size_t first = stack.top_index();                                                                               \
                           execute(*local_ops);                                                                                                    \
                           frame.store_params((Value**)stack.ptr(first), stack.top_index()-first); \
                           action;                                                                                                                                 \
                           stack.set_top_index(first);                                                                                             \
                   } else {                                                                                                                                        \
                           frame.empty_params();                                                                                                   \
                           action;                                                                                                                                 \
                   }
   
                 case OP::OP_CALL:                  case OP::OP_CALL:
                         {                          {
                                 ArrayOperation* local_ops=i.next().ops;                                  ArrayOperation* local_ops=i.next().ops;
Line 750  void Request::execute(ArrayOperation& op Line 761  void Request::execute(ArrayOperation& op
                                 }                                  }
   
                                 VMethodFrame frame(*junction, method_frame);                                  VMethodFrame frame(*junction, method_frame);
                                   METHOD_FRAME_ACTION(op_call(frame, GET_CONSTRUCTING(wcontext)));
                                 if(local_ops){ // store param code goes here  
                                         size_t first = stack.top_index();  
                                         execute(*local_ops);  
                                         frame.store_params((Value**)stack.ptr(first), stack.top_index()-first);  
                                         op_call(frame);  
                                         stack.set_top_index(first);  
                                 } else {  
                                         frame.empty_params();  
                                         op_call(frame);  
                                 }  
   
                                 stack.push(frame.result().as_value());                                  stack.push(frame.result().as_value());
   
                                 DEBUG_PRINT_STR("<-returned")                                  DEBUG_PRINT_STR("<-returned")
Line 801  void Request::execute(ArrayOperation& op Line 801  void Request::execute(ArrayOperation& op
   
 #ifdef OPTIMIZE_CALL  #ifdef OPTIMIZE_CALL
                                 const Method& method=*junction->method;                                  const Method& method=*junction->method;
                                 if (!wcontext->get_constructing() && method.call_optimization==Method::CO_WITHOUT_FRAME){                                  if (!GET_CONSTRUCTING(wcontext) && method.call_optimization==Method::CO_WITHOUT_FRAME){
                                         if(local_ops){ // store param code goes here                                          if(local_ops){ // store param code goes here
                                                 size_t first = stack.top_index();                                                  size_t first = stack.top_index();
                                                 execute(*local_ops);                                                  execute(*local_ops);
Line 817  void Request::execute(ArrayOperation& op Line 817  void Request::execute(ArrayOperation& op
                                                 method.check_actual_numbered_params(junction->self, &method_params);                                                  method.check_actual_numbered_params(junction->self, &method_params);
                                                 method.native_code(*this, method_params); // execute it                                                  method.native_code(*this, method_params); // execute it
                                         }                                          }
                                 } else if (!wcontext->get_constructing() && method.call_optimization==Method::CO_WITHOUT_WCONTEXT){                                  } else if (!GET_CONSTRUCTING(wcontext) && method.call_optimization==Method::CO_WITHOUT_WCONTEXT){
                                         VMethodFrame frame(*junction, method_frame);                                          VMethodFrame frame(*junction, method_frame);
                                         if(local_ops){ // store param code goes here                                          METHOD_FRAME_ACTION(op_call_write(frame));
                                                 size_t first = stack.top_index();  
                                                 execute(*local_ops);  
   
                                                 frame.store_params((Value**)stack.ptr(first), stack.top_index()-first);  
                                                 op_call_write(frame);  
   
                                                 stack.set_top_index(first);  
                                         } else {  
                                                 frame.empty_params();  
                                                 op_call_write(frame);  
                                         }  
                                 } else                                   } else 
 #endif // OPTIMIZE_CALL  #endif // OPTIMIZE_CALL
                                 {                                  {
                                         VMethodFrame frame(*junction, method_frame);                                          VMethodFrame frame(*junction, method_frame);
                                         if(local_ops){ // store param code goes here                                          METHOD_FRAME_ACTION(op_call(frame, GET_CONSTRUCTING(wcontext)));
                                                 size_t first = stack.top_index();  
                                                 execute(*local_ops);  
   
                                                 frame.store_params((Value**)stack.ptr(first), stack.top_index()-first);  
                                                 op_call(frame);  
   
                                                 stack.set_top_index(first);  
                                         } else {  
                                                 frame.empty_params();  
                                                 op_call(frame);  
                                         }  
                                         write_pass_lang(frame.result());                                          write_pass_lang(frame.result());
                                 }                                  }
   
Line 867  void Request::execute(ArrayOperation& op Line 845  void Request::execute(ArrayOperation& op
                 case OP::OP_CONSTRUCT_OBJECT:                  case OP::OP_CONSTRUCT_OBJECT:
                 case OP::OP_CONSTRUCT_OBJECT__WRITE:                  case OP::OP_CONSTRUCT_OBJECT__WRITE:
                         {                          {
                                 // maybe they do ^class:method[] call, remember the fact  
                                 wcontext->set_somebody_entered_some_class();  
   
                                 debug_origin=i.next().origin;                                  debug_origin=i.next().origin;
                                 Value& vclass_name=*i.next().value;                                  Value& vclass_name=*i.next().value;
                                 const String& class_name=*vclass_name.get_string();                                  const String& class_name=*vclass_name.get_string();
Line 882  void Request::execute(ArrayOperation& op Line 857  void Request::execute(ArrayOperation& op
                                                 &class_name,                                                  &class_name,
                                                 "class is undefined");                                                   "class is undefined"); 
   
                                 wcontext->set_constructing(true);                                  SET_CONSTRUCTING(wcontext,true)
   
                                 debug_origin=i.next().origin;                                  debug_origin=i.next().origin;
                                 Value& vconstructor_name=*i.next().value;                                  Value& vconstructor_name=*i.next().value;
Line 892  void Request::execute(ArrayOperation& op Line 867  void Request::execute(ArrayOperation& op
   
                                 Value& constructor_value=get_element(*class_value, constructor_name);                                  Value& constructor_value=get_element(*class_value, constructor_name);
   
                                   Junction* junction=constructor_value.get_junction();
   #ifdef OPTIMIZE_CONSTRUCT_OBJECT
                                   if(!junction || junction->self.get_class()!=class_value)
                                           throw Exception(PARSER_RUNTIME,
                                                   &constructor_name,
                                                   "constructor must be declared in class '%s'", 
                                                   class_value->get_class()->name_cstr());
   #endif
   
                                 ArrayOperation* local_ops=i.next().ops;                                  ArrayOperation* local_ops=i.next().ops;
                                 DEBUG_PRINT_OPS(local_ops)                                  DEBUG_PRINT_OPS(local_ops)
                                 DEBUG_PRINT_STR("->\n")                                  DEBUG_PRINT_STR("->\n")
   
                                 Junction* junction=constructor_value.get_junction();                                  VMethodFrame frame(*junction, method_frame);
                                 if(!junction) {                                  METHOD_FRAME_ACTION(op_call(frame, true /* constructing */));
                                         if(constructor_value.is("void"))                                  if(opcode==OP::OP_CONSTRUCT_OBJECT)
                                                 throw Exception(PARSER_RUNTIME,                                          stack.push(frame.result().as_value());
                                                         0,                                  else
                                                         "undefined method");                                          write_pass_lang(frame.result());
                                         else  
                                                 throw Exception(PARSER_RUNTIME,  
                                                         0,  
                                                         "is '%s', not a method or junction, can not call it",  
                                                         constructor_value.type());  
                                 } else {  
                                         VMethodFrame frame(*junction, method_frame);  
                                         if(local_ops){ // store param code goes here  
                                                 size_t first = stack.top_index();  
                                                 execute(*local_ops);  
   
                                                 frame.store_params((Value**)stack.ptr(first), stack.top_index()-first);  
                                                 op_call(frame);  
   
                                                 stack.set_top_index(first);  
                                         } else {  
                                                 frame.empty_params();  
                                                 op_call(frame);  
                                         }  
                                           
                                         if(opcode==OP::OP_CONSTRUCT_OBJECT)  
                                                 stack.push(frame.result().as_value());  
                                         else  
                                                 write_pass_lang(frame.result());  
                                 }  
   
                                 DEBUG_PRINT_STR("<-returned")                                  DEBUG_PRINT_STR("<-returned")
   
   
 /*  
                                 if(get_skip())  
                                         return;  
                                 if(get_interrupted()) {  
                                         set_interrupted(false);  
                                         throw Exception("parser.interrupted",  
                                                 0,  
                                                 "execution stopped");  
                                 }  
 */  
                                 break;                                  break;
                         }                          }
 #endif // OPTIMIZE_BYTECODE_CONSTRUCT_OBJECT  #endif // OPTIMIZE_BYTECODE_CONSTRUCT_OBJECT
Line 1276  void Request::execute(ArrayOperation& op Line 1223  void Request::execute(ArrayOperation& op
         rcontext=saved_rcontext;                        \          rcontext=saved_rcontext;                        \
         method_frame=saved_method_frame;          method_frame=saved_method_frame;
   
 void Request::op_call(VMethodFrame& frame){  void Request::op_call(VMethodFrame& frame, bool constructing){
         const Junction &junction=frame.junction;          const Junction &junction=frame.junction;
         VStateless_class& called_class=*junction.self.get_class();          VStateless_class& called_class=*junction.self.get_class();
         Value* new_self;          Value* new_self;
   
         if(wcontext->get_constructing()) {          if(constructing) {
                 wcontext->set_constructing(false);                  SET_CONSTRUCTING(wcontext,false)
                 if(junction.method->call_type!=Method::CT_STATIC) {                  if(junction.method->call_type!=Method::CT_STATIC) {
                         // this is a constructor call                          // this is a constructor call
                         if(new_self=called_class.create_new_value(fpool, 0 /*creating fields only in VClass*/)) {                          if(new_self=called_class.create_new_value(fpool, 0 /*creating fields only in VClass*/)) {
Line 1366  void Request::op_call_write(VMethodFrame Line 1313  void Request::op_call_write(VMethodFrame
         @bug ^superbase:method would dynamically call ^base:method if there is any          @bug ^superbase:method would dynamically call ^base:method if there is any
 */  */
 Value& Request::get_element(Value& ncontext, const String& name) {  Value& Request::get_element(Value& ncontext, const String& name) {
         if(!wcontext->get_constructing() // not constructing          if(!GET_CONSTRUCTING(wcontext) // not constructing
                 && wcontext->get_somebody_entered_some_class() ) // ^class:method                  && wcontext->get_somebody_entered_some_class() ) // ^class:method
                         if(VStateless_class *called_class=ncontext.get_class())                          if(VStateless_class *called_class=ncontext.get_class())
                                 if(VStateless_class *read_class=rcontext->get_class())                                  if(VStateless_class *read_class=rcontext->get_class())
Line 1379  Value& Request::get_element(Value& ncont Line 1326  Value& Request::get_element(Value& ncont
   
         Value* value=ncontext.get_element(name, ncontext, true);          Value* value=ncontext.get_element(name, ncontext, true);
   
         if(value && wcontext->get_constructing())          if(value && GET_CONSTRUCTING(wcontext))
                 if(Junction* junction=value->get_junction())                  if(Junction* junction=value->get_junction())
                         if(junction->self.get_class()!=&ncontext)                          if(junction->self.get_class()!=&ncontext)
                                 throw Exception(PARSER_RUNTIME,                                  throw Exception(PARSER_RUNTIME,
Line 1396  void Request::put_element(Value& ncontex Line 1343  void Request::put_element(Value& ncontex
                 if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) {                  if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) {
                         // process it                          // process it
                         VMethodFrame frame(vjunction->junction(), method_frame/*caller*/);                          VMethodFrame frame(vjunction->junction(), method_frame/*caller*/);
                         int param_count=frame.method_params_count();  
   
                           size_t param_count=frame.method_params_count();
                         if(param_count!=1)                          if(param_count!=1)
                                 throw Exception(PARSER_RUNTIME,                                  throw Exception(PARSER_RUNTIME,
                                         0,                                          0,
Line 1437  StringOrValue Request::process(Value& in Line 1384  StringOrValue Request::process(Value& in
         if(junction) {          if(junction) {
                 if(junction->is_getter) { // is it a getter-junction?                  if(junction->is_getter) { // is it a getter-junction?
                         VMethodFrame frame(*junction, method_frame/*caller*/);                          VMethodFrame frame(*junction, method_frame/*caller*/);
                         int param_count=frame.method_params_count();  
   
                         if(param_count){                          if(size_t param_count=frame.method_params_count()){
                                 if(junction->auto_name){ // default getter                                  if(junction->auto_name){ // default getter
                                         if(param_count==1){                                          if(param_count==1){
                                                 Value *param=new VString(*junction->auto_name);                                                  Value *param=new VString(*junction->auto_name);
Line 1477  StringOrValue Request::process(Value& in Line 1423  StringOrValue Request::process(Value& in
   
                         if(!junction->method_frame)                          if(!junction->method_frame)
                                 throw Exception(PARSER_RUNTIME,                                  throw Exception(PARSER_RUNTIME,
                                 0,                                          0,
                                 "junction used outside of context");                                          "junction used outside of context");
   
                         SAVE_CONTEXT                          SAVE_CONTEXT
   
Line 1502  StringOrValue Request::process(Value& in Line 1448  StringOrValue Request::process(Value& in
                                 result=wcontext->result();                                  result=wcontext->result();
                         } else {                          } else {
                                 // plain wwrapper                                  // plain wwrapper
                                 WWrapper local(0/*empty*/, wcontext);                                  WWrapper local(wcontext);
                                 wcontext=&local;                                  wcontext=&local;
   
                                 // execute it                                  // execute it
Line 1530  void Request::process_write(Value& input Line 1476  void Request::process_write(Value& input
         if(junction) {          if(junction) {
                 if(junction->is_getter) { // is it a getter-junction?                  if(junction->is_getter) { // is it a getter-junction?
                         VMethodFrame frame(*junction, method_frame/*caller*/);                          VMethodFrame frame(*junction, method_frame/*caller*/);
                         int param_count=frame.method_params_count();  
   
                         if(param_count){                          if(size_t param_count=frame.method_params_count()){
                                 if(junction->auto_name){ // default getter                                  if(junction->auto_name){ // default getter
                                         if(param_count==1){                                          if(param_count==1){
                                                 Value *param=new VString(*junction->auto_name);                                                  Value *param=new VString(*junction->auto_name);
Line 1599  void Request::process_write(Value& input Line 1544  void Request::process_write(Value& input
                                 write_pass_lang(local.result());                                  write_pass_lang(local.result());
                         } else {                          } else {
                                 // plain wwrapper                                  // plain wwrapper
                                 WWrapper local(0/*empty*/, wcontext);                                  WWrapper local(wcontext);
                                 wcontext=&local;                                  wcontext=&local;
   
                                 // execute it                                  // execute it

Removed from v.1.349  
changed lines
  Added in v.1.352


E-mail: