|
|
| version 1.18, 2001/02/22 13:52:26 | version 1.26, 2001/02/23 11:53:06 |
|---|---|
| Line 6 | Line 6 |
| #include "code.h" | #include "code.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_vstring.h" | #include "pa_vstring.h" |
| #include "pa_vhash.h" | |
| #include "pa_vunknown.h" | |
| #include <stdio.h> | #include <stdio.h> |
| #define PUSH(value) stack.push(value) | |
| #define POP() static_cast<Value *>(stack.pop()) | |
| char *opcode_name[]={ | char *opcode_name[]={ |
| "VALUE", "CODE_ARRAY", | "STRING", "CODE_ARRAY", |
| "WITH_ROOT", "WITH_SELF", "WITH_READ", "WITH_WRITE", | "WITH_ROOT", "WITH_SELF", "WITH_READ", "WITH_WRITE", |
| "CONSTRUCT", | "CONSTRUCT", |
| "EXPRESSION_EVAL", "MODIFY_EVAL", | "EXPRESSION_EVAL", "MODIFY_EVAL", |
| Line 26 char *opcode_name[]={ | Line 31 char *opcode_name[]={ |
| }; | }; |
| void dump(int level, const Array& ops) { | void dump(int level, const Array& ops) { |
| if(0){ | |
| int size=ops.size(); | |
| printf("size=%d\n", size); | |
| for(int i=0; i<size; i++) { | |
| Operation op; | |
| op.cast=ops.quick_get(i); | |
| printf("%8X\n", op.cast); | |
| } | |
| } | |
| int size=ops.size(); | int size=ops.size(); |
| printf("size=%d\n", size); | |
| for(int i=0; i<size; i++) { | for(int i=0; i<size; i++) { |
| int code=reinterpret_cast<int>(ops.quick_get(i)); | Operation op; |
| printf("%*s%s", level*4, "", opcode_name[code]); | op.cast=ops.quick_get(i); |
| printf("%*s%s", level*4, "", opcode_name[op.code]); | |
| if(code==OP_VALUE) { | |
| Value *value=static_cast<Value *>(ops.quick_get(++i)); | if(op.code==OP_STRING) { |
| printf(" \"%s\"", value->get_string()->cstr()); | VString *vstring=static_cast<VString *>(ops.quick_get(++i)); |
| printf(" \"%s\"", vstring->get_string()->cstr()); | |
| } | } |
| printf("\n"); | printf("\n"); |
| if(code==OP_CODE_ARRAY) { | if(op.code==OP_CODE_ARRAY) { |
| const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i)); | const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i)); |
| dump(level+1, *local_ops); | dump(level+1, *local_ops); |
| } | } |
| Line 52 void Request::execute(Array& ops) { | Line 69 void Request::execute(Array& ops) { |
| } | } |
| int size=ops.size(); | int size=ops.size(); |
| printf("size=%d\n", size); | |
| for(int i=0; i<size; i++) { | for(int i=0; i<size; i++) { |
| int code=reinterpret_cast<int>(ops.quick_get(i)); | Operation op; |
| printf("%d:%s", stack.top(), opcode_name[code]); | op.cast=ops.quick_get(i); |
| printf("%d:%s", stack.top(), opcode_name[op.code]); | |
| if(code==OP_CODE_ARRAY) { | if(op.code==OP_CODE_ARRAY) { |
| const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i)); | const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i)); |
| //dump(level+1, *local_ops); | //dump(level+1, *local_ops); |
| } | } |
| switch(code) { | switch(op.code) { |
| case OP_WITH_WRITE: | case OP_WITH_WRITE: |
| { | { |
| stack.push(wcontext); | PUSH(wcontext); |
| break; | break; |
| } | } |
| case OP_WITH_READ: | case OP_WITH_READ: |
| { | { |
| stack.push(rcontext); | PUSH(rcontext); |
| break; | |
| } | |
| case OP_WITH_ROOT: | |
| { | |
| PUSH(root); | |
| break; | |
| } | |
| case OP_WITH_SELF: | |
| { | |
| PUSH(self); | |
| break; | break; |
| } | } |
| case OP_VALUE: | case OP_STRING: |
| { | { |
| Value *value=static_cast<Value *>(ops.quick_get(++i)); | VString *vstring=static_cast<VString *>(ops.quick_get(++i)); |
| printf(" \"%s\"", value->get_string()->cstr()); | printf(" \"%s\"", vstring->get_string()->cstr()); |
| stack.push(value); | PUSH(vstring); |
| break; | break; |
| } | } |
| case OP_CONSTRUCT: | case OP_CONSTRUCT: |
| { | { |
| Value *value=static_cast<Value *>(stack.pop()); | Value *value=POP(); |
| VString *name=static_cast<VString *>(stack.pop()); | String& name=POP()->as_string(); |
| Value *ncontext=static_cast<Value *>(stack.pop()); | Value *ncontext=POP(); |
| ncontext->put_element(*name, value); | value->set_name(name); |
| ncontext->put_element(name, value); | |
| break; | break; |
| } | } |
| case OP_WRITE: | case OP_WRITE: |
| { | { |
| Value *value=static_cast<Value *>(stack.pop()); | Value *value=POP(); |
| wcontext->write(value); | wcontext->write(value); |
| break; | break; |
| } | } |
| Line 100 void Request::execute(Array& ops) { | Line 130 void Request::execute(Array& ops) { |
| case OP_GET_ELEMENT: | case OP_GET_ELEMENT: |
| { | { |
| Value *value=get_element(); | Value *value=get_element(); |
| stack.push(value); | PUSH(value); |
| break; | break; |
| } | } |
| Line 113 void Request::execute(Array& ops) { | Line 143 void Request::execute(Array& ops) { |
| case OP_CREATE_EWPOOL: | case OP_CREATE_EWPOOL: |
| { | { |
| stack.push(wcontext); | PUSH(wcontext); |
| wcontext=NEW WContext(pool(), 0 /* empty */); | wcontext=NEW WContext(pool(), 0 /* empty */); |
| break; | break; |
| } | } |
| case OP_REDUCE_EWPOOL: | case OP_REDUCE_EWPOOL: |
| { | { |
| Value *value=wcontext->value(); | Value *value=wcontext->value(); |
| wcontext=static_cast<WContext *>(stack.pop()); | wcontext=static_cast<WContext *>(POP()); |
| stack.push(value); | PUSH(value); |
| break; | break; |
| } | } |
| case OP_CREATE_RWPOOL: | |
| { | |
| Value *ncontext=POP(); | |
| PUSH(rcontext); | |
| rcontext=ncontext; | |
| PUSH(wcontext); | |
| wcontext=NEW WContext(pool(), ncontext); | |
| break; | |
| } | |
| case OP_REDUCE_RWPOOL: | |
| { | |
| String *string=wcontext->get_string(); | |
| Value *value=NEW VString(string); | |
| wcontext=static_cast<WContext *>(POP()); | |
| rcontext=POP(); | |
| PUSH(value); | |
| break; | |
| } | |
| default: | default: |
| printf("\tTODO"); | printf("\tTODO"); |
| break; | break; |
| Line 134 void Request::execute(Array& ops) { | Line 183 void Request::execute(Array& ops) { |
| } | } |
| Value *Request::get_element() { | Value *Request::get_element() { |
| VString *name=static_cast<VString *>(stack.pop()); | String& name=POP()->as_string(); |
| Value *ncontext=static_cast<Value *>(stack.pop()); | Value *ncontext=POP(); |
| Value *value=ncontext->get_element(*name); // name áûâàåò method, òîãäà âûäà¸ò new junction(ÀÂÒÎÂÛ×ÈÑËßÒÜ=false, root,self,rcontext,wcontext,code) | Value *value=ncontext->get_element(name); // name áûâàåò method, òîãäà âûäà¸ò new junction(ÀÂÒÎÂÛ×ÈÑËßÒÜ=false, root,self,rcontext,wcontext,code) |
| // name áûâàåò èìÿ junction, òîãäà èëè îñòàâëÿåò â ïîêîå, èëè âû÷èñëÿåò â çàâèñèìîñòè îò ôëàãà ÀÂÒÎÂÛ×ÈÑËßÒÜ | // name áûâàåò èìÿ junction, òîãäà èëè îñòàâëÿåò â ïîêîå, èëè âû÷èñëÿåò â çàâèñèìîñòè îò ôëàãà ÀÂÒÎÂÛ×ÈÑËßÒÜ |
| if(!value) { | |
| value=NEW VUnknown(pool()); | |
| value->set_name(name); | |
| } | |
| return value; | return value; |
| } | } |