aboutsummaryrefslogtreecommitdiff
path: root/ps/core.ps
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-14 22:46:54 -0500
committerJoel Martin <github@martintribe.org>2014-04-14 22:46:54 -0500
commit0027e8fed423a24ec93234a6bf0fb701c233d583 (patch)
treec1c447a16958fc174f15af15c181b1582506d9ed /ps/core.ps
parent8adb082743f12402d0817018ab1e8ff0c0e4729e (diff)
downloadmal-0027e8fed423a24ec93234a6bf0fb701c233d583.tar.gz
mal-0027e8fed423a24ec93234a6bf0fb701c233d583.zip
PS: fix function closures. Self-hosted up to step7.
Diffstat (limited to 'ps/core.ps')
-rw-r--r--ps/core.ps24
1 files changed, 17 insertions, 7 deletions
diff --git a/ps/core.ps b/ps/core.ps
index afda426..590388a 100644
--- a/ps/core.ps
+++ b/ps/core.ps
@@ -40,12 +40,17 @@ end } def
% [hashmap key] -> hash_map_get -> value
/hash_map_get {
- dup 0 _nth /data get % stack: args dict
- exch 1 _nth % stack: dict key
- 2 copy known { %if has key
- get
- }{
+ dup 0 _nth % stack: args hash_map
+ dup null eq { %if hash_map is a nil
pop pop null
+ }{ %else hash_map is not a nil
+ /data get % stack: args dict
+ exch 1 _nth % stack: dict key
+ 2 copy known { %if has key
+ get
+ }{
+ pop pop null
+ } ifelse
} ifelse
} def
@@ -172,7 +177,12 @@ end } def
% [obj] -> meta -> meta
/meta {
- 0 _nth dup /meta known { /meta get }{ null } ifelse
+ 0 _nth % stack: obj
+ dup type /dicttype eq { %if dictionary
+ dup /meta known { /meta get }{ null } ifelse
+ }{ %else
+ pop null % no meta on non-collections
+ } ifelse
} def
@@ -196,7 +206,7 @@ end } def
[ atm /data get ]
args 2 args _count 2 sub _slice /data get
concatenate _list_from_array
- args 1 _nth callable % make sure function is callable
+ args 1 _nth callable % extract proc
exec
/new_val exch def
atm /data new_val put