diff options
-rw-r--r-- | spec/inputs/global.yue | 7 | ||||
-rw-r--r-- | spec/outputs/5.1/attrib.lua | 192 | ||||
-rw-r--r-- | spec/outputs/global.lua | 6 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 6 |
4 files changed, 184 insertions, 27 deletions
diff --git a/spec/inputs/global.yue b/spec/inputs/global.yue index 59cf764..ce1cc15 100644 --- a/spec/inputs/global.yue +++ b/spec/inputs/global.yue | |||
@@ -75,3 +75,10 @@ do | |||
75 | 75 | ||
76 | h = 100 | 76 | h = 100 |
77 | 77 | ||
78 | do | ||
79 | global x = y | ||
80 | global ^ | ||
81 | foobar = "all lowercase" | ||
82 | FooBar = "pascal case" | ||
83 | FOOBAR = "all uppercase" | ||
84 | |||
diff --git a/spec/outputs/5.1/attrib.lua b/spec/outputs/5.1/attrib.lua index dc1285c..a156e84 100644 --- a/spec/outputs/5.1/attrib.lua +++ b/spec/outputs/5.1/attrib.lua | |||
@@ -5,12 +5,36 @@ do | |||
5 | return print("closed") | 5 | return print("closed") |
6 | end | 6 | end |
7 | }) | 7 | }) |
8 | local _close_0 = assert(getmetatable(a).__close) | 8 | local _close_0 |
9 | local _close_1 = assert(getmetatable(b).__close); | 9 | if (function() |
10 | local _val_0 = type(a) | ||
11 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
12 | end)() then | ||
13 | _close_0 = assert(getmetatable(a) and getmetatable(a).__close, "variable 'a' got a non-closable value") | ||
14 | elseif a == nil then | ||
15 | _close_0 = nil | ||
16 | else | ||
17 | _close_0 = error("variable 'a' got a non-closable value") | ||
18 | end | ||
19 | local _close_1 | ||
20 | if (function() | ||
21 | local _val_0 = type(b) | ||
22 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
23 | end)() then | ||
24 | _close_1 = assert(getmetatable(b) and getmetatable(b).__close, "variable 'b' got a non-closable value") | ||
25 | elseif b == nil then | ||
26 | _close_1 = nil | ||
27 | else | ||
28 | _close_1 = error("variable 'b' got a non-closable value") | ||
29 | end | ||
10 | (function(_arg_0, ...) | 30 | (function(_arg_0, ...) |
11 | local _ok_0 = _arg_0 | 31 | local _ok_0 = _arg_0 |
12 | _close_1(b) | 32 | if _close_1 ~= nil then |
13 | _close_0(a) | 33 | _close_1(b) |
34 | end | ||
35 | if _close_0 ~= nil then | ||
36 | _close_0(a) | ||
37 | end | ||
14 | if _ok_0 then | 38 | if _ok_0 then |
15 | return ... | 39 | return ... |
16 | else | 40 | else |
@@ -53,10 +77,22 @@ do | |||
53 | __close = function(self) end | 77 | __close = function(self) end |
54 | }) | 78 | }) |
55 | end | 79 | end |
56 | local _close_0 = assert(getmetatable(v).__close); | 80 | local _close_0 |
81 | if (function() | ||
82 | local _val_0 = type(v) | ||
83 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
84 | end)() then | ||
85 | _close_0 = assert(getmetatable(v) and getmetatable(v).__close, "variable 'v' got a non-closable value") | ||
86 | elseif v == nil then | ||
87 | _close_0 = nil | ||
88 | else | ||
89 | _close_0 = error("variable 'v' got a non-closable value") | ||
90 | end | ||
57 | (function(_arg_0, ...) | 91 | (function(_arg_0, ...) |
58 | local _ok_0 = _arg_0 | 92 | local _ok_0 = _arg_0 |
59 | _close_0(v) | 93 | if _close_0 ~= nil then |
94 | _close_0(v) | ||
95 | end | ||
60 | if _ok_0 then | 96 | if _ok_0 then |
61 | return ... | 97 | return ... |
62 | else | 98 | else |
@@ -69,10 +105,22 @@ do | |||
69 | _with_0:write("Hello") | 105 | _with_0:write("Hello") |
70 | f = _with_0 | 106 | f = _with_0 |
71 | end | 107 | end |
72 | local _close_1 = assert(getmetatable(f).__close) | 108 | local _close_1 |
109 | if (function() | ||
110 | local _val_0 = type(f) | ||
111 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
112 | end)() then | ||
113 | _close_1 = assert(getmetatable(f) and getmetatable(f).__close, "variable 'f' got a non-closable value") | ||
114 | elseif f == nil then | ||
115 | _close_1 = nil | ||
116 | else | ||
117 | _close_1 = error("variable 'f' got a non-closable value") | ||
118 | end | ||
73 | return (function(_arg_0, ...) | 119 | return (function(_arg_0, ...) |
74 | local _ok_0 = _arg_0 | 120 | local _ok_0 = _arg_0 |
75 | _close_1(f) | 121 | if _close_1 ~= nil then |
122 | _close_1(f) | ||
123 | end | ||
76 | if _ok_0 then | 124 | if _ok_0 then |
77 | return ... | 125 | return ... |
78 | else | 126 | else |
@@ -92,10 +140,22 @@ do | |||
92 | b = 1 | 140 | b = 1 |
93 | end | 141 | end |
94 | end | 142 | end |
95 | local _close_0 = assert(getmetatable(b).__close); | 143 | local _close_0 |
144 | if (function() | ||
145 | local _val_0 = type(b) | ||
146 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
147 | end)() then | ||
148 | _close_0 = assert(getmetatable(b) and getmetatable(b).__close, "variable 'b' got a non-closable value") | ||
149 | elseif b == nil then | ||
150 | _close_0 = nil | ||
151 | else | ||
152 | _close_0 = error("variable 'b' got a non-closable value") | ||
153 | end | ||
96 | (function(_arg_0, ...) | 154 | (function(_arg_0, ...) |
97 | local _ok_0 = _arg_0 | 155 | local _ok_0 = _arg_0 |
98 | _close_0(b) | 156 | if _close_0 ~= nil then |
157 | _close_0(b) | ||
158 | end | ||
99 | if _ok_0 then | 159 | if _ok_0 then |
100 | return ... | 160 | return ... |
101 | else | 161 | else |
@@ -121,10 +181,22 @@ do | |||
121 | value = value | 181 | value = value |
122 | } | 182 | } |
123 | end | 183 | end |
124 | local _close_1 = assert(getmetatable(d).__close) | 184 | local _close_1 |
185 | if (function() | ||
186 | local _val_0 = type(d) | ||
187 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
188 | end)() then | ||
189 | _close_1 = assert(getmetatable(d) and getmetatable(d).__close, "variable 'd' got a non-closable value") | ||
190 | elseif d == nil then | ||
191 | _close_1 = nil | ||
192 | else | ||
193 | _close_1 = error("variable 'd' got a non-closable value") | ||
194 | end | ||
125 | return (function(_arg_0, ...) | 195 | return (function(_arg_0, ...) |
126 | local _ok_0 = _arg_0 | 196 | local _ok_0 = _arg_0 |
127 | _close_1(d) | 197 | if _close_1 ~= nil then |
198 | _close_1(d) | ||
199 | end | ||
128 | if _ok_0 then | 200 | if _ok_0 then |
129 | return ... | 201 | return ... |
130 | else | 202 | else |
@@ -140,10 +212,22 @@ do | |||
140 | _with_0:write("Hello") | 212 | _with_0:write("Hello") |
141 | _ = _with_0 | 213 | _ = _with_0 |
142 | end | 214 | end |
143 | local _close_0 = assert(getmetatable(_).__close); | 215 | local _close_0 |
216 | if (function() | ||
217 | local _val_0 = type(_) | ||
218 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
219 | end)() then | ||
220 | _close_0 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
221 | elseif _ == nil then | ||
222 | _close_0 = nil | ||
223 | else | ||
224 | _close_0 = error("variable '_' got a non-closable value") | ||
225 | end | ||
144 | (function(_arg_0, ...) | 226 | (function(_arg_0, ...) |
145 | local _ok_0 = _arg_0 | 227 | local _ok_0 = _arg_0 |
146 | _close_0(_) | 228 | if _close_0 ~= nil then |
229 | _close_0(_) | ||
230 | end | ||
147 | if _ok_0 then | 231 | if _ok_0 then |
148 | return ... | 232 | return ... |
149 | else | 233 | else |
@@ -155,10 +239,22 @@ do | |||
155 | return print("second") | 239 | return print("second") |
156 | end | 240 | end |
157 | }) | 241 | }) |
158 | local _close_1 = assert(getmetatable(_).__close) | 242 | local _close_1 |
243 | if (function() | ||
244 | local _val_0 = type(_) | ||
245 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
246 | end)() then | ||
247 | _close_1 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
248 | elseif _ == nil then | ||
249 | _close_1 = nil | ||
250 | else | ||
251 | _close_1 = error("variable '_' got a non-closable value") | ||
252 | end | ||
159 | return (function(_arg_0, ...) | 253 | return (function(_arg_0, ...) |
160 | local _ok_0 = _arg_0 | 254 | local _ok_0 = _arg_0 |
161 | _close_1(_) | 255 | if _close_1 ~= nil then |
256 | _close_1(_) | ||
257 | end | ||
162 | if _ok_0 then | 258 | if _ok_0 then |
163 | return ... | 259 | return ... |
164 | else | 260 | else |
@@ -170,10 +266,22 @@ do | |||
170 | return print("first") | 266 | return print("first") |
171 | end | 267 | end |
172 | }) | 268 | }) |
173 | local _close_2 = assert(getmetatable(_).__close) | 269 | local _close_2 |
270 | if (function() | ||
271 | local _val_0 = type(_) | ||
272 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
273 | end)() then | ||
274 | _close_2 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
275 | elseif _ == nil then | ||
276 | _close_2 = nil | ||
277 | else | ||
278 | _close_2 = error("variable '_' got a non-closable value") | ||
279 | end | ||
174 | return (function(_arg_0, ...) | 280 | return (function(_arg_0, ...) |
175 | local _ok_0 = _arg_0 | 281 | local _ok_0 = _arg_0 |
176 | _close_2(_) | 282 | if _close_2 ~= nil then |
283 | _close_2(_) | ||
284 | end | ||
177 | if _ok_0 then | 285 | if _ok_0 then |
178 | return ... | 286 | return ... |
179 | else | 287 | else |
@@ -200,10 +308,22 @@ do | |||
200 | local _ = def(function() | 308 | local _ = def(function() |
201 | return print(3) | 309 | return print(3) |
202 | end) | 310 | end) |
203 | local _close_0 = assert(getmetatable(_).__close) | 311 | local _close_0 |
312 | if (function() | ||
313 | local _val_0 = type(_) | ||
314 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
315 | end)() then | ||
316 | _close_0 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
317 | elseif _ == nil then | ||
318 | _close_0 = nil | ||
319 | else | ||
320 | _close_0 = error("variable '_' got a non-closable value") | ||
321 | end | ||
204 | return (function(_arg_0, ...) | 322 | return (function(_arg_0, ...) |
205 | local _ok_0 = _arg_0 | 323 | local _ok_0 = _arg_0 |
206 | _close_0(_) | 324 | if _close_0 ~= nil then |
325 | _close_0(_) | ||
326 | end | ||
207 | if _ok_0 then | 327 | if _ok_0 then |
208 | return ... | 328 | return ... |
209 | else | 329 | else |
@@ -213,10 +333,22 @@ do | |||
213 | local _ = def(function() | 333 | local _ = def(function() |
214 | return print(2) | 334 | return print(2) |
215 | end) | 335 | end) |
216 | local _close_1 = assert(getmetatable(_).__close) | 336 | local _close_1 |
337 | if (function() | ||
338 | local _val_0 = type(_) | ||
339 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
340 | end)() then | ||
341 | _close_1 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
342 | elseif _ == nil then | ||
343 | _close_1 = nil | ||
344 | else | ||
345 | _close_1 = error("variable '_' got a non-closable value") | ||
346 | end | ||
217 | return (function(_arg_0, ...) | 347 | return (function(_arg_0, ...) |
218 | local _ok_0 = _arg_0 | 348 | local _ok_0 = _arg_0 |
219 | _close_1(_) | 349 | if _close_1 ~= nil then |
350 | _close_1(_) | ||
351 | end | ||
220 | if _ok_0 then | 352 | if _ok_0 then |
221 | return ... | 353 | return ... |
222 | else | 354 | else |
@@ -226,10 +358,22 @@ do | |||
226 | local _ = def(function() | 358 | local _ = def(function() |
227 | return print(1) | 359 | return print(1) |
228 | end) | 360 | end) |
229 | local _close_2 = assert(getmetatable(_).__close) | 361 | local _close_2 |
362 | if (function() | ||
363 | local _val_0 = type(_) | ||
364 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
365 | end)() then | ||
366 | _close_2 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
367 | elseif _ == nil then | ||
368 | _close_2 = nil | ||
369 | else | ||
370 | _close_2 = error("variable '_' got a non-closable value") | ||
371 | end | ||
230 | return (function(_arg_0, ...) | 372 | return (function(_arg_0, ...) |
231 | local _ok_0 = _arg_0 | 373 | local _ok_0 = _arg_0 |
232 | _close_2(_) | 374 | if _close_2 ~= nil then |
375 | _close_2(_) | ||
376 | end | ||
233 | if _ok_0 then | 377 | if _ok_0 then |
234 | return ... | 378 | return ... |
235 | else | 379 | else |
diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua index 7e74387..54a21a9 100644 --- a/spec/outputs/global.lua +++ b/spec/outputs/global.lua | |||
@@ -87,3 +87,9 @@ do | |||
87 | end | 87 | end |
88 | local h = 100 | 88 | local h = 100 |
89 | end | 89 | end |
90 | do | ||
91 | x = y | ||
92 | local foobar = "all lowercase" | ||
93 | FooBar = "pascal case" | ||
94 | FOOBAR = "all uppercase" | ||
95 | end | ||
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index e3c9d31..a2a1864 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
75 | "close"s // Lua 5.4 | 75 | "close"s // Lua 5.4 |
76 | }; | 76 | }; |
77 | 77 | ||
78 | const std::string_view version = "0.27.2"sv; | 78 | const std::string_view version = "0.27.3"sv; |
79 | const std::string_view extension = "yue"sv; | 79 | const std::string_view extension = "yue"sv; |
80 | 80 | ||
81 | class CompileError : public std::logic_error { | 81 | class CompileError : public std::logic_error { |
@@ -4795,8 +4795,8 @@ private: | |||
4795 | auto varName = variableToString(ast_to<Variable_t>(var)); | 4795 | auto varName = variableToString(ast_to<Variable_t>(var)); |
4796 | auto closeVar = getUnusedName("_close_"sv); | 4796 | auto closeVar = getUnusedName("_close_"sv); |
4797 | addToScope(closeVar); | 4797 | addToScope(closeVar); |
4798 | getCloses.push_back(closeVar + "=assert "s + varName + ".<close>"s); | 4798 | getCloses.push_back(closeVar + "=if type("s + varName + ") in ['table', 'userdata'] then assert "s + varName + ".<> and "s + varName +".<close>, \""s + "variable '"s + varName + "' got a non-closable value\" elseif "s + varName + " == nil then nil else error \""s + "variable '"s + varName + "' got a non-closable value\""); |
4799 | doCloses.push_front(closeVar + ' ' + varName); | 4799 | doCloses.push_front(closeVar + "? "s + varName); |
4800 | } | 4800 | } |
4801 | popScope(); | 4801 | popScope(); |
4802 | auto okVar = getUnusedName("_ok_"sv); | 4802 | auto okVar = getUnusedName("_ok_"sv); |