VM: change callstack>array primitive so it doesn't reverse anymore

This fixes one part of the #452 bug.
char-rename
Björn Lindqvist 2016-10-11 09:32:55 +02:00
parent 98db13fe9d
commit 46105b62f6
8 changed files with 27 additions and 14 deletions

View File

@ -11,10 +11,10 @@ IN: compiler.tests.stack-trace
: bar ( -- * ) foo 4 ; : bar ( -- * ) foo 4 ;
: baz ( -- * ) bar 5 ; : baz ( -- * ) bar 5 ;
[ baz ] [ 3 = ] must-fail-with [ baz ] [ 3 = ] must-fail-with
[ t ] [ {
symbolic-stack-trace { foo bar baz }
2 head* } [
{ baz bar foo } tail? 2 5 symbolic-stack-trace subseq
] unit-test ] unit-test
: bleh ( seq -- seq' ) [ 3 + ] map [ 0 > ] filter ; : bleh ( seq -- seq' ) [ 3 + ] map [ 0 > ] filter ;

View File

@ -249,7 +249,7 @@ HELP: stack.
HELP: callstack. HELP: callstack.
{ $values { "callstack" 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 HELP: .c
{ $description "Displays the contents of the call stack, with the top of the stack printed first." } ; { $description "Displays the contents of the call stack, with the top of the stack printed first." } ;

View File

@ -122,7 +122,7 @@ SYMBOL: =>
PRIVATE> PRIVATE>
: callstack. ( callstack -- ) : callstack. ( callstack -- )
callstack>array 3 <groups> callstack>array 3 <groups> reverse
{ { table-gap { 5 5 } } } [ [ callframe. ] each ] tabular-output nl ; { { table-gap { 5 5 } } } [ [ callframe. ] each ] tabular-output nl ;
: .c ( -- ) get-callstack callstack. ; : .c ( -- ) get-callstack callstack. ;

View File

@ -35,6 +35,10 @@ HELP: -rot $complex-shuffle ;
HELP: dupd $complex-shuffle ; HELP: dupd $complex-shuffle ;
HELP: swapd $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 HELP: get-datastack
{ $values { "array" array } } { $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." } ; { $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." } ;

View File

@ -153,7 +153,7 @@ IN: kernel.tests
! Test traceback accuracy ! Test traceback accuracy
: last-frame ( -- pair ) : 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 } { [ 1 2 [ 3 throw ] call 4 ] [ 1 2 [ 3 throw ] call 4 ] 3 }

View File

@ -1,6 +1,6 @@
USING: accessors arrays compiler.units definitions eval generic USING: accessors arrays compiler.units definitions eval generic
io.streams.string kernel math namespaces parser sequences io.streams.string kernel math namespaces parser sequences tools.test
tools.test vocabs words words.symbol ; vocabs words words.private words.symbol ;
IN: words.tests IN: words.tests
{ 4 } [ { 4 } [
@ -134,3 +134,15 @@ DEFER: deferred
] unit-test ] unit-test
[ "hi" word-code ] must-fail [ "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

View File

@ -52,7 +52,8 @@ M: word definition def>> ;
<PRIVATE <PRIVATE
: caller ( callstack -- word ) callstack>array <reversed> third ; : caller ( callstack -- word )
callstack>array first ;
PRIVATE> PRIVATE>

View File

@ -70,10 +70,6 @@ void factor_vm::primitive_callstack_to_array() {
}; };
iterate_callstack_object(callstack.untagged(), stack_frame_accumulator); 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(); frames.trim();
ctx->replace(frames.elements.value()); ctx->replace(frames.elements.value());