diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-06 15:23:40 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-06 15:23:40 -0500 |
| commit | 5ce65382cf4bdece30e9dee3f7765b698bd375e9 (patch) | |
| tree | 454089f5d1ea4ff1a2d78cf00e5c23397cac3065 /ps/step2_eval.ps | |
| parent | ea81a8087bcd7953b083a2be9db447f75e7ebf56 (diff) | |
| download | mal-5ce65382cf4bdece30e9dee3f7765b698bd375e9.tar.gz mal-5ce65382cf4bdece30e9dee3f7765b698bd375e9.zip | |
PS: add vector, hash-map, atoms and metadata.
As part of this lists switch from being a postscript array to being
a mal boxed type (dictionary with type in the /_maltype_ key).
Diffstat (limited to 'ps/step2_eval.ps')
| -rw-r--r-- | ps/step2_eval.ps | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/ps/step2_eval.ps b/ps/step2_eval.ps index 7b03a99..d5c956b 100644 --- a/ps/step2_eval.ps +++ b/ps/step2_eval.ps @@ -20,24 +20,31 @@ env ast known { env ast get }{ - (') ast pr_str (' not found) - concatenate concatenate throw + (') ast false _pr_str (' not found) + concatenate concatenate _throw } ifelse - }{ ast _list? { %elseif list + }{ ast _sequential? { %elseif list or vector [ - ast { + ast /data get { %forall items env EVAL } forall - ] + ] ast _list? { _list_from_array }{ _vector_from_array } ifelse + }{ ast _hash_map? { %elseif list or vector + << + ast /data get { %forall entries + env EVAL + } forall + >> _hash_map_from_dict }{ % else ast - } ifelse } ifelse + } ifelse } ifelse } ifelse end } def /EVAL { 3 dict begin /env exch def /ast exch def - %(EVAL: ) print ast == + + %(EVAL: ) print ast true _pr_str print (\n) print ast _list? not { %if not a list ast env eval_ast }{ %else apply the list @@ -56,10 +63,10 @@ end } def % repl /repl_env << - (+) { dup 0 get exch 1 get add } - (-) { dup 0 get exch 1 get sub } - (*) { dup 0 get exch 1 get mul } - (/) { dup 0 get exch 1 get idiv } + (+) { dup 0 _nth exch 1 _nth add } + (-) { dup 0 _nth exch 1 _nth sub } + (*) { dup 0 _nth exch 1 _nth mul } + (/) { dup 0 _nth exch 1 _nth idiv } >> def /REP { READ repl_env EVAL PRINT } def |
