]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: object_size, compute_entry_point_address, code_block_owner made into
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 24 Apr 2016 12:45:03 +0000 (14:45 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Sun, 24 Apr 2016 12:45:03 +0000 (14:45 +0200)
functions

It is to make the vm class less heavy

vm/code_blocks.cpp
vm/factor.hpp
vm/objects.cpp
vm/vm.hpp

index 2088a3d9b4db3560ae93c46f11d05f619b677b2d..aa14eb8cb6ab22c983bfb16a149211e1dc9b4cdd 100644 (file)
@@ -2,6 +2,34 @@
 
 namespace factor {
 
+cell code_block_owner(code_block* compiled) {
+  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 (TAG(owner) != QUOTATION_TYPE)
+    return owner;
+
+  quotation* quot = untag<quotation>(owner);
+  array* elements = untag<array>(quot->array);
+
+  FACTOR_ASSERT(array_capacity(elements) == 5);
+  wrapper* wrap = untag<wrapper>(array_nth(elements, 0));
+  return wrap->object;
+}
+
+cell compute_entry_point_address(cell obj) {
+  switch (TAG(obj)) {
+    case WORD_TYPE:
+      return untag<word>(obj)->entry_point;
+    case QUOTATION_TYPE:
+      return untag<quotation>(obj)->entry_point;
+    default:
+      critical_error("Expected word or quotation", obj);
+      return 0;
+  }
+}
+
 cell code_block::owner_quot() const {
   if (!optimized_p() && TAG(owner) == WORD_TYPE)
     return untag<word>(owner)->def;
@@ -24,18 +52,6 @@ cell code_block::scan(factor_vm* vm, cell addr) const {
   return tag_fixnum(vm->quot_code_offset_to_scan(ptr, ofs));
 }
 
-cell factor_vm::compute_entry_point_address(cell obj) {
-  switch (TAG(obj)) {
-    case WORD_TYPE:
-      return untag<word>(obj)->entry_point;
-    case QUOTATION_TYPE:
-      return untag<quotation>(obj)->entry_point;
-    default:
-      critical_error("Expected word or quotation", obj);
-      return 0;
-  }
-}
-
 cell factor_vm::compute_entry_point_pic_address(word* w, cell tagged_quot) {
   if (!to_boolean(tagged_quot) || max_pic_size == 0)
     return w->entry_point;
@@ -55,24 +71,6 @@ cell factor_vm::compute_entry_point_pic_tail_address(cell w_) {
   return compute_entry_point_pic_address(w.untagged(), w->pic_tail_def);
 }
 
-cell factor_vm::code_block_owner(code_block* compiled) {
-  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 (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 {
   factor_vm* parent;
   bool reset_inline_caches;
@@ -87,12 +85,12 @@ struct update_word_references_relocation_visitor {
       case RT_ENTRY_POINT: {
         cell owner = compiled->owner;
         if (to_boolean(owner))
-          op.store_value(parent->compute_entry_point_address(owner));
+          op.store_value(compute_entry_point_address(owner));
         break;
       }
       case RT_ENTRY_POINT_PIC: {
         if (reset_inline_caches || !compiled->pic_p()) {
-          cell owner = parent->code_block_owner(compiled);
+          cell owner = code_block_owner(compiled);
           if (to_boolean(owner))
             op.store_value(parent->compute_entry_point_pic_address(owner));
         }
@@ -100,7 +98,7 @@ struct update_word_references_relocation_visitor {
       }
       case RT_ENTRY_POINT_PIC_TAIL: {
         if (reset_inline_caches || !compiled->pic_p()) {
-          cell owner = parent->code_block_owner(compiled);
+          cell owner = code_block_owner(compiled);
           if (to_boolean(owner))
             op.store_value(parent->compute_entry_point_pic_tail_address(owner));
         }
@@ -239,7 +237,7 @@ struct initial_code_block_visitor {
       case RT_LITERAL:
         return next_literal();
       case RT_ENTRY_POINT:
-        return parent->compute_entry_point_address(next_literal());
+        return compute_entry_point_address(next_literal());
       case RT_ENTRY_POINT_PIC:
         return parent->compute_entry_point_pic_address(next_literal());
       case RT_ENTRY_POINT_PIC_TAIL:
index 2af555b4a6277228807412f52b8af0ee3833efb4..3e2c09736835163f83b33f472d5633ec45d9cffd 100644 (file)
@@ -4,6 +4,9 @@ VM_C_API void init_globals();
 factor_vm* new_factor_vm();
 VM_C_API void start_standalone_factor(int argc, vm_char** argv);
 
+// objects
+cell object_size(cell tagged);
+
 // os-*
 void open_console();
 void close_console();
index 6ac8bf6d92b9d2d1d2e8759d4be27fbcf9dbc110..1a8b56a5b2be7ad5242fda728275486dc5e64ce1 100644 (file)
@@ -2,6 +2,13 @@
 
 namespace factor {
 
+/* Size of the object pointed to by a tagged pointer */
+cell object_size(cell tagged) {
+  if (immediate_p(tagged))
+    return 0;
+  return untag<object>(tagged)->size();
+}
+
 void factor_vm::primitive_special_object() {
   fixnum n = untag_fixnum(ctx->peek());
   ctx->replace(special_objects[n]);
@@ -57,13 +64,6 @@ cell factor_vm::clone_object(cell obj_) {
 /* Allocates memory */
 void factor_vm::primitive_clone() { ctx->replace(clone_object(ctx->peek())); }
 
-/* Size of the object pointed to by a tagged pointer */
-cell factor_vm::object_size(cell tagged) {
-  if (immediate_p(tagged))
-    return 0;
-  return untag<object>(tagged)->size();
-}
-
 /* Allocates memory */
 void factor_vm::primitive_size() {
   ctx->replace(from_unsigned_cell(object_size(ctx->peek())));
index 82a1664115e91bc926a3b40d804fb215a2a13613..1eb116a004d82afa4f75ccd47ec0a76d91ff73b9 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -186,7 +186,6 @@ struct factor_vm {
   void primitive_identity_hashcode();
   void compute_identity_hashcode(object* obj);
   void primitive_compute_identity_hashcode();
-  cell object_size(cell tagged);
   cell clone_object(cell obj_);
   void primitive_clone();
   void primitive_become();
@@ -559,13 +558,11 @@ struct factor_vm {
   void primitive_fclose();
 
   // code_block
-  cell compute_entry_point_address(cell obj);
   cell compute_entry_point_pic_address(word* w, cell tagged_quot);
   cell compute_entry_point_pic_address(cell w_);
   cell compute_entry_point_pic_tail_address(cell w_);
   cell compute_external_address(instruction_operand op);
 
-  cell code_block_owner(code_block* compiled);
   void update_word_references(code_block* compiled, bool reset_inline_caches);
   void undefined_symbol();
   cell compute_dlsym_address(array* literals, cell index, bool toc);