char-rename
Björn Lindqvist 2016-11-07 14:18:10 +01:00
parent bbcd039c6c
commit e9c72baf2e
5 changed files with 41 additions and 35 deletions

View File

@ -5,7 +5,7 @@ namespace factor {
// gets the address of an object representing a C pointer, with the // gets the address of an object representing a C pointer, with the
// intention of storing the pointer across code which may potentially GC. // intention of storing the pointer across code which may potentially GC.
char* factor_vm::pinned_alien_offset(cell obj) { char* factor_vm::pinned_alien_offset(cell obj) {
switch (TAG(obj)) { switch (tagged<object>(obj).type()) {
case ALIEN_TYPE: { case ALIEN_TYPE: {
alien* ptr = untag<alien>(obj); alien* ptr = untag<alien>(obj);
if (to_boolean(ptr->expired)) if (to_boolean(ptr->expired))
@ -57,7 +57,7 @@ void factor_vm::primitive_displaced_alien() {
cell alien = ctx->pop(); cell alien = ctx->pop();
cell displacement = to_cell(ctx->pop()); cell displacement = to_cell(ctx->pop());
switch (TAG(alien)) { switch (tagged<object>(alien).type()) {
case BYTE_ARRAY_TYPE: case BYTE_ARRAY_TYPE:
case ALIEN_TYPE: case ALIEN_TYPE:
case F_TYPE: case F_TYPE:
@ -163,7 +163,7 @@ void factor_vm::primitive_dll_validp() {
// gets the address of an object representing a C pointer // gets the address of an object representing a C pointer
char* factor_vm::alien_offset(cell obj) { char* factor_vm::alien_offset(cell obj) {
switch (TAG(obj)) { switch (tagged<object>(obj).type()) {
case BYTE_ARRAY_TYPE: case BYTE_ARRAY_TYPE:
return untag<byte_array>(obj)->data<char>(); return untag<byte_array>(obj)->data<char>();
case ALIEN_TYPE: case ALIEN_TYPE:

View File

@ -3,23 +3,28 @@
namespace factor { namespace factor {
static cell code_block_owner(code_block* compiled) { static cell code_block_owner(code_block* compiled) {
cell owner = compiled->owner; tagged<object> owner(compiled->owner);
// Cold generic word call sites point to quotations that call the // Cold generic word call sites point to quotations that call the
// inline-cache-miss and inline-cache-miss-tail primitives. // inline-cache-miss and inline-cache-miss-tail primitives.
if (TAG(owner) != QUOTATION_TYPE) if (owner.type() == QUOTATION_TYPE) {
return owner; tagged<quotation> quot(owner.as<quotation>());
tagged<array> elements(quot->array);
quotation* quot = untag<quotation>(owner); FACTOR_ASSERT(array_capacity(elements.untagged()) == 5);
array* elements = untag<array>(quot->array); FACTOR_ASSERT(array_nth(elements.untagged(), 4) ==
special_objects[PIC_MISS_WORD] ||
array_nth(elements.untagged(), 4) ==
special_objects[PIC_MISS_TAIL_WORD]);
FACTOR_ASSERT(array_capacity(elements) == 5); tagged<wrapper> word_wrapper(array_nth(elements.untagged(), 0));
wrapper* wrap = untag<wrapper>(array_nth(elements, 0)); return word_wrapper->object;
return wrap->object; }
return compiled->owner;
} }
static cell compute_entry_point_address(cell obj) { static cell compute_entry_point_address(cell obj) {
switch (TAG(obj)) { switch (tagged<object>(obj).type()) {
case WORD_TYPE: case WORD_TYPE:
return untag<word>(obj)->entry_point; return untag<word>(obj)->entry_point;
case QUOTATION_TYPE: case QUOTATION_TYPE:
@ -38,9 +43,10 @@ static cell compute_here_address(cell arg, cell offset, code_block* compiled) {
} }
cell code_block::owner_quot() const { cell code_block::owner_quot() const {
if (type() != CODE_BLOCK_OPTIMIZED && TAG(owner) == WORD_TYPE) tagged<object> executing(owner);
return untag<word>(owner)->def; if (type() != CODE_BLOCK_OPTIMIZED && executing->type() == WORD_TYPE)
return owner; executing = executing.as<word>()->def;
return executing.value();
} }
// If the code block is an unoptimized quotation, we can calculate the // If the code block is an unoptimized quotation, we can calculate the
@ -51,13 +57,13 @@ cell code_block::scan(factor_vm* vm, cell addr) const {
return tag_fixnum(-1); return tag_fixnum(-1);
} }
cell ptr = owner; tagged<object> obj(owner);
if (TAG(ptr) == WORD_TYPE) if (obj.type() == WORD_TYPE)
ptr = untag<word>(ptr)->def; obj = obj.as<word>()->def;
if (TAG(ptr) != QUOTATION_TYPE) if (obj.type() != QUOTATION_TYPE)
return tag_fixnum(-1); return tag_fixnum(-1);
cell ofs = offset(addr); cell ofs = offset(addr);
return tag_fixnum(vm->quot_code_offset_to_scan(ptr, ofs)); return tag_fixnum(vm->quot_code_offset_to_scan(obj.value(), ofs));
} }
cell factor_vm::compute_entry_point_pic_address(word* w, cell tagged_quot) { cell factor_vm::compute_entry_point_pic_address(word* w, cell tagged_quot) {

View File

@ -74,13 +74,11 @@ struct code_block {
void flush_icache() { factor::flush_icache((cell)this, size()); } void flush_icache() { factor::flush_icache((cell)this, size()); }
template <typename Iterator> void each_instruction_operand(Iterator& iter) { template <typename Iterator> void each_instruction_operand(Iterator& iter) {
if (!to_boolean(relocation)) if (to_boolean(relocation)) {
return; byte_array* rels = (byte_array*)UNTAG(relocation);
byte_array* rels = untag<byte_array>(relocation);
cell index = 0; cell index = 0;
cell length = untag_fixnum(rels->capacity) / sizeof(relocation_entry); cell length = (rels->capacity >> TAG_BITS) / sizeof(relocation_entry);
for (cell i = 0; i < length; i++) { for (cell i = 0; i < length; i++) {
relocation_entry rel = rels->data<relocation_entry>()[i]; relocation_entry rel = rels->data<relocation_entry>()[i];
@ -88,6 +86,7 @@ struct code_block {
index += rel.number_of_parameters(); index += rel.number_of_parameters();
} }
} }
}
cell offset(cell addr) const { return addr - entry_point(); } cell offset(cell addr) const { return addr - entry_point(); }

View File

@ -40,7 +40,7 @@ cell factor_vm::lookup_tuple_method(cell obj, cell methods) {
while (echelon >= 0) { while (echelon >= 0) {
cell echelon_methods = array_nth(echelons, echelon); cell echelon_methods = array_nth(echelons, echelon);
if (TAG(echelon_methods) == WORD_TYPE) if (tagged<object>(echelon_methods).type() == WORD_TYPE)
return echelon_methods; return echelon_methods;
else if (to_boolean(echelon_methods)) { else if (to_boolean(echelon_methods)) {
cell klass = nth_superclass(layout, echelon); cell klass = nth_superclass(layout, echelon);

View File

@ -93,10 +93,11 @@ void factor_vm::primitive_become() {
std::map<object*, object*> become_map; std::map<object*, object*> become_map;
for (cell i = 0; i < capacity; i++) { for (cell i = 0; i < capacity; i++) {
cell old_ptr = array_nth(old_objects, i); tagged<object> old_obj(array_nth(old_objects, i));
cell new_ptr = array_nth(new_objects, i); tagged<object> new_obj(array_nth(new_objects, i));
if (old_ptr != new_ptr)
become_map[untag<object>(old_ptr)] = untag<object>(new_ptr); if (old_obj != new_obj)
become_map[old_obj.untagged()] = new_obj.untagged();
} }
// Update all references to old objects to point to new objects // Update all references to old objects to point to new objects