aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/macro_export.yue
blob: eec5848f289f5ef433702f273875928eeb3c1670 (plain)
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
import "macro_todo" as $

import "macro_todo" as {$, :$todo}

export macro config = (debugging = true)->
	global debugMode = debugging == "true"
	global debugMacro = true
	""

export macro showMacro = (name, res)->
	if debugMacro then "
do
	txt = #{res}
	print '[macro ' .. #{name} .. ']'
	print txt
	txt
"
	else
		res

export macro asserts = (cond)->
	if debugMode
		$showMacro "assert", "assert #{cond}"
	else
		""

export macro assert = (cond)->
	if debugMode
		$showMacro "assert", "assert #{cond}"
	else
		"#{cond}"

export macro copy = (src, dst, ...)->
	assert(
		src != "_src_" and src != "_dst_" and dst != "_src_" and dst != "_dst_"
		"copy targets can not be _src_ or _dst_"
	)
	"
do
	local _src_, _dst_
	with _dst_ = #{dst}
		with _src_ = #{src}
#{table.concat for field in *{...} do "
			_dst_.#{field} = _src_.#{field}
"}"

$ ->
	global debugMode = true
	global debugMacro = true