static STATES prev_object(STATES now) { STATES result = now; while (next_object(result) != now) result = next_object(result); return result; }
void BakerGC::clear_marks() { Object* obj = current->first_object(); while(obj < current->current) { obj->clear_mark(); obj = next_object(obj); } obj = next->first_object(); while(obj < next->current) { obj->clear_mark(); obj = next_object(obj); } }
void BakerGC::free_objects() { Object* obj = current->first_object(); while(obj < current->current) { delete_object(obj); obj = next_object(obj); } assert(next->current < next->last); obj = next->first_object(); while(obj < next->current) { delete_object(obj); obj = next_object(obj); } }
/* Set the XT fields now that the heap has been compacted */ void fixup_object_xts(void) { begin_scan(); CELL obj; while((obj = next_object()) != F) { if(type_of(obj) == WORD_TYPE) { F_WORD *word = untag_object(obj); update_word_xt(word); } else if(type_of(obj) == QUOTATION_TYPE) { F_QUOTATION *quot = untag_object(obj); if(quot->compiledp != F) set_quot_xt(quot,quot->code); } } /* End the heap scan */ gc_off = false; }
static void trace_by_addr(void *obj_addr, int distance) { // An arbitrary cut-off for a search that's too deep to be useful. if(distance > 20) { return; } Object_With_Header *obj = (Object_With_Header *) GC::pinned_objects; while(obj) { uint64 sz = get_object_size(obj); void **obj_start = (void **)obj->start(); void **obj_end = (void **)(((Byte *)obj_start) + sz); for(void **p = obj_start; p < obj_end; p++) { if(obj_addr == *p) { printf("GC TRACE: [%d] %p in obj %p(+%d): %s\n", distance, obj_addr, obj_start, (int)(((Byte *)p) - ((Byte *)obj_start)), class_get_name(obj->vt()->gcvt->ch)); if(!is_marked(obj)) { printf("GC TRACE: %p is not marked\n", obj_start); trace_by_addr(obj_start, distance + 1); } } } obj = next_object(obj); } } //trace_by_addr
/* Set the XT fields now that the heap has been compacted */ void factor_vm::fixup_object_xts() { begin_scan(); cell obj; while((obj = next_object()) != F) { switch(tagged<object>(obj).type()) { case WORD_TYPE: update_word_xt(obj); break; case QUOTATION_TYPE: { quotation *quot = untag<quotation>(obj); if(quot->code) set_quot_xt(quot,quot->code); break; } default: break; } } end_scan(); }
void forward_object_xts(void) { begin_scan(); CELL obj; while((obj = next_object()) != F) { if(type_of(obj) == WORD_TYPE) { F_WORD *word = untag_object(obj); word->code = forward_xt(word->code); if(word->profiling) word->profiling = forward_xt(word->profiling); } else if(type_of(obj) == QUOTATION_TYPE) { F_QUOTATION *quot = untag_object(obj); if(quot->compiledp != F) quot->code = forward_xt(quot->code); } else if(type_of(obj) == CALLSTACK_TYPE) { F_CALLSTACK *stack = untag_object(obj); iterate_callstack_object(stack,forward_frame_xt); } } /* End the heap scan */ gc_off = false; }
void unmark_all() { Object_With_Header *obj = GC::pinned_objects; while(obj) { set_unmarked(obj); obj = next_object(obj); } unmark_all_in_current_semispace(); } //unmark_all
int key_edit_hook(int keycode, t_env *env) { if (keycode == T_ESC) return (close_edit_window(env, 0)); if (keycode == T_ENTER || keycode == T_RETURN) copy_env_mods(env); if (keycode == T_G || keycode == T_S || keycode == T_R || keycode == T_C) change_mode(env, keycode); if (keycode == T_TAB) next_object(env); expose_edit_hook(env); return (1); }
void BakerGC::find_lost_souls() { Object* obj = current->first_object(); while(obj < current->current) { if(!obj->forwarded_p()) { delete_object(obj); #ifdef RBX_GC_STATS stats::GCStats::get()->lifetimes[obj->age]++; #endif } obj = next_object(obj); } }
void strip_compiled_quotations(void) { begin_scan(); CELL obj; while((obj = next_object()) != F) { if(type_of(obj) == QUOTATION_TYPE) { F_QUOTATION *quot = untag_object(obj); quot->compiledp = F; } } gc_off = false; }
void factor_vm::forward_object_xts() { begin_scan(); cell obj; while(to_boolean(obj = next_object())) { switch(tagged<object>(obj).type()) { case WORD_TYPE: { word *w = untag<word>(obj); if(w->code) w->code = code->forward_code_block(w->code); if(w->profiling) w->profiling = code->forward_code_block(w->profiling); update_word_xt(obj); } break; case QUOTATION_TYPE: { quotation *quot = untag<quotation>(obj); if(quot->code) { quot->code = code->forward_code_block(quot->code); set_quot_xt(quot,quot->code); } } break; case CALLSTACK_TYPE: { callstack *stack = untag<callstack>(obj); callframe_forwarder forwarder(this); iterate_callstack_object(stack,forwarder); } break; default: break; } } end_scan(); }
sc_object* sc_object_manager::first_object() { if (m_ordered_object_vector_dirty) { m_ordered_object_vector->erase_all(); object_table_type::iterator it(m_object_table); while (! it.empty()) { sc_object* obj = it.contents(); m_ordered_object_vector->push_back(obj); it++; } m_ordered_object_vector->sort(object_name_compare); m_ordered_object_vector_dirty = false; } m_next_object_index = 0; return next_object(); }
void factor_vm::forward_object_xts() { begin_scan(); cell obj; while((obj = next_object()) != F) { switch(tagged<object>(obj).type()) { case WORD_TYPE: { word *w = untag<word>(obj); if(w->code) w->code = forward_xt(w->code); if(w->profiling) w->profiling = forward_xt(w->profiling); } break; case QUOTATION_TYPE: { quotation *quot = untag<quotation>(obj); if(quot->code) quot->code = forward_xt(quot->code); } break; case CALLSTACK_TYPE: { callstack *stack = untag<callstack>(obj); xt_forwarder forwarder(this); iterate_callstack_object(stack,forwarder); } break; default: break; } } end_scan(); }
void mark_by_pointers() { if(ptr_table_ptr == 0) { return; } Object_With_Header *obj = (Object_With_Header *) GC::pinned_objects; while(obj) { mark_object_by_pointers(obj); // An optimization: if we used every pointer at least once, we don't // have to continue scanning the heap. if(ptr_table_ptr == 0) { break; } obj = next_object(obj); } mark_by_pointers_in_current_semispace(); } //mark_by_pointers
/* * Display a dialog box for entering a date */ int dialog_timebox(const char *title, const char *subtitle, int height, int width, int hour, int minute, int second) { BOX hr_box, mn_box, sc_box; int key = 0, key2, button = sOK; int result = -2; WINDOW *dialog; time_t now_time = time((time_t *) 0); struct tm current; STATES state = sOK; const char **buttons = dlg_ok_labels(); char *prompt = strclone(subtitle); now_time = time((time_t *) 0); current = *localtime(&now_time); auto_size(title, prompt, &height, &width, 0, 0); height += MIN_HIGH; if (width < MIN_WIDE) width = MIN_WIDE; dlg_button_layout(buttons, &width); print_size(height, width); ctl_size(height, width); /* FIXME: how to make this resizable? */ dialog = new_window(height, width, box_y_ordinate(height), box_x_ordinate(width)); draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); draw_bottom_box(dialog); draw_title(dialog, title); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, height, width); /* compute positions of hour, month and year boxes */ memset(&hr_box, 0, sizeof(hr_box)); memset(&mn_box, 0, sizeof(mn_box)); memset(&sc_box, 0, sizeof(sc_box)); if (init_object(&hr_box, dialog, (width - MIN_WIDE + 1) / 2 + MARGIN, (height - MIN_HIGH + MARGIN), ONE_WIDE, ONE_HIGH, 24, hour >= 0 ? hour : current.tm_hour, 'H') < 0 || DrawObject(&hr_box) < 0) return -1; mvwprintw(dialog, hr_box.y, hr_box.x + ONE_WIDE + MARGIN, ":"); if (init_object(&mn_box, dialog, hr_box.x + (ONE_WIDE + 2 * MARGIN + 1), hr_box.y, hr_box.width, hr_box.height, 60, minute >= 0 ? minute : current.tm_min, 'M') < 0 || DrawObject(&mn_box) < 0) return -1; mvwprintw(dialog, mn_box.y, mn_box.x + ONE_WIDE + MARGIN, ":"); if (init_object(&sc_box, dialog, mn_box.x + (ONE_WIDE + 2 * MARGIN + 1), mn_box.y, mn_box.width, mn_box.height, 60, second >= 0 ? second : current.tm_sec, 'S') < 0 || DrawObject(&sc_box) < 0) return -1; while (result == -2) { BOX *obj = (state == sHR ? &hr_box : (state == sMN ? &mn_box : (state == sSC ? &sc_box : 0))); button = (state == sCANCEL) ? 1 : 0; dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); if (obj != 0) dlg_set_focus(dialog, obj->window); key = mouse_wgetch(dialog); if ((key2 = dlg_char_to_button(key, buttons)) >= 0) { result = key2; } else { switch (key) { case M_EVENT + 0: result = DLG_EXIT_OK; break; case M_EVENT + 1: result = DLG_EXIT_CANCEL; break; case M_EVENT + 'H': state = sHR; break; case M_EVENT + 'M': state = sMN; break; case M_EVENT + 'S': state = sSC; break; case ESC: result = -1; break; case ' ': case '\n': result = button; break; case KEY_BTAB: state = prev_object(state); break; case TAB: state = next_object(state); break; default: if (obj != 0) { int step = next_or_previous(key); if (step != 0) { obj->value += step; while (obj->value < 0) obj->value += obj->period; obj->value %= obj->period; (void) DrawObject(obj); } } break; } } } del_window(dialog); sprintf(dialog_vars.input_result, "%02d:%02d:%02d\n", hr_box.value, mn_box.value, sc_box.value); mouse_free_regions(); return result; }
void mutation_branch::load( JsonObject &jo, const std::string & ) { mandatory( jo, was_loaded, "id", id ); mandatory( jo, was_loaded, "name", raw_name, translated_string_reader ); mandatory( jo, was_loaded, "description", raw_desc, translated_string_reader ); mandatory( jo, was_loaded, "points", points ); optional( jo, was_loaded, "visibility", visibility, 0 ); optional( jo, was_loaded, "ugliness", ugliness, 0 ); optional( jo, was_loaded, "starting_trait", startingtrait, false ); optional( jo, was_loaded, "mixed_effect", mixed_effect, false ); optional( jo, was_loaded, "active", activated, false ); optional( jo, was_loaded, "starts_active", starts_active, false ); optional( jo, was_loaded, "destroys_gear", destroys_gear, false ); optional( jo, was_loaded, "allow_soft_gear", allow_soft_gear, false ); optional( jo, was_loaded, "cost", cost, 0 ); optional( jo, was_loaded, "time", cooldown, 0 ); optional( jo, was_loaded, "hunger", hunger, false ); optional( jo, was_loaded, "thirst", thirst, false ); optional( jo, was_loaded, "fatigue", fatigue, false ); optional( jo, was_loaded, "valid", valid, true ); optional( jo, was_loaded, "purifiable", purifiable, true ); if( jo.has_object( "spawn_item" ) ) { auto si = jo.get_object( "spawn_item" ); optional( si, was_loaded, "type", spawn_item ); optional( si, was_loaded, "message", raw_spawn_item_message ); } if( jo.has_object( "ranged_mutation" ) ) { auto si = jo.get_object( "ranged_mutation" ); optional( si, was_loaded, "type", ranged_mutation ); optional( si, was_loaded, "message", raw_ranged_mutation_message ); } optional( jo, was_loaded, "initial_ma_styles", initial_ma_styles ); if( jo.has_array( "bodytemp_modifiers" ) ) { auto bodytemp_array = jo.get_array( "bodytemp_modifiers" ); bodytemp_min = bodytemp_array.get_int( 0 ); bodytemp_max = bodytemp_array.get_int( 1 ); } optional( jo, was_loaded, "bodytemp_sleep", bodytemp_sleep, 0 ); optional( jo, was_loaded, "threshold", threshold, false ); optional( jo, was_loaded, "profession", profession, false ); optional( jo, was_loaded, "debug", debug, false ); optional( jo, was_loaded, "player_display", player_display, true ); JsonArray vr = jo.get_array( "vitamin_rates" ); while( vr.has_more() ) { auto pair = vr.next_array(); vitamin_rates.emplace( vitamin_id( pair.get_string( 0 ) ), time_duration::from_turns( pair.get_int( 1 ) ) ); } auto vam = jo.get_array( "vitamins_absorb_multi" ); while( vam.has_more() ) { auto pair = vam.next_array(); std::map<vitamin_id, double> vit; auto vit_array = pair.get_array( 1 ); // fill the inner map with vitamins while( vit_array.has_more() ) { auto vitamins = vit_array.next_array(); vit.emplace( vitamin_id( vitamins.get_string( 0 ) ), vitamins.get_float( 1 ) ); } // assign the inner vitamin map to the material_id key vitamin_absorb_multi.emplace( material_id( pair.get_string( 0 ) ), vit ); } optional( jo, was_loaded, "healing_awake", healing_awake, 0.0f ); optional( jo, was_loaded, "healing_resting", healing_resting, 0.0f ); optional( jo, was_loaded, "hp_modifier", hp_modifier, 0.0f ); optional( jo, was_loaded, "hp_modifier_secondary", hp_modifier_secondary, 0.0f ); optional( jo, was_loaded, "hp_adjustment", hp_adjustment, 0.0f ); optional( jo, was_loaded, "stealth_modifier", stealth_modifier, 0.0f ); optional( jo, was_loaded, "str_modifier", str_modifier, 0.0f ); optional( jo, was_loaded, "dodge_modifier", dodge_modifier, 0.0f ); optional( jo, was_loaded, "speed_modifier", speed_modifier, 1.0f ); optional( jo, was_loaded, "movecost_modifier", movecost_modifier, 1.0f ); optional( jo, was_loaded, "movecost_flatground_modifier", movecost_flatground_modifier, 1.0f ); optional( jo, was_loaded, "movecost_obstacle_modifier", movecost_obstacle_modifier, 1.0f ); optional( jo, was_loaded, "attackcost_modifier", attackcost_modifier, 1.0f ); optional( jo, was_loaded, "max_stamina_modifier", max_stamina_modifier, 1.0f ); optional( jo, was_loaded, "weight_capacity_modifier", weight_capacity_modifier, 1.0f ); optional( jo, was_loaded, "hearing_modifier", hearing_modifier, 1.0f ); optional( jo, was_loaded, "noise_modifier", noise_modifier, 1.0f ); optional( jo, was_loaded, "metabolism_modifier", metabolism_modifier, 0.0f ); optional( jo, was_loaded, "thirst_modifier", thirst_modifier, 0.0f ); optional( jo, was_loaded, "fatigue_modifier", fatigue_modifier, 0.0f ); optional( jo, was_loaded, "fatigue_regen_modifier", fatigue_regen_modifier, 0.0f ); optional( jo, was_loaded, "stamina_regen_modifier", stamina_regen_modifier, 0.0f ); optional( jo, was_loaded, "overmap_sight", overmap_sight, 0.0f ); optional( jo, was_loaded, "overmap_multiplier", overmap_multiplier, 1.0f ); if( jo.has_object( "social_modifiers" ) ) { JsonObject sm = jo.get_object( "social_modifiers" ); social_mods = load_mutation_social_mods( sm ); } load_mutation_mods( jo, "passive_mods", mods ); /* Not currently supported due to inability to save active mutation state load_mutation_mods(jsobj, "active_mods", new_mut.mods); */ optional( jo, was_loaded, "prereqs", prereqs ); optional( jo, was_loaded, "prereqs2", prereqs2 ); optional( jo, was_loaded, "threshreq", threshreq ); optional( jo, was_loaded, "cancels", cancels ); optional( jo, was_loaded, "changes_to", replacements ); optional( jo, was_loaded, "leads_to", additions ); optional( jo, was_loaded, "flags", flags ); optional( jo, was_loaded, "types", types ); auto jsarr = jo.get_array( "category" ); while( jsarr.has_more() ) { std::string s = jsarr.next_string(); category.push_back( s ); mutations_category[s].push_back( trait_id( id ) ); } jsarr = jo.get_array( "wet_protection" ); while( jsarr.has_more() ) { JsonObject jo = jsarr.next_object(); std::string part_id = jo.get_string( "part" ); int ignored = jo.get_int( "ignored", 0 ); int neutral = jo.get_int( "neutral", 0 ); int good = jo.get_int( "good", 0 ); tripoint protect = tripoint( ignored, neutral, good ); protection[get_body_part_token( part_id )] = protect; } jsarr = jo.get_array( "encumbrance_always" ); while( jsarr.has_more() ) { JsonArray jo = jsarr.next_array(); std::string part_id = jo.next_string(); int enc = jo.next_int(); encumbrance_always[get_body_part_token( part_id )] = enc; } jsarr = jo.get_array( "encumbrance_covered" ); while( jsarr.has_more() ) { JsonArray jo = jsarr.next_array(); std::string part_id = jo.next_string(); int enc = jo.next_int(); encumbrance_covered[get_body_part_token( part_id )] = enc; } jsarr = jo.get_array( "restricts_gear" ); while( jsarr.has_more() ) { restricts_gear.insert( get_body_part_token( jsarr.next_string() ) ); } jsarr = jo.get_array( "armor" ); while( jsarr.has_more() ) { JsonObject jo = jsarr.next_object(); auto parts = jo.get_tags( "parts" ); std::set<body_part> bps; for( const std::string &part_string : parts ) { if( part_string == "ALL" ) { // Shorthand, since many mutations protect whole body bps.insert( all_body_parts.begin(), all_body_parts.end() ); } else { bps.insert( get_body_part_token( part_string ) ); } } resistances res = load_resistances_instance( jo ); for( body_part bp : bps ) { armor[ bp ] = res; } } if( jo.has_array( "attacks" ) ) { jsarr = jo.get_array( "attacks" ); while( jsarr.has_more() ) { JsonObject jo = jsarr.next_object(); attacks_granted.emplace_back( load_mutation_attack( jo ) ); } } else if( jo.has_object( "attacks" ) ) { JsonObject attack = jo.get_object( "attacks" ); attacks_granted.emplace_back( load_mutation_attack( attack ) ); } }