diff --git a/lib/metaprogramming.nom b/lib/metaprogramming.nom index 4924e78..a2cf4bf 100644 --- a/lib/metaprogramming.nom +++ b/lib/metaprogramming.nom @@ -80,12 +80,14 @@ compile [nomsu %method %args] to: "nomsu[\(%method as lua)](nomsu, unpack(\(%arg # Get the source code for a function rule [help %rule] =: lua block ".." - |local fn_def = nomsu:get_fn_def(vars.rule); + |local fn_def = nomsu.defs[nomsu:get_stub(vars.rule)] |if not fn_def then; | nomsu:writeln("Rule not found: "..nomsu:repr(vars.rule)); |else; - | nomsu:writeln("rule "..nomsu:repr(nomsu.utils.keys(fn_def.stub)) - | .." ="..(fn_def.src or ":\\n ")); + | local template = fn_def.is_macro and "compile %s to%s" or "rule %s =%s"; + | local src = fn_def.src or ":\\n "; + | if src:sub(1,1) ~= ":" and fn_def.is_macro then; template = "parse %s as: %s"; end; + | nomsu:writeln(template:format(nomsu:repr(fn_def.stub), src)); |end; # Compiler tools diff --git a/lib/permissions.nom b/lib/permissions.nom index 1f297d0..1725683 100644 --- a/lib/permissions.nom +++ b/lib/permissions.nom @@ -7,6 +7,14 @@ require "lib/collections.nom" rule [standardize rules %rules] =: if (lua expr "type(vars.rules) == 'string'"): %rules = [%rules] (nomsu "get_stub" [%]) for all %rules + %set = [] + for %rule in %rules: + %stub = (nomsu "get_stub" [%rule]) + %aliases = (((nomsu's "defs")->%stub)->"aliases") + for all %aliases: %set -> % = (yes) + keys in %set + + rule [restrict %rules to within %elite-rules] =: %rules = (standardize rules %rules) %elite-rules = (standardize rules %elite-rules) diff --git a/nomsu.lua b/nomsu.lua index ad64522..3b8ad49 100644 --- a/nomsu.lua +++ b/nomsu.lua @@ -207,6 +207,7 @@ do end assert(type(thunk) == 'function', "Bad thunk: " .. tostring(repr(thunk))) local canonical_args = nil + local aliases = { } local _list_0 = self:get_stubs(signature) for _index_0 = 1, #_list_0 do local _des_0 = _list_0[_index_0] @@ -228,12 +229,14 @@ do else canonical_args = utils.set(arg_names) end + insert(aliases, stub) self.defs[stub] = { thunk = thunk, stub = stub, arg_names = arg_names, src = src, - is_macro = is_macro + is_macro = is_macro, + aliases = aliases } end end, @@ -781,7 +784,9 @@ do return repr(...) end self.loaded_files = { } - return self:initialize_core() + if not parent then + return self:initialize_core() + end end, __base = _base_0, __name = "NomsuCompiler" diff --git a/nomsu.moon b/nomsu.moon index 4254ad2..cfe9aa3 100755 --- a/nomsu.moon +++ b/nomsu.moon @@ -191,7 +191,8 @@ class NomsuCompiler @utils = utils @repr = (...)=> repr(...) @loaded_files = {} - @initialize_core! + if not parent + @initialize_core! writeln:(...)=> @write(...) @@ -200,6 +201,7 @@ class NomsuCompiler def: (signature, thunk, src, is_macro=false)=> assert type(thunk) == 'function', "Bad thunk: #{repr thunk}" canonical_args = nil + aliases = {} for {stub, arg_names} in *@get_stubs(signature) assert stub, "NO STUB FOUND: #{repr signature}" if @debug then @writeln "#{colored.bright "DEFINING RULE:"} #{colored.underscore colored.magenta repr(stub)} #{colored.bright "WITH ARGS"} #{colored.dim repr(arg_names)}" @@ -208,7 +210,8 @@ class NomsuCompiler if canonical_args assert utils.equivalent(utils.set(arg_names), canonical_args), "Mismatched args" else canonical_args = utils.set(arg_names) - @defs[stub] = {:thunk, :stub, :arg_names, :src, :is_macro} + insert aliases, stub + @defs[stub] = {:thunk, :stub, :arg_names, :src, :is_macro, :aliases} defmacro: (signature, thunk, src)=> @def(signature, thunk, src, true)