mirror of
https://github.com/kanaka/mal.git
synced 2024-10-27 14:52:16 +03:00
8a19f60386
- Reorder README to have implementation list after "learning tool" bullet. - This also moves tests/ and libs/ into impls. It would be preferrable to have these directories at the top level. However, this causes difficulties with the wasm implementations which need pre-open directories and have trouble with paths starting with "../../". So in lieu of that, symlink those directories to the top-level. - Move the run_argv_test.sh script into the tests directory for general hygiene.
43 lines
1000 B
Scala
43 lines
1000 B
Scala
import types._list
|
|
|
|
import scala.collection.mutable
|
|
|
|
object env {
|
|
class Env(outer: Env = null,
|
|
binds: Iterator[Any] = null,
|
|
exprs: Iterator[Any] = null) {
|
|
val data: mutable.Map[Symbol, Any] = mutable.Map()
|
|
if (binds != null && exprs != null) {
|
|
binds.foreach(b => {
|
|
val k = b.asInstanceOf[Symbol]
|
|
if (k == '&) {
|
|
data(binds.next().asInstanceOf[Symbol]) = _list(exprs.toSeq:_*)
|
|
} else {
|
|
data(k) = exprs.next()
|
|
}
|
|
})
|
|
}
|
|
|
|
def find(key: Symbol): Env = {
|
|
if (data.contains(key)) {
|
|
this
|
|
} else if (outer != null) {
|
|
outer.find(key)
|
|
} else {
|
|
null
|
|
}
|
|
}
|
|
def set(key: Symbol, value: Any): Any = {
|
|
data(key) = value
|
|
value
|
|
}
|
|
def get(key: Symbol): Any = {
|
|
val env = find(key)
|
|
if (env == null) throw new Exception("'" + key.name + "' not found")
|
|
env.data(key)
|
|
}
|
|
}
|
|
}
|
|
|
|
// vim:ts=2:sw=2
|