当前位置: 首页>>代码示例>>C++>>正文


C++ Proc::block方法代码示例

本文整理汇总了C++中Proc::block方法的典型用法代码示例。如果您正苦于以下问题:C++ Proc::block方法的具体用法?C++ Proc::block怎么用?C++ Proc::block使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Proc的用法示例。


在下文中一共展示了Proc::block方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: from_env

  Proc* Proc::from_env(STATE, Object* env) {
    if(Proc* p = try_as<Proc>(env)) {
      return p;
    }

    if(BlockEnvironment* be = try_as<BlockEnvironment>(env)) {
      Proc* proc = Proc::create(state, G(proc));
      proc->block(state, be);
      return proc;
    }

    return reinterpret_cast<Proc*>(Primitives::failure());
  }
开发者ID:vasco,项目名称:rubinius,代码行数:13,代码来源:proc.cpp

示例2: from_env

  Proc* Proc::from_env(STATE, Object* self, Object* env) {
    if(Proc* p = try_as<Proc>(env)) {
      return p;
    }

    if(BlockEnvironment* be = try_as<BlockEnvironment>(env)) {
      Proc* proc = Proc::create(state, self);
      proc->block(state, be);
      return proc;
    }

    return NULL;
  }
开发者ID:Energy0124,项目名称:rubinius,代码行数:13,代码来源:proc.cpp

示例3: from_env

  Proc* Proc::from_env(STATE, Object* self, Object* env) {
    if(Proc* p = try_as<Proc>(env)) {
      if(p->klass() != self &&
         p->klass() != G(proc)->get_const(state, "Method")) {
        p = as<Proc>(p->duplicate(state));
        p->klass(state, as<Class>(self));
      }
      return p;
    }

    if(BlockEnvironment* be = try_as<BlockEnvironment>(env)) {
      Proc* proc = Proc::create(state, self);
      proc->block(state, be);
      return proc;
    }

    return reinterpret_cast<Proc*>(Primitives::failure());
  }
开发者ID:markburns,项目名称:rubinius,代码行数:18,代码来源:proc.cpp

示例4: call

  Object* Proc::call(STATE, Arguments& args) {
    bool lambda_style = CBOOL(lambda());
    int flags = 0;

    Proc* self = this;
    OnStack<1> os(state, self);
    // Check the arity in lambda mode
    if(lambda_style && !block()->nil_p()) {
      flags = CallFrame::cIsLambda;
      int total = self->block()->compiled_code()->total_args()->to_native();
      int required = self->block()->compiled_code()->required_args()->to_native();

      bool arity_ok = false;
      if(Fixnum* fix = try_as<Fixnum>(self->block()->compiled_code()->splat())) {
        switch(fix->to_native()) {
        case -2:
          arity_ok = true;
          break;
        case -4:
          // splat = -4 means { |(a, b)| }
          if(args.total() == 1) {
            Array* ary = 0;
            Object* obj = args.get_argument(0);

            if(!(ary = try_as<Array>(obj))) {
              if(CBOOL(obj->respond_to(state, G(sym_to_ary), cFalse))) {
                if(!(ary = try_as<Array>(obj->send(state, G(sym_to_ary))))) {
                  Exception::type_error(state, "to_ary must return an Array");
                  return 0;
                }
              }
            }

            if(ary) args.use_argument(ary);
          }
          // fall through for arity check
        case -3:
          // splat = -3 is used to distinguish { |a, | } from { |a| }
          if(args.total() == (size_t)required) arity_ok = true;
          break;
        default:
          if(args.total() >= (size_t)required) {
            arity_ok = true;
          }
        }

      } else {
        arity_ok = args.total() <= (size_t)total &&
                   args.total() >= (size_t)required;
      }

      if(!arity_ok) {
        Exception* exc =
          Exception::make_argument_error(state, required, args.total(),
              block()->compiled_code()->name());
        exc->locations(state, Location::from_call_stack(state));
        state->raise_exception(exc);
        return NULL;
      }
    }

    if(self->bound_method()->nil_p()) {
      if(self->block()->nil_p()) {
        Dispatch dispatch(state->symbol("__yield__"));
        return dispatch.send(state, args);
      } else {
        return self->block()->call(state, args, flags);
      }
    } else if(NativeMethod* nm = try_as<NativeMethod>(self->bound_method())) {
      return nm->execute(state, nm, G(object), args);
    } else if(NativeFunction* nf = try_as<NativeFunction>(self->bound_method())) {
      return nf->call(state, args);
    } else {
      Exception* exc =
        Exception::make_type_error(state, BlockEnvironment::type, self->bound_method(), "NativeMethod nor NativeFunction bound to proc");
      exc->locations(state, Location::from_call_stack(state));
      state->raise_exception(exc);
      return NULL;
    }
  }
开发者ID:JesseChavez,项目名称:rubinius,代码行数:80,代码来源:proc.cpp


注:本文中的Proc::block方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。