Diff for /parser3/src/main/execute.C between versions 1.91 and 1.99

version 1.91, 2001/03/11 21:41:04 version 1.99, 2001/03/13 12:37:05
Line 17 Line 17
 #include "pa_vobject.h"  #include "pa_vobject.h"
 #include "pa_vdouble.h"  #include "pa_vdouble.h"
 #include "pa_vbool.h"  #include "pa_vbool.h"
   #include "pa_vtable.h"
   
 #include <stdio.h>  #include <stdio.h>
   
Line 122  void Request::execute(const Array& ops) Line 123  void Request::execute(const Array& ops)
                                 Value *value=NEW VJunction(j);                                  Value *value=NEW VJunction(j);
   
                                 // store param                                  // store param
                                 frame->store_param(value);                                  frame->store_param(frame->name(), value);
                                 break;                                  break;
                         }                          }
                 case OP_GET_CLASS:                  case OP_GET_CLASS:
                         {                          {
                                   // maybe the do ^class:method[] call, remember the fact
                                   wcontext->set_somebody_entered_some_class();
   
                                 const String& name=POP_NAME();                                  const String& name=POP_NAME();
                                 VClass *vclass=static_cast<VClass *>(classes().get(name));                                  VClass *vclass=static_cast<VClass *>(classes().get(name));
                                 if(!vclass)                                   if(!vclass) 
Line 182  void Request::execute(const Array& ops) Line 186  void Request::execute(const Array& ops)
                 case OP_WRITE:                  case OP_WRITE:
                         {                          {
                                 Value *value=POP();                                  Value *value=POP();
                                 write(*value);                                  write_assign_lang(*value);
                                 break;                                  break;
                         }                          }
                 case OP_STRING__WRITE:                  case OP_STRING__WRITE:
Line 203  void Request::execute(const Array& ops) Line 207  void Request::execute(const Array& ops)
                 case OP_GET_ELEMENT__WRITE:                  case OP_GET_ELEMENT__WRITE:
                         {                          {
                                 Value *value=get_element();                                  Value *value=get_element();
                                 write(*value);                                  write_assign_lang(*value);
                                 break;                                  break;
                         }                          }
   
Line 274  void Request::execute(const Array& ops) Line 278  void Request::execute(const Array& ops)
                                 if(!junction)                                  if(!junction)
                                         THROW(0,0,                                          THROW(0,0,
                                                 &value->name(),                                                  &value->name(),
                                                 "type is '%s', can not call it (must be method or junction)",                                                  "(%s) uncallable, must be method or junction",
                                                         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(junction->self.name());
                                   frame->set_name(value->name());
                                 PUSH(frame);                                  PUSH(frame);
                                 break;                                  break;
                         }                          }
Line 286  void Request::execute(const Array& ops) Line 291  void Request::execute(const Array& ops)
                         {                          {
                                 Value *value=POP();                                  Value *value=POP();
                                 VMethodFrame *frame=static_cast<VMethodFrame *>(stack.top_value());                                  VMethodFrame *frame=static_cast<VMethodFrame *>(stack.top_value());
                                 frame->store_param(value);                                  frame->store_param(frame->name(), value);
                                 break;                                  break;
                         }                          }
   
Line 306  void Request::execute(const Array& ops) Line 311  void Request::execute(const Array& ops)
                                 if(read_class && read_class->is_or_derived_from(*called_class)) // yes                                  if(read_class && read_class->is_or_derived_from(*called_class)) // yes
                                         self=rcontext; // class dynamic call                                          self=rcontext; // class dynamic call
                                 else // no, not me or relative of mine (total stranger)                                  else // no, not me or relative of mine (total stranger)
                                         if(wcontext->constructing()) {  // constructing?                                          if(
                                                 // yes, constructor call: $some(^class:method(..))                                                  wcontext->constructing() && // constructing?
                                                 self=NEW VObject(pool(), *called_class);                                                  wcontext->somebody_entered_some_class()) { // ^class:method[..]?
                                                   // yes, this is a constructor call
                                                   if(called_class->name()==TABLE_CLASS_NAME)
                                                           self=NEW VTable(pool());
                                                   else
                                                           self=NEW VObject(pool(), *called_class);
                                                 frame->write(*self,                                                   frame->write(*self, 
                                                         String::Untaint_lang::NO  // not used, always an object, not string                                                          String::Untaint_lang::NO  // not used, always an object, not string
                                                 );                                                  );
Line 323  void Request::execute(const Array& ops) Line 333  void Request::execute(const Array& ops)
                                         // substitute class alias to the class they are called AS                                          // substitute class alias to the class they are called AS
                                         Temp_alias temp_alias(*aliased, *frame->junction.vclass);                                          Temp_alias temp_alias(*aliased, *frame->junction.vclass);
   
                                         Method& method=*frame->junction.method;                                          const Method& method=*frame->junction.method;
                                         if(method.native_code) { // native code?                                          if(method.native_code) { // native code?
                                                 method.check_actual_numbered_params(frame->numbered_params());                                                  method.check_actual_numbered_params(
                                                 (*method.native_code)(*this, frame->numbered_params()); // execute it                                                          frame->name(), frame->numbered_params());
                                                   (*method.native_code)(*this, 
                                                           frame->name(), frame->numbered_params()); // execute it
                                         } else // parser code                                          } else // parser code
                                                 execute(*method.parser_code); // execute it                                                  execute(*method.parser_code); // execute it
                                 }                                  }
Line 353  void Request::execute(const Array& ops) Line 365  void Request::execute(const Array& ops)
                 case OP_INV:                  case OP_INV:
                         {                          {
                                 Value *operand=POP();                                  Value *operand=POP();
                                 Value *value=NEW VDouble(pool(), ~static_cast<int>(operand->get_double()));                                  Value *value=NEW VDouble(pool(), ~(int)operand->get_double());
                                 PUSH(value);                                  PUSH(value);
                                 break;                                  break;
                         }                          }
Line 419  void Request::execute(const Array& ops) Line 431  void Request::execute(const Array& ops)
                         {                          {
                                 Value *b=POP();  Value *a=POP();                                  Value *b=POP();  Value *a=POP();
                                 Value *value=NEW VDouble(pool(),                                   Value *value=NEW VDouble(pool(), 
                                         static_cast<int>(a->get_double()) %                                          (int)a->get_double() %
                                         static_cast<int>(b->get_double()));                                          (int)b->get_double());
                                 PUSH(value);                                  PUSH(value);
                                 break;                                  break;
                         }                          }
Line 428  void Request::execute(const Array& ops) Line 440  void Request::execute(const Array& ops)
                         {                          {
                                 Value *b=POP();  Value *a=POP();                                  Value *b=POP();  Value *a=POP();
                                 Value *value=NEW VDouble(pool(),                                   Value *value=NEW VDouble(pool(), 
                                         static_cast<int>(a->get_double()) &                                          (int)a->get_double() &
                                         static_cast<int>(b->get_double()));                                          (int)b->get_double());
                                 PUSH(value);                                  PUSH(value);
                                 break;                                  break;
                         }                          }
Line 437  void Request::execute(const Array& ops) Line 449  void Request::execute(const Array& ops)
                         {                          {
                                 Value *b=POP();  Value *a=POP();                                  Value *b=POP();  Value *a=POP();
                                 Value *value=NEW VDouble(pool(),                                   Value *value=NEW VDouble(pool(), 
                                         static_cast<int>(a->get_double()) |                                          (int)a->get_double() |
                                         static_cast<int>(b->get_double()));                                          (int)b->get_double());
                                 PUSH(value);                                  PUSH(value);
                                 break;                                  break;
                         }                          }
Line 446  void Request::execute(const Array& ops) Line 458  void Request::execute(const Array& ops)
                         {                          {
                                 Value *b=POP();  Value *a=POP();                                  Value *b=POP();  Value *a=POP();
                                 Value *value=NEW VDouble(pool(),                                   Value *value=NEW VDouble(pool(), 
                                         static_cast<int>(a->get_double()) ^                                          (int)a->get_double() ^
                                         static_cast<int>(b->get_double()));                                          (int)b->get_double());
                                 PUSH(value);                                  PUSH(value);
                                 break;                                  break;
                         }                          }
Line 572  Value *Request::get_element() { Line 584  Value *Request::get_element() {
         Value *value=ncontext->get_element(name);          Value *value=ncontext->get_element(name);
   
         if(value)          if(value)
                 value=&autocalc(*value, &name); // autocalc possible code-junction                  value=&process(*value, &name); // process possible code-junction
         else {          else {
                 value=NEW VUnknown(pool());                  value=NEW VUnknown(pool());
                 value->set_name(name);                  value->set_name(name);
Line 581  Value *Request::get_element() { Line 593  Value *Request::get_element() {
         return value;          return value;
 }  }
   
 Value& Request::autocalc(Value& value, const String *name, bool intercept_string) {  Value& Request::process(Value& value, const String *name, bool intercept_string) {
         // intercept_string:          // intercept_string:
         //      true:          //      true:
         //              they want result=string value,           //              they want result=string value, 
Line 594  Value& Request::autocalc(Value& value, c Line 606  Value& Request::autocalc(Value& value, c
         Value *result;          Value *result;
         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                  // process it
                 fprintf(stderr, "ja->\n");                  fprintf(stderr, "ja->\n");
                 PUSH(self);                    PUSH(self);  
                 PUSH(root);                    PUSH(root);  
Line 638  Value& Request::autocalc(Value& value, c Line 650  Value& Request::autocalc(Value& value, c
         return *result;          return *result;
 }  }
   
 char *Request::execute_static_method(VClass& vclass, String& method_name, bool return_cstr) {  char *Request::execute_method(Value& aself, const Method& method, bool return_cstr) {
         Value *value=vclass.get_element(method_name);          PUSH(self);  
         if(value) { // found some 'METHOD_NAME' element          PUSH(root);  
                 Junction *junction=value->get_junction();          PUSH(rcontext);  
                 if(junction) {// it even has junction!          PUSH(wcontext);
                         const Method *method=junction->method;          
                         if(method) { // and junction is method-junction! call it          // initialize contexts
                                 PUSH(self);            root=rcontext=self=&aself;
                                 PUSH(root);            wcontext=NEW WWrapper(pool(), &aself, false /* not constructing */);
                                 PUSH(rcontext);            
                                 PUSH(wcontext);          // execute!     
                                           execute(*method.parser_code);
                                 // initialize contexts          
                                 root=rcontext=self=&vclass;          // result
                                 wcontext=NEW WWrapper(pool(), &vclass, false /* not constructing */);          char *result;
                                           if(return_cstr)
                                 // execute!                       result=wcontext->get_string()->cstr(); // chars
                                 execute(*method->parser_code);          else
                                                   result=0; // ignore result
                                 // result          
                                 char *result;          wcontext=static_cast<WContext *>(POP());  
                                 if(return_cstr)          rcontext=POP();  
                                         result=wcontext->get_string()->cstr(); // chars          root=POP();  
                                 else          self=static_cast<VAliased *>(POP());
                                         result=0; // ignore result          
           // return
           return result;
   }
   
                                 wcontext=static_cast<WContext *>(POP());    char *Request::execute_method(Value& aself, 
                                 rcontext=POP();                                                              const String& method_name, bool return_cstr) {
                                 root=POP();            if(Value *value=aself.get_element(method_name))
                                 self=static_cast<VAliased *>(POP());                  if(Junction *junction=value->get_junction())
                           if(const Method *method=junction->method) 
                                   return execute_method(aself, *method, return_cstr);
   
                                 // return  
                                 return result;  
                         }  
                 }  
         }  
         return 0;          return 0;
 }  }

Removed from v.1.91  
changed lines
  Added in v.1.99


E-mail: