diff --git a/vm/alien.cpp b/vm/alien.cpp index bd6aa9077a..894ba2d4c8 100644 --- a/vm/alien.cpp +++ b/vm/alien.cpp @@ -5,7 +5,7 @@ namespace factor { // gets the address of an object representing a C pointer, with the // intention of storing the pointer across code which may potentially GC. char* factor_vm::pinned_alien_offset(cell obj) { - switch (tagged(obj).type()) { + switch (TAG(obj)) { case ALIEN_TYPE: { alien* ptr = untag(obj); if (to_boolean(ptr->expired)) @@ -57,7 +57,7 @@ void factor_vm::primitive_displaced_alien() { cell alien = ctx->pop(); cell displacement = to_cell(ctx->pop()); - switch (tagged(alien).type()) { + switch (TAG(alien)) { case BYTE_ARRAY_TYPE: case ALIEN_TYPE: case F_TYPE: @@ -163,7 +163,7 @@ void factor_vm::primitive_dll_validp() { // gets the address of an object representing a C pointer char* factor_vm::alien_offset(cell obj) { - switch (tagged(obj).type()) { + switch (TAG(obj)) { case BYTE_ARRAY_TYPE: return untag(obj)->data(); case ALIEN_TYPE: diff --git a/vm/code_blocks.cpp b/vm/code_blocks.cpp index 6b4ef18bc6..d9d774f9f9 100644 --- a/vm/code_blocks.cpp +++ b/vm/code_blocks.cpp @@ -3,28 +3,23 @@ namespace factor { static cell code_block_owner(code_block* compiled) { - tagged owner(compiled->owner); + cell owner = compiled->owner; // Cold generic word call sites point to quotations that call the // inline-cache-miss and inline-cache-miss-tail primitives. - if (owner.type() == QUOTATION_TYPE) { - tagged quot(owner.as()); - tagged elements(quot->array); + if (TAG(owner) != QUOTATION_TYPE) + return owner; - FACTOR_ASSERT(array_capacity(elements.untagged()) == 5); - FACTOR_ASSERT(array_nth(elements.untagged(), 4) == - special_objects[PIC_MISS_WORD] || - array_nth(elements.untagged(), 4) == - special_objects[PIC_MISS_TAIL_WORD]); + quotation* quot = untag(owner); + array* elements = untag(quot->array); - tagged word_wrapper(array_nth(elements.untagged(), 0)); - return word_wrapper->object; - } - return compiled->owner; + FACTOR_ASSERT(array_capacity(elements) == 5); + wrapper* wrap = untag(array_nth(elements, 0)); + return wrap->object; } static cell compute_entry_point_address(cell obj) { - switch (tagged(obj).type()) { + switch (TAG(obj)) { case WORD_TYPE: return untag(obj)->entry_point; case QUOTATION_TYPE: @@ -43,10 +38,9 @@ static cell compute_here_address(cell arg, cell offset, code_block* compiled) { } cell code_block::owner_quot() const { - tagged executing(owner); - if (type() != CODE_BLOCK_OPTIMIZED && executing->type() == WORD_TYPE) - executing = executing.as()->def; - return executing.value(); + if (type() != CODE_BLOCK_OPTIMIZED && TAG(owner) == WORD_TYPE) + return untag(owner)->def; + return owner; } // If the code block is an unoptimized quotation, we can calculate the @@ -57,13 +51,13 @@ cell code_block::scan(factor_vm* vm, cell addr) const { return tag_fixnum(-1); } - tagged obj(owner); - if (obj.type() == WORD_TYPE) - obj = obj.as()->def; - if (obj.type() != QUOTATION_TYPE) + cell ptr = owner; + if (TAG(ptr) == WORD_TYPE) + ptr = untag(ptr)->def; + if (TAG(ptr) != QUOTATION_TYPE) return tag_fixnum(-1); cell ofs = offset(addr); - return tag_fixnum(vm->quot_code_offset_to_scan(obj.value(), ofs)); + return tag_fixnum(vm->quot_code_offset_to_scan(ptr, ofs)); } cell factor_vm::compute_entry_point_pic_address(word* w, cell tagged_quot) { diff --git a/vm/code_blocks.hpp b/vm/code_blocks.hpp index 7711980922..09b0dc4a47 100644 --- a/vm/code_blocks.hpp +++ b/vm/code_blocks.hpp @@ -74,17 +74,18 @@ struct code_block { void flush_icache() { factor::flush_icache((cell)this, size()); } template void each_instruction_operand(Iterator& iter) { - if (to_boolean(relocation)) { - byte_array* rels = (byte_array*)UNTAG(relocation); + if (!to_boolean(relocation)) + return; - cell index = 0; - cell length = (rels->capacity >> TAG_BITS) / sizeof(relocation_entry); + byte_array* rels = untag(relocation); - for (cell i = 0; i < length; i++) { - relocation_entry rel = rels->data()[i]; - iter(instruction_operand(rel, this, index)); - index += rel.number_of_parameters(); - } + cell index = 0; + cell length = untag_fixnum(rels->capacity) / sizeof(relocation_entry); + + for (cell i = 0; i < length; i++) { + relocation_entry rel = rels->data()[i]; + iter(instruction_operand(rel, this, index)); + index += rel.number_of_parameters(); } } diff --git a/vm/dispatch.cpp b/vm/dispatch.cpp index 4e44512201..810f5eb83e 100644 --- a/vm/dispatch.cpp +++ b/vm/dispatch.cpp @@ -40,7 +40,7 @@ cell factor_vm::lookup_tuple_method(cell obj, cell methods) { while (echelon >= 0) { cell echelon_methods = array_nth(echelons, echelon); - if (tagged(echelon_methods).type() == WORD_TYPE) + if (TAG(echelon_methods) == WORD_TYPE) return echelon_methods; else if (to_boolean(echelon_methods)) { cell klass = nth_superclass(layout, echelon); diff --git a/vm/objects.cpp b/vm/objects.cpp index 012c28a9f2..1f821cbe39 100644 --- a/vm/objects.cpp +++ b/vm/objects.cpp @@ -93,11 +93,10 @@ void factor_vm::primitive_become() { std::map become_map; for (cell i = 0; i < capacity; i++) { - tagged old_obj(array_nth(old_objects, i)); - tagged new_obj(array_nth(new_objects, i)); - - if (old_obj != new_obj) - become_map[old_obj.untagged()] = new_obj.untagged(); + cell old_ptr = array_nth(old_objects, i); + cell new_ptr = array_nth(new_objects, i); + if (old_ptr != new_ptr) + become_map[untag(old_ptr)] = untag(new_ptr); } // Update all references to old objects to point to new objects