aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2020-03-12 10:27:53 +0800
committerLi Jin <dragon-fly@qq.com>2020-03-12 10:27:53 +0800
commitb2cdbc975526b710d23c41af18978afbac516240 (patch)
tree40092d049e9e424476a548f1b3de08575fd1ac99 /spec
parentbd5550aa0aff81eafd077cd44e6fa3e88015f6e7 (diff)
downloadyuescript-b2cdbc975526b710d23c41af18978afbac516240.tar.gz
yuescript-b2cdbc975526b710d23c41af18978afbac516240.tar.bz2
yuescript-b2cdbc975526b710d23c41af18978afbac516240.zip
fix macro type mismatch issue.
Diffstat (limited to 'spec')
-rw-r--r--spec/inputs/macro.moon40
1 files changed, 38 insertions, 2 deletions
diff --git a/spec/inputs/macro.moon b/spec/inputs/macro.moon
index db03a10..07ac7b3 100644
--- a/spec/inputs/macro.moon
+++ b/spec/inputs/macro.moon
@@ -43,7 +43,7 @@ macro block foreach = (items,action)->
43 #{action}" 43 #{action}"
44 44
45macro expr pipe = (...)-> 45macro expr pipe = (...)->
46 switch select "#",... 46 switch select "#", ...
47 when 0 then return "" 47 when 0 then return ""
48 when 1 then return ... 48 when 1 then return ...
49 ops = {...} 49 ops = {...}
@@ -53,7 +53,7 @@ macro expr pipe = (...)->
53 last = "_#{i}" 53 last = "_#{i}"
54 stmt 54 stmt
55 res = "do 55 res = "do
56#{table.concat stmts,"\n"} 56#{table.concat stmts, "\n"}
57 #{last}" 57 #{last}"
58 $showMacro "pipe", res 58 $showMacro "pipe", res
59 59
@@ -68,3 +68,39 @@ val = $pipe(
68 $reduce(0, _1 + _2) 68 $reduce(0, _1 + _2)
69) 69)
70 70
71macro expr plus = (a, b)-> "#{a} + #{b}"
72
73$plus(1,2)\call 123
74
75macro expr curry = (...)->
76 args = {...}
77 len = #args
78 body = args[len]
79 def = table.concat ["(#{args[i]})->" for i = 1, len - 1]
80 "#{def}\n#{body\gsub "^do\n",""}"
81
82f = $curry x,y,z,do
83 print x,y,z
84
85macro expr get_inner = (var)-> "do
86 a = 1
87 a + 1"
88
89macro expr get_inner_hygienic = (var)-> "(->
90 local a = 1
91 a + 1)!"
92
93do
94 a = 8
95 a = $get_inner!
96 a += $get_inner!
97 print a
98
99do
100 a = 8
101 a = $get_inner_hygienic!
102 a += $get_inner_hygienic!
103 print a
104
105nil
106