Annotation of parser3/src/main/core.C, revision 1.24
1.18 paf 1: /*
1.24 ! paf 2: $Id: core.C,v 1.23 2001/02/22 09:36:24 paf Exp $
1.18 paf 3: */
4:
1.23 paf 5: #include "pa_request.h"
6: #include "pa_wcontext.h"
7: #include "pa_common.h"
8: #include "pa_vclass.h"
9:
10: #include <stdio.h>
11:
12: void core() {
13: Exception exception;
1.24 ! paf 14: Pool pool(exception);
! 15: Request request(pool);
! 16: request.core();
1.23 paf 17: }
18:
19: void Request::core() {
1.24 ! paf 20: TRY {
1.23 paf 21: String name_RUN(pool()); name_RUN.APPEND_CONST("RUN");
22: char *result=execute_MAIN(construct_class(name_RUN, load_and_compile_RUN()));
23: printf("-----------------\n%s\n----------------\n", result);
1.24 ! paf 24: }
! 25: CATCH(e) {
1.23 paf 26: printf("operator error occured: %s\n", e.comment());
27: const String *type=e.type();
28: if(type) {
29: printf(" type: %s", type->cstr());
30: const String *code=e.code();
31: if(code)
32: printf(", code: %s", code->cstr());
33: printf("\n");
34: }
35: const String *problem_source=e.problem_source();
36: if(problem_source) {
37: const Origin& origin=problem_source->origin();
38: printf(" '%s'\n",
39: problem_source->cstr());
40: if(origin.file)
41: printf(" [%s:%d]",
42: origin.file, origin.line);
43: printf("\n");
44: }
45: }
1.24 ! paf 46: END_CATCH
1.23 paf 47: }
48:
49: Array& Request::load_and_compile_RUN() {
50: char *file="Y:\\parser3\\src\\test.p";
51: char *source=file_read(pool(), file);
52: Array& compiled_methods=COMPILE(source, file);
53: return compiled_methods;
54: }
55:
56: VClass *Request::construct_class(String& name, Array& compiled_methods) {
57: // create new 'name' vclass, add it to request's classes
58: Array immediate_parents(pool());
59: // TODO: immediate_parents=@PARENTS
60:
61: VClass *result=new(pool()) VClass(pool(), name, immediate_parents);
62: classes().put(name, result);
63:
64: for(int i=0; i<compiled_methods.size(); i++) {
65: // TODO: filter out @PARENTS & ?co?
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;
76: wcontext=new(pool()) WContext(pool(), class_RUN);
77:
78: // locate @main code
79: String name_main(pool());
80: name_main.APPEND_CONST(MAIN_METHOD_NAME);
81:
82: Method *method_main=class_RUN->get_method(name_main);
83: if(!method_main)
1.24 ! paf 84: THROW(0,0,
1.23 paf 85: &class_RUN->name(),
86: "no '"MAIN_METHOD_NAME"' method in class");
87:
88: // execute!
89: execute(method_main->code);
90:
91: // return chars
92: return wcontext->get_string()->cstr();
93: }
E-mail: