aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-09-22 11:56:46 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-09-22 11:56:46 -0700
commite4660b169c14d24c3ec373b197e8b9469d200d50 (patch)
treeb9576e166caf1dcb994b7fe9162baa1a6a97756e /lib
parent6882862d0ff226d73bc6a010d335896c44d8cde9 (diff)
Renamed compiler -> nomsu for concision and clarity.
Diffstat (limited to 'lib')
-rw-r--r--lib/collections.nom4
-rw-r--r--lib/control_flow.nom16
-rw-r--r--lib/metaprogramming.nom97
-rw-r--r--lib/moonscript.nom14
-rw-r--r--lib/operators.nom52
-rw-r--r--lib/permissions.nom30
-rw-r--r--lib/secrets.nom6
-rw-r--r--lib/testing.nom2
-rw-r--r--lib/utils.nom54
9 files changed, 137 insertions, 138 deletions
diff --git a/lib/collections.nom b/lib/collections.nom
index 4a40c0f..09fff10 100644
--- a/lib/collections.nom
+++ b/lib/collections.nom
@@ -15,12 +15,12 @@ macro [..]
%index st to last in %list, %index nd to last in %list, %index rd to last in %list
%index th to last in %list
..=:
- ".."|compiler.utils.nth_to_last(\%list as lua\, \%index as lua\)
+ ".."|nomsu.utils.nth_to_last(\%list as lua\, \%index as lua\)
macro [first in %list, first %list] =:
".."|\%list as lua\[1]
macro [last in %list, last %list] =:
- ".."|compiler.utils.nth_to_last(\%list as lua\, 1)
+ ".."|nomsu.utils.nth_to_last(\%list as lua\, 1)
# Dict iteration convenience function. This could also be accomplished with: for all (entries in %dict): ...
macro block [for %key -> %value in %dict %body] =:
diff --git a/lib/control_flow.nom b/lib/control_flow.nom
index 4bdaa06..8d5f8ab 100644
--- a/lib/control_flow.nom
+++ b/lib/control_flow.nom
@@ -21,14 +21,14 @@ macro block [return %return-value] =: ".."
|return \%return-value as lua\
macro [do %action] =: ".."
- |(\%action as lua\)(compiler, setmetatable({}, {__index=vars}))
+ |(\%action as lua\)(nomsu, setmetatable({}, {__index=vars}))
# GOTOs
macro statement [-> %label] =: ".."
- |::label_\compiler "var_to_lua_identifier" [%label]\::
+ |::label_\nomsu "var_to_lua_identifier" [%label]\::
macro statement [go to %label] =: ".."
- |goto label_\compiler "var_to_lua_identifier" [%label]\
+ |goto label_\nomsu "var_to_lua_identifier" [%label]\
# Loop control flow
macro statement [break] =: "break"
@@ -38,7 +38,7 @@ macro statement [break repeat] =: "goto break_repeat"
macro statement [break repeat-until] =: "goto break_repeat_until"
macro statement [break repeat-while] =: "goto break_repeat_while"
macro statement [break %var, stop getting %var, no more %var] =: ".."
- |goto break_\compiler "var_to_lua_identifier" [%var]\
+ |goto break_\nomsu "var_to_lua_identifier" [%var]\
macro statement [continue] =: "continue"
macro statement [continue for] =: "goto continue_for"
@@ -47,7 +47,7 @@ macro statement [continue repeat] =: "goto continue_repeat"
macro statement [continue repeat-until] =: "goto continue_repeat_until"
macro statement [continue repeat-while] =: "goto continue_repeat_while"
macro statement [continue %var, go to next %var, on to the next %var] =: ".."
- |goto continue_\compiler "var_to_lua_identifier" [%var]\
+ |goto continue_\nomsu "var_to_lua_identifier" [%var]\
# While loops
macro block [repeat %body] =:
@@ -80,10 +80,10 @@ macro block [for %var in %iterable %body] =:
| \%var as lua\ = value
| \(lua expr "vars.body.value") as lua\
| ::continue_for::
- | ::continue_\compiler "var_to_lua_identifier" [%var]\::
+ | ::continue_\nomsu "var_to_lua_identifier" [%var]\::
|end
|::break_for::
- |::break_\compiler "var_to_lua_identifier" [%var]\::
+ |::break_\nomsu "var_to_lua_identifier" [%var]\::
macro block [for all %iterable %body] =:
pass # TODO: fix compiler bug
@@ -171,7 +171,7 @@ macro block [when %branch-value %body] =:
["value", %condition_bits]
%result join=: ".."
|
- |if compiler.utils.equivalent(branch_condition, \%condition as lua\) then
+ |if nomsu.utils.equivalent(branch_condition, \%condition as lua\) then
| \(lua expr "vars.thunk.value") as lua\
| goto finished_when
|end
diff --git a/lib/metaprogramming.nom b/lib/metaprogramming.nom
index 19df984..72c50b5 100644
--- a/lib/metaprogramming.nom
+++ b/lib/metaprogramming.nom
@@ -6,53 +6,52 @@
lua block ".."
|local function make_fn(wrap_in_block)
- | return function(compiler, vars, kind)
+ | return function(nomsu, vars, kind)
# Do a minimal amount of pre-processing (get the aliases and the source)
- | local aliases = compiler:repr(compiler:get_aliases(vars.macro_def))
- | local src = compiler:repr(vars.user_macro.src)
- | local user_macro = compiler:tree_to_lua(vars.user_macro)
+ | local aliases = nomsu:repr(nomsu:get_aliases(vars.macro_def))
+ | local src = nomsu:repr(vars.user_macro.src)
+ | local user_macro = nomsu:tree_to_lua(vars.user_macro)
# Then produce a block of code that creates the macro at runtime
| local lua = [[
- | compiler:defmacro(%s, (function(compiler, vars, kind)
- | if kind == "Expression" then
- | compiler:error("Macro "..%s.." was defined to be a block, but is being used as an expression")
- | end
- | local user_macro = %s
- | local lua = user_macro(compiler, vars)
- | %s
- | return lua, true
- | end), %s)
- | ]]
- | lua = lua:format(aliases, compiler:repr(aliases), user_macro,
+ |nomsu:defmacro(%s, (function(nomsu, vars, kind)
+ | if kind == "Expression" then
+ | nomsu:error("Macro "..%s.." was defined to be a block, but is being used as an expression")
+ | end
+ | local user_macro = %s
+ | local lua = user_macro(nomsu, vars)
+ | %s
+ | return lua, true
+ |end), %s)]]
+ | lua = lua:format(aliases, nomsu:repr(aliases), user_macro,
| wrap_in_block and [[lua = "do\\n "..lua.."\\nend"]] or "", src)
| return lua, true
| end
|end
- |compiler:defmacro("macro statement %macro_def = %user_macro", make_fn(false), "see:lib/metaprogramming.nom")
- |compiler:defmacro("macro block %macro_def = %user_macro", make_fn(true), "see:lib/metaprogramming.nom")
+ |nomsu:defmacro("macro statement %macro_def = %user_macro", make_fn(false), "see:lib/metaprogramming.nom")
+ |nomsu:defmacro("macro block %macro_def = %user_macro", make_fn(true), "see:lib/metaprogramming.nom")
macro statement [macro %macro_def = %user_macro] =:
- ".."|compiler:defmacro(
- | \lua expr "compiler:get_aliases(vars.macro_def)"\,
- | \lua expr "compiler:tree_to_lua(vars.user_macro)"\,
- | \lua expr "compiler:repr(vars.user_macro.src)"\)
-
-macro [compiler] =: "compiler"
-macro [compiler's %key] =: ".."|compiler[\%key as lua\]
-macro [compiler %method %args] =:
+ ".."|nomsu:defmacro(
+ | \lua expr "nomsu:get_aliases(vars.macro_def)"\,
+ | \lua expr "nomsu:tree_to_lua(vars.user_macro)"\,
+ | \lua expr "nomsu:repr(vars.user_macro.src)"\)
+
+macro [nomsu] =: "nomsu"
+macro [nomsu's %key] =: ".."|nomsu[\%key as lua\]
+macro [nomsu %method %args] =:
lua block ".."
- |local args = {"compiler"}
+ |local args = {"nomsu"}
|for _,arg in ipairs(vars.args.value) do
- | table.insert(args, compiler:tree_to_lua(arg))
+ | table.insert(args, nomsu:tree_to_lua(arg))
|end
- |return "compiler["..compiler:repr(compiler:tree_to_value(vars.method, vars)).."]("..table.concat(args, ", ")..")"
-macro [compiler utils %method %args] =:
+ |return "nomsu["..nomsu:repr(nomsu:tree_to_value(vars.method, vars)).."]("..table.concat(args, ", ")..")"
+macro [nomsu utils %method %args] =:
lua block ".."
|local args = {}
|for i,arg in ipairs(vars.args.value) do
- | args[i] = compiler:tree_to_lua(arg)
+ | args[i] = nomsu:tree_to_lua(arg)
|end
- |return "compiler.utils["..compiler:repr(compiler:tree_to_value(vars.method, vars)).."]("..table.concat(args, ", ")..")"
+ |return "nomsu.utils["..nomsu:repr(nomsu:tree_to_value(vars.method, vars)).."]("..table.concat(args, ", ")..")"
# Macro that lets you make new rules
#..
@@ -61,51 +60,51 @@ macro [compiler utils %method %args] =:
is currently in the middle of being defined). Being a macro also allows us to snatch
the source code and store that
macro statement [rule %rule_def = %body] =: ".."
- |compiler:def(
- | \compiler "repr" [compiler "get_aliases" [%rule_def]]\,
- | \compiler "tree_to_lua" [%body]\,
- | \compiler "repr" [lua expr "vars.body.src"]\)
+ |nomsu:def(
+ | \nomsu "repr" [nomsu "get_aliases" [%rule_def]]\,
+ | \nomsu "tree_to_lua" [%body]\,
+ | \nomsu "repr" [lua expr "vars.body.src"]\)
rule [fart]=: lua block "print('poot')"
macro block [alias %aliases = %aliased] =:
lua block ".."
- |local aliases = compiler:get_aliases(vars.aliases)
- |aliases = compiler:repr(aliases)
+ |local aliases = nomsu:get_aliases(vars.aliases)
+ |aliases = nomsu:repr(aliases)
|if vars.aliased.type ~= "Thunk" then
- | compiler:error("Right hand side of alias % = % should be a Thunk, but got "..vars.aliased.type
+ | nomsu:error("Right hand side of alias % = % should be a Thunk, but got "..vars.aliased.type
| ..". Maybe you used = instead of =: by mistake?")
|end
- |local aliased = next(compiler:get_aliases(vars.aliased.value))
- |aliased = compiler:repr(aliased)
+ |local aliased = next(nomsu:get_aliases(vars.aliased.value))
+ |aliased = nomsu:repr(aliased)
|local lua = ([[
- |compiler:add_aliases(%s, compiler.defs[%s])
+ |nomsu:add_aliases(%s, nomsu.defs[%s])
|]]):format(aliases, aliased)
|return lua
# Get the source code for a function
rule [help %rule] =:
lua block ".."
- |local fn_def = compiler:get_fn_def(vars.rule)
+ |local fn_def = nomsu:get_fn_def(vars.rule)
|if not fn_def then
- | compiler:writeln("Rule not found: "..compiler:repr(vars.rule))
+ | nomsu:writeln("Rule not found: "..nomsu:repr(vars.rule))
|else
- | compiler:writeln("rule "..compiler:repr(compiler.utils.keys(fn_def.aliases))
+ | nomsu:writeln("rule "..nomsu:repr(nomsu.utils.keys(fn_def.aliases))
| .." ="..(fn_def.src or ":\\n <unknown source code>"))
|end
# Macro helper functions
rule [%tree as value] =:
- lua expr "compiler:tree_to_value(vars.tree, vars)"
+ lua expr "nomsu:tree_to_value(vars.tree, vars)"
rule [%tree as lua] =:
- lua expr "compiler:tree_to_lua(vars.tree)"
+ lua expr "nomsu:tree_to_lua(vars.tree)"
rule [test, foobar] =: lua expr "print('yup')"
# Compiler tools
-rule [eval %code, run %code] =: compiler "run" [%code]
+rule [eval %code, run %code] =: nomsu "run" [%code]
rule [source code from tree %tree] =:
lua block ".."
@@ -119,8 +118,8 @@ rule [source code from tree %tree] =:
|end
macro [source code %body] =:
- compiler "repr" [compiler "call" ["source code from tree %", %body]]
+ nomsu "repr" [nomsu "call" ["source code from tree %", %body]]
macro [parse tree %code] =:
- compiler "repr" [compiler "stringify_tree" [lua expr "vars.code.value"]]
+ nomsu "repr" [nomsu "stringify_tree" [lua expr "vars.code.value"]]
diff --git a/lib/moonscript.nom b/lib/moonscript.nom
index 1b7bf2d..f5a18b5 100644
--- a/lib/moonscript.nom
+++ b/lib/moonscript.nom
@@ -4,27 +4,27 @@ require "lib/metaprogramming.nom"
macro block [moonscript block %moonscript_code] =:
lua block ".."
|local parse, compile = require('moonscript.parse'), require('moonscript.compile')
- |local moon_code = compiler:tree_to_value(vars.moonscript_code, vars)
+ |local moon_code = nomsu:tree_to_value(vars.moonscript_code, vars)
|local tree, err = parse.string(moon_code)
|if not tree then
- | compiler:error("Failed to parse moonscript: "..err)
+ | nomsu:error("Failed to parse moonscript: "..err)
|end
|local lua_code, err, pos = compile.tree(tree)
|if not lua_code then
- | compiler:error(compile.format_error(err, pos, moon_code))
+ | nomsu:error(compile.format_error(err, pos, moon_code))
|end
|return "do\\n"..lua_code.."\\nend"
macro [moonscript %moonscript_code] =:
lua block ".."
|local parse, compile = require('moonscript.parse'), require('moonscript.compile')
- |local moon_code = compiler:tree_to_value(vars.moonscript_code, vars)
+ |local moon_code = nomsu:tree_to_value(vars.moonscript_code, vars)
|local tree, err = parse.string(moon_code)
|if not tree then
- | compiler:error("Failed to parse moonscript: "..err)
+ | nomsu:error("Failed to parse moonscript: "..err)
|end
|local lua_code, err, pos = compile.tree(tree)
|if not lua_code then
- | compiler:error(compile.format_error(err, pos, moon_code))
+ | nomsu:error(compile.format_error(err, pos, moon_code))
|end
- |return "(function(compiler, vars)\\n"..lua_code.."\\nend)(compiler, vars)"
+ |return "(function(nomsu, vars)\\n"..lua_code.."\\nend)(nomsu, vars)"
diff --git a/lib/operators.nom b/lib/operators.nom
index 38e8758..6dadaf3 100644
--- a/lib/operators.nom
+++ b/lib/operators.nom
@@ -11,46 +11,46 @@ macro [%if_expr if %condition else %else_expr] =:
pass # TODO: Fix compiler bug that doesn't parse right here
#.. Note: this uses a function instead of (condition and if_expr or else_expr)
because that breaks if %if_expr is falsey.
- ".."|(function(compiler, vars)
+ ".."|(function(nomsu, vars)
| if \%condition as lua\ then
| return \%if_expr as lua\
| else
| return \%else_expr as lua\
| end
- |end)(compiler, vars)
+ |end)(nomsu, vars)
# Variable assignment operator, and += type versions
lua block ".."
|local function assign(callback)
- | return function(compiler, vars, kind)
+ | return function(nomsu, vars, kind)
| if kind == "Expression" then
- | compiler:error("Cannot use an assignment operation as an expression value.")
+ | nomsu:error("Cannot use an assignment operation as an expression value.")
| end
| if vars.var.type ~= "Var" then
- | compiler:error("Assignment operation has the wrong type for the left hand side. "
+ | nomsu:error("Assignment operation has the wrong type for the left hand side. "
| .."Expected Var, but got: "..vars.var.type.."\\nMaybe you forgot a percent sign on the variable name?")
| end
| if vars.rhs.type ~= "Thunk" then
- | compiler:error("Assignment operation has the wrong type for the right hand side. "
+ | nomsu:error("Assignment operation has the wrong type for the right hand side. "
| .."Expected Thunk, but got: "..vars.rhs.type.."\\nMaybe you used '=' instead of '=:'?")
| end
| if #vars.rhs.value.value > 1 then
- | compiler:error("Assignment operation should not have more than one value on the right hand side.")
+ | nomsu:error("Assignment operation should not have more than one value on the right hand side.")
| end
- | return callback(compiler:tree_to_lua(vars.var),
- | compiler:tree_to_lua(vars.rhs.value.value[1].value)), true
+ | return callback(nomsu:tree_to_lua(vars.var),
+ | nomsu:tree_to_lua(vars.rhs.value.value[1].value)), true
| end
|end
- |compiler:defmacro("%var = %rhs", assign(function(var,result) return var.." = "..result end))
- |compiler:defmacro("%var += %rhs", assign(function(var,result) return var.." = "..var.." + "..result end))
- |compiler:defmacro("%var -= %rhs", assign(function(var,result) return var.." = "..var.." - "..result end))
- |compiler:defmacro("%var *= %rhs", assign(function(var,result) return var.." = "..var.." * "..result end))
- |compiler:defmacro("%var /= %rhs", assign(function(var,result) return var.." = "..var.." / "..result end))
- |compiler:defmacro("%var ^= %rhs", assign(function(var,result) return var.." = "..var.." ^ "..result end))
- |compiler:defmacro("%var and= %rhs", assign(function(var,result) return var.." = "..var.." and "..result end))
- |compiler:defmacro("%var or= %rhs", assign(function(var,result) return var.." = "..var.." or "..result end))
- |compiler:defmacro("%var join= %rhs", assign(function(var,result) return var.." = "..var.." .. "..result end))
- |compiler:defmacro("%var mod= %rhs", assign(function(var,result) return var.." = "..var.." % "..result end))
+ |nomsu:defmacro("%var = %rhs", assign(function(var,result) return var.." = "..result end))
+ |nomsu:defmacro("%var += %rhs", assign(function(var,result) return var.." = "..var.." + "..result end))
+ |nomsu:defmacro("%var -= %rhs", assign(function(var,result) return var.." = "..var.." - "..result end))
+ |nomsu:defmacro("%var *= %rhs", assign(function(var,result) return var.." = "..var.." * "..result end))
+ |nomsu:defmacro("%var /= %rhs", assign(function(var,result) return var.." = "..var.." / "..result end))
+ |nomsu:defmacro("%var ^= %rhs", assign(function(var,result) return var.." = "..var.." ^ "..result end))
+ |nomsu:defmacro("%var and= %rhs", assign(function(var,result) return var.." = "..var.." and "..result end))
+ |nomsu:defmacro("%var or= %rhs", assign(function(var,result) return var.." = "..var.." or "..result end))
+ |nomsu:defmacro("%var join= %rhs", assign(function(var,result) return var.." = "..var.." .. "..result end))
+ |nomsu:defmacro("%var mod= %rhs", assign(function(var,result) return var.." = "..var.." % "..result end))
# Binary Operators
lua block ".."
@@ -60,13 +60,13 @@ lua block ".."
| if type(op) == 'table' then
| nomsu_alias, op = unpack(op)
| end
- | compiler:defmacro("%a "..nomsu_alias.." %b", (function(compiler, vars, kind)
- | return "("..compiler:tree_to_lua(vars.a).." "..op.." "..compiler:tree_to_lua(vars.b)..")"
+ | nomsu:defmacro("%a "..nomsu_alias.." %b", (function(nomsu, vars, kind)
+ | return "("..nomsu:tree_to_lua(vars.a).." "..op.." "..nomsu:tree_to_lua(vars.b)..")"
| end), [[".."|(\\%a as lua\\ ]]..op..[[ \\%b as lua\\)]])
|end
# == and != do equivalence checking, rather than identity checking
-macro [%a == %b] =: ".."|compiler.utils.equivalent(\%a as lua\, \%b as lua\)
-macro [%a != %b] =: ".."|(not compiler.utils.equivalent(\%a as lua\, \%b as lua\))
+macro [%a == %b] =: ".."|nomsu.utils.equivalent(\%a as lua\, \%b as lua\)
+macro [%a != %b] =: ".."|(not nomsu.utils.equivalent(\%a as lua\, \%b as lua\))
# Commutative Operators defined for up to 8 operands
# TODO: work out solution for commutative operators using more clever macros
@@ -78,10 +78,10 @@ lua block ".."
| local spec = "%1 "..op.." %2"
| for n=3,max_operands do
| spec = spec .." "..op.." %"..tostring(n)
- | compiler:defmacro(spec, (function(compiler, vars, kind)
+ | nomsu:defmacro(spec, (function(nomsu, vars, kind)
| local bits = {}
| for i=1,n do
- | table.insert(bits, (compiler:tree_to_lua(vars[tostring(i)])))
+ | table.insert(bits, (nomsu:tree_to_lua(vars[tostring(i)])))
| end
| return "("..table.concat(bits, " "..op.." ")..")"
| end))
@@ -100,7 +100,7 @@ lua block ".."
| spec = spec .. " "..op.." %"..tostring(i+1)
| end
# Chained comparisons need to be functions to avoid re-evaluating their arguments :\
- | compiler:def(spec, function(compiler, vars)
+ | nomsu:def(spec, function(nomsu, vars)
| for i,op in ipairs(chain) do
| local a, b, result = vars[i], vars[i+1]
| if op == "<" then result = a < b
diff --git a/lib/permissions.nom b/lib/permissions.nom
index c4caa14..3bb8f42 100644
--- a/lib/permissions.nom
+++ b/lib/permissions.nom
@@ -6,40 +6,40 @@ require "lib/collections.nom"
# Permission functions
rule [restrict %rules to within %elite-rules] =:
say ".."|Restricting \%rules\ to within \%elite-rules\
- %rules =: keys in (compiler "get_aliases" [%rules])
- %elite-rules =: keys in (compiler "get_aliases" [%elite-rules])
+ %rules =: keys in (nomsu "get_aliases" [%rules])
+ %elite-rules =: keys in (nomsu "get_aliases" [%elite-rules])
for all (flatten [%elite-rules, %rules]):
- assert ((compiler's "defs") has key %it) ".."|Undefined function: \%it\
+ assert ((nomsu's "defs") has key %it) ".."|Undefined function: \%it\
for all %rules:
- assert (compiler "check_permission" [%it]) ".."
+ assert (nomsu "check_permission" [%it]) ".."
|You do not have permission to restrict permissions for function: \%it\
%foo =: dict (..)
[%it, yes] for %it in %elite-rules
- ((compiler's "defs")'s %it)'s "whiteset" =: %foo
+ ((nomsu's "defs")'s %it)'s "whiteset" =: %foo
rule [allow %elite-rules to use %rules] =:
say ".."|Allowing \%elite-rules\ to use \%rules\
- %rules =: keys in (compiler "get_aliases" [%rules])
- %elite-rules =: keys in (compiler "get_aliases" [%elite-rules])
+ %rules =: keys in (nomsu "get_aliases" [%rules])
+ %elite-rules =: keys in (nomsu "get_aliases" [%elite-rules])
for all (flatten [%elite-rules, %rules]):
- assert ((compiler's "defs") has key %it) ".."|Undefined function: \%it\
+ assert ((nomsu's "defs") has key %it) ".."|Undefined function: \%it\
for %fn in %rules:
- assert (compiler "check_permission" [%fn]) ".."
+ assert (nomsu "check_permission" [%fn]) ".."
|You do not have permission to grant permissions for function: \%fn\
- %whiteset =: ((compiler's "defs")'s %fn)'s "whiteset"
+ %whiteset =: ((nomsu's "defs")'s %fn)'s "whiteset"
if (not %whiteset): on to the next %fn
for all %elite-rules: %whiteset's %it =: yes
rule [forbid %pleb-rules to use %rules] =:
say ".."|Forbidding \%pleb-rules\ to use \%rules\
- %rules =: keys in (compiler "get_aliases" [%rules])
- %pleb-rules =: keys in (compiler "get_aliases" [%pleb-rules])
+ %rules =: keys in (nomsu "get_aliases" [%rules])
+ %pleb-rules =: keys in (nomsu "get_aliases" [%pleb-rules])
for all (flatten [%pleb-rules, %used]):
- assert ((compiler's "defs") has key %it) ".."|Undefined function: \%it\
+ assert ((nomsu's "defs") has key %it) ".."|Undefined function: \%it\
for all %rules:
- assert (compiler "check_permission" [%it]) ".."
+ assert (nomsu "check_permission" [%it]) ".."
|You do not have permission to grant permissions for function: \%it\
- %whiteset =: ((compiler's "defs")'s %it)'s "whiteset"
+ %whiteset =: ((nomsu's "defs")'s %it)'s "whiteset"
assert %whiteset ".."
|Cannot individually restrict permissions for \%it\ because it is currently
|available to everyone. Perhaps you meant to use "restrict % to within %" instead?
diff --git a/lib/secrets.nom b/lib/secrets.nom
index 5d9551f..052ee6c 100644
--- a/lib/secrets.nom
+++ b/lib/secrets.nom
@@ -20,14 +20,14 @@ macro [secret %key, secret value of %key, secret value for %key] =:
macro block [secret %key = %new_value] =:
lua block ".."
|if vars.key.type ~= "Var" then
- | compiler:error("Assignment operation has the wrong type for the left hand side. "
+ | nomsu:error("Assignment operation has the wrong type for the left hand side. "
| .."Expected Var, but got: "..vars.key.type)
|end
|if vars.new_value.type ~= "Thunk" then
- | compiler:error("Assignment operation has the wrong type for the right hand side. "
+ | nomsu:error("Assignment operation has the wrong type for the right hand side. "
| .."Expected Thunk, but got: "..vars.new_value.type.."\\nMaybe you used '=' instead of '=:'?")
|end
".."
|local ret
- |\lua expr "compiler:tree_to_lua(vars.new_value.value)"\
+ |\lua expr "nomsu:tree_to_lua(vars.new_value.value)"\
|secrets[\repr (%key's "value")\] = ret
diff --git a/lib/testing.nom b/lib/testing.nom
index 94d9e8e..87a7711 100644
--- a/lib/testing.nom
+++ b/lib/testing.nom
@@ -2,7 +2,7 @@ require "lib/metaprogramming.nom"
# For unit testing
macro block [test %code yields %expected] =:
- %generated =: lua expr "compiler.utils.repr(compiler:stringify_tree(vars.code.value))"
+ %generated =: repr (nomsu "stringify_tree" [%code's "value"])
%expected =: %expected as lua
if (%generated != %expected):
say "Test failed!"
diff --git a/lib/utils.nom b/lib/utils.nom
index 41c5d61..b1e104b 100644
--- a/lib/utils.nom
+++ b/lib/utils.nom
@@ -2,64 +2,64 @@ require "lib/metaprogramming.nom"
# Error functions
rule [error!, panic!, fail!, abort!] =:
- compiler "error"[]
+ nomsu "error"[]
rule [error %msg] =:
- compiler "error"[%msg]
+ nomsu "error"[%msg]
macro statement [assert %condition] =: ".."
|if not (\%condition as lua\) then
- | compiler:error()
+ | nomsu:error()
|end
macro statement [assert %condition %msg] =: ".."
|if not (\%condition as lua\) then
- | compiler:error(\%msg as lua\)
+ | nomsu:error(\%msg as lua\)
|end
macro statement [show generated lua %block] =: ".."
- |compiler:writeln(\lua expr "compiler:repr(compiler:tree_to_lua(vars.block.value))"\)
+ |nomsu:writeln(\lua expr "nomsu:repr(nomsu:tree_to_lua(vars.block.value))"\)
# String functions
rule [join %strs] =:
lua block ".."
|local str_bits = {}
- |for i,bit in ipairs(vars.strs) do str_bits[i] = compiler.utils.repr_if_not_string(bit) end
+ |for i,bit in ipairs(vars.strs) do str_bits[i] = nomsu.utils.repr_if_not_string(bit) end
|return table.concat(str_bits)
rule [join %strs with glue %glue] =:
lua block ".."
|local str_bits = {}
- |for i,bit in ipairs(vars.strs) do str_bits[i] = compiler.utils.repr_if_not_string(bit) end
+ |for i,bit in ipairs(vars.strs) do str_bits[i] = nomsu.utils.repr_if_not_string(bit) end
|return table.concat(str_bits, vars.glue)
macro [capitalize %str, %str capitalized] =: ".."
|(\%str as lua\):gsub("%l", string.upper, 1)
macro [repr %obj] =:
- ".."|compiler:repr(\%obj as lua\)
+ ".."|nomsu:repr(\%obj as lua\)
macro [%obj as string] =:
- ".."|compiler.utils.repr_if_not_string(\%obj as lua\)
+ ".."|nomsu.utils.repr_if_not_string(\%obj as lua\)
macro [say %str] =:
- ".."|compiler:writeln(compiler.utils.repr_if_not_string(\%str as lua\))
+ ".."|nomsu:writeln(nomsu.utils.repr_if_not_string(\%str as lua\))
# Number ranges
macro [%start up to %stop] =: ".."
- |compiler.utils.range(\%start as lua\, \%stop as lua\-1)
+ |nomsu.utils.range(\%start as lua\, \%stop as lua\-1)
macro [%start thru %stop, %start through %stop] =: ".."
- |compiler.utils.range(\%start as lua\, \%stop as lua\)
+ |nomsu.utils.range(\%start as lua\, \%stop as lua\)
macro [%start down to %stop] =: ".."
- |compiler.utils.range(\%start as lua\, \%stop as lua\+1,-1)
+ |nomsu.utils.range(\%start as lua\, \%stop as lua\+1,-1)
macro [%start down thru %stop, %start down through %stop] =: ".."
- |compiler.utils.range(\%start as lua\, \%stop as lua\,-1)
+ |nomsu.utils.range(\%start as lua\, \%stop as lua\,-1)
macro [%start up to %stop via %step] =: ".."
- |compiler.utils.range(\%start as lua\,\%stop as lua\-1,vars.step)
+ |nomsu.utils.range(\%start as lua\,\%stop as lua\-1,vars.step)
macro [%start thru %stop via %step, %start through %stop via %step] =: ".."
- |compiler.utils.range(\%start as lua\,\%stop as lua\,vars.step)
+ |nomsu.utils.range(\%start as lua\,\%stop as lua\,vars.step)
macro [%start down to %stop via %step] =: ".."
- |compiler.utils.range(\%start as lua\,\%stop as lua\+1,-vars.step)
+ |nomsu.utils.range(\%start as lua\,\%stop as lua\+1,-vars.step)
macro [%start down thru %stop via %step, %start down through %stop via %step] =: ".."
- |compiler.utils.range(\%start as lua\,\%stop as lua\,-vars.step)
+ |nomsu.utils.range(\%start as lua\,\%stop as lua\,-vars.step)
# Common utility functions
macro [random number, random, rand] =: "math.random()"
@@ -68,18 +68,18 @@ macro [random from %low to %high, random number from %low to %high, rand %low %h
|math.random(\%low as lua\, \%high as lua\)
rule [random choice from %elements, random choice %elements, random %elements] =:
lua expr ".."|vars.elements[math.random(#vars.elements)]
-macro [sum of %items, sum %items] =: ".."|compiler.utils.sum(\%items as lua\)
-macro [product of %items, product %items] =: ".."|compiler.utils.product(\%items as lua\)
-macro [all of %items] =: ".."|compiler.utils.all(\%items as lua\)
-macro [any of %items] =: ".."|compiler.utils.any(\%items as lua\)
+macro [sum of %items, sum %items] =: ".."|nomsu.utils.sum(\%items as lua\)
+macro [product of %items, product %items] =: ".."|nomsu.utils.product(\%items as lua\)
+macro [all of %items] =: ".."|nomsu.utils.all(\%items as lua\)
+macro [any of %items] =: ".."|nomsu.utils.any(\%items as lua\)
# This is a rule, not a macro so we can use vars.items twice without running it twice.
rule [avg of %items, average of %items] =:
- lua expr ".."|(compiler.utils.sum(vars.items)/#vars.items)
+ lua expr ".."|(nomsu.utils.sum(vars.items)/#vars.items)
macro [min of %items, smallest of %items, lowest of %items] =:
- ".."|compiler.utils.min(\%items as lua\)
+ ".."|nomsu.utils.min(\%items as lua\)
macro [max of %items, biggest of %items, largest of %items, highest of %items] =:
- ".."|compiler.utils.min(\%items as lua\)
+ ".."|nomsu.utils.min(\%items as lua\)
macro [min of %items with respect to %keys] =:
- ".."|compiler.utils.min(\%items as lua\, \%keys as lua\)
+ ".."|nomsu.utils.min(\%items as lua\, \%keys as lua\)
macro [max of %items with respect to %keys] =:
- ".."|compiler.utils.max(\%items as lua\, \%keys as lua\)
+ ".."|nomsu.utils.max(\%items as lua\, \%keys as lua\)