|
|
| version 1.83, 2001/03/10 12:12:51 | version 1.91, 2001/03/11 21:41:04 |
|---|---|
| Line 1 | Line 1 |
| /* | /* |
| $Id$ | Parser |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | |
| $Id$ | |
| */ | */ |
| #include "pa_array.h" | #include "pa_array.h" |
| Line 29 char *opcode_name[]={ | Line 33 char *opcode_name[]={ |
| "WITH_SELF", "WITH_ROOT", "WITH_READ", "WITH_WRITE", | "WITH_SELF", "WITH_ROOT", "WITH_READ", "WITH_WRITE", |
| "GET_CLASS", | "GET_CLASS", |
| "CONSTRUCT_VALUE", "CONSTRUCT_DOUBLE", | "CONSTRUCT_VALUE", "CONSTRUCT_DOUBLE", |
| "WRITE", | "WRITE", "STRING__WRITE", |
| "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 66 void dump(int level, const Array& ops) { | Line 70 void dump(int level, const Array& ops) { |
| op.cast=ops.quick_get(i); | op.cast=ops.quick_get(i); |
| fprintf(stderr, "%*s%s", level*4, "", opcode_name[op.code]); | fprintf(stderr, "%*s%s", level*4, "", opcode_name[op.code]); |
| if(op.code==OP_VALUE) { | if(op.code==OP_VALUE || op.code==OP_STRING__WRITE) { |
| Value *value=static_cast<Value *>(ops.quick_get(++i)); | Value *value=static_cast<Value *>(ops.quick_get(++i)); |
| fprintf(stderr, " \"%s\" %s", value->get_string()->cstr(), value->type()); | fprintf(stderr, " \"%s\" %s", value->get_string()->cstr(), value->type()); |
| } | } |
| Line 116 void Request::execute(const Array& ops) | Line 120 void Request::execute(const Array& ops) |
| root, frame, frame, local_ops); | root, frame, frame, local_ops); |
| Value *value=NEW VJunction(j); | Value *value=NEW VJunction(j); |
| ///value->set_name(frame->name()); | |
| // store param | // store param |
| frame->store_param(value); | frame->store_param(value); |
| Line 182 void Request::execute(const Array& ops) | Line 185 void Request::execute(const Array& ops) |
| write(*value); | write(*value); |
| break; | break; |
| } | } |
| case OP_STRING__WRITE: | |
| { | |
| VString *vstring=static_cast<VString *>(ops.quick_get(++i)); | |
| fprintf(stderr, " \"%s\"", vstring->value().cstr()); | |
| write(vstring->value()); | |
| break; | |
| } | |
| case OP_GET_ELEMENT: | case OP_GET_ELEMENT: |
| { | { |
| Line 562 Value *Request::get_element() { | Line 572 Value *Request::get_element() { |
| Value *value=ncontext->get_element(name); | Value *value=ncontext->get_element(name); |
| if(value) | if(value) |
| value=&autocalc(*value); // autocalc possible code-junction | value=&autocalc(*value, &name); // autocalc possible code-junction |
| else { | else { |
| value=NEW VUnknown(pool()); | value=NEW VUnknown(pool()); |
| value->set_name(name); | value->set_name(name); |
| Line 571 Value *Request::get_element() { | Line 581 Value *Request::get_element() { |
| return value; | return value; |
| } | } |
| Value& Request::autocalc(Value& value, bool make_string) { | Value& Request::autocalc(Value& value, const String *name, bool intercept_string) { |
| // intercept_string: | |
| // true: | |
| // they want result=string value, | |
| // possible object result goes to wcontext | |
| // false: | |
| // they want any result[string|object] | |
| // nothing goes to wcontext. | |
| // used in (expression) params evaluation | |
| Value *result; | |
| Junction *junction=value.get_junction(); | Junction *junction=value.get_junction(); |
| if(junction && junction->code) { // is it a code-junction? | if(junction && junction->code) { // is it a code-junction? |
| // autocalc it | // autocalc it |
| Line 582 Value& Request::autocalc(Value& value, b | Line 602 Value& Request::autocalc(Value& value, b |
| PUSH(wcontext); | PUSH(wcontext); |
| WContext *frame; | WContext *frame; |
| if(make_string) { | if(intercept_string) { |
| // almost plain wwrapper about junction wcontext, | // almost plain wwrapper about junction wcontext, |
| // BUT intercepts string writes | // BUT intercepts string writes |
| frame=NEW VCodeFrame(pool(), *junction->wcontext); | frame=NEW VCodeFrame(pool(), *junction->wcontext); |
| Line 596 Value& Request::autocalc(Value& value, b | Line 616 Value& Request::autocalc(Value& value, b |
| root=junction->root; | root=junction->root; |
| rcontext=junction->rcontext; | rcontext=junction->rcontext; |
| execute(*junction->code); | execute(*junction->code); |
| Value *result; | if(intercept_string) { |
| if(make_string) { | |
| // CodeFrame soul: | // CodeFrame soul: |
| // string writes were intercepted | // string writes were intercepted |
| // returning them as the result of getting code-junction | // returning them as the result of getting code-junction |
| Line 611 Value& Request::autocalc(Value& value, b | Line 630 Value& Request::autocalc(Value& value, b |
| self=static_cast<VAliased *>(POP()); | self=static_cast<VAliased *>(POP()); |
| fprintf(stderr, "<-ja returned"); | fprintf(stderr, "<-ja returned"); |
| return *result; | |
| } else | } else |
| return value; | result=&value; |
| if(name) | |
| result->set_name(*name); | |
| return *result; | |
| } | |
| char *Request::execute_static_method(VClass& vclass, String& method_name, bool return_cstr) { | |
| Value *value=vclass.get_element(method_name); | |
| if(value) { // found some 'METHOD_NAME' element | |
| Junction *junction=value->get_junction(); | |
| if(junction) {// it even has junction! | |
| const Method *method=junction->method; | |
| if(method) { // and junction is method-junction! call it | |
| PUSH(self); | |
| PUSH(root); | |
| PUSH(rcontext); | |
| PUSH(wcontext); | |
| // initialize contexts | |
| root=rcontext=self=&vclass; | |
| wcontext=NEW WWrapper(pool(), &vclass, false /* not constructing */); | |
| // execute! | |
| execute(*method->parser_code); | |
| // result | |
| char *result; | |
| if(return_cstr) | |
| result=wcontext->get_string()->cstr(); // chars | |
| else | |
| result=0; // ignore result | |
| wcontext=static_cast<WContext *>(POP()); | |
| rcontext=POP(); | |
| root=POP(); | |
| self=static_cast<VAliased *>(POP()); | |
| // return | |
| return result; | |
| } | |
| } | |
| } | |
| return 0; | |
| } | } |