From 6c49847668e01d45cf56ec2b2e4fbf312957ee3d Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 15 Apr 2024 22:00:37 -0500 Subject: Change names and hoist eval read is unimplemented and load is buggy --- core.lua | 7 ++++++- eval.lua | 6 +++--- load.lua | 24 +++++++++++++++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/core.lua b/core.lua index 3e4773a..4f84f7f 100644 --- a/core.lua +++ b/core.lua @@ -16,7 +16,12 @@ local function fold (kons, knil, r) end end -local env = {} +local env = type.environment({}, {}) + +env["interaction-environment"] = function (r) + assert_arity(r,0,0) + return env +end ---[[ EQUIVALENCE ]]--- diff --git a/eval.lua b/eval.lua index 4b8f782..342624f 100644 --- a/eval.lua +++ b/eval.lua @@ -6,7 +6,7 @@ local assert_arity = type.assert_arity local util = require("util") local error = util.error -m.special_forms = { +m.primitives = { quote = function (r, _) assert_arity(r,1,1) @@ -89,8 +89,8 @@ function m.eval (x, env) return x else local op, args = x[1], x[2] - if m.special_forms[op] then - return m.special_forms[op](args, env) + if m.primitives[op] then + return m.primitives[op](args, env) else -- procedure application local fn = m.eval(op, env) local params = {} diff --git a/load.lua b/load.lua index 7f14207..db2651f 100644 --- a/load.lua +++ b/load.lua @@ -15,9 +15,21 @@ local function schemeprint (x) end end -local function handle_error (e) - local start = e:find(": ") - return e:sub(start + 2) +function core.environment.read (r) + type.assert_arity(r,1,1) + error("unimplemented") +end + +function core.environment.eval (r) + type.assert_arity(r,1,2) + local form = r[1] + local env = r[2][1] or core.environment + return eval.eval(form, env) +end + +function core.environment.load (r) + type.assert_arity(r,1,1) + return m.load(tostring(r[1])) end function m.load (filename, interactive) @@ -29,6 +41,12 @@ function m.load (filename, interactive) else io.output():setvbuf("no") end + + local function handle_error (e) + local start = e:find(": ") + return e:sub(start + 2) + end + repeat if interactive then io.stderr:write(interactive.prompt or "") -- cgit 1.4.1-21-gabe81