本文整理汇总了C++中Tuple::num_fields方法的典型用法代码示例。如果您正苦于以下问题:C++ Tuple::num_fields方法的具体用法?C++ Tuple::num_fields怎么用?C++ Tuple::num_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tuple
的用法示例。
在下文中一共展示了Tuple::num_fields方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: indent
void Tuple::Info::show_simple(STATE, Object* self, int level) {
Tuple* tup = as<Tuple>(self);
native_int size = tup->num_fields();
native_int stop = size < 6 ? size : 6;
if(size == 0) {
class_info(state, self, true);
return;
}
class_info(state, self);
std::cout << ": " << size << std::endl;
++level;
for(native_int i = 0; i < stop; i++) {
indent(level);
Object* obj = tup->at(state, i);
if(Tuple* t = try_as<Tuple>(obj)) {
class_info(state, self);
std::cout << ": " << t->num_fields() << ">" << std::endl;
} else {
obj->show_simple(state, level);
}
}
if(tup->num_fields() > stop) ellipsis(level);
close_body(level);
}
示例2: priority
/** @todo Should we queue thread? Probably unnecessary. --rue */
void Thread::priority(STATE, Fixnum* new_priority) {
/* This gets somewhat ugly to avoid existing lists. */
if(new_priority->to_native() < 0) {
Exception::argument_error(state, "Thread priority must be non-negative!");
}
Tuple* scheduled = state->globals.scheduled_threads.get();
std::size_t desired = new_priority->to_ulong();
std::size_t existing = scheduled->num_fields();
if(desired >= existing) {
Tuple* replacement = Tuple::create(state, (desired + 1));
replacement->copy_from(state, scheduled, Fixnum::from(0),
Fixnum::from(scheduled->num_fields()),
Fixnum::from(0));
for(std::size_t i = existing - 1; i <= desired; ++i) {
if(replacement->at(state, i)->nil_p()) {
replacement->put(state, i, List::create(state));
}
}
state->globals.scheduled_threads.set(replacement);
scheduled = replacement;
}
priority_ = new_priority;
}
示例3: set_iseq
void Marshaller::set_iseq(InstructionSequence* iseq) {
Tuple* ops = iseq->opcodes();
stream << "i" << endl << ops->num_fields() << endl;
for(size_t i = 0; i < ops->num_fields(); i++) {
stream << as<Fixnum>(ops->at(state, i))->to_native() << endl;
}
}
示例4: update_profile
void VM::update_profile(STATE) {
timer::StopWatch<timer::nanoseconds> timer(metrics().machine.profile_ns);
metrics().machine.profiles++;
profile_sample_count_++;
CompiledCode* code = state->vm()->call_frame()->compiled_code;
code->machine_code()->sample_count++;
Tuple* profile = profile_.get();
if(profile->nil_p()) {
profile = Tuple::create(state, max_profile_entries_);
profile_.set(profile);
}
::qsort(reinterpret_cast<void*>(profile->field), profile->num_fields(),
sizeof(intptr_t), profile_compare);
for(native_int i = 0; i < profile->num_fields(); i++) {
if(code == profile->at(i)) return;
}
CompiledCode* pcode = try_as<CompiledCode>(profile->at(0));
if(!pcode || (pcode &&
code->machine_code()->call_count > pcode->machine_code()->call_count))
{
profile->put(state, 0, code);
min_profile_call_count_ = code->machine_code()->call_count;
}
}
示例5: clean_weakrefs
// HACK todo test this!
void MarkSweepGC::clean_weakrefs() {
if(!weak_refs) return;
for(ObjectArray::iterator i = weak_refs->begin();
i != weak_refs->end();
i++) {
// ATM, only a Tuple can be marked weak.
Tuple* tup = as<Tuple>(*i);
for(size_t ti = 0; ti < tup->num_fields(); ti++) {
Object* obj = tup->at(object_memory->state, ti);
if(!obj->reference_p()) continue;
if(obj->young_object_p()) {
if(!obj->marked_p()) {
tup->field[ti] = Qnil;
}
} else {
Entry *entry = find_entry(obj);
if(!entry->marked_p()) {
tup->field[ti] = Qnil;
}
}
}
}
delete weak_refs;
weak_refs = NULL;
}
示例6:
void Tuple::Info::visit(Object* obj, ObjectVisitor& visit) {
Tuple* tup = as<Tuple>(obj);
for(size_t i = 0; i < tup->num_fields(); i++) {
visit.call(tup->field[i]);
}
}
示例7: update_cached_rarray
/* We were in Ruby-land and we are heading to C-land. In Ruby-land, we
* may have updated the existing Array elements, appended new elements,
* or shifted off elements. We account for this when updating the C
* structure contents.
*
* We are potentially writing into a C structure that exists and that
* may have been changed in C-land. It is possible for C code to change
* both the len and ptr values of an RArray. We DO NOT EVER encourage
* doing this, but we must account for it. The C code may also merely
* change the contents of the array pointed to by ptr. Updating that
* array with the current elements in the Ruby Array is the purpose of
* this code.
*/
void update_cached_rarray(NativeMethodEnvironment* env, Handle* handle) {
if(handle->is_rarray()) {
Array* array = c_as<Array>(handle->object());
Tuple* tuple = array->tuple();
RArray* rarray = handle->as_rarray(env);
native_int size = tuple->num_fields();
native_int start = array->start()->to_native();
native_int num = 0;
if(rarray->ptr != rarray->dmwmb) {
// This is a very bad C extension. Assume len is valid
// and do not change its value.
num = rarray->len;
} else {
env->shared().capi_ds_lock().lock();
if(rarray->aux.capa < size) {
delete[] rarray->dmwmb;
rarray->dmwmb = rarray->ptr = new VALUE[size];
rarray->aux.capa = size;
}
num = rarray->aux.capa;
rarray->len = array->size();
env->shared().capi_ds_lock().unlock();
}
for(native_int i = 0, j = start; i < num && j < size; i++, j++) {
rarray->ptr[i] = env->get_handle(tuple->at(j));
}
}
}
示例8: flush_cached_rarray
/* We were in C-land and now we are returning to Ruby-land. Since the C
* program can freely assign to RArray.len and RArray.ptr, we account
* for that when updating the Ruby Array with the C structure contents.
*
* Note that we must copy the total elements in the cached C array
* regardless of the value of the len parameter because the C array
* contents can be changed indepedently from the len parameter.
*
* See Handle::as_rarray below.
*/
void flush_cached_rarray(NativeMethodEnvironment* env, Handle* handle) {
if(handle->is_rarray()) {
Array* array = c_as<Array>(handle->object());
Tuple* tuple = array->tuple();
RArray* rarray = handle->as_rarray(env);
native_int size = tuple->num_fields();
native_int num = 0;
if(rarray->ptr != rarray->dmwmb) {
// This is a very bad C extension. Assume len is valid.
num = rarray->len;
} else {
num = rarray->aux.capa;
}
if(num > size) {
tuple = Tuple::create(env->state(), rarray->aux.capa);
array->tuple(env->state(), tuple);
}
array->start(env->state(), Fixnum::from(0));
array->total(env->state(), Fixnum::from(rarray->len));
for(native_int i = 0; i < num; i++) {
tuple->put(env->state(), i, env->get_object(rarray->ptr[i]));
}
}
}
示例9: find_and_activate_thread
bool VM::find_and_activate_thread() {
Tuple* scheduled = globals.scheduled_threads.get();
for(std::size_t i = scheduled->num_fields() - 1; i > 0; i--) {
List* list = as<List>(scheduled->at(this, i));
Thread* thread = try_as<Thread>(list->shift(this));
while(thread) {
thread->queued(this, Qfalse);
/** @todo Should probably try to prevent dead threads here.. */
if(thread->alive() == Qfalse) {
thread = try_as<Thread>(list->shift(this));
continue;
}
if(thread->sleep() == Qtrue) {
thread = try_as<Thread>(list->shift(this));
continue;
}
activate_thread(thread);
return true;
}
}
return false;
}
示例10:
void Tuple::Info::mark(Object* obj, ObjectMark& mark) {
Tuple* tup = as<Tuple>(obj);
for(native_int i = 0; i < tup->num_fields(); i++) {
Object* tmp = mark.call(tup->field[i]);
if(tmp && tmp != tup->field[i]) mark.set(obj, &tup->field[i], tmp);
}
}
示例11: test_pattern
void test_pattern() {
Fixnum* ten = Fixnum::from(10);
Tuple* tuple = Tuple::pattern(state, Fixnum::from(5), ten);
TS_ASSERT_EQUALS(5, tuple->num_fields());
for(size_t i = 0; i < 5; i++) {
TS_ASSERT_EQUALS(ten, tuple->at(state, i));
}
}
示例12:
void Tuple::Info::mark(Object* obj, memory::ObjectMark& mark) {
Tuple* tup = as<Tuple>(obj);
for(native_int i = 0; i < tup->num_fields(); i++) {
if(Object* tmp = mark.call(tup->field[i])) {
mark.set(obj, &tup->field[i], tmp);
}
}
}
示例13: post_marshal
void CompiledMethod::post_marshal(STATE) {
formalize(state); // side-effect, populates backend_method_
// Set the sender attribute of all SendSites in this method to this CM
Tuple *lit = literals();
for(std::size_t i = 0; i < lit->num_fields(); i++) {
SendSite *ss = try_as<SendSite>(lit->at(state, i));
if(ss != NULL) ss->sender(state, this);
}
}
示例14:
void Tuple::Info::mark(Object* obj, ObjectMark& mark) {
Object* tmp;
Tuple* tup = as<Tuple>(obj);
for(size_t i = 0; i < tup->num_fields(); i++) {
tmp = mark.call(tup->field[i]);
if(tmp) mark.set(obj, &tup->field[i], tmp);
}
}
示例15: test_new_object
void test_new_object() {
ObjectMemory& om = *state->memory();
Tuple* obj;
obj = util_new_object(om);
TS_ASSERT_EQUALS(obj->num_fields(), 3);
TS_ASSERT_EQUALS(obj->zone(), YoungObjectZone);
}