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

1.18      paf         1: /*
1.36    ! paf         2: $Id: core.C,v 1.35 2001/02/24 15:26:03 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.35      paf        20:                char *file="Y:\\parser3\\src\\test.p";
                     21:                String RUN(pool()); RUN.APPEND_CONST(NAME_RUN);
                     22:                use(file, &RUN);
                     23: 
                     24:                char *result=execute_MAIN();
1.34      paf        25:                printf("result-----------------\n%sEOF----------------\n", result);
1.24      paf        26:        } 
                     27:        CATCH(e) {
1.31      paf        28:                printf("\nERROR: ");
                     29:                const String *problem_source=e.problem_source();
                     30:                if(problem_source) {
                     31:                        const Origin& origin=problem_source->origin();
                     32:                        if(origin.file)
                     33:                                printf("%s(%d): ",
                     34:                                origin.file, 1+origin.line);
1.32      paf        35:                        printf("'%s' ", 
1.31      paf        36:                                problem_source->cstr());
                     37:                }
                     38:                printf("%s", e.comment());
1.23      paf        39:                const String *type=e.type();
                     40:                if(type) {
                     41:                        printf("  type: %s", type->cstr());
                     42:                        const String *code=e.code();
                     43:                        if(code)
                     44:                                printf(", code: %s", code->cstr());
                     45:                }
1.31      paf        46:                printf("\n");
1.23      paf        47:        }
1.24      paf        48:        END_CATCH
1.23      paf        49: }
                     50: 
1.35      paf        51: void Request::use(char *file, String *name) {
1.23      paf        52:        char *source=file_read(pool(), file);
1.35      paf        53:        VClass& vclass=COMPILE(source, file);
                     54:        if(name) // they forced some name?
                     55:                vclass.set_name(*name);
                     56:        name=vclass.name();
                     57:        if(!name)
                     58:                return; //TODO: add operators 
                     59:        classes_array()+=&vclass;
                     60:        classes().put(*name, &vclass);
1.23      paf        61: }
                     62: 
1.35      paf        63: char *Request::execute_MAIN() {
                     64:        // locate class with @main & it's code
1.23      paf        65:        String name_main(pool());
                     66:        name_main.APPEND_CONST(MAIN_METHOD_NAME);
                     67: 
1.35      paf        68:        // looking for latest known @main
                     69:        for(int i=classes_array().size(); --i>=0;) {
                     70:                VClass *vclass=static_cast<VClass *>(classes_array().get(i));
                     71:                Value *main=vclass->get_element(name_main);
                     72:                if(main) { // found some 'main' element
                     73:                        Junction *junction=main->get_junction();
1.36    ! paf        74:                        if(junction) {// it even has junction!
        !            75:                                const Method *method=junction->method;
        !            76:                                if(method) { // and junction is method-junction! call it
        !            77:                                        // initialize contexts
        !            78:                                        self=root=rcontext=vclass;
        !            79:                                        wcontext=NEW WWrapper(pool(), vclass);
        !            80:                                        
        !            81:                                        // execute!     
        !            82:                                        execute(method->code);
        !            83:                                        
        !            84:                                        // return chars
        !            85:                                        return wcontext->get_string()->cstr();
        !            86:                                }
1.35      paf        87:                        }
                     88:                }
                     89:        }
                     90:        
                     91:        THROW(0,0,
                     92:                0, 
                     93:                "'"MAIN_METHOD_NAME"' method not found");
                     94:        return 0;
1.23      paf        95: }

E-mail: