Skip to content

Commit 22efb3d

Browse files
committed
ada.2: fix environments for closures
1 parent 900ab5c commit 22efb3d

File tree

9 files changed

+10
-72
lines changed

9 files changed

+10
-72
lines changed

impls/ada.2/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:20.04
1+
FROM ubuntu:24.04
22
MAINTAINER Joel Martin <[email protected]>
33

44
##########################################################

impls/ada.2/envs.ads

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ package Envs is
1414
subtype Ptr is not null Link;
1515

1616
function New_Env (Outer : in Link := null) return Ptr with Inline;
17-
-- Set_Binds is provided as distinct subprograms because we some
18-
-- time spare the creation of a subenvironment.
1917

2018
procedure Set_Binds (Env : in out Instance;
2119
Binds : in Types.T_Array;

impls/ada.2/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
exec $(dirname $0)/${STEP:-stepA_mal} "${@}"

impls/ada.2/step5_tco.adb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ procedure Step5_Tco is
4848
-- optimization goes to <<Restart>>.
4949
Ast : Types.T := Ast0;
5050
Env : Envs.Ptr := Env0;
51-
Env_Reusable : Boolean := False;
52-
-- True when the environment has been created in this recursion
53-
-- level, and has not yet been referenced by a closure. If so,
54-
-- we can reuse it instead of creating a subenvironment.
5551
First : Types.T;
5652
begin
5753
<<Restart>>
@@ -106,10 +102,7 @@ procedure Step5_Tco is
106102
renames Ast.Sequence.all.Data (2).Sequence.all.Data;
107103
begin
108104
Err.Check (Bindings'Length mod 2 = 0, "expected even binds");
109-
if not Env_Reusable then
110-
Env := Envs.New_Env (Outer => Env);
111-
Env_Reusable := True;
112-
end if;
105+
Env := Envs.New_Env (Outer => Env);
113106
for I in 0 .. Bindings'Length / 2 - 1 loop
114107
Env.all.Set (Bindings (Bindings'First + 2 * I),
115108
Eval (Bindings (Bindings'First + 2 * I + 1), Env));
@@ -146,7 +139,6 @@ procedure Step5_Tco is
146139
begin
147140
Err.Check (Params.Kind in Types.Kind_Sequence,
148141
"first argument of fn* must be a sequence");
149-
Env_Reusable := False;
150142
return (Kind_Fn, Types.Fns.New_Function
151143
(Params => Params.Sequence,
152144
Ast => Ast.Sequence.all.Data (3),
@@ -185,7 +177,6 @@ procedure Step5_Tco is
185177
end if;
186178
-- Like Types.Fns.Apply, except that we use TCO.
187179
Env := Envs.New_Env (Outer => First.Fn.all.Env);
188-
Env_Reusable := True;
189180
Env.all.Set_Binds (Binds => First.Fn.all.Params.all.Data,
190181
Exprs => Args);
191182
Ast := First.Fn.all.Ast;

impls/ada.2/step6_file.adb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ procedure Step6_File is
5252
-- optimization goes to <<Restart>>.
5353
Ast : Types.T := Ast0;
5454
Env : Envs.Ptr := Env0;
55-
Env_Reusable : Boolean := False;
56-
-- True when the environment has been created in this recursion
57-
-- level, and has not yet been referenced by a closure. If so,
58-
-- we can reuse it instead of creating a subenvironment.
5955
First : Types.T;
6056
begin
6157
<<Restart>>
@@ -110,10 +106,7 @@ procedure Step6_File is
110106
renames Ast.Sequence.all.Data (2).Sequence.all.Data;
111107
begin
112108
Err.Check (Bindings'Length mod 2 = 0, "expected even binds");
113-
if not Env_Reusable then
114-
Env := Envs.New_Env (Outer => Env);
115-
Env_Reusable := True;
116-
end if;
109+
Env := Envs.New_Env (Outer => Env);
117110
for I in 0 .. Bindings'Length / 2 - 1 loop
118111
Env.all.Set (Bindings (Bindings'First + 2 * I),
119112
Eval (Bindings (Bindings'First + 2 * I + 1), Env));
@@ -150,7 +143,6 @@ procedure Step6_File is
150143
begin
151144
Err.Check (Params.Kind in Types.Kind_Sequence,
152145
"first argument of fn* must be a sequence");
153-
Env_Reusable := False;
154146
return (Kind_Fn, Types.Fns.New_Function
155147
(Params => Params.Sequence,
156148
Ast => Ast.Sequence.all.Data (3),
@@ -189,7 +181,6 @@ procedure Step6_File is
189181
end if;
190182
-- Like Types.Fns.Apply, except that we use TCO.
191183
Env := Envs.New_Env (Outer => First.Fn.all.Env);
192-
Env_Reusable := True;
193184
Env.all.Set_Binds (Binds => First.Fn.all.Params.all.Data,
194185
Exprs => Args);
195186
Ast := First.Fn.all.Ast;

impls/ada.2/step7_quote.adb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ procedure Step7_Quote is
5454
-- optimization goes to <<Restart>>.
5555
Ast : Types.T := Ast0;
5656
Env : Envs.Ptr := Env0;
57-
Env_Reusable : Boolean := False;
58-
-- True when the environment has been created in this recursion
59-
-- level, and has not yet been referenced by a closure. If so,
60-
-- we can reuse it instead of creating a subenvironment.
6157
First : Types.T;
6258
begin
6359
<<Restart>>
@@ -112,10 +108,7 @@ procedure Step7_Quote is
112108
renames Ast.Sequence.all.Data (2).Sequence.all.Data;
113109
begin
114110
Err.Check (Bindings'Length mod 2 = 0, "expected even binds");
115-
if not Env_Reusable then
116-
Env := Envs.New_Env (Outer => Env);
117-
Env_Reusable := True;
118-
end if;
111+
Env := Envs.New_Env (Outer => Env);
119112
for I in 0 .. Bindings'Length / 2 - 1 loop
120113
Env.all.Set (Bindings (Bindings'First + 2 * I),
121114
Eval (Bindings (Bindings'First + 2 * I + 1), Env));
@@ -155,7 +148,6 @@ procedure Step7_Quote is
155148
begin
156149
Err.Check (Params.Kind in Types.Kind_Sequence,
157150
"first argument of fn* must be a sequence");
158-
Env_Reusable := False;
159151
return (Kind_Fn, Types.Fns.New_Function
160152
(Params => Params.Sequence,
161153
Ast => Ast.Sequence.all.Data (3),
@@ -198,7 +190,6 @@ procedure Step7_Quote is
198190
end if;
199191
-- Like Types.Fns.Apply, except that we use TCO.
200192
Env := Envs.New_Env (Outer => First.Fn.all.Env);
201-
Env_Reusable := True;
202193
Env.all.Set_Binds (Binds => First.Fn.all.Params.all.Data,
203194
Exprs => Args);
204195
Ast := First.Fn.all.Ast;

impls/ada.2/step8_macros.adb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ procedure Step8_Macros is
5454
-- optimization goes to <<Restart>>.
5555
Ast : Types.T := Ast0;
5656
Env : Envs.Ptr := Env0;
57-
Env_Reusable : Boolean := False;
58-
-- True when the environment has been created in this recursion
59-
-- level, and has not yet been referenced by a closure. If so,
60-
-- we can reuse it instead of creating a subenvironment.
6157
First : Types.T;
6258
begin
6359
<<Restart>>
@@ -112,10 +108,7 @@ procedure Step8_Macros is
112108
renames Ast.Sequence.all.Data (2).Sequence.all.Data;
113109
begin
114110
Err.Check (Bindings'Length mod 2 = 0, "expected even binds");
115-
if not Env_Reusable then
116-
Env := Envs.New_Env (Outer => Env);
117-
Env_Reusable := True;
118-
end if;
111+
Env := Envs.New_Env (Outer => Env);
119112
for I in 0 .. Bindings'Length / 2 - 1 loop
120113
Env.all.Set (Bindings (Bindings'First + 2 * I),
121114
Eval (Bindings (Bindings'First + 2 * I + 1), Env));
@@ -170,7 +163,6 @@ procedure Step8_Macros is
170163
begin
171164
Err.Check (Params.Kind in Types.Kind_Sequence,
172165
"first argument of fn* must be a sequence");
173-
Env_Reusable := False;
174166
return (Kind_Fn, Types.Fns.New_Function
175167
(Params => Params.Sequence,
176168
Ast => Ast.Sequence.all.Data (3),
@@ -223,7 +215,6 @@ procedure Step8_Macros is
223215
end if;
224216
-- Like Types.Fns.Apply, except that we use TCO.
225217
Env := Envs.New_Env (Outer => First.Fn.all.Env);
226-
Env_Reusable := True;
227218
Env.all.Set_Binds (Binds => First.Fn.all.Params.all.Data,
228219
Exprs => Args);
229220
Ast := First.Fn.all.Ast;

impls/ada.2/step9_try.adb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ procedure Step9_Try is
5454
-- optimization goes to <<Restart>>.
5555
Ast : Types.T := Ast0;
5656
Env : Envs.Ptr := Env0;
57-
Env_Reusable : Boolean := False;
58-
-- True when the environment has been created in this recursion
59-
-- level, and has not yet been referenced by a closure. If so,
60-
-- we can reuse it instead of creating a subenvironment.
6157
First : Types.T;
6258
begin
6359
<<Restart>>
@@ -112,10 +108,7 @@ procedure Step9_Try is
112108
renames Ast.Sequence.all.Data (2).Sequence.all.Data;
113109
begin
114110
Err.Check (Bindings'Length mod 2 = 0, "expected even binds");
115-
if not Env_Reusable then
116-
Env := Envs.New_Env (Outer => Env);
117-
Env_Reusable := True;
118-
end if;
111+
Env := Envs.New_Env (Outer => Env);
119112
for I in 0 .. Bindings'Length / 2 - 1 loop
120113
Env.all.Set (Bindings (Bindings'First + 2 * I),
121114
Eval (Bindings (Bindings'First + 2 * I + 1), Env));
@@ -170,7 +163,6 @@ procedure Step9_Try is
170163
begin
171164
Err.Check (Params.Kind in Types.Kind_Sequence,
172165
"first argument of fn* must be a sequence");
173-
Env_Reusable := False;
174166
return (Kind_Fn, Types.Fns.New_Function
175167
(Params => Params.Sequence,
176168
Ast => Ast.Sequence.all.Data (3),
@@ -202,10 +194,7 @@ procedure Step9_Try is
202194
when Err.Error =>
203195
null;
204196
end;
205-
if not Env_Reusable then
206-
Env := Envs.New_Env (Outer => Env);
207-
Env_Reusable := True;
208-
end if;
197+
Env := Envs.New_Env (Outer => Env);
209198
Env.all.Set (A3 (A3'First + 1), Err.Data); -- check key kind
210199
Ast := A3 (A3'Last);
211200
goto Restart;
@@ -253,7 +242,6 @@ procedure Step9_Try is
253242
end if;
254243
-- Like Types.Fns.Apply, except that we use TCO.
255244
Env := Envs.New_Env (Outer => First.Fn.all.Env);
256-
Env_Reusable := True;
257245
Env.all.Set_Binds (Binds => First.Fn.all.Params.all.Data,
258246
Exprs => Args);
259247
Ast := First.Fn.all.Ast;

impls/ada.2/stepa_mal.adb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ procedure StepA_Mal is
5555
-- optimization goes to <<Restart>>.
5656
Ast : Types.T := Ast0;
5757
Env : Envs.Ptr := Env0;
58-
Env_Reusable : Boolean := False;
59-
-- True when the environment has been created in this recursion
60-
-- level, and has not yet been referenced by a closure. If so,
61-
-- we can reuse it instead of creating a subenvironment.
6258
First : Types.T;
6359
begin
6460
<<Restart>>
@@ -113,10 +109,7 @@ procedure StepA_Mal is
113109
renames Ast.Sequence.all.Data (2).Sequence.all.Data;
114110
begin
115111
Err.Check (Bindings'Length mod 2 = 0, "expected even binds");
116-
if not Env_Reusable then
117-
Env := Envs.New_Env (Outer => Env);
118-
Env_Reusable := True;
119-
end if;
112+
Env := Envs.New_Env (Outer => Env);
120113
for I in 0 .. Bindings'Length / 2 - 1 loop
121114
Env.all.Set (Bindings (Bindings'First + 2 * I),
122115
Eval (Bindings (Bindings'First + 2 * I + 1), Env));
@@ -171,7 +164,6 @@ procedure StepA_Mal is
171164
begin
172165
Err.Check (Params.Kind in Types.Kind_Sequence,
173166
"first argument of fn* must be a sequence");
174-
Env_Reusable := False;
175167
return (Kind_Fn, Types.Fns.New_Function
176168
(Params => Params.Sequence,
177169
Ast => Ast.Sequence.all.Data (3),
@@ -203,10 +195,7 @@ procedure StepA_Mal is
203195
when Err.Error =>
204196
null;
205197
end;
206-
if not Env_Reusable then
207-
Env := Envs.New_Env (Outer => Env);
208-
Env_Reusable := True;
209-
end if;
198+
Env := Envs.New_Env (Outer => Env);
210199
Env.all.Set (A3 (A3'First + 1), Err.Data); -- check key kind
211200
Ast := A3 (A3'Last);
212201
goto Restart;
@@ -259,7 +248,6 @@ procedure StepA_Mal is
259248
end case;
260249
-- Like Types.Fns.Apply, except that we use TCO.
261250
Env := Envs.New_Env (Outer => First.Fn.all.Env);
262-
Env_Reusable := True;
263251
Env.all.Set_Binds (Binds => First.Fn.all.Params.all.Data,
264252
Exprs => Args);
265253
Ast := First.Fn.all.Ast;

0 commit comments

Comments
 (0)