-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbg
53 lines (48 loc) · 1.11 KB
/
dbg
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
(fun (dbg/out str)
(var ptr str)
(while (u8 ptr)
(set ptr (+ ptr 1)))
(sys/write 2 str (- ptr str)))
(fun (dbg/int l n)
(dbg/out l)
(dbg/out ": ")
(if ((< n 0)
(dbg/out "-")
(set n (- n))))
(mem buf 40)
(var end (+ buf 40))
(var ptr end)
(set ptr (- ptr 1))
(set (u8 ptr) 0)
(while (begin
(set ptr (- ptr 1))
(set (u8 ptr) (+ (% n 10) 48))
(set n (/ n 10))
n))
(dbg/out ptr)
(dbg/out "\n"))
(fun (dbg/str l s)
(dbg/out l)
(dbg/out ": ")
(dbg/out s)
(dbg/out "\n"))
(fun (dbg/assert cond msg)
(if ((not cond)
(dbg/out msg)
(dbg/out "\n")
(sys/exit 1))))
(fun (dbg/assert-equal actual expected thing)
(if ((!= actual expected)
(dbg/out "wrong ")
(dbg/out thing)
(dbg/out "\n")
(dbg/int " actual" actual)
(dbg/int " expected" expected)
(sys/exit 1))))
(fun (dbg/assert-less-or-equal value max thing)
(if ((> value max)
(dbg/out thing)
(dbg/out " too large\n")
(dbg/int " value" value)
(dbg/int " maximum" max)
(sys/exit 1))))