Lua: fix with new runtest.py
authorJoel Martin <github@martintribe.org>
Sat, 28 Feb 2015 21:58:35 +0000 (15:58 -0600)
committerJoel Martin <github@martintribe.org>
Sat, 28 Feb 2015 21:58:35 +0000 (15:58 -0600)
14 files changed:
Makefile
docs/TODO
lua/core.lua
lua/readline.lua
lua/step1_read_print.lua
lua/step2_eval.lua
lua/step3_env.lua
lua/step4_if_fn_do.lua
lua/step5_tco.lua
lua/step6_file.lua
lua/step7_quote.lua
lua/step8_macros.lua
lua/step9_try.lua
lua/stepA_mal.lua

index 6405422..85652a6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -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)
index 0452fe0..8abbf6c 100644 (file)
--- a/docs/TODO
+++ b/docs/TODO
@@ -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
index 3f46aeb..279a6d6 100644 (file)
@@ -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
 
index a75f4ff..5acdb54 100644 (file)
@@ -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")
index abd555d..46d71f5 100755 (executable)
@@ -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
index 7487064..22ac8cf 100755 (executable)
@@ -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
index ed2e62a..dbdb879 100755 (executable)
@@ -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
index e211973..65b3a0a 100755 (executable)
@@ -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
index fa4e41f..237f5ea 100755 (executable)
@@ -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
index b109a90..7992888 100755 (executable)
@@ -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)
index 974e342..32bf60c 100755 (executable)
@@ -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)
index 46a5881..25a9238 100755 (executable)
@@ -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)
index f3d8cce..315d698 100755 (executable)
@@ -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
index 430fffc..db31789 100755 (executable)
@@ -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)