From 11e906139b99652a2e0d89a6d6bfb2c149a7ddcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Sun, 4 Jan 2015 15:30:04 +0100 Subject: [PATCH] VM: code_block::scan, make it so the method always returns -1 if scan can't be determined, part of the fix for #1265 --- core/kernel/kernel-docs.factor | 8 +++++++- vm/code_blocks.cpp | 31 +++++++++++++------------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/core/kernel/kernel-docs.factor b/core/kernel/kernel-docs.factor index d4a00de05d..ca07d52a9a 100644 --- a/core/kernel/kernel-docs.factor +++ b/core/kernel/kernel-docs.factor @@ -44,7 +44,13 @@ HELP: set-retainstack HELP: callstack { $values { "callstack" callstack } } -{ $description "Outputs a copy of the call stack contents, with the top of the stack at the end of the vector. The stack frame of the caller word is " { $emphasis "not" } " included." } ; +{ $description "Outputs a copy of the call stack contents, with the top of the stack at the end of the vector. The stack frame of the caller word is " { $emphasis "not" } " included. Each group of three elements in the callstack is frame:" + { $list + "The first element is the executing word or quotation." + "The second element is the executing quotation." + "The third element is the offset in the executing quotation, or -1 if the offset can't be determined." + } +} ; HELP: set-callstack { $values { "callstack" callstack } } diff --git a/vm/code_blocks.cpp b/vm/code_blocks.cpp index bb993f1ff4..19f8f4946b 100644 --- a/vm/code_blocks.cpp +++ b/vm/code_blocks.cpp @@ -9,26 +9,21 @@ cell code_block::owner_quot() const { return executing.value(); } +/* If the code block is an unoptimized quotation, we can calculate the + scan offset. In all other cases -1 is returned. */ cell code_block::scan(factor_vm* vm, void* addr) const { - switch (type()) { - case code_block_unoptimized: { - tagged obj(owner); - if (obj.type_p(WORD_TYPE)) - obj = obj.as()->def; - - if (obj.type_p(QUOTATION_TYPE)) - return tag_fixnum( - vm->quot_code_offset_to_scan(obj.value(), offset(addr))); - else - return false_object; - } - case code_block_optimized: - case code_block_pic: - return false_object; - default: - critical_error("Bad frame type", type()); - return false_object; + if (type() != code_block_unoptimized) { + return tag_fixnum(-1); } + + tagged obj(owner); + if (obj.type_p(WORD_TYPE)) + obj = obj.as()->def; + if (!obj.type_p(QUOTATION_TYPE)) + return tag_fixnum(-1); + + cell ofs = offset(addr); + return tag_fixnum(vm->quot_code_offset_to_scan(obj.value(), ofs)); } cell factor_vm::compute_entry_point_address(cell obj) {