]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/code_blocks.hpp
io.streams.256color: faster by caching styles
[factor.git] / vm / code_blocks.hpp
index bfff763eeac4e0ebb7bbeec06481269aa24036d4..baa0faa6c9d3554d28cfccd28598f8f1252a997a 100644 (file)
@@ -1,6 +1,6 @@
 namespace factor {
 
-/* The compiled code heap is structured into blocks. */
+// The compiled code heap is structured into blocks.
 struct code_block {
   // header format (bits indexed with least significant as zero):
   // bit   0  : free?
@@ -11,9 +11,9 @@ struct code_block {
   // if free:
   //   bits  3-end: code size / 8
   cell header;
-  cell owner;      /* tagged pointer to word, quotation or f */
-  cell parameters; /* tagged pointer to array or f */
-  cell relocation; /* tagged pointer to byte-array or f */
+  cell owner;      // tagged pointer to word, quotation or f
+  cell parameters; // tagged pointer to array or f
+  cell relocation; // tagged pointer to byte-array or f
 
   bool free_p() const { return (header & 1) == 1; }
 
@@ -25,9 +25,7 @@ struct code_block {
     header = ((header & ~0x7) | (type << 1));
   }
 
-  bool pic_p() const { return type() == code_block_pic; }
-
-  bool optimized_p() const { return type() == code_block_optimized; }
+  bool pic_p() const { return type() == CODE_BLOCK_PIC; }
 
   cell size() const {
     cell size;
@@ -47,10 +45,10 @@ struct code_block {
 
   cell stack_frame_size_for_address(cell addr) const {
     cell natural_frame_size = stack_frame_size();
-    /* The first instruction in a code block is the prolog safepoint,
-       and a leaf procedure code block will record a frame size of zero.
-       If we're seeing a stack frame in either of these cases, it's a
-       fake "leaf frame" set up by the signal handler. */
+    // The first instruction in a code block is the prolog safepoint,
+    // and a leaf procedure code block will record a frame size of zero.
+    // If we're seeing a stack frame in either of these cases, it's a
+    // fake "leaf frame" set up by the signal handler.
     if (natural_frame_size == 0 || addr == entry_point())
       return LEAF_FRAME_SIZE;
     return natural_frame_size;
@@ -64,11 +62,11 @@ struct code_block {
     header = (header & 0xFFFFFF) | (frame_size << 20);
   }
 
-  template <typename Fixup> cell size(Fixup fixup) const { return size(); }
+  template <typename Fixup> cell size(Fixup fixup) const { (void)fixup; return size(); }
 
   cell entry_point() const { return (cell)(this + 1); }
 
-  /* GC info is stored at the end of the block */
+  // GC info is stored at the end of the block
   gc_info* block_gc_info() const {
     return (gc_info*)((uint8_t*)this + size() - sizeof(gc_info));
   }
@@ -76,17 +74,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;
+
+    byte_array* rels = untag<byte_array>(relocation);
 
-      cell index = 0;
-      cell length = (rels->capacity >> TAG_BITS) / sizeof(relocation_entry);
+    cell index = 0;
+    cell length = untag_fixnum(rels->capacity) / 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();
-      }
+    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();
     }
   }