1 ! Copyright (C) 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel sequences namespaces generic
4 combinators classes classes.algebra
5 inference inference.dataflow ;
6 IN: optimizer.pattern-match
8 ! Funny pattern matching
11 : match-@ ( value -- ? )
13 @ get [ eq? ] [ @ set t ] if* ;
15 : match-class ( value spec -- ? )
16 >r node get swap node-class r> class<= ;
18 : value-match? ( value spec -- ? )
20 { [ dup @ eq? ] [ drop match-@ ] }
21 { [ dup class? ] [ match-class ] }
22 { [ over value? not ] [ 2drop f ] }
23 [ swap value-literal = ]
26 : node-match? ( node values pattern -- ? )
29 [ value-match? ] 2all?
32 : in-d-match? ( node pattern -- ? )
33 >r dup node-in-d r> node-match? ;