Diff for /parser3/src/main/execute.C between versions 1.35 and 1.41

version 1.35, 2001/02/24 11:30:10 version 1.41, 2001/02/25 10:11:50
Line 10 Line 10
 #include "pa_vunknown.h"  #include "pa_vunknown.h"
 #include "pa_vcframe.h"  #include "pa_vcframe.h"
 #include "pa_vmframe.h"  #include "pa_vmframe.h"
   #include "pa_vobject.h"
   
 #include <stdio.h>  #include <stdio.h>
   
Line 19 Line 20
   
   
 char *opcode_name[]={  char *opcode_name[]={
         "STRING",  "CODE",          "STRING",  "CODE",  "CLASS",
         "WITH_ROOT",    "WITH_SELF",    "WITH_READ",    "WITH_WRITE",          "WITH_ROOT",    "WITH_SELF",    "WITH_READ",    "WITH_WRITE",
         "CONSTRUCT",          "CONSTRUCT",
         "EXPRESSION_EVAL",      "MODIFY_EVAL",          "EXPRESSION_EVAL",      "MODIFY_EVAL",
Line 54  void dump(int level, const Array& ops) { Line 55  void dump(int level, const Array& ops) {
                         VString *vstring=static_cast<VString *>(ops.quick_get(++i));                          VString *vstring=static_cast<VString *>(ops.quick_get(++i));
                         printf(" \"%s\"", vstring->get_string()->cstr());                          printf(" \"%s\"", vstring->get_string()->cstr());
                 }                  }
                   if(op.code==OP_CLASS) {
                           VClass *vclass=static_cast<VClass *>(ops.quick_get(++i));
                           printf(" \"%s\"", vclass->name()->cstr());
                   }
                 printf("\n");                  printf("\n");
   
                 if(op.code==OP_CODE) {                  if(op.code==OP_CODE) {
Line 89  void Request::execute(const Array& ops) Line 94  void Request::execute(const Array& ops)
                 case OP_CODE:                  case OP_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));
                                 printf(" (%d)", local_ops->size());                                  printf(" (%d)\n", local_ops->size());
                                   dump(1, *local_ops);
                                 Junction& j=*NEW Junction(pool(),                                   Junction& j=*NEW Junction(pool(), 
                                         *self,                                          *self,
                                         0,                                          0,
Line 99  void Request::execute(const Array& ops) Line 105  void Request::execute(const Array& ops)
                                 PUSH(value);                                  PUSH(value);
                                 break;                                  break;
                         }                          }
                                           case OP_CLASS:
                         // OP_WITH  
                 case OP_WITH_WRITE:   
                         {                          {
                                 PUSH(wcontext);                                  VClass *vclass=static_cast<VClass *>(ops.quick_get(++i));
                                   printf(" \"%s\"", vclass->name()->cstr());
                           PUSH(vclass);
                                 break;                                  break;
                         }                          }
                 case OP_WITH_READ:                           
                           // OP_WITH
                   case OP_WITH_SELF: 
                         {                          {
                                 PUSH(rcontext);                                  PUSH(self);
                                 break;                                  break;
                         }                          }
                 case OP_WITH_ROOT:                   case OP_WITH_ROOT: 
Line 116  void Request::execute(const Array& ops) Line 124  void Request::execute(const Array& ops)
                                 PUSH(root);                                  PUSH(root);
                                 break;                                  break;
                         }                          }
                 case OP_WITH_SELF:                   case OP_WITH_READ: 
                         {                          {
                                 PUSH(self);                                  PUSH(rcontext);
                                   break;
                           }
                   case OP_WITH_WRITE: 
                           {
                                   PUSH(wcontext);
                                 break;                                  break;
                         }                          }
                                                   
                         // ...                          // ...
                   case OP_CONSTRUCT:
                           {
                                   Value *value=POP();
                                   String& name=POP_NAME();
                                   Value *ncontext=POP();
                                   value->set_name(name);
                                   ncontext->put_element(name, value);
                                   break;
                           }
                           // TODO: OP_EXPRESSION_EVAL,    OP_MODIFY_EVAL,
                 case OP_WRITE:                  case OP_WRITE:
                         {                          {
                                 Value *value=POP();                                  Value *value=POP();
Line 144  void Request::execute(const Array& ops) Line 167  void Request::execute(const Array& ops)
                                 break;                                  break;
                         }                          }
   
                 case OP_CONSTRUCT:  
                         {  
                                 Value *value=POP();  
                                 String& name=POP_NAME();  
                                 Value *ncontext=POP();  
                                 value->set_name(name);  
                                 ncontext->put_element(name, value);  
                                 break;  
                         }  
   
                 case OP_CREATE_EWPOOL:                  case OP_CREATE_EWPOOL:
                         {                          {
Line 162  void Request::execute(const Array& ops) Line 176  void Request::execute(const Array& ops)
                         }                          }
                 case OP_REDUCE_EWPOOL:                  case OP_REDUCE_EWPOOL:
                         {                          {
                                 Value *value=wcontext->value_or_string();                                  Value *value=wcontext->result();
                                 wcontext=static_cast<WContext *>(POP());                                  wcontext=static_cast<WContext *>(POP());
                                 PUSH(value);                                  PUSH(value);
                                 break;                                  break;
Line 187  void Request::execute(const Array& ops) Line 201  void Request::execute(const Array& ops)
                                 break;                                  break;
                         }                          }
   
                           // CALL
                 case OP_GET_METHOD_FRAME:                  case OP_GET_METHOD_FRAME:
                         {                          {
                                 Value *value=POP();                                  Value *value=POP();
Line 195  void Request::execute(const Array& ops) Line 210  void Request::execute(const Array& ops)
                                 if(!junction)                                  if(!junction)
                                         THROW(0,0,                                          THROW(0,0,
                                                 value->name(),                                                  value->name(),
                                                 "is not a method or a junction (it is '%s'), can not call it",                                                  "type is '%s', can not call it (must be method or junction)",
                                                 value->type());                                                           value->type()); 
                                 //unless(method) method=operators.get_method[...;code/native_code](name)                                  //unless(method) method=operators.get_method[...;code/native_code](name)
                                 VMethodFrame *frame=NEW VMethodFrame(pool(), *junction);                                  VMethodFrame *frame=NEW VMethodFrame(pool(), *junction);
                                 PUSH(frame);                                  PUSH(frame);
Line 216  void Request::execute(const Array& ops) Line 231  void Request::execute(const Array& ops)
                                 VMethodFrame *frame=static_cast<VMethodFrame *>(POP());                                  VMethodFrame *frame=static_cast<VMethodFrame *>(POP());
                                 frame->fill_unspecified_params();                                  frame->fill_unspecified_params();
                                 PUSH(self);  PUSH(root);  PUSH(rcontext);  PUSH(wcontext);                                   PUSH(self);  PUSH(root);  PUSH(rcontext);  PUSH(wcontext); 
                                 //left_class=ncontext.get_class()  
                                 //right_class=frame.self.get_class()                                  VClass *called_class=frame->junction.self.get_class();
                                 //self=f(left_class[thoughts' food], right_self[junction], right_class[static], wcontext.value()[dynamic], new(right_class)[construct])                                  // variable already constructed?
                                 self=&frame->junction.self; // TODO: не всегда frame..self                                  if(wcontext->get_class()) { // yes
                                           // static or dynamic call
                                           self=&frame->junction.self;
                                   } else { // no
                                           // constructor call: $some(^class:method(..))
                                           self=NEW VObject(pool(), *called_class);
                                           frame->write(self); 
                                   }
                                 frame->set_self(self);                                  frame->set_self(self);
   
                                 root=rcontext=wcontext=frame;                                  root=rcontext=wcontext=frame;
                                 execute(frame->junction.method->code);                                  execute(frame->junction.method->code);
                                 Value *value=wcontext->value();                                  Value *value=wcontext->result();
                                 wcontext=static_cast<WContext *>(POP());  rcontext=POP();  root=POP();  self=POP();                                  wcontext=static_cast<WContext *>(POP());  rcontext=POP();  root=POP();  self=POP();
                                 wcontext->write(value);                                  wcontext->write(value);
                                 printf("<-returned");                                  printf("<-returned");
                                 break;                                  break;
                         }                          }
   
   
                 default:                  default:
                         printf("\tTODO");                          printf("\tTODO");
                         break;                          break;
Line 246  Value *Request::get_element() { Line 268  Value *Request::get_element() {
   
         if(value) {          if(value) {
                 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?
                         // autocalc it                          // autocalc it
                         printf("ja->\n");                          printf("ja->\n");
                         PUSH(self);  PUSH(root);  PUSH(rcontext);  PUSH(wcontext);                          PUSH(self);  PUSH(root);  PUSH(rcontext);  PUSH(wcontext);
Line 258  Value *Request::get_element() { Line 280  Value *Request::get_element() {
                         rcontext=junction->rcontext;                          rcontext=junction->rcontext;
                         execute(*junction->code);                          execute(*junction->code);
                         // CodeFrame soul:                          // CodeFrame soul:
                         //    string writes intercepted                          //   string writes were intercepted
                         //   and they are the result of getting code junction                          //   returning them as the result of getting code-junction
                         value=NEW VString(frame.get_string());                          value=NEW VString(frame.get_string());
                         wcontext=static_cast<WContext *>(POP());  rcontext=POP();  root=POP();  self=POP();                          wcontext=static_cast<WContext *>(POP());  rcontext=POP();  root=POP();  self=POP();
                         printf("<-ja returned");                          printf("<-ja returned");

Removed from v.1.35  
changed lines
  Added in v.1.41


E-mail: