Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / MLtonPointer.adoc
CommitLineData
7f918cf1
CE
1MLtonPointer
2============
3
4[source,sml]
5----
6signature MLTON_POINTER =
7 sig
8 eqtype t
9
10 val add: t * word -> t
11 val compare: t * t -> order
12 val diff: t * t -> word
13 val getInt8: t * int -> Int8.int
14 val getInt16: t * int -> Int16.int
15 val getInt32: t * int -> Int32.int
16 val getInt64: t * int -> Int64.int
17 val getPointer: t * int -> t
18 val getReal32: t * int -> Real32.real
19 val getReal64: t * int -> Real64.real
20 val getWord8: t * int -> Word8.word
21 val getWord16: t * int -> Word16.word
22 val getWord32: t * int -> Word32.word
23 val getWord64: t * int -> Word64.word
24 val null: t
25 val setInt8: t * int * Int8.int -> unit
26 val setInt16: t * int * Int16.int -> unit
27 val setInt32: t * int * Int32.int -> unit
28 val setInt64: t * int * Int64.int -> unit
29 val setPointer: t * int * t -> unit
30 val setReal32: t * int * Real32.real -> unit
31 val setReal64: t * int * Real64.real -> unit
32 val setWord8: t * int * Word8.word -> unit
33 val setWord16: t * int * Word16.word -> unit
34 val setWord32: t * int * Word32.word -> unit
35 val setWord64: t * int * Word64.word -> unit
36 val sizeofPointer: word
37 val sub: t * word -> t
38 end
39----
40
41* `eqtype t`
42+
43the type of pointers, i.e. machine addresses.
44
45* `add (p, w)`
46+
47returns the pointer `w` bytes after than `p`. Does not check for
48overflow.
49
50* `compare (p1, p2)`
51+
52compares the pointer `p1` to the pointer `p2` (as addresses).
53
54* `diff (p1, p2)`
55+
56returns the number of bytes `w` such that `add (p2, w) = p1`. Does
57not check for overflow.
58
59* ++get__<X>__ (p, i)++
60+
61returns the object stored at index i of the array of _X_ objects
62pointed to by `p`. For example, `getWord32 (p, 7)` returns the 32-bit
63word stored 28 bytes beyond `p`.
64
65* `null`
66+
67the null pointer, i.e. 0.
68
69* ++set__<X>__ (p, i, v)++
70+
71assigns `v` to the object stored at index i of the array of _X_
72objects pointed to by `p`. For example, `setWord32 (p, 7, w)` stores
73the 32-bit word `w` at the address 28 bytes beyond `p`.
74
75* `sizeofPointer`
76+
77size, in bytes, of a pointer.
78
79* `sub (p, w)`
80+
81returns the pointer `w` bytes before `p`. Does not check for
82overflow.