aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-03 22:33:44 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-03 22:34:00 -0700
commita5bbce315dd9e6861d426bb16a3d792e2a3c0dfc (patch)
treef52d66e366bcc9c2aee002a27e69febc6cadef9b
parentbf60ac28c5ab128a15d1b0a2d5f1021dbe7081fd (diff)
Minor tweaks/cleanups.
-rw-r--r--code_obj.lua2
-rw-r--r--code_obj.moon2
-rw-r--r--nomsu.lua13
-rwxr-xr-xnomsu.moon9
-rw-r--r--nomsu_tree.lua8
-rw-r--r--nomsu_tree.moon8
6 files changed, 18 insertions, 24 deletions
diff --git a/code_obj.lua b/code_obj.lua
index 4e7de9b..dbc1d65 100644
--- a/code_obj.lua
+++ b/code_obj.lua
@@ -16,7 +16,7 @@ Source = immutable({
start, stop = 1, #FILE_CACHE[filename]
end
if stop then
- assert(start <= stop, "Invalid range: " .. tostring(start) .. ", " .. tostring(stop))
+ assert(start <= stop + 1, "Invalid range: " .. tostring(start) .. ", " .. tostring(stop))
end
return filename, start, stop
end,
diff --git a/code_obj.moon b/code_obj.moon
index 9df218c..dbb0211 100644
--- a/code_obj.moon
+++ b/code_obj.moon
@@ -8,7 +8,7 @@ Source = immutable {"filename","start","stop"}, {
__new: (filename, start, stop)=>
if not start
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
__tostring: =>
if @stop
diff --git a/nomsu.lua b/nomsu.lua
index d70fd76..888011e 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -236,9 +236,9 @@ do
local _class_0
local stub_defs, stub_pattern, var_pattern, _nomsu_chunk_counter
local _base_0 = {
- define_action = function(self, signature, fn, is_macro)
- if is_macro == nil then
- is_macro = false
+ define_action = function(self, signature, fn, is_compile_action)
+ if is_compile_action == nil then
+ is_compile_action = false
end
assert(type(fn) == 'function', "Bad fn: " .. tostring(repr(fn)))
if type(signature) == 'string' then
@@ -285,7 +285,7 @@ do
local alias = signature[_index_0]
local stub = assert(stub_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
local _accum_0 = { }
local _len_0 = 1
@@ -634,9 +634,6 @@ do
end
return lua
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)
return nomsu:run_file(_filename)
end)
@@ -727,7 +724,7 @@ do
end
end
})
- self.environment.MACROS = { }
+ self.environment.COMPILE_ACTIONS = { }
self.environment.ARG_ORDERS = setmetatable({ }, {
__mode = "k"
})
diff --git a/nomsu.moon b/nomsu.moon
index fd6899f..cc6b17b 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -243,7 +243,7 @@ class NomsuCompiler
(...)->
error("Attempt to run undefined action: #{key}", 0)
})
- @environment.MACROS = {}
+ @environment.COMPILE_ACTIONS = {}
@environment.ARG_ORDERS = setmetatable({}, {__mode:"k"})
@environment.LOADED = {}
@environment.Types = Types
@@ -258,7 +258,7 @@ class NomsuCompiler
{~ (%space->'') (('%' (%varname->'')) / %word)? ((%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}")
if type(signature) == 'string'
signature = {signature}
@@ -275,7 +275,7 @@ class NomsuCompiler
for alias in *signature
stub = assert(stub_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]
@environment.ARG_ORDERS[fn] = arg_orders
@@ -522,9 +522,6 @@ class NomsuCompiler
lua\append bit_lua
return lua
- @define_compile_action "!! code location !!", =>
- return Lua.Value(@source, repr(tostring(@source)))
-
@define_action "run file %filename", (_filename)->
return nomsu\run_file(_filename)
diff --git a/nomsu_tree.lua b/nomsu_tree.lua
index 5b24b75..a4940af 100644
--- a/nomsu_tree.lua
+++ b/nomsu_tree.lua
@@ -186,8 +186,8 @@ local math_expression = re.compile([[ ([+-] " ")* "%" (" " [*/^+-] (" " [+-])* "
Tree("Action", {
as_lua = function(self, nomsu)
local stub = self:get_stub()
- local macro = nomsu.environment.MACROS[stub]
- if macro then
+ local compile_action = nomsu.environment.COMPILE_ACTIONS[stub]
+ if compile_action then
local args
do
local _accum_0 = { }
@@ -205,7 +205,7 @@ Tree("Action", {
do
local _accum_0 = { }
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
local p = _list_0[_index_0]
_accum_0[_len_0] = args[p - 1]
@@ -213,7 +213,7 @@ Tree("Action", {
end
args = _accum_0
end
- local ret = macro(self, unpack(args))
+ local ret = compile_action(self, unpack(args))
return ret
end
local action = rawget(nomsu.environment.ACTIONS, stub)
diff --git a/nomsu_tree.moon b/nomsu_tree.moon
index 69f338f..8fe8283 100644
--- a/nomsu_tree.moon
+++ b/nomsu_tree.moon
@@ -116,13 +116,13 @@ math_expression = re.compile [[ ([+-] " ")* "%" (" " [*/^+-] (" " [+-])* " %")+
Tree "Action",
as_lua: (nomsu)=>
stub = @get_stub!
- macro = nomsu.environment.MACROS[stub]
- if macro
+ compile_action = nomsu.environment.COMPILE_ACTIONS[stub]
+ if compile_action
args = [arg for arg in *@value when arg.type != "Word"]
-- 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
- ret = macro(self, unpack(args))
+ ret = compile_action(self, unpack(args))
return ret
action = rawget(nomsu.environment.ACTIONS, stub)
lua = Lua.Value(@source)