]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: fixes to use the TAG macro over tagged<object>(obj).type()
authorBjörn Lindqvist <bjourne@gmail.com>
Mon, 23 Nov 2015 01:27:22 +0000 (02:27 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Mon, 23 Nov 2015 01:27:22 +0000 (02:27 +0100)
vm/alien.cpp
vm/code_blocks.cpp
vm/code_blocks.hpp
vm/debug.cpp
vm/dispatch.cpp
vm/objects.cpp

index 9768908f2ff4b397f5ad73220c83e7ee8c1e54a3..7fe30bb69dec14697a7733b4bd630a12a9d494e2 100644 (file)
@@ -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<object>(obj).type()) {
+  switch (TAG(obj)) {
     case ALIEN_TYPE: {
       alien* ptr = untag<alien>(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<object>(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<object>(obj).type()) {
+  switch (TAG(obj)) {
     case BYTE_ARRAY_TYPE:
       return untag<byte_array>(obj)->data<char>();
     case ALIEN_TYPE:
index 0eb1ed338f833b02ff7a8e10b55c2d98c633c861..f65af3d9ede08ea079e842a8e9eceb577c34c59f 100644 (file)
@@ -3,10 +3,9 @@
 namespace factor {
 
 cell code_block::owner_quot() const {
-  tagged<object> executing(owner);
-  if (!optimized_p() && executing->type() == WORD_TYPE)
-    executing = executing.as<word>()->def;
-  return executing.value();
+  if (!optimized_p() && TAG(owner) == WORD_TYPE)
+    return untag<word>(owner)->def;
+  return owner;
 }
 
 /* If the code block is an unoptimized quotation, we can calculate the
@@ -16,18 +15,17 @@ cell code_block::scan(factor_vm* vm, cell addr) const {
     return tag_fixnum(-1);
   }
 
-  tagged<object> obj(owner);
-  if (obj.type_p(WORD_TYPE))
-    obj = obj.as<word>()->def;
-  if (!obj.type_p(QUOTATION_TYPE))
+  cell ptr = owner;
+  if (TAG(ptr) == WORD_TYPE)
+    ptr = untag<word>(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_address(cell obj) {
-  switch (tagged<object>(obj).type()) {
+  switch (TAG(obj)) {
     case WORD_TYPE:
       return untag<word>(obj)->entry_point;
     case QUOTATION_TYPE:
@@ -58,24 +56,21 @@ cell factor_vm::compute_entry_point_pic_tail_address(cell w_) {
 }
 
 cell factor_vm::code_block_owner(code_block* compiled) {
-  tagged<object> 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_p(QUOTATION_TYPE)) {
-    tagged<quotation> quot(owner.as<quotation>());
-    tagged<array> elements(quot->array);
-
-    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]);
-
-    tagged<wrapper> word_wrapper(array_nth(elements.untagged(), 0));
-    return word_wrapper->object;
-  } else
-    return compiled->owner;
+  if (TAG(owner) != QUOTATION_TYPE)
+    return owner;
+
+  quotation* quot = untag<quotation>(owner);
+  array* elements = untag<array>(quot->array);
+
+  FACTOR_ASSERT(array_capacity(elements) == 5);
+  FACTOR_ASSERT(array_nth(elements, 4) == special_objects[PIC_MISS_WORD] ||
+                array_nth(elements, 4) == special_objects[PIC_MISS_TAIL_WORD]);
+  wrapper* wrap = untag<wrapper>(array_nth(elements, 0));
+  return wrap->object;
 }
 
 struct update_word_references_relocation_visitor {
index bfff763eeac4e0ebb7bbeec06481269aa24036d4..00c97985a8f5e928e1dbf4b2f1ad39e3f14476de 100644 (file)
@@ -76,17 +76,18 @@ struct code_block {
   void flush_icache() { factor::flush_icache((cell)this, size()); }
 
   template <typename Iterator> 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 = (byte_array*)UNTAG(relocation);
 
-      for (cell i = 0; i < length; i++) {
-        relocation_entry rel = rels->data<relocation_entry>()[i];
-        iter(instruction_operand(rel, this, index));
-        index += rel.number_of_parameters();
-      }
+    cell index = 0;
+    cell length = (rels->capacity >> TAG_BITS) / sizeof(relocation_entry);
+
+    for (cell i = 0; i < length; i++) {
+      relocation_entry rel = rels->data<relocation_entry>()[i];
+      iter(instruction_operand(rel, this, index));
+      index += rel.number_of_parameters();
     }
   }
 
index a464ff751bedfbf8c69bb82ba1066fd2508b21e8..762aa524b1d07180a5054dc4c9291176b74aa838 100644 (file)
@@ -13,10 +13,10 @@ ostream& operator<<(ostream& out, const string* str) {
 }
 
 void factor_vm::print_word(ostream& out, word* word, cell nesting) {
-  if (tagged<object>(word->vocabulary).type_p(STRING_TYPE))
+  if (TAG(word->vocabulary) == STRING_TYPE)
     out << untag<string>(word->vocabulary) << ":";
 
-  if (tagged<object>(word->name).type_p(STRING_TYPE))
+  if (TAG(word->name) == STRING_TYPE)
     out << untag<string>(word->name);
   else {
     out << "#<not a string: ";
@@ -112,7 +112,7 @@ void factor_vm::print_nested_obj(ostream& out, cell obj, fixnum nesting) {
 
   quotation* quot;
 
-  switch (tagged<object>(obj).type()) {
+  switch (TAG(obj)) {
     case FIXNUM_TYPE:
       out << untag_fixnum(obj);
       break;
@@ -158,7 +158,7 @@ void factor_vm::print_nested_obj(ostream& out, cell obj, fixnum nesting) {
       print_alien(out, untag<alien>(obj), nesting - 1);
       break;
     default:
-      out << "#<" << type_name(tagged<object>(obj).type()) << " @ ";
+      out << "#<" << type_name(TAG(obj)) << " @ ";
       out << (void*)obj << ">";
       break;
   }
index 1c522bfb6816734d1f6ab0b5547737c416bbde66..0fe653489a21de7e3e5e8fd3ca37bcce9f112619 100644 (file)
@@ -45,7 +45,7 @@ cell factor_vm::lookup_tuple_method(cell obj, cell methods) {
   while (echelon >= 0) {
     cell echelon_methods = array_nth(echelons, echelon);
 
-    if (tagged<object>(echelon_methods).type_p(WORD_TYPE))
+    if (TAG(echelon_methods) == WORD_TYPE)
       return echelon_methods;
     else if (to_boolean(echelon_methods)) {
       cell klass = nth_superclass(layout, echelon);
index 034f3ada2a85165a97077ec90e2ab5cc4919e0ad..e0ea7d8e3359af15bab90b7941349a06500b5f83 100644 (file)
@@ -102,11 +102,10 @@ void factor_vm::primitive_become() {
   std::map<object*, object*> become_map;
 
   for (cell i = 0; i < capacity; i++) {
-    tagged<object> old_obj(array_nth(old_objects, i));
-    tagged<object> 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<object>(old_ptr)] = untag<object>(new_ptr);
   }
 
   /* Update all references to old objects to point to new objects */