diff --git a/moonscript/compile.lua b/moonscript/compile.lua index 72f8ab3..e012842 100644 --- a/moonscript/compile.lua +++ b/moonscript/compile.lua @@ -436,8 +436,8 @@ do local t = ntype(node) return value_compilers[t] ~= nil or t == "value" end, - name = function(self, node) - return self:value(node) + name = function(self, node, ...) + return self:value(node, ...) end, value = function(self, node, ...) node = self.transform.value(node) diff --git a/moonscript/compile.moon b/moonscript/compile.moon index b262644..c289b6a 100644 --- a/moonscript/compile.moon +++ b/moonscript/compile.moon @@ -279,7 +279,8 @@ class Block value_compilers[t] != nil or t == "value" -- line wise compile functions - name: (node) => @value node + name: (node, ...) => @value node, ... + value: (node, ...) => node = @transform.value node action = if type(node) != "table" diff --git a/moonscript/compile/statement.lua b/moonscript/compile/statement.lua index 471364e..4c8ae3e 100644 --- a/moonscript/compile/statement.lua +++ b/moonscript/compile/statement.lua @@ -185,19 +185,23 @@ local statement_compilers = { do local _with_0 = self:line() _with_0:append("for ") - _with_0:append_list((function() + loop = _with_0 + end + do + local _with_0 = self:block(loop) + loop: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) + _accum_0[_len_0] = _with_0:name(name, false) end return _accum_0 end)(), ", ") - _with_0:append(" in ") - _with_0:append_list((function() + loop:append(" in ") + loop:append_list((function() local _accum_0 = { } local _len_0 = 0 local _list_0 = exps @@ -208,11 +212,7 @@ local statement_compilers = { end return _accum_0 end)(), ",") - _with_0:append(" do") - loop = _with_0 - end - do - local _with_0 = self:block(loop) + loop:append(" do") _with_0:declare(names) _with_0:stms(block) return _with_0 diff --git a/moonscript/compile/statement.moon b/moonscript/compile/statement.moon index 4d68701..d390186 100644 --- a/moonscript/compile/statement.moon +++ b/moonscript/compile/statement.moon @@ -100,12 +100,13 @@ statement_compilers = loop = with @line! \append "for " - \append_list [@name name for name in *names], ", " - \append " in " - \append_list [@value exp for exp in *exps], "," - \append " do" with @block loop + loop\append_list [\name name, false for name in *names], ", " + loop\append " in " + loop\append_list [@value exp for exp in *exps], "," + loop\append " do" + \declare names \stms block diff --git a/moonscript/compile/value.lua b/moonscript/compile/value.lua index 3416ccc..7f9c30b 100644 --- a/moonscript/compile/value.lua +++ b/moonscript/compile/value.lua @@ -266,8 +266,8 @@ local value_compilers = { minus = function(self, node) return self:line("-", self:value(node[2])) end, - temp_name = function(self, node) - return node:get_name(self) + temp_name = function(self, node, ...) + return node:get_name(self, ...) end, number = function(self, node) return node[2] diff --git a/moonscript/compile/value.moon b/moonscript/compile/value.moon index 1087244..87e4714 100644 --- a/moonscript/compile/value.moon +++ b/moonscript/compile/value.moon @@ -150,8 +150,8 @@ value_compilers = minus: (node) => @line "-", @value node[2] - temp_name: (node) => - node\get_name self + temp_name: (node, ...) => + node\get_name self, ... number: (node) => node[2] diff --git a/moonscript/transform/names.lua b/moonscript/transform/names.lua index aa28dcd..4eb294d 100644 --- a/moonscript/transform/names.lua +++ b/moonscript/transform/names.lua @@ -48,9 +48,12 @@ local NameProxy do local _parent_0 = nil local _base_0 = { - get_name = function(self, scope) + get_name = function(self, scope, dont_put) + if dont_put == nil then + dont_put = true + end if not self.name then - self.name = scope:free_name(self.prefix, true) + self.name = scope:free_name(self.prefix, dont_put) end return self.name end, diff --git a/moonscript/transform/names.moon b/moonscript/transform/names.moon index f505997..79a2b00 100644 --- a/moonscript/transform/names.moon +++ b/moonscript/transform/names.moon @@ -11,9 +11,9 @@ class NameProxy new: (@prefix) => self[1] = "temp_name" - get_name: (scope) => + get_name: (scope, dont_put=true) => if not @name - @name = scope\free_name @prefix, true + @name = scope\free_name @prefix, dont_put @name chain: (...) =>