Annotation of parser3/src/main/execute.C, revision 1.17
1.1 paf 1: /*
1.17 ! paf 2: $Id: execute.C,v 1.16 2001/02/22 12:43:55 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.16 paf 52: if(0) {
1.12 paf 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));
1.17 ! paf 61: printf("%d:%s", stack.top(), opcode_name[code]);
1.11 paf 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));
1.16 paf 83: printf(" \"%s\"", string->cstr());
1.13 paf 84: stack.push(string);
85: break;
1.11 paf 86: }
1.13 paf 87:
1.15 paf 88: case OP_VSTRING:
89: {
90: Value *value=static_cast<Value *>(ops.quick_get(++i));
1.16 paf 91: printf(" \"%s\"", value->get_string()->cstr());
1.15 paf 92: stack.push(value);
93: break;
94: }
95:
1.11 paf 96: case OP_CONSTRUCT:
97: {
1.13 paf 98: Value *value=static_cast<Value *>(stack.pop());
99: String *name=static_cast<String *>(stack.pop());
100: Value *ncontext=static_cast<Value *>(stack.pop());
101: ncontext->put_element(*name, value);
102: break;
1.11 paf 103: }
1.13 paf 104:
1.14 paf 105: case OP_WRITE_STRING:
106: {
107: String *string=static_cast<String *>(stack.pop());
108: wcontext->write(string);
109: break;
110: }
111:
112: case OP_WRITE_VALUE:
1.13 paf 113: {
114: Value *value=static_cast<Value *>(stack.pop());
1.14 paf 115: wcontext->write(value);
1.13 paf 116: break;
1.14 paf 117: }
1.13 paf 118:
1.15 paf 119: case OP_GET_ELEMENT:
1.11 paf 120: {
1.17 ! paf 121: Value *value=get_element();
! 122: stack.push(value);
! 123: break;
! 124: }
! 125:
! 126: case OP_GET_ELEMENT__WRITE_VALUE:
! 127: {
! 128: Value *value=get_element();
! 129: wcontext->write(value);
! 130: break;
! 131: }
! 132:
! 133: case OP_CREATE_EWPOOL:
! 134: {
! 135: stack.push(wcontext);
! 136: wcontext=NEW WContext(pool(), 0 /* empty */);
! 137: break;
! 138: }
! 139: case OP_REDUCE_EWPOOL:
! 140: {
! 141: Value *value=wcontext->value();
! 142: wcontext=static_cast<WContext *>(stack.pop());
1.13 paf 143: stack.push(value);
144: break;
1.15 paf 145: }
1.13 paf 146:
1.11 paf 147: default:
1.16 paf 148: printf("\tTODO");
1.11 paf 149: break;
150: }
1.16 paf 151: printf("\n");
1.11 paf 152: }
1.1 paf 153: }
1.17 ! paf 154:
! 155: Value *Request::get_element() {
! 156: String *name=static_cast<String *>(stack.pop());
! 157: Value *ncontext=static_cast<Value *>(stack.pop());
! 158: Value *value=ncontext->get_element(*name); // name áûâàåò method, òîãäà âûäà¸ò new junction(ÀÂÒÎÂÛ×ÈÑËßÒÜ=false, root,self,rcontext,wcontext,code)
! 159: // name áûâàåò èìÿ junction, òîãäà èëè îñòàâëÿåò â ïîêîå, èëè âû÷èñëÿåò â çàâèñèìîñòè îò ôëàãà ÀÂÒÎÂÛ×ÈÑËßÒÜ
! 160: return value;
! 161: }
E-mail: