diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-14 22:46:54 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-14 22:46:54 -0500 |
| commit | 0027e8fed423a24ec93234a6bf0fb701c233d583 (patch) | |
| tree | c1c447a16958fc174f15af15c181b1582506d9ed /ps/step7_quote.ps | |
| parent | 8adb082743f12402d0817018ab1e8ff0c0e4729e (diff) | |
| download | mal-0027e8fed423a24ec93234a6bf0fb701c233d583.tar.gz mal-0027e8fed423a24ec93234a6bf0fb701c233d583.zip | |
PS: fix function closures. Self-hosted up to step7.
Diffstat (limited to 'ps/step7_quote.ps')
| -rw-r--r-- | ps/step7_quote.ps | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/ps/step7_quote.ps b/ps/step7_quote.ps index 4708aa0..6913bf6 100644 --- a/ps/step7_quote.ps +++ b/ps/step7_quote.ps @@ -122,28 +122,19 @@ 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 - } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse + (cannot apply native proc!\n) print quit + } ifelse } ifelse + } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse loop? not { exit } if @@ -162,7 +153,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 |
