2014-04-07 00:23:40 +04:00
|
|
|
% outer binds exprs -> env_new -> new_env
|
|
|
|
/env_new { 3 dict begin
|
|
|
|
%(in env_new\n) print
|
|
|
|
/exprs exch dup _sequential? { /data get }{ pop [ ] } ifelse def
|
|
|
|
/binds exch dup _sequential? { /data get }{ pop [ ] } ifelse def
|
|
|
|
/outer exch def
|
|
|
|
<<
|
|
|
|
/__outer__ outer
|
|
|
|
0 1 binds length 1 sub {
|
|
|
|
/idx exch def
|
|
|
|
binds idx get (&) eq { %if &
|
|
|
|
binds idx 1 add get % key
|
|
|
|
exprs idx exprs length idx sub getinterval % value
|
|
|
|
_list_from_array
|
|
|
|
exit
|
|
|
|
} if
|
|
|
|
binds idx get % key
|
|
|
|
exprs idx get % value
|
|
|
|
} for
|
|
|
|
>>
|
|
|
|
end } def
|
|
|
|
|
2014-04-15 07:46:54 +04:00
|
|
|
% env key -> env_find -> env
|
|
|
|
% env key -> env_find -> null
|
2014-04-07 00:23:40 +04:00
|
|
|
/env_find { 2 dict begin
|
|
|
|
/key exch def
|
|
|
|
/env exch def
|
|
|
|
env key known { %if key in env
|
|
|
|
env
|
|
|
|
}{ env /__outer__ get null ne { %elseif __outer__ not null
|
|
|
|
env /__outer__ get key env_find
|
|
|
|
}{ %else
|
|
|
|
null
|
|
|
|
} ifelse } ifelse
|
|
|
|
end } def
|
|
|
|
|
2014-04-15 07:46:54 +04:00
|
|
|
% env key val -> env_set -> val
|
|
|
|
/env_set {
|
|
|
|
dup 4 1 roll % stack: val env key val
|
|
|
|
put % stack: val
|
|
|
|
} def
|
2014-04-07 00:23:40 +04:00
|
|
|
|
2014-04-15 07:46:54 +04:00
|
|
|
/env_get {
|
|
|
|
dup 3 1 roll % stack: key env key
|
|
|
|
env_find % stack: key env/null
|
2014-04-07 00:23:40 +04:00
|
|
|
dup null eq {
|
2014-04-15 07:46:54 +04:00
|
|
|
pop % stack: key
|
|
|
|
(') exch % stack: (') key
|
|
|
|
dup length string cvs
|
2014-04-07 00:23:40 +04:00
|
|
|
(' not found)
|
|
|
|
concatenate concatenate
|
|
|
|
_throw
|
|
|
|
}{
|
2014-04-15 07:46:54 +04:00
|
|
|
exch % stack: env key
|
|
|
|
get
|
2014-04-07 00:23:40 +04:00
|
|
|
} ifelse
|
2014-04-15 07:46:54 +04:00
|
|
|
} def
|