packages feed

ats-storable (empty) → 0.1.0.3

raw patch · 7 files changed

+574/−0 lines, 7 filesdep +ats-storabledep +basedep +composition-preludebuild-type:Customsetup-changed

Dependencies added: ats-storable, base, composition-prelude, hspec

Files

+ LICENSE view
@@ -0,0 +1,11 @@+Copyright Vanessa McHale (c) 2018++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.++3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,5 @@+# ats-generic++## Installation++## Configuration
+ Setup.hs view
@@ -0,0 +1,5 @@+import           Distribution.ATS+import           Distribution.Simple++main = defaultMainWithHooks $ defaultUserHooks+    -- atsUserHooks mempty -- [ atsPrelude [0,3,9] ]
+ ats-storable.cabal view
@@ -0,0 +1,59 @@+name:                ats-storable+version:             0.1.0.3+synopsis:            Marshal ATS types into Haskell+description:         Facilities for sharing types between ATS and Haskell+homepage:            https://github.com//ats-generic#readme+license:             BSD3+license-file:        LICENSE+author:              Vanessa McHale+maintainer:          vamchale@gmail.com+copyright:           Copyright: (c) 2018 Vanessa McHale+category:            ATS, Generics+build-type:          Custom+extra-source-files:  cbits/ats-generic.c+extra-doc-files:     README.md+cabal-version:       >=1.18++Flag development {+  Description: Enable `-Werror`+  manual: True+  default: False+}++custom-setup+  setup-depends:      base >= 4.7 && < 5, +                      -- ats-setup >= 0.1.0.2,+                      Cabal++library+  -- c-sources:           cbits/ats-generic.c+  -- include-dirs:        ats-deps/prelude/ATS2-Postiats-include-0.3.9/ccomp/runtime+  --                    , ats-deps/prelude/ATS2-Postiats-include-0.3.9+  hs-source-dirs:      src+  exposed-modules:     Foreign.Storable.ATS+  build-depends:       base >= 4.7 && < 5+                     , composition-prelude+  default-language:    Haskell2010+  if flag(development)+    ghc-options:       -Werror+  if impl(ghc >= 8.0)+    ghc-options:       -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat +  ghc-options:         -Wall++test-suite ats-generic-test+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             Spec.hs+  build-depends:       base+                     , ats-storable+                     , hspec+  if flag(development)+    ghc-options: -Werror+  if impl(ghc >= 8.0)+    ghc-options:       -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat +  ghc-options:         -threaded -rtsopts -with-rtsopts=-N -Wall+  default-language:    Haskell2010++source-repository head+  type:     darcs+  location: https://hub.darcs.net/vmchale/ats
+ cbits/ats-generic.c view
@@ -0,0 +1,356 @@+/*+**+** The C code is generated by [ATS/Postiats-0-3-9]+** The starting compilation time is: 2018-2-4: 17h:45m+**+*/++/*+** include runtime header files+*/+#ifndef _ATS_CCOMP_HEADER_NONE_+#include "pats_ccomp_config.h"+#include "pats_ccomp_basics.h"+#include "pats_ccomp_typedefs.h"+#include "pats_ccomp_instrset.h"+#include "pats_ccomp_memalloc.h"+#ifndef _ATS_CCOMP_EXCEPTION_NONE_+#include "pats_ccomp_memalloca.h"+#include "pats_ccomp_exception.h"+#endif // end of [_ATS_CCOMP_EXCEPTION_NONE_]+#endif /* _ATS_CCOMP_HEADER_NONE_ */+++/*+** include prelude cats files+*/+#ifndef _ATS_CCOMP_PRELUDE_NONE_+//+#include "prelude/CATS/basics.cats"+#include "prelude/CATS/integer.cats"+#include "prelude/CATS/pointer.cats"+#include "prelude/CATS/integer_long.cats"+#include "prelude/CATS/integer_size.cats"+#include "prelude/CATS/integer_short.cats"+#include "prelude/CATS/bool.cats"+#include "prelude/CATS/char.cats"+#include "prelude/CATS/float.cats"+#include "prelude/CATS/integer_ptr.cats"+#include "prelude/CATS/integer_fixed.cats"+#include "prelude/CATS/memory.cats"+#include "prelude/CATS/string.cats"+#include "prelude/CATS/strptr.cats"+//+#include "prelude/CATS/fprintf.cats"+//+#include "prelude/CATS/filebas.cats"+//+#include "prelude/CATS/list.cats"+#include "prelude/CATS/option.cats"+#include "prelude/CATS/array.cats"+#include "prelude/CATS/arrayptr.cats"+#include "prelude/CATS/arrayref.cats"+#include "prelude/CATS/matrix.cats"+#include "prelude/CATS/matrixptr.cats"+//+#endif /* _ATS_CCOMP_PRELUDE_NONE_ */+/*+** for user-supplied prelude+*/+#ifdef _ATS_CCOMP_PRELUDE_USER_+//+#include _ATS_CCOMP_PRELUDE_USER_+//+#endif /* _ATS_CCOMP_PRELUDE_USER_ */+/*+** for user2-supplied prelude+*/+#ifdef _ATS_CCOMP_PRELUDE_USER2_+//+#include _ATS_CCOMP_PRELUDE_USER2_+//+#endif /* _ATS_CCOMP_PRELUDE_USER2_ */++/*+staload-prologues(beg)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/basics.dats: 1636(line=50, offs=1) -- 1675(line=50, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/integer.dats: 1596(line=49, offs=1) -- 1635(line=49, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/pointer.dats: 1533(line=44, offs=1) -- 1572(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/integer_long.dats: 1602(line=49, offs=1) -- 1641(line=49, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/integer_size.dats: 1597(line=49, offs=1) -- 1636(line=49, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/integer_short.dats: 1603(line=49, offs=1) -- 1642(line=49, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/char.dats: 1610(line=48, offs=1) -- 1649(line=48, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/float.dats: 1636(line=50, offs=1) -- 1675(line=50, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/string.dats: 1631(line=50, offs=1) -- 1670(line=50, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/strptr.dats: 1629(line=50, offs=1) -- 1668(line=50, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/strptr.dats: 1691(line=54, offs=1) -- 1738(line=54, offs=48)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/integer.dats: 1596(line=49, offs=1) -- 1635(line=49, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/integer_ptr.dats: 1601(line=49, offs=1) -- 1640(line=49, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/integer_fixed.dats: 1603(line=49, offs=1) -- 1642(line=49, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/memory.dats: 1410(line=38, offs=1) -- 1449(line=39, offs=32)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/filebas.dats: 1607(line=49, offs=1) -- 1646(line=50, offs=32)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/filebas.dats: 1669(line=54, offs=1) -- 1715(line=55, offs=39)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/integer.dats: 1596(line=49, offs=1) -- 1635(line=49, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/filebas.dats: 1738(line=59, offs=1) -- 1783(line=60, offs=38)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/libats/libc/SATS/stdio.sats: 1390(line=36, offs=1) -- 1437(line=39, offs=3)+*/++#include \+"libats/libc/CATS/stdio.cats"+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/libats/libc/SATS/stdio.sats: 1950(line=69, offs=1) -- 1999(line=71, offs=34)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/libats/libc/SATS/sys/types.sats: 1390(line=36, offs=1) -- 1441(line=39, offs=3)+*/++#include \+"libats/libc/CATS/sys/types.cats"+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/filebas.dats: 1865(line=66, offs=1) -- 1912(line=66, offs=48)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/libats/libc/SATS/sys/stat.sats: 1390(line=36, offs=1) -- 1440(line=39, offs=3)+*/++#include \+"libats/libc/CATS/sys/stat.cats"+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/libats/libc/SATS/sys/stat.sats: 1756(line=58, offs=1) -- 1805(line=60, offs=34)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/libats/libc/SATS/sys/types.sats: 1390(line=36, offs=1) -- 1441(line=39, offs=3)+*/++#include \+"libats/libc/CATS/sys/types.cats"+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/filebas.dats: 15937(line=927, offs=1) -- 15974(line=928, offs=30)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/libats/libc/SATS/stdio.sats: 1390(line=36, offs=1) -- 1437(line=39, offs=3)+*/++#include \+"libats/libc/CATS/stdio.cats"+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/libats/libc/SATS/stdio.sats: 1950(line=69, offs=1) -- 1999(line=71, offs=34)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/libats/libc/SATS/sys/types.sats: 1390(line=36, offs=1) -- 1441(line=39, offs=3)+*/++#include \+"libats/libc/CATS/sys/types.cats"+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/list.dats: 1529(line=44, offs=1) -- 1568(line=45, offs=32)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/list.dats: 1569(line=46, offs=1) -- 1615(line=47, offs=39)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/unsafe.dats: 1532(line=44, offs=1) -- 1566(line=44, offs=35)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/list_vt.dats: 1538(line=44, offs=1) -- 1577(line=45, offs=32)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/list_vt.dats: 1578(line=46, offs=1) -- 1624(line=47, offs=39)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/unsafe.dats: 1532(line=44, offs=1) -- 1566(line=44, offs=35)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/SHARE/list_vt_mergesort.dats: 1546(line=44, offs=1) -- 1585(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/SHARE/list_vt_quicksort.dats: 1546(line=44, offs=1) -- 1585(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/array.dats: 1528(line=44, offs=1) -- 1567(line=45, offs=32)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/SHARE/array_bsearch.dats: 1531(line=44, offs=1) -- 1570(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/SHARE/array_quicksort.dats: 1531(line=44, offs=1) -- 1570(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/arrayptr.dats: 1532(line=44, offs=1) -- 1571(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/arrayref.dats: 1532(line=44, offs=1) -- 1571(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/matrix.dats: 1535(line=44, offs=1) -- 1574(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/matrixptr.dats: 1538(line=44, offs=1) -- 1577(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/matrixref.dats: 1538(line=44, offs=1) -- 1577(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/stream.dats: 1523(line=44, offs=1) -- 1562(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/stream_vt.dats: 1523(line=44, offs=1) -- 1562(line=44, offs=40)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/tostring.dats: 1528(line=44, offs=1) -- 1567(line=45, offs=32)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/unsafe.dats: 1532(line=44, offs=1) -- 1566(line=44, offs=35)+*/+/*+/home/vanessa/.atspkg/0.3.9/lib/ats2-postiats-0.3.9/prelude/DATS/checkast.dats: 1531(line=44, offs=1) -- 1570(line=45, offs=32)+*/+/*+staload-prologues(end)+*/+/*+typedefs-for-tyrecs-and-tysums(beg)+*/+typedef+ATSstruct {+atstkind_t0ype(atstype_int) atslab__first ;+atstkind_t0ype(atstype_int) atslab__second ;+} postiats_tyrec_0 ;+/*+typedefs-for-tyrecs-and-tysums(end)+*/+/*+dynconlst-declaration(beg)+*/+/*+dynconlst-declaration(end)+*/+/*+dyncstlst-declaration(beg)+*/+/*+dyncstlst-declaration(end)+*/+/*+dynvalist-implementation(beg)+*/+ATSdyncst_valimp(pass_boring_type, postiats_tyrec_0) ;+/*+dynvalist-implementation(end)+*/+/*+exnconlst-declaration(beg)+*/+#ifndef _ATS_CCOMP_EXCEPTION_NONE_+ATSextern()+atsvoid_t0ype+the_atsexncon_initize+(+  atstype_exnconptr d2c, atstype_string exnmsg+) ;+#endif // end of [_ATS_CCOMP_EXCEPTION_NONE_]+/*+exnconlst-declaration(end)+*/+/*+extypelst-declaration(beg)+*/+/*+extypelst-declaration(end)+*/+/*+assumelst-declaration(beg)+*/+#ifndef _ATS_CCOMP_ASSUME_CHECK_NONE_+#endif // #ifndef(_ATS_CCOMP_ASSUME_CHECK_NONE_)+/*+assumelst-declaration(end)+*/+ATSstatmpdec(statmp0, postiats_tyrec_0) ;+/*+** for initialization(dynloading)+*/+ATSdynloadflag_minit(_057_home_057_vanessa_057_programming_057_haskell_057_done_057_hs_055_ats_057_ats_055_storable_057_ats_055_src_057_ats_055_generic_056_dats__dynloadflag) ;+ATSextern()+atsvoid_t0ype+_057_home_057_vanessa_057_programming_057_haskell_057_done_057_hs_055_ats_057_ats_055_storable_057_ats_055_src_057_ats_055_generic_056_dats__dynload()+{+ATSfunbody_beg()+ATSdynload(/*void*/)+ATSdynloadflag_sta(+_057_home_057_vanessa_057_programming_057_haskell_057_done_057_hs_055_ats_057_ats_055_storable_057_ats_055_src_057_ats_055_generic_056_dats__dynloadflag+) ;+ATSif(+ATSCKiseqz(+_057_home_057_vanessa_057_programming_057_haskell_057_done_057_hs_055_ats_057_ats_055_storable_057_ats_055_src_057_ats_055_generic_056_dats__dynloadflag+)+) ATSthen() {+ATSdynloadset(_057_home_057_vanessa_057_programming_057_haskell_057_done_057_hs_055_ats_057_ats_055_storable_057_ats_055_src_057_ats_055_generic_056_dats__dynloadflag) ;+/*+dynexnlst-initize(beg)+*/+/*+dynexnlst-initize(end)+*/+/* local */+/* in of [local] */+/*+emit_instr: loc0 = /home/vanessa/programming/haskell/done/hs-ats/ats-storable/ats-src/ats-generic.dats: 200(line=9, offs=39) -- 228(line=9, offs=67)+*/+ATSINSmove_fltrec_beg()+ATSINSstore_fltrec_ofs(statmp0, postiats_tyrec_0, atslab__first, ATSPMVi0nt(12)) ;+ATSINSstore_fltrec_ofs(statmp0, postiats_tyrec_0, atslab__second, ATSPMVi0nt(13)) ;+ATSINSmove_fltrec_end()+/*+emit_instr: loc0 = /home/vanessa/programming/haskell/done/hs-ats/ats-storable/ats-src/ats-generic.dats: 291(line=14, offs=11) -- 330(line=15, offs=21)+*/+ATSINSdyncst_valbind(pass_boring_type, statmp0) ;+/* end of [local] */+} /* ATSendif */+ATSfunbody_end()+ATSreturn_void(tmpret_void) ;+} /* end of [*_dynload] */++/* ****** ****** */++/* end-of-compilation-unit */
+ src/Foreign/Storable/ATS.hs view
@@ -0,0 +1,113 @@+{-# LANGUAGE DefaultSignatures    #-}+{-# LANGUAGE FlexibleContexts     #-}+{-# LANGUAGE FlexibleInstances    #-}+{-# LANGUAGE InstanceSigs         #-}+{-# LANGUAGE ScopedTypeVariables  #-}+{-# LANGUAGE TypeOperators        #-}+{-# LANGUAGE UndecidableInstances #-}++module Foreign.Storable.ATS+    ( ATSStorable (..)+    ) where++import           Control.Composition+import           Data.Word+import           Foreign.Marshal.Alloc+import           Foreign.Ptr+import qualified Foreign.Storable      as C+import           GHC.Generics++class Storable' f where++    sizeOf' :: f a -> Int++    alignment' :: f a -> Int++    peek' :: Ptr (f a) -> IO (f a)++    poke' :: Ptr (f a) -> f a -> IO ()++    pokeByteOff' :: Ptr (f a) -> Int -> f a -> IO ()+    pokeByteOff' = poke' .* plusPtr++    peekByteOff' :: Ptr (f a) -> Int -> IO (f a)+    peekByteOff' = peek' .* plusPtr++instance Storable' V1 where+    peek' = undefined+    poke' = undefined+    alignment' = undefined+    sizeOf' = undefined++-- TODO closed type families?++instance (Storable' a, Storable' b) => Storable' (a :*: b) where+    sizeOf' _ = sizeOf' (undefined :: a x) + sizeOf' (undefined :: b x)+    alignment' _ = gcd (alignment' (undefined :: a x)) (alignment' (undefined :: b x))+    peek' ptr = do+        a <- peek' (castPtr ptr)+        (a :*:) <$> peekByteOff' (castPtr ptr) (sizeOf' a)+    poke' ptr (a :*: b) = mconcat+        [ poke' (castPtr ptr) a+        , pokeByteOff' (castPtr ptr) (sizeOf' a) b ]++instance C.Storable a => ATSStorable a where+    sizeOf :: a -> Int+    sizeOf = C.sizeOf+    alignment :: a -> Int+    alignment = C.alignment+    poke :: Ptr a -> a -> IO ()+    poke = C.poke+    peek :: Ptr a -> IO a+    peek = C.peek++instance (Storable' a, Storable' b) => Storable' (a :+: b) where+    sizeOf' _ = 4 + max (sizeOf' (undefined :: a x)) (sizeOf' (undefined :: b x))+    alignment' _ = gcd 4 $ gcd (alignment' (undefined :: a x)) (alignment' (undefined :: b x))+    peek' ptr = do+        tag <- peek (castPtr ptr)+        if (tag :: Word32) == 0+            then pure L1 <*> peekByteOff' (castPtr ptr) 4+            else pure R1 <*> peekByteOff' (castPtr ptr) 4+    poke' ptr (L1 val) = mconcat+        [ poke (castPtr ptr) (0 :: Word32)+        , pokeByteOff' (castPtr ptr) 4 val ]+    poke' ptr (R1 val) = mconcat+        [ poke (castPtr ptr) (1 :: Word32)+        , pokeByteOff' (castPtr ptr) 4 val ]++instance (ATSStorable a) => Storable' (K1 i a) where+    sizeOf' _ = sizeOf (undefined :: a)+    alignment' _ = alignment (undefined :: a)+    peek' ptr = pure K1 <*> peek (castPtr ptr)+    poke' ptr (K1 val) = poke (castPtr ptr) val++instance (Storable' a) => Storable' (M1 i c a) where+    sizeOf' _ = sizeOf' (undefined :: a x)+    alignment' _ = alignment' (undefined :: a x)+    peek' ptr = pure M1 <*> peek' (castPtr ptr)+    poke' ptr (M1 val) = poke' (castPtr ptr) val++class ATSStorable a where++    sizeOf :: a -> Int+    default sizeOf :: (Generic a, Storable' (Rep a)) => a -> Int+    sizeOf _ = (sizeOf' . from) (undefined :: a)++    alignment :: a -> Int+    default alignment :: (Generic a, Storable' (Rep a)) => a -> Int+    alignment _ = (alignment' . from) (undefined :: a)++    poke :: Ptr a -> a -> IO ()+    default poke :: (Generic a, Storable' (Rep a)) => Ptr a -> a -> IO ()+    poke ptr x = poke' (castPtr ptr) (from x)++    peek :: Ptr a -> IO a+    default peek :: (Generic a, Storable' (Rep a)) => Ptr a -> IO a+    peek = fmap to . peek' . castPtr++    writePtr :: a -> IO (Ptr a)+    writePtr val = do+        ptr <- mallocBytes (sizeOf val)+        poke ptr val+        pure ptr
+ test/Spec.hs view
@@ -0,0 +1,25 @@+{-# LANGUAGE DeriveAnyClass           #-}+{-# LANGUAGE DeriveGeneric            #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE IncoherentInstances      #-}++import           Foreign.C.Types+import           Foreign.Ptr+import           Foreign.Storable.ATS+import           GHC.Generics+import           Test.Hspec++data BoringType = BoringType CInt CInt+    deriving (Show, Eq, Generic, ATSStorable)++foreign import ccall unsafe pass_boring_type :: Ptr BoringType++-- are pointers functorial?? a monad??+passBoringType :: IO BoringType+passBoringType = peek pass_boring_type++main :: IO ()+main = hspec $+    parallel $ describe "passBoringType" $+        it "should so the right thing" $+            passBoringType >>= (`shouldBe` (BoringType 12 13))