-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStdError.milone
48 lines (33 loc) · 1.18 KB
/
StdError.milone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module rec Std.StdError
let __dump (_: 'T) : string = "<dump>"
let __writeError (s: string) : unit =
__nativeStmt ("fwrite({0}.ptr, sizeof(char), (size_t){0}.len, stderr);", s)
let __writeErrorLine (s: string) : unit = __writeError (s + "\n")
/// Only for debugging. Prints to stderr.
let __trace (s: string) : unit = __writeErrorLine s
/// Only for debugging. Adds context to error info if thrown.
let __context _ (action: unit -> 'A) : 'A = action ()
// -----------------------------------------------
// F# primitives
// -----------------------------------------------
// add to prelude?
let failwith (msg: string) : never =
__nativeStmt (
"""
milone_failwithf("failwith: %s", string_to_c_str({0}));
""",
msg
)
// Make it clear that it's cold path.
assert false
__nativeExpr "never"
let failwithf (msg: string) (_: 'A) : never = failwith msg
// -----------------------------------------------
// Exceptions
// -----------------------------------------------
/// Never executed.
let unreachable (_: 'A) : never = failwith "unreachable"
/// Not implemented.
let todo () : never = failwith "todo"
/// For compatibility with F#.
let never (n: never) : never = n