Diff for /parser3/src/main/Attic/core.C between versions 1.9 and 1.38

version 1.9, 2001/02/14 12:20:48 version 1.38, 2001/02/25 09:14:02
Line 1 Line 1
 void process(method_self_n_params_n_locals& root, Value& self,  /*
                          arcontext& arcontext, WContext& awcontext,   $Id$
                          String_iterator& code, char char_to_stop_before) {  */
           
         // $ on code?  #include "pa_request.h"
         process_dollar(root, self, arcontext, awcontext, code, char_to_stop_before);  #include "pa_wwrapper.h"
   #include "pa_common.h"
         // ^ on code?  #include "pa_vclass.h"
         process_bird(root, self, arcontext, awcontext, code, char_to_stop_before);  
   #include <stdio.h>
         // TODO  
         // 2. вызовы статических методов  void core() {
           Pool pool;
           Request request(pool);
           request.core();
 }  }
   
 void process_dollar(method_self_n_params_n_locals& root, Value& self,  void Request::core() {
                                         arcontext& arcontext, WContext& awcontext,           TRY {
                                         String_iterator& iter, char char_to_stop_before) {                  char *file="Y:\\parser3\\src\\test.p";
                   String RUN(pool()); RUN.APPEND_CONST(NAME_RUN);
         // $name.field.subfield -- read                  use(file, &RUN);
         // $name.field.subfield(constructor code) -- construct  
         // $name.field.subfield[usage code & if none existed autoconstructed as VHash] -- use OR auto-VHash construct                  char *result=execute_MAIN();
                           printf("result-----------------\n%sEOF----------------\n", result);
         Array/*<String&>*/ names(pool);  // what.they.refer.to left-to-right list          } 
         char names_ended_before; // the char after long name          CATCH(e) {
         Prefix prefix;                  printf("\nERROR: ");
         get_names(                  const String *problem_source=e.problem_source();
                 iter, " ([",                  if(problem_source) {
                 &prefix, &names, &names_ended_before); // can return count()=0 when $self alone                          const Origin& origin=problem_source->origin();
                           if(origin.file)
         bool read_mode=name_ended_before==' ';                                  printf("%s(%d): ",
         Value *context=                                  origin.file, 1+origin.line);
                 prefix?                          printf("'%s' ", 
                         prefix==ROOT_PREFIX?root:self:                                  problem_source->cstr());
                 read_mode?arcontext:awcontext;  
           
         if(read_mode) {  
                 // 'context' dive into dotted path  
                 for(int i=0; i<names.count(); i++) {  
                         context=context->get_element(static_cast<Value *>(names.get[i]));  
                         if(!context) // no such object field, nothing bad, just ignore that  
                                 return;  
                 }                  }
                 awcontext.write(context);                  printf("%s", e.comment());
         } else { // write mode                  const String *type=e.type();
                 iter++; // skip '(' '['                  if(type) {
                           printf("  type: %s", type->cstr());
                 bool construct_mode=names_ended_before=='(';                          const String *code=e.code();
                           if(code)
                 // 'context' dive into dotted path,                                   printf(", code: %s", code->cstr());
                 int steps=names.count();  
                 // if constructing then "excluding last .name"  
                 if(construct_mode)  
                         if(!steps--) // bad: "$self("; now we can safely do ".get[steps]" below  
                                 pool.exception().raise("self re-construction prohibited");  
                 for(int i=0; i<steps; i++) {  
                         String& name=static_cast<String&>(names.get[i]);  
                         Value *next_current=context->get_element(name);  
                         if(next_current)  
                                 next_current=context->put_element(name, new(pool) VHash(pool));  
                         context=new_current;  
                 }                  }
                   printf("\n");
                 if(construct_mode) {    
                         // .name(construct-code), processing on arcontext in empty temp awcontext  
                         // pure side effect, no awcontext.write here  
                         // last .name  
                         String& name=static_cast<String&>(names.get[steps]);  
                         WContext local_wcontext(pool /* empty */);  
                         process(root, self, arcontext, local_wcontext, iter, ')');  
                         context->put_element(name, local_wcontext.value());  
                 } else { // =='['  
                         // .name[with-code], processing on 'context'  
                         WContext local_context(pool, context);  
                         process(root, self, local_context, local_context, iter, ']');  
                         awcontext.write(local_context);  
                 }  
                   
                 iter++; // skip ')' ']'  
         }          }
           END_CATCH
 }  }
   
 void process_bird(method_self_n_params_n_locals& root, Value& self,  void Request::use(char *file, String *alias) {
                                   arcontext& arcontext, WContext& awcontext,           char *source=file_read(pool(), file);
                                   String_iterator& iter, char char_to_stop_before) {          if(!source)
                           THROW(0,0,
         // ^name.field.subfield.method[..] -- plain call                          0,
         // ^name.field.subfield.method_ref[..] -- method ref call, when .get_method()!=0                          "use: can not read '%s' file", file);
         // ^class:method[..]  -- no dotted path allowed before/after  
         //  1: wcontext.object_class == 0?  -- constructor          VClass& vclass=COMPILE(source, alias, file);
         //  2: wcontext.object_class.has_parent('class')? -- dynamic call          String *vclass_name=vclass.name();
         //  3: not -------------------------------------? -- static call          if(!vclass_name)
                           return; //TODO: add operators 
         Array/*<String&>*/ names(pool);  // what.they.refer.to left-to-right list          classes_array()+=&vclass;
         char names_ended_before; // the char after long name          classes().put(*vclass_name, &vclass);
         Prefix prefix;          if(alias)
         get_names(                  classes().put(*alias, &vclass);
                 iter, "[",  }
                 &prefix, &names, &names_ended_before); // can return count()=0 when ^self alone  
   char *Request::execute_MAIN() {
         Value *context=          // locate class with @main & it's code
                 prefix?          String name_main(pool());
                         prefix==ROOT_PREFIX?root:self:          name_main.APPEND_CONST(MAIN_METHOD_NAME);
                 arcontext;  
         iter++; // skip '['          // looking for latest known @main
           for(int i=classes_array().size(); --i>=0;) {
         // 'context' dive into dotted path, excluding last .name                  VClass *vclass=static_cast<VClass *>(classes_array().get(i));
         int steps=names.count()-1;                  Value *main=vclass->get_element(name_main);
         if(steps<0) // bad: "^self["; now we can safely do ".get[steps]" below                  if(main) { // found some 'main' element
                 pool.exception().raise("call: calling method named 'self'");                          Junction *junction=main->get_junction();
         for(int i=0; i<steps; i++) {                          if(junction) {// it even has junction!
                 String& name=static_cast<String&>(names.get[i]);                                  const Method *method=junction->method;
                 context=context->get_element(name);                                  if(method) { // and junction is method-junction! call it
                 if(!context) // no such object field, sad story: can't call method of void                                          // initialize contexts
                         pool.exception().raise(name, "call: to void.method");                                          self=root=rcontext=vclass;
         }                                          wcontext=NEW WWrapper(pool(), vclass);
                                                   
         // last .name                                          // execute!     
         String& name=static_cast<String&>(names.get[steps]);                                          execute(method->code);
         if(steps==0) { // the sole name on path, maybe ^class:method[ call                                          
                 String_iterator ni(name);                                          // return chars
                 if(ni.skip_to(':')) { // it is                                          return wcontext->get_string()->cstr();
                         ni++; // skip ':'                                  }
                         String method_name(pool); method_name.append(ni, 0);  
                         name=method_name; // trim "class:" prefix from the name  
   
                         String cn(pool);  cn.append(0, ni);  
                         Class *right_class=classes.get(cn);  
                         if(!right_class) // bad: no such class  
                                 pool.exception().raise(cn, "call: undefined class");  
                         Class *left_class=awcontext.get_class();  
                         if(left_class) {  
                                 if(left_class.has_parent(right_class)) // dynamic call  
                                         context=awcontext.value(); // it's 'self'  
                                 else // static call  
                                         context=right_class; // 'self' := class, not instance  
                         } else { // constructor: $some(^class:method[..]) call  
                                 context=new(pool) VClass(pool, right_class); // 'self' := new VClass of 'class:'  
                                 awcontext.write(context);  
                         }                          }
                 }                  }
         }          }
         // first we're trying to locate method with that 'name'  
         Method *method=context.get_method(name);  
         if(!method) { // no such method: try to locate method ref field  
                 Value *value=context.get_element(name);  
                 if(value) { // good: we have some element of that 'name'  
                         Method_ref *method_ref=value->get_method_ref();  
                         if(!method_ref) // bad: that field wasn't method_ref  
                                 pool.exception().raise(name, "call: this field is not a method reference");  
                         method=method_ref->method;  
                         context=method_ref->self;  
                 } else { // no element of that 'name', that must be operator then  
                         method=operators.get(name);  
                         if(!method) // bad: that 'name' is neither method nor field nor operator  
                                 pool.exception().raise(name, "call: neither method nor field nor operator");  
                 }  
         }  
   
   
         Array/*<String&>*/ param_values(pool);  
         get_params(  
                 iter,  
                 arcontext,  
                 &param_values);  
         iter++; // skip ']'  
   
         method_self_n_params_n_locals local_rcontext(pool,   
                 context,  
                 method->param_names, param_values,  
                 method->local_names);  
         WContext local_wcontext(pool, context);  
         process(  
                 local_rcontext/* $:vars */, context /* $self.vars */,  
                 local_rcontext, local_wcontext,   
                 iter, ']');  
         awcontext.write(local_wcontext);  
 }  
   
           
           THROW(0,0,
                   0, 
                   "'"MAIN_METHOD_NAME"' method not found");
           return 0;
   }

Removed from v.1.9  
changed lines
  Added in v.1.38


E-mail: