This fixes one part of the #452 bug.
: 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 ;
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." } ;
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. ;
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." } ;
! 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 }
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 } [
] 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
<PRIVATE
-: caller ( callstack -- word ) callstack>array <reversed> third ;
+: caller ( callstack -- word )
+ callstack>array first ;
PRIVATE>
};
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());