Annotation of parser3/src/main/pa_request.C, revision 1.1
1.1 ! paf 1: /*
! 2: $Id: core.C,v 1.21 2001/02/20 18:45:52 paf Exp $
! 3: */
! 4:
! 5: #include "pa_request.h"
! 6: #include "compile.h"
! 7: #include "pa_context.h"
! 8:
! 9: void Request::core() {
! 10: Exception exception;
! 11: Local_request_exception subst(*this, exception);
! 12: if(EXCEPTION_TRY(exception())) {
! 13: String name_RUN(pool()); name_RUN.APPEND_CONST("RUN");
! 14: execute_MAIN(construct_class(name_RUN, load_and_compile_RUN())));
! 15: } else {
! 16: Exception& e=exception();
! 17: printf("operator error occured: %s\n", e.comment());
! 18: const String *type=e.type();
! 19: if(type) {
! 20: printf(" type: %s", type->cstr());
! 21: const String *code=e.code();
! 22: if(code)
! 23: printf(", code: %s", code->cstr());
! 24: printf("\n");
! 25: }
! 26: const String *problem_source=e.problem_source();
! 27: if(problem_source) {
! 28: const Origin& origin=problem_source->origin();
! 29: printf(" '%s'\n",
! 30: problem_source->cstr());
! 31: if(origin.file)
! 32: printf(" [%s:%d]",
! 33: origin.file, origin.line);
! 34: printf("\n");
! 35: }
! 36: }
! 37: }
! 38:
! 39: Array& Request::load_and_compile_RUN() {
! 40: char *file="c:\\temp\\test.p";
! 41: char *source=file_read(pool(), file);
! 42: Array& compiled_methods=COMPILE(request, source, file);
! 43: return compiled_methods;
! 44: }
! 45:
! 46: VClass *Request::construct_class(String& name, Array& compiled_methods) {
! 47: // create new 'name' vclass, add it to request's classes
! 48: Array immediate_parents(pool);
! 49: // TODO: immediate_parents=@PARENTS
! 50:
! 51: VClass *vclass=new(pool) VClass(pool, name, immediate_parents);
! 52: request.classes().put(name, vclass);
! 53:
! 54: for(int i=0; i<compiled_methods.size(); i++) {
! 55: // TODO: filter out @PARENTS & ?co?
! 56: Method &method=*static_cast<Method *>(compiled_methods.quick_get(i));
! 57: vclass->add_method(method.name, method);
! 58: }
! 59: }
! 60:
! 61: char *Request::execute_MAIN(Value *class_RUN) {
! 62: // initialize contexts
! 63: root=self=rcontext=class_RUN;
! 64: wcontext=new(pool()) WContext(pool());
! 65:
! 66: // locate @main code
! 67: String name_main(pool);
! 68: name_main.APPEND_CONST(MAIN_METHOD_NAME);
! 69:
! 70: Method *method_main=class_RUN->get_method(name_main);
! 71: if(!method_main)
! 72: request.exception().raise(0,0,
! 73: &class_RUN->name(),
! 74: "no 'main' method in class");
! 75:
! 76: // execute!
! 77: execute(method_main->code);
! 78:
! 79: // return chars
! 80: return wcontext.get_string()->cstr();
! 81: }
E-mail: