let mut target = Vec::new();
self.marker.reset_arg(arity);
- self.marker.mark_var(name, Level::Shallow, vr, term_loc, &mut target);
+ self.marker.mark_var(name, Level::Shallow, vr, term_loc, &mut target);
code.push(Line::Query(target));
vr.get().norm()
}
fn add_conditional_call_inlined(_: &InlinedQueryTerm, code: &mut Code)
{
code.push(proceed!());
-
+
/*
match term {
&InlinedQueryTerm::IsAtomic(_) | &InlinedQueryTerm::IsVar(_) =>
- code.push(proceed!())
+ code.push(proceed!())
};
*/
}
-
+
fn add_conditional_call(code: &mut Code, qt: &QueryTerm, pvs: usize)
{
match qt {
if let Some(&mut Line::Control(ref mut ctrl)) = code.last_mut() {
let mut instr = ControlInstruction::Proceed;
swap(ctrl, &mut instr);
-
+
match instr {
ControlInstruction::Call(name, arity, _) =>
*ctrl = ControlInstruction::Execute(name, arity),
dealloc_index
}
-
+
fn compile_inlined(&mut self, term: &'a InlinedQueryTerm, term_loc: GenContext, code: &mut Code)
-> Result<(), ParserError>
{
code.append(&mut lcode);
code.append(&mut rcode);
-
+
code.push(compare_number_instr!(cmp,
at_1.unwrap_or(interm!(1)),
- at_2.unwrap_or(interm!(2))));
+ at_2.unwrap_or(interm!(2))));
},
&InlinedQueryTerm::IsAtomic(ref inner_term) =>
match inner_term[0].as_ref() {
let r = self.mark_non_callable(name, 1, term_loc, vr, code);
code.push(is_atomic!(r));
}
- },
+ },
&InlinedQueryTerm::IsVar(ref inner_term) =>
match inner_term[0].as_ref() {
&Term::Constant(_, _) | &Term::Clause(_, _, _) | &Term::Cons(_, _, _) => {
Ok(())
}
-
+
fn call_arith_eval(&self, term: &'a Term, target_int: usize) -> Result<ArithCont, ArithmeticError>
{
let mut evaluator = ArithmeticEvaluator::new(self.marker.bindings(), target_int);
evaluator.eval(term)
}
-
+
fn compile_seq(&mut self,
iter: ChunkedIterator<'a>,
conjunct_info: &ConjunctInfo<'a>,
});
},
&QueryTerm::Inlined(ref term) =>
- self.compile_inlined(term, term_loc, code)?,
+ self.compile_inlined(term, term_loc, code)?,
&QueryTerm::Is(ref terms) => {
let (mut acode, at) = try!(self.call_arith_eval(terms[1].as_ref(), 1));
code.append(&mut acode);
code.push(fail!());
}
}
- },
+ },
_ if chunk_num == 0 => {
self.marker.reset_arg(term.arity());
Ok(())
}
-
+
fn compile_seq_prelude(&mut self, conjunct_info: &ConjunctInfo, body: &mut Code)
{
if conjunct_info.allocates() {
}
struct MachineState {
- h: usize,
s: usize,
p: CodePtr,
b: usize,
tr: usize,
hb: usize,
block: usize, // an offset into the OR stack.
- ball: (usize, Heap), // heap boundary, and a term copy
+ ball: (usize, Vec<HeapCellValue>), // heap boundary, and a term copy
interms: Vec<Number> // intermediate numbers.
}
// the ordinary, heap term copier, used by duplicate_term.
impl<'a> CopierTarget for DuplicateTerm<'a> {
fn source(&self) -> usize {
- self.state.h
+ self.state.heap.h
}
fn threshold(&self) -> usize {
- self.state.h
+ self.state.heap.h
}
fn push(&mut self, hcv: HeapCellValue) {
self.state.heap.push(hcv);
- self.state.h += 1;
+ self.state.heap.h += 1;
}
fn store(&self, a: Addr) -> Addr {
fn fail<'a>(&mut self) -> EvalSession<'a>
{
if self.ms.ball.1.len() > 0 {
- let h = self.ms.h;
+ let h = self.ms.heap.h;
self.ms.copy_and_align_ball_to_heap();
EvalSession::QueryFailureWithException(self.print_term(&Addr::HeapCell(h)))
impl MachineState {
fn new() -> MachineState {
- MachineState { h: 0,
- s: 0,
+ MachineState { s: 0,
p: CodePtr::default(),
b: 0,
b0: 0,
num_of_args: 0,
cp: CodePtr::default(),
fail: false,
- heap: Vec::with_capacity(256),
+ heap: Heap::with_capacity(256),
mode: MachineMode::Write,
and_stack: AndStack::new(),
or_stack: OrStack::new(),
fn num_frames(&self) -> usize {
self.and_stack.len() + self.or_stack.len()
}
-
+
fn store(&self, a: Addr) -> Addr {
match a {
Addr::HeapCell(r) => self.heap[r].as_addr(r),
match self.store(addr.clone()) {
Addr::HeapCell(hc) => {
- let h = self.h;
+ let h = self.heap.h;
self.heap.push(HeapCellValue::Lis(h+1));
self.bind(Ref::HeapCell(hc), Addr::HeapCell(h));
- self.h += 1;
self.mode = MachineMode::Write;
},
Addr::StackCell(fr, sc) => {
- let h = self.h;
+ let h = self.heap.h;
self.heap.push(HeapCellValue::Lis(h+1));
self.bind(Ref::StackCell(fr, sc), Addr::HeapCell(h));
- self.h += 1;
self.mode = MachineMode::Write;
},
Addr::Lis(a) => {
}
},
Addr::HeapCell(_) | Addr::StackCell(_, _) => {
- self.heap.push(HeapCellValue::Str(self.h + 1));
+ let h = self.heap.h;
+
+ self.heap.push(HeapCellValue::Str(h + 1));
self.heap.push(HeapCellValue::NamedStr(arity, name.clone()));
- let h = self.h;
-
self.bind(addr.as_ref().unwrap(), Addr::HeapCell(h));
- self.h += 2;
self.mode = MachineMode::Write;
},
_ => self.fail = true
},
MachineMode::Write => {
self.heap.push(HeapCellValue::Con(c.clone()));
- self.h += 1;
}
};
MachineMode::Read =>
self[reg] = self.heap[self.s].as_addr(self.s),
MachineMode::Write => {
- let h = self.h;
+ let h = self.heap.h;
self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
- self[reg] = Addr::HeapCell(self.h);
- self.h += 1;
+ self[reg] = Addr::HeapCell(h);
}
};
},
MachineMode::Write => {
let addr = self.deref(self[reg].clone());
- let h = self.h;
+ let h = self.heap.h;
if let Addr::HeapCell(hc) = addr {
if hc < h {
let val = self.heap[hc].clone();
+
self.heap.push(val);
-
- self.h += 1;
self.s += 1;
return;
self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
self.bind(Ref::HeapCell(h), addr);
-
- self.h += 1;
}
};
MachineMode::Write => {
let heap_val = self.store(self[reg].clone());
self.heap.push(HeapCellValue::from(heap_val));
- self.h += 1;
}
};
MachineMode::Read =>
self.s += n,
MachineMode::Write => {
- let h = self.h;
+ let h = self.heap.h;
for i in h .. h + n {
self.heap.push(HeapCellValue::Ref(Ref::HeapCell(i)));
}
-
- self.h += n;
}
};
}
&QueryInstruction::PutConstant(_, ref constant, reg) =>
self[reg] = Addr::Con(constant.clone()),
&QueryInstruction::PutList(_, reg) =>
- self[reg] = Addr::Lis(self.h),
+ self[reg] = Addr::Lis(self.heap.h),
&QueryInstruction::PutStructure(_, ref name, arity, reg) => {
+ let h = self.heap.h;
+
self.heap.push(HeapCellValue::NamedStr(arity, name.clone()));
- self[reg] = Addr::Str(self.h);
- self.h += 1;
+ self[reg] = Addr::Str(h);
},
&QueryInstruction::PutUnsafeValue(n, arg) => {
let e = self.e;
if addr.is_protected(e) {
self.registers[arg] = self.store(addr);
} else {
- let h = self.h;
+ let h = self.heap.h;
self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
self.bind(Ref::HeapCell(h), addr);
self.registers[arg] = self.heap[h].as_addr(h);
- self.h += 1;
}
},
&QueryInstruction::PutValue(norm, arg) =>
self.registers[arg] = self[norm].clone();
},
RegType::Temp(_) => {
- let h = self.h;
+ let h = self.heap.h;
self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
self[norm] = Addr::HeapCell(h);
self.registers[arg] = Addr::HeapCell(h);
-
- self.h += 1;
}
};
},
&QueryInstruction::SetConstant(ref constant) => {
self.heap.push(HeapCellValue::Con(constant.clone()));
- self.h += 1;
},
&QueryInstruction::SetLocalValue(reg) => {
let addr = self.deref(self[reg].clone());
- let h = self.h;
+ let h = self.heap.h;
if let Addr::HeapCell(hc) = addr {
if hc < h {
self.heap.push(HeapCellValue::from(addr));
- self.h += 1;
return;
}
}
self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
self.bind(Ref::HeapCell(h), addr);
-
- self.h += 1;
},
&QueryInstruction::SetVariable(reg) => {
- let h = self.h;
+ let h = self.heap.h;
self.heap.push(HeapCellValue::Ref(Ref::HeapCell(h)));
self[reg] = Addr::HeapCell(h);
-
- self.h += 1;
},
&QueryInstruction::SetValue(reg) => {
let heap_val = self[reg].clone();
self.heap.push(HeapCellValue::from(heap_val));
-
- self.h += 1;
},
&QueryInstruction::SetVoid(n) => {
- let h = self.h;
+ let h = self.heap.h;
for i in h .. h + n {
self.heap.push(HeapCellValue::Ref(Ref::HeapCell(i)));
}
-
- self.h += n;
}
}
}
self.p = CodePtr::DirEntry(59);
}
- fn throw_exception(&mut self, mut hcv: Vec<HeapCellValue>) {
- let h = self.h;
+ fn throw_exception(&mut self, hcv: Vec<HeapCellValue>) {
+ let h = self.heap.h;
self.registers[1] = Addr::HeapCell(h);
- self.h += hcv.len();
-
- self.heap.append(&mut hcv);
+
+ self.heap.append(hcv);
self.goto_throw();
}
}
fn copy_and_align_ball_to_heap(&mut self) {
- let diff = self.ball.0 - self.h;
-
+ let diff = self.ball.0 - self.heap.h;
+
for heap_value in self.ball.1.iter().cloned() {
self.heap.push(match heap_value {
HeapCellValue::Con(c) => HeapCellValue::Con(c),
_ => heap_value
});
}
-
- self.h += self.ball.1.len();
}
fn execute_built_in_instr(&mut self, code_dir: &CodeDir, instr: &BuiltInInstruction)
self.p += 1;
},
&BuiltInInstruction::DuplicateTerm => {
- let old_h = self.h;
+ let old_h = self.heap.h;
let a1 = self[temp_v!(1)].clone();
let a2 = self[temp_v!(2)].clone();
},
&BuiltInInstruction::GetBall => {
let addr = self.store(self.deref(self[temp_v!(1)].clone()));
- let h = self.h;
+ let h = self.heap.h;
if self.ball.1.len() > 0 {
self.copy_and_align_ball_to_heap();
},
&BuiltInInstruction::SetBall => {
let addr = self[temp_v!(1)].clone();
- self.ball.0 = self.h;
+ self.ball.0 = self.heap.h;
{
let mut duplicator = DuplicateBallTerm::new(self);
self.b,
self.p + 1,
self.tr,
- self.h,
+ self.heap.h,
self.b0,
self.num_of_args);
self.or_stack[b][i] = self.registers[i].clone();
}
- self.hb = self.h;
+ self.hb = self.heap.h;
self.p += l;
},
&IndexedChoiceInstruction::Retry(l) => {
self.trail.truncate(self.tr);
self.heap.truncate(self.or_stack[b].h);
- self.h = self.or_stack[b].h;
- self.hb = self.h;
+ self.hb = self.heap.h;
self.p += l;
},
self.tr = self.or_stack[b].tr;
self.trail.truncate(self.tr);
- self.h = self.or_stack[b].h;
- self.heap.truncate(self.h);
-
+ self.heap.truncate(self.or_stack[b].h);
self.b = self.or_stack[b].b;
self.or_stack.pop();
- self.hb = self.h;
+ self.hb = self.heap.h;
self.p += l;
},
};
self.b,
self.p + offset,
self.tr,
- self.h,
+ self.heap.h,
self.b0,
self.num_of_args);
self.or_stack[b][i] = self.registers[i].clone();
}
- self.hb = self.h;
+ self.hb = self.heap.h;
self.p += 1;
},
&ChoiceInstruction::RetryMeElse(offset) => {
self.trail.truncate(self.tr);
self.heap.truncate(self.or_stack[b].h);
- self.h = self.or_stack[b].h;
- self.hb = self.h;
+ self.hb = self.heap.h;
self.p += 1;
},
self.tr = self.or_stack[b].tr;
self.trail.truncate(self.tr);
- self.h = self.or_stack[b].h;
- self.heap.truncate(self.h);
+ self.heap.truncate(self.or_stack[b].h);
self.b = self.or_stack[b].b;
self.or_stack.pop();
- self.hb = self.h;
+ self.hb = self.heap.h;
self.p += 1;
}
}
&CutInstruction::GetLevel => {
let b0 = self.b0;
let e = self.e;
-
+
self.and_stack[e].b0 = b0;
self.p += 1;
},
}
fn reset(&mut self) {
- self.h = 0;
self.hb = 0;
self.e = 0;
self.b = 0;