diff options
| author | Joel Martin <github@martintribe.org> | 2015-02-28 15:58:35 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-02-28 15:58:35 -0600 |
| commit | 3e0b36dcee99ddfd7ea0e04a382c1ad3858fc45f (patch) | |
| tree | 523465cf281c01c8930e3166e4050cd201335411 | |
| parent | 7907cd904a12c542529b27b0517a609e9cc4bb08 (diff) | |
| download | mal-3e0b36dcee99ddfd7ea0e04a382c1ad3858fc45f.tar.gz mal-3e0b36dcee99ddfd7ea0e04a382c1ad3858fc45f.zip | |
Lua: fix with new runtest.py
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | docs/TODO | 1 | ||||
| -rw-r--r-- | lua/core.lua | 2 | ||||
| -rw-r--r-- | lua/readline.lua | 9 | ||||
| -rwxr-xr-x | lua/step1_read_print.lua | 4 | ||||
| -rwxr-xr-x | lua/step2_eval.lua | 4 | ||||
| -rwxr-xr-x | lua/step3_env.lua | 4 | ||||
| -rwxr-xr-x | lua/step4_if_fn_do.lua | 4 | ||||
| -rwxr-xr-x | lua/step5_tco.lua | 4 | ||||
| -rwxr-xr-x | lua/step6_file.lua | 5 | ||||
| -rwxr-xr-x | lua/step7_quote.lua | 5 | ||||
| -rwxr-xr-x | lua/step8_macros.lua | 5 | ||||
| -rwxr-xr-x | lua/step9_try.lua | 31 | ||||
| -rwxr-xr-x | lua/stepA_mal.lua | 5 |
14 files changed, 71 insertions, 14 deletions
@@ -95,7 +95,7 @@ go_RUNSTEP = ../$(2) $(3) haskell_RUNSTEP = ../$(2) $(3) java_RUNSTEP = mvn -quiet exec:java -Dexec.mainClass="mal.$($(1))" -Dexec.args="--raw$(if $(3), $(3),)" js_RUNSTEP = node ../$(2) $(3) -lua_RUNSTEP = ../$(2) $(3) +lua_RUNSTEP = ../$(2) --raw $(3) make_RUNSTEP = make -f ../$(2) $(3) mal_RUNSTEP = $(call $(MAL_IMPL)_RUNSTEP,$(1),$(call $(MAL_IMPL)_STEP_TO_PROG,stepA),../$(2),") #" ocaml_RUNSTEP = ../$(2) $(3) @@ -9,6 +9,7 @@ All: of iterations per second - redefine (defmacro!) as (def! (macro*)) - runtest expect fixes: + - fix C#, VB and Lua * stop using expect, so we can drop --raw option - fix long line splitting in runtest - regular expression matching in runtest diff --git a/lua/core.lua b/lua/core.lua index 3f46aeb..279a6d6 100644 --- a/lua/core.lua +++ b/lua/core.lua @@ -23,12 +23,14 @@ end function prn(...) print(table.concat( utils.map(function(e) return _pr_str(e, true) end, arg), " ")) + io.flush() return Nil end function println(...) print(table.concat( utils.map(function(e) return _pr_str(e, false) end, arg), " ")) + io.flush() return Nil end diff --git a/lua/readline.lua b/lua/readline.lua index a75f4ff..5acdb54 100644 --- a/lua/readline.lua +++ b/lua/readline.lua @@ -5,6 +5,8 @@ local M = {} local history_loaded = false local history_file = os.getenv("HOME") .. "/.mal-history" +M.raw = false + function M.readline(prompt) if not history_loaded then history_loaded = true @@ -13,7 +15,12 @@ function M.readline(prompt) end end - line = LN.linenoise(prompt) + if M.raw then + io.write(prompt); io.flush(); + line = io.read() + else + line = LN.linenoise(prompt) + end if line then LN.historyadd(line) local f = io.open(history_file, "a") diff --git a/lua/step1_read_print.lua b/lua/step1_read_print.lua index abd555d..46d71f5 100755 --- a/lua/step1_read_print.lua +++ b/lua/step1_read_print.lua @@ -25,6 +25,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/lua/step2_eval.lua b/lua/step2_eval.lua index 7487064..22ac8cf 100755 --- a/lua/step2_eval.lua +++ b/lua/step2_eval.lua @@ -58,6 +58,10 @@ function rep(str) return PRINT(EVAL(READ(str),repl_env)) 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/lua/step3_env.lua b/lua/step3_env.lua index ed2e62a..dbdb879 100755 --- a/lua/step3_env.lua +++ b/lua/step3_env.lua @@ -71,6 +71,10 @@ repl_env:set(types.Symbol:new('-'), function(a,b) return a-b end) repl_env:set(types.Symbol:new('*'), function(a,b) return a*b end) repl_env:set(types.Symbol:new('/'), function(a,b) return math.floor(a/b) 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/lua/step4_if_fn_do.lua b/lua/step4_if_fn_do.lua index e211973..65b3a0a 100755 --- a/lua/step4_if_fn_do.lua +++ b/lua/step4_if_fn_do.lua @@ -89,6 +89,10 @@ end -- core.mal: defined using mal rep("(def! not (fn* (a) (if a false true)))") +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/lua/step5_tco.lua b/lua/step5_tco.lua index fa4e41f..237f5ea 100755 --- a/lua/step5_tco.lua +++ b/lua/step5_tco.lua @@ -97,6 +97,10 @@ end -- core.mal: defined using mal rep("(def! not (fn* (a) (if a false true)))") +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/lua/step6_file.lua b/lua/step6_file.lua index b109a90..7992888 100755 --- a/lua/step6_file.lua +++ b/lua/step6_file.lua @@ -101,6 +101,11 @@ repl_env:set(types.Symbol:new('*ARGV*'), types.List:new(types.slice(arg,2))) rep("(def! not (fn* (a) (if a false true)))") rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") +if #arg > 0 and arg[1] == "--raw" then + readline.raw = true + table.remove(arg,1) +end + if #arg > 0 then rep("(load-file \""..arg[1].."\")") os.exit(0) diff --git a/lua/step7_quote.lua b/lua/step7_quote.lua index 974e342..32bf60c 100755 --- a/lua/step7_quote.lua +++ b/lua/step7_quote.lua @@ -127,6 +127,11 @@ repl_env:set(types.Symbol:new('*ARGV*'), types.List:new(types.slice(arg,2))) rep("(def! not (fn* (a) (if a false true)))") rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") +if #arg > 0 and arg[1] == "--raw" then + readline.raw = true + table.remove(arg,1) +end + if #arg > 0 then rep("(load-file \""..arg[1].."\")") os.exit(0) diff --git a/lua/step8_macros.lua b/lua/step8_macros.lua index 46a5881..25a9238 100755 --- a/lua/step8_macros.lua +++ b/lua/step8_macros.lua @@ -156,6 +156,11 @@ 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)))))))") 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 #arg > 0 and arg[1] == "--raw" then + readline.raw = true + table.remove(arg,1) +end + if #arg > 0 then rep("(load-file \""..arg[1].."\")") os.exit(0) diff --git a/lua/step9_try.lua b/lua/step9_try.lua index f3d8cce..315d698 100755 --- a/lua/step9_try.lua +++ b/lua/step9_try.lua @@ -174,23 +174,30 @@ 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)))))))") 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))))))))") +function print_exception(exc) + if exc then + if types._malexception_Q(exc) then + exc = printer._pr_str(exc.val, true) + end + print("Error: " .. exc) + print(debug.traceback()) + end +end + +if #arg > 0 and arg[1] == "--raw" then + readline.raw = true + table.remove(arg,1) +end + if #arg > 0 then - rep("(load-file \""..arg[1].."\")") + xpcall(function() rep("(load-file \""..arg[1].."\")") end, + print_exception) os.exit(0) end while true do line = readline.readline("user> ") if not line then break end - xpcall(function() - print(rep(line)) - end, function(exc) - if exc then - if types._malexception_Q(exc) then - exc = printer._pr_str(exc.val, true) - end - print("Error: " .. exc) - print(debug.traceback()) - end - end) + xpcall(function() print(rep(line)) end, + print_exception) end diff --git a/lua/stepA_mal.lua b/lua/stepA_mal.lua index 430fffc..db31789 100755 --- a/lua/stepA_mal.lua +++ b/lua/stepA_mal.lua @@ -185,6 +185,11 @@ function print_exception(exc) end end +if #arg > 0 and arg[1] == "--raw" then + readline.raw = true + table.remove(arg,1) +end + if #arg > 0 then xpcall(function() rep("(load-file \""..arg[1].."\")") end, print_exception) |
