--- parser3/src/main/execute.C 2001/03/15 11:00:40 1.106 +++ parser3/src/main/execute.C 2001/03/16 12:30:23 1.112 @@ -3,7 +3,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: execute.C,v 1.106 2001/03/15 11:00:40 paf Exp $ + $Id: execute.C,v 1.112 2001/03/16 12:30:23 paf Exp $ */ #include "pa_array.h" @@ -20,6 +20,7 @@ #include "pa_vtable.h" #include +#include #define PUSH(value) stack.push(value) #define POP() static_cast(stack.pop()) @@ -28,13 +29,13 @@ char *opcode_name[]={ // literals - "VALUE", "CODE__STORE_PARAM", + "VALUE", "CURLY_CODE__STORE_PARAM", "EXPR_CODE__STORE_PARAM", // actions "WITH_SELF", "WITH_ROOT", "WITH_READ", "WITH_WRITE", "GET_CLASS", "CONSTRUCT_VALUE", "CONSTRUCT_DOUBLE", - "WRITE", "STRING__WRITE", + "WRITE_VALUE", "WRITE_EXPR_RESULT", "STRING__WRITE", "GET_ELEMENT", "GET_ELEMENT__WRITE", "CREATE_EWPOOL", "REDUCE_EWPOOL", "CREATE_RWPOOL", "REDUCE_RWPOOL", @@ -54,8 +55,16 @@ char *opcode_name[]={ "IS" }; +void va_log_printf(const char *fmt,va_list args) { + vfprintf(stderr, fmt, args); +} + void log_printf(const char *fmt, ...) { // TODO: куда-нибудь пристроить + va_list args; + va_start(args,fmt); + va_log_printf(fmt,args); + va_end(args); } void dump(int level, const Array& ops) { @@ -82,7 +91,7 @@ void dump(int level, const Array& ops) { } log_printf("\n"); - if(op.code==OP_CODE__STORE_PARAM) { + if(op.code==OP_CURLY_CODE__STORE_PARAM || op.code==OP_EXPR_CODE__STORE_PARAM) { const Array *local_ops=reinterpret_cast(ops.quick_get(++i)); dump(level+1, *local_ops); } @@ -112,7 +121,8 @@ void Request::execute(const Array& ops) PUSH(value); break; } - case OP_CODE__STORE_PARAM: + case OP_CURLY_CODE__STORE_PARAM: + case OP_EXPR_CODE__STORE_PARAM: { VMethodFrame *frame=static_cast(stack.top_value()); // code @@ -120,9 +130,16 @@ void Request::execute(const Array& ops) log_printf(" (%d)\n", local_ops->size()); dump(1, *local_ops); + // when they evaluate expression parameter, + // the object expression result + // does not need to be written into calling frame + // it must go into any expressions using that parameter + // hence, zeroing junction.wcontext being created + // later, in .process would test that field + // in decision "which wwrapper to use" Junction& j=*NEW Junction(pool(), *self, 0, 0, - root, frame, frame, local_ops); + root, frame, op.code==OP_EXPR_CODE__STORE_PARAM?0:frame, local_ops); Value *value=NEW VJunction(j); @@ -187,17 +204,23 @@ void Request::execute(const Array& ops) value->set_name(name); break; } - case OP_WRITE: + case OP_WRITE_VALUE: { Value *value=POP(); write_assign_lang(*value); break; } + case OP_WRITE_EXPR_RESULT: + { + Value *value=POP(); + write_expr_result(*value->get_expr_result()); + break; + } case OP_STRING__WRITE: { VString *vstring=static_cast(ops.quick_get(++i)); - log_printf(" \"%s\"", vstring->value().cstr()); - write(vstring->value()); + log_printf(" \"%s\"", vstring->string().cstr()); + write(vstring->string()); break; } @@ -277,12 +300,14 @@ void Request::execute(const Array& ops) case OP_GET_METHOD_FRAME: { Value *value=POP(); - // info: this one's always method-junction, not a code-junction + // info: + // code compiled so that this one's always method-junction, + // not a code-junction Junction *junction=value->get_junction(); if(!junction) THROW(0,0, &value->name(), - "(%s) uncallable, must be method or junction", + "(%s) not a method or junction, can not call it", value->type()); VMethodFrame *frame=NEW VMethodFrame(pool(), *junction); @@ -390,7 +415,8 @@ void Request::execute(const Array& ops) case OP_IN: { Value *operand=POP(); - Value *value=NEW VBool(pool(), true/*TODO*/); + const char *path=operand->as_string().cstr(); + Value *value=NEW VBool(pool(), strcmp(path, info.uri)<=0); PUSH(value); break; } @@ -625,13 +651,17 @@ Value& Request::process(Value& value, co PUSH(wcontext); WContext *frame; - if(intercept_string) { + // for expression method params + // wcontext is set 0 + // using the fact in decision "which wwrapper to use" + bool using_code_frame=intercept_string && junction->wcontext; + if(using_code_frame) { // almost plain wwrapper about junction wcontext, // BUT intercepts string writes frame=NEW VCodeFrame(pool(), *junction->wcontext); } else { // plain wwrapper - frame=NEW WWrapper(pool(), 0 /* empty */, false /*not constructing*/); + frame=NEW WWrapper(pool(), 0/*empty*/, false/*not constructing*/); } wcontext=frame; @@ -639,7 +669,7 @@ Value& Request::process(Value& value, co root=junction->root; rcontext=junction->rcontext; execute(*junction->code); - if(intercept_string) { + if(using_code_frame) { // CodeFrame soul: // string writes were intercepted // returning them as the result of getting code-junction