|
|
| version 1.92, 2001/03/12 09:08:51 | version 1.99, 2001/03/13 12:37:05 |
|---|---|
| Line 17 | Line 17 |
| #include "pa_vobject.h" | #include "pa_vobject.h" |
| #include "pa_vdouble.h" | #include "pa_vdouble.h" |
| #include "pa_vbool.h" | #include "pa_vbool.h" |
| #include "pa_vtable.h" | |
| #include <stdio.h> | #include <stdio.h> |
| Line 127 void Request::execute(const Array& ops) | Line 128 void Request::execute(const Array& ops) |
| } | } |
| case OP_GET_CLASS: | case OP_GET_CLASS: |
| { | { |
| // maybe the do ^class:method[] call, remember the fact | |
| wcontext->set_somebody_entered_some_class(); | |
| const String& name=POP_NAME(); | const String& name=POP_NAME(); |
| VClass *vclass=static_cast<VClass *>(classes().get(name)); | VClass *vclass=static_cast<VClass *>(classes().get(name)); |
| if(!vclass) | if(!vclass) |
| Line 274 void Request::execute(const Array& ops) | Line 278 void Request::execute(const Array& ops) |
| if(!junction) | if(!junction) |
| THROW(0,0, | THROW(0,0, |
| &value->name(), | &value->name(), |
| "type is '%s', can not call it (must be method or junction)", | "(%s) uncallable, must be method or junction", |
| value->type()); | value->type()); |
| VMethodFrame *frame=NEW VMethodFrame(pool(), *junction); | VMethodFrame *frame=NEW VMethodFrame(pool(), *junction); |
| Line 307 void Request::execute(const Array& ops) | Line 311 void Request::execute(const Array& ops) |
| if(read_class && read_class->is_or_derived_from(*called_class)) // yes | if(read_class && read_class->is_or_derived_from(*called_class)) // yes |
| self=rcontext; // class dynamic call | self=rcontext; // class dynamic call |
| else // no, not me or relative of mine (total stranger) | else // no, not me or relative of mine (total stranger) |
| if(wcontext->constructing()) { // constructing? | if( |
| // yes, constructor call: $some(^class:method(..)) | wcontext->constructing() && // constructing? |
| self=NEW VObject(pool(), *called_class); | wcontext->somebody_entered_some_class()) { // ^class:method[..]? |
| // yes, this is a constructor call | |
| if(called_class->name()==TABLE_CLASS_NAME) | |
| self=NEW VTable(pool()); | |
| else | |
| self=NEW VObject(pool(), *called_class); | |
| frame->write(*self, | frame->write(*self, |
| String::Untaint_lang::NO // not used, always an object, not string | String::Untaint_lang::NO // not used, always an object, not string |
| ); | ); |
| Line 324 void Request::execute(const Array& ops) | Line 333 void Request::execute(const Array& ops) |
| // substitute class alias to the class they are called AS | // substitute class alias to the class they are called AS |
| Temp_alias temp_alias(*aliased, *frame->junction.vclass); | Temp_alias temp_alias(*aliased, *frame->junction.vclass); |
| Method& method=*frame->junction.method; | const Method& method=*frame->junction.method; |
| if(method.native_code) { // native code? | if(method.native_code) { // native code? |
| method.check_actual_numbered_params( | method.check_actual_numbered_params( |
| frame->name(), frame->numbered_params()); | frame->name(), frame->numbered_params()); |
| Line 356 void Request::execute(const Array& ops) | Line 365 void Request::execute(const Array& ops) |
| case OP_INV: | case OP_INV: |
| { | { |
| Value *operand=POP(); | Value *operand=POP(); |
| Value *value=NEW VDouble(pool(), ~static_cast<int>(operand->get_double())); | Value *value=NEW VDouble(pool(), ~(int)operand->get_double()); |
| PUSH(value); | PUSH(value); |
| break; | break; |
| } | } |
| Line 422 void Request::execute(const Array& ops) | Line 431 void Request::execute(const Array& ops) |
| { | { |
| Value *b=POP(); Value *a=POP(); | Value *b=POP(); Value *a=POP(); |
| Value *value=NEW VDouble(pool(), | Value *value=NEW VDouble(pool(), |
| static_cast<int>(a->get_double()) % | (int)a->get_double() % |
| static_cast<int>(b->get_double())); | (int)b->get_double()); |
| PUSH(value); | PUSH(value); |
| break; | break; |
| } | } |
| Line 431 void Request::execute(const Array& ops) | Line 440 void Request::execute(const Array& ops) |
| { | { |
| Value *b=POP(); Value *a=POP(); | Value *b=POP(); Value *a=POP(); |
| Value *value=NEW VDouble(pool(), | Value *value=NEW VDouble(pool(), |
| static_cast<int>(a->get_double()) & | (int)a->get_double() & |
| static_cast<int>(b->get_double())); | (int)b->get_double()); |
| PUSH(value); | PUSH(value); |
| break; | break; |
| } | } |
| Line 440 void Request::execute(const Array& ops) | Line 449 void Request::execute(const Array& ops) |
| { | { |
| Value *b=POP(); Value *a=POP(); | Value *b=POP(); Value *a=POP(); |
| Value *value=NEW VDouble(pool(), | Value *value=NEW VDouble(pool(), |
| static_cast<int>(a->get_double()) | | (int)a->get_double() | |
| static_cast<int>(b->get_double())); | (int)b->get_double()); |
| PUSH(value); | PUSH(value); |
| break; | break; |
| } | } |
| Line 449 void Request::execute(const Array& ops) | Line 458 void Request::execute(const Array& ops) |
| { | { |
| Value *b=POP(); Value *a=POP(); | Value *b=POP(); Value *a=POP(); |
| Value *value=NEW VDouble(pool(), | Value *value=NEW VDouble(pool(), |
| static_cast<int>(a->get_double()) ^ | (int)a->get_double() ^ |
| static_cast<int>(b->get_double())); | (int)b->get_double()); |
| PUSH(value); | PUSH(value); |
| break; | break; |
| } | } |
| Line 641 Value& Request::process(Value& value, co | Line 650 Value& Request::process(Value& value, co |
| return *result; | return *result; |
| } | } |
| char *Request::execute_static_method(VClass& vclass, String& method_name, bool return_cstr) { | char *Request::execute_method(Value& aself, const Method& method, bool return_cstr) { |
| if(Value *value=vclass.get_element(method_name)) { // found some 'METHOD_NAME' element | PUSH(self); |
| if(Junction *junction=value->get_junction()) {// it even has junction! | PUSH(root); |
| if(const Method *method=junction->method) { // and junction is method-junction! call it | PUSH(rcontext); |
| PUSH(self); | PUSH(wcontext); |
| PUSH(root); | |
| PUSH(rcontext); | // initialize contexts |
| PUSH(wcontext); | root=rcontext=self=&aself; |
| wcontext=NEW WWrapper(pool(), &aself, false /* not constructing */); | |
| // initialize contexts | |
| root=rcontext=self=&vclass; | // execute! |
| wcontext=NEW WWrapper(pool(), &vclass, false /* not constructing */); | execute(*method.parser_code); |
| // execute! | // result |
| execute(*method->parser_code); | char *result; |
| if(return_cstr) | |
| // result | result=wcontext->get_string()->cstr(); // chars |
| char *result; | else |
| if(return_cstr) | result=0; // ignore result |
| result=wcontext->get_string()->cstr(); // chars | |
| else | wcontext=static_cast<WContext *>(POP()); |
| result=0; // ignore result | rcontext=POP(); |
| root=POP(); | |
| self=static_cast<VAliased *>(POP()); | |
| // return | |
| return result; | |
| } | |
| wcontext=static_cast<WContext *>(POP()); | char *Request::execute_method(Value& aself, |
| rcontext=POP(); | const String& method_name, bool return_cstr) { |
| root=POP(); | if(Value *value=aself.get_element(method_name)) |
| self=static_cast<VAliased *>(POP()); | if(Junction *junction=value->get_junction()) |
| if(const Method *method=junction->method) | |
| return execute_method(aself, *method, return_cstr); | |
| // return | |
| return result; | |
| } | |
| } | |
| } | |
| return 0; | return 0; |
| } | } |