diff options
| author | Joel Martin <github@martintribe.org> | 2015-03-07 09:04:07 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-03-07 09:04:07 -0600 |
| commit | 10b07148ba8efec543ded60a4b7916960709ce1e (patch) | |
| tree | 43c10dbc3c6bd2035c34cabf5aca3aa08e37a2f6 | |
| parent | 64574360c510d644f5b8c175dbe3114f1f2d7b68 (diff) | |
| download | mal-10b07148ba8efec543ded60a4b7916960709ce1e.tar.gz mal-10b07148ba8efec543ded60a4b7916960709ce1e.zip | |
All step0: add test, fix bugs, remove step0 eval.
| -rwxr-xr-x | bash/step0_repl.sh | 3 | ||||
| -rw-r--r-- | clojure/src/step0_repl.clj | 8 | ||||
| -rw-r--r-- | cs/step0_repl.cs | 8 | ||||
| -rw-r--r-- | js/step0_repl.js | 3 | ||||
| -rwxr-xr-x | lua/step0_repl.lua | 4 | ||||
| -rw-r--r-- | miniMAL/miniMAL-core.json | 9 | ||||
| -rw-r--r-- | miniMAL/step0_repl.json | 8 | ||||
| -rw-r--r-- | perl/readline.pm | 2 | ||||
| -rw-r--r-- | perl/step0_repl.pl | 5 | ||||
| -rw-r--r-- | php/step0_repl.php | 8 | ||||
| -rw-r--r-- | php/step1_read_print.php | 4 | ||||
| -rw-r--r-- | php/step2_eval.php | 4 | ||||
| -rw-r--r-- | php/step3_env.php | 4 | ||||
| -rw-r--r-- | php/step4_if_fn_do.php | 4 | ||||
| -rw-r--r-- | php/step5_tco.php | 4 | ||||
| -rw-r--r-- | php/step6_file.php | 4 | ||||
| -rw-r--r-- | php/step7_quote.php | 4 | ||||
| -rw-r--r-- | php/step8_macros.php | 4 | ||||
| -rw-r--r-- | php/step9_try.php | 4 | ||||
| -rw-r--r-- | php/stepA_mal.php | 4 | ||||
| -rw-r--r-- | python/step0_repl.py | 8 | ||||
| -rw-r--r-- | python/step1_read_print.py | 1 | ||||
| -rwxr-xr-x | racket/step0_repl.rkt | 2 | ||||
| -rw-r--r-- | vb/step0_repl.vb | 11 |
24 files changed, 68 insertions, 52 deletions
diff --git a/bash/step0_repl.sh b/bash/step0_repl.sh index 8e1fff0..97bce61 100755 --- a/bash/step0_repl.sh +++ b/bash/step0_repl.sh @@ -5,8 +5,7 @@ READ () { } EVAL () { - r= - eval "${1}" + r="${1}" } PRINT () { diff --git a/clojure/src/step0_repl.clj b/clojure/src/step0_repl.clj index 7a1a443..405037a 100644 --- a/clojure/src/step0_repl.clj +++ b/clojure/src/step0_repl.clj @@ -4,15 +4,15 @@ ;; read (defn READ [& [strng]] - (let [line (if strng strng (read-line))] - strng)) + strng) ;; eval (defn EVAL [ast env] - (eval (read-string ast))) + ast) ;; print -(defn PRINT [exp] exp) +(defn PRINT [exp] + exp) ;; repl (defn rep [strng] (PRINT (EVAL (READ strng), {}))) diff --git a/cs/step0_repl.cs b/cs/step0_repl.cs index 616e154..68cac94 100644 --- a/cs/step0_repl.cs +++ b/cs/step0_repl.cs @@ -25,13 +25,17 @@ namespace Mal { } static void Main(string[] args) { - string prompt = "user> "; + if (args.Length > 0 && args[0] == "--raw") { + Mal.readline.mode = Mal.readline.Mode.Raw; + } + // repl loop while (true) { string line; try { - line = Mal.readline.Readline(prompt); + line = Mal.readline.Readline("user> "); if (line == null) { break; } + if (line == "") { continue; } } catch (IOException e) { Console.WriteLine("IOException: " + e.Message); break; diff --git a/js/step0_repl.js b/js/step0_repl.js index f9fa60e..126a436 100644 --- a/js/step0_repl.js +++ b/js/step0_repl.js @@ -1,5 +1,6 @@ if (typeof module !== 'undefined') { var readline = require('./node_readline'); + var printer = require('./printer'); } // read @@ -9,7 +10,7 @@ function READ(str) { // eval function EVAL(ast, env) { - return eval(ast); + return ast; } // print diff --git a/lua/step0_repl.lua b/lua/step0_repl.lua index 24584d2..bb082a5 100755 --- a/lua/step0_repl.lua +++ b/lua/step0_repl.lua @@ -18,6 +18,10 @@ function rep(str) return PRINT(EVAL(READ(str),"")) end +if #arg > 0 and arg[1] == "--raw" then + readline.raw = true +end + while true do line = readline.readline("user> ") if not line then break end diff --git a/miniMAL/miniMAL-core.json b/miniMAL/miniMAL-core.json index c22376a..25ee914 100644 --- a/miniMAL/miniMAL-core.json +++ b/miniMAL/miniMAL-core.json @@ -101,10 +101,11 @@ ["println", ["rep", "line"]], ["cb"]]]], "opts", {"ignoreUndefined": true, - "terminal": false}, - "opts", ["assoc!", "opts", ["`", "prompt"], "prompt"], - "opts", ["assoc!", "opts", ["`", "eval"], "evl"]], - [".", "r", ["`", "start"], "opts"]]]], + "terminal": false}], + ["do", + [".-", "opts", ["`", "prompt"], "prompt"], + [".-", "opts", ["`", "eval"], "evl"], + [".", "r", ["`", "start"], "opts"]]]]], null ] diff --git a/miniMAL/step0_repl.json b/miniMAL/step0_repl.json index 6599930..50f8846 100644 --- a/miniMAL/step0_repl.json +++ b/miniMAL/step0_repl.json @@ -3,16 +3,16 @@ ["load-file", ["`", "miniMAL-core.json"]], ["def", "READ", ["fn", ["strng"], - "strng"]], + "strng"]], ["def", "EVAL", ["fn", ["ast", "env"], - "ast"]], + "ast"]], ["def", "PRINT", ["fn", ["exp"], - "exp"]], + "exp"]], ["def", "rep", ["fn", ["strng"], - ["PRINT", ["EVAL", ["READ", "strng"], null]]]], + ["PRINT", ["EVAL", ["READ", "strng"], null]]]], ["repl", ["`", "user> "], "rep"], diff --git a/perl/readline.pm b/perl/readline.pm index 0629f39..149c3fb 100644 --- a/perl/readline.pm +++ b/perl/readline.pm @@ -54,6 +54,7 @@ sub mal_readline { if ($rl_mode eq "terminal") { if (defined ($line = $_rl->readline($prompt))) { save_line($line); + chomp $line; return $line; } else { return undef; @@ -62,6 +63,7 @@ sub mal_readline { print "$prompt"; if (defined ($line = readline(*STDIN))) { save_line($line); + chomp($line); return $line; } else { return undef; diff --git a/perl/step0_repl.pl b/perl/step0_repl.pl index 36d6375..a2f15cb 100644 --- a/perl/step0_repl.pl +++ b/perl/step0_repl.pl @@ -2,7 +2,7 @@ use strict; use warnings FATAL => qw(all); use File::Basename; use lib dirname (__FILE__); -use readline qw(mal_readline); +use readline qw(mal_readline set_rl_mode); # read sub READ { @@ -28,6 +28,9 @@ sub REP { return PRINT(EVAL(READ($str), {})); } +if (scalar(@ARGV) > 0 && $ARGV[0] eq "--raw") { + set_rl_mode("raw"); +} while (1) { my $line = mal_readline("user> "); if (! defined $line) { last; } diff --git a/php/step0_repl.php b/php/step0_repl.php index eecb052..421173c 100644 --- a/php/step0_repl.php +++ b/php/step0_repl.php @@ -9,12 +9,12 @@ function READ($str) { // eval function MAL_EVAL($ast, $env) { - return eval($ast); + return $ast; } // print function MAL_PRINT($exp) { - return var_export($exp, true) . "\n"; + return $exp; } // repl @@ -26,8 +26,8 @@ function rep($str) { do { $line = mal_readline("user> "); if ($line === NULL) { break; } - if (!empty($line)) { - print(rep($line)); + if ($line !== "") { + print(rep($line) . "\n"); } } while (true); diff --git a/php/step1_read_print.php b/php/step1_read_print.php index c9c5267..b1f18a8 100644 --- a/php/step1_read_print.php +++ b/php/step1_read_print.php @@ -17,7 +17,7 @@ function MAL_EVAL($ast, $env) { // print function MAL_PRINT($exp) { - return _pr_str($exp, True) . "\n"; + return _pr_str($exp, True); } // repl @@ -31,7 +31,7 @@ do { $line = mal_readline("user> "); if ($line === NULL) { break; } if ($line !== "") { - print(rep($line)); + print(rep($line) . "\n"); } } catch (BlankException $e) { continue; diff --git a/php/step2_eval.php b/php/step2_eval.php index b9d2e8e..e96e8fd 100644 --- a/php/step2_eval.php +++ b/php/step2_eval.php @@ -46,7 +46,7 @@ function MAL_EVAL($ast, $env) { // print function MAL_PRINT($exp) { - return _pr_str($exp, True) . "\n"; + return _pr_str($exp, True); } // repl @@ -67,7 +67,7 @@ do { $line = mal_readline("user> "); if ($line === NULL) { break; } if ($line !== "") { - print(rep($line)); + print(rep($line) . "\n"); } } catch (BlankException $e) { continue; diff --git a/php/step3_env.php b/php/step3_env.php index a31c298..9da2fd2 100644 --- a/php/step3_env.php +++ b/php/step3_env.php @@ -63,7 +63,7 @@ function MAL_EVAL($ast, $env) { // print function MAL_PRINT($exp) { - return _pr_str($exp, True) . "\n"; + return _pr_str($exp, True); } // repl @@ -84,7 +84,7 @@ do { $line = mal_readline("user> "); if ($line === NULL) { break; } if ($line !== "") { - print(rep($line)); + print(rep($line) . "\n"); } } catch (BlankException $e) { continue; diff --git a/php/step4_if_fn_do.php b/php/step4_if_fn_do.php index 7266261..4601112 100644 --- a/php/step4_if_fn_do.php +++ b/php/step4_if_fn_do.php @@ -81,7 +81,7 @@ function MAL_EVAL($ast, $env) { // print function MAL_PRINT($exp) { - return _pr_str($exp, True) . "\n"; + return _pr_str($exp, True); } // repl @@ -105,7 +105,7 @@ do { $line = mal_readline("user> "); if ($line === NULL) { break; } if ($line !== "") { - print(rep($line)); + print(rep($line) . "\n"); } } catch (BlankException $e) { continue; diff --git a/php/step5_tco.php b/php/step5_tco.php index a3785cf..283e47e 100644 --- a/php/step5_tco.php +++ b/php/step5_tco.php @@ -93,7 +93,7 @@ function MAL_EVAL($ast, $env) { // print function MAL_PRINT($exp) { - return _pr_str($exp, True) . "\n"; + return _pr_str($exp, True); } // repl @@ -117,7 +117,7 @@ do { $line = mal_readline("user> "); if ($line === NULL) { break; } if ($line !== "") { - print(rep($line)); + print(rep($line) . "\n"); } } catch (BlankException $e) { continue; diff --git a/php/step6_file.php b/php/step6_file.php index a27acb8..eaa765a 100644 --- a/php/step6_file.php +++ b/php/step6_file.php @@ -93,7 +93,7 @@ function MAL_EVAL($ast, $env) { // print function MAL_PRINT($exp) { - return _pr_str($exp, True) . "\n"; + return _pr_str($exp, True); } // repl @@ -131,7 +131,7 @@ do { $line = mal_readline("user> "); if ($line === NULL) { break; } if ($line !== "") { - print(rep($line)); + print(rep($line) . "\n"); } } catch (BlankException $e) { continue; diff --git a/php/step7_quote.php b/php/step7_quote.php index 37903d0..cb98825 100644 --- a/php/step7_quote.php +++ b/php/step7_quote.php @@ -117,7 +117,7 @@ function MAL_EVAL($ast, $env) { // print function MAL_PRINT($exp) { - return _pr_str($exp, True) . "\n"; + return _pr_str($exp, True); } // repl @@ -155,7 +155,7 @@ do { $line = mal_readline("user> "); if ($line === NULL) { break; } if ($line !== "") { - print(rep($line)); + print(rep($line) . "\n"); } } catch (BlankException $e) { continue; diff --git a/php/step8_macros.php b/php/step8_macros.php index c7e0175..d3d22d8 100644 --- a/php/step8_macros.php +++ b/php/step8_macros.php @@ -142,7 +142,7 @@ function MAL_EVAL($ast, $env) { // print function MAL_PRINT($exp) { - return _pr_str($exp, True) . "\n"; + return _pr_str($exp, True); } // repl @@ -182,7 +182,7 @@ do { $line = mal_readline("user> "); if ($line === NULL) { break; } if ($line !== "") { - print(rep($line)); + print(rep($line) . "\n"); } } catch (BlankException $e) { continue; diff --git a/php/step9_try.php b/php/step9_try.php index 0470763..bb7fd27 100644 --- a/php/step9_try.php +++ b/php/step9_try.php @@ -160,7 +160,7 @@ function MAL_EVAL($ast, $env) { // print function MAL_PRINT($exp) { - return _pr_str($exp, True) . "\n"; + return _pr_str($exp, True); } // repl @@ -200,7 +200,7 @@ do { $line = mal_readline("user> "); if ($line === NULL) { break; } if ($line !== "") { - print(rep($line)); + print(rep($line) . "\n"); } } catch (BlankException $e) { continue; diff --git a/php/stepA_mal.php b/php/stepA_mal.php index 1dc3b04..bac0f97 100644 --- a/php/stepA_mal.php +++ b/php/stepA_mal.php @@ -174,7 +174,7 @@ function MAL_EVAL($ast, $env) { // print function MAL_PRINT($exp) { - return _pr_str($exp, True) . "\n"; + return _pr_str($exp, True); } // repl @@ -216,7 +216,7 @@ do { $line = mal_readline("user> "); if ($line === NULL) { break; } if ($line !== "") { - print(rep($line)); + print(rep($line) . "\n"); } } catch (BlankException $e) { continue; diff --git a/python/step0_repl.py b/python/step0_repl.py index d915989..3e5801b 100644 --- a/python/step0_repl.py +++ b/python/step0_repl.py @@ -7,12 +7,8 @@ def READ(str): # eval def EVAL(ast, env): - # try it as an expression then a statement - try: - return eval(ast) - except SyntaxError: - exec(compile(ast, '', 'single'), globals()) - return None + #print("EVAL %s" % printer._pr_str(ast)) + return ast # print def PRINT(exp): diff --git a/python/step1_read_print.py b/python/step1_read_print.py index 3c2e4ac..c167e38 100644 --- a/python/step1_read_print.py +++ b/python/step1_read_print.py @@ -12,6 +12,7 @@ def EVAL(ast, env): #print("EVAL %s" % printer._pr_str(ast)) return ast +# print def PRINT(exp): return printer._pr_str(exp) diff --git a/racket/step0_repl.rkt b/racket/step0_repl.rkt index d09d5ba..643d132 100755 --- a/racket/step0_repl.rkt +++ b/racket/step0_repl.rkt @@ -1,7 +1,7 @@ #!/usr/bin/env racket #lang racket -(require "types.rkt") +(require "readline.rkt" "types.rkt") ;; read (define (READ str) diff --git a/vb/step0_repl.vb b/vb/step0_repl.vb index f53f378..3880598 100644 --- a/vb/step0_repl.vb +++ b/vb/step0_repl.vb @@ -24,11 +24,16 @@ Namespace Mal End Function Shared Function Main As Integer - Dim prompt As String = "user> " - Dim line As String + Dim args As String() = Environment.GetCommandLineArgs() + + If args.Length > 1 AndAlso args(1) = "--raw" Then + Mal.readline.SetMode(Mal.readline.Modes.Raw) + End If + ' repl loop + Dim line As String Do - line = Mal.readline.Readline(prompt) + line = Mal.readline.Readline("user> ") If line is Nothing Then Exit Do End If |
