1
1
-- $Id: GenericTemplate.hs,v 1.26 2005/01/14 14:47:22 simonmar Exp $
4
#undef __GLASGOW_HASKELL__
5
#define HAPPY_IF_GHC_GT_500 #if __GLASGOW_HASKELL__ > 500
6
#define HAPPY_IF_GHC_GE_503 #if __GLASGOW_HASKELL__ >= 503
7
#define HAPPY_ELIF_GHC_500 #elif __GLASGOW_HASKELL__ == 500
8
#define HAPPY_IF_GHC_GT_706 #if __GLASGOW_HASKELL__ > 706
9
#define HAPPY_ELSE #else
10
#define HAPPY_ENDIF #endif
11
#define HAPPY_DEFINE #define
5
#define FAST_INT_BINDING(n) (n)
6
16
#define IBOX(n) (Happy_GHC_Exts.I# (n))
7
17
#define FAST_INT Happy_GHC_Exts.Int#
8
#define LT(n,m) (n Happy_GHC_Exts.<# m)
9
#define GTE(n,m) (n Happy_GHC_Exts.>=# m)
10
#define EQ(n,m) (n Happy_GHC_Exts.==# m)
19
HAPPY_DEFINE LT(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.<# m)) :: Bool)
20
HAPPY_DEFINE GTE(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.>=# m)) :: Bool)
21
HAPPY_DEFINE EQ(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.==# m)) :: Bool)
23
HAPPY_DEFINE LT(n,m) (n Happy_GHC_Exts.<# m)
24
HAPPY_DEFINE GTE(n,m) (n Happy_GHC_Exts.>=# m)
25
HAPPY_DEFINE EQ(n,m) (n Happy_GHC_Exts.==# m)
11
27
#define PLUS(n,m) (n Happy_GHC_Exts.+# m)
12
28
#define MINUS(n,m) (n Happy_GHC_Exts.-# m)
13
29
#define TIMES(n,m) (n Happy_GHC_Exts.*# m)
109
124
++ show IBOX(new_state)
111
126
happyShift new_state i tk st
112
where FAST_INT_BINDING(new_state) = MINUS(n,(ILIT(1) :: FAST_INT))
113
where FAST_INT_BINDING(off) = indexShortOffAddr happyActOffsets st
114
FAST_INT_BINDING(off_i) = PLUS(off,i)
127
where new_state = MINUS(n,(ILIT(1) :: FAST_INT))
128
where off = indexShortOffAddr happyActOffsets st
115
130
check = if GTE(off_i,(ILIT(0) :: FAST_INT))
116
then EQ(indexShortOffAddr happyCheck off_i, i)
118
FAST_INT_BINDING(action)
131
then EQ(indexShortOffAddr happyCheck off_i, i)
119
134
| check = indexShortOffAddr happyTable off_i
120
135
| otherwise = indexShortOffAddr happyDefActions st
123
#undef __GLASGOW_HASKELL__
124
#define HAPPY_IF_GHC_GT_500 #if __GLASGOW_HASKELL__ > 500
125
#define HAPPY_IF_GHC_GE_503 #if __GLASGOW_HASKELL__ >= 503
126
#define HAPPY_ELIF_GHC_500 #elif __GLASGOW_HASKELL__ == 500
127
#define HAPPY_ELSE #else
128
#define HAPPY_ENDIF #endif
132
138
indexShortOffAddr (HappyA# arr) off =
133
139
Happy_GHC_Exts.narrow16Int# i
165
171
-- Shifting a token
167
173
happyShift new_state ERROR_TOK tk st sts stk@(x `HappyStk` _) =
168
let FAST_INT_BINDING(i) = GET_ERROR_TOKEN(x) in
174
let i = GET_ERROR_TOKEN(x) in
169
175
-- trace "shifting the error token" $
170
176
DO_ACTION(new_state,i,tk,CONS(st,sts),stk)
208
214
happyMonadReduce k nt fn ERROR_TOK tk st sts stk
209
215
= happyFail ERROR_TOK tk st sts stk
210
216
happyMonadReduce k nt fn j tk st sts stk =
211
happyThen1 (fn stk tk) (\r -> GOTO(action) nt j tk st1 sts1 (r `HappyStk` drop_stk))
212
where FAST_INT_BINDING(sts1@(CONS(st1@HAPPYSTATE(action),_))) = happyDrop k CONS(st,sts)
213
drop_stk = happyDropStk k stk
217
case happyDrop k CONS(st,sts) of
218
sts1@(CONS(st1@HAPPYSTATE(action),_)) ->
219
let drop_stk = happyDropStk k stk in
220
happyThen1 (fn stk tk) (\r -> GOTO(action) nt j tk st1 sts1 (r `HappyStk` drop_stk))
215
222
happyMonad2Reduce k nt fn ERROR_TOK tk st sts stk
216
223
= happyFail ERROR_TOK tk st sts stk
217
224
happyMonad2Reduce k nt fn j tk st sts stk =
218
happyThen1 (fn stk tk) (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk))
219
where FAST_INT_BINDING(sts1@(CONS(st1@HAPPYSTATE(action),_))) = happyDrop k CONS(st,sts)
220
drop_stk = happyDropStk k stk
225
case happyDrop k CONS(st,sts) of
226
sts1@(CONS(st1@HAPPYSTATE(action),_)) ->
227
let drop_stk = happyDropStk k stk
221
228
#if defined(HAPPY_ARRAY)
222
FAST_INT_BINDING(off) = indexShortOffAddr happyGotoOffsets st1
223
FAST_INT_BINDING(off_i) = PLUS(off,nt)
224
FAST_INT_BINDING(new_state) = indexShortOffAddr happyTable off_i
229
off = indexShortOffAddr happyGotoOffsets st1
231
new_state = indexShortOffAddr happyTable off_i
226
233
new_state = action
236
happyThen1 (fn stk tk) (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk))
229
238
happyDrop ILIT(0) l = l
230
239
happyDrop n CONS(_,t) = happyDrop MINUS(n,(ILIT(1) :: FAST_INT)) t
239
248
happyGoto nt j tk st =
240
249
DEBUG_TRACE(", goto state " ++ show IBOX(new_state) ++ "\n")
241
250
happyDoAction j tk new_state
242
where FAST_INT_BINDING(off) = indexShortOffAddr happyGotoOffsets st
243
FAST_INT_BINDING(off_i) = PLUS(off,nt)
244
FAST_INT_BINDING(new_state) = indexShortOffAddr happyTable off_i
251
where off = indexShortOffAddr happyGotoOffsets st
253
new_state = indexShortOffAddr happyTable off_i
246
255
happyGoto action j tk st = action j j tk (HappyState action)