Created
September 11, 2008 22:09
-
-
Save rue/10327 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This method always executes on the separate stack created for the context. | |
* | |
* Fortunately for us, Message always has an Array of arguments. | |
* | |
* Arity -3: VALUE func(VALUE argument_array); | |
* Arity -2: VALUE func(VALUE receiver, VALUE argument_array); | |
* Arity -1: VALUE func(int argument_count, VALUE*, VALUE receiver); | |
* Otherwise: VALUE func(VALUE receiver, VALUE arg1[, VALUE arg2, ...]); // Currently max 10 args | |
* | |
* TODO: Argument count check? | |
* TODO: Check for inefficiencies. | |
*/ | |
void VMNativeMethod::perform_call() | |
{ | |
NativeMethodContext* context = NativeMethodContext::current(); | |
NativeMethod::PointerTo c_method = context->method->actual_function_object(); | |
Message* message = context->message; | |
HandleTo receiver(context->handles, message->recv); | |
switch (context->method->arity()->to_int()) { | |
case ARGS_IN_RUBY_ARRAY: { /* Braces required to create objects in a switch */ | |
HandleTo args(context->handles, message->arguments); | |
context->return_value = c_method(args); | |
break; | |
} | |
case RECEIVER_PLUS_ARGS_IN_RUBY_ARRAY: { | |
HandleTo args(context->handles, message->arguments); | |
context->return_value = c_method(receiver, args); | |
break; | |
} | |
// | |
// case ARG_COUNT_ARGS_IN_C_ARRAY_PLUS_RECEIVER: { | |
// | |
// for (std::size_t i = 0; i < message->total_args; ++i) { | |
// HandleTo(context->handles, message->arguments->get(context->state, i)); | |
// } | |
// | |
// context->return_value = c_method( message->total_args | |
// , &context->handles[1] /* Guaranteed to produce an array-like pointer. 1 leaves out receiver. */ | |
// , receiver); | |
// | |
// break; | |
// } | |
default: | |
sassert(false && "Not a valid arity, wth?"); | |
} | |
context->action = NativeMethodContext::RETURN_FROM_C; | |
jump_to_execution_point_in(context->dispatch_point); | |
/* Never actually returns, control never reaches here. */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment