Minor tweaks/cleanups.
This commit is contained in:
parent
bf60ac28c5
commit
a5bbce315d
@ -16,7 +16,7 @@ Source = immutable({
|
|||||||
start, stop = 1, #FILE_CACHE[filename]
|
start, stop = 1, #FILE_CACHE[filename]
|
||||||
end
|
end
|
||||||
if stop then
|
if stop then
|
||||||
assert(start <= stop, "Invalid range: " .. tostring(start) .. ", " .. tostring(stop))
|
assert(start <= stop + 1, "Invalid range: " .. tostring(start) .. ", " .. tostring(stop))
|
||||||
end
|
end
|
||||||
return filename, start, stop
|
return filename, start, stop
|
||||||
end,
|
end,
|
||||||
|
@ -8,7 +8,7 @@ Source = immutable {"filename","start","stop"}, {
|
|||||||
__new: (filename, start, stop)=>
|
__new: (filename, start, stop)=>
|
||||||
if not start
|
if not start
|
||||||
start, stop = 1, #FILE_CACHE[filename]
|
start, stop = 1, #FILE_CACHE[filename]
|
||||||
if stop then assert(start <= stop, "Invalid range: #{start}, #{stop}")
|
if stop then assert(start <= stop+1, "Invalid range: #{start}, #{stop}")
|
||||||
return filename, start, stop
|
return filename, start, stop
|
||||||
__tostring: =>
|
__tostring: =>
|
||||||
if @stop
|
if @stop
|
||||||
|
13
nomsu.lua
13
nomsu.lua
@ -236,9 +236,9 @@ do
|
|||||||
local _class_0
|
local _class_0
|
||||||
local stub_defs, stub_pattern, var_pattern, _nomsu_chunk_counter
|
local stub_defs, stub_pattern, var_pattern, _nomsu_chunk_counter
|
||||||
local _base_0 = {
|
local _base_0 = {
|
||||||
define_action = function(self, signature, fn, is_macro)
|
define_action = function(self, signature, fn, is_compile_action)
|
||||||
if is_macro == nil then
|
if is_compile_action == nil then
|
||||||
is_macro = false
|
is_compile_action = false
|
||||||
end
|
end
|
||||||
assert(type(fn) == 'function', "Bad fn: " .. tostring(repr(fn)))
|
assert(type(fn) == 'function', "Bad fn: " .. tostring(repr(fn)))
|
||||||
if type(signature) == 'string' then
|
if type(signature) == 'string' then
|
||||||
@ -285,7 +285,7 @@ do
|
|||||||
local alias = signature[_index_0]
|
local alias = signature[_index_0]
|
||||||
local stub = assert(stub_pattern:match(alias))
|
local stub = assert(stub_pattern:match(alias))
|
||||||
stub_args = assert(var_pattern:match(alias));
|
stub_args = assert(var_pattern:match(alias));
|
||||||
(is_macro and self.environment.MACROS or self.environment.ACTIONS)[stub] = fn
|
(is_compile_action and self.environment.COMPILE_ACTIONS or self.environment.ACTIONS)[stub] = fn
|
||||||
do
|
do
|
||||||
local _accum_0 = { }
|
local _accum_0 = { }
|
||||||
local _len_0 = 1
|
local _len_0 = 1
|
||||||
@ -634,9 +634,6 @@ do
|
|||||||
end
|
end
|
||||||
return lua
|
return lua
|
||||||
end)
|
end)
|
||||||
self:define_compile_action("!! code location !!", function(self)
|
|
||||||
return Lua.Value(self.source, repr(tostring(self.source)))
|
|
||||||
end)
|
|
||||||
self:define_action("run file %filename", function(_filename)
|
self:define_action("run file %filename", function(_filename)
|
||||||
return nomsu:run_file(_filename)
|
return nomsu:run_file(_filename)
|
||||||
end)
|
end)
|
||||||
@ -727,7 +724,7 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
self.environment.MACROS = { }
|
self.environment.COMPILE_ACTIONS = { }
|
||||||
self.environment.ARG_ORDERS = setmetatable({ }, {
|
self.environment.ARG_ORDERS = setmetatable({ }, {
|
||||||
__mode = "k"
|
__mode = "k"
|
||||||
})
|
})
|
||||||
|
@ -243,7 +243,7 @@ class NomsuCompiler
|
|||||||
(...)->
|
(...)->
|
||||||
error("Attempt to run undefined action: #{key}", 0)
|
error("Attempt to run undefined action: #{key}", 0)
|
||||||
})
|
})
|
||||||
@environment.MACROS = {}
|
@environment.COMPILE_ACTIONS = {}
|
||||||
@environment.ARG_ORDERS = setmetatable({}, {__mode:"k"})
|
@environment.ARG_ORDERS = setmetatable({}, {__mode:"k"})
|
||||||
@environment.LOADED = {}
|
@environment.LOADED = {}
|
||||||
@environment.Types = Types
|
@environment.Types = Types
|
||||||
@ -258,7 +258,7 @@ class NomsuCompiler
|
|||||||
{~ (%space->'') (('%' (%varname->'')) / %word)? ((%space->' ') (('%' (%varname->'')) / %word))* (%space->'') ~}
|
{~ (%space->'') (('%' (%varname->'')) / %word)? ((%space->' ') (('%' (%varname->'')) / %word))* (%space->'') ~}
|
||||||
]=], stub_defs
|
]=], stub_defs
|
||||||
var_pattern = re.compile "{| %space ((('%' {%varname}) / %word) %space)+ |}", stub_defs
|
var_pattern = re.compile "{| %space ((('%' {%varname}) / %word) %space)+ |}", stub_defs
|
||||||
define_action: (signature, fn, is_macro=false)=>
|
define_action: (signature, fn, is_compile_action=false)=>
|
||||||
assert(type(fn) == 'function', "Bad fn: #{repr fn}")
|
assert(type(fn) == 'function', "Bad fn: #{repr fn}")
|
||||||
if type(signature) == 'string'
|
if type(signature) == 'string'
|
||||||
signature = {signature}
|
signature = {signature}
|
||||||
@ -275,7 +275,7 @@ class NomsuCompiler
|
|||||||
for alias in *signature
|
for alias in *signature
|
||||||
stub = assert(stub_pattern\match(alias))
|
stub = assert(stub_pattern\match(alias))
|
||||||
stub_args = assert(var_pattern\match(alias))
|
stub_args = assert(var_pattern\match(alias))
|
||||||
(is_macro and @environment.MACROS or @environment.ACTIONS)[stub] = fn
|
(is_compile_action and @environment.COMPILE_ACTIONS or @environment.ACTIONS)[stub] = fn
|
||||||
arg_orders[stub] = [fn_arg_positions[@var_to_lua_identifier(a)] for a in *stub_args]
|
arg_orders[stub] = [fn_arg_positions[@var_to_lua_identifier(a)] for a in *stub_args]
|
||||||
@environment.ARG_ORDERS[fn] = arg_orders
|
@environment.ARG_ORDERS[fn] = arg_orders
|
||||||
|
|
||||||
@ -522,9 +522,6 @@ class NomsuCompiler
|
|||||||
lua\append bit_lua
|
lua\append bit_lua
|
||||||
return lua
|
return lua
|
||||||
|
|
||||||
@define_compile_action "!! code location !!", =>
|
|
||||||
return Lua.Value(@source, repr(tostring(@source)))
|
|
||||||
|
|
||||||
@define_action "run file %filename", (_filename)->
|
@define_action "run file %filename", (_filename)->
|
||||||
return nomsu\run_file(_filename)
|
return nomsu\run_file(_filename)
|
||||||
|
|
||||||
|
@ -186,8 +186,8 @@ local math_expression = re.compile([[ ([+-] " ")* "%" (" " [*/^+-] (" " [+-])* "
|
|||||||
Tree("Action", {
|
Tree("Action", {
|
||||||
as_lua = function(self, nomsu)
|
as_lua = function(self, nomsu)
|
||||||
local stub = self:get_stub()
|
local stub = self:get_stub()
|
||||||
local macro = nomsu.environment.MACROS[stub]
|
local compile_action = nomsu.environment.COMPILE_ACTIONS[stub]
|
||||||
if macro then
|
if compile_action then
|
||||||
local args
|
local args
|
||||||
do
|
do
|
||||||
local _accum_0 = { }
|
local _accum_0 = { }
|
||||||
@ -205,7 +205,7 @@ Tree("Action", {
|
|||||||
do
|
do
|
||||||
local _accum_0 = { }
|
local _accum_0 = { }
|
||||||
local _len_0 = 1
|
local _len_0 = 1
|
||||||
local _list_0 = nomsu.environment.ARG_ORDERS[macro][stub]
|
local _list_0 = nomsu.environment.ARG_ORDERS[compile_action][stub]
|
||||||
for _index_0 = 1, #_list_0 do
|
for _index_0 = 1, #_list_0 do
|
||||||
local p = _list_0[_index_0]
|
local p = _list_0[_index_0]
|
||||||
_accum_0[_len_0] = args[p - 1]
|
_accum_0[_len_0] = args[p - 1]
|
||||||
@ -213,7 +213,7 @@ Tree("Action", {
|
|||||||
end
|
end
|
||||||
args = _accum_0
|
args = _accum_0
|
||||||
end
|
end
|
||||||
local ret = macro(self, unpack(args))
|
local ret = compile_action(self, unpack(args))
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
local action = rawget(nomsu.environment.ACTIONS, stub)
|
local action = rawget(nomsu.environment.ACTIONS, stub)
|
||||||
|
@ -116,13 +116,13 @@ math_expression = re.compile [[ ([+-] " ")* "%" (" " [*/^+-] (" " [+-])* " %")+
|
|||||||
Tree "Action",
|
Tree "Action",
|
||||||
as_lua: (nomsu)=>
|
as_lua: (nomsu)=>
|
||||||
stub = @get_stub!
|
stub = @get_stub!
|
||||||
macro = nomsu.environment.MACROS[stub]
|
compile_action = nomsu.environment.COMPILE_ACTIONS[stub]
|
||||||
if macro
|
if compile_action
|
||||||
args = [arg for arg in *@value when arg.type != "Word"]
|
args = [arg for arg in *@value when arg.type != "Word"]
|
||||||
-- Force all compile-time actions to take a tree location
|
-- Force all compile-time actions to take a tree location
|
||||||
args = [args[p-1] for p in *nomsu.environment.ARG_ORDERS[macro][stub]]
|
args = [args[p-1] for p in *nomsu.environment.ARG_ORDERS[compile_action][stub]]
|
||||||
-- Force Lua to avoid tail call optimization for debugging purposes
|
-- Force Lua to avoid tail call optimization for debugging purposes
|
||||||
ret = macro(self, unpack(args))
|
ret = compile_action(self, unpack(args))
|
||||||
return ret
|
return ret
|
||||||
action = rawget(nomsu.environment.ACTIONS, stub)
|
action = rawget(nomsu.environment.ACTIONS, stub)
|
||||||
lua = Lua.Value(@source)
|
lua = Lua.Value(@source)
|
||||||
|
Loading…
Reference in New Issue
Block a user