本文整理汇总了C++中NativeMethod::arity方法的典型用法代码示例。如果您正苦于以下问题:C++ NativeMethod::arity方法的具体用法?C++ NativeMethod::arity怎么用?C++ NativeMethod::arity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NativeMethod
的用法示例。
在下文中一共展示了NativeMethod::arity方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: executor_implementation
Object* NativeMethod::executor_implementation(STATE,
CallFrame* call_frame, Dispatch& msg, Arguments& args) {
NativeMethod* nm = as<NativeMethod>(msg.method);
int arity = nm->arity()->to_int();
if(arity >= 0 && (size_t)arity != args.total()) {
Exception* exc = Exception::make_argument_error(
state, arity, args.total(), msg.name);
exc->locations(state, System::vm_backtrace(state, Fixnum::from(1), call_frame));
state->thread_state()->raise_exception(exc);
return NULL;
}
NativeMethodEnvironment* env = native_method_environment.get();
NativeMethodFrame nmf(env->current_native_frame());
CallFrame* saved_frame = env->current_call_frame();
Object* saved_block = env->block();
env->set_current_call_frame(call_frame);
env->set_current_native_frame(&nmf);
env->set_current_block(args.block());
Object* ret;
ExceptionPoint ep(env);
PLACE_EXCEPTION_POINT(ep);
if(unlikely(ep.jumped_to())) {
ret = NULL;
} else {
#ifdef RBX_PROFILER
if(unlikely(state->shared.profiling())) {
profiler::MethodEntry method(state, msg, args);
ret = nm->call(state, env, args);
} else {
ret = nm->call(state, env, args);
}
#else
ret = nm->call(state, env, args);
#endif
}
env->set_current_block(saved_block);
env->set_current_call_frame(saved_frame);
env->set_current_native_frame(nmf.previous());
ep.pop(env);
return ret;
}
示例2: create
NativeMethod* NativeMethod::create(State* state, String* file_name,
Module* module, Symbol* method_name,
void* func, Fixnum* arity)
{
NativeMethod* nmethod = state->new_object<NativeMethod>(G(nmethod));
nmethod->arity(state, arity);
nmethod->file(state, file_name);
nmethod->name(state, method_name);
nmethod->module(state, module);
nmethod->func_ = func;
switch(arity->to_native()) {
case 0:
nmethod->set_executor(&NativeMethod::executor_implementation<ZeroArguments>);
break;
case 1:
nmethod->set_executor(&NativeMethod::executor_implementation<OneArgument>);
break;
case 2:
nmethod->set_executor(&NativeMethod::executor_implementation<TwoArguments>);
break;
case 3:
nmethod->set_executor(&NativeMethod::executor_implementation<ThreeArguments>);
break;
default:
nmethod->set_executor(&NativeMethod::executor_implementation<GenericArguments>);
break;
}
nmethod->primitive(state, state->symbol("nativemethod_call"));
nmethod->serial(state, Fixnum::from(0));
nmethod->inliners_ = 0;
return nmethod;
}
示例3: create
static NativeMethod* create(VM* state,
String* file_name = as<String>(Qnil),
Module* module = as<Module>(Qnil),
Symbol* method_name = as<Symbol>(Qnil),
FunctorType functor = static_cast<GenericFunctor>(NULL),
Fixnum* arity = as<Fixnum>(Qnil))
{
NativeMethod* nmethod = state->new_object<NativeMethod>(G(nmethod));
nmethod->arity(state, arity);
nmethod->file_name(state, file_name);
nmethod->method_name(state, method_name);
nmethod->module(state, module);
nmethod->functor(state, MemoryPointer::create(state, reinterpret_cast<void*>(functor)));
nmethod->set_executor(&NativeMethod::executor_implementation);
nmethod->primitive(state, state->symbol("nativemethod_call"));
nmethod->serial(state, Fixnum::from(0));
return nmethod;
}
示例4: executor_implementation
Object* NativeMethod::executor_implementation(STATE,
CallFrame* call_frame, Dispatch& msg, Arguments& args) {
NativeMethod* nm = as<NativeMethod>(msg.method);
int arity = nm->arity()->to_int();
if(arity >= 0 && (size_t)arity != args.total()) {
Exception* exc = Exception::make_argument_error(
state, arity, args.total(), msg.name);
exc->locations(state, Location::from_call_stack(state, call_frame));
state->thread_state()->raise_exception(exc);
return NULL;
}
NativeMethodEnvironment* env = native_method_environment.get();
// Optionally get the handles back to the proper state.
if(state->shared.config.capi_global_flush) {
capi::Handles* handles = state->shared.cached_handles();
if(handles->size() > 0) {
for(capi::Handles::Iterator i(*handles); i.more(); i.advance()) {
i->update(env);
}
}
}
// Register the CallFrame, because we might GC below this.
state->set_call_frame(call_frame);
NativeMethodFrame nmf(env->current_native_frame());
CallFrame* saved_frame = env->current_call_frame();
env->set_current_call_frame(call_frame);
env->set_current_native_frame(&nmf);
// Be sure to do this after installing nmf as the current
// native frame.
nmf.setup(
env->get_handle(args.recv()),
env->get_handle(args.block()),
env->get_handle(msg.method),
env->get_handle(msg.module));
Object* ret;
ExceptionPoint ep(env);
PLACE_EXCEPTION_POINT(ep);
if(unlikely(ep.jumped_to())) {
ret = NULL;
} else {
#ifdef RBX_PROFILER
if(unlikely(state->tooling())) {
tooling::MethodEntry method(state, msg, args);
ret = ArgumentHandler::invoke(state, nm, env, args);
} else {
ret = ArgumentHandler::invoke(state, nm, env, args);
}
#else
ret = ArgumentHandler::invoke(state, nm, env, args);
#endif
}
env->set_current_call_frame(saved_frame);
env->set_current_native_frame(nmf.previous());
ep.pop(env);
// Handle any signals that occurred while the native method
// was running.
if(!state->check_async(call_frame)) return NULL;
return ret;
}
示例5: executor_implementation
Object* NativeMethod::executor_implementation(STATE,
CallFrame* previous, Executable* exec, Module* mod, Arguments& args) {
NativeMethod* nm = as<NativeMethod>(exec);
int arity = nm->arity()->to_int();
if(arity >= 0 && (size_t)arity != args.total()) {
Exception* exc = Exception::make_argument_error(
state, arity, args.total(), args.name());
exc->locations(state, Location::from_call_stack(state, previous));
state->raise_exception(exc);
return NULL;
}
NativeMethodEnvironment* env = native_method_environment.get();
// Optionally get the handles back to the proper state.
if(state->shared().config.capi_global_flush) {
std::list<capi::Handle*>* handles = env->state()->memory()->cached_capi_handles();
for(std::list<capi::Handle*>::iterator i = handles->begin();
i != handles->end();
++i) {
(*i)->update(env);
}
}
NativeMethodFrame nmf(env->current_native_frame());
CallFrame* call_frame = ALLOCA_CALLFRAME(0);
call_frame->previous = previous;
call_frame->constant_scope_ = 0;
call_frame->dispatch_data = (void*)&nmf;
call_frame->compiled_code = 0;
call_frame->flags = CallFrame::cNativeMethod;
call_frame->optional_jit_data = 0;
call_frame->top_scope_ = 0;
call_frame->scope = 0;
call_frame->arguments = &args;
CallFrame* saved_frame = env->current_call_frame();
env->set_current_call_frame(call_frame);
env->set_current_native_frame(&nmf);
// Register the CallFrame, because we might GC below this.
state->set_call_frame(call_frame);
// Be sure to do this after installing nmf as the current
// native frame.
nmf.setup(
env->get_handle(args.recv()),
env->get_handle(args.block()),
env->get_handle(exec),
env->get_handle(mod));
// We've got things setup (they can be GC'd properly), so we need to
// wait before entering the extension code.
ENTER_CAPI(state);
Object* ret;
ExceptionPoint ep(env);
#ifdef RBX_PROFILER
// This is organized like this so that we don't jump past the destructor of
// MethodEntry. It's duplicated, but it's much easier to understand than
// trying to de-dup it.
OnStack<2> os(state, exec, mod);
if(unlikely(state->vm()->tooling())) {
tooling::MethodEntry method(state, exec, mod, args);
RUBINIUS_METHOD_NATIVE_ENTRY_HOOK(state, mod, args.name(), call_frame);
PLACE_EXCEPTION_POINT(ep);
if(unlikely(ep.jumped_to())) {
ret = NULL;
} else {
ret = ArgumentHandler::invoke(state, nm, env, args);
}
RUBINIUS_METHOD_NATIVE_RETURN_HOOK(state, mod, args.name(), call_frame);
} else {
RUBINIUS_METHOD_NATIVE_ENTRY_HOOK(state, mod, args.name(), call_frame);
PLACE_EXCEPTION_POINT(ep);
if(unlikely(ep.jumped_to())) {
ret = NULL;
} else {
ret = ArgumentHandler::invoke(state, nm, env, args);
}
RUBINIUS_METHOD_NATIVE_RETURN_HOOK(state, mod, args.name(), call_frame);
}
#else
RUBINIUS_METHOD_NATIVE_ENTRY_HOOK(state, mod, args.name(), call_frame);
PLACE_EXCEPTION_POINT(ep);
if(unlikely(ep.jumped_to())) {
ret = NULL;
//.........这里部分代码省略.........