Debian Codegraph @

basis-library/primitive/prim1.sml

raw
1 (* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 * Copyright (C) 1997-2000 NEC Research Institute.
4 *
5 * MLton is released under a HPND-style license.
6 * See the file MLton-LICENSE for details.
7 *)
8
9 (* Primitive names are special -- see atoms/prim.fun. *)
10
11 structure Primitive = struct
12
13 open Primitive
14
15 structure GetSet =
16 struct
17 type 'a t = (unit -> 'a) * ('a -> unit)
18 end
19
20 structure PreThread :> sig type t end = struct type t = Thread.t end
21 structure Thread :> sig type t end = struct type t = Thread.t end
22
23 (**************************************************************************)
24
25 structure Bool =
26 struct
27 open Bool
28 fun not b = if b then false else true
29 end
30
31 structure Controls =
32 struct
33 val debug = _command_line_const "MLton.debug": bool = false;
34 val detectOverflow = _command_line_const "MLton.detectOverflow": bool = true;
35 val safe = _command_line_const "MLton.safe": bool = true;
36 val bufSize = _command_line_const "TextIO.bufSize": Int32.int = 4096;
37 end
38
39 structure Exn =
40 struct
41 open Exn
42
43 val name = _prim "Exn_name": exn -> String8.string;
44
45 exception Div
46 exception Domain
47 exception Fail8 of String8.string
48 exception Fail16 of String16.string
49 exception Fail32 of String32.string
50 exception Overflow
51 exception Size
52 exception Span
53 exception Subscript
54
55 (* Fusing of adjacent `Word<N>_<op>` and `Word{S,U}<N>_<op>CheckP` primitives
56 * by the codegens may depend on the relative order of `!a` and `?a`;
57 * see:
58 * - /mlton/codegen/amd64-codegen/amd64-simplify.fun:elimALRedundant
59 * - /mlton/codegen/c-codegen/c-codegen.fun:outputStatementsFuseOpAndChk
60 * - /mlton/codegen/llvm-codegen/llvm-codegen.fun:outputStatementsFuseOpAndChk
61 * - /mlton/codegen/x86-codegen/x86-simplify.fun:elimALRedundant
62 *)
63 val mkOverflow: ('a -> 'b) * ('a -> bool) -> ('a -> 'b) =
64 fn (!, ?) => fn a =>
65 let val r = ! a
66 in if ? a then raise Overflow else r
67 end
68 end
69
70 structure Order =
71 struct
72 datatype t = LESS | EQUAL | GREATER
73 datatype order = datatype t
74 end
75
76 structure Option =
77 struct
78 datatype 'a t = NONE | SOME of 'a
79 datatype option = datatype t
80 end
81
82 structure Ref =
83 struct
84 open Ref
85 val deref = _prim "Ref_deref": 'a ref -> 'a;
86 val assign = _prim "Ref_assign": 'a ref * 'a -> unit;
87 end
88
89 structure TopLevel =
90 struct
91 val getHandler = _prim "TopLevel_getHandler": unit -> (exn -> unit);
92 val getSuffix = _prim "TopLevel_getSuffix": unit -> (unit -> unit);
93 val setHandler = _prim "TopLevel_setHandler": (exn -> unit) -> unit;
94 val setSuffix = _prim "TopLevel_setSuffix": (unit -> unit) -> unit;
95 end
96
97 end
98
99 val not = Primitive.Bool.not
100
101 exception Bind = Primitive.Exn.Bind
102 exception Div = Primitive.Exn.Div
103 exception Domain = Primitive.Exn.Domain
104 exception Match = Primitive.Exn.Match
105 exception Overflow = Primitive.Exn.Overflow
106 exception Size = Primitive.Exn.Size
107 exception Span = Primitive.Exn.Span
108 exception Subscript = Primitive.Exn.Subscript
109
110 datatype option = datatype Primitive.Option.option
111 datatype order = datatype Primitive.Order.order
112
113 infix 4 = <>
114 val op = = _prim "MLton_equal": ''a * ''a -> bool;
115 val op <> = fn (x, y) => not (x = y)