|
|
| version 1.24, 2001/02/22 10:43:45 | version 1.32, 2001/02/24 08:28:37 |
|---|---|
| Line 3 $Id$ | Line 3 $Id$ |
| */ | */ |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_wcontext.h" | #include "pa_wwrapper.h" |
| #include "pa_common.h" | #include "pa_common.h" |
| #include "pa_vclass.h" | #include "pa_vclass.h" |
| #include <stdio.h> | #include <stdio.h> |
| void core() { | void core() { |
| Exception exception; | Pool pool; |
| Pool pool(exception); | |
| Request request(pool); | Request request(pool); |
| request.core(); | request.core(); |
| } | } |
| Line 20 void Request::core() { | Line 19 void Request::core() { |
| TRY { | TRY { |
| String name_RUN(pool()); name_RUN.APPEND_CONST("RUN"); | String name_RUN(pool()); name_RUN.APPEND_CONST("RUN"); |
| char *result=execute_MAIN(construct_class(name_RUN, load_and_compile_RUN())); | char *result=execute_MAIN(construct_class(name_RUN, load_and_compile_RUN())); |
| printf("-----------------\n%s\n----------------\n", result); | printf("result-----------------\n%s\nEOF----------------\n", result); |
| } | } |
| CATCH(e) { | CATCH(e) { |
| printf("operator error occured: %s\n", e.comment()); | printf("\nERROR: "); |
| const String *problem_source=e.problem_source(); | |
| if(problem_source) { | |
| const Origin& origin=problem_source->origin(); | |
| if(origin.file) | |
| printf("%s(%d): ", | |
| origin.file, 1+origin.line); | |
| printf("'%s' ", | |
| problem_source->cstr()); | |
| } | |
| printf("%s", e.comment()); | |
| const String *type=e.type(); | const String *type=e.type(); |
| if(type) { | if(type) { |
| printf(" type: %s", type->cstr()); | printf(" type: %s", type->cstr()); |
| const String *code=e.code(); | const String *code=e.code(); |
| if(code) | if(code) |
| printf(", code: %s", code->cstr()); | printf(", code: %s", code->cstr()); |
| printf("\n"); | |
| } | |
| const String *problem_source=e.problem_source(); | |
| if(problem_source) { | |
| const Origin& origin=problem_source->origin(); | |
| printf(" '%s'\n", | |
| problem_source->cstr()); | |
| if(origin.file) | |
| printf(" [%s:%d]", | |
| origin.file, origin.line); | |
| printf("\n"); | |
| } | } |
| printf("\n"); | |
| } | } |
| END_CATCH | END_CATCH |
| } | } |
| Line 58 VClass *Request::construct_class(String& | Line 57 VClass *Request::construct_class(String& |
| Array immediate_parents(pool()); | Array immediate_parents(pool()); |
| // TODO: immediate_parents=@PARENTS | // TODO: immediate_parents=@PARENTS |
| VClass *result=new(pool()) VClass(pool(), name, immediate_parents); | VClass *result=NEW VClass(pool(), name, immediate_parents); |
| result->set_name(name); | |
| classes().put(name, result); | classes().put(name, result); |
| for(int i=0; i<compiled_methods.size(); i++) { | for(int i=0; i<compiled_methods.size(); i++) { |
| // TODO: filter out @PARENTS & ?co? | // TODO: filter out @PARENTS & @CLASS & ?co? |
| Method &method=*static_cast<Method *>(compiled_methods.quick_get(i)); | Method &method=*static_cast<Method *>(compiled_methods.quick_get(i)); |
| result->add_method(method.name, method); | result->add_method(method.name, method); |
| } | } |
| Line 72 VClass *Request::construct_class(String& | Line 72 VClass *Request::construct_class(String& |
| char *Request::execute_MAIN(VClass *class_RUN) { | char *Request::execute_MAIN(VClass *class_RUN) { |
| // initialize contexts | // initialize contexts |
| root=self=rcontext=class_RUN; | self=root=rcontext=class_RUN; |
| wcontext=new(pool()) WContext(pool(), class_RUN); | wcontext=NEW WWrapper(pool(), class_RUN); |
| // locate @main code | // locate @main code |
| String name_main(pool()); | String name_main(pool()); |
| name_main.APPEND_CONST(MAIN_METHOD_NAME); | name_main.APPEND_CONST(MAIN_METHOD_NAME); |
| Method *method_main=class_RUN->get_method(name_main); | Value *value_main=class_RUN->get_element(name_main); |
| if(!method_main) | if(!value_main) |
| THROW(0,0, | THROW(0,0, |
| &class_RUN->name(), | &class_RUN->name(), |
| "no '"MAIN_METHOD_NAME"' method in class"); | "no '"MAIN_METHOD_NAME"' method in class"); |
| Junction *junction_main=value_main->get_junction(); | |
| const Method *method_main=junction_main->method; | |
| if(!method_main) | |
| THROW(0,0, | |
| &class_RUN->name(), | |
| "'"MAIN_METHOD_NAME"' in class is not a method"); | |
| // execute! | // execute! |
| execute(method_main->code); | execute(method_main->code); |