Diff for /parser3/src/main/execute.C between versions 1.337 and 1.342

version 1.337, 2009/05/20 13:22:59 version 1.342, 2009/05/24 07:34:10
Line 66  char *opcode_name[]={ Line 66  char *opcode_name[]={
         "CALL", "CALL__WRITE",          "CALL", "CALL__WRITE",
   
 #ifdef OPTIMIZE_BYTECODE_CONSTRUCT  #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
         "ROOT_CONSTRUCT_EXPR", "ROOT_CONSTRUCT_VALUE",          "ROOT_CONSTRUCT_EXPR",
         "WRITE_CONSTRUCT_EXPR", "WRITE_CONSTRUCT_VALUE",          "ROOT_ELEMENT_CONSTRUCT_EXPR",
           "ROOT_OBJECT_ELEMENT_CONSTRUCT_EXPR",
           "ROOT_OBJECT_VAR_ELEMENT_CONSTRUCT_EXPR",
   
           "ROOT_CONSTRUCT_VALUE",
           "ROOT_ELEMENT_CONSTRUCT_VALUE",
           "ROOT_OBJECT_ELEMENT_CONSTRUCT_VALUE",
           "ROOT_OBJECT_VAR_ELEMENT_CONSTRUCT_VALUE",
   
           "WRITE_CONSTRUCT_EXPR",
           "WRITE_ELEMENT_CONSTRUCT_EXPR",
           "WRITE_OBJECT_ELEMENT_CONSTRUCT_EXPR",
           "WRITE_OBJECT_VAR_ELEMENT_CONSTRUCT_EXPR",
   
           "WRITE_CONSTRUCT_VALUE",
           "WRITE_ELEMENT_CONSTRUCT_VALUE",
           "WRITE_OBJECT_ELEMENT_CONSTRUCT_VALUE",
           "WRITE_OBJECT_VAR_ELEMENT_CONSTRUCT_VALUE",
   #endif
   
   #ifdef OPTIMIZE_BYTECODE_CALL_CONSTRUCT
           "ROOT_CALL_CONSTRUCT_EXPR",
           //"ROOT_CALL_OBJECT_ELEMENT_CONSTRUCT_EXPR",
   
           "ROOT_CALL_CONSTRUCT_VALUE",
           //"ROOT_CALL_OBJECT_ELEMENT_CONSTRUCT_VALUE",
   
           "WRITE_CALL_CONSTRUCT_EXPR",
           //"WRITE_CALL_OBJECT_ELEMENT_CONSTRUCT_EXPR",
   
           "WRITE_CALL_CONSTRUCT_VALUE",
           //"WRITE_CALL_OBJECT_ELEMENT_CONSTRUCT_VALUE",
 #endif  #endif
   
         // expression ops: unary          // expression ops: unary
Line 82  char *opcode_name[]={ Line 113  char *opcode_name[]={
         "IS"          "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()?"<true>":"<false>";
                   else
                           return "<value>";
   }
   
 void va_debug_printf(SAPI_Info& sapi_info, const char* fmt,va_list args) {  void va_debug_printf(SAPI_Info& sapi_info, const char* fmt,va_list args) {
         char buf[MAX_STRING];          char buf[MAX_STRING];
         vsnprintf(buf, MAX_STRING, fmt, args);          vsnprintf(buf, MAX_STRING, fmt, args);
Line 113  void debug_dump(SAPI_Info& sapi_info, in Line 156  void debug_dump(SAPI_Info& sapi_info, in
 #endif  #endif
 #ifdef OPTIMIZE_BYTECODE_CONSTRUCT  #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
                         || opcode==OP::OP_ROOT_CONSTRUCT_EXPR                          || opcode==OP::OP_ROOT_CONSTRUCT_EXPR
                           || opcode==OP::OP_ROOT_ELEMENT_CONSTRUCT_EXPR
   
                         || opcode==OP::OP_ROOT_CONSTRUCT_VALUE                          || opcode==OP::OP_ROOT_CONSTRUCT_VALUE
                           || opcode==OP::OP_ROOT_ELEMENT_CONSTRUCT_VALUE
   
                         || opcode==OP::OP_WRITE_CONSTRUCT_EXPR                          || opcode==OP::OP_WRITE_CONSTRUCT_EXPR
                           || opcode==OP::OP_WRITE_ELEMENT_CONSTRUCT_EXPR
   
                         || opcode==OP::OP_WRITE_CONSTRUCT_VALUE                          || opcode==OP::OP_WRITE_CONSTRUCT_VALUE
                           || opcode==OP::OP_WRITE_ELEMENT_CONSTRUCT_VALUE
   #endif
   #ifdef OPTIMIZE_BYTECODE_CALL_CONSTRUCT
                           || opcode==OP::OP_ROOT_CALL_CONSTRUCT_EXPR
                           || opcode==OP::OP_ROOT_CALL_CONSTRUCT_VALUE
   
                           || opcode==OP::OP_WRITE_CALL_CONSTRUCT_EXPR
                           || opcode==OP::OP_WRITE_CALL_CONSTRUCT_VALUE
 #endif  #endif
                 ){                  ){
                         i.next(); // skip origin                          i.next(); // skip origin
Line 126  void debug_dump(SAPI_Info& sapi_info, in Line 183  void debug_dump(SAPI_Info& sapi_info, in
                                 "%*s%s"                                  "%*s%s"
                                 " \"%s\" \"%s\"",                                   " \"%s\" \"%s\"", 
                                 level*4, "", opcode_name[opcode],                                  level*4, "", opcode_name[opcode],
                                 value1.get_string()->cstr(), value2.get_string()->cstr());                                  debug_value_to_cstr(value1), debug_value_to_cstr(value2));
                         continue;                          continue;
                 }                  }
 #endif  #endif
Line 141  void debug_dump(SAPI_Info& sapi_info, in Line 198  void debug_dump(SAPI_Info& sapi_info, in
                         || opcode==OP::OP_VALUE__GET_ELEMENT__WRITE                          || opcode==OP::OP_VALUE__GET_ELEMENT__WRITE
                         || opcode==OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR                          || opcode==OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR
 #endif  #endif
   #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
                           || opcode==OP::OP_ROOT_OBJECT_ELEMENT_CONSTRUCT_EXPR
                           || opcode==OP::OP_ROOT_OBJECT_VAR_ELEMENT_CONSTRUCT_EXPR
   
                           || opcode==OP::OP_ROOT_OBJECT_ELEMENT_CONSTRUCT_VALUE
                           || opcode==OP::OP_ROOT_OBJECT_VAR_ELEMENT_CONSTRUCT_VALUE
   
                           || opcode==OP::OP_WRITE_OBJECT_ELEMENT_CONSTRUCT_EXPR
                           || opcode==OP::OP_WRITE_OBJECT_VAR_ELEMENT_CONSTRUCT_EXPR
   
                           || opcode==OP::OP_WRITE_OBJECT_ELEMENT_CONSTRUCT_VALUE
                           || opcode==OP::OP_WRITE_OBJECT_VAR_ELEMENT_CONSTRUCT_VALUE
   #endif
                 ) {                  ) {
                         Operation::Origin origin=i.next().origin;                          Operation::Origin origin=i.next().origin;
                         Value& value=*i.next().value;                          Value& value=*i.next().value;
   
                         debug_printf(sapi_info,                           debug_printf(sapi_info, 
                                 "%*s%s"                                  "%*s%s"
                                 " \"%s\" %s",                                   " \"%s\" %s", 
                                 level*4, "", opcode_name[opcode],                                  level*4, "", opcode_name[opcode],
                                 value.get_string()->cstr(), value.type());                                  debug_value_to_cstr(value), value.type());
                         continue;                          continue;
                 }                  }
                 debug_printf(sapi_info, "%*s%s", level*4, "", opcode_name[opcode]);                  debug_printf(sapi_info, "%*s%s", level*4, "", opcode_name[opcode]);
Line 169  void debug_dump(SAPI_Info& sapi_info, in Line 240  void debug_dump(SAPI_Info& sapi_info, in
 }  }
 #define DEBUG_PRINT_STR(str) debug_printf(sapi_info, str);  #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_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) \  #define DEBUG_PRINT_OPS(local_ops) \
                                         debug_printf(sapi_info, \                                          debug_printf(sapi_info, \
                                         " (%d)\n", local_ops?local_ops->count():0); \                                          " (%d)\n", local_ops?local_ops->count():0); \
Line 177  void debug_dump(SAPI_Info& sapi_info, in Line 249  void debug_dump(SAPI_Info& sapi_info, in
 #else  #else
 #define DEBUG_PRINT_STR(str)  #define DEBUG_PRINT_STR(str)
 #define DEBUG_PRINT_STRING(value)  #define DEBUG_PRINT_STRING(value)
   #define DEBUG_PRINT_VALUE_AND_TYPE(value)
 #define DEBUG_PRINT_OPS(local_ops)  #define DEBUG_PRINT_OPS(local_ops)
 #endif  #endif
   
Line 196  void Request::execute(ArrayOperation& op Line 269  void Request::execute(ArrayOperation& op
         for(Array_iterator<Operation> i(ops); i.has_next(); ) {          for(Array_iterator<Operation> i(ops); i.has_next(); ) {
                 OP::OPCODE opcode=i.next().code;                  OP::OPCODE opcode=i.next().code;
   
                   bool with_root=true;
   
 #ifdef DEBUG_EXECUTE  #ifdef DEBUG_EXECUTE
                 debug_printf(sapi_info, "%d:%s", stack.top_index()+1, opcode_name[opcode]);                  debug_printf(sapi_info, "%d:%s", stack.top_index()+1, opcode_name[opcode]);
 #endif  #endif
Line 206  void Request::execute(ArrayOperation& op Line 281  void Request::execute(ArrayOperation& op
                         {                          {
                                 debug_origin=i.next().origin;                                  debug_origin=i.next().origin;
                                 Value& value=*i.next().value;                                  Value& value=*i.next().value;
 #ifdef DEBUG_EXECUTE  
                                 debug_printf(sapi_info, " \"%s\" %s", value.get_string()->cstr(), value.type());                                  DEBUG_PRINT_VALUE_AND_TYPE(value)
 #endif  
                                 stack.push(value);                                  stack.push(value);
                                 break;                                  break;
                         }                          }
Line 290  void Request::execute(ArrayOperation& op Line 365  void Request::execute(ArrayOperation& op
                         }                          }
   
 #ifdef OPTIMIZE_BYTECODE_CONSTRUCT  #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
                   case OP::OP_WRITE_CONSTRUCT_EXPR:
                   case OP::OP_WRITE_CONSTRUCT_VALUE:
                           {
                                   if(wcontext==method_frame)
                                           throw Exception(PARSER_RUNTIME,
                                                   0,
                                                   "$.name outside of $name[...]");
                                   with_root=false;
                                   // don't stop here. continue in the next block
                           }
                 case OP::OP_ROOT_CONSTRUCT_EXPR:                  case OP::OP_ROOT_CONSTRUCT_EXPR:
                   case OP::OP_ROOT_CONSTRUCT_VALUE:
                         {                          {
                                 debug_origin=i.next().origin;                                  debug_origin=i.next().origin;
                                 const String& name=*i.next().value->get_string();  debug_name=&name;                                  const String& name=*i.next().value->get_string();  debug_name=&name;
                                   DEBUG_PRINT_STRING(name)
   
                                 i.next(); // skip origin                                  debug_origin=i.next().origin;
                                 Value& expr=*i.next().value;                                  Value& value=*i.next().value;
   
                                   if(
                                              opcode == OP::OP_WRITE_CONSTRUCT_EXPR
                                           || opcode == OP::OP_ROOT_CONSTRUCT_EXPR
                                   ){
                                           put_element( with_root?*method_frame:*wcontext, name, &value.as_expr_result());
                                   } else {
                                           put_element( with_root?*method_frame:*wcontext, name, &value);
                                   }
                                   break;
                           }
   
                   case OP::OP_WRITE_ELEMENT_CONSTRUCT_EXPR:
                   case OP::OP_WRITE_ELEMENT_CONSTRUCT_VALUE:
                           {
                                   if(wcontext==method_frame)
                                           throw Exception(PARSER_RUNTIME,
                                                   0,
                                                   "$.name outside of $name[...]");
                                   with_root=false;
                                   // don't stop here. continue in the next block
                           }
                   case OP::OP_ROOT_ELEMENT_CONSTRUCT_EXPR:
                   case OP::OP_ROOT_ELEMENT_CONSTRUCT_VALUE:
                           {
                                   debug_origin=i.next().origin;
                                   const String& name=*i.next().value->get_string();  debug_name=&name;
                                 DEBUG_PRINT_STRING(name)                                  DEBUG_PRINT_STRING(name)
   
                                 wcontext->set_in_expression(true);                                  debug_origin=i.next().origin;
                                   const String& source_var_name=*i.next().value->get_string();  debug_name=&source_var_name;
                                   DEBUG_PRINT_STRING(source_var_name)
   
                                   Value& value=get_element(*rcontext, source_var_name);
   
                                 Value& value=expr.as_expr_result();                                  if(
                                 put_element(*method_frame, name, &value);                                             opcode == OP::OP_WRITE_ELEMENT_CONSTRUCT_EXPR
                                           || opcode == OP::OP_ROOT_ELEMENT_CONSTRUCT_EXPR
                                   ){
                                           put_element( with_root?*method_frame:*wcontext, name, &value.as_expr_result());
                                   } else {
                                           put_element( with_root?*method_frame:*wcontext, name, value.is_void()?new VString():&value);
                                   }
                                 break;                                  break;
                         }                          }
   
                 case OP::OP_WRITE_CONSTRUCT_EXPR:                  case OP::OP_WRITE_OBJECT_ELEMENT_CONSTRUCT_EXPR:
                   case OP::OP_WRITE_OBJECT_ELEMENT_CONSTRUCT_VALUE:
                         {                          {
                                 if(wcontext==method_frame)                                  if(wcontext==method_frame)
                                         throw Exception(PARSER_RUNTIME,                                          throw Exception(PARSER_RUNTIME,
                                                 0,                                                  0,
                                                 "$.name outside of $name[...]");                                                  "$.name outside of $name[...]");
                                   with_root=false;
                                   // don't stop here. continue in the next block
                           }
                   case OP::OP_ROOT_OBJECT_ELEMENT_CONSTRUCT_EXPR:
                   case OP::OP_ROOT_OBJECT_ELEMENT_CONSTRUCT_VALUE:
                           {
                                 debug_origin=i.next().origin;                                  debug_origin=i.next().origin;
                                 const String& name=*i.next().value->get_string();  debug_name=&name;                                  const String& name=*i.next().value->get_string();  debug_name=&name;
                                   DEBUG_PRINT_STRING(name)
   
                                 i.next(); // skip origin                                  i.next(); // skip OP_GET_OBJECT_ELEMENT
                                 Value& expr=*i.next().value;                                  debug_origin=i.next().origin;
                                   const String& context_name=*i.next().value->get_string();  debug_name=&context_name;
                                   DEBUG_PRINT_STRING(context_name)
   
                                 DEBUG_PRINT_STRING(name)                                  Value& object=get_element(*rcontext, context_name);
   
                                 wcontext->set_in_expression(true);                                  debug_origin=i.next().origin;
                                   const String& field_name=*i.next().value->get_string();  debug_name=&field_name;
                                   DEBUG_PRINT_STRING(field_name)
   
                                 Value& value=expr.as_expr_result();                                  Value& value=get_element(object, field_name);
                                 put_element(*wcontext, name, &value);  
                                   if(
                                              opcode == OP::OP_WRITE_OBJECT_ELEMENT_CONSTRUCT_EXPR
                                           || opcode == OP::OP_ROOT_OBJECT_ELEMENT_CONSTRUCT_EXPR
                                   ){
                                           put_element( with_root?*method_frame:*wcontext, name, &value.as_expr_result());
                                   } else {
                                           put_element( with_root?*method_frame:*wcontext, name, value.is_void()?new VString():&value);
                                   }
                                 break;                                  break;
                         }                          }
   
                 case OP::OP_ROOT_CONSTRUCT_VALUE:                  case OP::OP_WRITE_OBJECT_VAR_ELEMENT_CONSTRUCT_EXPR:
                   case OP::OP_WRITE_OBJECT_VAR_ELEMENT_CONSTRUCT_VALUE:
                           {
                                   if(wcontext==method_frame)
                                           throw Exception(PARSER_RUNTIME,
                                                   0,
                                                   "$.name outside of $name[...]");
                                   with_root=false;
                                   // don't stop here. continue in the next block
                           }
                   case OP::OP_ROOT_OBJECT_VAR_ELEMENT_CONSTRUCT_EXPR:
                   case OP::OP_ROOT_OBJECT_VAR_ELEMENT_CONSTRUCT_VALUE:
                         {                          {
                                 debug_origin=i.next().origin;                                  debug_origin=i.next().origin;
                                 const String& name=*i.next().value->get_string();  debug_name=&name;                                  const String& name=*i.next().value->get_string();  debug_name=&name;
                                   DEBUG_PRINT_STRING(name)
   
                                 i.next(); // skip origin                                  i.next(); // skip OP_GET_OBJECT_VAR_ELEMENT
                                 Value& value=*i.next().value;                                  debug_origin=i.next().origin;
                                   const String& context_name=*i.next().value->get_string();  debug_name=&context_name;
                                   DEBUG_PRINT_STRING(context_name)
   
                                 DEBUG_PRINT_STRING(name)                                  Value& object=get_element(*rcontext, context_name);
   
                                 put_element(*method_frame, name, &value);                                  debug_origin=i.next().origin;
                                 break;                                  const String& var_name=*i.next().value->get_string();  debug_name=&var_name;
                         }                                  DEBUG_PRINT_STRING(var_name)
   
                 case OP::OP_WRITE_CONSTRUCT_VALUE:                                  const String* field_name=get_element(*rcontext, var_name).get_string();
                                   Value& value=get_element(object, *field_name);
   
                                   if(
                                              opcode == OP::OP_WRITE_OBJECT_VAR_ELEMENT_CONSTRUCT_EXPR
                                           || opcode == OP::OP_ROOT_OBJECT_VAR_ELEMENT_CONSTRUCT_EXPR
                                   ){
                                           put_element( with_root?*method_frame:*wcontext, name, &value.as_expr_result());
                                   } else {
                                           put_element( with_root?*method_frame:*wcontext, name, value.is_void()?new VString():&value);
                                   }
                                   break;
                           }
   #endif // OPTIMIZE_BYTECODE_CONSTRUCT
   
   #ifdef OPTIMIZE_BYTECODE_CALL_CONSTRUCT
                   case OP::OP_WRITE_CALL_CONSTRUCT_EXPR:
                   case OP::OP_WRITE_CALL_CONSTRUCT_VALUE:
                         {                          {
                                 if(wcontext==method_frame)                                  if(wcontext==method_frame)
                                         throw Exception(PARSER_RUNTIME,                                          throw Exception(PARSER_RUNTIME,
                                                 0,                                                  0,
                                                 "$.name outside of $name[...]");                                                  "$.name outside of $name[...]");
                                   with_root=false;
                                   // don't stop here. continue in the next block
                           }
   
                   case OP::OP_ROOT_CALL_CONSTRUCT_EXPR:
                   case OP::OP_ROOT_CALL_CONSTRUCT_VALUE:
                           {
                                 debug_origin=i.next().origin;                                  debug_origin=i.next().origin;
                                 const String& name=*i.next().value->get_string();  debug_name=&name;                                  const String& name=*i.next().value->get_string();  debug_name=&name;
   
                                 i.next(); // skip origin  
                                 Value& value=*i.next().value;  
   
                                 DEBUG_PRINT_STRING(name)                                  DEBUG_PRINT_STRING(name)
   
                                 put_element(*wcontext, name, &value);                                  debug_origin=i.next().origin;
                                   const String& method_name=*i.next().value->get_string();  debug_name=&method_name;
   
                                   DEBUG_PRINT_STRING(method_name)
   
                                   bool is_expr=(opcode==OP::OP_WRITE_CALL_CONSTRUCT_EXPR || opcode==OP::OP_ROOT_CALL_CONSTRUCT_EXPR);
                                   if(is_expr)
                                           wcontext->set_in_expression(true);
   
                                   Value* vjunction;
                                   if(Method* method=main_class.get_method(method_name)){ // looking operator of that name FIRST
                                           if(!method->junction_template)
                                                   method->junction_template=new VJunction(main_class, method);
                                           vjunction=method->junction_template;
                                   } else {
                                           vjunction=&get_element(*rcontext, method_name);
                                   }
   
                                   // CALL
                                   Operation call_op=i.next();
                                   ArrayOperation* local_ops=i.next().ops;
   
                                   DEBUG_PRINT_OPS(local_ops)
                                   DEBUG_PRINT_STR("->\n")
   
                                   Junction* junction=vjunction->get_junction();
                                   if(!junction) {
                                           if(vjunction->is("void"))
                                                   throw Exception(PARSER_RUNTIME,
                                                           0,
                                                           "undefined method");
                                           else
                                                   throw Exception(PARSER_RUNTIME,
                                                           0,
                                                           "is '%s', not a method or junction, can not call it",
                                                                   vjunction->type());
                                   }
   
                                   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);
                                   }
                                   
                                   DEBUG_PRINT_STR("<-returned")
   
                                   if(call_op.code==OP::OP_CALL__WRITE){
                                           write_assign_lang(frame.result());
                                   } else {
                                           Value& value=frame.result().as_value();
   
                                           if(is_expr){
                                                   wcontext->set_in_expression(false);
                                                   put_element( with_root?*method_frame:*wcontext, name, &value.as_expr_result());
                                           } else {
                                                   put_element( with_root?*method_frame:*wcontext, name, &value);
                                           }
                                   }
   
                                   if(get_skip())
                                           return;
                                   if(get_interrupted()) {
                                           set_interrupted(false);
                                           throw Exception("parser.interrupted",
                                                   0,
                                                   "execution stopped");
                                   }
   
                                 break;                                  break;
                         }                          }
 #endif  #endif // OPTIMIZE_BYTECODE_CALL_CONSTRUCT
   
                 case OP::OP_CONSTRUCT_EXPR:                  case OP::OP_CONSTRUCT_EXPR:
                         {                          {

Removed from v.1.337  
changed lines
  Added in v.1.342


E-mail: