Mon Mar 12 17:56:07 PDT 2012 John Meacham <[email protected]> * update manual entry for CTYPE
Tue Mar 13 13:25:21 PDT 2012 John Meacham <[email protected]> * add jhc/Jhc/ForeignPtr.hs
New patches: [update manual entry for CTYPE John Meacham <[email protected]>**20120313005607 Ignore-this: 8a1c03f1f92e00c503edf78f675bc434 ] hunk ./docs/pragmas.mkd 40 Pragma ------ --------------------------------------------------- -_EXTTYPE_ Specify the external type that a data or newtype should use for foreign function interfaces. +_CTYPE_ Specify the external type that a data or newtype should use for foreign function interfaces. The type must be a newtype or unary data constructor of a type that is already foreignable. hunk ./docs/pragmas.mkd 42 - This pragma must appear in the same file as the type declaration. - Example {-# EXTTYPE CUShort "unsigned short" #-} + Example + ~~~ + data {-# CTYPE "unsigned short" #-} CUShort = CUShort Word16 + ~~~ # Header Pragmas hunk ./docs/pragmas.mkd 60 LANGUAGE : Specify various language options - - [add jhc/Jhc/ForeignPtr.hs John Meacham <[email protected]>**20120313202521 Ignore-this: 46f936c65c0e521e47da1e2baf2b2de0 ] addfile ./lib/jhc/Jhc/ForeignPtr.hs hunk ./lib/jhc/Jhc/ForeignPtr.hs 1 +module Jhc.ForeignPtr( + ForeignPtr(), + newPlainForeignPtr_, + newForeignPtr_, + mallocPlainForeignPtrAlignBytes, + mallocForeignPtrAlignBytes, + unsafeForeignPtrToPtr, + castForeignPtr, + touchForeignPtr + ) where + +import Jhc.Addr +import Jhc.IO +import Jhc.Prim.Prim +import Jhc.Prim.Rts +import Jhc.Type.Basic +import Jhc.Basics + +type FinalizerPtr a = FunPtr (Ptr a -> IO ()) + +-- not Addr_ because we need to make sure it is allocated in a real heap +-- location. The actual ForeignPtr heap location may contain more than the +-- single BitsPtr_ argument. +data ForeignPtr a = FP BitsPtr_ + +-- | This function creates a plain ForeignPtr from a Ptr, a plain foreignptr +-- may not have finalizers associated with it, hence this function may be pure. +newPlainForeignPtr_ :: Ptr a -> ForeignPtr a +newPlainForeignPtr_ (Ptr (Addr_ addr)) = FP addr + +newForeignPtr_ :: Ptr a -> IO (ForeignPtr a) +newForeignPtr_ ptr = fromUIO $ \w -> + case gc_new_foreignptr ptr w of + (# w', bp #) -> (# w', fromBang_ bp #) + +-- | This function is similar to 'mallocForeignPtrAlignBytes', except that the +-- internally an optimised ForeignPtr representation with no finalizer is used. +-- Attempts to add a finalizer will cause the program to abort. +mallocPlainForeignPtrAlignBytes + :: Int -- ^ alignment in bytes, must be power of 2. May be zero. + -> Int -- ^ size to allocate in bytes. + -> IO (ForeignPtr a) +mallocPlainForeignPtrAlignBytes align size = fromUIO $ \w -> + case gc_malloc_foreignptr (int2word align) (int2word size) False w of + (# w', bp #) -> (# w', fromBang_ bp #) + +-- | Allocate memory of the given size and alignment that will automatically be +-- reclaimed. Any Finalizers that are attached to this will run before the +-- memory is freed. +mallocForeignPtrAlignBytes + :: Int -- ^ alignment in bytes, must be power of 2. May be zero. + -> Int -- ^ size to allocate in bytes. + -> IO (ForeignPtr a) +mallocForeignPtrAlignBytes align size = fromUIO $ \w -> + case gc_malloc_foreignptr (int2word align) (int2word size) True w of + (# w', bp #) -> (# w', fromBang_ bp #) + +foreign import safe ccall gc_malloc_foreignptr + :: Word -- alignment in words + -> Word -- size in words + -> Bool -- false for plain foreignptrs, true for ones with finalizers. + -> UIO (Bang_ (ForeignPtr a)) + +foreign import safe ccall gc_new_foreignptr :: + Ptr a -> UIO (Bang_ (ForeignPtr a)) + +foreign import unsafe ccall gc_add_foreignptr_finalizer + :: Bang_ (ForeignPtr a) + -> FinalizerPtr a + -> IO () + +unsafeForeignPtrToPtr :: ForeignPtr a -> Ptr a +unsafeForeignPtrToPtr (FP x) = Ptr (Addr_ x) + +touchForeignPtr :: ForeignPtr a -> IO () +touchForeignPtr x = fromUIO_ (touch_ x) + +castForeignPtr :: ForeignPtr a -> ForeignPtr b +castForeignPtr x = unsafeCoerce x + +foreign import primitive touch_ :: ForeignPtr a -> UIO_ +foreign import primitive "B2B" int2word :: Int -> Word +foreign import primitive unsafeCoerce :: a -> b Context: [utilize the CTYPE pragma for most built in types, clean up src/data/names.txt John Meacham <[email protected]>**20120311055029 Ignore-this: 3965b08298708f2a1bf42ae09df3b321 ] [add support for CTYPE pragma John Meacham <[email protected]>**20120311040440 Ignore-this: 3df9d37a3d057f01809bd2aa50baad42 ] [remove HsNewTypeDecl in favor of re-using existing HsDataDecl, clean up code as a result. John Meacham <[email protected]>**20120311030703 Ignore-this: 2b50fff95eeca8295050be2eff84b82 ] [update library dependencies John Meacham <[email protected]>**20120307100809 Ignore-this: 8a7d092c6112d7a5590d2adaec9c271a ] [clean up configure.ac a little John Meacham <[email protected]>**20120307085227 Ignore-this: 255bde23aa451530727987934e68787 ] [mv base to haskell-extras John Meacham <[email protected]>**20120307061504 Ignore-this: acc62fbf85b246155f10055cf7228cd7 ] [add auto-generated make rules for all libraries. John Meacham <[email protected]>**20120307055016 Ignore-this: a6febbaf42d19ca29b0541809182b93c ] [begin adding haskell2010 package John Meacham <[email protected]>**20120307035605 Ignore-this: eaae9201d70dece4f2e7bb115d295e07 ] [start using Jhc.ForeignPtr John Meacham <[email protected]>**20120307035523 Ignore-this: 4947965ba3de583014a924e498ba5367 ] [remove some files from drift_processed that no longer have DrIFT annotations John Meacham <[email protected]>**20120307020552 Ignore-this: 12c00145035104fbbf869072f3be3569 ] [make Info type ids not depend on the exact format of TypeRep, reduce size of type ids from 32 to 8 bits. John Meacham <[email protected]>**20120307014613 Ignore-this: c2243c0c28122f03a4b869c28a449d8d ] [build_extlibs.prl: correctly check the return status of getstore Roman Cheplyaka <[email protected]>**20120218071732 Ignore-this: 20165069fc8aaa1528969216f7c51435 ] [ghc 7.4 compatibility changes John Meacham <[email protected]>**20120306035643 Ignore-this: c15e182e5a05efb7a623f6386fbb9884 ] [implement finalizers in the RTS, add foreignptr rts routines, properly set saved_gc on safe ffi calls John Meacham <[email protected]>**20120221132313 Ignore-this: 1a27919674abc4a6955c245eec88aaf9 ] [add support for monolithic blocks that are plain malloced memory and can be big. John Meacham <[email protected]>**20120221032043 Ignore-this: 201ba4e67027f3336cfa5e984aefa89 ] [introduce dedicated array allocation routine. clean up jgc garbage collector John Meacham <[email protected]>**20120221011655 Ignore-this: b8e153205aeaf94af76a97b0ee9aa895 ] [make 'div' and 'mod' round to -Infinity properly John Meacham <[email protected]>**20120220094634 Ignore-this: c46b383b9a2a6a63ff44e30a8a63f376 ] [add prototype for gc_alloc John Meacham <[email protected]>**20120220050616 Ignore-this: 444b34148332459dc0e3d32b7c55d3e0 ] [fix deriving rules for read/show when it comes to labels John Meacham <[email protected]>**20120220044322 Ignore-this: 20c9c89ae066716fe3ec8eb4d37c6034 ] [disabled buggy unused transformation in type analysis pass John Meacham <[email protected]>**20120220031442 Ignore-this: 8ad84739daff7f4faff0ba251898ea1a ] [move debugging routines to rts/profile.c John Meacham <[email protected]>**20120217052015 Ignore-this: d2e087faf6e3408dc135fd905d85244b ] [fix rts unit tests John Meacham <[email protected]>**20120217035045 Ignore-this: 460d7eadde056908b668ea27d5a69aa5 ] [export gc_alloc John Meacham <[email protected]>**20120217002235 Ignore-this: dcb70b3ad303f0343147b4e1d6d413b9 ] [Makes the class deriving mechanism more robust: [email protected]**20120216214017 Ignore-this: 6d93691849d255c310b2af7098572ea8 - the names of the classes to be derived may be given qualified. - the functions from the Prelude internally used need not be in scope and won't clash with other bindings. ] [Moved Jhc.List.drop to module Jhc.Basics (since it is used in instance deriving) [email protected]**20120214222939 Ignore-this: f95d4818bad6d79d8fc7566ee0912714 ] [The typechecker now verifies that the main function has a type that can be unified with IO a. This is required by the Haskell 98 Report. [email protected]**20120211050446 Ignore-this: 8a1d8ca36929c0de0fb4357538ea6c5b Failing to do so allows both to accept invalid programs like: > main :: [()] > main = return () and to reject valid programs like: > main = return () ] [Improves the error message shown when a monomorphic pattern has a polymorphic type that cannot be defaulted. [email protected]**20120211045931 Ignore-this: efd70b7535eb0444148aabdbe96ed0b9 The previous error message seemed more like an internal error ("withDefaults.ambiguity: ...") ] [fix for building rts in different modes, profile,debug,windows John Meacham <[email protected]>**20120216201402 Ignore-this: 39b08c82b7239beaeaa6e77a3b986cd4 ] [move rest of rts into seperate c files rather than including it directly. John Meacham <[email protected]>**20120216090215 Ignore-this: d0bf719a38e306f78e182a5c0107573d ] [add pragmaExp to the lexer/parser John Meacham <[email protected]>**20120216044837 Ignore-this: 77393cb5bdd28fba526d57d26ac099b8 ] [update documentation with new extensions John Meacham <[email protected]>**20120214172359 Ignore-this: 2f412f29f20127ce3f97f200674ed8b6 ] [fixes for android John Meacham <[email protected]>**20120213150333 Ignore-this: cf6df59b212e3402ec21507410485270 ] [make += work with '-m' command line options John Meacham <[email protected]>**20120213102300 Ignore-this: 36cb4039cd34ba73d2cc973b7c00798b ] [move jhc_rts_alloc to gc_none John Meacham <[email protected]>**20120213100906 Ignore-this: 1c2e9028d72127acd5a448971266f627 ] [added rts/rts_support, cleaned up rts code. John Meacham <[email protected]>**20120213070644 Ignore-this: 79533860331fbd02057748e3d1b81666 ] [make 'Requires' a simple set, include the calling convention with the requirements. John Meacham <[email protected]>**20120212053838 Ignore-this: b7fa6f8ece79c96073d8638a876456de ] [move slub.c and jhc_jgc.* to rts directory John Meacham <[email protected]>**20120212040246 Ignore-this: a40354544b8908732c733bf8a38e7e68 ] [add unit tests for stableptr John Meacham <[email protected]>**20120212031148 Ignore-this: 17b41baeec806fb53ca2c10c6489097 ] [reorganize rts/ directory, add README for it John Meacham <[email protected]>**20120212022718 Ignore-this: c8a9f067696233958757830b62a7264b ] [add rts/test directory John Meacham <[email protected]>**20120212004706 Ignore-this: 1e6d0cb4ba809a1d6089d04704d5a60f ] [allow being explicit in export/import lists by specifying 'kind', 'class', 'type', or 'data'. add PTS rule to allow proper typing of Complex_ John Meacham <[email protected]>**20120211052157 Ignore-this: 12155286186022f896d3474a2bb5d23a ] [fix Options.hs makefile dependency John Meacham <[email protected]>**20120211024909 Ignore-this: a0742d7ce4eba41314741b6ca2d6498d ] [added user defined kind extension John Meacham <[email protected]>**20120211042248 Ignore-this: ded329985c5c81aa8c4612f7aa19559b ] [Add missing src/Options.hs to jhc tarball Sergei Trofimovich <[email protected]>**20120209065334 Ignore-this: dfc50115ee26986ab2d303a462cd29b9 ] [added mingw32-gcc to MINGW search Sergei Trofimovich <[email protected]>**20110414073938 Ignore-this: 87fa46f0e4532663a9d92930c9c38152 ] [add c-- types for complex and vector values John Meacham <[email protected]>**20120210051026 Ignore-this: 4a1e4c8cec01f73b75913622c22fa55 ] [add documentation for the multi-return ccall extension, clean up code. John Meacham <[email protected]>**20120209201351 Ignore-this: 47504b653ee9f71bde40e91959238292 ] [add extension to allow multiple return values from c functions John Meacham <[email protected]>**20120209142228 Ignore-this: 51e4a3f9ca80ff2eae7f21376f0a0992 ] [fix obscure error message for invalid instance reported by roman John Meacham <[email protected]>**20120209114221 Ignore-this: 98d60e20cb63caaebbe1269887160b9f ] [remove APrim type, use Prim directly, clean up corresponding cruft. John Meacham <[email protected]>**20120209104920 Ignore-this: 8a3fbeea72e7f52809a3468df2b8b228 ] [turn ExtType into a real abstract type John Meacham <[email protected]>**20120209100704 Ignore-this: c802a07fee0f2461cca19aa28f99ff61 ] [add 'capi' foreign function call type, simplify type of E.FromHs monad, check for more FFI related errors John Meacham <[email protected]>**20120209091611 Ignore-this: 1945b5336e6001d6da6cd63a77bd1efd ] [add md5lazyIO, check for bad paths in createTempFile John Meacham <[email protected]>**20120209091527 Ignore-this: f9e5f0dafc9615d5c5c50cb49829c5a5 ] [add foreign types, interpret Ptr when creating external C types John Meacham <[email protected]>**20120209090647 Ignore-this: c49bea3938e2edabda9d7528cfb1121a ] [Add some more exotic primitive ops, ffs,clz,ctz,byteswap,popcount,parity. John Meacham <[email protected]>**20120209070848 Ignore-this: b61b1c08db35ccad33f24536b99913df ] [jhc.spec fixes John Meacham <[email protected]>**20120209015329 Ignore-this: 64488edc34893a734f81b1c01c0b1ff4 ] [TAG 0.8.0 John Meacham <[email protected]>**20120208020026 Ignore-this: 2d0d963331a43650879ae72d81ff62e8 ] Patch bundle hash: 5f2e33e1a60e4ce8191c0e64da2f24e3ec845599
_______________________________________________ jhc mailing list [email protected] http://www.haskell.org/mailman/listinfo/jhc
