]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: pack frame size into code block header bits
authorJoe Groff <arcata@gmail.com>
Sat, 26 Nov 2011 03:23:07 +0000 (19:23 -0800)
committerJoe Groff <arcata@gmail.com>
Wed, 14 Dec 2011 17:56:45 +0000 (09:56 -0800)
vm/code_blocks.cpp
vm/code_blocks.hpp
vm/debug.cpp

index bc3171a2398ee2b2efb425ffbe663f26abf08a4a..4e1944b79263376ec49acac39cd19d8c118b53fe 100755 (executable)
@@ -433,7 +433,7 @@ code_block *factor_vm::add_code_block(code_block_type type, cell code_, cell lab
        if(to_boolean(labels.value()))
                fixup_labels(labels.as<array>().untagged(),compiled);
 
-       compiled->stack_frame_size = frame_size_untagged;
+       compiled->set_stack_frame_size(frame_size_untagged);
 
        /* Once we are ready, fill in literal and word references in this code
        block's instruction operands. In most cases this is done right after this
index 099b7938667da3be69b7acd6bbd3beae7afb54d0..d14a55c479fcf074cf452f7a2e00ae602c8727ee 100644 (file)
@@ -5,15 +5,17 @@ namespace factor
 struct code_block
 {
        // header format (bits indexed with least significant as zero):
-       // bit   0   : free?
-       // bits  1- 2: type (as a code_block_type)
-       // bits  4-  : code size / 16
+       // bit   0  : free?
+       // bits  1-2: type (as a code_block_type)
+       // if not free:
+       //   bits  3-23: code size / 8
+       //   bits 24-31: stack frame size / 16
+       // 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 stack_frame_size;
-       cell pad;
 
        bool free_p() const
        {
@@ -42,11 +44,32 @@ struct code_block
 
        cell size() const
        {
-               cell size = header & ~7;
+               cell size;
+               if (free_p())
+                       size = header & ~7;
+               else
+                       size = header & 0xFFFFF8;
                FACTOR_ASSERT(size > 0);
                return size;
        }
 
+       cell stack_frame_size() const
+       {
+               if (free_p())
+                       return 0;
+               else
+                       return (header >> 20) & 0xFF0;
+       }
+
+       void set_stack_frame_size(cell frame_size)
+       {
+               FACTOR_ASSERT(size() < 0xFFFFFF);
+               FACTOR_ASSERT(!free_p());
+               FACTOR_ASSERT(frame_size % 16 == 0);
+               FACTOR_ASSERT(frame_size <= 0xFF0);
+               header = (header & 0xFFFFFF) | (frame_size << 20);
+       }
+
        template<typename Fixup> cell size(Fixup fixup) const
        {
                return size();
index 17363a526c0caf1d20c5e7ae9fb87ba760898ea4..54a48897e5fca9e1ce6c8b554d81bdda2822f1f1 100755 (executable)
@@ -418,7 +418,7 @@ struct code_block_printer {
                        std::cout << std::hex << (cell)scan << std::dec << " ";
                        std::cout << std::hex << size << std::dec << " ";
                        std::cout << status << " ";
-                       std::cout << "stack frame " << scan->stack_frame_size;
+                       std::cout << "stack frame " << scan->stack_frame_size();
                        std::cout << std::endl;
                }
        }