|
|
| version 1.166, 2001/05/28 06:10:06 | version 1.181, 2001/07/24 15:43:56 |
|---|---|
| Line 4 | Line 4 |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) |
| $Id$ | |
| */ | */ |
| static const char *RCSId="$Id$"; | |
| #include "pa_opcode.h" | #include "pa_opcode.h" |
| #include "pa_array.h" | #include "pa_array.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_vstring.h" | #include "pa_vstring.h" |
| #include "pa_vhash.h" | #include "pa_vhash.h" |
| #include "pa_vnothing.h" | #include "pa_vvoid.h" |
| #include "pa_vcode_frame.h" | #include "pa_vcode_frame.h" |
| #include "pa_vmethod_frame.h" | #include "pa_vmethod_frame.h" |
| #include "pa_vobject.h" | #include "pa_vobject.h" |
| Line 35 char *opcode_name[]={ | Line 34 char *opcode_name[]={ |
| // actions | // actions |
| "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_EXPR", |
| "WRITE_VALUE", "WRITE_EXPR_RESULT", "STRING__WRITE", | "WRITE_VALUE", "WRITE_EXPR_RESULT", "STRING__WRITE", |
| "GET_ELEMENT", "GET_ELEMENT__WRITE", | "GET_ELEMENT", "GET_ELEMENT__WRITE", |
| "CREATE_EWPOOL", "REDUCE_EWPOOL", | "CREATE_EWPOOL", "REDUCE_EWPOOL", |
| Line 70 void debug_printf(Pool& pool, const char | Line 69 void debug_printf(Pool& pool, const char |
| } | } |
| void debug_dump(Pool& pool, int level, const Array& ops) { | void debug_dump(Pool& pool, int level, const Array& ops) { |
| { | /* { |
| int size=ops.quick_size(); | int size=ops.quick_size(); |
| //debug_printf(pool, "size=%d\n", size); | //debug_printf(pool, "size=%d\n", size); |
| for(int i=0; i<size; i++) { | for(int i=0; i<size; i++) { |
| Line 78 void debug_dump(Pool& pool, int level, c | Line 77 void debug_dump(Pool& pool, int level, c |
| op.cast=ops.quick_get(i); | op.cast=ops.quick_get(i); |
| debug_printf(pool, "%8X\n", op.cast); | debug_printf(pool, "%8X\n", op.cast); |
| } | } |
| } | }*/ |
| int size=ops.quick_size(); | int size=ops.quick_size(); |
| //debug_printf(pool, "size=%d\n", size); | //debug_printf(pool, "size=%d\n", size); |
| Line 254 void Request::execute(const Array& ops) | Line 253 void Request::execute(const Array& ops) |
| // maybe they do ^object.method[] call, remember the fact | // maybe they do ^object.method[] call, remember the fact |
| wcontext->inc_somebody_entered_some_object(); | wcontext->inc_somebody_entered_some_object(); |
| //_asm int 3; | |
| Value *value=get_element(); | Value *value=get_element(); |
| PUSH(value); | PUSH(value); |
| break; | break; |
| Line 300 void Request::execute(const Array& ops) | Line 300 void Request::execute(const Array& ops) |
| if(string) | if(string) |
| value=NEW VString(*string); | value=NEW VString(*string); |
| else | else |
| value=NEW VNothing(pool()); | value=NEW VVoid(pool()); |
| wcontext=static_cast<WContext *>(POP()); | wcontext=static_cast<WContext *>(POP()); |
| rcontext=POP(); | rcontext=POP(); |
| PUSH(value); | PUSH(value); |
| Line 321 void Request::execute(const Array& ops) | Line 321 void Request::execute(const Array& ops) |
| if(string) | if(string) |
| value=NEW VString(*string); | value=NEW VString(*string); |
| else | else |
| NEW VNothing(pool()); | NEW VVoid(pool()); |
| wcontext=static_cast<WContext *>(POP()); | wcontext=static_cast<WContext *>(POP()); |
| PUSH(value); | PUSH(value); |
| break; | break; |
| Line 373 void Request::execute(const Array& ops) | Line 373 void Request::execute(const Array& ops) |
| PUSH(wcontext); | PUSH(wcontext); |
| VStateless_class *called_class=frame->junction.self.get_class(); | VStateless_class *called_class=frame->junction.self.get_class(); |
| // not ^name.method call and | // not ^name.method call, name:method call; and |
| // is context object or class & is it my class or my parent's class and? | // is context object or class & is it my class or my parent's class and? |
| VStateless_class *read_class=rcontext->get_class(); | VStateless_class *read_class=rcontext->get_class(); |
| if(!wcontext->somebody_entered_some_object() && | if( |
| !(wcontext->somebody_entered_some_object() && | |
| !wcontext->somebody_entered_some_class()) && | |
| read_class && read_class->is_or_derived_from(*called_class)) // yes | 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) |
| Line 530 void Request::execute(const Array& ops) | Line 532 void Request::execute(const Array& ops) |
| case OP_DIV: | case OP_DIV: |
| { | { |
| Value *b=POP(); Value *a=POP(); | Value *b=POP(); Value *a=POP(); |
| Value *value=NEW VDouble(pool(), a->as_double() / b->as_double()); | |
| double a_double=a->as_double(); | |
| double b_double=b->as_double(); | |
| if(b_double == 0) { | |
| const String *problem_source=&b->as_string(); | |
| #ifndef NO_STRING_ORIGIN | |
| if(!problem_source->origin().file) | |
| problem_source=&b->name(); | |
| #endif | |
| THROW(0, 0, | |
| problem_source, | |
| "Division by zero"); | |
| } | |
| Value *value=NEW VDouble(pool(), a_double / b_double); | |
| PUSH(value); | PUSH(value); |
| break; | break; |
| } | } |
| case OP_MOD: | case OP_MOD: |
| { | { |
| Value *b=POP(); Value *a=POP(); | Value *b=POP(); Value *a=POP(); |
| Value *value=NEW VDouble(pool(), | |
| a->as_int() % | double a_double=a->as_double(); |
| b->as_int()); | double b_double=b->as_double(); |
| if(b_double == 0) { | |
| const String *problem_source=&b->as_string(); | |
| #ifndef NO_STRING_ORIGIN | |
| if(!problem_source->origin().file) | |
| problem_source=&b->name(); | |
| #endif | |
| THROW(0, 0, | |
| problem_source, | |
| "Modulus by zero"); | |
| } | |
| Value *value=NEW VDouble(pool(), fmod(a_double, b_double)); | |
| PUSH(value); | PUSH(value); |
| break; | break; |
| } | } |
| Line 694 void Request::execute(const Array& ops) | Line 724 void Request::execute(const Array& ops) |
| Value *Request::get_element() { | Value *Request::get_element() { |
| const String& name=POP_NAME(); | const String& name=POP_NAME(); |
| Value *ncontext=POP(); | Value *ncontext=POP(); |
| Value *value; | Value *value=ncontext->get_element(name); |
| if(Method* method=OP.get_method(name)) { // operator? | if(!value) |
| // as if that method were in self and we have normal dynamic method here | if(Method* method=OP.get_method(name)) { // maybe operator? |
| Junction& junction=*NEW Junction(pool(), | // as if that method were in self and we have normal dynamic method here |
| *self, self->get_class(), method, 0,0,0,0); | Junction& junction=*NEW Junction(pool(), |
| value=NEW VJunction(junction); | *self, self->get_class(), method, 0,0,0,0); |
| } else | value=NEW VJunction(junction); |
| value=ncontext->get_element(name); | } |
| if(value) | if(value) |
| value=&process(*value, &name); // process possible code-junction | value=&process(*value, &name); // process possible code-junction |
| else { | else { |
| value=NEW VNothing(pool()); | value=NEW VVoid(pool()); |
| value->set_name(name); | value->set_name(name); |
| } | } |
| Line 777 Value& Request::process(Value& value, co | Line 807 Value& Request::process(Value& value, co |
| return *result; | return *result; |
| } | } |
| const String *Request::execute_method(Value& aself, const Method& method, bool return_cstr) { | const String *Request::execute_method(Value& aself, const Method& method, |
| bool return_cstr) { | |
| PUSH(self); | PUSH(self); |
| PUSH(root); | PUSH(root); |
| PUSH(rcontext); | PUSH(rcontext); |
| Line 806 const String *Request::execute_method(Va | Line 837 const String *Request::execute_method(Va |
| return result; | return result; |
| } | } |
| const String *Request::execute_method(Value& aself, | const String *Request::execute_virtual_method(Value& aself, |
| const String& method_name, bool return_cstr) { | const String& method_name, |
| bool return_cstr) { | |
| if(Value *value=aself.get_element(method_name)) | if(Value *value=aself.get_element(method_name)) |
| if(Junction *junction=value->get_junction()) | if(Junction *junction=value->get_junction()) |
| if(const Method *method=junction->method) | if(const Method *method=junction->method) |
| Line 815 const String *Request::execute_method(Va | Line 847 const String *Request::execute_method(Va |
| return 0; | return 0; |
| } | } |
| const String *Request::execute_nonvirtual_method(VStateless_class& aclass, | |
| const String& method_name, | |
| bool return_cstr) { | |
| if(const Method *method=aclass.get_method(method_name)) | |
| return execute_method(aclass, *method, return_cstr); | |
| return 0; | |
| } |