mirror of
https://github.com/kanaka/mal.git
synced 2024-09-17 16:47:22 +03:00
Lua: fix with new runtest.py
This commit is contained in:
parent
7907cd904a
commit
3e0b36dcee
2
Makefile
2
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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user