aboutsummaryrefslogtreecommitdiffstats
path: root/core/scope.moon
diff options
context:
space:
mode:
Diffstat (limited to 'core/scope.moon')
-rw-r--r--core/scope.moon11
1 files changed, 8 insertions, 3 deletions
diff --git a/core/scope.moon b/core/scope.moon
index f795f97..5e73f64 100644
--- a/core/scope.moon
+++ b/core/scope.moon
@@ -1,7 +1,7 @@
import Result, Value from require 'core.value'
class Scope
- new: (@node, @parent) =>
+ new: (@parent, @dynamic_parent) =>
@values = {}
set_raw: (key, val) =>
@@ -11,8 +11,14 @@ class Scope
set: (key, val) =>
L\trace "setting #{key} = #{val} in #{@}"
assert val.__class == Result, "expected #{key}=#{val} to be Result"
+ assert not @values[key], "cannot redefine symbol #{key}!"
@values[key] = val
+ recurse: (key) =>
+ parent = if key\match '^%*.*%*$' then @dynamic_parent else @parent
+ parent or= @parent
+ return parent and L\push parent\get, key
+
get: (key, prefix='') =>
L\debug "checking for #{key} in #{@}"
if val = @values[key]
@@ -22,7 +28,7 @@ class Scope
start, rest = key\match '^(.-)/(.+)'
if not start
- return @parent and L\push -> @parent\get key
+ return @recurse key
child = @get start
assert child and child.value.type == 'scope', "#{start} is not a scope (looking for #{key})"
@@ -40,7 +46,6 @@ class Scope
__tostring: =>
buf = "<Scope"
- buf ..= "@#{@node}" if @node
depth = -1
parent = @parent