VM: macro FACTOR_FOR_EACH used in more places to drive iteration

db4
Björn Lindqvist 2015-05-29 12:25:12 +02:00
parent b7bd0668b3
commit 9d289e35f4
8 changed files with 10 additions and 30 deletions

View File

@ -146,14 +146,10 @@ void factor_vm::update_code_heap_words(bool reset_inline_caches) {
/* Fix up new words only. /* Fix up new words only.
Fast path for compilation units that only define new words. */ Fast path for compilation units that only define new words. */
void factor_vm::initialize_code_blocks() { void factor_vm::initialize_code_blocks() {
std::map<code_block*, cell>::const_iterator iter =
code->uninitialized_blocks.begin();
std::map<code_block*, cell>::const_iterator end =
code->uninitialized_blocks.end();
for (; iter != end; iter++) FACTOR_FOR_EACH(code->uninitialized_blocks) {
initialize_code_block(iter->first, iter->second); initialize_code_block(iter->first, iter->second);
}
code->uninitialized_blocks.clear(); code->uninitialized_blocks.clear();
} }

View File

@ -85,10 +85,7 @@ template <typename TargetGeneration, typename Policy> struct collector {
} }
void trace_code_heap_roots(std::set<code_block*>* remembered_set) { void trace_code_heap_roots(std::set<code_block*>* remembered_set) {
std::set<code_block*>::const_iterator iter = remembered_set->begin(); FACTOR_FOR_EACH(*remembered_set) {
std::set<code_block*>::const_iterator end = remembered_set->end();
for (; iter != end; iter++) {
code_block* compiled = *iter; code_block* compiled = *iter;
visitor.visit_code_block_objects(compiled); visitor.visit_code_block_objects(compiled);
visitor.visit_embedded_literals(compiled); visitor.visit_embedded_literals(compiled);

View File

@ -143,12 +143,10 @@ template <typename Fixup> struct code_block_compaction_updater {
marked, and also slide the valid roots up so that call sites can be updated marked, and also slide the valid roots up so that call sites can be updated
correctly in case an inline cache compilation triggered compaction. */ correctly in case an inline cache compilation triggered compaction. */
void factor_vm::update_code_roots_for_compaction() { void factor_vm::update_code_roots_for_compaction() {
std::vector<code_root*>::const_iterator iter = code_roots.begin();
std::vector<code_root*>::const_iterator end = code_roots.end();
mark_bits* state = &code->allocator->state; mark_bits* state = &code->allocator->state;
for (; iter < end; iter++) { FACTOR_FOR_EACH(code_roots) {
code_root* root = *iter; code_root* root = *iter;
cell block = root->value & (~data_alignment + 1); cell block = root->value & (~data_alignment + 1);

View File

@ -79,9 +79,7 @@ void factor_vm::init_contexts(cell datastack_size_, cell retainstack_size_,
void factor_vm::delete_contexts() { void factor_vm::delete_contexts() {
FACTOR_ASSERT(!ctx); FACTOR_ASSERT(!ctx);
std::list<context*>::const_iterator iter = unused_contexts.begin(); FACTOR_FOR_EACH(unused_contexts) {
std::list<context*>::const_iterator end = unused_contexts.end();
while (iter != end) {
delete *iter; delete *iter;
iter++; iter++;
} }

View File

@ -7,12 +7,9 @@ namespace factor {
compiler triggers a GC, and the caller block gets GCd as a result, compiler triggers a GC, and the caller block gets GCd as a result,
the PIC code won't try to overwrite the call site */ the PIC code won't try to overwrite the call site */
void factor_vm::update_code_roots_for_sweep() { void factor_vm::update_code_roots_for_sweep() {
std::vector<code_root*>::const_iterator iter = code_roots.begin();
std::vector<code_root*>::const_iterator end = code_roots.end();
mark_bits* state = &code->allocator->state; mark_bits* state = &code->allocator->state;
for (; iter < end; iter++) { FACTOR_FOR_EACH(code_roots) {
code_root* root = *iter; code_root* root = *iter;
cell block = root->value & (~data_alignment - 1); cell block = root->value & (~data_alignment - 1);
if (root->valid && !state->marked_p(block)) if (root->valid && !state->marked_p(block))

View File

@ -239,10 +239,7 @@ void factor_vm::primitive_disable_gc_events() {
std::vector<gc_event>* gc_events = this->gc_events; std::vector<gc_event>* gc_events = this->gc_events;
this->gc_events = NULL; this->gc_events = NULL;
std::vector<gc_event>::const_iterator iter = gc_events->begin(); FACTOR_FOR_EACH(*gc_events) {
std::vector<gc_event>::const_iterator end = gc_events->end();
for (; iter != end; iter++) {
gc_event event = *iter; gc_event event = *iter;
byte_array* obj = byte_array_from_value(&event); byte_array* obj = byte_array_from_value(&event);
result.add(tag<byte_array>(obj)); result.add(tag<byte_array>(obj));

View File

@ -2,8 +2,8 @@ namespace factor {
// Poor mans range-based for loops. // Poor mans range-based for loops.
#define FACTOR_FOR_EACH(iterable) \ #define FACTOR_FOR_EACH(iterable) \
for (typeof(iterable.begin()) iter = iterable.begin(); \ for (typeof((iterable).begin()) iter = (iterable).begin(); \
iter != iterable.end(); \ iter != (iterable).end(); \
iter++) iter++)
inline static void memset_2(void* dst, uint16_t pattern, size_t size) { inline static void memset_2(void* dst, uint16_t pattern, size_t size) {

View File

@ -32,11 +32,8 @@ factor_vm::~factor_vm() {
delete signal_callstack_seg; delete signal_callstack_seg;
signal_callstack_seg = NULL; signal_callstack_seg = NULL;
} }
std::list<void**>::const_iterator iter = function_descriptors.begin(); FACTOR_FOR_EACH(function_descriptors) {
std::list<void**>::const_iterator end = function_descriptors.end();
while (iter != end) {
delete[] * iter; delete[] * iter;
iter++;
} }
} }