--- parser3/src/main/Attic/core.C 2001/02/24 15:26:03 1.35 +++ parser3/src/main/Attic/core.C 2001/03/08 13:13:41 1.45 @@ -1,5 +1,5 @@ /* -$Id: core.C,v 1.35 2001/02/24 15:26:03 paf Exp $ +$Id: core.C,v 1.45 2001/03/08 13:13:41 paf Exp $ */ #include "pa_request.h" @@ -15,10 +15,31 @@ void 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() { TRY { char *file="Y:\\parser3\\src\\test.p"; - String RUN(pool()); RUN.APPEND_CONST(NAME_RUN); + String RUN(pool()); RUN.APPEND_CONST(RUN_NAME); use(file, &RUN); char *result=execute_MAIN(); @@ -49,15 +70,18 @@ void Request::core() { } void Request::use(char *file, String *name) { + // TODO: обнаружить|решить cyclic dependences char *source=file_read(pool(), file); - VClass& vclass=COMPILE(source, file); - if(name) // they forced some name? - vclass.set_name(*name); - name=vclass.name(); - if(!name) - return; //TODO: add operators - classes_array()+=&vclass; - classes().put(*name, &vclass); + if(!source) + THROW(0,0, + 0, + "use: can not read '%s' file", file); + + COMPILE(source, name, file); + // TODO: запустить @STATIC[], если есть + +// if(alias) + //classes().put(*alias, &vclass); } char *Request::execute_MAIN() { @@ -71,17 +95,19 @@ char *Request::execute_MAIN() { Value *main=vclass->get_element(name_main); if(main) { // found some 'main' element Junction *junction=main->get_junction(); - const Method *method=junction->method; - if(method) { // that element is a method, call it - // initialize contexts - self=root=rcontext=vclass; - wcontext=NEW WWrapper(pool(), vclass); - - // execute! - execute(method->code); - - // return chars - return wcontext->get_string()->cstr(); + if(junction) {// it even has junction! + const Method *method=junction->method; + if(method) { // and junction is method-junction! call it + // initialize contexts + root=rcontext=self=vclass; + wcontext=NEW WWrapper(pool(), vclass, false /* not constructing */); + + // execute! + execute(*method->parser_code); + + // return chars + return wcontext->get_string()->cstr(); + } } } }