diff --git a/nomsu.lua b/nomsu.lua index b15e90b..17b40fe 100644 --- a/nomsu.lua +++ b/nomsu.lua @@ -38,18 +38,6 @@ local Tuple = immutable(nil, { end)(), ", ")) .. ")" end }) -local cached -cached = function(fn) - local cache = setmetatable({ }, { - __mode = "k" - }) - return function(self, arg) - if not (cache[arg]) then - cache[arg] = fn(self, arg) - end - return cache[arg] - end -end do local STRING_METATABLE = getmetatable("") STRING_METATABLE.__add = function(self, other) @@ -363,7 +351,7 @@ do end return code:gsub("\n", "\n" .. (" "):rep(levels)) end, - get_line_number = cached(function(self, tree) + get_line_number = function(self, tree) local metadata = self.tree_metadata[tree] if not (metadata) then return "" @@ -381,7 +369,7 @@ do last_line = last_line + 1 end return tostring(metadata.filename) .. ":" .. tostring(first_line) - end), + end, get_source_code = function(self, tree) local metadata = self.tree_metadata[tree] if not (metadata) then @@ -1363,7 +1351,7 @@ do end end) end, - tree_to_stub = cached(function(self, tree) + tree_to_stub = function(self, tree) if tree.type ~= "FunctionCall" then error("Tried to get stub from non-functioncall tree: " .. tostring(tree.type), 0) end @@ -1378,8 +1366,8 @@ do end return _accum_0 end)(), " ") - end), - tree_to_named_stub = cached(function(self, tree) + end, + tree_to_named_stub = function(self, tree) if tree.type ~= "FunctionCall" then error("Tried to get stub from non-functioncall tree: " .. tostring(tree.type), 0) end @@ -1394,7 +1382,7 @@ do end return _accum_0 end)(), " ") - end), + end, get_stubs_from_signature = function(self, signature) if type(signature) ~= 'table' or signature.type then error("Invalid signature: " .. tostring(repr(signature)), 0) diff --git a/nomsu.moon b/nomsu.moon index 2b384b7..ecd4cef 100755 --- a/nomsu.moon +++ b/nomsu.moon @@ -23,13 +23,6 @@ colored = setmetatable({}, {__index:(_,color)-> ((msg)-> colors[color]..(msg or Tuple = immutable(nil, {name:"Tuple", __tostring:=> "Tuple(#{concat [repr(x) for x in *@], ", "})"}) -cached = (fn)-> - cache = setmetatable({}, {__mode:"k"}) - return (self, arg)-> - unless cache[arg] - cache[arg] = fn(self, arg) - return cache[arg] - -- Use + operator for string coercive concatenation (note: "asdf" + 3 == "asdf3") -- Use [] for accessing string characters, or s[{3,4}] for s:sub(3,4) -- Note: This globally affects all strings in this instance of Lua! @@ -262,7 +255,7 @@ class NomsuCompiler indent: (code, levels=1)=> return code\gsub("\n","\n"..(" ")\rep(levels)) - get_line_number: cached (tree)=> + get_line_number: (tree)=> metadata = @tree_metadata[tree] unless metadata return "" @@ -924,11 +917,11 @@ class NomsuCompiler if replacements[id] != nil return replacements[id] - tree_to_stub: cached (tree)=> + tree_to_stub: (tree)=> if tree.type != "FunctionCall" then error "Tried to get stub from non-functioncall tree: #{tree.type}", 0 return concat([(t.type == "Word" and t.value or "%") for t in *tree.value], " ") - tree_to_named_stub: cached (tree)=> + tree_to_named_stub: (tree)=> if tree.type != "FunctionCall" then error "Tried to get stub from non-functioncall tree: #{tree.type}", 0 return concat([(t.type == "Word" and t.value or "%#{t.value}") for t in *tree.value], " ")