aboutsummaryrefslogtreecommitdiffstats
path: root/scope.moon
diff options
context:
space:
mode:
Diffstat (limited to 'scope.moon')
-rw-r--r--scope.moon45
1 files changed, 5 insertions, 40 deletions
diff --git a/scope.moon b/scope.moon
index 2ca81b4..01f479b 100644
--- a/scope.moon
+++ b/scope.moon
@@ -1,46 +1,12 @@
-import Const, Op, Macro from require 'base'
-
-ancestor = (klass) ->
- assert klass, "cant find the ancestor of nil"
- while klass.__parent
- klass = klass.__parent
- klass
-
-local Scope
-
-constify = (val, key) ->
- typ = switch type val
- when 'number' then 'num'
- when 'string' then 'str'
- when 'table'
- if base = rawget val, '__base'
- -- a class
- switch ancestor val
- when Op then 'opdef'
- when Macro then 'macrodef'
- else
- error "#{key}: cannot constify klass '#{val.__name}'"
- elseif klass = val.__class
- -- an instance
- switch ancestor klass
- when Op then 'op'
- when Scope then 'scope'
- when Const
- return val
- else
- error "#{key}: cannot constify '#{klass.__name}' instance"
- else
- return Const 'scope', Scope.from_table val
- else
- error "#{key}: cannot constify Lua type '#{type val}'"
-
- Const typ, val
+local Const
class Scope
new: (@node, @parent) =>
+ import Const from require 'base'
+
@values = {}
- set_raw: (key, val) => @values[key] = constify val, key
+ set_raw: (key, val) => @values[key] = Const.wrap val, key
set: (key, val) =>
L\trace "setting #{key} = #{val}"
@values[key] = val
@@ -66,7 +32,7 @@ class Scope
from_table: (tbl) ->
with Scope!
- .values = { k, constify v, k for k,v in pairs tbl }
+ .values = { k, Const.wrap v, k for k,v in pairs tbl }
__tostring: =>
buf = "<Scope"
@@ -84,7 +50,6 @@ class Scope
buf ..= ">"
buf
-
{
:Scope
}