]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/tree/comparisons/comparisons.factor
Fixing failing unit tests in compiler.tree.propagation due to constraints
[factor.git] / basis / compiler / tree / comparisons / comparisons.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: math math.order math.intervals assocs combinators ;
4 IN: compiler.tree.comparisons
5
6 ! Some utilities for working with comparison operations.
7
8 CONSTANT: comparison-ops { < > <= >= }
9
10 CONSTANT: generic-comparison-ops { before? after? before=? after=? }
11
12 : assumption ( i1 i2 op -- i3 )
13     {
14         { \ <  [ assume< ] }
15         { \ >  [ assume> ] }
16         { \ <= [ assume<= ] }
17         { \ >= [ assume>= ] }
18     } case ;
19
20 : interval-comparison ( i1 i2 op -- result )
21     {
22         { \ <  [ interval< ] }
23         { \ >  [ interval> ] }
24         { \ <= [ interval<= ] }
25         { \ >= [ interval>= ] }
26     } case ;
27
28 : swap-comparison ( op -- op' )
29     {
30         { < > }
31         { > < }
32         { <= >= }
33         { >= <= }
34     } at ;
35
36 : negate-comparison ( op -- op' )
37     {
38         { < >= }
39         { > <= }
40         { <= > }
41         { >= < }
42     } at ;
43
44 : specific-comparison ( op -- op' )
45     {
46         { before? < }
47         { after? > }
48         { before=? <= }
49         { after=? >= }
50     } at ;