2017-12-23 16:10:44 +03:00
|
|
|
(defmodule Debug
|
|
|
|
|
|
|
|
(defdynamic sanitize-addresses []
|
|
|
|
(add-cflag "-fsanitize=address"))
|
|
|
|
|
|
|
|
(register memory-balance (Fn [] Long))
|
|
|
|
(register reset-memory-balance! (Fn [] ()))
|
2018-01-02 08:54:05 +03:00
|
|
|
(register log-memory-balance! (Fn [Bool] ()))
|
2018-01-02 08:46:01 +03:00
|
|
|
|
|
|
|
(defmacro memory-logged [form]
|
|
|
|
(list 'do
|
2018-01-02 08:54:05 +03:00
|
|
|
'(Debug.log-memory-balance! true)
|
2018-01-02 08:46:01 +03:00
|
|
|
form
|
2018-01-02 08:54:05 +03:00
|
|
|
'(Debug.log-memory-balance! false)))
|
2017-12-23 16:10:44 +03:00
|
|
|
|
2018-01-02 10:56:23 +03:00
|
|
|
(defmacro assert-balanced [form]
|
|
|
|
(list 'let '[balance (Debug.memory-balance)]
|
|
|
|
(list 'do
|
|
|
|
(list 'let []
|
|
|
|
form)
|
|
|
|
'(if (= balance (Debug.memory-balance))
|
|
|
|
()
|
|
|
|
(do (IO.println &(fmt "Invalid memory balance: %d" (Debug.memory-balance)))
|
|
|
|
(System.exit 1)))
|
|
|
|
())))
|
|
|
|
|
2017-12-25 18:33:03 +03:00
|
|
|
(defn trace [x]
|
|
|
|
(do
|
|
|
|
(IO.println &(str &x))
|
|
|
|
x))
|
|
|
|
|
2017-12-23 16:10:44 +03:00
|
|
|
)
|
2018-02-06 12:12:43 +03:00
|
|
|
|
|
|
|
(defmacro assert [expr]
|
|
|
|
(list 'if (list '= true expr)
|
|
|
|
()
|
|
|
|
(list 'do
|
|
|
|
(list 'IO.println (list 'ref
|
|
|
|
(list 'String.append (list 'String.copy "Assertion failed ")
|
|
|
|
(list 'String.copy (source-location)))))
|
|
|
|
'(System.exit 1))))
|