]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: change callstack>array primitive so it doesn't reverse anymore
authorBjörn Lindqvist <bjourne@gmail.com>
Tue, 11 Oct 2016 07:32:55 +0000 (09:32 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Wed, 12 Oct 2016 23:34:55 +0000 (01:34 +0200)
This fixes one part of the #452 bug.

basis/compiler/tests/stack-trace.factor
basis/prettyprint/prettyprint-docs.factor
basis/prettyprint/prettyprint.factor
core/kernel/kernel-docs.factor
core/kernel/kernel-tests.factor
core/words/words-tests.factor
core/words/words.factor
vm/callstack.cpp

index 87e629adb3522d2ff0aa908eb28f2b712ab4ae6a..776e58b1455fcbfb330ce24bd5c1ecc181db6cb6 100644 (file)
@@ -11,10 +11,10 @@ IN: compiler.tests.stack-trace
 : bar ( -- * ) foo 4 ;
 : baz ( -- * ) bar 5 ;
 [ baz ] [ 3 = ] must-fail-with
-[ t ] [
-    symbolic-stack-trace
-    2 head*
-    { baz bar foo } tail?
+{
+    { foo bar baz }
+} [
+    2 5 symbolic-stack-trace subseq
 ] unit-test
 
 : bleh ( seq -- seq' ) [ 3 + ] map [ 0 > ] filter ;
index 959e2283413eca080217bc04acff728b2e56cc54..c6dfc908b2c2da0b1016ea8e54310ac6a0134c54 100644 (file)
@@ -249,7 +249,7 @@ HELP: stack.
 
 HELP: callstack.
 { $values { "callstack" callstack } }
-{ $description "Displays a sequence output by " { $link callstack } " in a nice way, by highlighting the current execution point in every call frame with " { $link => } "." } ;
+{ $description "Displays the " { $link callstack } " in a user friendly fashion with outermost stack frames first and innermost frames at the bottom. The current execution point in every call frame is highlighted with " { $link => } "." } ;
 
 HELP: .c
 { $description "Displays the contents of the call stack, with the top of the stack printed first." } ;
index 661fe373e11c911f83ff6c2d20032e117b3e3d59..6323d05ea43261a4967b740ff0a319f979091841 100644 (file)
@@ -122,7 +122,7 @@ SYMBOL: =>
 PRIVATE>
 
 : callstack. ( callstack -- )
-    callstack>array 3 <groups>
+    callstack>array 3 <groups> reverse
     { { table-gap { 5 5 } } } [ [ callframe. ] each ] tabular-output nl ;
 
 : .c ( -- ) get-callstack callstack. ;
index facf08e51382b50a40642c06bf8f991db4fbc104..3bf0c8ec836fbb5fc1ce0cdc5d8f19501200ab76 100644 (file)
@@ -35,6 +35,10 @@ HELP: -rot  $complex-shuffle ;
 HELP: dupd  $complex-shuffle ;
 HELP: swapd $complex-shuffle ;
 
+HELP: callstack>array
+{ $values { "callstack" callstack } { "array" array } }
+{ $description "Converts the callstack to an array containing groups of three elements. The array is in reverse order so that the innermost frame comes first." } ;
+
 HELP: get-datastack
 { $values { "array" array } }
 { $description "Outputs an array containing a copy of the data stack contents right before the call to this word, with the top of the stack at the end of the array." } ;
index bbbe94adc008734457a2c52966492f829b99a9be..356982e068e4eb1e8c513865677ed419c7c39132 100644 (file)
@@ -153,7 +153,7 @@ IN: kernel.tests
 
 ! Test traceback accuracy
 : last-frame ( -- pair )
-    error-continuation get call>> callstack>array 6 head* 3 tail* ;
+    6 9 error-continuation get call>> callstack>array subseq ;
 
 {
     { [ 1 2 [ 3 throw ] call 4 ] [ 1 2 [ 3 throw ] call 4 ] 3 }
index b1bdde27b7a66a43bd5985c345e7501525882a1b..0333cafec9fc1911efa06775353054a784aa9ea7 100644 (file)
@@ -1,6 +1,6 @@
 USING: accessors arrays compiler.units definitions eval generic
-io.streams.string kernel math namespaces parser sequences
-tools.test vocabs words words.symbol ;
+io.streams.string kernel math namespaces parser sequences tools.test
+vocabs words words.private words.symbol ;
 IN: words.tests
 
 { 4 } [
@@ -134,3 +134,15 @@ DEFER: deferred
 ] unit-test
 
 [ "hi" word-code ] must-fail
+
+! Extra return values to defeat tco.
+: i-call1 ( -- w n )
+    get-callstack caller 20 ;
+
+! caller
+: i-call2 ( -- w x y )
+    i-call1 30 ;
+
+{ i-call2 } [
+    i-call2 2drop
+] unit-test
index 71126cf933a2c95f644ab59aac6b2bd844ae3809..79b1f016c6e3403880abaccd08841dd7a47352be 100644 (file)
@@ -52,7 +52,8 @@ M: word definition def>> ;
 
 <PRIVATE
 
-: caller ( callstack -- word ) callstack>array <reversed> third ;
+: caller ( callstack -- word )
+    callstack>array first ;
 
 PRIVATE>
 
index 103a7655476c64b8dd6f7d2bd85d3f009d211be6..45caa0131563baeb10143d07d3b0ed721fed0b46 100644 (file)
@@ -70,10 +70,6 @@ void factor_vm::primitive_callstack_to_array() {
   };
   iterate_callstack_object(callstack.untagged(), stack_frame_accumulator);
 
-  // The callstack iterator visits frames in reverse order (top to bottom)
-  std::reverse((stack_frame_in_array*)frames.elements->data(),
-               (stack_frame_in_array*)(frames.elements->data() +
-                                       frames.count));
   frames.trim();
 
   ctx->replace(frames.elements.value());