aboutsummaryrefslogtreecommitdiff
path: root/nomsu.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-30 13:46:40 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-30 13:46:54 -0700
commit624fcdcc7e8502cd8f0dc4c51669e5d1de7811b9 (patch)
treea3391aac7d1b6e286464aecd24b0df6fddf3c63a /nomsu.moon
parent0afcb416bcdb768c029e724ba08a900e7e95ee52 (diff)
Moved as_lua_id() onto 'string'
Diffstat (limited to 'nomsu.moon')
-rwxr-xr-xnomsu.moon9
1 files changed, 6 insertions, 3 deletions
diff --git a/nomsu.moon b/nomsu.moon
index 8475ced..1d2bff9 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -52,6 +52,10 @@ debug_getinfo = debug.getinfo
{:Nomsu, :Lua, :Source} = require "code_obj"
STDIN, STDOUT, STDERR = "/dev/fd/0", "/dev/fd/1", "/dev/fd/2"
+string.as_lua_id = (str)->
+ "_"..(str\gsub("%W", (c)-> if c == "_" then "__" else ("_%x")\format(c\byte!)))
+
+
-- TODO:
-- consider non-linear codegen, rather than doing thunks for things like comprehensions
-- type checking?
@@ -308,7 +312,7 @@ class NomsuCompiler
stub = concat(assert(stub_pattern\match(alias)), ' ')
stub_args = assert(var_pattern\match(alias))
(is_compile_action and @environment.COMPILE_ACTIONS or @environment.ACTIONS)[stub] = fn
- arg_orders[stub] = [fn_arg_positions[Types.Var.as_lua_id {value:a}] for a in *stub_args]
+ arg_orders[stub] = [fn_arg_positions[string.as_lua_id a] for a in *stub_args]
@environment.ARG_ORDERS[fn] = arg_orders
define_compile_action: (signature, fn)=>
@@ -641,12 +645,11 @@ class NomsuCompiler
Lua.Value(tree.source, tostring(tree.value))
when "Var"
- Lua.Value(tree.source, tree\as_lua_id!)
+ Lua.Value(tree.source, string.as_lua_id(tree.value))
else
error("Unknown type: #{tree.type}")
-
tree_to_nomsu: (tree, inline=false, can_use_colon=false)=>
switch tree.type
when "Action"