-
Notifications
You must be signed in to change notification settings - Fork 4
/
err.myr
59 lines (46 loc) · 1.04 KB
/
err.myr
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
49
50
51
52
53
54
55
56
57
58
use std
pkg qc =
type srcloc = struct
file : byte[:]
line : int
col : int
;;
const ifmt : (sb : std.strbuf#, ind : int, fmt : byte[:], args : ... -> void)
$noret const err : (loc : srcloc, msg : byte[:], args : ... -> void)
$noret const verr : (loc : srcloc, msg : byte[:], args : std.valist# -> void)
;;
const err = {loc, msg, args
var ap, sb, ln
ap = std.vastart(&args)
sb = std.mksb()
std.sbfmtv(sb, msg, &ap)
ln = std.sbfin(sb)
std.fatal("{}: {}\n", loc, ln)
std.slfree(ln)
}
const verr = {loc, msg, ap
var sb, ln
sb = std.mksb()
std.sbfmtv(sb, msg, ap)
ln = std.sbfin(sb)
std.fatal("{}: {}\n", loc, ln)
std.slfree(ln)
}
const ifmt = {sb, ind, fmt, args : ...
var ap
ap = std.vastart(&args)
for var i = 0; i < ind; i++
std.sbputs(sb, " ")
;;
std.sbfmtv(sb, fmt, &ap)
}
const posfmt = {sb, ap, opts
var loc : srcloc
loc = std.vanext(ap)
std.sbfmt(sb, "{}:{}:{}", loc.file, loc.line, loc.col)
}
const __init__ = {
var dummy : srcloc
dummy = [.file="", .line=0, .col=0]
std.fmtinstall(std.typeof(dummy), posfmt)
}