diff options
Diffstat (limited to 'spec/inputs/macro_export.yue')
-rw-r--r-- | spec/inputs/macro_export.yue | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/inputs/macro_export.yue b/spec/inputs/macro_export.yue new file mode 100644 index 0000000..eec5848 --- /dev/null +++ b/spec/inputs/macro_export.yue | |||
@@ -0,0 +1,50 @@ | |||
1 | import "macro_todo" as $ | ||
2 | |||
3 | import "macro_todo" as {$, :$todo} | ||
4 | |||
5 | export macro config = (debugging = true)-> | ||
6 | global debugMode = debugging == "true" | ||
7 | global debugMacro = true | ||
8 | "" | ||
9 | |||
10 | export macro showMacro = (name, res)-> | ||
11 | if debugMacro then " | ||
12 | do | ||
13 | txt = #{res} | ||
14 | print '[macro ' .. #{name} .. ']' | ||
15 | print txt | ||
16 | txt | ||
17 | " | ||
18 | else | ||
19 | res | ||
20 | |||
21 | export macro asserts = (cond)-> | ||
22 | if debugMode | ||
23 | $showMacro "assert", "assert #{cond}" | ||
24 | else | ||
25 | "" | ||
26 | |||
27 | export macro assert = (cond)-> | ||
28 | if debugMode | ||
29 | $showMacro "assert", "assert #{cond}" | ||
30 | else | ||
31 | "#{cond}" | ||
32 | |||
33 | export macro copy = (src, dst, ...)-> | ||
34 | assert( | ||
35 | src != "_src_" and src != "_dst_" and dst != "_src_" and dst != "_dst_" | ||
36 | "copy targets can not be _src_ or _dst_" | ||
37 | ) | ||
38 | " | ||
39 | do | ||
40 | local _src_, _dst_ | ||
41 | with _dst_ = #{dst} | ||
42 | with _src_ = #{src} | ||
43 | #{table.concat for field in *{...} do " | ||
44 | _dst_.#{field} = _src_.#{field} | ||
45 | "}" | ||
46 | |||
47 | $ -> | ||
48 | global debugMode = true | ||
49 | global debugMacro = true | ||
50 | |||