Annotation of parser3/src/main/execute.C, revision 1.11

1.1       paf         1: /*
1.11    ! paf         2:   $Id: execute.C,v 1.10 2001/02/21 15:26:54 paf Exp $
1.1       paf         3: */
                      4: 
1.8       paf         5: #include "pa_array.h" 
1.1       paf         6: #include "code.h"
1.11    ! paf         7: #include "pa_request.h"
1.1       paf         8: 
                      9: #include <stdio.h>
                     10: 
1.11    ! paf        11: 
1.1       paf        12: char *opcode_name[]={
                     13:        "STRING",
                     14:        "CODE_ARRAY",
                     15:        "WITH_ROOT",    "WITH_SELF",    "WITH_READ",    "WITH_WRITE",
                     16:        "CONSTRUCT",
                     17:        "EXPRESSION_EVAL",      "MODIFY_EVAL",
                     18:        "WRITE",
                     19:        "GET_ELEMENT",  "GET_ELEMENT__WRITE",
                     20:        "CREATE_EWPOOL",        "REDUCE_EWPOOL",
                     21:        "CREATE_RWPOOL",        "REDUCE_RWPOOL",
                     22:        "GET_METHOD_FRAME",
                     23:        "CREATE_JUNCTION",
                     24:        "STORE_PARAM",
                     25:        "CALL"
                     26: };
                     27: 
1.9       paf        28: void dump(int level, const Array& ops) {
                     29:        int size=ops.size();
1.1       paf        30:        for(int i=0; i<size; i++) {
1.10      paf        31:                int code=reinterpret_cast<int>(ops.quick_get(i));
1.1       paf        32:                printf("%*s%s", level*4, "", opcode_name[code]);
                     33: 
                     34:                if(code==OP_STRING) {
1.10      paf        35:                        printf(" \"%s\"", static_cast<const String *>(ops.quick_get(++i))->cstr());
1.1       paf        36:                }
                     37:                printf("\n");
                     38: 
                     39:                if(code==OP_CODE_ARRAY) {
1.10      paf        40:                        const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i));
1.9       paf        41:                        dump(level+1, *local_ops);
1.1       paf        42:                }
                     43:        }
                     44: }
                     45: 
1.11    ! paf        46: void Request::execute(Array& ops) {
        !            47:        int size=ops.size();
        !            48:        for(int i=0; i<size; i++) {
        !            49:                int code=reinterpret_cast<int>(ops.quick_get(i));
        !            50:                printf("%s\n", opcode_name[code]);
        !            51: 
        !            52:                if(code==OP_CODE_ARRAY) {
        !            53:                        const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i));
        !            54:                        //dump(level+1, *local_ops);
        !            55:                }
        !            56: 
        !            57:                switch(code) {
        !            58:                case OP_WITH_WRITE: 
        !            59:                        {
        !            60:                        stack.push(wcontext);
        !            61:                        break;
        !            62:                        }
        !            63: 
        !            64:                case OP_STRING:
        !            65:                        {
        !            66:                        String *string=static_cast<String *>(ops.quick_get(++i));
        !            67:                        stack.push(string);
        !            68:                        break;
        !            69:                        }
        !            70: 
        !            71:                case OP_CONSTRUCT:
        !            72:                        {
        !            73:                        Value *value=static_cast<Value *>(stack.pop());
        !            74:                        String *name=static_cast<String *>(stack.pop());
        !            75:                        Value *ncontext=static_cast<Value *>(stack.pop());
        !            76:                        ncontext->put_element(*name, value);
        !            77:                        break;
        !            78:                        }
        !            79: 
        !            80:                case OP_GET_ELEMENT:
        !            81:                        {
        !            82:                        String *name=static_cast<String *>(stack.pop());
        !            83:                        Value *ncontext=static_cast<Value *>(stack.pop());
        !            84:                        Value *value=ncontext->get_element(*name); // name áûâàåò method, òîãäà âûäà¸ò new junction(ÀÂÒÎÂÛ×ÈÑËßÒÜ=false, root,self,rcontext,wcontext,code)
        !            85:                        // name áûâàåò èìÿ junction, òîãäà èëè îñòàâëÿåò â ïîêîå, èëè âû÷èñëÿåò â çàâèñèìîñòè îò ôëàãà ÀÂÒÎÂÛ×ÈÑËßÒÜ
        !            86:                        stack.push(value);
        !            87:                        break;
        !            88:                        }
        !            89: 
        !            90:                default:
        !            91:                        printf("\tTODO\n");
        !            92:                        break;
        !            93:                }
        !            94:        }
        !            95: 
        !            96:        return;
1.2       paf        97:        puts("---------------------------");
1.1       paf        98:        dump(0, ops);
1.2       paf        99:        puts("---------------------------");
1.1       paf       100: }

E-mail: