reuse defunct AND stack frames.

This commit is contained in:
Mark Thom
2017-11-11 16:01:29 -07:00
parent d6086390e0
commit e503e312a1
2 changed files with 39 additions and 8 deletions

View File

@@ -49,8 +49,16 @@ impl AndStack {
self.0.clear()
}
pub fn pop(&mut self) {
self.0.pop();
pub fn resize(&mut self, fr: usize, n: usize) {
let len = self[fr].perms.len();
if len < n {
self[fr].perms.reserve(n - len);
for i in len .. n {
self[fr].perms.push(Addr::StackCell(fr, i));
}
}
}
}

View File

@@ -1510,10 +1510,33 @@ impl MachineState {
{
match instr {
&ControlInstruction::Allocate(num_cells) => {
if let Some(ref or_fr) = self.or_stack.top() {
let and_gi = if self.and_stack.len() > self.e {
self.and_stack[self.e].global_index
} else {
0
};
if and_gi <= or_fr.global_index {
self.e = or_fr.e;
}
}
if self.e + 1 < self.and_stack.len() {
let index = self.e + 1;
self.and_stack[index].e = self.e;
self.and_stack[index].cp = self.cp;
self.and_stack.resize(index, num_cells);
self.e = index;
} else {
let num_frames = self.num_frames();
self.and_stack.push(num_frames + 1, self.e, self.cp, num_cells);
self.e = self.and_stack.len() - 1;
};
self.p += 1;
},