aboutsummaryrefslogtreecommitdiff
path: root/ps/step6_file.ps
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-06 15:23:40 -0500
committerJoel Martin <github@martintribe.org>2014-04-06 15:23:40 -0500
commit5ce65382cf4bdece30e9dee3f7765b698bd375e9 (patch)
tree454089f5d1ea4ff1a2d78cf00e5c23397cac3065 /ps/step6_file.ps
parentea81a8087bcd7953b083a2be9db447f75e7ebf56 (diff)
downloadmal-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/step6_file.ps')
-rw-r--r--ps/step6_file.ps60
1 files changed, 33 insertions, 27 deletions
diff --git a/ps/step6_file.ps b/ps/step6_file.ps
index f6f4377..1eff14f 100644
--- a/ps/step6_file.ps
+++ b/ps/step6_file.ps
@@ -20,15 +20,21 @@
%(eval_ast: ) print ast ==
ast _symbol? { %if symbol
env ast env_get
- }{ 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 { 13 dict begin
@@ -42,50 +48,50 @@ end } def
ast _list? not { %if not a list
ast env eval_ast
}{ %else apply the list
- /a0 ast 0 get def
+ /a0 ast 0 _nth def
/def! a0 eq { %if def!
- /a1 ast 1 get def
- /a2 ast 2 get def
+ /a1 ast 1 _nth def
+ /a2 ast 2 _nth def
env a1 a2 env EVAL env_set
}{ /let* a0 eq { %if let*
- /a1 ast 1 get def
- /a2 ast 2 get def
- /let_env env [ ] [ ] env_new def
- 0 2 a1 length 1 sub { %for each pair
+ /a1 ast 1 _nth def
+ /a2 ast 2 _nth def
+ /let_env env null null env_new def
+ 0 2 a1 _count 1 sub { %for each pair
/idx exch def
let_env
- a1 idx get
- a1 idx 1 add get let_env EVAL
+ a1 idx _nth
+ a1 idx 1 add _nth let_env EVAL
env_set
pop % discard the return value
} for
a2 let_env EVAL
}{ /do a0 eq { %if do
- ast length 2 gt { %if ast has more than 2 elements
- ast 1 ast length 2 sub getinterval env eval_ast pop
+ ast _count 2 gt { %if ast has more than 2 elements
+ ast 1 ast _count 2 sub _slice env eval_ast pop
} if
- ast ast length 1 sub get % last ast becomes new ast
+ ast ast _count 1 sub _nth % last ast becomes new ast
env
/loop? true def % loop
}{ /if a0 eq { %if if
- /a1 ast 1 get def
+ /a1 ast 1 _nth def
/cond a1 env EVAL def
cond null eq cond false eq or { % if cond is nil or false
- ast length 3 gt { %if false branch with a3
- ast 3 get env
+ ast _count 3 gt { %if false branch with a3
+ ast 3 _nth env
/loop? true def
}{ % else false branch with no a3
null
} ifelse
}{ % true branch
- ast 2 get env
+ ast 2 _nth env
/loop? true def
} ifelse
}{ /fn* a0 eq { %if fn*
- /a1 ast 1 get def
- /a2 ast 2 get def
+ /a1 ast 1 _nth def
+ /a2 ast 2 _nth def
<<
- /type /_maltype_function % user defined function
+ /_maltype_ /function % user defined function
/params null % close over parameters
/ast null % close over ast
/env null % close over environment
@@ -120,7 +126,7 @@ end } def
% repl
-/repl_env null [ ] [ ] env_new def
+/repl_env null null null env_new def
/RE { READ repl_env EVAL } def
/REP { READ repl_env EVAL PRINT } def
@@ -128,10 +134,10 @@ end } def
core_ns { _ref } forall
-(read-string) { 0 get read_str } _ref
-(eval) { 0 get repl_env EVAL } _ref
+(read-string) { 0 _nth read_str } _ref
+(eval) { 0 _nth repl_env EVAL } _ref
/slurp { (r) file dup bytesavailable string readstring pop } def
-(slurp) { 0 get slurp } _ref
+(slurp) { 0 _nth slurp } _ref
(\(def! not \(fn* \(a\) \(if a false true\)\)\)) RE pop
(\(def! load-file \(fn* \(f\) \(eval \(read-string \(str "\(do " \(slurp f\) "\)"\)\)\)\)\)) RE pop