Annotation of parser3/src/main/core.C, revision 1.42
1.18 paf 1: /*
1.42 ! paf 2: $Id: core.C,v 1.41 2001/02/25 16:36:12 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:
18: void Request::core() {
1.24 paf 19: TRY {
1.35 paf 20: char *file="Y:\\parser3\\src\\test.p";
21: String RUN(pool()); RUN.APPEND_CONST(NAME_RUN);
22: use(file, &RUN);
23:
24: char *result=execute_MAIN();
1.34 paf 25: printf("result-----------------\n%sEOF----------------\n", result);
1.24 paf 26: }
27: CATCH(e) {
1.31 paf 28: printf("\nERROR: ");
29: const String *problem_source=e.problem_source();
30: if(problem_source) {
31: const Origin& origin=problem_source->origin();
32: if(origin.file)
33: printf("%s(%d): ",
34: origin.file, 1+origin.line);
1.32 paf 35: printf("'%s' ",
1.31 paf 36: problem_source->cstr());
37: }
38: printf("%s", e.comment());
1.23 paf 39: const String *type=e.type();
40: if(type) {
41: printf(" type: %s", type->cstr());
42: const String *code=e.code();
43: if(code)
44: printf(", code: %s", code->cstr());
45: }
1.31 paf 46: printf("\n");
1.23 paf 47: }
1.24 paf 48: END_CATCH
1.23 paf 49: }
50:
1.38 paf 51: void Request::use(char *file, String *alias) {
1.42 ! paf 52: // TODO: обнаружить|решить cyclic dependences
1.23 paf 53: char *source=file_read(pool(), file);
1.37 paf 54: if(!source)
55: THROW(0,0,
56: 0,
57: "use: can not read '%s' file", file);
58:
1.38 paf 59: VClass& vclass=COMPILE(source, alias, file);
1.39 paf 60: String& vclass_name=vclass.name();
61: //TODO: обнаружить, что грузят не объект, а операторы.
62: // загрузить операторы
1.35 paf 63: classes_array()+=&vclass;
1.39 paf 64: classes().put(vclass_name, &vclass);
1.38 paf 65: if(alias)
66: classes().put(*alias, &vclass);
1.23 paf 67: }
68:
1.35 paf 69: char *Request::execute_MAIN() {
70: // locate class with @main & it's code
1.23 paf 71: String name_main(pool());
72: name_main.APPEND_CONST(MAIN_METHOD_NAME);
73:
1.35 paf 74: // looking for latest known @main
75: for(int i=classes_array().size(); --i>=0;) {
76: VClass *vclass=static_cast<VClass *>(classes_array().get(i));
77: Value *main=vclass->get_element(name_main);
78: if(main) { // found some 'main' element
79: Junction *junction=main->get_junction();
1.36 paf 80: if(junction) {// it even has junction!
81: const Method *method=junction->method;
82: if(method) { // and junction is method-junction! call it
83: // initialize contexts
1.41 paf 84: root=rcontext=self=vclass;
1.40 paf 85: wcontext=NEW WWrapper(pool(), vclass, false /* not constructing */);
1.36 paf 86:
87: // execute!
88: execute(method->code);
89:
90: // return chars
91: return wcontext->get_string()->cstr();
92: }
1.35 paf 93: }
94: }
95: }
96:
97: THROW(0,0,
98: 0,
99: "'"MAIN_METHOD_NAME"' method not found");
100: return 0;
1.23 paf 101: }
E-mail: