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