Annotation of parser3/src/main/core.C, revision 1.43
1.18 paf 1: /*
1.43 ! paf 2: $Id: core.C,v 1.42 2001/03/06 10:49:24 paf Exp $
1.18 paf 3: */
4:
1.23 paf 5: #include "pa_request.h"
1.29 paf 6: #include "pa_wwrapper.h"
1.23 paf 7: #include "pa_common.h"
8: #include "pa_vclass.h"
9:
10: #include <stdio.h>
11:
12: void core() {
1.25 paf 13: Pool pool;
1.24 paf 14: Request request(pool);
15: request.core();
1.23 paf 16: }
17:
1.43 ! paf 18: Request::Request(Pool& apool) : Pooled(apool),
! 19: stack(apool),
! 20: ROOT_CLASS(apool),
! 21: fclasses(apool),
! 22: fclasses_array(apool)
! 23: {
! 24: // adding root superclass,
! 25: // parent of all classes,
! 26: // operators holder
! 27: String ROOT(pool()); ROOT.APPEND_CONST(ROOT_NAME);
! 28: classes().put(ROOT, &ROOT_CLASS);
! 29: }
! 30:
1.23 paf 31: void Request::core() {
1.24 paf 32: TRY {
1.35 paf 33: char *file="Y:\\parser3\\src\\test.p";
1.43 ! paf 34: String RUN(pool()); RUN.APPEND_CONST(RUN_NAME);
1.35 paf 35: use(file, &RUN);
36:
37: char *result=execute_MAIN();
1.34 paf 38: printf("result-----------------\n%sEOF----------------\n", result);
1.24 paf 39: }
40: CATCH(e) {
1.31 paf 41: printf("\nERROR: ");
42: const String *problem_source=e.problem_source();
43: if(problem_source) {
44: const Origin& origin=problem_source->origin();
45: if(origin.file)
46: printf("%s(%d): ",
47: origin.file, 1+origin.line);
1.32 paf 48: printf("'%s' ",
1.31 paf 49: problem_source->cstr());
50: }
51: printf("%s", e.comment());
1.23 paf 52: const String *type=e.type();
53: if(type) {
54: printf(" type: %s", type->cstr());
55: const String *code=e.code();
56: if(code)
57: printf(", code: %s", code->cstr());
58: }
1.31 paf 59: printf("\n");
1.23 paf 60: }
1.24 paf 61: END_CATCH
1.23 paf 62: }
63:
1.43 ! paf 64: void Request::use(char *file, String *name) {
1.42 paf 65: // TODO: обнаружить|решить cyclic dependences
1.23 paf 66: char *source=file_read(pool(), file);
1.37 paf 67: if(!source)
68: THROW(0,0,
69: 0,
70: "use: can not read '%s' file", file);
71:
1.43 ! paf 72: COMPILE(source, name, file);
! 73: // TODO: запустить @STATIC[], если есть
! 74:
! 75: // if(alias)
! 76: //classes().put(*alias, &vclass);
1.23 paf 77: }
78:
1.35 paf 79: char *Request::execute_MAIN() {
80: // locate class with @main & it's code
1.23 paf 81: String name_main(pool());
82: name_main.APPEND_CONST(MAIN_METHOD_NAME);
83:
1.35 paf 84: // looking for latest known @main
85: for(int i=classes_array().size(); --i>=0;) {
86: VClass *vclass=static_cast<VClass *>(classes_array().get(i));
87: Value *main=vclass->get_element(name_main);
88: if(main) { // found some 'main' element
89: Junction *junction=main->get_junction();
1.36 paf 90: if(junction) {// it even has junction!
91: const Method *method=junction->method;
92: if(method) { // and junction is method-junction! call it
93: // initialize contexts
1.41 paf 94: root=rcontext=self=vclass;
1.40 paf 95: wcontext=NEW WWrapper(pool(), vclass, false /* not constructing */);
1.36 paf 96:
97: // execute!
98: execute(method->code);
99:
100: // return chars
101: return wcontext->get_string()->cstr();
102: }
1.35 paf 103: }
104: }
105: }
106:
107: THROW(0,0,
108: 0,
109: "'"MAIN_METHOD_NAME"' method not found");
110: return 0;
1.23 paf 111: }
E-mail: