1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-10 12:47:45 +03:00
mal/coffee/env.coffee

25 lines
609 B
CoffeeScript
Raw Normal View History

types = require "./types.coffee"
# Env
exports.Env = class Env
constructor: (@outer=null, @binds=[], @exprs=[]) ->
@data = {}
if @binds.length > 0
for b,i in @binds
if types._symbol_Q(b) && b.name == "&"
@data[@binds[i+1].name] = exprs[i..]
break
else
@data[b.name] = exprs[i]
find: (key) ->
if key of @data then @
else if @outer then @outer.find(key)
else null
set: (key, value) -> @data[key] = value
get: (key) ->
env = @find(key)
throw new Error("'" + key + "' not found") if !env
env.data[key]
# vim: ts=2:sw=2