Reorganisation of the source tree
[ghc-hetmet.git] / compiler / ilxGen / tests / test18.hs
1 {-# OPTIONS -fno-implicit-prelude #-}
2
3 module Test18 where
4
5 import PrelGHC
6 import PrelBase
7
8 eftCharFB c n x y = go x
9                  where
10                     go x | x ># y    = n
11                          | otherwise = C# (chr# x) `c` go (x +# 1#)
12
13
14 eftIntFB c n x y | x ># y    = n        
15                  | otherwise = go x
16                  where
17                    go x = I# x `c` if x ==# y then n else go (x +# 1#)
18
19 eftIntList x y | x ># y    = []
20                | otherwise = go x
21                where
22                  go x = I# x : if x ==# y then [] else go (x +# 1#)
23
24
25 efdCharFB c n x1 x2
26   | delta >=# 0# = go_up_char_fb c n x1 delta 255#
27   | otherwise    = go_dn_char_fb c n x1 delta 0#
28   where
29     delta = x2 -# x1
30
31 efdCharList x1 x2
32   | delta >=# 0# = go_up_char_list x1 delta 255#
33   | otherwise    = go_dn_char_list x1 delta 0#
34   where
35     delta = x2 -# x1
36
37 efdtCharFB c n x1 x2 lim
38   | delta >=# 0# = go_up_char_fb c n x1 delta lim
39   | otherwise    = go_dn_char_fb c n x1 delta lim
40   where
41     delta = x2 -# x1
42
43 efdtCharList x1 x2 lim
44   | delta >=# 0# = go_up_char_list x1 delta lim
45   | otherwise    = go_dn_char_list x1 delta lim
46   where
47     delta = x2 -# x1
48
49 go_up_char_fb c n x delta lim
50   = go_up x
51   where
52     go_up x | x ># lim  = n
53             | otherwise = C# (chr# x) `c` go_up (x +# delta)
54
55 go_dn_char_fb c n x delta lim
56   = go_dn x
57   where
58     go_dn x | x <# lim  = n
59             | otherwise = C# (chr# x) `c` go_dn (x +# delta)
60
61 go_up_char_list x delta lim
62   = go_up x
63   where
64     go_up x | x ># lim  = []
65             | otherwise = C# (chr# x) : go_up (x +# delta)
66
67
68 go_dn_char_list x delta lim
69   = go_dn x
70   where
71     go_dn x | x <# lim  = []
72             | otherwise = C# (chr# x) : go_dn (x +# delta)
73
74 efdtIntFB c n x1 x2 y
75   | delta >=# 0# = if x1 ># y then n else go_up_int_fb c n x1 delta lim
76   | otherwise    = if x1 <# y then n else go_dn_int_fb c n x1 delta lim 
77   where
78     delta = x2 -# x1
79     lim   = y -# delta
80
81 efdtIntList x1 x2 y
82   | delta >=# 0# = if x1 ># y then [] else go_up_int_list x1 delta lim
83   | otherwise    = if x1 <# y then [] else go_dn_int_list x1 delta lim
84   where
85     delta = x2 -# x1
86     lim   = y -# delta
87
88 efdIntFB c n x1 x2
89   | delta >=# 0# = go_up_int_fb c n x1 delta (  2147483647#  -# delta)
90   | otherwise    = go_dn_int_fb c n x1 delta ((-2147483648#) -# delta)
91   where
92     delta = x2 -# x1
93
94 efdIntList x1 x2
95   | delta >=# 0# = go_up_int_list x1 delta (  2147483647#  -# delta)
96   | otherwise    = go_dn_int_list x1 delta ((-2147483648#) -# delta)
97   where
98     delta = x2 -# x1
99
100 -- In all of these, the (x +# delta) is guaranteed not to overflow
101
102 go_up_int_fb c n x delta lim
103   = go_up x
104   where
105     go_up x | x ># lim  = I# x `c` n
106             | otherwise = I# x `c` go_up (x +# delta)
107
108 go_dn_int_fb c n x delta lim 
109   = go_dn x
110   where
111     go_dn x | x <# lim  = I# x `c` n
112             | otherwise = I# x `c` go_dn (x +# delta)
113
114 go_up_int_list x delta lim
115   = go_up x
116   where
117     go_up x | x ># lim  = [I# x]
118             | otherwise = I# x : go_up (x +# delta)
119
120 go_dn_int_list x delta lim 
121   = go_dn x
122   where
123     go_dn x | x <# lim  = [I# x]
124             | otherwise = I# x : go_dn (x +# delta)
125 eftInt  = eftIntList
126 efdInt  = efdIntList
127 efdtInt = efdtIntList
128
129