@@ -18,14 +18,13 @@ import Data.Array.Unboxed
18import Data.Monoid
18import Data.Monoid
19import Data.Word
19import Data.Word
21+import Foreign.C.Types
21import Foreign.Marshal.Array
22import Foreign.Marshal.Array
22import Foreign.Ptr
23import Foreign.Ptr
24import Text.ParserCombinators.Parsec
25import Text.ParserCombinators.Parsec
26−type BytesLength = Word8
27−type BytesOffset = Word8
28−type CapBytes = ( Ptr Word8, Word )
27+type CapBytes = ( Ptr Word8, CSize )
30data CapExpression = CapExpression
29data CapExpression = CapExpression
31 { cap_ops :: !CapOps
30 { cap_ops :: !CapOps
@@ -43,7 +42,7 @@ type CapParam = Word
44type CapOps = [CapOp]
43type CapOps = [CapOp]
45data CapOp =
44data CapOp =
46− Bytes !BytesOffset !BytesLength
45+ Bytes !Int !CSize !Int
47 | DecOut | CharOut
46 | DecOut | CharOut
48 -- This stores a 0-based index to the parameter. However the operation that implies this op is
47 -- This stores a 0-based index to the parameter. However the operation that implies this op is
49 -- 1-based
48 -- 1-based
@@ -60,7 +59,7 @@ data CapOp =
60 deriving ( Show )
59 deriving ( Show )
62instance NFData CapOp where
61instance NFData CapOp where
63− rnf (Bytes offset c) = rnf offset >| rnf c
62+ rnf ( Bytes offset count next_offset ) = rnf offset
64 rnf (PushParam !_pn) = ()
63 rnf (PushParam !_pn) = ()
65 rnf (PushValue !_v) = ()
64 rnf (PushValue !_v) = ()
66 rnf (Conditional c_expr c_parts) = rnf c_expr >| rnf c_parts
65 rnf (Conditional c_expr c_parts) = rnf c_expr >| rnf c_parts
@@ -116,7 +115,7 @@ literal_percent_parser = do
116 _ <- char '%'
115 _ <- char '%'
117 start_offset <- getState >>= return . next_offset
116 start_offset <- getState >>= return . next_offset
118 inc_offset 1
117 inc_offset 1
119− return $ BuildResults 0 [Bytes start_offset 1] []
118+ return $ BuildResults 0 [Bytes start_offset 1 1] []
121param_op_parser :: CapParser BuildResults
120param_op_parser :: CapParser BuildResults
122param_op_parser
121param_op_parser
@@ -286,11 +285,11 @@ bytes_op_parser :: CapParser BuildResults
286bytes_op_parser = do
285bytes_op_parser = do
287 bytes <- many1 $ satisfy (/= '%')
286 bytes <- many1 $ satisfy (/= '%')
288 start_offset <- getState >>= return . next_offset
287 start_offset <- getState >>= return . next_offset
289− let !c = toEnum $ length bytes
288+ let !c = length bytes
290 !s <- getState
289 !s <- getState
291 let s' = s { next_offset = start_offset + c }
290 let s' = s { next_offset = start_offset + c }
292 setState s'
291 setState s'
293− return $ BuildResults 0 [Bytes start_offset c] []
292+ return $ BuildResults 0 [Bytes start_offset ( toEnum c ) c ] []
295char_const_parser :: CapParser BuildResults
294char_const_parser :: CapParser BuildResults
296char_const_parser = do
295char_const_parser = do
@@ -301,10 +300,10 @@ char_const_parser = do
301 return $ BuildResults 0 [ PushValue char_value ] [ ]
300 return $ BuildResults 0 [ PushValue char_value ] [ ]
303data BuildState = BuildState
302data BuildState = BuildState
304− { next_offset :: Word8
303+ { next_offset :: Int
307−inc_offset :: Word8 -> CapParser ()
306+inc_offset :: Int -> CapParser ()
308inc_offset n = do
307inc_offset n = do
309 s <- getState
308 s <- getState
310 let s' = s { next_offset = next_offset s + n }
309 let s' = s { next_offset = next_offset s + n }