From 79d4bd5125de7ff220fbf8a8a5493d437ed16963 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 18 Sep 2018 19:48:58 -0700 Subject: Got rid of repr() use and replaced with :as_lua() or :as_nomsu() in as many places as possible. --- code_obj.moon | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'code_obj.moon') diff --git a/code_obj.moon b/code_obj.moon index bd53c5b..4e70784 100644 --- a/code_obj.moon +++ b/code_obj.moon @@ -2,7 +2,6 @@ -- build up generated code, while keeping track of where it came from, and managing -- indentation levels. {:insert, :remove, :concat} = table -{:repr} = require 'utils' unpack or= table.unpack local LuaCode, NomsuCode, Source @@ -19,7 +18,7 @@ class Source __tostring: => "@#{@filename}[#{@start}#{@stop and ':'..@stop or ''}]" - __repr: => "Source(#{repr @filename}, #{@start}#{@stop and ', '..@stop or ''})" + as_lua: => "Source(#{@filename\as_lua!}, #{@start}#{@stop and ', '..@stop or ''})" __eq: (other)=> getmetatable(@) == getmetatable(other) and @filename == other.filename and @start == other.start and @stop == other.stop @@ -67,8 +66,8 @@ class Code @__str = concat(buff, "") return @__str - __repr: => - "#{@__class.__name}(#{concat {repr(tostring(@source)), unpack([repr(b) for b in *@bits])}, ", "})" + as_lua: => + "#{@__class.__name}(#{concat {tostring(@source)\as_lua!, unpack([b\as_lua! for b in *@bits])}, ", "})" __len: => #tostring(@) @@ -93,7 +92,7 @@ class Code if b == '' then continue b.dirty = error if b.is_code if type(b) != 'string' and not (type(b) == 'table' and b.is_code) - b = repr(b) + b = b\as_lua! bits[#bits+1] = b @dirty! @@ -148,7 +147,7 @@ class Code b = select(i, ...) b.dirty = error if b.is_code if type(b) != 'string' and not (type(b) == 'table' and b.is_code) - b = repr(b) + b = b\as_lua! bits[i] = b @dirty! @@ -158,7 +157,7 @@ class Code class LuaCode extends Code __tostring: Code.__tostring - __repr: Code.__repr + as_lua: Code.as_lua __len: Code.__len new: (...)=> super ... @@ -253,7 +252,7 @@ class LuaCode extends Code class NomsuCode extends Code __tostring: Code.__tostring - __repr: Code.__repr + as_lua: Code.as_lua __len: Code.__len Code.__base.append_1 = assert Code.__base.append -- cgit v1.2.3 From 258527750cea3372a932552e0f18cd48e132def5 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 28 Sep 2018 18:35:12 -0700 Subject: Slightly more robust. --- code_obj.moon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'code_obj.moon') diff --git a/code_obj.moon b/code_obj.moon index 4e70784..07b7618 100644 --- a/code_obj.moon +++ b/code_obj.moon @@ -207,7 +207,7 @@ class LuaCode extends Code seen[var] = true to_declare[#to_declare+1] = var for bit in *@bits - if bit.__class == LuaCode + unless type(bit) == 'string' gather_from bit gather_from self if #to_declare > 0 -- cgit v1.2.3 From 63d8b1cd3f34b15bf86210b99209e8b57e7019bb Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 28 Sep 2018 22:15:06 -0700 Subject: Fully working, I think? (with a lot of shims) --- code_obj.moon | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'code_obj.moon') diff --git a/code_obj.moon b/code_obj.moon index 07b7618..3e43b16 100644 --- a/code_obj.moon +++ b/code_obj.moon @@ -47,10 +47,10 @@ class Code @bits = {} if type(@source) == 'string' @source = Source\from_string(@source) - assert(@source and Source\is_instance(@source), "Source has the wrong type") + --assert(@source and Source\is_instance(@source), "Source has the wrong type") @append(...) - __tostring: => + as_smext: => if @__str == nil buff, indent = {}, 0 {:match, :gsub, :rep} = string @@ -59,21 +59,23 @@ class Code if spaces = match(b, "\n([ ]*)[^\n]*$") indent = #spaces else - b = tostring(b) + b = b\as_smext! if indent > 0 b = gsub(b, "\n", "\n"..rep(" ", indent)) buff[#buff+1] = b @__str = concat(buff, "") return @__str + __tostring: => @as_smext! + as_lua: => "#{@__class.__name}(#{concat {tostring(@source)\as_lua!, unpack([b\as_lua! for b in *@bits])}, ", "})" - __len: => #tostring(@) + __len: => #@as_smext! - match: (...)=> tostring(@)\match(...) + match: (...)=> @as_smext!\match(...) - gmatch: (...)=> tostring(@)\gmatch(...) + gmatch: (...)=> @as_smext!\gmatch(...) dirty: => @__str = nil @@ -91,14 +93,14 @@ class Code assert(not Source\is_instance(b), "code bit is a Source") if b == '' then continue b.dirty = error if b.is_code - if type(b) != 'string' and not (type(b) == 'table' and b.is_code) - b = b\as_lua! + --if type(b) != 'string' and not (type(b) == 'table' and b.is_code) + -- b = b\as_lua! bits[#bits+1] = b @dirty! trailing_line_len: => if @_trailing_line_len == nil - @_trailing_line_len = #tostring(@)\match("[^\n]*$") + @_trailing_line_len = #@as_smext!\match("[^\n]*$") return @_trailing_line_len is_multiline: => @@ -130,7 +132,8 @@ class Code bits[#bits+1] = joiner bits[#bits+1] = b b.dirty = error if b.is_code - b = tostring(b) + unless type(b) == 'string' + b = b\as_smext! line = match(b, "\n([^\n]*)$") if line line_len = #line @@ -146,8 +149,8 @@ class Code for i=1,n b = select(i, ...) b.dirty = error if b.is_code - if type(b) != 'string' and not (type(b) == 'table' and b.is_code) - b = b\as_lua! + --if type(b) != 'string' and not (type(b) == 'table' and b.is_code) + -- b = b\as_lua! bits[i] = b @dirty! @@ -237,7 +240,8 @@ class LuaCode extends Code nomsu_to_lua[lua.source.start] = pos else walk b, pos - pos += #tostring(b) + b = b\as_smext! + pos += #b walk self, 1 return { nomsu_filename:@source.filename -- cgit v1.2.3 From 307dea18815ba4a06a3098edb170d7ad90708815 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 2 Nov 2018 14:38:24 -0700 Subject: Changed stub convention to (foo 1 baz 2) -> foo_1_baz instead of foo_1_baz_2, removed "smext", made some cleanup changes. --- code_obj.moon | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'code_obj.moon') diff --git a/code_obj.moon b/code_obj.moon index 3e43b16..22969a4 100644 --- a/code_obj.moon +++ b/code_obj.moon @@ -50,7 +50,7 @@ class Code --assert(@source and Source\is_instance(@source), "Source has the wrong type") @append(...) - as_smext: => + text: => if @__str == nil buff, indent = {}, 0 {:match, :gsub, :rep} = string @@ -59,23 +59,23 @@ class Code if spaces = match(b, "\n([ ]*)[^\n]*$") indent = #spaces else - b = b\as_smext! + b = b\text! if indent > 0 b = gsub(b, "\n", "\n"..rep(" ", indent)) buff[#buff+1] = b @__str = concat(buff, "") return @__str - __tostring: => @as_smext! + __tostring: => @text! as_lua: => "#{@__class.__name}(#{concat {tostring(@source)\as_lua!, unpack([b\as_lua! for b in *@bits])}, ", "})" - __len: => #@as_smext! + __len: => #@text! - match: (...)=> @as_smext!\match(...) + match: (...)=> @text!\match(...) - gmatch: (...)=> @as_smext!\gmatch(...) + gmatch: (...)=> @text!\gmatch(...) dirty: => @__str = nil @@ -100,7 +100,7 @@ class Code trailing_line_len: => if @_trailing_line_len == nil - @_trailing_line_len = #@as_smext!\match("[^\n]*$") + @_trailing_line_len = #@text!\match("[^\n]*$") return @_trailing_line_len is_multiline: => @@ -133,7 +133,7 @@ class Code bits[#bits+1] = b b.dirty = error if b.is_code unless type(b) == 'string' - b = b\as_smext! + b = b\text! line = match(b, "\n([^\n]*)$") if line line_len = #line @@ -240,7 +240,7 @@ class LuaCode extends Code nomsu_to_lua[lua.source.start] = pos else walk b, pos - b = b\as_smext! + b = b\text! pos += #b walk self, 1 return { @@ -259,11 +259,6 @@ class NomsuCode extends Code as_lua: Code.as_lua __len: Code.__len -Code.__base.append_1 = assert Code.__base.append -Code.__base.append_1_joined_by_2 = assert Code.__base.concat_append -Code.__base.prepend_1 = assert Code.__base.prepend -LuaCode.__base.declare_locals_1 = assert LuaCode.__base.declare_locals -LuaCode.__base.remove_free_vars_1 = assert LuaCode.__base.remove_free_vars -LuaCode.__base.add_free_vars_1 = assert LuaCode.__base.add_free_vars +Code.__base.add_1_joined_with = assert Code.__base.concat_append return {:Code, :NomsuCode, :LuaCode, :Source} -- cgit v1.2.3