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/step6_file.js | |
| parent | 718887c3019c49fc807bc18fbd5feb975ec03c85 (diff) | |
| download | mal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.tar.gz mal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.zip | |
All: *ARGV* and *host-language*. Misc syncing/fixes.
Diffstat (limited to 'js/step6_file.js')
| -rw-r--r-- | js/step6_file.js | 14 |
1 files changed, 9 insertions, 5 deletions
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) { |
