Skip to content

Commit c14ce79

Browse files
committed
Eliminated most of the use of E_CONS outside of the core utilities. Some
code cleanup was also done. Tests were rerun and coverage updated.
1 parent 3edfd52 commit c14ce79

10 files changed

+139
-128
lines changed

documentation/Coverage-Summary.ods

-9 Bytes
Binary file not shown.

src/bbs-lisp-evaluate-func.adb

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package body BBS.lisp.evaluate.func is
1616
procedure defun(e : out element_type; s : cons_index; p : phase) is
1717
params : element_type;
1818
name : element_type;
19-
temp : element_type;
19+
temp : cons_index;
2020
p2 : element_type;
2121
p3 : element_type;
2222
symb : symb_index;
@@ -41,7 +41,7 @@ package body BBS.lisp.evaluate.func is
4141
--
4242
p2 := cons_table(s).cdr;
4343
p3 := cons_table(p2.ps).car; -- Should be a symbol or tempsym
44-
temp := cons_table(p2.ps).cdr; -- Should be parameter list.
44+
temp := getList(cons_table(p2.ps).cdr); -- Should be parameter list.
4545
--
4646
-- Process the function name
4747
--
@@ -75,32 +75,32 @@ package body BBS.lisp.evaluate.func is
7575
-- functions or local blocks. Thus there should be no stack
7676
-- variables to check when processing the parameter list.
7777
--
78-
if isList(temp) then
79-
params := cons_table(getList(temp)).car;
78+
if temp > NIL_CONS then
79+
params := cons_table(temp).car;
8080
else
8181
error("defun", "Improper parameters.");
8282
e := (Kind => E_ERROR);
8383
return;
8484
end if;
85-
temp := params;
85+
temp := getList(params);
8686
BBS.lisp.stack.start_frame(error_occured);
87-
while temp.Kind = E_CONS loop
88-
if isList(cons_table(temp.ps).car) then
87+
while temp > NIL_CONS loop
88+
if isList(cons_table(temp).car) then
8989
error("defun", "A parameter cannot be a list.");
90-
BBS.lisp.memory.deref(cons_table(temp.ps).car);
91-
cons_table(temp.ps).car := (Kind => E_ERROR);
90+
BBS.lisp.memory.deref(cons_table(temp).car);
91+
cons_table(temp).car := (Kind => E_ERROR);
9292
error_occured := True;
9393
end if;
9494
declare
95-
el : element_type := cons_table(temp.ps).car;
95+
el : element_type := cons_table(temp).car;
9696
str : string_index;
9797
offset : Natural := 1;
9898
begin
9999
if (el.Kind = E_SYMBOL) then
100100
if (symb_table(el.sym).Kind = SY_BUILTIN) or
101101
(symb_table(el.sym).Kind = SY_SPECIAL) then
102102
error("defun", "Parameter can't be a builtin or special symbol.");
103-
cons_table(temp.ps).car := (Kind => E_ERROR);
103+
cons_table(temp).car := (Kind => E_ERROR);
104104
error_occured := True;
105105
else
106106
msg("defun", "Converting symbol to parameter.");
@@ -123,23 +123,23 @@ package body BBS.lisp.evaluate.func is
123123
error("defun", "Can't convert item into a parameter.");
124124
print(el, False, True);
125125
Put_Line("Item is of kind " & ptr_type'Image(el.kind));
126-
BBS.lisp.memory.deref(cons_table(temp.ps).car);
127-
cons_table(temp.ps).car := (Kind => E_ERROR);
126+
BBS.lisp.memory.deref(cons_table(temp).car);
127+
cons_table(temp).car := (Kind => E_ERROR);
128128
error_occured := True;
129129
end if;
130130
offset := offset + 1;
131-
cons_table(temp.ps).car := el;
131+
cons_table(temp).car := el;
132132
end;
133-
temp := cons_table(temp.ps).cdr;
133+
temp := getList(cons_table(temp).cdr);
134134
end loop;
135135
else
136136
error("defun", "Something went horribly wrong and defun did not get a list.");
137137
error_occured := True;
138138
end if;
139139
if error_occured then
140140
BBS.lisp.memory.deref(params);
141-
temp := cons_table(p2.ps).cdr;
142-
cons_table(temp.ps).car := (Kind => E_ERROR);
141+
temp := getList(cons_table(p2.ps).cdr);
142+
cons_table(temp).car := (Kind => E_ERROR);
143143
e := (Kind => E_ERROR);
144144
end if;
145145
when PH_PARSE_END =>
@@ -154,9 +154,9 @@ package body BBS.lisp.evaluate.func is
154154
return;
155155
end if;
156156
name := cons_table(s).car;
157-
temp := cons_table(s).cdr;
158-
if isList(temp) then
159-
params := cons_table(getList(temp)).car;
157+
temp := getList(cons_table(s).cdr);
158+
if temp > NIL_CONS then
159+
params := cons_table(temp).car;
160160
else
161161
error("defun", "Improper parameters.");
162162
e := (kind => E_ERROR);
@@ -167,7 +167,7 @@ package body BBS.lisp.evaluate.func is
167167
e := (kind => E_ERROR);
168168
return;
169169
end if;
170-
if (params.kind /= E_CONS) and (params.kind /= E_NIL) then
170+
if (not isList(params)) and (params.kind /= E_NIL) then
171171
error("defun", "Parameter list must be a list or NIL.");
172172
e := (kind => E_ERROR);
173173
return;
@@ -185,10 +185,10 @@ package body BBS.lisp.evaluate.func is
185185
elsif symb_table(symb).kind = SY_VARIABLE then
186186
BBS.lisp.memory.deref(symb_table(symb).pv);
187187
end if;
188-
temp := cons_table(s).cdr;
188+
temp := getList(cons_table(s).cdr);
189189
cons_table(s).cdr := NIL_ELEM;
190190
symb_table(symb) := (ref => 1, str => symb_table(symb).str,
191-
kind => SY_LAMBDA, ps => temp.ps);
191+
kind => SY_LAMBDA, ps => temp);
192192
end case;
193193
e := NIL_ELEM;
194194
end;
@@ -205,7 +205,7 @@ package body BBS.lisp.evaluate.func is
205205
--
206206
procedure lambda(e : out element_type; s : cons_index; p : phase) is
207207
params : element_type;
208-
temp : element_type;
208+
temp : cons_index;
209209
error_occured : Boolean := False;
210210
begin
211211
--
@@ -235,26 +235,26 @@ package body BBS.lisp.evaluate.func is
235235
e := (kind => E_ERROR);
236236
return;
237237
end if;
238-
temp := params;
238+
temp := getList(params);
239239
BBS.lisp.stack.start_frame(error_occured);
240240
declare
241241
el : element_type;
242242
str : string_index;
243243
offset : Natural := 1;
244244
begin
245-
while temp.kind = E_CONS loop
246-
if isList(cons_table(temp.ps).car) then
245+
while temp > NIL_CONS loop
246+
if isList(cons_table(temp).car) then
247247
error("lambda", "A parameter cannot be a list.");
248-
BBS.lisp.memory.deref(cons_table(temp.ps).car);
249-
cons_table(temp.ps).car := (Kind => E_ERROR);
248+
BBS.lisp.memory.deref(cons_table(temp).car);
249+
cons_table(temp).car := (Kind => E_ERROR);
250250
error_occured := True;
251251
end if;
252-
el := cons_table(temp.ps).car;
252+
el := cons_table(temp).car;
253253
if (el.kind = E_SYMBOL) then
254254
if (symb_table(el.sym).Kind = SY_BUILTIN) or
255255
(symb_table(el.sym).Kind = SY_SPECIAL) then
256256
error("lambda", "Parameter can't be a builtin or special symbol.");
257-
cons_table(temp.ps).car := (Kind => E_ERROR);
257+
cons_table(temp).car := (Kind => E_ERROR);
258258
error_occured := True;
259259
else
260260
str := symb_table(el.sym).str;
@@ -277,13 +277,13 @@ package body BBS.lisp.evaluate.func is
277277
error("lambda", "Can't convert item into a parameter.");
278278
print(el, False, True);
279279
Put_Line("Item is of kind " & ptr_type'Image(el.kind));
280-
BBS.lisp.memory.deref(cons_table(temp.ps).car);
281-
cons_table(temp.ps).car := (Kind => E_ERROR);
280+
BBS.lisp.memory.deref(cons_table(temp).car);
281+
cons_table(temp).car := (Kind => E_ERROR);
282282
error_occured := True;
283283
end if;
284284
offset := offset + 1;
285-
cons_table(temp.ps).car := el;
286-
temp := cons_table(temp.ps).cdr;
285+
cons_table(temp).car := el;
286+
temp := getList(cons_table(temp).cdr);
287287
end loop;
288288
end;
289289
else
@@ -292,8 +292,8 @@ package body BBS.lisp.evaluate.func is
292292
end if;
293293
if error_occured then
294294
BBS.lisp.memory.deref(params);
295-
temp := cons_table(s).cdr;
296-
cons_table(temp.ps).car := (Kind => E_ERROR);
295+
temp := getList(cons_table(s).cdr);
296+
cons_table(temp).car := (Kind => E_ERROR);
297297
e := (Kind => E_ERROR);
298298
end if;
299299
when PH_PARSE_END =>
@@ -307,15 +307,15 @@ package body BBS.lisp.evaluate.func is
307307
e := (kind => E_ERROR);
308308
return;
309309
end if;
310-
temp := cons_table(s).car;
311-
if isList(temp) then
312-
params := temp;
310+
temp := getList(cons_table(s).car);
311+
if temp > NIL_CONS then
312+
params := makeList(temp);
313313
else
314314
error("defun", "Improper parameters.");
315315
e := (kind => E_ERROR);
316316
return;
317317
end if;
318-
if (params.kind /= E_CONS) and (params.kind /= E_NIL) then
318+
if (not isList(params)) and (params.kind /= E_NIL) then
319319
error("lambda", "Parameter list must be a list or NIL.");
320320
e := (kind => E_ERROR);
321321
return;

src/bbs-lisp-evaluate-list.adb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ package body BBS.lisp.evaluate.list is
7979
-- Create a list verbatum from the parameter list
8080
--
8181
procedure quote(e : out element_type; s : cons_index) is
82-
t : constant element_type := (kind => E_CONS, ps => s);
8382
begin
84-
bbs.lisp.memory.ref(t);
85-
e := t;
83+
bbs.lisp.memory.ref(s);
84+
e := makeList(s);
8685
end;
8786
--
8887
-- Create a list by evaluating the parameters, similar to quote, but quote

src/bbs-lisp-evaluate-loops.adb

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ package body BBS.lisp.evaluate.loops is
8080
-- (dotimes (local count [result]) <body>).
8181
--
8282
procedure dotimes(e : out element_type; s : cons_index; p : phase) is
83-
limits : element_type; -- Condition to evaluate
83+
limits : cons_index; -- Condition to evaluate
8484
list : element_type; -- List of operations to execute
8585
result : element_type := NIL_ELEM;
8686
var : element_type := NIL_ELEM;
87-
rest : element_type := NIL_ELEM;
87+
rest : cons_index := NIL_CONS;
8888
limit : element_type := NIL_ELEM;
8989
limit_value : Natural := 0;
9090
s1 : cons_index;
@@ -99,38 +99,38 @@ package body BBS.lisp.evaluate.loops is
9999
BBS.lisp.stack.start_frame(err);
100100
if s > NIL_CONS then
101101
list := cons_table(s).car; -- This is the dotimes symbol and ignored here
102-
limits := cons_table(s).cdr;
102+
limits := getList(cons_table(s).cdr);
103103
--
104104
-- Extract local variable, limit, and optional result
105105
--
106-
if not isList(limits) then
106+
if limits = NIL_CONS then
107107
error("dotimes", "No parameters provided");
108108
e := (kind => E_ERROR);
109109
return;
110110
end if;
111-
limits := cons_table(getList(limits)).car;
112-
if not isList(limits) then
111+
limits := getList(cons_table(limits).car);
112+
if limits = NIL_CONS then
113113
error("dotimes", "List not provided for limits.");
114114
e := (kind => E_ERROR);
115115
return;
116116
end if;
117-
var := cons_table(getList(limits)).car;
118-
rest := cons_table(getList(limits)).cdr;
117+
var := cons_table(limits).car;
118+
rest := getList(cons_table(limits).cdr);
119119
if isList(var) then
120120
error("dotimes", "The loop variable cannot be a list.");
121121
BBS.lisp.memory.deref(var);
122-
cons_table(getList(limits)).car := (Kind => E_ERROR);
122+
cons_table(limits).car := (Kind => E_ERROR);
123123
e := (kind => E_ERROR);
124124
return;
125125
end if;
126-
if isList(rest) then
127-
limit := cons_table(getList(rest)).car;
126+
if rest > NIL_CONS then
127+
limit := cons_table(rest).car;
128128
if isList(limit) then
129129
limit := eval_dispatch(getList(limit));
130130
else
131131
limit := indirect_elem(limit);
132132
end if;
133-
result := cons_table(rest.ps).cdr;
133+
result := cons_table(rest).cdr;
134134
if isList(result) then
135135
result := cons_table(getList(result)).car;
136136
end if;
@@ -171,7 +171,7 @@ package body BBS.lisp.evaluate.loops is
171171
-- Var has been converted to a local variable. Now put it back into
172172
-- the list.
173173
--
174-
cons_table(limits.ps).car := var;
174+
cons_table(limits).car := var;
175175
end if;
176176
e := NIL_ELEM;
177177
when PH_PARSE_END =>
@@ -182,29 +182,28 @@ package body BBS.lisp.evaluate.loops is
182182
-- EXECUTE Phase
183183
--
184184
if s > NIL_CONS then
185-
limits := cons_table(s).car;
185+
limits := getList(cons_table(s).car);
186186
list := cons_table(s).cdr;
187187
--
188188
-- Extract local variable, limit, and optional result
189189
--
190-
if limits.kind = E_CONS then
191-
var := cons_table(limits.ps).car;
192-
rest := cons_table(limits.ps).cdr;
193-
else
190+
if limits = NIL_CONS then
194191
error("dotimes", "List not provided for limits.");
195192
e := (kind => E_ERROR);
196193
return;
197194
end if;
198-
if rest.kind = E_CONS then
199-
limit := cons_table(rest.ps).car;
200-
if limit.kind = E_CONS then
201-
limit := eval_dispatch(limit.ps);
195+
var := cons_table(limits).car;
196+
rest := getList(cons_table(limits).cdr);
197+
if rest > NIL_CONS then
198+
limit := cons_table(rest).car;
199+
if isList(limit) then
200+
limit := eval_dispatch(getList(limit));
202201
else
203202
limit := indirect_elem(limit);
204203
end if;
205-
result := cons_table(rest.ps).cdr;
206-
if result.kind = E_CONS then
207-
result := cons_table(result.ps).car;
204+
result := cons_table(rest).cdr;
205+
if isList(result) then
206+
result := cons_table(getList(result)).car;
208207
end if;
209208
else
210209
error("dotimes", "Loop limit not provided.");
@@ -215,8 +214,8 @@ package body BBS.lisp.evaluate.loops is
215214
--
216215
-- Next determine what the loop limit is
217216
--
218-
if limit.kind = E_CONS then
219-
s1 := limit.ps;
217+
if isList(limit) then
218+
s1 := getList(limit);
220219
limit := first_value(s1);
221220
end if;
222221
if limit.kind = E_VALUE then
@@ -241,8 +240,8 @@ package body BBS.lisp.evaluate.loops is
241240
--
242241
-- Find the index variable name in the body and convert all occurences.
243242
--
244-
if list.kind = E_CONS then
245-
dummy := BBS.lisp.utilities.replace_sym(list.ps, var);
243+
if isList(list) then
244+
dummy := BBS.lisp.utilities.replace_sym(getList(list), var);
246245
end if;
247246
--
248247
-- Build the stack frame
@@ -290,8 +289,8 @@ package body BBS.lisp.evaluate.loops is
290289
-- Exit the stack frame
291290
--
292291
BBS.lisp.stack.exit_frame;
293-
if result.kind = E_CONS then
294-
t := eval_dispatch(result.ps);
292+
if isList(result) then
293+
t := eval_dispatch(getList(result));
295294
else
296295
t := indirect_elem(result);
297296
if t.kind = E_ERROR then
@@ -306,7 +305,7 @@ package body BBS.lisp.evaluate.loops is
306305
--
307306
procedure progn(e : out element_type; s : cons_index) is
308307
begin
309-
e := execute_block((kind => E_CONS, ps => s));
308+
e := execute_block(makeList(s));
310309
end;
311310
--
312311
-- Breaks out of a loop (or other exclosing block) and returns a value

0 commit comments

Comments
 (0)