Annotation of parser3/src/main/core.C, revision 1.37
1.18 paf 1: /*
1.37 ! paf 2: $Id: core.C,v 1.36 2001/02/24 15:35:28 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.35 paf 51: void Request::use(char *file, String *name) {
1.23 paf 52: char *source=file_read(pool(), file);
1.37 ! paf 53: if(!source)
! 54: THROW(0,0,
! 55: 0,
! 56: "use: can not read '%s' file", file);
! 57:
1.35 paf 58: VClass& vclass=COMPILE(source, file);
59: if(name) // they forced some name?
60: vclass.set_name(*name);
61: name=vclass.name();
62: if(!name)
63: return; //TODO: add operators
64: classes_array()+=&vclass;
65: classes().put(*name, &vclass);
1.23 paf 66: }
67:
1.35 paf 68: char *Request::execute_MAIN() {
69: // locate class with @main & it's code
1.23 paf 70: String name_main(pool());
71: name_main.APPEND_CONST(MAIN_METHOD_NAME);
72:
1.35 paf 73: // looking for latest known @main
74: for(int i=classes_array().size(); --i>=0;) {
75: VClass *vclass=static_cast<VClass *>(classes_array().get(i));
76: Value *main=vclass->get_element(name_main);
77: if(main) { // found some 'main' element
78: Junction *junction=main->get_junction();
1.36 paf 79: if(junction) {// it even has junction!
80: const Method *method=junction->method;
81: if(method) { // and junction is method-junction! call it
82: // initialize contexts
83: self=root=rcontext=vclass;
84: wcontext=NEW WWrapper(pool(), vclass);
85:
86: // execute!
87: execute(method->code);
88:
89: // return chars
90: return wcontext->get_string()->cstr();
91: }
1.35 paf 92: }
93: }
94: }
95:
96: THROW(0,0,
97: 0,
98: "'"MAIN_METHOD_NAME"' method not found");
99: return 0;
1.23 paf 100: }
E-mail: