aboutsummaryrefslogtreecommitdiff
path: root/code_obj.moon
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-01 15:05:58 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-01 15:07:10 -0800
commitb6d3cbd61cd08e39d20a569b7c5ece6bb25897dd (patch)
treeccf3930b7a2834ffad1a10a9d91f0042542dec34 /code_obj.moon
parent0760d4fb6495c4aa4f74038457acede5063f514a (diff)
Misc changes, including text indented interpolations are now indented
relative to the text, not the opening '("', code objects can now remove all free vars, the REPL uses global vars. Error API is changing a bit.
Diffstat (limited to 'code_obj.moon')
-rw-r--r--code_obj.moon28
1 files changed, 16 insertions, 12 deletions
diff --git a/code_obj.moon b/code_obj.moon
index bdce010..9315264 100644
--- a/code_obj.moon
+++ b/code_obj.moon
@@ -179,7 +179,8 @@ class LuaCode extends Code
seen[var] = true
@dirty!
- remove_free_vars: (vars)=>
+ remove_free_vars: (vars=nil)=>
+ vars or= @get_free_vars!
return unless #vars > 0
removals = {}
for var in *vars
@@ -198,18 +199,21 @@ class LuaCode extends Code
stack[#stack+1] = b
@dirty!
+ get_free_vars: =>
+ vars, seen = {}, {}
+ gather_from = =>
+ for var in *@free_vars
+ unless seen[var]
+ seen[var] = true
+ vars[#vars+1] = var
+ for bit in *@bits
+ unless type(bit) == 'string'
+ gather_from bit
+ gather_from self
+ return vars
+
declare_locals: (to_declare=nil)=>
- if to_declare == nil
- to_declare, seen = {}, {}
- gather_from = =>
- for var in *@free_vars
- unless seen[var]
- seen[var] = true
- to_declare[#to_declare+1] = var
- for bit in *@bits
- unless type(bit) == 'string'
- gather_from bit
- gather_from self
+ to_declare or= @get_free_vars!
if #to_declare > 0
@remove_free_vars to_declare
@prepend "local #{concat to_declare, ", "};\n"