Permalink
Browse files

Refactor Message out

  • Loading branch information...
Evan Phoenix
Evan Phoenix committed Apr 1, 2009
1 parent 5cd4fc9 commit 214fe7e549d10b1d1f17c5aecef82875bc0f2899
Showing with 840 additions and 814 deletions.
  1. +37 −1 vm/arguments.hpp
  2. +10 −9 vm/builtin/access_variable.cpp
  3. +1 −1 vm/builtin/access_variable.hpp
  4. +1 −7 vm/builtin/autoload.cpp
  5. +19 −17 vm/builtin/block_environment.cpp
  6. +3 −3 vm/builtin/block_environment.hpp
  7. +16 −17 vm/builtin/compiledmethod.cpp
  8. +3 −3 vm/builtin/compiledmethod.hpp
  9. +7 −6 vm/builtin/executable.cpp
  10. +3 −1 vm/builtin/executable.hpp
  11. +19 −18 vm/builtin/nativefunction.cpp
  12. +2 −2 vm/builtin/nativefunction.hpp
  13. +29 −28 vm/builtin/nativemethod.cpp
  14. +3 −2 vm/builtin/nativemethod.hpp
  15. +22 −18 vm/builtin/object.cpp
  16. +2 −2 vm/builtin/object.hpp
  17. +23 −22 vm/builtin/proc.cpp
  18. +3 −3 vm/builtin/proc.hpp
  19. +207 −84 vm/builtin/sendsite.cpp
  20. +30 −24 vm/builtin/sendsite.hpp
  21. +2 −4 vm/builtin/variable_scope.cpp
  22. +4 −4 vm/builtin/variable_scope.hpp
  23. +13 −13 vm/codegen/field_extract.rb
  24. +3 −11 vm/compiled_file.cpp
  25. +35 −0 vm/dispatch.cpp
  26. +47 −0 vm/dispatch.hpp
  27. +3 −2 vm/executor.hpp
  28. +9 −18 vm/helpers.cpp
  29. +101 −81 vm/instructions.rb
  30. +6 −12 vm/llvm/instructions.cpp
  31. +18 −0 vm/lookup_data.hpp
  32. +0 −137 vm/message.cpp
  33. +2 −7 vm/message.hpp
  34. +1 −1 vm/primitives.cpp
  35. +1 −1 vm/primitives.hpp
  36. +4 −4 vm/profiler.cpp
  37. +6 −4 vm/profiler.hpp
  38. +17 −24 vm/test/test_access_variable.hpp
  39. +62 −62 vm/test/test_nativefunction.hpp
  40. +10 −12 vm/test/test_profiler.hpp
  41. +0 −8 vm/test/test_selector.hpp
  42. +0 −93 vm/test/test_sendsite.hpp
  43. +53 −45 vm/vmmethod.cpp
  44. +3 −3 vm/vmmethod.hpp
View
@@ -9,14 +9,34 @@ namespace rubinius {
class Array;
class Arguments {
+ Object* recv_;
+ Object* block_;
+
size_t total_;
Object** arguments_;
Array* array_;
public:
+ Arguments(Object* recv, Object* block, size_t total, Object** buffer)
+ : recv_(recv)
+ , block_(block)
+ , total_(total)
+ , arguments_(buffer)
+ , array_(0)
+ {}
+
+ Arguments(Object* recv, size_t total, Object** buffer)
+ : recv_(recv)
+ , block_(Qnil)
+ , total_(total)
+ , arguments_(buffer)
+ , array_(0)
+ {}
Arguments(size_t total, Object** buffer)
- : total_(total)
+ : recv_(0)
+ , block_(Qnil)
+ , total_(total)
, arguments_(buffer)
, array_(0)
{}
@@ -31,6 +51,22 @@ namespace rubinius {
use_array(ary);
}
+ Object* recv() {
+ return recv_;
+ }
+
+ void set_recv(Object* val) {
+ recv_ = val;
+ }
+
+ Object* block() {
+ return block_;
+ }
+
+ void set_block(Object* val) {
+ block_ = val;
+ }
+
Object* get_argument(size_t which) {
return arguments_[which];
}
@@ -25,27 +25,28 @@ namespace rubinius {
}
/* Run when an AccessVariable is executed. Uses the details in msg.method
- * to access instance variables of msg.recv */
- Object* AccessVariable::access_execute(STATE, CallFrame* call_frame, Message& msg) {
+ * to access instance variables of args.recv() */
+ Object* AccessVariable::access_execute(STATE, CallFrame* call_frame, Dispatch& msg,
+ Arguments& args) {
AccessVariable* access = as<AccessVariable>(msg.method);
/* The writer case. */
if(access->write()->true_p()) {
- if(msg.args() != 1) {
- Exception::argument_error(state, 1, msg.args());
+ if(args.total() != 1) {
+ Exception::argument_error(state, 1, args.total());
}
/* Fall through, handle it as a normal ivar. */
- msg.recv->set_ivar(state, access->name(), msg.get_argument(0));
- return msg.get_argument(0);
+ args.recv()->set_ivar(state, access->name(), args.get_argument(0));
+ return args.get_argument(0);
}
/* The read case. */
- if(msg.args() != 0) {
- Exception::argument_error(state, 0, msg.args());
+ if(args.total() != 0) {
+ Exception::argument_error(state, 0, args.total());
return NULL;
} else {
- return msg.recv->get_ivar(state, access->name());
+ return args.recv()->get_ivar(state, access->name());
}
}
}
@@ -30,7 +30,7 @@ namespace rubinius {
static void init(STATE);
// Ruby.primitive :accessvariable_allocate
static AccessVariable* allocate(STATE);
- static Object* access_execute(STATE, CallFrame* call_frame, Message& msg);
+ static Object* access_execute(STATE, CallFrame* call_frame, Dispatch& msg, Arguments& args);
class Info : public TypeInfo {
public:
View
@@ -15,12 +15,6 @@ namespace rubinius {
}
Object* Autoload::resolve(STATE, CallFrame* call_frame) {
- Message msg(G(sym_call),
- this,
- 0,
- Qnil,
- this->lookup_begin(state));
-
- return msg.send(state, call_frame);
+ return send(state, call_frame, G(sym_call));
}
}
@@ -81,12 +81,12 @@ namespace rubinius {
}
/** @todo See above. --rue */
- Object* BlockEnvironment::call(STATE, CallFrame* call_frame, Message& msg, int flags) {
+ Object* BlockEnvironment::call(STATE, CallFrame* call_frame, Arguments& args, int flags) {
Object* val;
- if(msg.args() > 0) {
- Tuple* tup = Tuple::create(state, msg.args());
- for(int i = msg.args() - 1; i >= 0; i--) {
- tup->put(state, i, msg.get_argument(i));
+ if(args.total() > 0) {
+ Tuple* tup = Tuple::create(state, args.total());
+ for(int i = args.total() - 1; i >= 0; i--) {
+ tup->put(state, i, args.get_argument(i));
}
val = tup;
@@ -106,7 +106,7 @@ namespace rubinius {
frame->previous = call_frame;
frame->name = name_;
frame->cm = method_;
- frame->args = msg.args();
+ frame->args = args.total();
frame->scope = scope;
frame->top_scope = top_scope_;
frame->flags = flags;
@@ -117,28 +117,30 @@ namespace rubinius {
return VMMethod::run_interpreter(state, vmm, frame);
}
- Object* BlockEnvironment::call_prim(STATE, Executable* exec, CallFrame* call_frame, Message& msg) {
- return call(state, call_frame, msg);
+ Object* BlockEnvironment::call_prim(STATE, Executable* exec, CallFrame* call_frame, Dispatch& msg,
+ Arguments& args) {
+ return call(state, call_frame, args);
}
/** @todo See above. --emp */
- Object* BlockEnvironment::call_on_object(STATE, CallFrame* call_frame, Message& msg, int flags) {
+ Object* BlockEnvironment::call_on_object(STATE, CallFrame* call_frame,
+ Arguments& args, int flags) {
Object* val;
- if(msg.args() < 1) {
+ if(args.total() < 1) {
Exception* exc =
- Exception::make_argument_error(state, 1, msg.args(), state->symbol("__block__"));
+ Exception::make_argument_error(state, 1, args.total(), state->symbol("__block__"));
exc->locations(state, System::vm_backtrace(state, Fixnum::from(0), call_frame));
state->thread_state()->raise_exception(exc);
return NULL;
}
- Object* recv = msg.get_argument(0);
+ Object* recv = args.get_argument(0);
- if(msg.args() > 1) {
- Tuple* tup = Tuple::create(state, msg.args() - 1);
- for(size_t i = 0, j = 1; j < msg.args(); i++, j++) {
- tup->put(state, i, msg.get_argument(j));
+ if(args.total() > 1) {
+ Tuple* tup = Tuple::create(state, args.total() - 1);
+ for(size_t i = 0, j = 1; j < args.total(); i++, j++) {
+ tup->put(state, i, args.get_argument(j));
}
val = tup;
@@ -158,7 +160,7 @@ namespace rubinius {
frame->previous = call_frame;
frame->name = name_;
frame->cm = method_;
- frame->args = msg.args();
+ frame->args = args.total();
frame->scope = scope;
frame->top_scope = top_scope_;
frame->flags = flags;
@@ -47,13 +47,13 @@ namespace rubinius {
VMMethod* caller, CallFrame* call_frame, size_t index);
Object* call(STATE, CallFrame* call_frame, size_t args, int flags=0);
- Object* call(STATE, CallFrame* call_frame, Message& msg, int flags=0);
+ Object* call(STATE, CallFrame* call_frame, Arguments& args, int flags=0);
BlockContext* create_context(STATE, MethodContext* sender);
// Ruby.primitive? :block_call
- Object* call_prim(STATE, Executable* exec, CallFrame* call_frame, Message& msg);
+ Object* call_prim(STATE, Executable* exec, CallFrame* call_frame, Dispatch& msg, Arguments& args);
- Object* call_on_object(STATE, CallFrame* call_frame, Message& msg, int flags=0);
+ Object* call_on_object(STATE, CallFrame* call_frame, Arguments& args, int flags=0);
BlockEnvironment* dup(STATE);
@@ -89,9 +89,10 @@ namespace rubinius {
return backend_method_;
}
- Object* CompiledMethod::primitive_failed(STATE, CallFrame* call_frame, Message& msg) {
+ Object* CompiledMethod::primitive_failed(STATE, CallFrame* call_frame, Dispatch& msg,
+ Arguments& args) {
if(try_as<CompiledMethod>(msg.method)) {
- return VMMethod::execute(state, call_frame, msg);
+ return VMMethod::execute(state, call_frame, msg, args);
}
// TODO fix me to raise an exception
@@ -110,12 +111,13 @@ namespace rubinius {
return this;
}
- Object* CompiledMethod::default_executor(STATE, CallFrame* call_frame, Message& msg) {
+ Object* CompiledMethod::default_executor(STATE, CallFrame* call_frame, Dispatch& msg,
+ Arguments& args) {
CompiledMethod* cm = as<CompiledMethod>(msg.method);
cm->formalize(state, false);
// Refactor
cm->backend_method_->find_super_instructions();
- return cm->execute(state, call_frame, msg);
+ return cm->execute(state, call_frame, msg, args);
}
void CompiledMethod::post_marshal(STATE) {
@@ -132,26 +134,23 @@ namespace rubinius {
return local_count_->to_native();
}
- Object* CompiledMethod::activate(STATE, Executable* exec, CallFrame* call_frame, Message& msg) {
- CompiledMethod* meth = as<CompiledMethod>(msg.recv);
- Object* recv = msg.get_argument(0);
- Module* mod = as<Module>(msg.get_argument(1));
- Array* args = as<Array>(msg.get_argument(2));
+ Object* CompiledMethod::activate(STATE, Executable* exec, CallFrame* call_frame, Dispatch& msg,
+ Arguments& args) {
+ CompiledMethod* meth = as<CompiledMethod>(args.recv());
+ Object* recv = args.get_argument(0);
+ Module* mod = as<Module>(args.get_argument(1));
+ Array* ary = as<Array>(args.get_argument(2));
// Leave msg.block set and pass it through.
- msg.recv = recv;
- msg.method = meth;
- msg.module = mod;
- msg.set_arguments(state, args);
- msg.name = meth->name();
- msg.priv = true;
- msg.method_missing = false;
+ Dispatch disp(meth->name(), mod, meth);
+ Arguments new_args(recv, 0, 0);
+ new_args.use_array(ary);
// NOTE even when we're activating a method_missing, we don't
// push the name given, because there really isn't one. So if
// this is used to call a method_missing, you have to supply all
// the args.
- return meth->execute(state, call_frame, msg);
+ return meth->execute(state, call_frame, disp, new_args);
}
MachineMethod* CompiledMethod::make_machine_method(STATE) {
@@ -60,7 +60,7 @@ namespace rubinius {
// Ruby.primitive :compiledmethod_allocate
static CompiledMethod* create(STATE);
- static Object* primitive_failed(STATE, CallFrame* call_frame, Message& msg);
+ static Object* primitive_failed(STATE, CallFrame* call_frame, Dispatch& msg, Arguments& args);
int start_line(STATE);
int line(STATE, int ip);
@@ -70,7 +70,7 @@ namespace rubinius {
VMMethod* formalize(STATE, bool ondemand=true);
void specialize(STATE, TypeInfo* ti);
- static Object* default_executor(STATE, CallFrame*, Message&);
+ static Object* default_executor(STATE, CallFrame*, Dispatch&, Arguments& args);
// Ruby.primitive :compiledmethod_compile
Object* compile(STATE);
@@ -79,7 +79,7 @@ namespace rubinius {
MachineMethod* make_machine_method(STATE);
// Ruby.primitive? :compiledmethod_activate
- Object* activate(STATE, Executable* exec, CallFrame* call_frame, Message& msg);
+ Object* activate(STATE, Executable* exec, CallFrame* call_frame, Dispatch& msg, Arguments& args);
bool is_rescue_target(STATE, int ip);
View
@@ -41,11 +41,12 @@ namespace rubinius {
}
- Object* Executable::default_executor(STATE, CallFrame* call_frame, Message& msg) {
- msg.arguments().unshift2(state, msg.recv, msg.name);
- msg.name = state->symbol("call");
- msg.recv = msg.method;
- msg.flush_lookup();
- return msg.send(state, call_frame);
+ Object* Executable::default_executor(STATE, CallFrame* call_frame, Dispatch& msg,
+ Arguments& args) {
+ args.unshift2(state, args.recv(), msg.name);
+ args.set_recv(msg.method);
+
+ Dispatch dis(state->symbol("call"));
+ return dis.send(state, call_frame, args);
}
}
@@ -9,6 +9,8 @@
namespace rubinius {
class MemoryPointer;
+ class Dispatch;
+ class Arguments;
class Executable : public Object {
public:
@@ -30,7 +32,7 @@ namespace rubinius {
/* interface */
static void init(STATE);
- static Object* default_executor(STATE, CallFrame* call_frame, Message& msg);
+ static Object* default_executor(STATE, CallFrame* call_frame, Dispatch& msg, Arguments& args);
bool resolve_primitive(STATE);
Oops, something went wrong.

0 comments on commit 214fe7e

Please sign in to comment.