-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmacro.ml
49 lines (45 loc) · 889 Bytes
/
macro.ml
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
import stdlib.builtin.for
macro repeat(_n, _body)
for _repeat_it in range(_n)
_body
end
end
# Inserts a delimiter between arguments
macro delimit(_delim, _arg)
_arg
end
macro delimit(_delim, _arg, _arg2)
_arg, _delim, _arg2
end
macro delimit(_delim2, _arg, _arg2, _other)
delimit(_delim2, _arg, _arg2), _delim2, delimit(_delim2, _other)
end
# Reverses the argument list
macro reverse(_arg, _arg2)
_arg2, _arg
end
macro reverse(_arg1, _arg2, _arg3)
reverse(_arg2, _arg3), _arg1
end
# Miscellaneous
macro ref(_arg)
&_arg
end
macro not(_arg)
false if _arg else true
end
macro neg(_arg)
_arg = not(_arg)
end
macro incr(_arg)
_arg = _arg + 1
end
macro incr(_arg, _val)
_arg = _arg + _val
end
macro decr(_arg)
_arg = _arg - 1
end
macro decr(_arg, _val)
_arg = _arg - _val
end