mirror of
https://github.com/kanaka/mal.git
synced 2024-08-18 02:00:40 +03:00
8a19f60386
- Reorder README to have implementation list after "learning tool" bullet. - This also moves tests/ and libs/ into impls. It would be preferrable to have these directories at the top level. However, this causes difficulties with the wasm implementations which need pre-open directories and have trouble with paths starting with "../../". So in lieu of that, symlink those directories to the top-level. - Move the run_argv_test.sh script into the tests directory for general hygiene.
48 lines
900 B
Lua
Executable File
48 lines
900 B
Lua
Executable File
#!/usr/bin/env lua
|
|
|
|
local readline = require('readline')
|
|
local utils = require('utils')
|
|
local types = require('types')
|
|
local reader = require('reader')
|
|
local printer = require('printer')
|
|
|
|
-- read
|
|
function READ(str)
|
|
return reader.read_str(str)
|
|
end
|
|
|
|
-- eval
|
|
function EVAL(ast, env)
|
|
return ast
|
|
end
|
|
|
|
-- print
|
|
function PRINT(exp)
|
|
return printer._pr_str(exp, true)
|
|
end
|
|
|
|
-- repl
|
|
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
|
|
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)
|
|
end
|