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 /python | |
| 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 'python')
| -rw-r--r-- | python/Makefile | 2 | ||||
| -rw-r--r-- | python/step9_try.py (renamed from python/step9_interop.py) | 19 | ||||
| -rw-r--r-- | python/stepA_interop.py (renamed from python/stepA_more.py) | 0 |
3 files changed, 14 insertions, 7 deletions
diff --git a/python/Makefile b/python/Makefile index b461db3..6e51430 100644 --- a/python/Makefile +++ b/python/Makefile @@ -3,7 +3,7 @@ TESTS = SOURCES_BASE = mal_readline.py mal_types.py reader.py printer.py -SOURCES_LISP = env.py core.py stepA_more.py +SOURCES_LISP = env.py core.py stepA_interop.py SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) diff --git a/python/step9_interop.py b/python/step9_try.py index 7cacf1f..65da08c 100644 --- a/python/step9_interop.py +++ b/python/step9_try.py @@ -97,12 +97,17 @@ def EVAL(ast, env): else: exec(compile(ast[1], '', 'single') in globals()) return None - elif "py*" == a0: - return eval(ast[1]) - elif "." == a0: - el = eval_ast(ast[2:], env) - f = eval(ast[1]) - return f(*el) + elif "try*" == a0: + a1, a2 = ast[1], ast[2] + if a2[0] == "catch*": + try: + return EVAL(a1, env); + except Exception as exc: + exc = exc.args[0] + catch_env = Env(env, [a2[1]], [exc]) + return EVAL(a2[2], catch_env) + else: + return EVAL(a1, env); elif "do" == a0: eval_ast(ast[1:-1], env) ast = ast[-1] @@ -143,6 +148,7 @@ repl_env.set('eval', lambda ast: EVAL(ast, repl_env)) repl_env.set('*ARGV*', types._list(*sys.argv[2:])) # core.mal: defined using the language itself +REP("(def! *host-language* \"python\")") REP("(def! not (fn* (a) (if a false true)))") REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") REP("(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)))))))") @@ -153,6 +159,7 @@ if len(sys.argv) >= 2: sys.exit(0) # repl loop +REP("(println (str \"Mal [\" *host-language* \"]\"))") while True: try: line = mal_readline.readline("user> ") diff --git a/python/stepA_more.py b/python/stepA_interop.py index 723f0ed..723f0ed 100644 --- a/python/stepA_more.py +++ b/python/stepA_interop.py |
