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

1.18      paf         1: /*
1.25    ! paf         2: $Id: core.C,v 1.24 2001/02/22 10:43:45 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() {
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]",
                     41:                                origin.file, origin.line);
                     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.23      paf        61:        classes().put(name, result);
                     62:                
                     63:        for(int i=0; i<compiled_methods.size(); i++) {
                     64:                // TODO: filter out @PARENTS & ?co?
                     65:                Method &method=*static_cast<Method *>(compiled_methods.quick_get(i));
                     66:                result->add_method(method.name, method);
                     67:        }
                     68: 
                     69:        return result;
                     70: }
                     71: 
                     72: char *Request::execute_MAIN(VClass *class_RUN) {
                     73:        // initialize contexts
                     74:        root=self=rcontext=class_RUN;
1.25    ! paf        75:        wcontext=NEW WContext(pool(), class_RUN);
1.23      paf        76: 
                     77:        // locate @main code
                     78:        String name_main(pool());
                     79:        name_main.APPEND_CONST(MAIN_METHOD_NAME);
                     80: 
                     81:        Method *method_main=class_RUN->get_method(name_main);
                     82:        if(!method_main)
1.24      paf        83:                THROW(0,0,
1.23      paf        84:                        &class_RUN->name(),
                     85:                        "no '"MAIN_METHOD_NAME"' method in class");
                     86: 
                     87:        // execute!     
                     88:        execute(method_main->code);
                     89: 
                     90:        // return chars
                     91:        return wcontext->get_string()->cstr();
                     92: }

E-mail: