diff options
-rw-r--r-- | core.lua | 7 | ||||
-rw-r--r-- | eval.lua | 6 | ||||
-rw-r--r-- | 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) | |||
16 | end | 16 | end |
17 | end | 17 | end |
18 | 18 | ||
19 | local env = {} | 19 | local env = type.environment({}, {}) |
20 | |||
21 | env["interaction-environment"] = function (r) | ||
22 | assert_arity(r,0,0) | ||
23 | return env | ||
24 | end | ||
20 | 25 | ||
21 | ---[[ EQUIVALENCE ]]--- | 26 | ---[[ EQUIVALENCE ]]--- |
22 | 27 | ||
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 | |||
6 | local util = require("util") | 6 | local util = require("util") |
7 | local error = util.error | 7 | local error = util.error |
8 | 8 | ||
9 | m.special_forms = { | 9 | m.primitives = { |
10 | quote = | 10 | quote = |
11 | function (r, _) | 11 | function (r, _) |
12 | assert_arity(r,1,1) | 12 | assert_arity(r,1,1) |
@@ -89,8 +89,8 @@ function m.eval (x, env) | |||
89 | return x | 89 | return x |
90 | else | 90 | else |
91 | local op, args = x[1], x[2] | 91 | local op, args = x[1], x[2] |
92 | if m.special_forms[op] then | 92 | if m.primitives[op] then |
93 | return m.special_forms[op](args, env) | 93 | return m.primitives[op](args, env) |
94 | else -- procedure application | 94 | else -- procedure application |
95 | local fn = m.eval(op, env) | 95 | local fn = m.eval(op, env) |
96 | local params = {} | 96 | 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) | |||
15 | end | 15 | end |
16 | end | 16 | end |
17 | 17 | ||
18 | local function handle_error (e) | 18 | function core.environment.read (r) |
19 | local start = e:find(": ") | 19 | type.assert_arity(r,1,1) |
20 | return e:sub(start + 2) | 20 | error("unimplemented") |
21 | end | ||
22 | |||
23 | function core.environment.eval (r) | ||
24 | type.assert_arity(r,1,2) | ||
25 | local form = r[1] | ||
26 | local env = r[2][1] or core.environment | ||
27 | return eval.eval(form, env) | ||
28 | end | ||
29 | |||
30 | function core.environment.load (r) | ||
31 | type.assert_arity(r,1,1) | ||
32 | return m.load(tostring(r[1])) | ||
21 | end | 33 | end |
22 | 34 | ||
23 | function m.load (filename, interactive) | 35 | function m.load (filename, interactive) |
@@ -29,6 +41,12 @@ function m.load (filename, interactive) | |||
29 | else | 41 | else |
30 | io.output():setvbuf("no") | 42 | io.output():setvbuf("no") |
31 | end | 43 | end |
44 | |||
45 | local function handle_error (e) | ||
46 | local start = e:find(": ") | ||
47 | return e:sub(start + 2) | ||
48 | end | ||
49 | |||
32 | repeat | 50 | repeat |
33 | if interactive then | 51 | if interactive then |
34 | io.stderr:write(interactive.prompt or "") | 52 | io.stderr:write(interactive.prompt or "") |