Diff for /parser3/src/main/execute.C between versions 1.16 and 1.26

version 1.16, 2001/02/22 12:43:55 version 1.26, 2001/02/23 11:53:06
Line 6 Line 6
 #include "code.h"  #include "code.h"
 #include "pa_request.h"  #include "pa_request.h"
 #include "pa_vstring.h"  #include "pa_vstring.h"
   #include "pa_vhash.h"
   #include "pa_vunknown.h"
   
 #include <stdio.h>  #include <stdio.h>
   
   #define PUSH(value) stack.push(value)
   #define POP() static_cast<Value *>(stack.pop())
   
   
 char *opcode_name[]={  char *opcode_name[]={
         "STRING",  "VSTRING",  "CODE_ARRAY",          "STRING",  "CODE_ARRAY",
         "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",
         "WRITE_STRING",  "WRITE_VALUE",          "WRITE",
         "GET_ELEMENT",  "GET_ELEMENT__WRITE_VALUE",          "GET_ELEMENT",  "GET_ELEMENT__WRITE",
         "CREATE_EWPOOL",        "REDUCE_EWPOOL",          "CREATE_EWPOOL",        "REDUCE_EWPOOL",
         "CREATE_RWPOOL",        "REDUCE_RWPOOL",          "CREATE_RWPOOL",        "REDUCE_RWPOOL",
         "GET_METHOD_FRAME",          "GET_METHOD_FRAME",
Line 26  char *opcode_name[]={ Line 31  char *opcode_name[]={
 };  };
   
 void dump(int level, const Array& ops) {  void dump(int level, const Array& ops) {
           if(0){
                   int size=ops.size();
                   printf("size=%d\n", size);
                   for(int i=0; i<size; i++) {
                           Operation op;
                           op.cast=ops.quick_get(i);
                           printf("%8X\n", op.cast);
                   }
           }
   
         int size=ops.size();          int size=ops.size();
           printf("size=%d\n", size);
         for(int i=0; i<size; i++) {          for(int i=0; i<size; i++) {
                 int code=reinterpret_cast<int>(ops.quick_get(i));                  Operation op;
                 printf("%*s%s", level*4, "", opcode_name[code]);                  op.cast=ops.quick_get(i);
                   printf("%*s%s", level*4, "", opcode_name[op.code]);
                 if(code==OP_STRING) {  
                         String *string=static_cast<String *>(ops.quick_get(++i));                  if(op.code==OP_STRING) {
                         printf(" \"%s\"", string->cstr());                          VString *vstring=static_cast<VString *>(ops.quick_get(++i));
                 }                          printf(" \"%s\"", vstring->get_string()->cstr());
                 if(code==OP_VSTRING) {  
                         Value *value=static_cast<Value *>(ops.quick_get(++i));  
                         printf(" \"%s\"", value->get_string()->cstr());  
                 }                  }
                 printf("\n");                  printf("\n");
   
                 if(code==OP_CODE_ARRAY) {                  if(op.code==OP_CODE_ARRAY) {
                         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);
                 }                  }
Line 56  void Request::execute(Array& ops) { Line 69  void Request::execute(Array& ops) {
         }          }
   
         int size=ops.size();          int size=ops.size();
           printf("size=%d\n", size);
         for(int i=0; i<size; i++) {          for(int i=0; i<size; i++) {
                 int code=reinterpret_cast<int>(ops.quick_get(i));                  Operation op;
                 printf("%s", opcode_name[code]);                  op.cast=ops.quick_get(i);
                   printf("%d:%s", stack.top(), opcode_name[op.code]);
   
                 if(code==OP_CODE_ARRAY) {                  if(op.code==OP_CODE_ARRAY) {
                         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);
                 }                  }
                                   
                 switch(code) {                  switch(op.code) {
                 case OP_WITH_WRITE:                   case OP_WITH_WRITE: 
                         {                          {
                                 stack.push(wcontext);                                  PUSH(wcontext);
                                 break;                                  break;
                         }                          }
                 case OP_WITH_READ:                   case OP_WITH_READ: 
                         {                          {
                                 stack.push(rcontext);                                  PUSH(rcontext);
                                 break;                                  break;
                         }                          }
                                           case OP_WITH_ROOT: 
                 case OP_STRING:  
                         {                          {
                                 String *string=static_cast<String *>(ops.quick_get(++i));                                  PUSH(root);
                                 printf(" \"%s\"", string->cstr());  
                                 stack.push(string);  
                                 break;                                  break;
                         }                          }
                                           case OP_WITH_SELF: 
                 case OP_VSTRING:  
                         {                          {
                                 Value *value=static_cast<Value *>(ops.quick_get(++i));                                  PUSH(self);
                                 printf(" \"%s\"", value->get_string()->cstr());  
                                 stack.push(value);  
                                 break;                                  break;
                         }                          }
                                                   
                 case OP_CONSTRUCT:                  case OP_STRING:
                         {                          {
                                 Value *value=static_cast<Value *>(stack.pop());                                  VString *vstring=static_cast<VString *>(ops.quick_get(++i));
                                 String *name=static_cast<String *>(stack.pop());                                  printf(" \"%s\"", vstring->get_string()->cstr());
                                 Value *ncontext=static_cast<Value *>(stack.pop());                                  PUSH(vstring);
                                 ncontext->put_element(*name, value);  
                                 break;                                  break;
                         }                          }
                                                   
                 case OP_WRITE_STRING:                  case OP_CONSTRUCT:
                         {                          {
                                 String *string=static_cast<String *>(stack.pop());                                  Value *value=POP();
                                 wcontext->write(string);                                  String& name=POP()->as_string();
                                   Value *ncontext=POP();
                                   value->set_name(name);
                                   ncontext->put_element(name, value);
                                 break;                                  break;
                         }                          }
                                                   
                 case OP_WRITE_VALUE:                  case OP_WRITE:
                         {                          {
                                 Value *value=static_cast<Value *>(stack.pop());                                  Value *value=POP();
                                 wcontext->write(value);                                  wcontext->write(value);
                                 break;                                  break;
                         }                          }
                                                   
                 case OP_GET_ELEMENT:                  case OP_GET_ELEMENT:
                         {                          {
                                 String *name=static_cast<String *>(stack.pop());                                  Value *value=get_element();
                                 Value *ncontext=static_cast<Value *>(stack.pop());                                  PUSH(value);
                                 Value *value=ncontext->get_element(*name); // name áûâàåò method, òîãäà âûäà¸ò new junction(ÀÂÒÎÂÛ×ÈÑËßÒÜ=false, root,self,rcontext,wcontext,code)                                  break;
                                 // name áûâàåò èìÿ junction, òîãäà èëè îñòàâëÿåò â ïîêîå, èëè âû÷èñëÿåò â çàâèñèìîñòè îò ôëàãà ÀÂÒÎÂÛ×ÈÑËßÒÜ                          }
                                 stack.push(value);  
                   case OP_GET_ELEMENT__WRITE:
                           {
                                   Value *value=get_element();
                                   wcontext->write(value);
                                   break;
                           }
   
                   case OP_CREATE_EWPOOL:
                           {
                                   PUSH(wcontext);
                                   wcontext=NEW WContext(pool(), 0 /* empty */);
                                   break;
                           }
                   case OP_REDUCE_EWPOOL:
                           {
                                   Value *value=wcontext->value();
                                   wcontext=static_cast<WContext *>(POP());
                                   PUSH(value);
                                 break;                                  break;
                         }                          }
                                                   
                   case OP_CREATE_RWPOOL:
                           {
                                   Value *ncontext=POP();
                                   PUSH(rcontext);
                                   rcontext=ncontext;
                                   PUSH(wcontext);
                                   wcontext=NEW WContext(pool(), ncontext);
                                   break;
                           }
                   case OP_REDUCE_RWPOOL:
                           {
                                   String *string=wcontext->get_string();
                                   Value *value=NEW VString(string);
                                   wcontext=static_cast<WContext *>(POP());
                                   rcontext=POP();
                                   PUSH(value);
                                   break;
                           }
   
                 default:                  default:
                         printf("\tTODO");                          printf("\tTODO");
                         break;                          break;
Line 133  void Request::execute(Array& ops) { Line 181  void Request::execute(Array& ops) {
                 printf("\n");                  printf("\n");
         }          }
 }  }
   
   Value *Request::get_element() {
           String& name=POP()->as_string();
           Value *ncontext=POP();
           Value *value=ncontext->get_element(name); // name áûâàåò method, òîãäà âûäà¸ò new junction(ÀÂÒÎÂÛ×ÈÑËßÒÜ=false, root,self,rcontext,wcontext,code)
           // name áûâàåò èìÿ junction, òîãäà èëè îñòàâëÿåò â ïîêîå, èëè âû÷èñëÿåò â çàâèñèìîñòè îò ôëàãà ÀÂÒÎÂÛ×ÈÑËßÒÜ
   
           if(!value) {
                   value=NEW VUnknown(pool());
                   value->set_name(name);
           }
           return value;
   }
   

Removed from v.1.16  
changed lines
  Added in v.1.26


E-mail: