1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: concurrency.promises models tools.continuations kernel
4 sequences concurrency.messaging locals continuations threads
5 namespaces namespaces.private make assocs accessors io strings
6 prettyprint math math.parser words effects summary io.styles classes
7 generic.math combinators.short-circuit kernel.private quotations ;
10 SYMBOL: exclude-vocabs
11 SYMBOL: include-vocabs
13 exclude-vocabs { "math" "accessors" } swap set-global
17 : callstack-depth ( callstack -- n )
18 callstack>array midpoint@ ;
22 : include? ( vocab -- ? )
23 include-vocabs get dup [ member? ] [ 2drop t ] if ;
25 : exclude? ( vocab -- ? )
26 exclude-vocabs get dup [ member? ] [ 2drop f ] if ;
38 [ vocabulary>> include? ]
39 [ vocabulary>> exclude? not ]
46 TUPLE: trace-step word inputs ;
50 [ "Word: " % word>> name>> % ]
51 [ " -- inputs: " % inputs>> unparse-short % ] bi
54 : <trace-step> ( continuation word -- trace-step )
55 [ nip ] [ [ data>> ] [ stack-effect in>> length ] bi* short tail* ] 2bi
58 : print-step ( continuation -- )
59 dup continuation-current dup word? [
60 [ nip name>> ] [ <trace-step> ] 2bi write-object nl
65 : print-depth ( continuation -- )
66 call>> callstack-depth
67 [ CHAR: \s <string> write ]
68 [ number>string write ": " write ] bi ;
70 : trace-into? ( continuation -- ? )
71 continuation-current into? ;
73 : trace-step ( continuation -- continuation' )
74 dup call>> innermost-frame-executing quotation? [
75 dup continuation-current end eq? [
78 [ dup trace-into? [ continuation-step-into ] [ continuation-step ] if ]
85 : trace ( quot -- data )
86 [ [ trace-step ] break-hook ] dip
87 [ break ] [ end drop ] surround
90 << \ trace t "no-compile" set-word-prop >>