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 /js | |
| 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 'js')
| -rw-r--r-- | js/Makefile | 2 | ||||
| -rw-r--r-- | js/step9_try.js (renamed from js/step9_interop.js) | 19 | ||||
| -rw-r--r-- | js/stepA_interop.js (renamed from js/stepA_more.js) | 0 | ||||
| -rw-r--r-- | js/tests/stepA_interop.mal (renamed from js/tests/step9_interop.mal) | 0 |
4 files changed, 14 insertions, 7 deletions
diff --git a/js/Makefile b/js/Makefile index 454e481..09ed5a4 100644 --- a/js/Makefile +++ b/js/Makefile @@ -2,7 +2,7 @@ TESTS = tests/types.js tests/reader.js SOURCES_BASE = node_readline.js types.js reader.js printer.js -SOURCES_LISP = env.js core.js stepA_more.js +SOURCES_LISP = env.js core.js stepA_interop.js SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) WEB_SOURCES = $(SOURCES:node_readline.js=jq_readline.js) diff --git a/js/step9_interop.js b/js/step9_try.js index 89d2ca4..ff02f72 100644 --- a/js/step9_interop.js +++ b/js/step9_try.js @@ -104,12 +104,17 @@ function _EVAL(ast, env) { return env.set(a1, func); case 'macroexpand': return macroexpand(a1, env); - case "js*": - return eval(a1.toString()); - case ".": - var el = eval_ast(ast.slice(2), env), - f = eval(a1.toString()); - return f.apply(f, el); + case "try*": + try { + return EVAL(a1, env); + } catch (exc) { + if (a2 && a2[0].value === "catch*") { + if (exc instanceof Error) { exc = exc.message; } + return EVAL(a2[2], new Env(env, [a2[1]], [exc])); + } else { + throw exc; + } + } case "do": eval_ast(ast.slice(1, -1), env); ast = ast[ast.length-1]; @@ -157,6 +162,7 @@ repl_env.set('eval', function(ast) { return EVAL(ast, repl_env); }); repl_env.set('*ARGV*', []); // core.mal: defined using the language itself +rep("(def! *host-language* \"javascript\")") 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)))))))"); @@ -171,6 +177,7 @@ if (typeof process !== 'undefined' && process.argv.length > 2) { // repl loop if (typeof require !== 'undefined' && require.main === module) { // Synchronous node.js commandline mode + rep("(println (str \"Mal [\" *host-language* \"]\"))"); while (true) { var line = readline.readline("user> "); if (line === null) { break; } diff --git a/js/stepA_more.js b/js/stepA_interop.js index 0955b7f..0955b7f 100644 --- a/js/stepA_more.js +++ b/js/stepA_interop.js diff --git a/js/tests/step9_interop.mal b/js/tests/stepA_interop.mal index f785292..f785292 100644 --- a/js/tests/step9_interop.mal +++ b/js/tests/stepA_interop.mal |
