Import Upstream version 20180207
[hcoop/debian/mlton.git] / basis-library / mlton / platform.sml
CommitLineData
7f918cf1
CE
1(* Copyright (C) 2003-2009 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
8structure MLtonPlatform: MLTON_PLATFORM =
9 struct
10 open Primitive.MLton.Platform
11
12 fun peek (l, f) = List.find f l
13 fun omap (opt, f) = Option.map f opt
14
15 structure Arch =
16 struct
17 open Arch
18
19 val all = [
20 (Alpha, "Alpha"),
21 (AMD64, "AMD64"),
22 (ARM, "ARM"),
23 (ARM64, "ARM64"),
24 (HPPA, "HPPA"),
25 (IA64, "IA64"),
26 (m68k, "m68k"),
27 (MIPS, "MIPS"),
28 (PowerPC, "PowerPC"),
29 (PowerPC64, "PowerPC64"),
30 (S390, "S390"),
31 (Sparc, "Sparc"),
32 (X86, "X86")]
33
34 fun fromString s =
35 let
36 val s = String.toLower s
37 in
38 omap (peek (all, fn (_, s') => s = String.toLower s'), #1)
39 end
40
41 fun toString a = #2 (valOf (peek (all, fn (a', _) => a = a')))
42 end
43
44 structure Format =
45 struct
46 open Format
47
48 val all = [
49 (Archive, "Archive"),
50 (Executable, "Executable"),
51 (LibArchive, "LibArchive"),
52 (Library, "Library")]
53
54 fun fromString s =
55 let
56 val s = String.toLower s
57 in
58 omap (peek (all, fn (_, s') => s = String.toLower s'), #1)
59 end
60
61 fun toString a = #2 (valOf (peek (all, fn (a', _) => a = a')))
62 end
63
64 structure OS =
65 struct
66 open OS
67
68 val all = [
69 (AIX, "AIX"),
70 (Cygwin, "Cygwin"),
71 (Darwin, "Darwin"),
72 (FreeBSD, "FreeBSD"),
73 (Hurd, "Hurd"),
74 (HPUX, "HPUX"),
75 (Linux, "Linux"),
76 (MinGW, "MinGW"),
77 (NetBSD, "NetBSD"),
78 (OpenBSD, "OpenBSD"),
79 (Solaris, "Solaris")]
80
81 fun fromString s =
82 let
83 val s = String.toLower s
84 in
85 omap (peek (all, fn (_, s') => s = String.toLower s'), #1)
86 end
87
88 fun toString a = #2 (valOf (peek (all, fn (a', _) => a = a')))
89 end
90 end