aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/metaprogramming.nom9
-rw-r--r--lua_obj.lua68
-rw-r--r--lua_obj.moon52
-rw-r--r--nomsu.lua92
-rwxr-xr-xnomsu.moon95
-rw-r--r--nomsu_tree.lua2
-rw-r--r--nomsu_tree.moon2
7 files changed, 179 insertions, 141 deletions
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 8622b07..aea756a 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -162,7 +162,7 @@ action [help %action]:
# Compiler tools
immediately:
compile [run %code] to:
- Lua value "nomsu:run(Nomsu(\(=lua "tree.source"), \(%code as lua expr)))"
+ Lua value "nomsu:run(Nomsu(\(=lua "tostring(tree.source)"), \(%code as lua expr)))"
parse [enable debugging] as: lua> "nomsu.debug = true;"
parse [disable debugging] as: lua> "nomsu.debug = false;"
@@ -184,9 +184,10 @@ immediately:
immediately:
compile [source] to: Lua value (=lua "tree.source") "tree.source"
-immediately:
- action [Lua %]: Lua (=lua "tree.source") %
- action [Lua value %]: Lua value (=lua "tree.source") %
+#..
+ immediately:
+ action [Lua %]: Lua (=lua "tree.source") %
+ action [Lua value %]: Lua value (=lua "tree.source") %
# Return
immediately:
diff --git a/lua_obj.lua b/lua_obj.lua
index a9a5459..8375016 100644
--- a/lua_obj.lua
+++ b/lua_obj.lua
@@ -12,6 +12,9 @@ Source = immutable({
}, {
name = "Source",
__new = function(self, filename, start, stop)
+ if not start then
+ start, stop = 1, #FILE_CACHE[filename]
+ end
if stop then
assert(start <= stop, "Invalid range: " .. tostring(start) .. ", " .. tostring(stop))
end
@@ -158,6 +161,12 @@ do
self.source = Source(self.source, 1, #self + 1)
end
end
+ assert(self.source == nil or Source:is_instance(self.source))
+ local _list_0 = self.bits
+ for _index_0 = 1, #_list_0 do
+ local b = _list_0[_index_0]
+ assert(not Source:is_instance(b))
+ end
end,
__base = _base_0,
__name = "Code"
@@ -215,22 +224,25 @@ do
end
removals[var] = true
end
- local remove_from
- remove_from = function(self)
- for i = #self.free_vars, 1, -1 do
- if removals[self.free_vars[i]] then
- remove(self.free_vars, i)
+ local stack = {
+ self
+ }
+ while #stack > 0 do
+ local lua
+ lua, stack[#stack] = stack[#stack], nil
+ for i = #lua.free_vars, 1, -1 do
+ if removals[lua.free_vars[i]] then
+ remove(lua.free_vars, i)
end
end
- local _list_0 = self.bits
+ local _list_0 = lua.bits
for _index_0 = 1, #_list_0 do
local b = _list_0[_index_0]
if type(b) ~= 'string' then
- remove_from(b)
+ stack[#stack + 1] = b
end
end
end
- remove_from(self)
self.__str = nil
end,
convert_to_statements = function(self, prefix, suffix)
@@ -282,6 +294,19 @@ do
return self:prepend("local " .. tostring(concat(to_declare, ", ")) .. ";\n")
end
end,
+ stringify = function(self)
+ if self.__str == nil then
+ local buff = { }
+ for i, b in ipairs(self.bits) do
+ if type(b) ~= 'string' then
+ b = b:stringify()
+ end
+ buff[#buff + 1] = b
+ end
+ self.__str = concat(buff, "")
+ end
+ return self.__str
+ end,
__tostring = function(self)
if self.__str == nil then
local buff = { }
@@ -329,32 +354,31 @@ do
self.__str = nil
end,
make_offset_table = function(self)
- local lua_chunkname = tostring(self.source) .. ".lua"
- local lua_str = tostring(self)
- local metadata = {
- nomsu_filename = self.source.filename,
- lua_filename = lua_chunkname,
- lua_file = lua_str,
- lua_to_nomsu = { },
- nomsu_to_lua = { }
- }
+ local lua_to_nomsu, nomsu_to_lua = { }, { }
local walk
walk = function(lua, pos)
local _list_0 = lua.bits
for _index_0 = 1, #_list_0 do
local b = _list_0[_index_0]
if type(b) == 'string' then
- local output = Source(lua_chunkname, pos, pos + #b)
- metadata.lua_to_nomsu[output] = lua.source
- metadata.nomsu_to_lua[lua.source] = output
+ if lua.source then
+ lua_to_nomsu[pos] = lua.source.start
+ nomsu_to_lua[lua.source.start] = pos
+ end
else
- walk(b, pos, pos + #b)
+ walk(b, pos)
end
pos = pos + #b
end
end
walk(self, 1)
- return lua_str, metadata
+ return {
+ nomsu_filename = self.source.filename,
+ lua_filename = tostring(self.source) .. ".lua",
+ lua_file = self:stringify(),
+ lua_to_nomsu = lua_to_nomsu,
+ nomsu_to_lua = nomsu_to_lua
+ }
end,
parenthesize = function(self)
if self.is_value then
diff --git a/lua_obj.moon b/lua_obj.moon
index d07aedd..a7c7ff6 100644
--- a/lua_obj.moon
+++ b/lua_obj.moon
@@ -6,6 +6,8 @@ export LINE_STARTS
Source = immutable {"filename","start","stop"}, {
name:"Source"
__new: (filename, start, stop)=>
+ if not start
+ start, stop = 1, #FILE_CACHE[filename]
if stop then assert(start <= stop, "Invalid range: #{start}, #{stop}")
return filename, start, stop
__tostring: =>
@@ -69,6 +71,9 @@ class Code
@source = Source(filename, tonumber(start), tonumber(stop))
else
@source = Source(@source, 1, #self+1)
+ assert(@source == nil or Source\is_instance(@source))
+ for b in *@bits
+ assert(not Source\is_instance(b))
clone: =>
cls = @__class
@@ -144,14 +149,16 @@ class Lua extends Code
elseif type(var) != 'string'
var = tostring(var)
removals[var] = true
- remove_from = =>
- for i=#@free_vars,1,-1
- if removals[@free_vars[i]]
- remove @free_vars, i
- for b in *@bits
+
+ stack = {self}
+ while #stack > 0
+ lua, stack[#stack] = stack[#stack], nil
+ for i=#lua.free_vars,1,-1
+ if removals[lua.free_vars[i]]
+ remove lua.free_vars, i
+ for b in *lua.bits
if type(b) != 'string'
- remove_from b
- remove_from self
+ stack[#stack+1] = b
@__str = nil
convert_to_statements: (prefix="", suffix=";")=>
@@ -178,6 +185,15 @@ class Lua extends Code
if #to_declare > 0
@prepend "local #{concat to_declare, ", "};\n"
+ stringify: =>
+ if @__str == nil
+ buff = {}
+ for i,b in ipairs @bits
+ if type(b) != 'string'
+ b = b\stringify!
+ buff[#buff+1] = b
+ @__str = concat(buff, "")
+ return @__str
__tostring: =>
if @__str == nil
buff = {}
@@ -218,24 +234,22 @@ class Lua extends Code
make_offset_table: =>
-- Return a mapping from output (lua) character number to input (nomsu) character number
- lua_chunkname = tostring(@source)..".lua"
- lua_str = tostring(self)
- metadata = {
- nomsu_filename:@source.filename
- lua_filename:lua_chunkname, lua_file:lua_str
- lua_to_nomsu: {}, nomsu_to_lua: {}
- }
+ lua_to_nomsu, nomsu_to_lua = {}, {}
walk = (lua, pos)->
for b in *lua.bits
if type(b) == 'string'
- output = Source(lua_chunkname, pos, pos+#b)
- metadata.lua_to_nomsu[output] = lua.source
- metadata.nomsu_to_lua[lua.source] = output
+ if lua.source
+ lua_to_nomsu[pos] = lua.source.start
+ nomsu_to_lua[lua.source.start] = pos
else
- walk b, pos, pos+#b
+ walk b, pos
pos += #b
walk self, 1
- return lua_str, metadata
+ return {
+ nomsu_filename:@source.filename
+ lua_filename:tostring(@source)..".lua", lua_file:@stringify!
+ :lua_to_nomsu, :nomsu_to_lua
+ }
parenthesize: =>
if @is_value
diff --git a/nomsu.lua b/nomsu.lua
index 9381847..b1427d3 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -41,16 +41,10 @@ FILE_CACHE = setmetatable({ }, {
if not (file) then
return nil
end
- local code = file:read("a"):sub(1, -2)
+ local contents = file:read("a"):sub(1, -2)
file:close()
- local source = Source(filename, 1, #code)
- if filename:match("%.nom$") then
- code = Nomsu(source, code)
- elseif filename:match("%.lua$") then
- code = Lua(source, code)
- end
- self[filename] = code
- return code
+ self[filename] = contents
+ return contents
end
})
local line_counter = re.compile([[ lines <- {| line (%nl line)* |}
@@ -188,7 +182,10 @@ setmetatable(NOMSU_DEFS, {
if type(value) == 'table' then
error("Not a tuple: " .. tostring(repr(value)))
end
- local source = lpeg.userdata.source_code.source:sub(start, stop - 1)
+ local source = lpeg.userdata.source_code.source
+ start = start + (source.start - 1)
+ stop = stop + (source.start - 1)
+ source = Source(source.filename, start, stop - 1)
local node = Types[key](value, source)
return node
end
@@ -330,8 +327,8 @@ do
if type(nomsu_code) == 'string' then
_nomsu_chunk_counter = _nomsu_chunk_counter + 1
local filename = "<nomsu chunk #" .. tostring(_nomsu_chunk_counter) .. ">.nom"
- nomsu_code = Nomsu(filename, nomsu_code)
FILE_CACHE[filename] = nomsu_code
+ nomsu_code = Nomsu(filename, nomsu_code)
end
local userdata = {
source_code = nomsu_code,
@@ -382,21 +379,21 @@ do
end
if filename:match(".*%.lua") then
local file = assert(FILE_CACHE[filename], "Could not find file: " .. tostring(filename))
- return self:run_lua(file)
+ return self:run_lua(Lua(Source(filename), file))
end
if filename:match(".*%.nom") then
if not self.skip_precompiled then
local lua_filename = filename:gsub("%.nom$", ".lua")
local file = FILE_CACHE[lua_filename]
if file then
- return self:run_lua(file)
+ return self:run_lua(Lua(Source(filename), file))
end
end
local file = file or FILE_CACHE[filename]
if not file then
error("File does not exist: " .. tostring(filename), 0)
end
- return self:run(file, compile_fn)
+ return self:run(Nomsu(Source(filename), file), compile_fn)
else
return error("Invalid filetype for " .. tostring(filename), 0)
end
@@ -427,8 +424,7 @@ do
end,
run_lua = function(self, lua)
assert(type(lua) ~= 'string', "Attempt to run lua string instead of Lua (object)")
- local lua_string, metadata = lua:make_offset_table()
- LUA_METADATA[metadata.lua_filename] = metadata
+ local lua_string = lua:stringify()
if rawget(FILE_CACHE, lua.source.filename) == nil then
FILE_CACHE[lua.source.filename] = lua_string
end
@@ -950,7 +946,7 @@ do
tree_with_replaced_vars = function(self, tree, replacements)
return self:tree_map(tree, function(t)
if t.type == "Var" then
- local id = tostring(t:as_lua(self))
+ local id = t:as_lua(self):stringify()
if replacements[id] ~= nil then
return replacements[id]
end
@@ -1050,12 +1046,13 @@ do
nomsu:run_lua(lua)
return Lua(self.source, "if IMMEDIATE then\n", lua, "\nend")
end)
- self:define_compile_action("Lua %source %code", get_line_no(), function(self, _source, _code)
- if _code.type ~= "Text" then
- return Lua.Value(_source, "Lua(", repr(_code.source), ", ", nomsu:tree_to_lua(_code), ")")
+ local add_lua_bits
+ add_lua_bits = function(lua, code)
+ if code.type ~= "Text" then
+ lua:append(", ", code:as_lua(nomsu))
+ return
end
- local lua = Lua.Value(_source, "Lua(", repr(_code.source))
- local _list_0 = _code.value
+ local _list_0 = code.value
for _index_0 = 1, #_list_0 do
local bit = _list_0[_index_0]
lua:append(", ")
@@ -1065,40 +1062,39 @@ do
local bit_lua = nomsu:tree_to_lua(bit)
if not (bit_lua.is_value) then
local line, src = bit.source:get_line(), bit.source:get_text()
- error(tostring(line) .. ": Cannot use " .. tostring(colored.yellow(src)) .. " as a string interpolation value, since it's not an expression.", 0)
+ error(tostring(line) .. ": Cannot use " .. tostring(colored.yellow(src)) .. " as a string interpolation value, since it's not an expression.")
end
lua:append(bit_lua)
end
end
+ end
+ self:define_compile_action("Lua %code", get_line_no(), function(self, _code)
+ local lua = Lua.Value(self.source, "Lua(", tostring(_code.source))
+ add_lua_bits(lua, _code)
+ lua:append(")")
+ return lua
+ end)
+ self:define_compile_action("Lua %source %code", get_line_no(), function(self, _source, _code)
+ local lua = Lua.Value(self.source, "Lua(", _source:as_lua(nomsu))
+ add_lua_bits(lua, _code)
+ lua:append(")")
+ return lua
+ end)
+ self:define_compile_action("Lua value %code", get_line_no(), function(self, _code)
+ local lua = Lua.Value(self.source, "Lua.Value(", tostring(_code.source))
+ add_lua_bits(lua, _code)
lua:append(")")
return lua
end)
self:define_compile_action("Lua value %source %code", get_line_no(), function(self, _source, _code)
- if _code.type ~= "Text" then
- return Lua.Value(_source, "Lua.Value(", repr(_code.source), ", ", nomsu:tree_to_lua(_code), ")")
- end
- local lua = Lua.Value(_source, "Lua.Value(", repr(_code.source))
- local _list_0 = _code.value
- for _index_0 = 1, #_list_0 do
- local bit = _list_0[_index_0]
- lua:append(", ")
- if type(bit) == "string" then
- lua:append(repr(bit))
- else
- local bit_lua = nomsu:tree_to_lua(bit)
- if not (bit_lua.is_value) then
- local line, src = bit.source:get_line(), bit.source:get_text()
- error(tostring(line) .. ": Cannot use " .. tostring(colored.yellow(src)) .. " as a string interpolation value, since it's not an expression.", 0)
- end
- lua:append(bit_lua)
- end
- end
+ local lua = Lua.Value(self.source, "Lua.Value(", _source:as_lua(nomsu))
+ add_lua_bits(lua, _code)
lua:append(")")
return lua
end)
self:define_compile_action("lua> %code", get_line_no(), function(self, _code)
if _code.type ~= "Text" then
- return Lua.Value(self.source, "nomsu:run_lua(Lua(", repr(_code.source), ", ", repr(tostring(nomsu:tree_to_lua(_code))), "))")
+ return Lua.Value(self.source, "nomsu:run_lua(Lua(", repr(_code.source), ", ", repr(nomsu:tree_to_lua(_code):stringify()), "))")
end
local lua = Lua(_code.source)
local _list_0 = _code.value
@@ -1119,7 +1115,7 @@ do
end)
self:define_compile_action("=lua %code", get_line_no(), function(self, _code)
if _code.type ~= "Text" then
- return Lua.Value(self.source, "nomsu:run_lua(Lua(", repr(_code.source), ", ", repr(tostring(nomsu:tree_to_lua(_code))), "))")
+ return Lua.Value(self.source, "nomsu:run_lua(Lua(", repr(_code.source), ", ", repr(nomsu:tree_to_lua(_code):stringify()), "))")
end
local lua = Lua.Value(self.source)
local _list_0 = _code.value
@@ -1363,11 +1359,11 @@ if arg and debug_getinfo(2).func ~= require then
if args.flags["-p"] then
nomsu.environment.print = function() end
compile_fn = function(code)
- return io.output():write("local IMMEDIATE = true;\n" .. tostring(code))
+ return io.output():write("local IMMEDIATE = true;\n" .. (code:stringify()))
end
elseif args.output then
compile_fn = function(code)
- return io.open(args.output, 'w'):write("local IMMEDIATE = true;\n" .. tostring(code))
+ return io.open(args.output, 'w'):write("local IMMEDIATE = true;\n" .. (code:stringify()))
end
end
if args.input:match(".*%.lua") then
@@ -1422,10 +1418,8 @@ if arg and debug_getinfo(2).func ~= require then
return nil
end
end
- local nomsu_file = FILE_CACHE["nomsu.moon"]
- local nomsu_source = nomsu_file:read("a")
+ local nomsu_source = FILE_CACHE["nomsu.moon"]
local _, line_table = to_lua(nomsu_source)
- nomsu_file:close()
local level = 2
while true do
local _continue_0 = false
diff --git a/nomsu.moon b/nomsu.moon
index 5c5676a..dd5b07d 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -42,20 +42,15 @@ debug_getinfo = debug.getinfo
-- Re-implement nomsu-to-lua comment translation
export FILE_CACHE
--- FILE_CACHE is a map from filename (string) -> file contents (Lua or Nomsu object)
+-- FILE_CACHE is a map from filename (string) -> string of file contents
FILE_CACHE = setmetatable {}, {
__index: (filename)=>
file = io.open(filename)
return nil unless file
- code = file\read("a")\sub(1,-2) -- Lua appends trailing newline for no apparent reason.
+ contents = file\read("a")\sub(1,-2) -- Lua appends trailing newline for no apparent reason.
file\close!
- source = Source(filename, 1, #code)
- if filename\match("%.nom$")
- code = Nomsu(source, code)
- elseif filename\match("%.lua$")
- code = Lua(source, code)
- self[filename] = code
- return code
+ self[filename] = contents
+ return contents
}
line_counter = re.compile([[
@@ -173,7 +168,11 @@ NOMSU_DEFS = with {}
setmetatable(NOMSU_DEFS, {__index:(key)=>
make_node = (start, value, stop)->
if type(value) == 'table' then error("Not a tuple: #{repr value}")-- = Tuple(value)
- source = lpeg.userdata.source_code.source\sub(start,stop-1)
+ --source = lpeg.userdata.source_code.source\sub(start,stop-1)
+ source = lpeg.userdata.source_code.source
+ start += source.start-1
+ stop += source.start-1
+ source = Source(source.filename, start, stop-1)
node = Types[key](value, source)
return node
self[key] = make_node
@@ -299,8 +298,8 @@ class NomsuCompiler
if type(nomsu_code) == 'string'
_nomsu_chunk_counter += 1
filename = "<nomsu chunk ##{_nomsu_chunk_counter}>.nom"
- nomsu_code = Nomsu(filename, nomsu_code)
FILE_CACHE[filename] = nomsu_code
+ nomsu_code = Nomsu(filename, nomsu_code)
userdata = {
source_code:nomsu_code, indent_stack: {""}
}
@@ -338,17 +337,17 @@ class NomsuCompiler
if filename\match(".*%.lua")
file = assert(FILE_CACHE[filename], "Could not find file: #{filename}")
- return @run_lua(file)
+ return @run_lua(Lua(Source(filename), file))
if filename\match(".*%.nom")
if not @skip_precompiled -- Look for precompiled version
lua_filename = filename\gsub("%.nom$", ".lua")
file = FILE_CACHE[lua_filename]
if file
- return @run_lua(file)
+ return @run_lua(Lua(Source(filename), file))
file = file or FILE_CACHE[filename]
if not file
error("File does not exist: #{filename}", 0)
- return @run(file, compile_fn)
+ return @run(Nomsu(Source(filename), file), compile_fn)
else
error("Invalid filetype for #{filename}", 0)
@@ -366,8 +365,9 @@ class NomsuCompiler
run_lua: (lua)=>
assert(type(lua) != 'string', "Attempt to run lua string instead of Lua (object)")
- lua_string, metadata = lua\make_offset_table!
- LUA_METADATA[metadata.lua_filename] = metadata
+ lua_string = lua\stringify!
+ --metadata = lua\make_offset_table!
+ --LUA_METADATA[metadata.lua_filename] = metadata
if rawget(FILE_CACHE, lua.source.filename) == nil
FILE_CACHE[lua.source.filename] = lua_string
if rawget(FILE_CACHE, lua.source) == nil
@@ -739,7 +739,7 @@ class NomsuCompiler
tree_with_replaced_vars: (tree, replacements)=>
return @tree_map tree, (t)->
if t.type == "Var"
- id = tostring(t\as_lua(self))
+ id = t\as_lua(self)\stringify!
if replacements[id] != nil
return replacements[id]
@@ -803,12 +803,11 @@ class NomsuCompiler
nomsu\run_lua(lua)
return Lua(@source, "if IMMEDIATE then\n", lua, "\nend")
- @define_compile_action "Lua %source %code", get_line_no!, (_source, _code)=>
- if _code.type != "Text"
- return Lua.Value(_source, "Lua(", repr(_code.source),", ",nomsu\tree_to_lua(_code),")")
-
- lua = Lua.Value(_source, "Lua(", repr(_code.source))
- for bit in *_code.value
+ add_lua_bits = (lua, code)->
+ if code.type != "Text"
+ lua\append ", ", code\as_lua(nomsu)
+ return
+ for bit in *code.value
lua\append ", "
if type(bit) == "string"
lua\append repr(bit)
@@ -816,33 +815,37 @@ class NomsuCompiler
bit_lua = nomsu\tree_to_lua bit
unless bit_lua.is_value
line, src = bit.source\get_line!, bit.source\get_text!
- error "#{line}: Cannot use #{colored.yellow src} as a string interpolation value, since it's not an expression.", 0
+ error "#{line}: Cannot use #{colored.yellow src} as a string interpolation value, since it's not an expression."
lua\append bit_lua
+
+ @define_compile_action "Lua %code", get_line_no!, (_code)=>
+ lua = Lua.Value(@source, "Lua(", tostring(_code.source))
+ add_lua_bits(lua, _code)
lua\append ")"
return lua
- @define_compile_action "Lua value %source %code", get_line_no!, (_source, _code)=>
- if _code.type != "Text"
- return Lua.Value(_source, "Lua.Value(", repr(_code.source),", ",nomsu\tree_to_lua(_code),")")
+ @define_compile_action "Lua %source %code", get_line_no!, (_source, _code)=>
+ lua = Lua.Value(@source, "Lua(", _source\as_lua(nomsu))
+ add_lua_bits(lua, _code)
+ lua\append ")"
+ return lua
- lua = Lua.Value(_source, "Lua.Value(", repr(_code.source))
- for bit in *_code.value
- lua\append ", "
- if type(bit) == "string"
- lua\append repr(bit)
- else
- bit_lua = nomsu\tree_to_lua bit
- unless bit_lua.is_value
- line, src = bit.source\get_line!, bit.source\get_text!
- error "#{line}: Cannot use #{colored.yellow src} as a string interpolation value, since it's not an expression.", 0
- lua\append bit_lua
+ @define_compile_action "Lua value %code", get_line_no!, (_code)=>
+ lua = Lua.Value(@source, "Lua.Value(", tostring(_code.source))
+ add_lua_bits(lua, _code)
+ lua\append ")"
+ return lua
+
+ @define_compile_action "Lua value %source %code", get_line_no!, (_source, _code)=>
+ lua = Lua.Value(@source, "Lua.Value(", _source\as_lua(nomsu))
+ add_lua_bits(lua, _code)
lua\append ")"
return lua
@define_compile_action "lua> %code", get_line_no!, (_code)=>
if _code.type != "Text"
return Lua.Value @source, "nomsu:run_lua(Lua(",repr(_code.source),
- ", ",repr(tostring(nomsu\tree_to_lua(_code))),"))"
+ ", ",repr(nomsu\tree_to_lua(_code)\stringify!),"))"
lua = Lua(_code.source)
for bit in *_code.value
@@ -859,7 +862,7 @@ class NomsuCompiler
@define_compile_action "=lua %code", get_line_no!, (_code)=>
if _code.type != "Text"
return Lua.Value @source, "nomsu:run_lua(Lua(",repr(_code.source),
- ", ",repr(tostring(nomsu\tree_to_lua(_code))),"))"
+ ", ",repr(nomsu\tree_to_lua(_code)\stringify!),"))"
lua = Lua.Value(@source)
for bit in *_code.value
@@ -951,10 +954,10 @@ if arg and debug_getinfo(2).func != require
if args.flags["-p"]
nomsu.environment.print = ->
compile_fn = (code)->
- io.output!\write("local IMMEDIATE = true;\n"..tostring(code))
+ io.output!\write("local IMMEDIATE = true;\n"..(code\stringify!))
elseif args.output
compile_fn = (code)->
- io.open(args.output, 'w')\write("local IMMEDIATE = true;\n"..tostring(code))
+ io.open(args.output, 'w')\write("local IMMEDIATE = true;\n"..(code\stringify!))
if args.input\match(".*%.lua")
dofile(args.input)(nomsu, {})
@@ -996,10 +999,8 @@ if arg and debug_getinfo(2).func != require
ok, to_lua = pcall -> require('moonscript.base').to_lua
if not ok then to_lua = -> nil
- nomsu_file = FILE_CACHE["nomsu.moon"]
- nomsu_source = nomsu_file\read("a")
+ nomsu_source = FILE_CACHE["nomsu.moon"]
_, line_table = to_lua(nomsu_source)
- nomsu_file\close!
level = 2
while true
@@ -1046,7 +1047,11 @@ if arg and debug_getinfo(2).func != require
-- for both APIs
-- TODO: revert back to old error handler
+ --ProFi = require 'ProFi'
+ --ProFi\start()
--require('ldt').guard run
xpcall(run, err_hand)
+ --ProFi\stop()
+ --ProFi\writeReport( 'MyProfilingReport.txt' )
return NomsuCompiler
diff --git a/nomsu_tree.lua b/nomsu_tree.lua
index b42fe52..a693d95 100644
--- a/nomsu_tree.lua
+++ b/nomsu_tree.lua
@@ -131,7 +131,7 @@ Tree("Action", {
end
args = new_args
end
- local ret = action(Lua(self.source), unpack(args))
+ local ret = action(self, unpack(args))
return ret
end
local lua = Lua.Value(self.source)
diff --git a/nomsu_tree.moon b/nomsu_tree.moon
index e675b17..421e02a 100644
--- a/nomsu_tree.moon
+++ b/nomsu_tree.moon
@@ -79,7 +79,7 @@ Tree "Action",
new_args = [args[p-1] for p in *metadata.arg_orders[stub]]
args = new_args
-- Force Lua to avoid tail call optimization for debugging purposes
- ret = action(Lua(@source), unpack(args))
+ ret = action(self, unpack(args))
return ret
lua = Lua.Value(@source)