aboutsummaryrefslogtreecommitdiff
path: root/code_obj.lua
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-09 16:40:36 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-11-09 16:41:19 -0800
commit69aaea030e08e083151aa25b8080eddd0d4c1683 (patch)
tree6cd90a65e6828f60cc052c4a1b33a4a4c0d65570 /code_obj.lua
parenta2f07415c5284bf94c146cea6eed4a15f171b9ab (diff)
No longer passing `tree` to every compile action. Now, you can just
return a LuaCode object, and it will automatically get a source from `tree` if it didn't already have a source. Plus some fixes/cleanup.
Diffstat (limited to 'code_obj.lua')
-rw-r--r--code_obj.lua59
1 files changed, 29 insertions, 30 deletions
diff --git a/code_obj.lua b/code_obj.lua
index 4fd01d6..376ee0c 100644
--- a/code_obj.lua
+++ b/code_obj.lua
@@ -110,9 +110,23 @@ do
return self:text()
end,
as_lua = function(self)
- return tostring(self.__class.__name) .. "(" .. tostring(concat({
- tostring(self.source):as_lua(),
- unpack((function()
+ if self.source then
+ return tostring(self.__class.__name) .. ":from(" .. tostring(concat({
+ 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] = b:as_lua()
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)())
+ }, ", ")) .. ")"
+ else
+ return tostring(self.__class.__name) .. "(" .. tostring(concat((function()
local _accum_0 = { }
local _len_0 = 1
local _list_0 = self.bits
@@ -122,8 +136,8 @@ do
_len_0 = _len_0 + 1
end
return _accum_0
- end)())
- }, ", ")) .. ")"
+ end)(), ", ")) .. ")"
+ end
end,
__len = function(self)
return #self:text()
@@ -246,12 +260,8 @@ do
}
_base_0.__index = _base_0
_class_0 = setmetatable({
- __init = function(self, source, ...)
- self.source = source
+ __init = function(self, ...)
self.bits = { }
- if type(self.source) == 'string' then
- self.source = Source:from_string(self.source)
- end
return self:append(...)
end,
__base = _base_0,
@@ -266,6 +276,14 @@ do
})
_base_0.__class = _class_0
local self = _class_0
+ self.from = function(self, source, ...)
+ local inst = self(...)
+ if type(source) == 'string' then
+ source = Source:from_string(source)
+ end
+ inst.source = source
+ return inst
+ end
self.is_instance = function(self, x)
return type(x) == 'table' and x.__class == self
end
@@ -370,27 +388,8 @@ do
end
return to_declare
end,
- as_statements = function(self, prefix, suffix)
- if prefix == nil then
- prefix = ""
- end
- if suffix == nil then
- suffix = ";"
- end
- if self:text():matches(";$") or self:text() == "" then
- return self
- end
- local statements = LuaCode(self.source)
- if prefix ~= "" then
- statements:append(prefix)
- end
- statements:append(self)
- if suffix ~= "" then
- statements:append(suffix)
- end
- return statements
- end,
make_offset_table = function(self)
+ assert(self.source, "This code doesn't have a source")
local lua_to_nomsu, nomsu_to_lua = { }, { }
local walk
walk = function(lua, pos)