Annotation of parser3/src/main/core.C, revision 1.23

1.18      paf         1: /*
1.23    ! paf         2: $Id: pa_request.C,v 1.1 2001/02/21 16:12:11 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;
        !            14:        if(EXCEPTION_TRY(exception)) {
        !            15:                Pool pool(exception);
        !            16:                Request request(pool);
        !            17:                request.core();
        !            18:        } else {
        !            19:                Exception& e=exception;
        !            20:                printf("fatal exception occured: %s\n", e.comment());
        !            21:                const String *type=e.type();
        !            22:                if(type) {
        !            23:                        printf("  type: %s", type->cstr());
        !            24:                        const String *code=e.code();
        !            25:                        if(code)
        !            26:                                printf(", code: %s", code->cstr());
        !            27:                        printf("\n");
        !            28:                }
        !            29:                const String *problem_source=e.problem_source();
        !            30:                if(problem_source) {
        !            31:                        const Origin& origin=problem_source->origin();
        !            32:                        printf("  '%s'\n", 
        !            33:                                problem_source->cstr());
        !            34:                        if(origin.file)
        !            35:                                printf(" [%s:%d]",
        !            36:                                origin.file, origin.line);
        !            37:                        printf("\n");
        !            38:                }
        !            39:        }
        !            40: }
        !            41: 
        !            42: void Request::core() {
        !            43:        Exception local_exception;
        !            44:        Local_request_exception subst(*this, local_exception);
        !            45:        if(EXCEPTION_TRY(local_exception)) {
        !            46:                String name_RUN(pool()); name_RUN.APPEND_CONST("RUN");
        !            47:                char *result=execute_MAIN(construct_class(name_RUN, load_and_compile_RUN()));
        !            48:                printf("-----------------\n%s\n----------------\n", result);
        !            49:        } else {
        !            50:                Exception& e=exception();
        !            51:                printf("operator error occured: %s\n", e.comment());
        !            52:                const String *type=e.type();
        !            53:                if(type) {
        !            54:                        printf("  type: %s", type->cstr());
        !            55:                        const String *code=e.code();
        !            56:                        if(code)
        !            57:                                printf(", code: %s", code->cstr());
        !            58:                        printf("\n");
        !            59:                }
        !            60:                const String *problem_source=e.problem_source();
        !            61:                if(problem_source) {
        !            62:                        const Origin& origin=problem_source->origin();
        !            63:                        printf("  '%s'\n", 
        !            64:                                problem_source->cstr());
        !            65:                        if(origin.file)
        !            66:                                printf(" [%s:%d]",
        !            67:                                origin.file, origin.line);
        !            68:                        printf("\n");
        !            69:                }
        !            70:        }
        !            71: }
        !            72: 
        !            73: Array& Request::load_and_compile_RUN() {
        !            74:        char *file="Y:\\parser3\\src\\test.p";
        !            75:        char *source=file_read(pool(), file);
        !            76:        Array& compiled_methods=COMPILE(source, file);
        !            77:        return compiled_methods;
        !            78: }
        !            79: 
        !            80: VClass *Request::construct_class(String& name, Array& compiled_methods) {
        !            81:        // create new 'name' vclass, add it to request's classes
        !            82:        Array immediate_parents(pool());
        !            83:        // TODO: immediate_parents=@PARENTS
        !            84: 
        !            85:        VClass *result=new(pool()) VClass(pool(), name, immediate_parents);
        !            86:        classes().put(name, result);
        !            87:                
        !            88:        for(int i=0; i<compiled_methods.size(); i++) {
        !            89:                // TODO: filter out @PARENTS & ?co?
        !            90:                Method &method=*static_cast<Method *>(compiled_methods.quick_get(i));
        !            91:                result->add_method(method.name, method);
        !            92:        }
        !            93: 
        !            94:        return result;
        !            95: }
        !            96: 
        !            97: char *Request::execute_MAIN(VClass *class_RUN) {
        !            98:        // initialize contexts
        !            99:        root=self=rcontext=class_RUN;
        !           100:        wcontext=new(pool()) WContext(pool(), class_RUN);
        !           101: 
        !           102:        // locate @main code
        !           103:        String name_main(pool());
        !           104:        name_main.APPEND_CONST(MAIN_METHOD_NAME);
        !           105: 
        !           106:        Method *method_main=class_RUN->get_method(name_main);
        !           107:        if(!method_main)
        !           108:                exception().raise(0,0,
        !           109:                        &class_RUN->name(),
        !           110:                        "no '"MAIN_METHOD_NAME"' method in class");
        !           111: 
        !           112:        // execute!     
        !           113:        execute(method_main->code);
        !           114: 
        !           115:        // return chars
        !           116:        return wcontext->get_string()->cstr();
        !           117: }

E-mail: