Annotation of parser3/src/main/core.C, revision 1.30
1.18 paf 1: /*
1.30 ! paf 2: $Id: core.C,v 1.29 2001/02/23 17:12:58 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.23 paf 20: String name_RUN(pool()); name_RUN.APPEND_CONST("RUN");
21: char *result=execute_MAIN(construct_class(name_RUN, load_and_compile_RUN()));
22: printf("-----------------\n%s\n----------------\n", result);
1.24 paf 23: }
24: CATCH(e) {
1.25 paf 25: printf("error occured: %s\n", e.comment());
1.23 paf 26: const String *type=e.type();
27: if(type) {
28: printf(" type: %s", type->cstr());
29: const String *code=e.code();
30: if(code)
31: printf(", code: %s", code->cstr());
32: printf("\n");
33: }
34: const String *problem_source=e.problem_source();
35: if(problem_source) {
36: const Origin& origin=problem_source->origin();
37: printf(" '%s'\n",
38: problem_source->cstr());
39: if(origin.file)
40: printf(" [%s:%d]",
1.27 paf 41: origin.file, 1+origin.line);
1.23 paf 42: printf("\n");
43: }
44: }
1.24 paf 45: END_CATCH
1.23 paf 46: }
47:
48: Array& Request::load_and_compile_RUN() {
49: char *file="Y:\\parser3\\src\\test.p";
50: char *source=file_read(pool(), file);
51: Array& compiled_methods=COMPILE(source, file);
52: return compiled_methods;
53: }
54:
55: VClass *Request::construct_class(String& name, Array& compiled_methods) {
56: // create new 'name' vclass, add it to request's classes
57: Array immediate_parents(pool());
58: // TODO: immediate_parents=@PARENTS
59:
1.25 paf 60: VClass *result=NEW VClass(pool(), name, immediate_parents);
1.28 paf 61: result->set_name(name);
1.23 paf 62: classes().put(name, result);
63:
64: for(int i=0; i<compiled_methods.size(); i++) {
1.26 paf 65: // TODO: filter out @PARENTS & @CLASS & ?co?
1.23 paf 66: Method &method=*static_cast<Method *>(compiled_methods.quick_get(i));
67: result->add_method(method.name, method);
68: }
69:
70: return result;
71: }
72:
73: char *Request::execute_MAIN(VClass *class_RUN) {
74: // initialize contexts
75: root=self=rcontext=class_RUN;
1.29 paf 76: wcontext=NEW WWrapper(pool(), class_RUN);
1.23 paf 77:
78: // locate @main code
79: String name_main(pool());
80: name_main.APPEND_CONST(MAIN_METHOD_NAME);
81:
1.30 ! paf 82: Value *value_main=class_RUN->get_element(name_main);
! 83: if(!value_main)
! 84: THROW(0,0,
! 85: &class_RUN->name(),
! 86: "no '"MAIN_METHOD_NAME"' method in class");
! 87:
! 88: Junction *junction_main=value_main->get_junction();
! 89: const Method *method_main=junction_main->method;
! 90:
1.23 paf 91: if(!method_main)
1.24 paf 92: THROW(0,0,
1.23 paf 93: &class_RUN->name(),
1.30 ! paf 94: "'"MAIN_METHOD_NAME"' in class is not a method");
1.23 paf 95:
96: // execute!
97: execute(method_main->code);
98:
99: // return chars
100: return wcontext->get_string()->cstr();
101: }
E-mail: