diff options
| author | Joel Martin <github@martintribe.org> | 2014-10-09 23:48:47 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-06 21:57:24 -0600 |
| commit | 01c9731649a7ed97fad0bdeac9cb75b7323c0ad6 (patch) | |
| tree | d6d00e574c489b206ddf78adc12c3d535bab7440 /ps | |
| parent | 1771ab50b87c745181e4e30f94b63e3f23d33dac (diff) | |
| download | mal-01c9731649a7ed97fad0bdeac9cb75b7323c0ad6.tar.gz mal-01c9731649a7ed97fad0bdeac9cb75b7323c0ad6.zip | |
All: swap step9,A. Fixes for bash, C, perl.
step9_interop -> stepA_interop
stepA_more -> step9_try
C: fix glib headers
bash: behavior change of declare -A and pattern replacement.
perl: squelch new 5.18 warnings related to switch/given statement.
Also, include some in-progress interop related files.
Diffstat (limited to 'ps')
| -rw-r--r-- | ps/Makefile | 2 | ||||
| -rw-r--r-- | ps/interop.ps | 21 | ||||
| -rw-r--r-- | ps/step9_try.ps (renamed from ps/step9_interop.ps) | 52 | ||||
| -rw-r--r-- | ps/stepA_interop.ps (renamed from ps/stepA_more.ps) | 0 |
4 files changed, 60 insertions, 15 deletions
diff --git a/ps/Makefile b/ps/Makefile index 43b5b70..26056a6 100644 --- a/ps/Makefile +++ b/ps/Makefile @@ -2,7 +2,7 @@ TESTS = SOURCES_BASE = types.ps reader.ps printer.ps -SOURCES_LISP = env.ps core.ps stepA_more.ps +SOURCES_LISP = env.ps core.ps stepA_interop.ps SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) .PHONY: stats tests $(TESTS) diff --git a/ps/interop.ps b/ps/interop.ps new file mode 100644 index 0000000..fb3b88d --- /dev/null +++ b/ps/interop.ps @@ -0,0 +1,21 @@ +% ps_val -> ps2mal -> mal_val +/ps2mal { + % convert a PS value to a Mal value (recursively) + [ exch + { %forall returned values + dup == + dup type /arraytype eq { + (here1\n) print + _list_from_array + }{ dup type /dicttype eq { + (here2\n) print + _hash_map_from_dict + }{ + (here3\n) print + % no-op + } ifelse } ifelse + } forall + ] + (here4\n) print +} def + diff --git a/ps/step9_interop.ps b/ps/step9_try.ps index 7f90d20..9c5c240 100644 --- a/ps/step9_interop.ps +++ b/ps/step9_try.ps @@ -144,20 +144,6 @@ end } def env exch a1 exch env_set % def! it }{ /macroexpand a0 eq { %if defmacro! ast 1 _nth env macroexpand - }{ /ps* a0 eq { %if ps* - count /stackcnt exch def - ast 1 _nth - { - token not { exit } if - exch - } loop - exec - count stackcnt gt { % if new operands on stack - % return an list of new operands - count stackcnt sub array astore - }{ - null % return nil - } ifelse }{ /do a0 eq { %if do ast _count 2 gt { %if ast has more than 2 elements ast 1 ast _count 2 sub _slice env eval_ast pop @@ -165,6 +151,42 @@ end } def ast ast _count 1 sub _nth % last ast becomes new ast env /loop? true def % loop + }{ /try* a0 eq { %if try* + { %try + countdictstack /dictcnt exch def + count /stackcnt exch def + ast 1 _nth env EVAL + } stopped { %catch + % clean up the dictionary stack + 1 1 countdictstack dictcnt sub { %foreach added dict + %(popping dict\n) print + pop end % pop idx and pop dict + %(new ast: ) print ast true _pr_str print (\n) print + } for + % clean up the operand stack + count 1 exch 1 exch stackcnt sub { %foreach added operand + %(op stack: ) print pstack + pop pop % pop idx and operand + %(popped op stack\n) print pstack + } for + % get error data and reset $error dict + /errdata get_error_data def + $error /newerror false put + $error /errorinfo null put + + ast _count 3 lt { %if no third (catch*) form + errdata throw + } if + ast 2 _nth 0 _nth (catch*) eq not { %if third form not catch* + (No catch* in throw form) _throw + } if + ast 2 _nth 2 _nth + env + ast 2 _nth 1 _nth 1 _list + errdata 1 _list + env_new + EVAL + } if }{ /if a0 eq { %if if /a1 ast 1 _nth def /cond a1 env EVAL def @@ -222,6 +244,7 @@ core_ns { _function _ref } forall (*ARGV*) [ ] _list_from_array _ref % core.mal: defined using the language itself +(\(def! *host-language* "postscript"\)) RE pop (\(def! not \(fn* \(a\) \(if a false true\)\)\)) RE pop (\(def! load-file \(fn* \(f\) \(eval \(read-string \(str "\(do " \(slurp f\) "\)"\)\)\)\)\)) RE pop (\(defmacro! cond \(fn* \(& xs\) \(if \(> \(count xs\) 0\) \(list 'if \(first xs\) \(if \(> \(count xs\) 1\) \(nth xs 1\) \(throw "odd number of forms to cond"\)\) \(cons 'cond \(rest \(rest xs\)\)\)\)\)\)\)) RE pop @@ -238,6 +261,7 @@ userdict /ARGUMENTS known { %if command line arguments } if % repl loop +(\(println \(str "Mal [" *host-language* "]"\)\)) RE pop { %loop (user> ) _readline not { exit } if % exit if EOF diff --git a/ps/stepA_more.ps b/ps/stepA_interop.ps index a24ee28..a24ee28 100644 --- a/ps/stepA_more.ps +++ b/ps/stepA_interop.ps |
