1 ! Copyright (C) 2006, 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math namespaces sequences strings words assocs
7 TUPLE: effect in out terminated? ;
9 : <effect> ( in out -- effect )
10 dup { "*" } sequence= [ drop { } t ] [ f ] if
11 effect construct-boa ;
13 : effect-height ( effect -- n )
14 dup effect-out length swap effect-in length - ;
16 : effect<= ( eff1 eff2 -- ? )
19 { [ over effect-terminated? ] [ t ] }
20 { [ dup effect-terminated? ] [ f ] }
21 { [ 2dup [ effect-in length ] 2apply > ] [ f ] }
22 { [ 2dup [ effect-height ] 2apply = not ] [ f ] }
26 GENERIC: (stack-picture) ( obj -- str )
27 M: string (stack-picture) ;
28 M: word (stack-picture) word-name ;
29 M: integer (stack-picture) drop "object" ;
31 : stack-picture ( seq -- string )
32 [ [ (stack-picture) % CHAR: \s , ] each ] "" make ;
34 : effect>string ( effect -- string )
37 dup effect-in stack-picture %
39 dup effect-out stack-picture %
40 effect-terminated? [ "* " % ] when
44 : stack-effect ( word -- effect/f )
48 { "declared-effect" "inferred-effect" }
49 swap word-props [ at ] curry map [ ] find nip
53 [ effect-in clone ] keep effect-out clone <effect> ;