|
|
| version 1.33, 2001/02/24 13:21:59 | version 1.52, 2001/03/10 15:56:16 |
|---|---|
| Line 2 | Line 2 |
| $Id$ | $Id$ |
| */ | */ |
| #include "core.h" | |
| #include "classes/_string.h" | |
| #include "classes/_double.h" | |
| #include "classes/_int.h" | |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_wwrapper.h" | |
| #include "pa_common.h" | |
| #include "pa_vclass.h" | |
| #include <stdio.h> | String *unnamed_name; |
| String *empty_string; | |
| String *auto_method_name; | |
| String *main_method_name; | |
| String *auto_class_name; | |
| String *run_class_name; | |
| String *root_class_name; | |
| String *env_class_name; | |
| void core() { | void core() { |
| Pool pool; | Pool pool; |
| // names | |
| unnamed_name=new(pool) String(pool); unnamed_name->APPEND_CONST("unnamed"); | |
| empty_string=new(pool) String(pool); | |
| auto_method_name=new(pool) String(pool); auto_method_name->APPEND_CONST(AUTO_METHOD_NAME); | |
| main_method_name=new(pool) String(pool); main_method_name->APPEND_CONST(MAIN_METHOD_NAME); | |
| auto_class_name=new(pool) String(pool); auto_class_name->APPEND_CONST(AUTO_CLASS_NAME); | |
| run_class_name=new(pool) String(pool); run_class_name->APPEND_CONST(RUN_CLASS_NAME); | |
| root_class_name=new(pool) String(pool); root_class_name->APPEND_CONST(ROOT_CLASS_NAME); | |
| env_class_name=new(pool) String(pool); env_class_name->APPEND_CONST(ENV_CLASS_NAME); | |
| // classes | |
| initialize_string_class(pool, *(string_class=new(pool) VClass(pool))); | |
| initialize_double_class(pool, *(double_class=new(pool) VClass(pool))); | |
| initialize_int_class(pool, *(int_class=new(pool) VClass(pool))); | |
| // request | |
| Request request(pool); | Request request(pool); |
| request.core(); | request.core(); |
| } | } |
| void Request::core() { | |
| TRY { | |
| String name_RUN(pool()); name_RUN.APPEND_CONST("RUN"); | |
| char *result=execute_MAIN(construct_class(name_RUN, load_and_compile_RUN())); | |
| printf("result-----------------\n%s\nEOF----------------\n", result); | |
| } | |
| CATCH(e) { | |
| 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(); | |
| if(type) { | |
| printf(" type: %s", type->cstr()); | |
| const String *code=e.code(); | |
| if(code) | |
| printf(", code: %s", code->cstr()); | |
| } | |
| printf("\n"); | |
| } | |
| END_CATCH | |
| } | |
| Array& Request::load_and_compile_RUN() { | |
| char *file="Y:\\parser3\\src\\test.p"; | |
| char *source=file_read(pool(), file); | |
| Array& compiled_methods=COMPILE(source, file); | |
| return compiled_methods; | |
| } | |
| VClass *Request::construct_class(String& name, Array& compiled_methods) { | |
| // create new 'name' vclass, add it to request's classes | |
| Array immediate_parents(pool()); | |
| // TODO: immediate_parents=@PARENTS | |
| VClass *result=NEW VClass(pool(), immediate_parents); | |
| result->set_name(name); | |
| classes().put(name, result); | |
| 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; | |
| } | |
| char *Request::execute_MAIN(VClass *class_RUN) { | |
| // initialize contexts | |
| self=root=rcontext=class_RUN; | |
| wcontext=NEW WWrapper(pool(), class_RUN); | |
| // locate @main code | |
| String name_main(pool()); | |
| name_main.APPEND_CONST(MAIN_METHOD_NAME); | |
| Value *value_main=class_RUN->get_element(name_main); | |
| if(!value_main) | |
| THROW(0,0, | |
| class_RUN->name(), "class does not contain method '"MAIN_METHOD_NAME"'"); | |
| Junction *junction_main=value_main->get_junction(); | |
| const Method *method_main=junction_main->method; | |
| if(!method_main) | |
| THROW(0,0, | |
| class_RUN->name(), | |
| "class does contain '"MAIN_METHOD_NAME"' but it is not a method"); | |
| // execute! | |
| execute(method_main->code); | |
| // return chars | |
| return wcontext->get_string()->cstr(); | |
| } |