~ubuntu-branches/ubuntu/trusty/happy/trusty-proposed

« back to all changes in this revision

Viewing changes to templates/GenericTemplate.hs

  • Committer: Package Import Robot
  • Author(s): Joachim Breitner
  • Date: 2013-09-18 19:11:12 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20130918191112-h5he0u2g5tqnh90m
Tags: 1.19.0-1
* Fix Vcs-Darcs url: http://darcs.debian.org/ instead of
  http://darcs.debian.org/darcs/
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
-- $Id: GenericTemplate.hs,v 1.26 2005/01/14 14:47:22 simonmar Exp $
2
2
 
3
3
#ifdef HAPPY_GHC
 
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
 
12
#endif
 
13
 
 
14
#ifdef HAPPY_GHC
4
15
#define ILIT(n) n#
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)
 
18
HAPPY_IF_GHC_GT_706
 
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)
 
22
HAPPY_ELSE
 
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)
 
26
HAPPY_ENDIF
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)
15
31
#define IF_GHC(x) (x)
16
32
#else
17
33
#define ILIT(n) (n)
18
 
#define FAST_INT_BINDING(n) (n)
19
34
#define IBOX(n) (n)
20
35
#define FAST_INT Int
21
36
#define LT(n,m) (n < m)
109
124
                                                 ++ show IBOX(new_state)
110
125
                                                 ++ "\n")
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
 
129
         off_i  = PLUS(off,i)
115
130
         check  = if GTE(off_i,(ILIT(0) :: FAST_INT))
116
 
                        then EQ(indexShortOffAddr happyCheck off_i, i)
117
 
                        else False
118
 
         FAST_INT_BINDING(action)
 
131
                  then EQ(indexShortOffAddr happyCheck off_i, i)
 
132
                  else False
 
133
         action
119
134
          | check     = indexShortOffAddr happyTable off_i
120
135
          | otherwise = indexShortOffAddr happyDefActions st
121
136
 
122
137
#ifdef HAPPY_GHC
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
129
 
#endif
130
 
 
131
 
#ifdef HAPPY_GHC
132
138
indexShortOffAddr (HappyA# arr) off =
133
139
        Happy_GHC_Exts.narrow16Int# i
134
140
  where
165
171
-- Shifting a token
166
172
 
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)
171
177
 
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))
214
221
 
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
 
230
             off_i = PLUS(off,nt)
 
231
             new_state = indexShortOffAddr happyTable off_i
225
232
#else
226
233
             new_state = action
227
234
#endif
 
235
          in
 
236
          happyThen1 (fn stk tk) (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk))
228
237
 
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
 
252
         off_i = PLUS(off,nt)
 
253
         new_state = indexShortOffAddr happyTable off_i
245
254
#else
246
255
happyGoto action j tk st = action j j tk (HappyState action)
247
256
#endif
251
260
 
252
261
-- parse error if we are in recovery and we fail again
253
262
happyFail ERROR_TOK tk old_st _ stk@(x `HappyStk` _) =
254
 
     let FAST_INT_BINDING(i) = GET_ERROR_TOKEN(x) in
 
263
     let i = GET_ERROR_TOKEN(x) in
255
264
--      trace "failing" $ 
256
265
        happyError_ i tk
257
266