From 8ce2915e3c54598c2fda4fec0980ebfc2a3adf6e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 9 Apr 2024 21:04:17 -0500 Subject: Reorganization --- repl.lua | 81 ++++------------------------------------------------------------ 1 file changed, 4 insertions(+), 77 deletions(-) (limited to 'repl.lua') diff --git a/repl.lua b/repl.lua index c4a6546..4bdd918 100644 --- a/repl.lua +++ b/repl.lua @@ -1,25 +1,9 @@ --- lam.repl local m = {} -local _r = require("read") -local read, inport, read_string, eof = - _r.read, _r.inport, _r.read_string, _r.eof -local eval = require("eval").eval +local load = require("load").load -local function schemeprint (x) - -- if x == nil then return end - if x == true then - print("#t") - elseif x == false then - print("#f") - elseif x == nil then - print("#") - else - print(x) - end -end - -local lam = [[ +m.logo = [[ @,,,@ <|^ ^|> l a m | /) 0015 @@ -27,66 +11,9 @@ local lam = [[ ------------- ]] -local function handle_error (e) - local start = e:find(": ") - return e:sub(start + 2) -end - -function m.read_eval (filename, interactive) - -- interactive = { out = file or handle, prompt = string, } - local inport = inport(filename) - local prompt = interactive and interactive.prompt or "> " - if interactive then - io.output(interactive.out or io.stdout) - io.write(lam) - io.output():setvbuf("line") - else - io.output():setvbuf("no") - end - repeat - if interactive then - io.stderr:write(prompt) - io.stderr:flush() - end - -- read - local ok, x = xpcall( - function () - local nxt = read(inport) - return nxt - end, - handle_error - ) - if not ok then - io.stderr:write("(read) not ok: ", x, "\n") - -- in interactive mode, errors should not be fatal. in - -- batch mode, they should be. - if not interactive then return nil end - end - -- eval - if ok then - local ok, v = xpcall( - function () return eval(x) end, - handle_error - ) - if not ok then - io.stderr:write("(eval) not ok: ", v, "\n") - if not interactive then return nil end - end - -- print - if ok and interactive then schemeprint(v) end - elseif interactive then - ok = "recover" - end - until x == eof -- loop - inport:close() -end - function m.repl (prompt) - return m.read_eval(nil, { prompt = prompt, }) -end - -function m.load (filename) - return m.read_eval(filename) + io.stderr:write(m.logo) + return load(nil, {prompt = prompt or "> ", }) end -------- -- cgit 1.4.1-21-gabe81