Fixing tools.interpreter

release
Slava 2007-10-03 20:49:17 -04:00
parent 1ef514ebdb
commit 0183a40717
4 changed files with 31 additions and 11 deletions

View File

@ -11,7 +11,8 @@ IN: tools.interpreter.debug
[ [
"out" set "out" set
[ f swap 2array restore "out" get continue ] callcc0 [ f swap 2array restore "out" get continue ] callcc0
] swap [ datastack "datastack" set stop ] 3append callcc0 ; ] swap [ datastack "datastack" set stop ]
3append callcc0 ;
: test-interpreter ( quot -- ) : test-interpreter ( quot -- )
init-interpreter run-interpreter "datastack" get ; init-interpreter run-interpreter "datastack" get ;

View File

@ -88,6 +88,10 @@ IN: temporary
[ [ 2 2 + number>string print ] string-out ] test-interpreter [ [ 2 2 + number>string print ] string-out ] test-interpreter
] unit-test ] unit-test
[ { 1 2 3 } ] [
[ { 1 2 3 } set-datastack ] test-interpreter
] unit-test
[ { 6 } ] [ { 6 } ]
[ [ 3 [ nip continue ] callcc0 2 * ] test-interpreter ] unit-test [ [ 3 [ nip continue ] callcc0 2 * ] test-interpreter ] unit-test
@ -97,6 +101,10 @@ IN: temporary
[ { 6 } ] [ { 6 } ]
[ [ [ 3 throw ] catch 2 * ] test-interpreter ] unit-test [ [ [ 3 throw ] catch 2 * ] test-interpreter ] unit-test
[ { "{ 1 2 3 }\n" } ] [
[ [ { 1 2 3 } . ] string-out ] test-interpreter
] unit-test
: meta-catch interpreter get continuation-catch ; : meta-catch interpreter get continuation-catch ;
! Step back test ! Step back test

View File

@ -26,7 +26,8 @@ M: continuation restore
clone interpreter set ; clone interpreter set ;
M: pair restore M: pair restore
first2 restore [ nip f ] curry with-interpreter-datastack ; first2 clone interpreter set
[ nip f ] curry with-interpreter-datastack ;
M: f restore M: f restore
drop interpreter off ; drop interpreter off ;
@ -49,17 +50,21 @@ M: f restore
] if ] if
] ?if ; ] ?if ;
: (step-into-continuation)
continuation callstack over set-continuation-call break ;
{ {
{ call [ (step-into-call) ] } { call [ (step-into-call) ] }
{ (throw) [ (step-into-call) ] } { (throw) [ (step-into-call) ] }
{ execute [ (step-into-execute) ] } { execute [ (step-into-execute) ] }
{ if [ (step-into-if) ] } { if [ (step-into-if) ] }
{ dispatch [ (step-into-dispatch) ] } { dispatch [ (step-into-dispatch) ] }
{ continuation [ (step-into-continuation) ] }
} [ "step-into" set-word-prop ] assoc-each } [ "step-into" set-word-prop ] assoc-each
{ {
>n ndrop >c c> >n ndrop >c c>
continuation continue continue-with continue continue-with
(continue-with) stop break (continue-with) stop break
} [ } [
dup [ execute break ] curry dup [ execute break ] curry
@ -72,9 +77,12 @@ SYMBOL: history
: save-interpreter ( -- ) : save-interpreter ( -- )
history get [ interpreter get clone swap push ] when* ; history get [ interpreter get clone swap push ] when* ;
: restore-interpreter ( interp -- )
clone interpreter set ;
: step-back ( -- ) : step-back ( -- )
history get dup empty? history get dup empty?
[ drop ] [ pop restore ] if ; [ drop ] [ pop restore-interpreter ] if ;
: (continue) ( continuation -- ) : (continue) ( continuation -- )
>continuation< >continuation<

View File

@ -227,26 +227,29 @@ DEFINE_PRIMITIVE(innermost_stack_frame_scan)
DEFINE_PRIMITIVE(set_innermost_stack_frame_quot) DEFINE_PRIMITIVE(set_innermost_stack_frame_quot)
{ {
CELL callstack = dpop(); F_CALLSTACK *callstack = untag_callstack(dpop());
REGISTER_ROOT(callstack);
F_QUOTATION *quot = untag_quotation(dpop()); F_QUOTATION *quot = untag_quotation(dpop());
REGISTER_UNTAGGED(callstack);
REGISTER_UNTAGGED(quot); REGISTER_UNTAGGED(quot);
if(quot->compiled == F) if(quot->compiled == F)
jit_compile(quot); jit_compile(quot);
UNREGISTER_UNTAGGED(quot); UNREGISTER_UNTAGGED(quot);
UNREGISTER_ROOT(callstack); UNREGISTER_UNTAGGED(callstack);
F_STACK_FRAME *inner = innermost_stack_frame( F_STACK_FRAME *inner = innermost_stack_frame(callstack);
untag_callstack(callstack));
type_check(QUOTATION_TYPE,frame_executing(inner)); type_check(QUOTATION_TYPE,frame_executing(inner));
CELL scan = inner->scan - inner->array; CELL scan = inner->scan - inner->array;
#ifdef CALLSTACK_UP_P #ifdef CALLSTACK_UP_P
CELL top = (CELL)(callstack + 1);
CELL bottom = top + untag_fixnum_fast(callstack->length);
CELL base = callstack->bottom;
CELL delta = (bottom - base);
F_STACK_FRAME *next = REBASE_FRAME_SUCCESSOR(inner,delta); F_STACK_FRAME *next = REBASE_FRAME_SUCCESSOR(inner,delta);
CELL offset = *(XT *)(next + 1) - inner->xt; CELL offset = *(XT *)(next + 1) - inner->xt;
#else #else