diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-01 21:50:24 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-01 21:50:24 -0500 |
| commit | 950e3c765e30648de34cfc4f65fffdce06f0727f (patch) | |
| tree | 3e66b70a71a5cfa01671830d80d7ea7926509b2d /ps/step9_interop.ps | |
| parent | 704194e12c5080f5c6842416a78fe7efa09da068 (diff) | |
| download | mal-950e3c765e30648de34cfc4f65fffdce06f0727f.tar.gz mal-950e3c765e30648de34cfc4f65fffdce06f0727f.zip | |
PS: add stepA_more.
Sync other steps. In particular, self reference in function definition
and putting readline into _readline function.
Diffstat (limited to 'ps/step9_interop.ps')
| -rw-r--r-- | ps/step9_interop.ps | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/ps/step9_interop.ps b/ps/step9_interop.ps index 5ccadf5..743422b 100644 --- a/ps/step9_interop.ps +++ b/ps/step9_interop.ps @@ -2,6 +2,8 @@ (reader.ps) run % read +/_readline { print flush (%stdin) (r) file 99 string readline } def + /READ { /str exch def str read_str @@ -172,18 +174,21 @@ end } def /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 }{ /el ast env eval_ast def - el _first _mal_function? { % if user defined function - el _rest el _first fload % stack: ast new_env + el _rest el _first % stack: ast function + dup _mal_function? { % if user defined function + fload % stack: ast new_env /loop? true def }{ %else (regular procedure/function) - el _rest el _first exec % apply function to args + exec % apply function to args } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse @@ -213,14 +218,10 @@ types_ns { _ref } forall (eval) { 0 get repl_env EVAL } _ref /slurp { (r) file dup bytesavailable string readstring pop } def (slurp) { 0 get slurp } _ref -(pstack) { (vvv\n) print pstack (^^^\n) print } _ref -(p1) { 1 index true _pr_str print (\n) print } _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 -/stdin (%stdin) (r) file def - userdict /ARGUMENTS known { %if command line arguments ARGUMENTS length 0 gt { %if more than 0 arguments ARGUMENTS { @@ -230,14 +231,9 @@ userdict /ARGUMENTS known { %if command line arguments } if } if { % loop - (user> ) print flush - - stdin 99 string readline - + (user> ) _readline not { exit } if % exit if EOF - %(\ngot line: ) print dup print (\n) print flush - { %try REP print (\n) print } stopped { @@ -246,6 +242,7 @@ userdict /ARGUMENTS known { %if command line arguments $error /newerror false put $error /errorinfo null put clear + cleardictstack } if } bind loop |
