From: rrt Date: Wed, 5 Jan 2000 11:06:24 +0000 (+0000) Subject: [project @ 2000-01-05 11:06:23 by rrt] X-Git-Tag: Approximately_9120_patches~5354 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=bb0b4b694e2f9cc87c195ca176ed522b1fe2ff8e;p=ghc-hetmet.git [project @ 2000-01-05 11:06:23 by rrt] Documentation changed from LinuxDoc to DocBook format, and license added to the user guide. --- diff --git a/ghc/docs/users_guide/ByteArray.sgml b/ghc/docs/users_guide/ByteArray.sgml index 69fae3e..e378be3 100644 --- a/ghc/docs/users_guide/ByteArray.sgml +++ b/ghc/docs/users_guide/ByteArray.sgml @@ -1,45 +1,77 @@ -The -

-ByteArray interface (GHC extensions) + +The ByteArray +<IndexTerm><Primary>ByteArray</Primary></IndexTerm> +interface + - +ByteArray interface (GHC extensions) + - + +ByteArrays are chunks of immutable Haskell heap: + + + + + data ByteArray ix -- abstract -- instance of: Eq, CCallable. -newByteArray :: Ix ix => (ix,ix) -> ST s (ByteArray ix) - -indexCharArray :: Ix ix => ByteArray ix -> ix -> Char -indexIntArray :: Ix ix => ByteArray ix -> ix -> Int -indexAddrArray :: Ix ix => ByteArray ix -> ix -> Addr -indexFloatArray :: Ix ix => ByteArray ix -> ix -> Float -indexDoubleArray :: Ix ix => ByteArray ix -> ix -> Double - -sizeofByteArray :: Ix ix => ByteArray ix -> Int - - - -The operation - +newByteArray :: Ix ix => (ix,ix) -> ST s (ByteArray ix) + +indexCharArray :: Ix ix => ByteArray ix -> ix -> Char +indexIntArray :: Ix ix => ByteArray ix -> ix -> Int +indexAddrArray :: Ix ix => ByteArray ix -> ix -> Addr +indexFloatArray :: Ix ix => ByteArray ix -> ix -> Float +indexDoubleArray :: Ix ix => ByteArray ix -> ix -> Double + +sizeofByteArray :: Ix ix => ByteArray ix -> Int + + +newByteArray +indexCharArray +indexIntArray +indexAddrArray +indexFloatArray +indexDoubleArray +indexDoubleArray +sizeofByteArray + + + +Remarks: + + + + + + + + +The operation newByteArray creates a byte array of length +equal to the range of its indices in bytes. + + + + + +sizeofByteArray returns the size of the byte array, in bytes. + + + + + + Equality on byte arrays is value equality, not pointer equality (as is the case for its mutable variant.) Two byte arrays are equal if they're of the same length and they're pairwise equal. - + + + + + + + + diff --git a/ghc/docs/users_guide/Makefile b/ghc/docs/users_guide/Makefile index 3e78ce8..a45ac78 100644 --- a/ghc/docs/users_guide/Makefile +++ b/ghc/docs/users_guide/Makefile @@ -5,10 +5,6 @@ ifeq "$(BIN_DIST)" "1" install :: html dvi info endif -# Split up the pages on a per-sect2 basis. Big HTML docs -# are a pain to flick through and use. -SRC_SGML2HTML_OPTS += -s 1 - SGML_DOC = users_guide # Generating index is semi-automatic, you need to: diff --git a/ghc/docs/users_guide/MutableArray.sgml b/ghc/docs/users_guide/MutableArray.sgml index 9abd850..9639366 100644 --- a/ghc/docs/users_guide/MutableArray.sgml +++ b/ghc/docs/users_guide/MutableArray.sgml @@ -1,211 +1,270 @@ - -

+ +MutableArray +<IndexTerm><Primary>MutableArray</Primary></IndexTerm> + -The +The MutableArray interface provide operations for reading and writing values to mutable arrays. There's two kinds of -mutable arrays, the mutatable version of Haskell Arrays +and mutable byte arrays, chunks of memory containing +values of some basic type. + - -

+ +Mutable arrays +<IndexTerm><Primary>Mutable arrays</Primary></IndexTerm> + + The mutable array section of the API provides the following operations: + - + + -- mutable arrays: -newArray :: Ix ix -> (ix,ix) -> elt -> ST s (MutableArray s ix elt) -boundsOfArray :: Ix ix => MutableArray s ix elt -> (ix, ix) -readArray :: Ix ix => MutableArray s ix elt -> ix -> ST s elt -writeArray :: Ix ix => MutableArray s ix elt -> ix -> elt -> ST s () -freezeArray :: Ix ix => MutableArray s ix elt -> ST s (Array ix elt) -thawArray :: Ix ix => Array ix elt -> ST s (MutableArray s ix elt) - -unsafeFreezeArray :: Ix ix => MutableArray s ix elt -> ST s (Array ix elt) -unsafeThawArray :: Ix ix => Array ix elt -> ST s (MutableArray s ix elt) - -newArray -boundsOfArray -readArray -writeArray -freezeArray -thawArray -unsafeFreezeArray -unsafeThawArray - - - -The + +newArray +boundsOfArray +readArray +writeArray +freezeArray +thawArray +unsafeFreezeArray +unsafeThawArray + + + +Remarks: + + + + + + + + +The freezeArray action converts a mutable array into an +immutable one by copying, whereas unsafeFreezeArray returns an immutable array that is effectively just the type cast version of the mutable array. Should you write to the mutable array after it has been (unsafely) frozen, you'll side-effect the immutable array in the process. Please don't :-) - -The operation + + + + +The operation thawArray goes the other way, converting +an immutable Array into a mutable one. This is done by +copying. The operation unsafeThawArray is also provided, which places the same kind of proof obligation on the programmer -as +as unsafeFreezeArray does. + + + + - -

+ - + + + +Mutable byte arrays +<IndexTerm><Primary>Mutable byte arrays</Primary></IndexTerm> + + + + -- creators: -newCharArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) -newAddrArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) -newIntArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) -newWordArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) -newFloatArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) -newDoubleArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) -newStablePtrArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) - -boundsOfMutableByteArray - :: Ix ix => MutableByteArray s ix -> (ix, ix) - -readCharArray :: Ix ix => MutableByteArray s ix -> ix -> ST s Char -readIntArray :: Ix ix => MutableByteArray s ix -> ix -> ST s Int -readAddrArray :: Ix ix => MutableByteArray s ix -> ix -> ST s Addr -readFloatArray :: Ix ix => MutableByteArray s ix -> ix -> ST s Float -readDoubleArray :: Ix ix => MutableByteArray s ix -> ix -> ST s Double -readStablePtrArray :: Ix ix => MutableByteArray s ix -> ix -> ST s (StablePtr a) -readWord8Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Word8 -readWord16Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Word16 -readWord32Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Word32 -readWord64Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Word64 -readInt8Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Int8 -readInt16Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Int16 -readInt32Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Int32 -readInt64Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Int64 - -writeCharArray :: Ix ix => MutableByteArray s ix -> ix -> Char -> ST s () -writeIntArray :: Ix ix => MutableByteArray s ix -> ix -> Int -> ST s () -writeAddrArray :: Ix ix => MutableByteArray s ix -> ix -> Addr -> ST s () -writeFloatArray :: Ix ix => MutableByteArray s ix -> ix -> Float -> ST s () -writeDoubleArray :: Ix ix => MutableByteArray s ix -> ix -> Double -> ST s () -writeStablePtrArray :: Ix ix => MutableByteArray s ix -> ix -> StablePtr a -> ST s () -writeWord8Array :: Ix ix => MutableByteArray s ix -> ix -> Word8 -> ST s () -writeWord16Array :: Ix ix => MutableByteArray s ix -> ix -> Word16 -> ST s () -writeWord32Array :: Ix ix => MutableByteArray s ix -> ix -> Word32 -> ST s () -writeWord64Array :: Ix ix => MutableByteArray s ix -> ix -> Word64 -> ST s () -writeInt8Array :: Ix ix => MutableByteArray s ix -> ix -> Int8 -> ST s () -writeInt16Array :: Ix ix => MutableByteArray s ix -> ix -> Int16 -> ST s () -writeInt32Array :: Ix ix => MutableByteArray s ix -> ix -> Int32 -> ST s () -writeInt64Array :: Ix ix => MutableByteArray s ix -> ix -> Int64 -> ST s () - -freezeCharArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) -freezeIntArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) -freezeAddrArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) -freezeFloatArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) -freezeDoubleArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) -freezeStablePtrArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) - -unsafeFreezeByteArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) - -sizeofMutableByteArray :: Ix ix => MutableByteArray s ix -> Int - -thawByteArray :: Ix ix => ByteArray ixt -> ST s (MutableByteArray s ix) -unsafeThawByteArray :: Ix ix => ByteArray ixt -> ST s (MutableByteArray s ix) - - -newCharArray -newAddrArray -newIntArray -newFloatArray -newDoubleArray -boundsOfMutableByteArray -readCharArray -readIntArray -readAddrArray -readFloatArray -readDoubleArray -readWord8Array -readWord16Array -readWord32Array -readWord64Array -readInt8Array -readInt16Array -readInt32Array -readInt64Array -writeCharArray -writeIntArray -writeAddrArray -writeFloatArray -writeDoubleArray -writeWord8Array -writeWord16Array -writeWord32Array -writeWord64Array -writeInt8Array -writeInt16Array -writeInt32Array -writeInt64Array -freezeCharArray -freezeIntArray -freezeAddrArray -freezeFloatArray -freezeDoubleArray -unsafeFreezeByteArray -unsafeThawByteArray -thawByteArray - - - +newCharArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) +newAddrArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) +newIntArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) +newWordArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) +newFloatArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) +newDoubleArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) +newStablePtrArray :: Ix ix => (ix,ix) -> ST s (MutableByteArray s ix) + +boundsOfMutableByteArray + :: Ix ix => MutableByteArray s ix -> (ix, ix) + +readCharArray :: Ix ix => MutableByteArray s ix -> ix -> ST s Char +readIntArray :: Ix ix => MutableByteArray s ix -> ix -> ST s Int +readAddrArray :: Ix ix => MutableByteArray s ix -> ix -> ST s Addr +readFloatArray :: Ix ix => MutableByteArray s ix -> ix -> ST s Float +readDoubleArray :: Ix ix => MutableByteArray s ix -> ix -> ST s Double +readStablePtrArray :: Ix ix => MutableByteArray s ix -> ix -> ST s (StablePtr a) +readWord8Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Word8 +readWord16Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Word16 +readWord32Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Word32 +readWord64Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Word64 +readInt8Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Int8 +readInt16Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Int16 +readInt32Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Int32 +readInt64Array :: Ix ix => MutableByteArray s ix -> ix -> ST s Int64 + +writeCharArray :: Ix ix => MutableByteArray s ix -> ix -> Char -> ST s () +writeIntArray :: Ix ix => MutableByteArray s ix -> ix -> Int -> ST s () +writeAddrArray :: Ix ix => MutableByteArray s ix -> ix -> Addr -> ST s () +writeFloatArray :: Ix ix => MutableByteArray s ix -> ix -> Float -> ST s () +writeDoubleArray :: Ix ix => MutableByteArray s ix -> ix -> Double -> ST s () +writeStablePtrArray :: Ix ix => MutableByteArray s ix -> ix -> StablePtr a -> ST s () +writeWord8Array :: Ix ix => MutableByteArray s ix -> ix -> Word8 -> ST s () +writeWord16Array :: Ix ix => MutableByteArray s ix -> ix -> Word16 -> ST s () +writeWord32Array :: Ix ix => MutableByteArray s ix -> ix -> Word32 -> ST s () +writeWord64Array :: Ix ix => MutableByteArray s ix -> ix -> Word64 -> ST s () +writeInt8Array :: Ix ix => MutableByteArray s ix -> ix -> Int8 -> ST s () +writeInt16Array :: Ix ix => MutableByteArray s ix -> ix -> Int16 -> ST s () +writeInt32Array :: Ix ix => MutableByteArray s ix -> ix -> Int32 -> ST s () +writeInt64Array :: Ix ix => MutableByteArray s ix -> ix -> Int64 -> ST s () + +freezeCharArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) +freezeIntArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) +freezeAddrArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) +freezeFloatArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) +freezeDoubleArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) +freezeStablePtrArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) + +unsafeFreezeByteArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix) + +sizeofMutableByteArray :: Ix ix => MutableByteArray s ix -> Int + +thawByteArray :: Ix ix => ByteArray ixt -> ST s (MutableByteArray s ix) +unsafeThawByteArray :: Ix ix => ByteArray ixt -> ST s (MutableByteArray s ix) + + +newCharArray +newAddrArray +newIntArray +newFloatArray +newDoubleArray +boundsOfMutableByteArray +readCharArray +readIntArray +readAddrArray +readFloatArray +readDoubleArray +readWord8Array +readWord16Array +readWord32Array +readWord64Array +readInt8Array +readInt16Array +readInt32Array +readInt64Array +writeCharArray +writeIntArray +writeAddrArray +writeFloatArray +writeDoubleArray +writeWord8Array +writeWord16Array +writeWord32Array +writeWord64Array +writeInt8Array +writeInt16Array +writeInt32Array +writeInt64Array +freezeCharArray +freezeIntArray +freezeAddrArray +freezeFloatArray +freezeDoubleArray +unsafeFreezeByteArray +unsafeThawByteArray +thawByteArray + + + +Remarks: + + + + + A Mutable byte array is created by specifying its size in units of some basic type. For example, - - mkPair :: ST s (MutableByteArray s Int) - mkPair = newIntArray (0,1) - -creates a mutable array capable of storing two +mkPair :: ST s (MutableByteArray s Int) +mkPair = newIntArray (0,1) + + + +creates a mutable array capable of storing two Ints. Notice +that the range size is not in bytes, but in units of the basic type. - + + + + + A mutable byte array is not parameterised over the kind of values it contains. A consequence of this is that it is possible to have byte arrays containing a mix of basic types, or even read a value from the array at a different type from which it was written, e.g., - - isLitteEndian :: IO Bool - isLitteEndian = stToIO $ do - x <- newIntArray (0,1) - writeIntArray x 1 - v <- readCharArray x 0 - return (v == chr 1) - + +isLitteEndian :: IO Bool +isLitteEndian = stToIO $ do + x <- newIntArray (0,1) + writeIntArray x 1 + v <- readCharArray x 0 + return (v == chr 1) + + It's left as an exercise for the reader to determine whether having byte arrays not be parameterised over the type of values they contain is a bug or a feature.. - + + + + As for mutable arrays, operations for turning mutable byte arrays -into immutable byte arrays are also provided by the freeze* class of actions. There's also the non-copying - - +unsafeFreezeByteArray. + + + + + Operations for going the other way, where an immutable byte -array is 'thawed' are also provided. thawByteArray does +this by copying, whereas unsafeThawByteArray does not + + + + + + +The operation sizeofMutableByteArray returns the size of +the array, in bytes. + + + + + + + + - -The operation + diff --git a/ghc/docs/users_guide/win32-dlls.sgml b/ghc/docs/users_guide/win32-dlls.sgml index 8c3090b..a26db27 100644 --- a/ghc/docs/users_guide/win32-dlls.sgml +++ b/ghc/docs/users_guide/win32-dlls.sgml @@ -1,31 +1,29 @@ -%************************************************************************ -%* * -Building and using Win32 DLLs -

-Dynamic link libraries, Win32 -DLLs, Win32 -%* * -%************************************************************************ + +Building and using Win32 DLLs + + +Dynamic link libraries, Win32 +DLLs, Win32 On Win32 platforms, the compiler is capable of both producing and using dynamic link libraries (DLLs) containing ghc-compiled code. This section shows you how to make use of this facility. + -%************************************************************************ -%* * -Linking with DLLs -

-%* * -%************************************************************************ + +Linking with DLLs + + The default on Win32 platforms is to link applications in such a way that the executables will use the Prelude and system libraries DLLs, rather than contain (large chunks of) them. This is transparent at the command-line, so + - + + + sh$ cat main.hs module Main where main = putStrLn "hello, world!" @@ -37,133 +35,186 @@ sh$ ls -l main.exe sh$ ./main hello, world! sh$ - + + + -will give you a binary as before, but the main.exe generated + +will give you a binary as before, but the main.exe generated will use the Prelude and RTS DLLs instead. + + + +6K for a "hello, world" application - not bad, huh? :-) + -6K for a "hello, world" application - not bad, huh? :-) + -%************************************************************************ -%* * -Not linking with DLLs -

-%* * -%************************************************************************ + +Not linking with DLLs +<IndexTerm><Primary>-static option (Win32)</Primary></IndexTerm> + If you want to build an executable that doesn't depend on any -ghc-compiled DLLs, use the -static option to link in +ghc-compiled DLLs, use the -static option to link in the code statically. + + Notice that you cannot mix code that has been compiled with --static and not, so you have to use the -static +-static and not, so you have to use the -static option on all the Haskell modules that make up your application. + -%************************************************************************ -%* * -Creating a DLL -

-Creating a Win32 DLL ---mk-dll -%* * -%************************************************************************ + + +Creating a DLL + + + +Creating a Win32 DLL +--mk-dll Sealing up your Haskell library inside a DLL is quite straightforward; compile up the object files that make up the library, and then build the DLL by issuing the following command: + - + + sh$ ghc --mk-dll -o HSsuper.dll A.o Super.o B.o libmine.a -lgdi32 - + + -By feeding the ghc compiler driver the option --mk-dll, it + +By feeding the ghc compiler driver the option --mk-dll, it will build a DLL rather than produce an executable. The DLL will consist of all the object files and archives given on the command line. + + A couple of things to notice: + + + + + + - - -When compiling the module A, the code emitted by the compiler + +When compiling the module A, the code emitted by the compiler differs depending on whether or not the functions and data it is importing from other Haskell modules correspond to symbols that are packaged up in a ghc-compiled DLL. To resolve whether such imports are 'DLL imports' or not, the following rules are used: - - + + + + + If the compiler imports from a module that's in the same directory as the one being compiled, it is assumed to not belong to a different DLL (or executable) than the module being processed, so none of the same-directory imports are considered 'DLL imports'. - + + + + + If a directory contains the (probably empty) file -dLL_ifs.hi, the code corresponding to the interface +dLL_ifs.hi, the code corresponding to the interface files found in that directory are assumed to live in a DLL separate from the one being compiled. Notice that the first rule takes precedence over this one, so if you're compiling a module that imports from a Haskell module whose -interface file live in the same directory, and that directory -also contains the file dLL_ifs.hi, the import is still not +interface file live in the same directory, and that directory +also contains the file dLL_ifs.hi, the import is still not being considered to be a 'DLL import'. - -If compiling with the option -static, the previous rule + + + + + +If compiling with the option -static, the previous rule is disabled. - + + + + + So, in short, after having built your Haskell DLL, make sure you -create the file dLL_ifs.hi in the directory that contains +create the file dLL_ifs.hi in the directory that contains its interface files. If you don't, Haskell code that calls upon entry points in that DLL, will do so incorrectly, and a crash will result. (it is unfortunate that this isn't currently caught at compile-time). - + + + + + By default, the entry points of all the object files will -be exported from the DLL when using --mk-dll. Should you want -to constrain this, you can specify the module definition file +be exported from the DLL when using --mk-dll. Should you want +to constrain this, you can specify the module definition file to use on the command line as follows: - + + sh$ ghc --mk-dll -o .... -optdll--def -optdllMyDef.def - + + See Microsoft documentation for details, but a module definition file simply lists what entry points you want to export. Here's one that's suitable when building a Haskell COM server DLL: - + + EXPORTS DllCanUnloadNow = DllCanUnloadNow@0 DllGetClassObject = DllGetClassObject@12 DllRegisterServer = DllRegisterServer@0 DllUnregisterServer = DllUnregisterServer@0 + + - + + + - -In addition to creating a DLL, the --mk-dll option will also + +In addition to creating a DLL, the --mk-dll option will also create an import library. The import library name is derived from the name of the DLL, as follows: - - DLL: HScool.dll ==> import lib: libHScool_imp.a - + +DLL: HScool.dll ==> import lib: libHScool_imp.a + + The naming scheme may look a bit weird, but it has the purpose of allowing the co-existence of import libraries with ordinary static -libraries (e.g., libHSfoo.a and libHSfoo_imp.a. +libraries (e.g., libHSfoo.a and libHSfoo_imp.a. Additionally, when the compiler driver is linking in non-static mode, -it will rewrite occurrence of -lHSfoo on the command line to --lHSfoo_imp. By doing this for you, switching from non-static -to static linking is simply a question of adding -static to +it will rewrite occurrence of -lHSfoo on the command line to +-lHSfoo_imp. By doing this for you, switching from non-static +to static linking is simply a question of adding -static to your command line. - + + + + + + + + + +