aboutsummaryrefslogtreecommitdiff
path: root/nomsu.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-15 16:36:21 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-15 16:36:38 -0700
commit01aa199f7acfe9af57c5970793259b36e060fd11 (patch)
tree0af9fd009d820053f83dd60eed862886bfb3eb5c /nomsu.moon
parent28cd9ae0b7a09d8f2cd0cd929f1ebdce4b081502 (diff)
Adding support for coroutines, and cleaning up comment syntax.
Diffstat (limited to 'nomsu.moon')
-rwxr-xr-xnomsu.moon22
1 files changed, 20 insertions, 2 deletions
diff --git a/nomsu.moon b/nomsu.moon
index bd15a08..21aff00 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -11,13 +11,13 @@
-- Or from the command line:
-- lua nomsu.lua [input_file [output_file or -]]
export lpeg, re
+_pairs, _ipairs = pairs, ipairs
if jit
package.cpath = "./luajit_lpeg/?.so;"..package.cpath
export bit32
bit32 = require('bit')
- _pairs, _ipairs = pairs, ipairs
export pairs, ipairs
pairs = (x)->
if mt = getmetatable(x)
@@ -259,6 +259,24 @@ class NomsuCompiler
return mt.__len(x)
return #x
else ((x) -> #x)
+ @environment.ipairs = (x)->
+ if type(x) == 'function'
+ return coroutine.wrap(x)
+ elseif type(x) == 'thread'
+ return coroutine.resume, x, nil
+ elseif mt = getmetatable(x)
+ if mt.__ipairs
+ return mt.__ipairs(x)
+ else return _ipairs(x)
+ @environment.pairs = (x)->
+ if type(x) == 'function'
+ return coroutine.wrap(x)
+ elseif type(x) == 'thread'
+ return coroutine.resume, x, nil
+ elseif mt = getmetatable(x)
+ if mt.__pairs
+ return mt.__pairs(x)
+ else return _pairs(x)
for k,v in pairs(Types) do @environment[k] = v
@environment.Tuple = Tuple
@environment.Lua = Lua
@@ -422,7 +440,7 @@ class NomsuCompiler
else @walk_tree(tree.value, depth+1)
return nil
- tree_with_replaced_vars: (tree, replacements)=>
+ tree_with_replacements: (tree, replacements)=>
return tree unless next(replacements)
if next(replacements).type == "Var"
replacements = {tostring(k\as_lua(@)),v for k,v in pairs(replacements)}