--- parser3/src/main/execute.C 2001/03/10 13:07:09 1.84 +++ parser3/src/main/execute.C 2001/03/11 09:24:43 1.90 @@ -1,5 +1,9 @@ /* - $Id: execute.C,v 1.84 2001/03/10 13:07:09 paf Exp $ + Parser + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: execute.C,v 1.90 2001/03/11 09:24:43 paf Exp $ */ #include "pa_array.h" @@ -29,7 +33,7 @@ char *opcode_name[]={ "WITH_SELF", "WITH_ROOT", "WITH_READ", "WITH_WRITE", "GET_CLASS", "CONSTRUCT_VALUE", "CONSTRUCT_DOUBLE", - "WRITE", + "WRITE", "STRING__WRITE", "GET_ELEMENT", "GET_ELEMENT__WRITE", "CREATE_EWPOOL", "REDUCE_EWPOOL", "CREATE_RWPOOL", "REDUCE_RWPOOL", @@ -66,7 +70,7 @@ void dump(int level, const Array& ops) { op.cast=ops.quick_get(i); 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(ops.quick_get(++i)); fprintf(stderr, " \"%s\" %s", value->get_string()->cstr(), value->type()); } @@ -116,7 +120,6 @@ void Request::execute(const Array& ops) root, frame, frame, local_ops); Value *value=NEW VJunction(j); - ///value->set_name(frame->name()); // store param frame->store_param(value); @@ -182,6 +185,13 @@ void Request::execute(const Array& ops) write(*value); break; } + case OP_STRING__WRITE: + { + VString *vstring=static_cast(ops.quick_get(++i)); + fprintf(stderr, " \"%s\"", vstring->value().cstr()); + write(vstring->value()); + break; + } case OP_GET_ELEMENT: { @@ -571,7 +581,16 @@ Value *Request::get_element() { return value; } -Value& Request::autocalc(Value& value, const String *name, 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 + Junction *junction=value.get_junction(); if(junction && junction->code) { // is it a code-junction? // autocalc it @@ -582,7 +601,7 @@ Value& Request::autocalc(Value& value, c PUSH(wcontext); WContext *frame; - if(make_string) { + if(intercept_string) { // almost plain wwrapper about junction wcontext, // BUT intercepts string writes frame=NEW VCodeFrame(pool(), *junction->wcontext); @@ -597,7 +616,7 @@ Value& Request::autocalc(Value& value, c rcontext=junction->rcontext; execute(*junction->code); Value *result; - if(make_string) { + if(intercept_string) { // CodeFrame soul: // string writes were intercepted // returning them as the result of getting code-junction @@ -617,3 +636,42 @@ Value& Request::autocalc(Value& value, c } else return value; } + +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(POP()); + rcontext=POP(); + root=POP(); + self=static_cast(POP()); + + // return + return result; + } + } + } + return 0; +}