-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassert.t
44 lines (37 loc) · 1.03 KB
/
assert.t
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
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
local C = terralib.includecstring [[
#include <stdio.h>
#include <stdlib.h>
]]
local ffi = require("ffi")
local OS = ffi.os
local S = {}
S.error = macro(function(expr, msg)
local tree = expr.tree
local filename = tree.filename
local linenumber = tree.linenumber
local offset = tree.offset
local loc = filename .. ":" .. linenumber .. "+" .. offset
return quote
terralib.debuginfo(filename, linenumber)
C.printf("%s: %s\n", loc, msg)
escape
--traceback currently does not work on macos
if OS == "Linux" then
emit quote terralib.traceback(nil) end
end
end
C.abort()
end
end)
S.assert = macro(function(condition)
return quote
if not condition then
S.error(condition, "assertion failed!")
end
end
end)
return S