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.lua | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'code_obj.lua') diff --git a/code_obj.lua b/code_obj.lua index d51d63f..5be92e6 100644 --- a/code_obj.lua +++ b/code_obj.lua @@ -3,8 +3,6 @@ do local _obj_0 = table insert, remove, concat = _obj_0.insert, _obj_0.remove, _obj_0.concat end -local repr -repr = require('utils').repr local unpack = unpack or table.unpack local LuaCode, NomsuCode, Source do @@ -13,8 +11,8 @@ do __tostring = function(self) return "@" .. tostring(self.filename) .. "[" .. tostring(self.start) .. tostring(self.stop and ':' .. self.stop or '') .. "]" end, - __repr = function(self) - return "Source(" .. tostring(repr(self.filename)) .. ", " .. tostring(self.start) .. tostring(self.stop and ', ' .. self.stop or '') .. ")" + as_lua = function(self) + return "Source(" .. tostring(self.filename:as_lua()) .. ", " .. tostring(self.start) .. tostring(self.stop and ', ' .. self.stop or '') .. ")" end, __eq = function(self, other) return getmetatable(self) == getmetatable(other) and self.filename == other.filename and self.start == other.start and self.stop == other.stop @@ -108,16 +106,16 @@ do end return self.__str end, - __repr = function(self) + as_lua = function(self) return tostring(self.__class.__name) .. "(" .. tostring(concat({ - repr(tostring(self.source)), + tostring(self.source):as_lua(), unpack((function() local _accum_0 = { } local _len_0 = 1 local _list_0 = self.bits for _index_0 = 1, #_list_0 do local b = _list_0[_index_0] - _accum_0[_len_0] = repr(b) + _accum_0[_len_0] = b:as_lua() _len_0 = _len_0 + 1 end return _accum_0 @@ -158,7 +156,7 @@ do b.dirty = error end if type(b) ~= 'string' and not (type(b) == 'table' and b.is_code) then - b = repr(b) + b = b:as_lua() end bits[#bits + 1] = b _continue_0 = true @@ -236,7 +234,7 @@ do b.dirty = error end if type(b) ~= 'string' and not (type(b) == 'table' and b.is_code) then - b = repr(b) + b = b:as_lua() end bits[i] = b end @@ -276,7 +274,7 @@ do local _parent_0 = Code local _base_0 = { __tostring = Code.__tostring, - __repr = Code.__repr, + as_lua = Code.as_lua, __len = Code.__len, add_free_vars = function(self, vars) if not (#vars > 0) then @@ -469,7 +467,7 @@ do local _parent_0 = Code local _base_0 = { __tostring = Code.__tostring, - __repr = Code.__repr, + as_lua = Code.as_lua, __len = Code.__len } _base_0.__index = _base_0 -- 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.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'code_obj.lua') diff --git a/code_obj.lua b/code_obj.lua index 5be92e6..577eaf3 100644 --- a/code_obj.lua +++ b/code_obj.lua @@ -355,7 +355,7 @@ do local _list_1 = self.bits for _index_0 = 1, #_list_1 do local bit = _list_1[_index_0] - if bit.__class == LuaCode then + if not (type(bit) == 'string') then gather_from(bit) end end -- cgit v1.2.3 From b7e768a2f826f6643e47b35272dbb35136d489b6 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 28 Sep 2018 22:15:24 -0700 Subject: Rebuild. --- code_obj.lua | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'code_obj.lua') diff --git a/code_obj.lua b/code_obj.lua index 577eaf3..a8d7adf 100644 --- a/code_obj.lua +++ b/code_obj.lua @@ -78,7 +78,7 @@ do local _class_0 local _base_0 = { is_code = true, - __tostring = function(self) + as_smext = function(self) if self.__str == nil then local buff, indent = { }, 0 local match, gsub, rep @@ -95,7 +95,7 @@ do end end else - b = tostring(b) + b = b:as_smext() if indent > 0 then b = gsub(b, "\n", "\n" .. rep(" ", indent)) end @@ -106,6 +106,9 @@ do end return self.__str end, + __tostring = function(self) + return self:as_smext() + end, as_lua = function(self) return tostring(self.__class.__name) .. "(" .. tostring(concat({ tostring(self.source):as_lua(), @@ -123,13 +126,13 @@ do }, ", ")) .. ")" end, __len = function(self) - return #tostring(self) + return #self:as_smext() end, match = function(self, ...) - return tostring(self):match(...) + return self:as_smext():match(...) end, gmatch = function(self, ...) - return tostring(self):gmatch(...) + return self:as_smext():gmatch(...) end, dirty = function(self) self.__str = nil @@ -155,9 +158,6 @@ do if b.is_code then b.dirty = error end - if type(b) ~= 'string' and not (type(b) == 'table' and b.is_code) then - b = b:as_lua() - end bits[#bits + 1] = b _continue_0 = true until true @@ -169,7 +169,7 @@ do end, trailing_line_len = function(self) if self._trailing_line_len == nil then - self._trailing_line_len = #tostring(self):match("[^\n]*$") + self._trailing_line_len = #self:as_smext():match("[^\n]*$") end return self._trailing_line_len end, @@ -212,7 +212,9 @@ do if b.is_code then b.dirty = error end - b = tostring(b) + if not (type(b) == 'string') then + b = b:as_smext() + end local line = match(b, "\n([^\n]*)$") if line then line_len = #line @@ -233,9 +235,6 @@ do if b.is_code then b.dirty = error end - if type(b) ~= 'string' and not (type(b) == 'table' and b.is_code) then - b = b:as_lua() - end bits[i] = b end return self:dirty() @@ -253,7 +252,6 @@ do if type(self.source) == 'string' then self.source = Source:from_string(self.source) end - assert(self.source and Source:is_instance(self.source), "Source has the wrong type") return self:append(...) end, __base = _base_0, @@ -402,8 +400,9 @@ do end else walk(b, pos) + b = b:as_smext() end - pos = pos + #tostring(b) + pos = pos + #b end end walk(self, 1) -- 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.lua | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'code_obj.lua') diff --git a/code_obj.lua b/code_obj.lua index a8d7adf..b5213c9 100644 --- a/code_obj.lua +++ b/code_obj.lua @@ -78,7 +78,7 @@ do local _class_0 local _base_0 = { is_code = true, - as_smext = function(self) + text = function(self) if self.__str == nil then local buff, indent = { }, 0 local match, gsub, rep @@ -95,7 +95,7 @@ do end end else - b = b:as_smext() + b = b:text() if indent > 0 then b = gsub(b, "\n", "\n" .. rep(" ", indent)) end @@ -107,7 +107,7 @@ do return self.__str end, __tostring = function(self) - return self:as_smext() + return self:text() end, as_lua = function(self) return tostring(self.__class.__name) .. "(" .. tostring(concat({ @@ -126,13 +126,13 @@ do }, ", ")) .. ")" end, __len = function(self) - return #self:as_smext() + return #self:text() end, match = function(self, ...) - return self:as_smext():match(...) + return self:text():match(...) end, gmatch = function(self, ...) - return self:as_smext():gmatch(...) + return self:text():gmatch(...) end, dirty = function(self) self.__str = nil @@ -169,7 +169,7 @@ do end, trailing_line_len = function(self) if self._trailing_line_len == nil then - self._trailing_line_len = #self:as_smext():match("[^\n]*$") + self._trailing_line_len = #self:text():match("[^\n]*$") end return self._trailing_line_len end, @@ -213,7 +213,7 @@ do b.dirty = error end if not (type(b) == 'string') then - b = b:as_smext() + b = b:text() end local line = match(b, "\n([^\n]*)$") if line then @@ -400,7 +400,7 @@ do end else walk(b, pos) - b = b:as_smext() + b = b:text() end pos = pos + #b end @@ -502,12 +502,7 @@ do end NomsuCode = _class_0 end -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 = Code, NomsuCode = NomsuCode, -- cgit v1.2.3