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

1.1       paf         1: /*
1.15    ! paf         2:   $Id: execute.C,v 1.14 2001/02/22 08:16:31 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.15    ! paf         8: #include "pa_vstring.h"
1.1       paf         9: 
                     10: #include <stdio.h>
                     11: 
1.11      paf        12: 
1.1       paf        13: char *opcode_name[]={
1.15    ! paf        14:        "STRING",  "VSTRING",  "CODE_ARRAY",
1.1       paf        15:        "WITH_ROOT",    "WITH_SELF",    "WITH_READ",    "WITH_WRITE",
                     16:        "CONSTRUCT",
                     17:        "EXPRESSION_EVAL",      "MODIFY_EVAL",
1.14      paf        18:        "WRITE_STRING",  "WRITE_VALUE",
                     19:        "GET_ELEMENT",  "GET_ELEMENT__WRITE_VALUE",
1.1       paf        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.15    ! paf        35:                        String *string=static_cast<String *>(ops.quick_get(++i));
1.12      paf        36:                        printf(" \"%s\"", string->cstr());
1.1       paf        37:                }
1.15    ! paf        38:                if(code==OP_VSTRING) {
        !            39:                        Value *value=static_cast<Value *>(ops.quick_get(++i));
        !            40:                        printf(" \"%s\"", value->get_string()->cstr());
        !            41:                }
1.1       paf        42:                printf("\n");
                     43: 
                     44:                if(code==OP_CODE_ARRAY) {
1.10      paf        45:                        const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i));
1.9       paf        46:                        dump(level+1, *local_ops);
1.1       paf        47:                }
                     48:        }
                     49: }
                     50: 
1.11      paf        51: void Request::execute(Array& ops) {
1.12      paf        52:        if(1) {
                     53:                puts("---------------------------");
                     54:                dump(0, ops);
                     55:                puts("---------------------------");
                     56:        }
                     57: 
1.11      paf        58:        int size=ops.size();
                     59:        for(int i=0; i<size; i++) {
                     60:                int code=reinterpret_cast<int>(ops.quick_get(i));
                     61:                printf("%s\n", opcode_name[code]);
                     62: 
                     63:                if(code==OP_CODE_ARRAY) {
                     64:                        const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i));
                     65:                        //dump(level+1, *local_ops);
                     66:                }
1.13      paf        67:                
1.11      paf        68:                switch(code) {
                     69:                case OP_WITH_WRITE: 
                     70:                        {
1.13      paf        71:                                stack.push(wcontext);
                     72:                                break;
1.11      paf        73:                        }
1.15    ! paf        74:                case OP_WITH_READ: 
        !            75:                        {
        !            76:                                stack.push(rcontext);
        !            77:                                break;
        !            78:                        }
1.13      paf        79:                        
1.11      paf        80:                case OP_STRING:
                     81:                        {
1.13      paf        82:                                String *string=static_cast<String *>(ops.quick_get(++i));
                     83:                                stack.push(string);
                     84:                                break;
1.11      paf        85:                        }
1.13      paf        86:                        
1.15    ! paf        87:                case OP_VSTRING:
        !            88:                        {
        !            89:                                Value *value=static_cast<Value *>(ops.quick_get(++i));
        !            90:                                stack.push(value);
        !            91:                                break;
        !            92:                        }
        !            93:                        
1.11      paf        94:                case OP_CONSTRUCT:
                     95:                        {
1.13      paf        96:                                Value *value=static_cast<Value *>(stack.pop());
                     97:                                String *name=static_cast<String *>(stack.pop());
                     98:                                Value *ncontext=static_cast<Value *>(stack.pop());
                     99:                                ncontext->put_element(*name, value);
                    100:                                break;
1.11      paf       101:                        }
1.13      paf       102:                        
1.14      paf       103:                case OP_WRITE_STRING:
                    104:                        {
                    105:                                String *string=static_cast<String *>(stack.pop());
                    106:                                wcontext->write(string);
                    107:                                break;
                    108:                        }
                    109:                        
                    110:                case OP_WRITE_VALUE:
1.13      paf       111:                        {
                    112:                                Value *value=static_cast<Value *>(stack.pop());
1.14      paf       113:                                wcontext->write(value);
1.13      paf       114:                                break;
1.14      paf       115:                        }
1.13      paf       116:                        
1.15    ! paf       117:                case OP_GET_ELEMENT:
1.11      paf       118:                        {
1.13      paf       119:                                String *name=static_cast<String *>(stack.pop());
                    120:                                Value *ncontext=static_cast<Value *>(stack.pop());
                    121:                                Value *value=ncontext->get_element(*name); // name áûâàåò method, òîãäà âûäà¸ò new junction(ÀÂÒÎÂÛ×ÈÑËßÒÜ=false, root,self,rcontext,wcontext,code)
                    122:                                // name áûâàåò èìÿ junction, òîãäà èëè îñòàâëÿåò â ïîêîå, èëè âû÷èñëÿåò â çàâèñèìîñòè îò ôëàãà ÀÂÒÎÂÛ×ÈÑËßÒÜ
                    123:                                stack.push(value);
                    124:                                break;
1.15    ! paf       125:                        }
1.13      paf       126:                        
1.11      paf       127:                default:
                    128:                        printf("\tTODO\n");
                    129:                        break;
                    130:                }
                    131:        }
1.1       paf       132: }

E-mail: