Incremental progress.

This commit is contained in:
Bruce Hill 2018-04-12 20:39:17 -07:00
parent 1de29826a8
commit b05a46c78c
4 changed files with 51 additions and 47 deletions

View File

@ -49,9 +49,9 @@ immediately:
lua:append(arg);
if i < #args then lua:append(", ") end
end
local body_lua = nomsu:tree_to_lua(\%lua):as_statements();
local body_lua = nomsu:tree_to_lua(\%body):as_statements();
body_lua:declare_locals(args);
lua:append("\\n ", body_lua, "\\nend);")
lua:append(")\\n ", body_lua, "\\nend);")
return lua;
# Macro to make nomsu macros:

View File

@ -5,7 +5,12 @@ export LINE_STARTS
Location = immutable {"text_name","text","start","stop"}, {
name:"Location"
__new: (text_name, text, start, stop)=> text_name, text, start, stop or start
__new: (text_name, text, start, stop)=>
assert(type(text_name) == 'string')
assert(type(text) == 'string')
assert(type(start) == 'number')
assert(type(stop or start) == 'number')
return text_name, text, start, stop or start
__tostring: => "#{@text_name}[#{@start}:#{@stop}]"
__lt: (other)=>
assert(@text == other.text, "Cannot compare sources from different texts")
@ -28,9 +33,9 @@ Location = immutable {"text_name","text","start","stop"}, {
while (line_starts[stop_line+1] or (#src+1)) <= @stop
stop_line += 1
return start_line, stop_line
get_line: => "#{@text_name}:#{@get_line_number}"
get_line: => "#{@text_name}:#{@get_line_number!}"
get_line_range: =>
start_line, stop_line = @get_line_number
start_line, stop_line = @get_line_number!
return if stop_line == start_line
"#{text_name}:#{start_line}"
else "#{text_name}:#{start_line}-#{stop_line}"
@ -41,6 +46,9 @@ class Lua
is_value: false
new: (@source, ...)=>
for i=1,select("#",...)
x = select(i,...)
assert(type(x) != 'table' or getmetatable(x))
@bits = {...}
@free_vars = {}
@ -81,14 +89,20 @@ class Lua
n = select("#",...)
bits = @bits
for i=1,n
x = select(i,...)
assert(type(x) != 'table' or getmetatable(x))
bits[#bits+1] = select(i, ...)
prepend: (...)=>
n = select("#",...)
bits = @bits
for i=#bits+n,n+1,-1
x = select(i,...)
assert(type(x) != 'table' or getmetatable(x))
bits[i] = bits[i-n]
for i=1,n
x = select(i,...)
assert(type(x) != 'table' or getmetatable(x))
bits[i] = select(i, ...)
make_offset_table: (lua_chunkname)=>
@ -132,7 +146,7 @@ class LuaValue extends Lua
as_statements: =>
bits = {unpack @bits}
bits[#bits+1] = ";"
return Lua(@source, bits)
return Lua(@source, unpack(bits))
parenthesize: =>
@prepend "("

View File

@ -973,11 +973,9 @@ do
return lua
end
local args = { }
local _list_1 = tree.value
for _index_0 = 1, #_list_1 do
for i, tok in ipairs(tree.value) do
local _continue_0 = false
repeat
local i, tok = _list_1[_index_0]
if tok.type == "Word" then
_continue_0 = true
break
@ -998,9 +996,9 @@ do
do
local _accum_0 = { }
local _len_0 = 1
local _list_2 = metadata.arg_orders[stub]
for _index_0 = 1, #_list_2 do
local p = _list_2[_index_0]
local _list_1 = metadata.arg_orders[stub]
for _index_0 = 1, #_list_1 do
local p = _list_1[_index_0]
_accum_0[_len_0] = args[p]
_len_0 = _len_0 + 1
end
@ -1612,26 +1610,22 @@ if arg and debug_getinfo(2).func ~= require then
if not info or not info.func then
return info
end
if info.short_src or info.source or info.linedefine or info.currentline then
do
local metadata = nomsu.action_metadata[info.func]
if metadata then
info.name = metadata.aliases[1]
local filename = metadata.source:match("^[^[:]*")
info.short_src = filename
info.source = FILE_CACHE[filename]
local linedefined
ok, linedefined = pcall(lua_line_to_nomsu_line, info.short_src, info.linedefined)
if ok then
info.linedefined = linedefined
end
local currentline
ok, currentline = pcall(lua_line_to_nomsu_line, info.short_src, info.currentline)
end
local is_nomsu, nomsu_line = pcall(lua_line_to_nomsu_line, info.short_src, info.linedefined)
if is_nomsu then
if info.source:sub(1, 1) == "@" then
error("Not-yet-loaded source: " .. tostring(info.source))
end
info.linedefined = nomsu_line
info.currentline = lua_line_to_nomsu_line(info.short_src, info.currentline)
info.short_src = metadata.source.text_name
info.source = metadata.source.text
else
if info.short_src and info.short_src:match("^.*%.moon$") then
local line_table = moonscript_line_tables[info.short_src]
local file = FILE_CACHE[info.short_src]
info.source = file or info.source
end
end
return info

View File

@ -714,7 +714,7 @@ class NomsuCompiler
return lua
args = {}
for i, tok in *tree.value
for i, tok in ipairs tree.value
if tok.type == "Word" then continue
arg_lua = @tree_to_lua(tok)
unless arg_lua.is_value
@ -1093,20 +1093,16 @@ if arg and debug_getinfo(2).func != require
debug_getinfo(f,what)
else debug_getinfo(thread,f,what)
if not info or not info.func then return info
if info.short_src or info.source or info.linedefine or info.currentline
if metadata = nomsu.action_metadata[info.func]
info.name = metadata.aliases[1]
is_nomsu, nomsu_line = pcall(lua_line_to_nomsu_line, info.short_src, info.linedefined)
if is_nomsu
if info.source\sub(1,1) == "@" then error("Not-yet-loaded source: #{info.source}")
info.linedefined = nomsu_line
info.currentline = lua_line_to_nomsu_line(info.short_src, info.currentline)
info.short_src = metadata.source.text_name
info.source = metadata.source.text
else
if info.short_src and info.short_src\match("^.*%.moon$")
line_table = moonscript_line_tables[info.short_src]
file = FILE_CACHE[info.short_src]
info.source = file or info.source
filename = metadata.source\match("^[^[:]*")
info.short_src = filename
info.source = FILE_CACHE[filename]
ok, linedefined = pcall(lua_line_to_nomsu_line, info.short_src, info.linedefined)
if ok then info.linedefined = linedefined
ok, currentline = pcall(lua_line_to_nomsu_line, info.short_src, info.currentline)
--if ok then info.currentline = currentline
return info