--- parser3/src/main/execute.C 2001/03/18 16:36:55 1.115 +++ parser3/src/main/execute.C 2001/03/27 13:47:31 1.127 @@ -1,13 +1,16 @@ -/* - Parser +/** @file + Parser: executor part of request class. + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) - $Id: execute.C,v 1.115 2001/03/18 16:36:55 paf Exp $ + $Id: execute.C,v 1.127 2001/03/27 13:47:31 paf Exp $ */ -#include "pa_array.h" +#include "pa_config_includes.h" #include "code.h" +#include "pa_array.h" #include "pa_request.h" #include "pa_vstring.h" #include "pa_vhash.h" @@ -20,7 +23,6 @@ #include "pa_vtable.h" #include -#include #define PUSH(value) stack.push(value) #define POP() static_cast(stack.pop()) @@ -55,70 +57,71 @@ char *opcode_name[]={ "IS" }; -void va_log_printf(const char *fmt,va_list args) { +void va_log_printf(Pool& pool, const char *fmt,va_list args) { return; - vfprintf(stderr, fmt, args); + char buf[MAX_STRING]; + vsnprintf(buf, MAX_STRING, fmt, args); + SAPI::log(pool, "%s", buf); } -void log_printf(const char *fmt, ...) { - // TODO: куда-нибудь пристроить +void log_printf(Pool& pool, const char *fmt, ...) { va_list args; va_start(args,fmt); - va_log_printf(fmt,args); + va_log_printf(pool,fmt,args); va_end(args); } -void dump(int level, const Array& ops) { +void dump(Pool& pool, int level, const Array& ops) { if(0){ int size=ops.size(); - //log_printf("size=%d\n", size); + //log_printf(pool, "size=%d\n", size); for(int i=0; i(ops.quick_get(++i)); - log_printf(" \"%s\" %s", value->get_string()->cstr(), value->type()); + log_printf(pool, " \"%s\" %s", value->get_string()->cstr(), value->type()); } - log_printf("\n"); + log_printf(pool, "\n"); 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); + dump(pool, level+1, *local_ops); } } } void Request::execute(const Array& ops) { if(1) { - log_printf("source----------------------------\n"); - dump(0, ops); - log_printf("execution-------------------------\n"); + log_printf(pool(), "source----------------------------\n"); + dump(pool(), 0, ops); + log_printf(pool(), "execution-------------------------\n"); } int size=ops.size(); - //log_printf("size=%d\n", size); + //log_printf(pool(), "size=%d\n", size); for(int i=0; i(ops.quick_get(++i)); - log_printf(" \"%s\" %s", value->get_string()->cstr(), value->type()); + log_printf(pool(), " \"%s\" %s", value->get_string()->cstr(), value->type()); PUSH(value); break; } @@ -128,8 +131,8 @@ void Request::execute(const Array& ops) VMethodFrame *frame=static_cast(stack.top_value()); // code const Array *local_ops=reinterpret_cast(ops.quick_get(++i)); - log_printf(" (%d)\n", local_ops->size()); - dump(1, *local_ops); + log_printf(pool(), " (%d)\n", local_ops->size()); + dump(pool(), 1, *local_ops); // when they evaluate expression parameter, // the object expression result @@ -154,13 +157,13 @@ void Request::execute(const Array& ops) wcontext->set_somebody_entered_some_class(); const String& name=POP_NAME(); - VClass *vclass=static_cast(classes().get(name)); - if(!vclass) + Value *value=static_cast(classes().get(name)); + if(!value) THROW(0,0, &name, ": undefined class"); - PUSH(vclass); + PUSH(value); break; } @@ -220,8 +223,8 @@ void Request::execute(const Array& ops) case OP_STRING__WRITE: { VString *vstring=static_cast(ops.quick_get(++i)); - log_printf(" \"%s\"", vstring->string().cstr()); - write(vstring->string()); + log_printf(pool(), " \"%s\"", vstring->string().cstr()); + write_no_lang(vstring->string()); break; } @@ -326,7 +329,7 @@ void Request::execute(const Array& ops) case OP_CALL: { - log_printf("->\n"); + log_printf(pool(), "->\n"); VMethodFrame *frame=static_cast(POP()); frame->fill_unspecified_params(); PUSH(self); @@ -345,14 +348,12 @@ void Request::execute(const Array& ops) wcontext->somebody_entered_some_class()) { // ^class:method[..]? // yes, this is a constructor call // some stateless_object derivates with constructors - if(called_class->name()==TABLE_CLASS_NAME) + if(called_class==table_class) self=NEW VTable(pool()); - else /*if(called_class->name()==ENV_CLASS_NAME) - self=NEW VEnv(pool()); - else */ // stateful object + else // stateful object self=NEW VObject(pool(), *called_class); frame->write(*self, - String::Untaint_lang::NO // not used, always an object, not string + String::UL_NO // not used, always an object, not string ); } else self=&frame->junction.self; // no, static or simple dynamic call @@ -383,7 +384,7 @@ void Request::execute(const Array& ops) self=static_cast(POP()); PUSH(value); - log_printf("<-returned"); + log_printf(pool(), "<-returned"); break; } @@ -420,14 +421,15 @@ void Request::execute(const Array& ops) { Value *operand=POP(); const char *path=operand->as_string().cstr(); - Value *value=NEW VBool(pool(), strcmp(path, info.uri)<=0); + Value *value=NEW VBool(pool(), info.uri && strcmp(path, info.uri)<=0); PUSH(value); break; } case OP_FEXISTS: { Value *operand=POP(); - Value *value=NEW VBool(pool(), true/*TODO*/); + Value *value=NEW VBool(pool(), + file_readable(absolute(operand->as_string()))); PUSH(value); break; } @@ -615,7 +617,7 @@ void Request::execute(const Array& ops) 0, "unhandled '%s' opcode", opcode_name[op.code]); } - log_printf("\n"); + log_printf(pool(), "\n"); } } @@ -634,25 +636,26 @@ Value *Request::get_element() { return value; } +/** + 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 @c (expression) params evaluation +*/ Value& Request::process(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(); if(junction && junction->code) { // is it a code-junction? // process it - log_printf("ja->\n"); + log_printf(pool(), "ja->\n"); PUSH(self); PUSH(root); PUSH(rcontext); - PUSH(wcontext); + PUSH(wcontext); WContext *frame; // for expression method params @@ -686,7 +689,7 @@ Value& Request::process(Value& value, co root=POP(); self=static_cast(POP()); - log_printf("<-ja returned"); + log_printf(pool(), "<-ja returned"); } else result=&value;