|
|
| version 1.349, 2009/06/14 00:34:04 | version 1.355, 2009/08/10 12:04:35 |
|---|---|
| Line 66 char *opcode_name[]={ | Line 66 char *opcode_name[]={ |
| #endif | #endif |
| "OBJECT_POOL", "STRING_POOL", | "OBJECT_POOL", "STRING_POOL", |
| "PREPARE_TO_CONSTRUCT_OBJECT", | "PREPARE_TO_CONSTRUCT_OBJECT", |
| #ifdef OPTIMIZE_BYTECODE_CONSTRUCT_OBJECT | |
| "CONSTRUCT_OBJECT", | "CONSTRUCT_OBJECT", |
| "CONSTRUCT_OBJECT__WRITE", | "CONSTRUCT_OBJECT__WRITE", |
| #endif | |
| "PREPARE_TO_EXPRESSION", | "PREPARE_TO_EXPRESSION", |
| "CALL", "CALL__WRITE", | "CALL", "CALL__WRITE", |
| Line 148 void debug_dump(SAPI_Info& sapi_info, in | Line 146 void debug_dump(SAPI_Info& sapi_info, in |
| continue; | continue; |
| } | } |
| #endif | #endif |
| #ifdef OPTIMIZE_BYTECODE_CONSTRUCT_OBJECT | |
| if( | if( |
| opcode==OP::OP_CONSTRUCT_OBJECT | opcode==OP::OP_CONSTRUCT_OBJECT |
| || opcode==OP::OP_CONSTRUCT_OBJECT__WRITE | || opcode==OP::OP_CONSTRUCT_OBJECT__WRITE |
| Line 167 void debug_dump(SAPI_Info& sapi_info, in | Line 164 void debug_dump(SAPI_Info& sapi_info, in |
| debug_dump(sapi_info, level+1, *local_ops); | debug_dump(sapi_info, level+1, *local_ops); |
| continue; | continue; |
| } | } |
| #endif | |
| if( | if( |
| opcode==OP::OP_VALUE | opcode==OP::OP_VALUE |
| || opcode==OP::OP_STRING__WRITE | || opcode==OP::OP_STRING__WRITE |
| Line 426 void Request::execute(ArrayOperation& op | Line 422 void Request::execute(ArrayOperation& op |
| const String& name=stack.pop().string(); debug_name=&name; | const String& name=stack.pop().string(); debug_name=&name; |
| Value& ncontext=stack.pop().value(); | Value& ncontext=stack.pop().value(); |
| if(const VJunction* vjunction=ncontext.put_element(ncontext, name, &value, false)) | if(const VJunction* vjunction=ncontext.put_element(name, &value, false)) |
| if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) | if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| Line 451 void Request::execute(ArrayOperation& op | Line 447 void Request::execute(ArrayOperation& op |
| } | } |
| case OP::OP_WRITE_EXPR_RESULT: | case OP::OP_WRITE_EXPR_RESULT: |
| { | { |
| Value& value=stack.pop().value(); | |
| write_no_lang(value.as_expr_result()); | |
| // must be after write(result) and | |
| // see OP_PREPARE_TO_EXPRESSION | // see OP_PREPARE_TO_EXPRESSION |
| wcontext->set_in_expression(false); | wcontext->set_in_expression(false); |
| Value& value=stack.pop().value(); | |
| wcontext->write(value.as_expr_result()); | |
| break; | break; |
| } | } |
| case OP::OP_STRING__WRITE: | case OP::OP_STRING__WRITE: |
| Line 645 void Request::execute(ArrayOperation& op | Line 640 void Request::execute(ArrayOperation& op |
| String::Language saved_lang=flang; | String::Language saved_lang=flang; |
| flang=String::L_PASS_APPENDED; | flang=String::L_PASS_APPENDED; |
| #ifdef OPTIMIZE_SINGLE_STRING_WRITE | #ifdef OPTIMIZE_SINGLE_STRING_WRITE |
| WObjectPoolWrapper local(0/*empty*/, wcontext); | WObjectPoolWrapper local(wcontext); |
| #else | #else |
| WWrapper local(0/*empty*/, wcontext); | WWrapper local(wcontext); |
| #endif | #endif |
| wcontext=&local; | wcontext=&local; |
| Line 664 void Request::execute(ArrayOperation& op | Line 659 void Request::execute(ArrayOperation& op |
| ArrayOperation& local_ops=*i.next().ops; | ArrayOperation& local_ops=*i.next().ops; |
| WContext *saved_wcontext=wcontext; | WContext *saved_wcontext=wcontext; |
| WWrapper local(0 /*empty*/, wcontext); | WWrapper local(wcontext); |
| wcontext=&local; | wcontext=&local; |
| execute(local_ops); | execute(local_ops); |
| Line 713 void Request::execute(ArrayOperation& op | Line 708 void Request::execute(ArrayOperation& op |
| break; | break; |
| } | } |
| #ifndef OPTIMIZE_BYTECODE_CONSTRUCT_OBJECT | |
| case OP::OP_PREPARE_TO_CONSTRUCT_OBJECT: | |
| { | |
| wcontext->set_constructing(true); | |
| break; | |
| } | |
| #endif | |
| case OP::OP_PREPARE_TO_EXPRESSION: | case OP::OP_PREPARE_TO_EXPRESSION: |
| { | { |
| wcontext->set_in_expression(true); | wcontext->set_in_expression(true); |
| break; | break; |
| } | } |
| #define METHOD_FRAME_ACTION(action) \ | |
| if(local_ops){ \ | |
| size_t first = stack.top_index(); \ | |
| execute(*local_ops); \ | |
| frame.store_params((Value**)stack.ptr(first), stack.top_index()-first); \ | |
| action; \ | |
| stack.set_top_index(first); \ | |
| } else { \ | |
| frame.empty_params(); \ | |
| action; \ | |
| } | |
| case OP::OP_CALL: | case OP::OP_CALL: |
| { | { |
| ArrayOperation* local_ops=i.next().ops; | ArrayOperation* local_ops=i.next().ops; |
| Line 750 void Request::execute(ArrayOperation& op | Line 749 void Request::execute(ArrayOperation& op |
| } | } |
| VMethodFrame frame(*junction, method_frame); | VMethodFrame frame(*junction, method_frame); |
| METHOD_FRAME_ACTION(op_call(frame, false)); | |
| if(local_ops){ // store param code goes here | |
| size_t first = stack.top_index(); | |
| execute(*local_ops); | |
| frame.store_params((Value**)stack.ptr(first), stack.top_index()-first); | |
| op_call(frame); | |
| stack.set_top_index(first); | |
| } else { | |
| frame.empty_params(); | |
| op_call(frame); | |
| } | |
| stack.push(frame.result().as_value()); | stack.push(frame.result().as_value()); |
| DEBUG_PRINT_STR("<-returned") | DEBUG_PRINT_STR("<-returned") |
| Line 801 void Request::execute(ArrayOperation& op | Line 789 void Request::execute(ArrayOperation& op |
| #ifdef OPTIMIZE_CALL | #ifdef OPTIMIZE_CALL |
| const Method& method=*junction->method; | const Method& method=*junction->method; |
| if (!wcontext->get_constructing() && method.call_optimization==Method::CO_WITHOUT_FRAME){ | if(method.call_optimization==Method::CO_WITHOUT_FRAME){ |
| if(local_ops){ // store param code goes here | if(local_ops){ // store param code goes here |
| size_t first = stack.top_index(); | size_t first = stack.top_index(); |
| execute(*local_ops); | execute(*local_ops); |
| Line 817 void Request::execute(ArrayOperation& op | Line 805 void Request::execute(ArrayOperation& op |
| method.check_actual_numbered_params(junction->self, &method_params); | method.check_actual_numbered_params(junction->self, &method_params); |
| method.native_code(*this, method_params); // execute it | method.native_code(*this, method_params); // execute it |
| } | } |
| } else if (!wcontext->get_constructing() && method.call_optimization==Method::CO_WITHOUT_WCONTEXT){ | } else if(method.call_optimization==Method::CO_WITHOUT_WCONTEXT){ |
| VMethodFrame frame(*junction, method_frame); | VMethodFrame frame(*junction, method_frame); |
| if(local_ops){ // store param code goes here | METHOD_FRAME_ACTION(op_call_write(frame)); |
| size_t first = stack.top_index(); | |
| execute(*local_ops); | |
| frame.store_params((Value**)stack.ptr(first), stack.top_index()-first); | |
| op_call_write(frame); | |
| stack.set_top_index(first); | |
| } else { | |
| frame.empty_params(); | |
| op_call_write(frame); | |
| } | |
| } else | } else |
| #endif // OPTIMIZE_CALL | #endif // OPTIMIZE_CALL |
| { | { |
| VMethodFrame frame(*junction, method_frame); | VMethodFrame frame(*junction, method_frame); |
| if(local_ops){ // store param code goes here | METHOD_FRAME_ACTION(op_call(frame, false)); |
| size_t first = stack.top_index(); | |
| execute(*local_ops); | |
| frame.store_params((Value**)stack.ptr(first), stack.top_index()-first); | |
| op_call(frame); | |
| stack.set_top_index(first); | |
| } else { | |
| frame.empty_params(); | |
| op_call(frame); | |
| } | |
| write_pass_lang(frame.result()); | write_pass_lang(frame.result()); |
| } | } |
| Line 863 void Request::execute(ArrayOperation& op | Line 829 void Request::execute(ArrayOperation& op |
| break; | break; |
| } | } |
| #ifdef OPTIMIZE_BYTECODE_CONSTRUCT_OBJECT | |
| case OP::OP_CONSTRUCT_OBJECT: | case OP::OP_CONSTRUCT_OBJECT: |
| case OP::OP_CONSTRUCT_OBJECT__WRITE: | case OP::OP_CONSTRUCT_OBJECT__WRITE: |
| { | { |
| // maybe they do ^class:method[] call, remember the fact | |
| wcontext->set_somebody_entered_some_class(); | |
| debug_origin=i.next().origin; | debug_origin=i.next().origin; |
| Value& vclass_name=*i.next().value; | Value& vclass_name=*i.next().value; |
| const String& class_name=*vclass_name.get_string(); | const String& class_name=*vclass_name.get_string(); |
| Line 882 void Request::execute(ArrayOperation& op | Line 844 void Request::execute(ArrayOperation& op |
| &class_name, | &class_name, |
| "class is undefined"); | "class is undefined"); |
| wcontext->set_constructing(true); | |
| debug_origin=i.next().origin; | debug_origin=i.next().origin; |
| Value& vconstructor_name=*i.next().value; | Value& vconstructor_name=*i.next().value; |
| const String& constructor_name=*vconstructor_name.get_string(); debug_name=&constructor_name; | const String& constructor_name=*vconstructor_name.get_string(); debug_name=&constructor_name; |
| Line 892 void Request::execute(ArrayOperation& op | Line 852 void Request::execute(ArrayOperation& op |
| Value& constructor_value=get_element(*class_value, constructor_name); | Value& constructor_value=get_element(*class_value, constructor_name); |
| Junction* junction=constructor_value.get_junction(); | |
| if(!junction) | |
| throw Exception(PARSER_RUNTIME, | |
| &constructor_name, | |
| "constructor must be declared in class '%s'", | |
| class_value->get_class()->name_cstr()); | |
| ArrayOperation* local_ops=i.next().ops; | ArrayOperation* local_ops=i.next().ops; |
| DEBUG_PRINT_OPS(local_ops) | DEBUG_PRINT_OPS(local_ops) |
| DEBUG_PRINT_STR("->\n") | DEBUG_PRINT_STR("->\n") |
| Junction* junction=constructor_value.get_junction(); | Junction casted=Junction(*class_value, junction->method); |
| if(!junction) { | VMethodFrame frame(casted, method_frame); |
| if(constructor_value.is("void")) | |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "undefined method"); | |
| else | |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "is '%s', not a method or junction, can not call it", | |
| constructor_value.type()); | |
| } else { | |
| VMethodFrame frame(*junction, method_frame); | |
| if(local_ops){ // store param code goes here | |
| size_t first = stack.top_index(); | |
| execute(*local_ops); | |
| frame.store_params((Value**)stack.ptr(first), stack.top_index()-first); | |
| op_call(frame); | |
| stack.set_top_index(first); | METHOD_FRAME_ACTION(op_call(frame, true /* constructing */)); |
| } else { | if(opcode==OP::OP_CONSTRUCT_OBJECT) |
| frame.empty_params(); | stack.push(frame.result().as_value()); |
| op_call(frame); | else |
| } | write_pass_lang(frame.result()); |
| if(opcode==OP::OP_CONSTRUCT_OBJECT) | |
| stack.push(frame.result().as_value()); | |
| else | |
| write_pass_lang(frame.result()); | |
| } | |
| DEBUG_PRINT_STR("<-returned") | DEBUG_PRINT_STR("<-returned") |
| /* | |
| if(get_skip()) | |
| return; | |
| if(get_interrupted()) { | |
| set_interrupted(false); | |
| throw Exception("parser.interrupted", | |
| 0, | |
| "execution stopped"); | |
| } | |
| */ | |
| break; | break; |
| } | } |
| #endif // OPTIMIZE_BYTECODE_CONSTRUCT_OBJECT | |
| // expression ops: unary | // expression ops: unary |
| case OP::OP_NEG: | case OP::OP_NEG: |
| Line 1276 void Request::execute(ArrayOperation& op | Line 1207 void Request::execute(ArrayOperation& op |
| rcontext=saved_rcontext; \ | rcontext=saved_rcontext; \ |
| method_frame=saved_method_frame; | method_frame=saved_method_frame; |
| void Request::op_call(VMethodFrame& frame){ | void Request::op_call(VMethodFrame& frame, bool constructing){ |
| const Junction &junction=frame.junction; | const Junction &junction=frame.junction; |
| VStateless_class& called_class=*junction.self.get_class(); | VStateless_class& called_class=*junction.self.get_class(); |
| Value* new_self; | Value* new_self; |
| if(wcontext->get_constructing()) { | if(constructing) { |
| wcontext->set_constructing(false); | |
| if(junction.method->call_type!=Method::CT_STATIC) { | if(junction.method->call_type!=Method::CT_STATIC) { |
| // this is a constructor call | // this is a constructor call |
| if(new_self=called_class.create_new_value(fpool, 0 /*creating fields only in VClass*/)) { | if(new_self=called_class.create_new_value(fpool)) { |
| // some stateless_class creatable derivates | // some stateless_class creatable derivates |
| } else | } else |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| Line 1362 void Request::op_call_write(VMethodFrame | Line 1292 void Request::op_call_write(VMethodFrame |
| method_frame=saved_method_frame; | method_frame=saved_method_frame; |
| } | } |
| /** | |
| @bug ^superbase:method would dynamically call ^base:method if there is any | |
| */ | |
| Value& Request::get_element(Value& ncontext, const String& name) { | Value& Request::get_element(Value& ncontext, const String& name) { |
| if(!wcontext->get_constructing() // not constructing | if(wcontext->get_somebody_entered_some_class()) // ^class:method |
| && wcontext->get_somebody_entered_some_class() ) // ^class:method | if(VStateless_class *called_class=ncontext.get_class()) |
| if(VStateless_class *called_class=ncontext.get_class()) | if(VStateless_class *read_class=rcontext->get_class()) |
| if(VStateless_class *read_class=rcontext->get_class()) | if(read_class->derived_from(*called_class)){ // current derived from called |
| if(read_class->derived_from(*called_class)) // current derived from called | Value *value=called_class->get_element(get_self(), name); |
| if(Value* base=get_self().base()) { // doing DYNAMIC call | return *(value ? &process_to_value(*value) : VVoid::get()); |
| Temp_derived temp_derived(*base, 0); // temporarily prevent go-back-down virtual calls | } |
| Value *value=base->get_element(name, *base, true); // virtual-up lookup starting from parent | |
| return *(value ? &process_to_value(*value) : VVoid::get()); | |
| } | |
| Value* value=ncontext.get_element(name, ncontext, true); | |
| if(value && wcontext->get_constructing()) | Value* value=ncontext.get_element(name); |
| if(Junction* junction=value->get_junction()) | |
| if(junction->self.get_class()!=&ncontext) | |
| throw Exception(PARSER_RUNTIME, | |
| &name, | |
| "constructor must be declared in class '%s'", | |
| ncontext.get_class()->name_cstr()); | |
| return *(value ? &process_to_value(*value) : VVoid::get()); | return *(value ? &process_to_value(*value) : VVoid::get()); |
| } | } |
| void Request::put_element(Value& ncontext, const String& name, Value* value) { | void Request::put_element(Value& ncontext, const String& name, Value* value) { |
| // put_element can return property-setting-junction | // put_element can return property-setting-junction |
| if(const VJunction* vjunction=ncontext.put_element(ncontext, name, value, false)) | if(const VJunction* vjunction=ncontext.put_element(name, value, false)) |
| if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) { | if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) { |
| // process it | // process it |
| VMethodFrame frame(vjunction->junction(), method_frame/*caller*/); | VMethodFrame frame(vjunction->junction(), method_frame/*caller*/); |
| int param_count=frame.method_params_count(); | |
| size_t param_count=frame.method_params_count(); | |
| if(param_count!=1) | if(param_count!=1) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| Line 1437 StringOrValue Request::process(Value& in | Line 1353 StringOrValue Request::process(Value& in |
| if(junction) { | if(junction) { |
| if(junction->is_getter) { // is it a getter-junction? | if(junction->is_getter) { // is it a getter-junction? |
| VMethodFrame frame(*junction, method_frame/*caller*/); | VMethodFrame frame(*junction, method_frame/*caller*/); |
| int param_count=frame.method_params_count(); | |
| if(param_count){ | if(size_t param_count=frame.method_params_count()){ |
| if(junction->auto_name){ // default getter | if(junction->auto_name){ // default getter |
| if(param_count==1){ | if(param_count==1){ |
| Value *param=new VString(*junction->auto_name); | Value *param=new VString(*junction->auto_name); |
| Line 1477 StringOrValue Request::process(Value& in | Line 1392 StringOrValue Request::process(Value& in |
| if(!junction->method_frame) | if(!junction->method_frame) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| "junction used outside of context"); | "junction used outside of context"); |
| SAVE_CONTEXT | SAVE_CONTEXT |
| Line 1502 StringOrValue Request::process(Value& in | Line 1417 StringOrValue Request::process(Value& in |
| result=wcontext->result(); | result=wcontext->result(); |
| } else { | } else { |
| // plain wwrapper | // plain wwrapper |
| WWrapper local(0/*empty*/, wcontext); | WWrapper local(wcontext); |
| wcontext=&local; | wcontext=&local; |
| // execute it | // execute it |
| Line 1530 void Request::process_write(Value& input | Line 1445 void Request::process_write(Value& input |
| if(junction) { | if(junction) { |
| if(junction->is_getter) { // is it a getter-junction? | if(junction->is_getter) { // is it a getter-junction? |
| VMethodFrame frame(*junction, method_frame/*caller*/); | VMethodFrame frame(*junction, method_frame/*caller*/); |
| int param_count=frame.method_params_count(); | |
| if(param_count){ | if(size_t param_count=frame.method_params_count()){ |
| if(junction->auto_name){ // default getter | if(junction->auto_name){ // default getter |
| if(param_count==1){ | if(param_count==1){ |
| Value *param=new VString(*junction->auto_name); | Value *param=new VString(*junction->auto_name); |
| Line 1599 void Request::process_write(Value& input | Line 1513 void Request::process_write(Value& input |
| write_pass_lang(local.result()); | write_pass_lang(local.result()); |
| } else { | } else { |
| // plain wwrapper | // plain wwrapper |
| WWrapper local(0/*empty*/, wcontext); | WWrapper local(wcontext); |
| wcontext=&local; | wcontext=&local; |
| // execute it | // execute it |
| Line 1685 Request::execute_nonvirtual_method(VStat | Line 1599 Request::execute_nonvirtual_method(VStat |
| const String* Request::execute_virtual_method(Value& aself, | const String* Request::execute_virtual_method(Value& aself, |
| const String& method_name) { | const String& method_name) { |
| if(Value* value=aself.get_element(method_name, aself, false)) | 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) |
| return execute_method(aself, *method, 0/*no params*/, true); | return execute_method(aself, *method, 0/*no params*/, true); |