2017-07-03 10:29:21 +03:00
|
|
|
Object subclass: Env [
|
|
|
|
| data outer |
|
|
|
|
|
|
|
|
Env class >> new: outerEnv [
|
2017-07-05 10:15:41 +03:00
|
|
|
^self new: outerEnv binds: {} exprs: {}
|
|
|
|
]
|
|
|
|
|
|
|
|
Env class >> new: outerEnv binds: binds exprs: exprs [
|
2017-07-03 10:29:21 +03:00
|
|
|
| env |
|
|
|
|
env := super new.
|
2017-07-05 10:15:41 +03:00
|
|
|
env init: outerEnv binds: binds exprs: exprs.
|
2017-07-03 10:29:21 +03:00
|
|
|
^env
|
|
|
|
]
|
|
|
|
|
2017-07-05 10:15:41 +03:00
|
|
|
init: env binds: binds exprs: exprs [
|
2017-07-03 10:29:21 +03:00
|
|
|
data := Dictionary new.
|
|
|
|
outer := env.
|
2017-07-05 10:15:41 +03:00
|
|
|
1 to: binds size do:
|
|
|
|
[ :i | (binds at: i) = #& ifTrue: [
|
|
|
|
| rest |
|
2017-07-09 23:51:15 +03:00
|
|
|
rest := OrderedCollection from: (exprs copyFrom: i).
|
|
|
|
self set: (binds at: i + 1) value: (MALList new: rest).
|
2017-07-05 10:15:41 +03:00
|
|
|
^nil
|
|
|
|
] ifFalse: [
|
|
|
|
self set: (binds at: i) value: (exprs at: i)
|
|
|
|
] ]
|
2017-07-03 10:29:21 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
set: key value: value [
|
|
|
|
data at: key put: value.
|
|
|
|
]
|
|
|
|
|
2022-01-10 02:15:40 +03:00
|
|
|
get: key [
|
2017-07-03 10:29:21 +03:00
|
|
|
^data at: key ifAbsent: [
|
2022-01-10 02:15:40 +03:00
|
|
|
outer isNil ifFalse: [
|
|
|
|
outer get: key
|
2017-07-03 10:29:21 +03:00
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|