aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-04-12 20:39:17 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-04-12 20:39:22 -0700
commitb05a46c78ca40e6838ee49121fdc5d02823ed44b (patch)
treed5aa898612ad090d545d517cb856391c5ba21deb
parent1de29826a82cc858cf6d9df9ead86655304251a4 (diff)
Incremental progress.
-rw-r--r--core/metaprogramming.nom4
-rw-r--r--lua_obj.moon22
-rw-r--r--nomsu.lua46
-rwxr-xr-xnomsu.moon26
4 files changed, 51 insertions, 47 deletions
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 24201b0..d7409d2 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -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:
diff --git a/lua_obj.moon b/lua_obj.moon
index ef5dc7e..6cc3e00 100644
--- a/lua_obj.moon
+++ b/lua_obj.moon
@@ -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 "("
diff --git a/nomsu.lua b/nomsu.lua
index 36d8e6b..ba1d813 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -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
- do
- local metadata = nomsu.action_metadata[info.func]
- if metadata then
- info.name = metadata.aliases[1]
- end
- 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
+ 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
end
end
return info
diff --git a/nomsu.moon b/nomsu.moon
index e75ba04..5c24430 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -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 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
+ 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]
+ 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