-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathstatement.lua
More file actions
248 lines (248 loc) · 6.18 KB
/
Copy pathstatement.lua
File metadata and controls
248 lines (248 loc) · 6.18 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
local ntype
ntype = require("moonscript.types").ntype
local concat, insert
do
local _obj_0 = table
concat, insert = _obj_0.concat, _obj_0.insert
end
local unpack
unpack = require("moonscript.util").unpack
return {
raw = function(self, node)
return self:add(node[2])
end,
declare_constants = function(self, node)
local _list_0 = node[2]
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
if ntype(name) == "ref" then
name = name[2]
end
self:put_name(name, {
const = true,
pos = node[-1]
})
end
return nil
end,
declare = function(self, node)
local names = node[2]
local undeclared = self:declare(names)
if #undeclared > 0 then
do
local _with_0 = self:line("local ")
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #undeclared do
local name = undeclared[_index_0]
_accum_0[_len_0] = self:name(name)
_len_0 = _len_0 + 1
end
return _accum_0
end)(), ", ")
return _with_0
end
end
end,
declare_with_shadows = function(self, node)
local names = node[2]
self:declare(names)
self:put_fresh_names(names)
do
local _with_0 = self:line("local ")
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #names do
local name = names[_index_0]
_accum_0[_len_0] = self:name(name)
_len_0 = _len_0 + 1
end
return _accum_0
end)(), ", ")
return _with_0
end
end,
assign = function(self, node)
local names, values = unpack(node, 2)
local undeclared = self:declare(names)
local declare = "local " .. concat(undeclared, ", ")
local has_fndef = false
local i = 1
while i <= #values do
if ntype(values[i]) == "fndef" then
has_fndef = true
end
i = i + 1
end
do
local _with_0 = self:line()
if #undeclared == #names and not has_fndef then
_with_0:append(declare)
else
if #undeclared > 0 then
self:add(declare, node[-1])
end
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #names do
local name = names[_index_0]
_accum_0[_len_0] = self:value(name)
_len_0 = _len_0 + 1
end
return _accum_0
end)(), ", ")
end
_with_0:append(" = ")
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #values do
local v = values[_index_0]
_accum_0[_len_0] = self:value(v)
_len_0 = _len_0 + 1
end
return _accum_0
end)(), ", ")
return _with_0
end
end,
["return"] = function(self, node)
return self:line("return ", (function()
if node[2] ~= "" then
return self:value(node[2])
end
end)())
end,
["break"] = function(self, node)
return "break"
end,
["if"] = function(self, node)
local cond, block = node[2], node[3]
local root
do
local _with_0 = self:block(self:line("if ", self:value(cond), " then"))
_with_0:stms(block)
root = _with_0
end
local current = root
local add_clause
add_clause = function(clause)
local type = clause[1]
local i = 2
local next
if type == "else" then
next = self:block("else")
else
i = i + 1
next = self:block(self:line("elseif ", self:value(clause[2]), " then"))
end
next:stms(clause[i])
current.next = next
current = next
end
for _index_0 = 4, #node do
local cond = node[_index_0]
add_clause(cond)
end
return root
end,
["repeat"] = function(self, node)
local cond, block = unpack(node, 2)
do
local _with_0 = self:block("repeat", self:line("until ", self:value(cond)))
_with_0:stms(block)
return _with_0
end
end,
["while"] = function(self, node)
local cond, block = unpack(node, 2)
do
local _with_0 = self:block(self:line("while ", self:value(cond), " do"))
_with_0:stms(block)
return _with_0
end
end,
["for"] = function(self, node)
local name, bounds, block = unpack(node, 2)
local loop = self:line("for ", self:name(name), " = ", self:value({
"explist",
unpack(bounds)
}), " do")
do
local _with_0 = self:block(loop)
_with_0:put_fresh_names({
name
})
_with_0:stms(block)
return _with_0
end
end,
foreach = function(self, node)
local names, exps, block = unpack(node, 2)
local loop
do
local _with_0 = self:line()
_with_0:append("for ")
loop = _with_0
end
do
local _with_0 = self:block(loop)
loop:append_list((function()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #names do
local name = names[_index_0]
_accum_0[_len_0] = _with_0:name(name, false)
_len_0 = _len_0 + 1
end
return _accum_0
end)(), ", ")
loop:append(" in ")
loop:append_list((function()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #exps do
local exp = exps[_index_0]
_accum_0[_len_0] = self:value(exp)
_len_0 = _len_0 + 1
end
return _accum_0
end)(), ",")
loop:append(" do")
_with_0:put_fresh_names(names)
_with_0:stms(block)
return _with_0
end
end,
export = function(self, node)
local names = unpack(node, 2)
if type(names) == "string" then
if names == "*" then
self.export_all = true
elseif names == "^" then
self.export_proper = true
end
else
self:declare(names)
end
return nil
end,
run = function(self, code)
code:call(self)
return nil
end,
group = function(self, node)
return self:stms(node[2])
end,
["do"] = function(self, node)
do
local _with_0 = self:block()
_with_0:stms(node[2])
return _with_0
end
end,
noop = function(self) end
}