Просмотр исходного кода

ivory backend: fix size calculation to use packRep

also suppress unused imports warnings

thanks jamey
Pat Hickey 10 лет назад
Родитель
Сommit
29998768fb
1 измененных файлов с 6 добавлено и 5 удалено
  1. 6 5
      src/Gidl/Backend/Ivory/Interface.hs

+ 6 - 5
src/Gidl/Backend/Ivory/Interface.hs

@@ -22,6 +22,7 @@ interfaceModule modulepath ir =
     [ text "{-# LANGUAGE DataKinds #-}"
     , text "{-# LANGUAGE RankNTypes #-}"
     , text "{-# LANGUAGE ScopedTypeVariables #-}"
+    , text "{-# OPTIONS_GHC -fno-warn-unused-imports #-}"
     , empty
     , text "module"
       <+> im (ifModuleName ir)
@@ -124,8 +125,8 @@ schemaDoc interfaceName (Schema schemaName schema) = stack
         [ case t of
             PrimType VoidType -> text (senderName n) <+> equals <+> text "do" </> indent 4
                   (stack [ text "o <- deref offs"
-                         , text "let required_size = sizeOf (Proxy :: Proxy (Stored Uint32))"
-                         , text "    sufficient_space = (o + required_size) <? sizeOf (Proxy :: Proxy (Array n (Stored Uint8)))"
+                         , text "let required_size = fromInteger (packSize (packRep :: PackRep (Stored Uint32)))"
+                         , text "    sufficient_space = (o + required_size) <? arrayLen arr"
                          , text "when sufficient_space $ do"
                          , indent 2 $ stack
                              [ text "ident <- local (ival (" <+> ppr h <+> text ":: Uint32))"
@@ -137,10 +138,10 @@ schemaDoc interfaceName (Schema schemaName schema) = stack
 
             _ -> text (senderName n) <+> equals <+> text "\\m -> do" </> indent 4
                   (stack [ text "o <- deref offs"
-                         , text "let required_size = sizeOf (Proxy :: Proxy"
+                         , text "let required_size = fromInteger (packSize (packRep :: PackRep"
                              <+> parens (text (typeIvoryType t)) <+> text ")"
-                             <+> text "+ sizeOf (Proxy :: Proxy (Stored Uint32))"
-                         , text "    sufficient_space = (o + required_size) <? sizeOf (Proxy :: Proxy (Array n (Stored Uint8)))"
+                             <+> text "+ packSize (packRep :: PackRep (Stored Uint32)))"
+                         , text "    sufficient_space = (o + required_size) <? arrayLen arr"
                          , text "when sufficient_space $ do"
                          , indent 2 $ stack
                              [ text "ident <- local (ival (" <+> ppr h <+> text ":: Uint32))"