diff --git a/vm/code_blocks.cpp b/vm/code_blocks.cpp index bc3171a239..4e1944b792 100755 --- a/vm/code_blocks.cpp +++ b/vm/code_blocks.cpp @@ -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().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 diff --git a/vm/code_blocks.hpp b/vm/code_blocks.hpp index 099b793866..d14a55c479 100644 --- a/vm/code_blocks.hpp +++ b/vm/code_blocks.hpp @@ -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 cell size(Fixup fixup) const { return size(); diff --git a/vm/debug.cpp b/vm/debug.cpp index 17363a526c..54a48897e5 100755 --- a/vm/debug.cpp +++ b/vm/debug.cpp @@ -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; } }