about summary refs log tree commit diff stats
path: root/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-10 23:47:19 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-10 23:47:19 -0700
commitfea45ccbea6bee563b41da199fb3c456c6069cb5 (patch)
treeae17f018819c5ba9674b8017000d553555dfadb1 /shell
parent12569711c9892e6b95859e056e45feb8ba662eb4 (diff)
downloadmu-fea45ccbea6bee563b41da199fb3c456c6069cb5.tar.gz
shell: full closures
Diffstat (limited to 'shell')
-rw-r--r--shell/evaluate.mu17
1 files changed, 11 insertions, 6 deletions
diff --git a/shell/evaluate.mu b/shell/evaluate.mu
index e47762ef..3aedb7c7 100644
--- a/shell/evaluate.mu
+++ b/shell/evaluate.mu
@@ -56,14 +56,19 @@ fn evaluate _in: (addr handle cell), out: (addr handle cell), env-h: (handle cel
     # trees starting with "fn" are anonymous functions and therefore literals
     var expr/esi: (addr cell) <- copy in-addr
     # if its first elem is not "fn", break
+    var in-addr/edx: (addr cell) <- copy in-addr
     var first-ah/ecx: (addr handle cell) <- get in-addr, left
     var first/eax: (addr cell) <- lookup *first-ah
     var fn?/eax: boolean <- fn? first
     compare fn?, 0/false
     break-if-=
-    #
+    # turn (fn ...) into (fn env ...)
     trace-text trace, "eval", "anonymous function"
-    copy-object _in, out
+    var rest-ah/eax: (addr handle cell) <- get in-addr, right
+    var tmp: (handle cell)
+    var tmp-ah/edi: (addr handle cell) <- address tmp
+    new-pair tmp-ah, env-h, *rest-ah
+    new-pair out, *first-ah, *tmp-ah
     trace-higher trace
     return
   }
@@ -255,12 +260,12 @@ fn apply _f-ah: (addr handle cell), args-ah: (addr handle cell), out: (addr hand
     break-if-=
     var rest-ah/esi: (addr handle cell) <- get f, right
     var rest/eax: (addr cell) <- lookup *rest-ah
+    var callee-env-ah/edx: (addr handle cell) <- get rest, left
+    rest-ah <- get rest, right
+    rest <- lookup *rest-ah
     var params-ah/ecx: (addr handle cell) <- get rest, left
     var body-ah/eax: (addr handle cell) <- get rest, right
-    var nil-env-h: (handle cell)
-    var nil-env-ah/edx: (addr handle cell) <- address nil-env-h
-    allocate-pair nil-env-ah
-    apply-function params-ah, args-ah, body-ah, out, nil-env-h, globals, trace, screen-cell, keyboard-cell
+    apply-function params-ah, args-ah, body-ah, out, *callee-env-ah, globals, trace, screen-cell, keyboard-cell
     trace-higher trace
     return
   }
rray.mu?h=main&id=9636c7ae2417a32831123c4f4ae3900c0a0bea16'>9636c7ae ^
e5f9c6ae ^
4a48bedc ^
7a84094a ^
9636c7ae ^

51b0936f ^
502d2ea5 ^
4a48bedc ^

991d76f3 ^
502d2ea5 ^
9636c7ae ^

1ead3562 ^
9636c7ae ^
56e00e88 ^


65cec710 ^
56e00e88 ^
4a48bedc ^
56e00e88 ^




4a48bedc ^
56e00e88 ^







6f65d591 ^

56e00e88 ^
56e00e88 ^











6f65d591 ^


56e00e88 ^
56e00e88 ^










4a48bedc ^
6f65d591 ^

56e00e88 ^
56e00e88 ^












65cec710 ^
56e00e88 ^
4a48bedc ^
56e00e88 ^






6f65d591 ^


56e00e88 ^
56e00e88 ^













4a48bedc ^
56e00e88 ^













6f65d591 ^


56e00e88 ^
56e00e88 ^











6f65d591 ^


56e00e88 ^
56e00e88 ^










1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181