| ... | ... | @@ -26,7 +26,7 @@ allow declarations of the form |
|
|
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
foreign space [const] <n> :: Ptr <type>
|
|
|
|
foreign space [const] <n> "name" :: Ptr <type>
|
|
|
|
```
|
|
|
|
|
|
|
|
|
| ... | ... | @@ -53,7 +53,7 @@ The initial contents of the memory may also be specified: |
|
|
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
foreign space [bigendian|littleendian] [const] <n> :: Ptr <type> = constant
|
|
|
|
foreign space [bigendian|littleendian] [const] <n> "name" :: Ptr <type> = constant
|
|
|
|
```
|
|
|
|
|
|
|
|
|
| ... | ... | @@ -64,14 +64,14 @@ where constant may be one of |
|
|
|
|
|
|
|
- an initialized list: \[ 0, 1, 2, …\]
|
|
|
|
|
|
|
|
- a "string" to be output as utf8, utf16 or ucs4 unicode code points depending on what type of pointer it is assigned to.
|
|
|
|
- a "string" to be output as utf8, utf16 or ucs4 unicode code points depending on the size of the type of pointer it is assigned to.
|
|
|
|
|
|
|
|
|
|
|
|
if the data is initialized as a string, \<n\> will always refer to a number of characters regardless of encoding and the string will be null terminated (unless an explicit \<n\> chops off the trailing space)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
big endian or little endian may be explicitly specified in which case the data is written out with the specified endianess, else it will be output in the default format of the given system.
|
|
|
|
big endian or little endian may be explicitly specified in which case the data is written out with the specified endianess, else it will be output in the default format of the target system.
|
|
|
|
|
|
|
|
|
|
|
|
## implementation
|
| ... | ... | @@ -88,3 +88,33 @@ Implementation is trivial once you can parse the new constructs (purposfully sim |
|
|
|
It is anoying that \<n\> must be a constant and \<type\> must be a builtin, but there is not really any other recourse without defining a preprocessor in haskell and the restrictions are no more onerous than those placed on the arguments to foreign function calls. Something like template haskell would mitigate this problem when available.
|
|
|
|
|
|
|
|
|
|
|
|
## sample translation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when compiling to C, here is an example of what the code will translate too.
|
|
|
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
foreign space const "myints" :: Ptr CInt = [1,2,3,4]
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
becomes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
the haskell import:
|
|
|
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
forign import "&c_myints" myints :: Ptr CInt
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
and the c code:
|
|
|
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
int c_myints[] = {1,2,3,4};
|
|
|
|
``` |
|
|
\ No newline at end of file |