Time* Time::specific(STATE, Object* self, Integer* sec, Integer* nsec, Object* gmt, Object* offset) { Time* tm = state->new_object_dirty<Time>(as<Class>(self)); tm->seconds_ = sec->to_long_long(); tm->nanoseconds_ = nsec->to_native(); // Do a little overflow cleanup. if(tm->nanoseconds_ >= 1000000000) { tm->seconds_ += tm->nanoseconds_ / 1000000000; tm->nanoseconds_ %= 1000000000; } if(tm->nanoseconds_ < 0) { tm->seconds_ += NDIV(tm->nanoseconds_, 1000000000); tm->nanoseconds_ = NMOD(tm->nanoseconds_, 1000000000); } tm->decomposed(state, nil<Array>()); tm->is_gmt(state, RBOOL(CBOOL(gmt))); tm->offset(state, offset); tm->zone(state, nil<String>()); return tm; }
Object* Character::alphabetical_p(STATE) { bool found; int c = codepoint(state, &found); OnigEncodingType* enc = encoding()->get_encoding(); return RBOOL(found && ONIGENC_IS_CODE_ALPHA(enc, c)); }
Object* Character::punctuation_p(STATE) { bool found; int c = codepoint(state, &found); OnigEncodingType* enc = encoding()->get_encoding(); return RBOOL(found && ONIGENC_IS_CODE_PUNCT(enc, c)); }
Object* Character::lower_p(STATE) { bool found; int c = codepoint(state, &found); OnigEncodingType* enc = encoding()->get_encoding(); return RBOOL(found && ONIGENC_IS_CODE_LOWER(enc, c)); }
Array* Time::calculate_decompose(STATE) { if(!decomposed_->nil_p()) return decomposed_; struct tm64 tm = get_tm(); /* update Time::TM_FIELDS when changing order of fields */ Array* ary = Array::create(state, 11); ary->set(state, 0, Integer::from(state, tm.tm_sec)); ary->set(state, 1, Integer::from(state, tm.tm_min)); ary->set(state, 2, Integer::from(state, tm.tm_hour)); ary->set(state, 3, Integer::from(state, tm.tm_mday)); ary->set(state, 4, Integer::from(state, tm.tm_mon + 1)); ary->set(state, 5, Integer::from(state, tm.tm_year)); ary->set(state, 6, Integer::from(state, tm.tm_wday)); ary->set(state, 7, Integer::from(state, tm.tm_yday + 1)); ary->set(state, 8, RBOOL(tm.tm_isdst)); if (zone_->nil_p()) { if(offset_->nil_p() && tm.tm_zone) { zone(state, locale_string(state, tm.tm_zone)); } else { zone(state, nil<String>()); } } ary->set(state, 9, zone()); // Cache it. decomposed(state, ary); return ary; }
VALUE rb_range_new(VALUE beg, VALUE end, int exclude_end) { VALUE range = rb_obj_alloc(rb_cRange); range_init(range, beg, end, RBOOL(exclude_end)); return range; }
inline bool passed_blockarg(STATE, CallFrame* call_frame, intptr_t count) { if(!call_frame->arguments) { Exception::internal_error(state, "no arguments object"); return false; } stack_push(RBOOL(count == (int)call_frame->arguments->total())); return true; }
static VALUE range_initialize(int argc, VALUE *argv, VALUE range) { VALUE beg, end, flags; rb_scan_args(argc, argv, "21", &beg, &end, &flags); range_modify(range); range_init(range, beg, end, RBOOL(RTEST(flags))); return Qnil; }
// Rubinius.primitive+ :string_equal Object* equal(STATE, String* other) { if(encoding() != other->encoding() && Encoding::compatible_p(state, this, other)->nil_p()) return cFalse; if(this->num_bytes() != other->num_bytes()) return cFalse; int comp = memcmp( this->byte_address(), other->byte_address(), this->num_bytes()->to_native()); return RBOOL(comp == 0); }
Object* CompiledCode::is_breakpoint(STATE, Fixnum* ip) { int i = ip->to_native(); if(machine_code() == NULL) return cFalse; if(!machine_code()->validate_ip(state, i)) return Primitives::failure(); if(breakpoints()->nil_p()) return cFalse; bool found = false; breakpoints()->fetch(state, ip, &found); return RBOOL(found); }
static void bool_test(LTRandomGenerator *r) { int bcounts[2]; bcounts[0] = 0; bcounts[1] = 0; for (int i = 0; i < SAMPLE_SIZE; i++) { bcounts[RBOOL(r) ? 1 : 0]++; } printf("Bool:\n"); printf(" false: %d\n", bcounts[0]); printf(" true : %d\n", bcounts[1]); }
// RenderTexture#active=(flag) // RenderTexture#set_active(flag) // RenderTexture#setActive(flag) VALUE rbRenderTexture::SetActive( int argc, VALUE* args, VALUE aSelf ) { bool flag = false; switch( argc ) { case 1: flag = RTEST( args[ 0 ] ); case 0: break; default: INVALID_ARGUMENT_LIST( argc, "0 or 1" ); } bool result = rbMacros::ToSFML< sf::RenderTexture >( aSelf, rbRenderTexture::Class )->setActive( flag ); return RBOOL( result ); }
Object* CompiledCode::clear_breakpoint(STATE, Fixnum* ip) { int i = ip->to_native(); if(machine_code() == NULL) return ip; if(!machine_code()->validate_ip(state, i)) return Primitives::failure(); bool removed = false; if(!breakpoints()->nil_p()) { breakpoints()->remove(state, ip, &removed); // No more breakpoints, switch back to the normal interpreter if(breakpoints()->entries()->to_native() == 0) { machine_code()->debugging = 0; machine_code()->run = MachineCode::interpreter; } } return RBOOL(removed); }
Object* CallUnit::kind_of_executor(STATE, CallFrame* call_frame, CallUnit* unit, Executable* exec, Module* mod, Arguments& args) { Object* obj; if(unit->which_ == -1) { obj = args.recv(); } else if(unit->which_ < (int)args.total()) { obj = args.get_argument(unit->which_); } else { return cFalse; } if(Module* mod = try_as<Module>(unit->value())) { return RBOOL(obj->kind_of_p(state, mod)); } else { return cFalse; } }
static void rand_bw_image(LTRandomGenerator *r, int w, int h, const char *name) { LTImageBuffer buf(name); buf.width = w; buf.height = h; buf.bb_left = 0; buf.bb_top = h - 1; buf.bb_right = w - 1; buf.bb_bottom = 0; buf.bb_pixels = new LTpixel[w * h]; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (RBOOL(r)) { buf.bb_pixels[j * w + i] = 0xFFFFFFFF; } else { buf.bb_pixels[j * w + i] = 0x000000FF; } } } ltWriteImage(name, &buf); printf("Generated %s\n", name); }
// RenderTexture#create(width, height, depth_buffer=false) VALUE rbRenderTexture::Create( int argc, VALUE* args, VALUE aSelf ) { bool useDepth = false; bool result = false; switch( argc ) { case 3: useDepth = RTEST( args[ 2 ] ); case 2: #ifdef SFML_GROOGY_EXTENSION result = rbMacros::ToSFML< sf::RenderTexture >( aSelf, rbRenderTexture::Class )->create( NUM2UINT( args[ 0 ] ), NUM2UINT( args[ 1 ] ), sf::TextureFormat::RGBA8, useDepth ); #else result = rbMacros::ToSFML< sf::RenderTexture >( aSelf, rbRenderTexture::Class )->create( NUM2UINT( args[ 0 ] ), NUM2UINT( args[ 1 ] ), useDepth ); #endif break; default: INVALID_ARGUMENT_LIST( argc, "2 or 3" ); } return RBOOL( result ); }
Object* VariableScope::script(STATE) { return RBOOL(script_p()); }
inline void push_has_block(CallFrame* call_frame) { stack_push(RBOOL(CBOOL(call_frame->scope->block()))); }
Object* VariableScope::top_level_visibility(STATE) { return RBOOL(top_level_visibility_p()); }
Object* IO::fnmatch(STATE, String* pattern, String* path, Fixnum* flags) { return RBOOL(mri_fnmatch(pattern->c_str(state), path->c_str(state), flags->to_native())); }
Object* Character::ascii_p(STATE) { bool found; int c = codepoint(state, &found); return RBOOL(found && ONIGENC_IS_CODE_ASCII(c)); }
static bool call(STATE, CallFrame* call_frame, MachineCode* mcode, StackVariables* scope, Arguments& args, int flags) { /* There are 5 types of arguments, illustrated here: * m(a, b=1, *c, d, e: 2) * * where: * a is a head (pre optional/splat) fixed position argument * b is an optional argument * c is a rest argument * d is a post (optional/splat) argument * e is a keyword argument, which may be required (having no default * value), optional, or keyword rest argument (**kw). * * The arity checking above ensures that we have at least one argument * on the stack for each fixed position argument (ie arguments a and d * above). * * We assign the arguments in the following order: first the fixed * arguments (head and post) and possibly the keyword argument, then the * optional arguments, and the remainder (if any) are combined in an * array for the rest argument. * * We assign values from the sender's side to local variables on the * receiver's side. Which values to assign are computed as follows: * * sender indexes (arguments) * -v-v-v-v-v-v-v-v-v-v-v-v-- * * 0...H H...H+ON H+ON...N-P-K N-P-K...N-K N-K * | | | | | * H O R P K * | | | | | * 0...H H...H+O RI PI...PI+P KI * * -^-^-^-^-^-^-^-^-^-^-^-^- * receiver indexes (locals) * * where: * * arguments passed by sender * -------------------------- * N : total number of arguments passed * H* : number of head arguments * E : number of extra arguments * ON : number or arguments assigned to optional parameters * RN : number of arguments assigned to the rest argument * P* : number of post arguments * K : number of keyword arguments passed, 1 if the last argument is * a Hash or if #to_hash returns a Hash, 0 otherwise * HL : maximum number of head arguments passed * PM : post arguments missing when N < M * * parameters defined by receiver * ------------------------------ * T : total number of parameters * M : number of head + post parameters * H* : number of head parameters * O : number of optional parameters * RP : true if a rest parameter is defined, false otherwise * RI : index of rest parameter if RP is true, else -1 * P* : number of post parameters * PI : index of the first post parameter * KP : true if a keyword parameter is defined, false otherwise * KA : true if the keyword argument was extracted from the passed * argument leaving a remaining value * KI : index of keyword rest parameter * * (*) The values of H and P are fixed and they represent the same * values at both the sender and receiver, so they are named the same. * * formulas * -------- * K = KP && !KA && N > M ? 1 : 0 * E = N - M - K * O = T - M - (keywords ? 1 : 0) * ON = (X = MIN(O, E)) > 0 ? X : 0 * RN = RP && (X = E - ON) > 0 ? X : 0 * PI = H + O + (RP ? 1 : 0) * KI = RP ? T : T - 1 * HL = (H - N) > 0 ? MIN(N, H - N) : H * PM = N - H > 0 ? P - (N - H) : P * */ native_int N = args.total(); const native_int T = mcode->total_args; const native_int M = mcode->required_args; const native_int O = T - M - (mcode->keywords ? 1 : 0); /* TODO: Clean up usage to uniformly refer to 'splat' as N arguments * passed from sender at a single position and 'rest' as N arguments * collected into a single argument at the receiver. */ const native_int RI = mcode->splat_position; const bool RP = (RI >= 0); // expecting 0, got 0. if(T == 0 && N == 0) { if(RP) { scope->set_local(mcode->splat_position, Array::create(state, 0)); } return true; } const bool lambda = ((flags & CallFrame::cIsLambda) == CallFrame::cIsLambda); // Only do destructuring in non-lambda mode if(!lambda) { /* If only one argument was yielded and the block takes more than one * argument or has form { |a, | }: * * 1. If the object is an Array, assign elements to arguments. * 2. If the object returns 'nil' from #to_ary, assign the object * to the first argument. * 3. If the object returns an Array from #to_ary, assign the * elements to the arguments. * 4. If the object returns non-Array from #to_ary, raise a TypeError. */ if(N == 1 && (T > 1 || (RP && T > 0) || RI < -2)) { Object* obj = args.get_argument(0); Array* ary = 0; if(!(ary = try_as<Array>(obj))) { if(CBOOL(obj->respond_to(state, G(sym_to_ary), cFalse))) { if(!(obj = obj->send(state, call_frame, G(sym_to_ary)))) { return false; } if(!(ary = try_as<Array>(obj)) && !obj->nil_p()) { Exception::type_error(state, "to_ary must return an Array", call_frame); return false; } } } if(ary) { if(RI == -4 && M == 1) { args.use_argument(ary); } else { args.use_array(ary); } N = args.total(); } } } const native_int P = mcode->post_args; const native_int H = M - P; // Too many args (no rest argument!) if(!RP && N > T) { if(lambda) return false; N = T; } // Too few args! if(lambda && N < M) return false; Object* kw = 0; Object* kw_remainder = 0; bool KP = false; bool KA = false; if(mcode->keywords && N > M) { Object* obj = args.get_argument(args.total() - 1); OnStack<1> os(state, obj); Object* arguments[2]; arguments[0] = obj; arguments[1] = RBOOL(O > 0 || RP); Arguments args(G(sym_keyword_object), G(runtime), 2, arguments); Dispatch dis(G(sym_keyword_object)); Object* kw_result = dis.send(state, call_frame, args); if(kw_result) { if(Array* ary = try_as<Array>(kw_result)) { Object* o = 0; if(!(o = ary->get(state, 0))->nil_p()) { kw_remainder = o; KA = true; } kw = ary->get(state, 1); KP = true; } } else { return false; } } // A single kwrest argument if(mcode->keywords && !RP && !KP && N >= T) { if(lambda) return false; N = T - 1; } const native_int K = (KP && !KA && N > M) ? 1 : 0; const native_int N_M_K = N - M - K; const native_int E = N_M_K > 0 ? N_M_K : 0; native_int X; const native_int ON = (X = MIN(O, E)) > 0 ? X : 0; const native_int RN = (RP && (X = E - ON) > 0) ? X : 0; const native_int PI = H + O + (RP ? 1 : 0); const native_int KI = RP ? T : T - 1; native_int a = 0; // argument index native_int l = 0; // local index // head arguments if(H > 0) { for(; l < H && a < N; l++, a++) { scope->set_local(l, args.get_argument(a)); } for(; l < H; l++) { scope->set_local(l, cNil); } } // optional arguments if(O > 0) { for(; l < H + O && a < MIN(N, H + ON); l++, a++) { if(unlikely(kw_remainder && !RP && (a == N - 1))) { scope->set_local(l, kw_remainder); } else { scope->set_local(l, args.get_argument(a)); } } for(; l < H + O; l++) { scope->set_local(l, G(undefined)); } } // rest arguments if(RP) { Array* ary; if(RN > 0) { ary = Array::create(state, RN); for(int i = 0; i < RN && a < N - P - K; i++, a++) { if(unlikely(kw_remainder && (a == N - 1))) { ary->set(state, i, kw_remainder); } else { ary->set(state, i, args.get_argument(a)); } } } else { ary = Array::create(state, 0); } scope->set_local(RI, ary); } // post arguments if(P > 0) { const native_int N_K = (X = MIN(N, N - K)) > 0 ? X : N; for(l = PI; l < PI + P && a < N_K; l++, a++) { scope->set_local(l, args.get_argument(a)); } for(; l < PI + P; l++) { scope->set_local(l, cNil); } } // keywords if(kw) { scope->set_local(KI, kw); } return true; }
Object* Encoding::ascii_compatible_p(STATE) { return RBOOL(ascii_compatible()); }
// Rubinius.primitive+ :symbol_s_eqq static Object* is_symbol(STATE, Object* obj) { return RBOOL(obj->symbol_p()); }
Object* VariableScope::locked(STATE) { return RBOOL(locked_p()); }
// RenderTexture#smooth? // RenderTexture#is_smooth? // RenderTexture#is_smooth // RenderTexture#isSmooth VALUE rbRenderTexture::IsSmooth( VALUE aSelf ) { return RBOOL( rbMacros::ToSFML< sf::RenderTexture >( aSelf, rbRenderTexture::Class )->isSmooth() ); }
Time* Time::from_array(STATE, Object* self, Fixnum* sec, Fixnum* min, Fixnum* hour, Fixnum* mday, Fixnum* mon, Fixnum* year, Fixnum* nsec, Fixnum* isdst, Object* from_gmt, Object* offset, Fixnum* offset_sec, Fixnum* offset_nsec) { struct tm64 tm; tm.tm_sec = sec->to_native(); if(tm.tm_sec < 0 || tm.tm_sec > 60) { Exception::argument_error(state, "sec must be in 0..60"); } tm.tm_min = min->to_native(); if(tm.tm_min < 0 || tm.tm_min > 60) { Exception::argument_error(state, "min must be in 0..60"); } tm.tm_hour = hour->to_native(); if(tm.tm_hour < 0 || tm.tm_hour > 24) { Exception::argument_error(state, "hour must be in 0..24"); } tm.tm_mday = mday->to_native(); if(tm.tm_mday < 1 || tm.tm_mday > 31) { Exception::argument_error(state, "mday must be in 1..31"); } tm.tm_mon = mon->to_native() - 1; if(tm.tm_mon < 0 || tm.tm_mon > 11) { Exception::argument_error(state, "mon must be in 0..11"); } tm.tm_wday = -1; tm.tm_gmtoff = 0; tm.tm_zone = 0; tm.tm_year = year->to_long_long(); tm.tm_isdst = isdst->to_native(); time64_t seconds = -1; if(CBOOL(from_gmt) || !offset->nil_p()) { seconds = ::timegm64(&tm); } else { tzset(); seconds = ::timelocal64(&tm); } Time* obj = state->new_object_dirty<Time>(as<Class>(self)); obj->seconds_ = seconds; obj->nanoseconds_ = nsec->to_native(); obj->is_gmt(state, RBOOL(CBOOL(from_gmt))); if(!offset->nil_p()) { obj->seconds_ -= offset_sec->to_long_long(); obj->nanoseconds_ -= offset_nsec->to_native(); // Deal with underflow wrapping if(obj->nanoseconds_ < 0) { obj->seconds_ += NDIV(obj->nanoseconds_, 1000000000); obj->nanoseconds_ = NMOD(obj->nanoseconds_, 1000000000); } obj->offset(state, offset); } else { obj->offset(state, nil<Fixnum>()); } obj->decomposed(state, nil<Array>()); obj->zone(state, nil<String>()); return obj; }
Object* Regexp::fixed_encoding_p(STATE) { return RBOOL(fixed_encoding_); }
Object* Dir::closed_p(STATE) { return RBOOL(!os()); }
inline void check_serial(STATE, CallFrame* call_frame, intptr_t literal, intptr_t serial) { Object* recv = stack_pop(); CallSite* call_site = reinterpret_cast<CallSite*>(literal); stack_push(RBOOL(call_site->valid_serial_p(state, recv, G(sym_public), serial))); }