Import Upstream version 20180207
[hcoop/debian/mlton.git] / mlton / atoms / real-size.fun
1 (* Copyright (C) 2004-2007 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 *
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
6 *)
7
8 functor RealSize (S: REAL_SIZE_STRUCTS): REAL_SIZE =
9 struct
10
11 open S
12
13 datatype t = R32 | R64
14
15 val all = [R32, R64]
16
17 val equals: t * t -> bool = op =
18
19 val memoize: (t -> 'a) -> t -> 'a =
20 fn f =>
21 let
22 val r32 = f R32
23 val r64 = f R64
24 in
25 fn R32 => r32
26 | R64 => r64
27 end
28
29 val toString =
30 fn R32 => "32"
31 | R64 => "64"
32
33 val bytes: t -> Bytes.t =
34 fn R32 => Bytes.fromInt 4
35 | R64 => Bytes.fromInt 8
36
37 val bits: t -> Bits.t = Bytes.toBits o bytes
38
39 end