mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
new assign compile
This commit is contained in:
parent
d8ff74ccba
commit
2e8c33ad23
@ -326,8 +326,8 @@ local compiler_index = {
|
|||||||
local ln = node[i]
|
local ln = node[i]
|
||||||
local value = self:stm(ln, return_value and i == len)
|
local value = self:stm(ln, return_value and i == len)
|
||||||
if type(value) == "table" then
|
if type(value) == "table" then
|
||||||
for _, v in value do
|
for _, v in ipairs(value) do
|
||||||
table.insert(lines, value)
|
table.insert(lines, v)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(lines, value)
|
table.insert(lines, value)
|
||||||
@ -386,40 +386,28 @@ local compiler_index = {
|
|||||||
local _, names, values = unpack(node)
|
local _, names, values = unpack(node)
|
||||||
local assigns, current = {}, nil
|
local assigns, current = {}, nil
|
||||||
|
|
||||||
local function append(t, name, value)
|
-- declare undeclared names
|
||||||
if not current or t ~= current[1] then
|
local undeclared_names = {}
|
||||||
current = {t, {name}, {value}}
|
for _, name in ipairs(names) do
|
||||||
table.insert(assigns, current)
|
if type(name) == "string" and not self:has_name(name) then
|
||||||
else
|
table.insert(undeclared_names, name)
|
||||||
table.insert(current[2], name)
|
self:put_name(name)
|
||||||
table.insert(current[3], value)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for i, assignee in ipairs(names) do
|
|
||||||
local name_value = self:value(assignee)
|
|
||||||
local value = self:value(values[i])
|
|
||||||
|
|
||||||
if ntype(assignee) == "chain" or self:has_name(assignee) then
|
|
||||||
append("non-local", name_value, value)
|
|
||||||
else
|
|
||||||
append("local", name_value, value)
|
|
||||||
end
|
|
||||||
|
|
||||||
if type(assignee) == "string" then
|
|
||||||
self:put_name(assignee)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local lines = {}
|
local lines = {}
|
||||||
for _, group in ipairs(assigns) do
|
local num_undeclared = #undeclared_names
|
||||||
local t, names, values = unpack(group)
|
if num_undeclared > 0 and num_undeclared ~= #names then
|
||||||
if #values == 0 then values = {"nil"} end
|
table.insert(lines, "local "..table.concat(undeclared_names, ", "))
|
||||||
local line = table.concat(names, ", ").." = "..table.concat(values, ", ")
|
|
||||||
table.insert(lines, t == "local" and "local "..line or line)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local ln = self:name_list(names).. " = "..table.concat(self:values(values), ", ")
|
||||||
|
|
||||||
|
if num_undeclared == #names then
|
||||||
|
ln = "local "..ln
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(lines, ln)
|
||||||
return self:pretty(lines)
|
return self:pretty(lines)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
@ -3,11 +3,10 @@ local _ = function()
|
|||||||
return function(hi)
|
return function(hi)
|
||||||
local d = 100
|
local d = 100
|
||||||
hi = 1021
|
hi = 1021
|
||||||
local a, b, c = 1, 2, 3
|
local a, b, c
|
||||||
d = 4
|
a, b, c, d = 1, 2, 3, 4
|
||||||
hello[232], (5 + 5)[121] = 100, 200
|
local hello
|
||||||
local hello = 300
|
hello[232], (5 + 5)[121], hello, x[99] = 100, 200, 300
|
||||||
x[99] = nil
|
|
||||||
joop = 12
|
joop = 12
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,8 +12,8 @@ do
|
|||||||
master = _table_0.master
|
master = _table_0.master
|
||||||
ghost = moon.bind(_table_0.ghost, _table_0)
|
ghost = moon.bind(_table_0.ghost, _table_0)
|
||||||
end
|
end
|
||||||
a = 3434
|
local yumm
|
||||||
local yumm = "hello"
|
a, yumm = 3434, "hello"
|
||||||
local _table_0 = 232
|
local _table_0 = 232
|
||||||
local something
|
local something
|
||||||
do
|
do
|
||||||
|
@ -12,11 +12,11 @@ end)
|
|||||||
local h = function() return hi end
|
local h = function() return hi end
|
||||||
eat(function() end, world)
|
eat(function() end, world)
|
||||||
local a = 1 + 2 * 3 / 6
|
local a = 1 + 2 * 3 / 6
|
||||||
a = another
|
local bunch, go, here
|
||||||
local bunch, go, here = world
|
a, bunch, go, here = another, world
|
||||||
func(arg1, arg2, another, arg3)
|
func(arg1, arg2, another, arg3)
|
||||||
here = function() end
|
local we
|
||||||
local we = yeah
|
here, we = function() end, yeah
|
||||||
local the, different = function() return approach end, yeah
|
local the, different = function() return approach end, yeah
|
||||||
dad()
|
dad()
|
||||||
dad(lord)
|
dad(lord)
|
||||||
@ -29,8 +29,8 @@ hello(world(what(are(you(doing(here))))))
|
|||||||
what(the)[3243](world, yeck(heck))
|
what(the)[3243](world, yeck(heck))
|
||||||
hairy[hands][are](gross)(okay(okay[world]));
|
hairy[hands][are](gross)(okay(okay[world]));
|
||||||
(get[something] + 5)[years]
|
(get[something] + 5)[years]
|
||||||
local i = 200
|
local i
|
||||||
x = 300
|
i, x = 200, 300
|
||||||
local yeah = (1 + 5) * 3
|
local yeah = (1 + 5) * 3
|
||||||
yeah = ((1 + 5) * 3) / 2
|
yeah = ((1 + 5) * 3) / 2
|
||||||
yeah = ((1 + 5) * 3) / 2 + i % 100
|
yeah = ((1 + 5) * 3) / 2 + i % 100
|
||||||
|
Loading…
Reference in New Issue
Block a user