]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: code_block::scan, make it so the method always returns -1 if scan can't be determ...
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 4 Jan 2015 14:30:04 +0000 (15:30 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Thu, 15 Jan 2015 09:29:13 +0000 (09:29 +0000)
core/kernel/kernel-docs.factor
vm/code_blocks.cpp

index d4a00de05da61911d189efe02a0b6b54ed188249..ca07d52a9aec2ab3b0d8bcedf52397891f366b2b 100644 (file)
@@ -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 } }
index bb993f1ff420c1bde13e35529d5b822dcf192ffb..19f8f4946bc1d541c91c87f75c8872f5c30b4fb0 100644 (file)
@@ -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<object> obj(owner);
-      if (obj.type_p(WORD_TYPE))
-        obj = obj.as<word>()->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<object> obj(owner);
+  if (obj.type_p(WORD_TYPE))
+    obj = obj.as<word>()->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) {