|
|
| version 1.2, 2001/02/20 19:21:13 | version 1.26, 2001/02/23 11:53:06 |
|---|---|
| Line 2 | Line 2 |
| $Id$ | $Id$ |
| */ | */ |
| #include "pa_array.h" | #include "pa_array.h" |
| #include "code.h" | #include "code.h" |
| #include "pa_request.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[]={ |
| "STRING", | "STRING", "CODE_ARRAY", |
| "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", |
| "WRITE", | "WRITE", |
| "REPLACE_RESULT", | |
| "GET_ELEMENT", "GET_ELEMENT__WRITE", | "GET_ELEMENT", "GET_ELEMENT__WRITE", |
| "CREATE_EWPOOL", "REDUCE_EWPOOL", | "CREATE_EWPOOL", "REDUCE_EWPOOL", |
| "CREATE_RWPOOL", "REDUCE_RWPOOL", | "CREATE_RWPOOL", "REDUCE_RWPOOL", |
| Line 24 char *opcode_name[]={ | Line 30 char *opcode_name[]={ |
| "CALL" | "CALL" |
| }; | }; |
| void dump(int level, const Array *ops) { | void dump(int level, const Array& ops) { |
| if(!ops) | if(0){ |
| return; | 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->raw_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_STRING) { | |
| printf(" \"%s\"", static_cast<const String *>(ops->raw_get(++i))->cstr()); | if(op.code==OP_STRING) { |
| 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->raw_get(++i)); | const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i)); |
| dump(level=1, local_ops); | dump(level+1, *local_ops); |
| } | } |
| } | } |
| } | } |
| void execute(Pool *pool, const Array *ops) { | void Request::execute(Array& ops) { |
| if(!ops) | if(0) { |
| return; | puts("---------------------------"); |
| dump(0, ops); | |
| puts("---------------------------"); | puts("---------------------------"); |
| dump(0, ops); | } |
| puts("---------------------------"); | |
| 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("%d:%s", stack.top(), opcode_name[op.code]); | |
| if(op.code==OP_CODE_ARRAY) { | |
| const Array *local_ops=reinterpret_cast<const Array *>(ops.quick_get(++i)); | |
| //dump(level+1, *local_ops); | |
| } | |
| switch(op.code) { | |
| case OP_WITH_WRITE: | |
| { | |
| PUSH(wcontext); | |
| break; | |
| } | |
| case OP_WITH_READ: | |
| { | |
| PUSH(rcontext); | |
| break; | |
| } | |
| case OP_WITH_ROOT: | |
| { | |
| PUSH(root); | |
| break; | |
| } | |
| case OP_WITH_SELF: | |
| { | |
| PUSH(self); | |
| break; | |
| } | |
| case OP_STRING: | |
| { | |
| VString *vstring=static_cast<VString *>(ops.quick_get(++i)); | |
| printf(" \"%s\"", vstring->get_string()->cstr()); | |
| PUSH(vstring); | |
| break; | |
| } | |
| case OP_CONSTRUCT: | |
| { | |
| Value *value=POP(); | |
| String& name=POP()->as_string(); | |
| Value *ncontext=POP(); | |
| value->set_name(name); | |
| ncontext->put_element(name, value); | |
| break; | |
| } | |
| case OP_WRITE: | |
| { | |
| Value *value=POP(); | |
| wcontext->write(value); | |
| break; | |
| } | |
| case OP_GET_ELEMENT: | |
| { | |
| Value *value=get_element(); | |
| PUSH(value); | |
| break; | |
| } | |
| case OP_GET_ELEMENT__WRITE: | |
| { | |
| Value *value=get_element(); | |
| wcontext->write(value); | |
| break; | |
| } | |
| case OP_CREATE_EWPOOL: | |
| { | |
| PUSH(wcontext); | |
| wcontext=NEW WContext(pool(), 0 /* empty */); | |
| break; | |
| } | |
| case OP_REDUCE_EWPOOL: | |
| { | |
| Value *value=wcontext->value(); | |
| wcontext=static_cast<WContext *>(POP()); | |
| PUSH(value); | |
| 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: | |
| printf("\tTODO"); | |
| break; | |
| } | |
| printf("\n"); | |
| } | |
| } | } |
| Value *Request::get_element() { | |
| String& name=POP()->as_string(); | |
| Value *ncontext=POP(); | |
| Value *value=ncontext->get_element(name); // name áûâàåò method, òîãäà âûäà¸ò new junction(ÀÂÒÎÂÛ×ÈÑËßÒÜ=false, root,self,rcontext,wcontext,code) | |
| // name áûâàåò èìÿ junction, òîãäà èëè îñòàâëÿåò â ïîêîå, èëè âû÷èñëÿåò â çàâèñèìîñòè îò ôëàãà ÀÂÒÎÂÛ×ÈÑËßÒÜ | |
| if(!value) { | |
| value=NEW VUnknown(pool()); | |
| value->set_name(name); | |
| } | |
| return value; | |
| } | |