diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-19 13:04:09 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-19 13:04:09 -0500 |
| commit | 86b689f3d7111a9fa13da389a30f3dfdf877d1a4 (patch) | |
| tree | d72b065f9f987e291f892ceee5a8640363bfd9df /js | |
| parent | 718887c3019c49fc807bc18fbd5feb975ec03c85 (diff) | |
| download | mal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.tar.gz mal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.zip | |
All: *ARGV* and *host-language*. Misc syncing/fixes.
Diffstat (limited to 'js')
| -rw-r--r-- | js/step0_repl.js | 1 | ||||
| -rw-r--r-- | js/step1_read_print.js | 1 | ||||
| -rw-r--r-- | js/step2_eval.js | 3 | ||||
| -rw-r--r-- | js/step3_env.js | 3 | ||||
| -rw-r--r-- | js/step4_if_fn_do.js | 4 | ||||
| -rw-r--r-- | js/step5_tco.js | 4 | ||||
| -rw-r--r-- | js/step6_file.js | 14 | ||||
| -rw-r--r-- | js/step7_quote.js | 14 | ||||
| -rw-r--r-- | js/step8_macros.js | 14 | ||||
| -rw-r--r-- | js/step9_interop.js | 14 | ||||
| -rw-r--r-- | js/stepA_more.js | 15 |
11 files changed, 56 insertions, 31 deletions
diff --git a/js/step0_repl.js b/js/step0_repl.js index 1d2bbfb..c13be2d 100644 --- a/js/step0_repl.js +++ b/js/step0_repl.js @@ -20,6 +20,7 @@ function PRINT(exp) { // repl var rep = function(str) { return PRINT(EVAL(READ(str), {})); }; +// repl loop if (typeof require === 'undefined') { // Asynchronous browser mode readline.rlwrap(function(line) { return rep(line); }, diff --git a/js/step1_read_print.js b/js/step1_read_print.js index ef9b6bc..1ab162f 100644 --- a/js/step1_read_print.js +++ b/js/step1_read_print.js @@ -24,6 +24,7 @@ function PRINT(exp) { var re = function(str) { return EVAL(READ(str), {}); }; var rep = function(str) { return PRINT(EVAL(READ(str), {})); }; +// repl loop if (typeof require === 'undefined') { // Asynchronous browser mode readline.rlwrap(function(line) { return rep(line); }, diff --git a/js/step2_eval.js b/js/step2_eval.js index adcefe5..72b1f9c 100644 --- a/js/step2_eval.js +++ b/js/step2_eval.js @@ -32,7 +32,7 @@ function eval_ast(ast, env) { } function _EVAL(ast, env) { - //printer.println("EVAL:", types._pr_str(ast, true)); + //printer.println("EVAL:", printer._pr_str(ast, true)); if (!types._list_Q(ast)) { return eval_ast(ast, env); } @@ -61,6 +61,7 @@ repl_env['-'] = function(a,b){return a-b;}; repl_env['*'] = function(a,b){return a*b;}; repl_env['/'] = function(a,b){return a/b;}; +// repl loop if (typeof require === 'undefined') { // Asynchronous browser mode readline.rlwrap(function(line) { return rep(line); }, diff --git a/js/step3_env.js b/js/step3_env.js index 7dbefc4..b65824f 100644 --- a/js/step3_env.js +++ b/js/step3_env.js @@ -33,7 +33,7 @@ function eval_ast(ast, env) { } function _EVAL(ast, env) { - //printer.println("EVAL:", types._pr_str(ast, true)); + //printer.println("EVAL:", printer._pr_str(ast, true)); if (!types._list_Q(ast)) { return eval_ast(ast, env); } @@ -75,6 +75,7 @@ repl_env.set('-', function(a,b){return a-b;}); repl_env.set('*', function(a,b){return a*b;}); repl_env.set('/', function(a,b){return a/b;}); +// repl loop if (typeof require === 'undefined') { // Asynchronous browser mode readline.rlwrap(function(line) { return rep(line); }, diff --git a/js/step4_if_fn_do.js b/js/step4_if_fn_do.js index 7d679a9..a0bb548 100644 --- a/js/step4_if_fn_do.js +++ b/js/step4_if_fn_do.js @@ -34,7 +34,7 @@ function eval_ast(ast, env) { } function _EVAL(ast, env) { - //printer.println("EVAL:", types._pr_str(ast, true)); + //printer.println("EVAL:", printer._pr_str(ast, true)); if (!types._list_Q(ast)) { return eval_ast(ast, env); } @@ -87,11 +87,11 @@ var rep = function(str) { return PRINT(EVAL(READ(str), repl_env)); }; // core.js: defined using javascript for (var n in core.ns) { repl_env.set(n, core.ns[n]); } -repl_env.set('eval', function(ast) { return EVAL(ast, repl_env); }); // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); +// repl loop if (typeof require === 'undefined') { // Asynchronous browser mode readline.rlwrap(function(line) { return rep(line); }, diff --git a/js/step5_tco.js b/js/step5_tco.js index 320807c..9335aa8 100644 --- a/js/step5_tco.js +++ b/js/step5_tco.js @@ -36,7 +36,7 @@ function eval_ast(ast, env) { function _EVAL(ast, env) { while (true) { - //printer.println("EVAL:", types._pr_str(ast, true)); + //printer.println("EVAL:", printer._pr_str(ast, true)); if (!types._list_Q(ast)) { return eval_ast(ast, env); } @@ -96,11 +96,11 @@ var rep = function(str) { return PRINT(EVAL(READ(str), repl_env)); }; // core.js: defined using javascript for (var n in core.ns) { repl_env.set(n, core.ns[n]); } -repl_env.set('eval', function(ast) { return EVAL(ast, repl_env); }); // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); +// repl loop if (typeof require === 'undefined') { // Asynchronous browser mode readline.rlwrap(function(line) { return rep(line); }, diff --git a/js/step6_file.js b/js/step6_file.js index aed1825..85de49e 100644 --- a/js/step6_file.js +++ b/js/step6_file.js @@ -36,7 +36,7 @@ function eval_ast(ast, env) { function _EVAL(ast, env) { while (true) { - //printer.println("EVAL:", types._pr_str(ast, true)); + //printer.println("EVAL:", printer._pr_str(ast, true)); if (!types._list_Q(ast)) { return eval_ast(ast, env); } @@ -97,16 +97,20 @@ var rep = function(str) { return PRINT(EVAL(READ(str), repl_env)); }; // core.js: defined using javascript for (var n in core.ns) { repl_env.set(n, core.ns[n]); } repl_env.set('eval', function(ast) { return EVAL(ast, repl_env); }); +repl_env.set('*ARGV*', []); // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); if (typeof process !== 'undefined' && process.argv.length > 2) { - for (var i=2; i < process.argv.length; i++) { - rep('(load-file "' + process.argv[i] + '")'); - } -} else if (typeof require === 'undefined') { + repl_env.set('*ARGV*', process.argv.slice(3)); + rep('(load-file "' + process.argv[2] + '")'); + process.exit(0); +} + +// repl loop +if (typeof require === 'undefined') { // Asynchronous browser mode readline.rlwrap(function(line) { return rep(line); }, function(exc) { diff --git a/js/step7_quote.js b/js/step7_quote.js index a7f4535..8676d07 100644 --- a/js/step7_quote.js +++ b/js/step7_quote.js @@ -56,7 +56,7 @@ function eval_ast(ast, env) { function _EVAL(ast, env) { while (true) { - //printer.println("EVAL:", types._pr_str(ast, true)); + //printer.println("EVAL:", printer._pr_str(ast, true)); if (!types._list_Q(ast)) { return eval_ast(ast, env); } @@ -121,16 +121,20 @@ var rep = function(str) { return PRINT(EVAL(READ(str), repl_env)); }; // core.js: defined using javascript for (var n in core.ns) { repl_env.set(n, core.ns[n]); } repl_env.set('eval', function(ast) { return EVAL(ast, repl_env); }); +repl_env.set('*ARGV*', []); // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); if (typeof process !== 'undefined' && process.argv.length > 2) { - for (var i=2; i < process.argv.length; i++) { - rep('(load-file "' + process.argv[i] + '")'); - } -} else if (typeof require === 'undefined') { + repl_env.set('*ARGV*', process.argv.slice(3)); + rep('(load-file "' + process.argv[2] + '")'); + process.exit(0); +} + +// repl loop +if (typeof require === 'undefined') { // Asynchronous browser mode readline.rlwrap(function(line) { return rep(line); }, function(exc) { diff --git a/js/step8_macros.js b/js/step8_macros.js index 1268a4d..dca7beb 100644 --- a/js/step8_macros.js +++ b/js/step8_macros.js @@ -71,7 +71,7 @@ function eval_ast(ast, env) { function _EVAL(ast, env) { while (true) { - //printer.println("EVAL:", types._pr_str(ast, true)); + //printer.println("EVAL:", printer._pr_str(ast, true)); if (!types._list_Q(ast)) { return eval_ast(ast, env); } @@ -145,6 +145,7 @@ var rep = function(str) { return PRINT(EVAL(READ(str), repl_env)); }; // core.js: defined using javascript for (var n in core.ns) { repl_env.set(n, core.ns[n]); } repl_env.set('eval', function(ast) { return EVAL(ast, repl_env); }); +repl_env.set('*ARGV*', []); // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); @@ -153,10 +154,13 @@ rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if ( rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); if (typeof process !== 'undefined' && process.argv.length > 2) { - for (var i=2; i < process.argv.length; i++) { - rep('(load-file "' + process.argv[i] + '")'); - } -} else if (typeof require === 'undefined') { + repl_env.set('*ARGV*', process.argv.slice(3)); + rep('(load-file "' + process.argv[2] + '")'); + process.exit(0); +} + +// repl loop +if (typeof require === 'undefined') { // Asynchronous browser mode readline.rlwrap(function(line) { return rep(line); }, function(exc) { diff --git a/js/step9_interop.js b/js/step9_interop.js index 1fd07d4..e95b4ca 100644 --- a/js/step9_interop.js +++ b/js/step9_interop.js @@ -71,7 +71,7 @@ function eval_ast(ast, env) { function _EVAL(ast, env) { while (true) { - //printer.println("EVAL:", types._pr_str(ast, true)); + //printer.println("EVAL:", printer._pr_str(ast, true)); if (!types._list_Q(ast)) { return eval_ast(ast, env); } @@ -151,6 +151,7 @@ var rep = function(str) { return PRINT(EVAL(READ(str), repl_env)); }; // core.js: defined using javascript for (var n in core.ns) { repl_env.set(n, core.ns[n]); } repl_env.set('eval', function(ast) { return EVAL(ast, repl_env); }); +repl_env.set('*ARGV*', []); // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); @@ -159,10 +160,13 @@ rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if ( rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); if (typeof process !== 'undefined' && process.argv.length > 2) { - for (var i=2; i < process.argv.length; i++) { - rep('(load-file "' + process.argv[i] + '")'); - } -} else if (typeof require === 'undefined') { + repl_env.set('*ARGV*', process.argv.slice(3)); + rep('(load-file "' + process.argv[2] + '")'); + process.exit(0); +} + +// repl loop +if (typeof require === 'undefined') { // Asynchronous browser mode readline.rlwrap(function(line) { return rep(line); }, function(exc) { diff --git a/js/stepA_more.js b/js/stepA_more.js index a2035dc..58840eb 100644 --- a/js/stepA_more.js +++ b/js/stepA_more.js @@ -71,7 +71,7 @@ function eval_ast(ast, env) { function _EVAL(ast, env) { while (true) { - //printer.println("EVAL:", types._pr_str(ast, true)); + //printer.println("EVAL:", printer._pr_str(ast, true)); if (!types._list_Q(ast)) { return eval_ast(ast, env); } @@ -162,6 +162,7 @@ var rep = function(str) { return PRINT(EVAL(READ(str), repl_env)); }; // core.js: defined using javascript for (var n in core.ns) { repl_env.set(n, core.ns[n]); } 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\")") @@ -171,10 +172,14 @@ rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if ( rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); if (typeof process !== 'undefined' && process.argv.length > 2) { - for (var i=2; i < process.argv.length; i++) { - rep('(load-file "' + process.argv[i] + '")'); - } -} else if (typeof require === 'undefined') { + repl_env.set('*ARGV*', process.argv.slice(3)); + rep('(load-file "' + process.argv[2] + '")'); + process.exit(0); +} + +// repl loop +rep("(println (str \"Mal [\" *host-language* \"]\"))"); +if (typeof require === 'undefined') { // Asynchronous browser mode readline.rlwrap(function(line) { return rep(line); }, function(exc) { |
