|
|
| version 1.31, 2001/02/23 22:22:08 | version 1.46, 2001/03/09 04:47:29 |
|---|---|
| Line 8 $Id$ | Line 8 $Id$ |
| #include "pa_vclass.h" | #include "pa_vclass.h" |
| #include <stdio.h> | #include <stdio.h> |
| #include "classes/_string.h" | |
| void core() { | void core() { |
| Pool pool; | Pool pool; |
| initialize_string_class(pool); | |
| Request request(pool); | Request request(pool); |
| request.core(); | request.core(); |
| } | } |
| Request::Request(Pool& apool) : Pooled(apool), | |
| stack(apool), | |
| root_class(apool), | |
| fclasses(apool), | |
| fclasses_array(apool) | |
| { | |
| // construct_root_class | |
| void construct_root_class(Request& request); // classes/root | |
| construct_root_class(*this); | |
| // TODO: construct other classes, | |
| // для встроенных какая-то табличка | |
| // для внешних - конфиг с @CLASSES файлы с классами/ворохами операторов | |
| // adding root superclass, | |
| // parent of all classes, | |
| // operators holder | |
| String ROOT(pool()); ROOT.APPEND_CONST(ROOT_NAME); | |
| classes().put(ROOT, &root_class); | |
| } | |
| void Request::core() { | void Request::core() { |
| TRY { | TRY { |
| String name_RUN(pool()); name_RUN.APPEND_CONST("RUN"); | char *file="Y:\\parser3\\src\\test.p"; |
| char *result=execute_MAIN(construct_class(name_RUN, load_and_compile_RUN())); | String RUN(pool()); RUN.APPEND_CONST(RUN_NAME); |
| printf("-----------------\n%s\n----------------\n", result); | use(file, &RUN); |
| char *result=execute_MAIN(); | |
| printf("result-----------------\n%sEOF----------------\n", result); | |
| } | } |
| CATCH(e) { | CATCH(e) { |
| printf("\nERROR: "); | printf("\nERROR: "); |
| Line 29 void Request::core() { | Line 55 void Request::core() { |
| if(origin.file) | if(origin.file) |
| printf("%s(%d): ", | printf("%s(%d): ", |
| origin.file, 1+origin.line); | origin.file, 1+origin.line); |
| printf("%s ", | printf("'%s' ", |
| problem_source->cstr()); | problem_source->cstr()); |
| } | } |
| printf("%s", e.comment()); | printf("%s", e.comment()); |
| Line 45 void Request::core() { | Line 71 void Request::core() { |
| END_CATCH | END_CATCH |
| } | } |
| Array& Request::load_and_compile_RUN() { | void Request::use(char *file, String *name) { |
| char *file="Y:\\parser3\\src\\test.p"; | // TODO: обнаружить|решить cyclic dependences |
| char *source=file_read(pool(), file); | char *source=file_read(pool(), file); |
| Array& compiled_methods=COMPILE(source, file); | if(!source) |
| return compiled_methods; | THROW(0,0, |
| } | 0, |
| "use: can not read '%s' file", file); | |
| VClass *Request::construct_class(String& name, Array& compiled_methods) { | COMPILE(source, name, file); |
| // create new 'name' vclass, add it to request's classes | // TODO: запустить @STATIC[], если есть |
| Array immediate_parents(pool()); | |
| // TODO: immediate_parents=@PARENTS | |
| VClass *result=NEW VClass(pool(), name, 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; | // if(alias) |
| //classes().put(*alias, &vclass); | |
| } | } |
| char *Request::execute_MAIN(VClass *class_RUN) { | char *Request::execute_MAIN() { |
| // initialize contexts | // locate class with @main & it's code |
| root=self=rcontext=class_RUN; | |
| wcontext=NEW WWrapper(pool(), class_RUN); | |
| // 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); |
| Value *value_main=class_RUN->get_element(name_main); | // looking for latest known @main |
| if(!value_main) | for(int i=classes_array().size(); --i>=0;) { |
| THROW(0,0, | VClass *vclass=static_cast<VClass *>(classes_array().get(i)); |
| &class_RUN->name(), | Value *main=vclass->get_element(name_main); |
| "no '"MAIN_METHOD_NAME"' method in class"); | if(main) { // found some 'main' element |
| Junction *junction=main->get_junction(); | |
| Junction *junction_main=value_main->get_junction(); | if(junction) {// it even has junction! |
| const Method *method_main=junction_main->method; | const Method *method=junction->method; |
| if(method) { // and junction is method-junction! call it | |
| if(!method_main) | // initialize contexts |
| THROW(0,0, | root=rcontext=self=vclass; |
| &class_RUN->name(), | wcontext=NEW WWrapper(pool(), vclass, false /* not constructing */); |
| "'"MAIN_METHOD_NAME"' in class is not a method"); | |
| // execute! | |
| // execute! | execute(*method->parser_code); |
| execute(method_main->code); | |
| // return chars | |
| // return chars | return wcontext->get_string()->cstr(); |
| return wcontext->get_string()->cstr(); | } |
| } | |
| } | |
| } | |
| THROW(0,0, | |
| 0, | |
| "'"MAIN_METHOD_NAME"' method not found"); | |
| return 0; | |
| } | } |