aboutsummaryrefslogtreecommitdiff
path: root/ps/step6_file.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/step6_file.ps
parent8adb082743f12402d0817018ab1e8ff0c0e4729e (diff)
downloadmal-0027e8fed423a24ec93234a6bf0fb701c233d583.tar.gz
mal-0027e8fed423a24ec93234a6bf0fb701c233d583.zip
PS: fix function closures. Self-hosted up to step7.
Diffstat (limited to 'ps/step6_file.ps')
-rw-r--r--ps/step6_file.ps23
1 files changed, 7 insertions, 16 deletions
diff --git a/ps/step6_file.ps b/ps/step6_file.ps
index 1eff14f..fc12cc1 100644
--- a/ps/step6_file.ps
+++ b/ps/step6_file.ps
@@ -90,27 +90,18 @@ end } def
}{ /fn* a0 eq { %if fn*
/a1 ast 1 _nth def
/a2 ast 2 _nth def
- <<
- /_maltype_ /function % user defined function
- /params null % close over parameters
- /ast null % close over ast
- /env null % close over environment
- /data { __self__ fload EVAL }
- >>
- dup length dict copy % make an actual copy/new instance
- dup /params a1 put % insert closed over a1 into position 2
- dup /ast a2 put % insert closed over a2 into position 3
- dup /env env put % insert closed over env into position 4
- dup dup /data get exch 0 exch put % insert self reference
+ a2 env a1 _mal_function
}{
/el ast env eval_ast def
el _rest el _first % stack: ast function
- dup _mal_function? { % if user defined function
+ dup _mal_function? { %if user defined function
fload % stack: ast new_env
/loop? true def
+ }{ dup _function? { %else if builtin function
+ /data get exec
}{ %else (regular procedure/function)
- exec % apply function to args
- } ifelse
+ (cannot apply native proc!\n) print quit
+ } ifelse } ifelse
} ifelse } ifelse } ifelse } ifelse } ifelse
} ifelse
@@ -130,7 +121,7 @@ end } def
/RE { READ repl_env EVAL } def
/REP { READ repl_env EVAL PRINT } def
-/_ref { repl_env 3 1 roll env_set pop } def
+/_ref { _function repl_env 3 1 roll env_set pop } def
core_ns { _ref } forall