-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathstatement.lua
More file actions
217 lines (217 loc) · 5.34 KB
/
Copy pathstatement.lua
File metadata and controls
217 lines (217 loc) · 5.34 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
module("moonscript.compile", package.seeall)
local util = require("moonscript.util")
require("moonscript.compile.format")
local dump = require("moonscript.dump")
local reversed = util.reversed
local ntype
do
local _table_0 = require("moonscript.types")
ntype = _table_0.ntype
end
local concat, insert = table.concat, table.insert
line_compile = {
raw = function(self, node)
local _, text = unpack(node)
return self:add(text)
end,
declare = function(self, node)
local _, names = unpack(node)
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 = 0
local _list_0 = names
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = self:name(name)
end
return _accum_0
end)(), ", ")
return _with_0
end
end
end,
assign = function(self, node)
local _, names, values = unpack(node)
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)
end
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 0
local _list_0 = names
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = self:value(name)
end
return _accum_0
end)(), ", ")
end
_with_0:append(" = ")
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 0
local _list_0 = values
for _index_0 = 1, #_list_0 do
local v = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = self:value(v)
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
local _list_0 = node
for _index_0 = 4, #_list_0 do
cond = _list_0[_index_0]
add_clause(cond)
end
return root
end,
["while"] = function(self, node)
local _, cond, block = unpack(node)
local out
if is_non_atomic(cond) then
do
local _with_0 = self:block("while true do")
_with_0:stm({
"if",
{
"not",
cond
},
{
{
"break"
}
}
})
out = _with_0
end
else
out = self:block(self:line("while ", self:value(cond), " do"))
end
out:stms(block)
return out
end,
["for"] = function(self, node)
local _, name, bounds, block = unpack(node)
local loop = self:line("for ", self:name(name), " = ", self:value({
"explist",
unpack(bounds)
}), " do")
do
local _with_0 = self:block(loop)
_with_0:stms(block)
return _with_0
end
end,
foreach = function(self, node)
local _, names, exp, block = unpack(node)
local loop
do
local _with_0 = self:line()
_with_0:append("for ")
_with_0:append_list((function()
local _accum_0 = { }
local _len_0 = 0
local _list_0 = names
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = self:name(name)
end
return _accum_0
end)(), ", ")
_with_0:append(" in ", self:value(exp), " do")
loop = _with_0
end
do
local _with_0 = self:block(loop)
_with_0:stms(block)
return _with_0
end
end,
export = function(self, node)
local _, names = unpack(node)
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
}