Diff for /parser3/src/main/execute.C between versions 1.101 and 1.105

version 1.101, 2001/03/13 14:02:51 version 1.105, 2001/03/15 09:58:18
Line 50  char *opcode_name[]={ Line 50  char *opcode_name[]={
         "BIN_AND", "BIN_OR", "BIN_XOR",          "BIN_AND", "BIN_OR", "BIN_XOR",
         "LOG_AND", "LOG_OR", "LOG_XOR",          "LOG_AND", "LOG_OR", "LOG_XOR",
         "NUM_LT", "NUM_GT", "NUM_LE", "NUM_GE", "NUM_EQ", "NUM_NE",          "NUM_LT", "NUM_GT", "NUM_LE", "NUM_GE", "NUM_EQ", "NUM_NE",
         "STR_LT", "STR_GT", "STR_LE", "STR_GE", "STR_EQ", "STR_NE"          "STR_LT", "STR_GT", "STR_LE", "STR_GE", "STR_EQ", "STR_NE",
           "IS"
 };  };
   
   void log_printf(const char *fmt, ...) {
           // TODO: куда-нибудь пристроить
   }
   
 void dump(int level, const Array& ops) {  void dump(int level, const Array& ops) {
         if(0){          if(0){
                 int size=ops.size();                  int size=ops.size();
                 //fprintf(stderr, "size=%d\n", size);                  //log_printf("size=%d\n", size);
                 for(int i=0; i<size; i++) {                  for(int i=0; i<size; i++) {
                         Operation op;                          Operation op;
                         op.cast=ops.quick_get(i);                          op.cast=ops.quick_get(i);
                         fprintf(stderr, "%8X\n", op.cast);                          log_printf("%8X\n", op.cast);
                 }                  }
         }          }
   
         int size=ops.size();          int size=ops.size();
         //fprintf(stderr, "size=%d\n", size);          //log_printf("size=%d\n", size);
         for(int i=0; i<size; i++) {          for(int i=0; i<size; i++) {
                 Operation op;                  Operation op;
                 op.cast=ops.quick_get(i);                  op.cast=ops.quick_get(i);
                 fprintf(stderr, "%*s%s", level*4, "", opcode_name[op.code]);                  log_printf("%*s%s", level*4, "", opcode_name[op.code]);
   
                 if(op.code==OP_VALUE || op.code==OP_STRING__WRITE) {                  if(op.code==OP_VALUE || op.code==OP_STRING__WRITE) {
                         Value *value=static_cast<Value *>(ops.quick_get(++i));                          Value *value=static_cast<Value *>(ops.quick_get(++i));
                         fprintf(stderr, " \"%s\" %s", value->get_string()->cstr(), value->type());                          log_printf(" \"%s\" %s", value->get_string()->cstr(), value->type());
                 }                  }
                 fprintf(stderr, "\n");                  log_printf("\n");
   
                 if(op.code==OP_CODE__STORE_PARAM) {                  if(op.code==OP_CODE__STORE_PARAM) {
                         const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i));                          const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i));
                         dump(level+1, *local_ops);                          dump(level+1, *local_ops);
                 }                  }
         }          }
         fflush(stderr);  
 }  }
   
 void Request::execute(const Array& ops) {  void Request::execute(const Array& ops) {
         if(1) {          if(1) {
                 fputs("source----------------------------\n", stderr);                  log_printf("source----------------------------\n");
                 dump(0, ops);                  dump(0, ops);
                 fputs("execution-------------------------\n", stderr);                  log_printf("execution-------------------------\n");
         }          }
   
         int size=ops.size();          int size=ops.size();
         //fprintf(stderr, "size=%d\n", size);          //log_printf("size=%d\n", size);
         for(int i=0; i<size; i++) {          for(int i=0; i<size; i++) {
                 Operation op;                  Operation op;
                 op.cast=ops.quick_get(i);                  op.cast=ops.quick_get(i);
                 fprintf(stderr, "%d:%s", stack.top_index()+1, opcode_name[op.code]); fflush(stderr);                  log_printf("%d:%s", stack.top_index()+1, opcode_name[op.code]);
   
                 switch(op.code) {                  switch(op.code) {
                 // param in next instruction                  // param in next instruction
                 case OP_VALUE:                  case OP_VALUE:
                         {                          {
                                 Value *value=static_cast<Value *>(ops.quick_get(++i));                                  Value *value=static_cast<Value *>(ops.quick_get(++i));
                                 fprintf(stderr, " \"%s\" %s", value->get_string()->cstr(), value->type());                                  log_printf(" \"%s\" %s", value->get_string()->cstr(), value->type());
                                 PUSH(value);                                  PUSH(value);
                                 break;                                  break;
                         }                          }
Line 113  void Request::execute(const Array& ops) Line 117  void Request::execute(const Array& ops)
                                 VMethodFrame *frame=static_cast<VMethodFrame *>(stack.top_value());                                  VMethodFrame *frame=static_cast<VMethodFrame *>(stack.top_value());
                                 // code                                  // code
                                 const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i));                                  const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i));
                                 fprintf(stderr, " (%d)\n", local_ops->size());                                  log_printf(" (%d)\n", local_ops->size());
                                 dump(1, *local_ops);                                  dump(1, *local_ops);
                                                                   
                                 Junction& j=*NEW Junction(pool(),                                   Junction& j=*NEW Junction(pool(), 
Line 192  void Request::execute(const Array& ops) Line 196  void Request::execute(const Array& ops)
                 case OP_STRING__WRITE:                  case OP_STRING__WRITE:
                         {                          {
                                 VString *vstring=static_cast<VString *>(ops.quick_get(++i));                                  VString *vstring=static_cast<VString *>(ops.quick_get(++i));
                                 fprintf(stderr, " \"%s\"", vstring->value().cstr());                                  log_printf(" \"%s\"", vstring->value().cstr());
                                 write(vstring->value());                                  write(vstring->value());
                                 break;                                  break;
                         }                          }
Line 282  void Request::execute(const Array& ops) Line 286  void Request::execute(const Array& ops)
                                                         value->type());                                                           value->type()); 
   
                                 VMethodFrame *frame=NEW VMethodFrame(pool(), *junction);                                  VMethodFrame *frame=NEW VMethodFrame(pool(), *junction);
                                 //frame->set_name(junction->self.name());                                  //frame->set_name(value->name());
                                 frame->set_name(value->name());  
                                 PUSH(frame);                                  PUSH(frame);
                                 break;                                  break;
                         }                          }
Line 297  void Request::execute(const Array& ops) Line 300  void Request::execute(const Array& ops)
   
                 case OP_CALL:                  case OP_CALL:
                         {                          {
                                 fprintf(stderr, "->\n");                                  log_printf("->\n");
                                 VMethodFrame *frame=static_cast<VMethodFrame *>(POP());                                  VMethodFrame *frame=static_cast<VMethodFrame *>(POP());
                                 frame->fill_unspecified_params();                                  frame->fill_unspecified_params();
                                 PUSH(self);                                    PUSH(self);  
Line 331  void Request::execute(const Array& ops) Line 334  void Request::execute(const Array& ops)
                                 root=rcontext=wcontext=frame;                                  root=rcontext=wcontext=frame;
                                 {                                  {
                                         // take object or class from any wrappers                                          // take object or class from any wrappers
                                         VAliased *aliased=self->get_aliased();                                          // and substitute class alias to the class they are called AS
                                         // substitute class alias to the class they are called AS                                          Temp_alias temp_alias(*self->get_aliased(), *frame->junction.vclass);
                                         Temp_alias temp_alias(*aliased, *frame->junction.vclass);  
   
                                         const Method& method=*frame->junction.method;                                          const Method& method=*frame->junction.method;
                                         if(method.native_code) { // native code?                                          if(method.native_code) { // native code?
Line 352  void Request::execute(const Array& ops) Line 354  void Request::execute(const Array& ops)
                                 self=static_cast<VAliased *>(POP());                                  self=static_cast<VAliased *>(POP());
   
                                 PUSH(value);                                  PUSH(value);
                                 fprintf(stderr, "<-returned");                                  log_printf("<-returned");
                                 break;                                  break;
                         }                          }
   
Line 570  void Request::execute(const Array& ops) Line 572  void Request::execute(const Array& ops)
                                 PUSH(value);                                  PUSH(value);
                                 break;                                  break;
                         }                          }
                   case OP_IS:
                           {
                                   Value *b=POP();  Value *a=POP();
                                   Value *value=NEW VBool(pool(), b->as_string() == a->type());
                                   PUSH(value);
                                   break;
                           }
   
                 default:                  default:
                         THROW(0,0,                          THROW(0,0,
                                 0,                                  0,
                                 "unhandled '%s' opcode", opcode_name[op.code]);                                   "unhandled '%s' opcode", opcode_name[op.code]); 
                 }                  }
                 fprintf(stderr, "\n");                  log_printf("\n");
         }          }
 }  }
   
Line 609  Value& Request::process(Value& value, co Line 618  Value& Request::process(Value& value, co
         Junction *junction=value.get_junction();          Junction *junction=value.get_junction();
         if(junction && junction->code) { // is it a code-junction?          if(junction && junction->code) { // is it a code-junction?
                 // process it                  // process it
                 fprintf(stderr, "ja->\n");                  log_printf("ja->\n");
                 PUSH(self);                    PUSH(self);  
                 PUSH(root);                    PUSH(root);  
                 PUSH(rcontext);                    PUSH(rcontext);  
Line 643  Value& Request::process(Value& value, co Line 652  Value& Request::process(Value& value, co
                 root=POP();                    root=POP();  
                 self=static_cast<VAliased *>(POP());                  self=static_cast<VAliased *>(POP());
                                   
                 fprintf(stderr, "<-ja returned");                  log_printf("<-ja returned");
         } else          } else
                 result=&value;                  result=&value;
   

Removed from v.1.101  
changed lines
  Added in v.1.105


E-mail: