Skip to content

Commit

Permalink
correct latest out of bounds panic, use first argument indexing in ma…
Browse files Browse the repository at this point in the history
…plists/{2..9}
  • Loading branch information
mthom committed Oct 12, 2019
1 parent f898b98 commit 5893ff4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 35 deletions.
78 changes: 47 additions & 31 deletions src/prolog/lib/lists.pl
Original file line number Diff line number Diff line change
Expand Up @@ -50,42 +50,58 @@
reverse([X1|Xs], [Y1|Ys], YsPreludeRev, Xss) :-
reverse(Xs, Ys, [Y1|YsPreludeRev], Xss).

maplist(_, []).
maplist(Cont1, [E1|E1s]) :-
call(Cont1, E1),
maplist(Cont1, E1s).

maplist(_, [], []).
maplist(Cont2, [E1|E1s], [E2|E2s]) :-
call(Cont2, E1, E2),
maplist(Cont2, E1s, E2s).

maplist(_, [], [], []).
maplist(Cont3, [E1|E1s], [E2|E2s], [E3|E3s]) :-
call(Cont3, E1, E2, E3),
maplist(Cont3, E1s, E2s, E3s).

maplist(_, [], [], [], []).
maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s]) :-
maplist_([], _).
maplist_([E1|E1s], Cont) :-
call(Cont, E1),
maplist_(E1s, Cont).

maplist(Cont, Es) :- maplist_(Es, Cont).

maplist_([], _, []).
maplist_([E1|E1s], Cont, [E2|E2s]) :-
call(Cont, E1, E2),
maplist_(E1s, Cont, E2s).

maplist(Cont, Es1, Es2) :- maplist_(Es1, Cont, Es2).

maplist_([], Cont, [], []).
maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s]) :-
call(Cont, E1, E2, E3),
maplist_(E1s, Cont, E2s, E3s).

maplist(Cont, Es1, Es2, Es3) :- maplist_(Es1, Cont, Es2, Es3).

maplist_([], _, [], [], []).
maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s], [E4|E4s]) :-
call(Cont, E1, E2, E3, E4),
maplist(Cont, E1s, E2s, E3s, E4s).
maplist_(E1s, Cont, E2s, E3s, E4s).

maplist(_, [], [], [], [], []).
maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s]) :-
maplist(Cont, Es1, Es2, Es3, Es4) :- maplist_(Es1, Cont, Es2, Es3, Es4).

maplist_([], _, [], [], [], []).
maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s]) :-
call(Cont, E1, E2, E3, E4, E5),
maplist(Cont, E1s, E2s, E3s, E4s, E5s).
maplist_(E1s, Cont, E2s, E3s, E4s, E5s).

maplist(Cont, Es1, Es2, Es3, Es4, Es5) :- maplist_(Es1, Cont, Es2, Es3, Es4, Es5).

maplist(_, [], [], [], [], [], []).
maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s]) :-
maplist_([], _, [], [], [], [], []).
maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s]) :-
call(Cont, E1, E2, E3, E4, E5, E6),
maplist(Cont, E1s, E2s, E3s, E4s, E5s, E6s).
maplist_(E1s, Cont, E2s, E3s, E4s, E5s, E6s).

maplist(_, [], [], [], [], [], [], []).
maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s]) :-
call(Cont, E1, E2, E3, E4, E5, E6, E7),
maplist(Cont, E1s, E2s, E3s, E4s, E5s, E6s, E7s).
maplist(Cont, Es1, Es2, Es3, Es4, Es5, Es6) :- maplist_(Es1, Cont, Es2, Es3, Es4, Es6, Es6).

maplist(_, [], [], [], [], [], [], [], []).
maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s], [E8|E8s]) :-
maplist_([], _, [], [], [], [], [], []).
maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s]) :-
call(Cont, E1, E2, E3, E4, E5, E6, E7),
maplist(Cont, E1s, E2s, E3s, E4s, E5s, E6s, E7s, E8s).
maplist_(E1s, Cont, E2s, E3s, E4s, E5s, E6s, E7s).

maplist(Cont, Es1, Es2, Es3, Es4, Es5, Es6, Es7) :- maplist_(Es1, Cont, Es2, Es3, Es4, Es6, Es6, Es7).

maplist_([], _, [], [], [], [], [], [], []).
maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s], [E8|E8s]) :-
call(Cont, E1, E2, E3, E4, E5, E6, E7, E8),
maplist_(E1s, Cont, E2s, E3s, E4s, E5s, E6s, E7s, E8s).

maplist(Cont, Es1, Es2, Es3, Es4, Es5, Es6, Es7, Es8) :- maplist_(Es1, Cont, Es2, Es3, Es4, Es6, Es6, Es7, Es8).
23 changes: 19 additions & 4 deletions src/prolog/machine/system_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,17 @@ impl MachineState {

if let Addr::Lis(l1) = ls0 {
if let Addr::Lis(l2) = self.store(self.deref(Addr::HeapCell(l1 + 1))) {
let addr = self.heap[l1 + 1].as_addr(l1 + 1);
self.heap[l1 + 1] = HeapCellValue::Addr(Addr::HeapCell(l2 + 1));
self.trail(TrailRef::AttrVarLink(l1 + 1, addr));
let old_addr = self.heap[l1 + 1].as_addr(l1 + 1);

let tail = self.store(self.deref(Addr::HeapCell(l2 + 1)));
let tail = if tail.is_ref() {
Addr::HeapCell(l1 + 1)
} else {
tail
};

self.heap[l1 + 1] = HeapCellValue::Addr(tail);
self.trail(TrailRef::AttrVarLink(l1 + 1, old_addr));
}
}
}
Expand All @@ -988,7 +996,14 @@ impl MachineState {

match addr {
Addr::Lis(l) => {
self.heap[h + 1] = HeapCellValue::Addr(Addr::HeapCell(l + 1));
let tail = self.store(self.deref(Addr::HeapCell(l + 1)));
let tail = if tail.is_ref() {
Addr::HeapCell(h + 1)
} else {
tail
};

self.heap[h + 1] = HeapCellValue::Addr(tail);
self.trail(TrailRef::AttrVarLink(h + 1, Addr::Lis(l)));
}
_ => unreachable!(),
Expand Down

0 comments on commit 5893ff4

Please sign in to comment.