Diff for /parser3/src/main/execute.C between versions 1.366 and 1.375

version 1.366, 2010/10/09 23:17:26 version 1.375, 2015/05/08 14:30:44
Line 1 Line 1
 /** @file  /** @file
         Parser: executor part of request class.          Parser: executor part of request class.
   
         Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
 static const char * const IDENT_EXECUTE_C="$Date$";  
   
 #include "pa_opcode.h"  #include "pa_opcode.h"
 #include "pa_array.h"   #include "pa_array.h" 
 #include "pa_request.h"  #include "pa_request.h"
Line 23  static const char * const IDENT_EXECUTE_ Line 21  static const char * const IDENT_EXECUTE_
 #include "pa_vimage.h"  #include "pa_vimage.h"
 #include "pa_wwrapper.h"  #include "pa_wwrapper.h"
   
   volatile const char * IDENT_EXECUTE_C="$Id$" IDENT_PA_OPCODE_H IDENT_PA_OPERATION_H IDENT_PA_VCODE_FRAME_H IDENT_PA_WWRAPPER_H;
   
 //#define DEBUG_EXECUTE  //#define DEBUG_EXECUTE
   
 #ifdef DEBUG_EXECUTE  #ifdef DEBUG_EXECUTE
Line 76  char *opcode_name[]={ Line 76  char *opcode_name[]={
         "WITH_SELF__VALUE__CONSTRUCT_VALUE",          "WITH_SELF__VALUE__CONSTRUCT_VALUE",
 #endif  #endif
   
   #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL
           "GET_ELEMENT__SPECIAL",
           "GET_ELEMENT__SPECIAL__WRITE",
   #endif
         // expression ops: unary          // expression ops: unary
         "NEG", "INV", "NOT", "DEF", "IN", "FEXISTS", "DEXISTS",          "NEG", "INV", "NOT", "DEF", "IN", "FEXISTS", "DEXISTS",
         // expression ops: binary          // expression ops: binary
Line 263  void Request::execute(ArrayOperation& op Line 267  void Request::execute(ArrayOperation& op
                                 wcontext->set_somebody_entered_some_class();                                  wcontext->set_somebody_entered_some_class();
   
                                 debug_origin=i.next().origin;                                  debug_origin=i.next().origin;
                                 Value& value=*i.next().value;                                  const String& name=*i.next().value->get_string(); debug_name=&name;
                                 const String& name=*value.get_string(); debug_name=&name;  
   
                                 DEBUG_PRINT_STRING(name)                                  DEBUG_PRINT_STRING(name)
   
Line 277  void Request::execute(ArrayOperation& op Line 280  void Request::execute(ArrayOperation& op
                                 stack.push(*class_value);                                  stack.push(*class_value);
                                 break;                                  break;
                         }                          }
   
   #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL
                   case OP::OP_GET_ELEMENT__SPECIAL:
                   case OP::OP_GET_ELEMENT__SPECIAL__WRITE:
                           {
                                   const String& name=stack.pop().string();  debug_name=&name;
                                   Value& ncontext=stack.pop().value();
   
                                   Value* value=0;
                                   if(VStateless_class* vclass=ncontext.get_class()){
                                           if(name==class_element_name){
                                                   value=vclass;
                                           } else if(name==class_name_element_name){
                                                   value=new VString(vclass->name());
                                           }
                                   } else {
                                           // Value
                                           if(name==class_element_name){
                                                   value=&ncontext;
                                           }else if(name==class_name_element_name){
                                                   value=new VString(*new String(ncontext.type()));
                                           }
                                   };
                                   if(opcode==OP::OP_GET_ELEMENT__SPECIAL){
                                           stack.push(*value);
                                   } else {
                                           write_assign_lang(*value);
                                   }
                                   break;
                           }
   #endif
   
                 // OP_WITH                  // OP_WITH
                 case OP::OP_WITH_ROOT:                  case OP::OP_WITH_ROOT:
                         {                          {
Line 397  void Request::execute(ArrayOperation& op Line 432  void Request::execute(ArrayOperation& op
   
                                 const String& name=stack.pop().string();  debug_name=&name;                                  const String& name=stack.pop().string();  debug_name=&name;
                                 Value& ncontext=stack.pop().value();                                  Value& ncontext=stack.pop().value();
                                 if(const VJunction* vjunction=ncontext.put_element(name, &value, false))                                  if(const VJunction* vjunction=ncontext.put_element(name, &value))
                                         if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT)                                          if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT)
                                                 throw Exception(PARSER_RUNTIME,                                                  throw Exception(PARSER_RUNTIME,
                                                         0,                                                          0,
Line 639  void Request::execute(ArrayOperation& op Line 674  void Request::execute(ArrayOperation& op
   
                                 execute(local_ops);                                  execute(local_ops);
   
                                 Value* value;  
                                 // from "$a $b" part of expression taking only string value,                                  // from "$a $b" part of expression taking only string value,
                                 // ignoring any other content of wcontext                                  // ignoring any other content of wcontext
                                 if(const String* string=wcontext->get_string())                                  const String* string=wcontext->get_string();
                                         value=new VString(*string);                                  Value* value=string ? new VString(*string) : new VString();
                                 else  
                                         value=VVoid::get();  
                                 stack.push(*value);                                  stack.push(*value);
   
                                 wcontext=saved_wcontext;                                  wcontext=saved_wcontext;
Line 723  void Request::execute(ArrayOperation& op Line 755  void Request::execute(ArrayOperation& op
                                                                 value.type());                                                                  value.type());
                                 }                                  }
   
                                 VMethodFrame frame(*junction->method, method_frame, junction->self);                                  Value *result;
                                 METHOD_FRAME_ACTION(op_call(frame));                                  {
                                 stack.push(frame.result().as_value());                                          VMethodFrame frame(*junction->method, method_frame, junction->self);
                                           METHOD_FRAME_ACTION(op_call(frame));
                                           result=&frame.result().as_value();
                                           // VMethodFrame desctructor deletes junctions in stack params here
                                   }
                                   stack.push(*result);
   
                                 DEBUG_PRINT_STR("<-returned")                                  DEBUG_PRINT_STR("<-returned")
   
Line 836  void Request::execute(ArrayOperation& op Line 873  void Request::execute(ArrayOperation& op
                                 DEBUG_PRINT_OPS(local_ops)                                  DEBUG_PRINT_OPS(local_ops)
                                 DEBUG_PRINT_STR("->\n")                                  DEBUG_PRINT_STR("->\n")
   
                                 Value &object=construct(*class_value, *constructor_junction->method);                                  Value *result;
                                 VConstructorFrame frame(*constructor_junction->method, method_frame, object);                                  {
                                 METHOD_FRAME_ACTION(op_call(frame));                                          Value& object=construct(*class_value, *constructor_junction->method);
                                 object.enable_default_setter();                                          VConstructorFrame frame(*constructor_junction->method, method_frame, object);
                                           METHOD_FRAME_ACTION(op_call(frame));
                                           object.enable_default_setter();
                                           result=&frame.result().as_value();
                                           // VMethodFrame desctructor deletes junctions in stack params here
                                   }
   
                                 if(opcode==OP::OP_CONSTRUCT_OBJECT)                                  if(opcode==OP::OP_CONSTRUCT_OBJECT)
                                         stack.push(frame.result().as_value());                                          stack.push(*result);
                                 else                                  else
                                         write_pass_lang(frame.result());                                          write_pass_lang(*result);
   
                                 DEBUG_PRINT_STR("<-returned")                                  DEBUG_PRINT_STR("<-returned")
                                 break;                                  break;
Line 1271  Value& Request::get_element(Value& ncont Line 1313  Value& Request::get_element(Value& ncont
   
 void Request::put_element(Value& ncontext, const String& name, Value* value) {  void Request::put_element(Value& ncontext, const String& name, Value* value) {
         // put_element can return property-setting-junction          // put_element can return property-setting-junction
         if(const VJunction* vjunction=ncontext.put_element(name, value, false))          if(const VJunction* vjunction=ncontext.put_element(name, value))
                 if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) {                  if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) {
                         const Junction& junction = vjunction->junction();                          const Junction& junction = vjunction->junction();
                         VConstructorFrame frame(*junction.method, method_frame /*caller*/, junction.self);                          VConstructorFrame frame(*junction.method, method_frame /*caller*/, junction.self);
Line 1352  StringOrValue Request::process(Value& in Line 1394  StringOrValue Request::process(Value& in
         Junction* junction=input_value.get_junction();          Junction* junction=input_value.get_junction();
         if(junction) {          if(junction) {
                 if(junction->is_getter) { // is it a getter-junction?                  if(junction->is_getter) { // is it a getter-junction?
                         return process_getter(*junction);                          return process(process_getter(*junction).as_value(), intercept_string);
                 }                  }
   
                 if(junction->code) { // is it a code-junction?                  if(junction->code) { // is it a code-junction?
Line 1414  StringOrValue Request::process(Value& in Line 1456  StringOrValue Request::process(Value& in
 void Request::process_write(Value& input_value) {  void Request::process_write(Value& input_value) {
         Junction* junction=input_value.get_junction();          Junction* junction=input_value.get_junction();
         if(junction) {          if(junction) {
                 if(junction->is_getter) { // is it a getter-junction?                  // no getter-junction check as process_write is called
                         write_pass_lang(process_getter(*junction));                  // to process method arguments, not from get_element
                         return;  
                 }  
   
                 if(junction->code) { // is it a code-junction?                  if(junction->code) { // is it a code-junction?
                                                         // process it                                                          // process it
Line 1587  const String* Request::get_method_filena Line 1627  const String* Request::get_method_filena
                                                         origin=i.next().origin;                                                          origin=i.next().origin;
                                                         break;                                                          break;
                                                 }                                                  }
                                           default: break;
                                 }                                  }
                                 if(origin.file_no)                                  if(origin.file_no)
                                         return get_used_filename(origin.file_no);                                          return get_used_filename(origin.file_no);

Removed from v.1.366  
changed lines
  Added in v.1.375


E-mail: