1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors classes combinators.short-circuit effects
4 generic.math io io.styles kernel kernel.private make math.parser
5 namespaces prettyprint quotations sequences strings summary
6 tools.continuations words ;
11 : callstack-depth ( callstack -- n )
12 callstack>array midpoint@ ;
23 [ vocabulary>> { "math" "accessors" } member? not ] bi or
27 TUPLE: trace-step-state word inputs ;
29 M: trace-step-state summary
31 [ "Word: " % word>> name>> % ]
32 [ " -- inputs: " % inputs>> unparse-short % ] bi
35 : <trace-step> ( continuation word -- trace-step )
36 [ nip ] [ [ data>> ] [ stack-effect in>> length ] bi* cramp tail* ] 2bi
37 \ trace-step-state boa ;
39 : print-step ( continuation -- )
40 dup continuation-current dup word? [
41 [ nip name>> ] [ <trace-step> ] 2bi write-object nl
46 : print-depth ( continuation -- )
47 call>> callstack-depth
48 [ CHAR: \s <string> write ]
49 [ number>string write ": " write ] bi ;
51 : trace-into? ( continuation -- ? )
52 continuation-current into? ;
54 : trace-step ( continuation -- continuation' )
55 dup call>> innermost-frame-executing quotation? [
56 dup continuation-current end eq? [
59 [ dup trace-into? [ continuation-step-into ] [ continuation-step ] if ]
66 : trace ( quot -- data )
67 [ [ trace-step ] break-hook ] dip
68 [ break ] [ end drop ] surround
71 << \ trace t "no-compile" set-word-prop >>