Diff for /parser3/src/main/Attic/core.C between versions 1.1 and 1.34

version 1.1, 2001/02/11 19:35:39 version 1.34, 2001/02/24 14:20:51
Line 1 Line 1
 void process(Pool& pool,   /*
                          Value& self,  $Id$
                          RContext& rcontext, WContext& wcontext,   */
                          StringIterator& code, char char_to_stop_before) {  
           #include "pa_request.h"
         // $ on code?  #include "pa_wwrapper.h"
         process_dollar(pool, rcontext, wcontext, code, char_to_stop_before);  #include "pa_common.h"
   #include "pa_vclass.h"
         // ^ on code?  
         process_bird(pool, rcontext, wcontext, code, char_to_stop_before);  #include <stdio.h>
   
   void core() {
           Pool pool;
           Request request(pool);
           request.core();
 }  }
   
 void process_dollar(Pool& pool,   void Request::core() {
                                         Value& THIS,          TRY {
                                         RContext& rcontext, WContext& wcontext,                   String name_RUN(pool()); name_RUN.APPEND_CONST("RUN");
                                         StringIterator& iter, char char_to_stop_before) {                  char *result=execute_MAIN(construct_class(name_RUN, load_and_compile_RUN()));
                   printf("result-----------------\n%sEOF----------------\n", result);
         // $name.field.subfield -- read          } 
         // $name.field.subfield(constructor code) -- construct          CATCH(e) {
         // $name.field.subfield[usage code & if none existed autoconstructed as VHash] -- use OR auto-VHash construct                  printf("\nERROR: ");
                           const String *problem_source=e.problem_source();
         Array/*<String&>*/ names(pool);  // what.they.refer.to left-to-right list                  if(problem_source) {
         char names_ended_before; // the char after long name                          const Origin& origin=problem_source->origin();
         get_names(                          if(origin.file)
                 iter, " ([",                                  printf("%s(%d): ",
                 &names, &names_ended_before); // must return count()>0                                  origin.file, 1+origin.line);
                           printf("'%s' ", 
         bool read_mode=name_ended_before==' ';                                  problem_source->cstr());
         Value *context=read_mode?rcontext:wcontext;  
           
         if(read_mode) {  
                 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;  
                 }                  }
                 wcontext.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)
                 int steps=names.count();                                  printf(", code: %s", code->cstr());
                 if(construct_mode)  
                         steps--;  
                 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");
           }
           END_CATCH
   }
   
                 if(construct_mode) {    Array& Request::load_and_compile_RUN() {
                         // pure side effect, no wcontext.write here          char *file="Y:\\parser3\\src\\test.p";
                         String& name=static_cast<String&>(names.get[steps]);          char *source=file_read(pool(), file);
                         WContext local_wcontext(pool /* empty */);          Array& compiled_methods=COMPILE(source, file);
                         process(pool, rcontext, local_wcontext, iter, ')');          return compiled_methods;
                         context->put_element(name, local_wcontext.value());  }
                 } else { // =='['  
                         WContext local_context(pool, context);  VClass *Request::construct_class(String& name, Array& compiled_methods) {
                         process(pool, local_context, local_context, iter, ']');          // create new 'name' vclass, add it to request's classes
                         wcontext.write(local_context);          Array immediate_parents(pool());
                 }          // TODO: immediate_parents=@PARENTS
   
           VClass *result=NEW VClass(pool(), immediate_parents);
           result->set_name(name);
           classes().put(name, result);
                                   
                 iter++; // skip ')' ']'          for(int i=0; i<compiled_methods.size(); i++) {
                   // TODO: filter out @PARENTS & @CLASS & ?co?
                   Method &method=*static_cast<Method *>(compiled_methods.quick_get(i));
                   result->add_method(method.name, method);
         }          }
   
           return result;
 }  }
   
 void process_bird(Pool& pool,   char *Request::execute_MAIN(VClass *class_RUN) {
                                   Value& self,          // initialize contexts
                                   RContext& rcontext, WContext& wcontext,           self=root=rcontext=class_RUN;
                                   StringIterator& iter, char char_to_stop_before) {          wcontext=NEW WWrapper(pool(), class_RUN);
           
         // ^name.field.subfield.method[..] -- plain call          // locate @main code
         // ^name.field.subfield.method_ref[..] -- method ref call, when .get_method()!=0          String name_main(pool());
                   name_main.APPEND_CONST(MAIN_METHOD_NAME);
         Array/*<String&>*/ names(pool);  // what.they.refer.to left-to-right list  
         char names_ended_before; // the char after long name          Value *value_main=class_RUN->get_element(name_main);
         get_names(          if(!value_main)
                 iter, "[",                  THROW(0,0,
                 &names, &names_ended_before); // must return count()>0                          class_RUN->name(), "class does not contain method '"MAIN_METHOD_NAME"'");
   
         Value *context=rcontext;          Junction *junction_main=value_main->get_junction();
         iter++; // skip '['          const Method *method_main=junction_main->method;
   
         Value *local_self=context;          if(!method_main)
         int steps=names.count()-1;                  THROW(0,0,
         for(int i=0; i<steps; i++) {                          class_RUN->name(), 
                 String& name=static_cast<String&>(names.get[i]);                          "class does contain '"MAIN_METHOD_NAME"' but it is not a method");
                 context=(local_self=context)->get_element(name);  
                 if(!context) // no such object field, sad story: can't call method of void  
                         pool.exception().raise(name, "call: to void.method");  
         }  
           
         String& name=static_cast<String&>(names.get[steps]);  
         // 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) // failed: no element of that 'name'  
                         pool.exception().raise(name, "call: no method field found");  
                 method=value->get_method();  
                 if(!method) // failed: that field wasn't method_ref  
                         pool.exception().raise(name, "call: this field is not a method reference");  
                 local_self=value->get_self();  
         }  
   
           // execute!     
           execute(method_main->code);
   
         Array/*<String&>*/ param_values(pool);  
         get_params(  
                 iter, "]",  
                 &param_values);  
         iter++; // skip ']'  
   
         Method_this_n_params local_rcontext(pool,   
                 local_self,  
                 method->param_names, param_values);  
         WContext local_wcontext(pool /* empty */);  
         process(pool, local_rcontext, local_wcontext, iter, ']');  
         wcontext.write(local_wcontext);  
 }  
   
           // return chars
           return wcontext->get_string()->cstr();
   }

Removed from v.1.1  
changed lines
  Added in v.1.34


E-mail: