preliminary cont work
This commit is contained in:
@@ -353,7 +353,7 @@ impl MachineState {
|
||||
copy_ball_term.push(HeapCellValue::Addr(Addr::HeapCell(threshold + 3)));
|
||||
copy_ball_term.push(HeapCellValue::Addr(Addr::HeapCell(threshold + 2)));
|
||||
|
||||
copy_term(copy_ball_term, copy_target);
|
||||
copy_term(copy_ball_term, copy_target, AttrVarPolicy::DeepCopy);
|
||||
threshold + lh_offset + 2
|
||||
}
|
||||
|
||||
@@ -527,6 +527,16 @@ impl MachineState {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn fetch_attribute_goals(&mut self, mut attr_goals: Vec<Addr>) {
|
||||
attr_goals.sort_unstable_by(|a1, a2| self.compare_term_test(a1, a2));
|
||||
self.term_dedup(&mut attr_goals);
|
||||
|
||||
let attr_goals = Addr::HeapCell(self.heap.to_list(attr_goals.into_iter()));
|
||||
let target = self[temp_v!(1)].clone();
|
||||
|
||||
self.unify(attr_goals, target);
|
||||
}
|
||||
|
||||
fn create_instruction_functors(&mut self, code: &Code, first_idx: usize) -> Vec<Addr> {
|
||||
let mut queue = VecDeque::new();
|
||||
let mut functors = vec![];
|
||||
@@ -594,6 +604,25 @@ impl MachineState {
|
||||
self.p = CodePtr::DynamicTransaction(trans_type, p);
|
||||
return Ok(());
|
||||
}
|
||||
&SystemClauseType::BindFromRegister => {
|
||||
let reg = self.store(self.deref(self[temp_v!(2)].clone()));
|
||||
let n = match reg {
|
||||
Addr::Con(Constant::Integer(n)) => n.to_usize(),
|
||||
_ => unreachable!()
|
||||
};
|
||||
|
||||
if let Some(n) = n {
|
||||
if n <= MAX_ARITY {
|
||||
let target = self[temp_v!(n)].clone();
|
||||
let addr = self[temp_v!(1)].clone();
|
||||
|
||||
self.unify(addr, target);
|
||||
return return_from_clause!(self.last_call, self);
|
||||
}
|
||||
}
|
||||
|
||||
self.fail = true;
|
||||
}
|
||||
&SystemClauseType::AssertDynamicPredicateToFront => {
|
||||
let p = self.cp;
|
||||
let trans_type = DynamicTransactionType::Assert(DynamicAssertPlace::Front);
|
||||
@@ -874,6 +903,9 @@ impl MachineState {
|
||||
_ => self.fail = true,
|
||||
};
|
||||
}
|
||||
&SystemClauseType::CopyTermWithoutAttrVars => {
|
||||
self.copy_term(AttrVarPolicy::StripAttributes);
|
||||
}
|
||||
&SystemClauseType::FetchGlobalVar => {
|
||||
let key = self[temp_v!(1)].clone();
|
||||
|
||||
@@ -1109,7 +1141,7 @@ impl MachineState {
|
||||
for i in (arity + 1 .. arity + narity + 1).rev() {
|
||||
self.registers[i] = self.registers[i - arity].clone();
|
||||
}
|
||||
|
||||
|
||||
for i in 1 .. arity + 1 {
|
||||
self.registers[i] = self.heap[a + i].as_addr(a + i);
|
||||
}
|
||||
@@ -1122,7 +1154,7 @@ impl MachineState {
|
||||
);
|
||||
}
|
||||
}
|
||||
Addr::Con(Constant::Atom(name, _)) => {
|
||||
Addr::Con(Constant::Atom(name, _)) => {
|
||||
return self.module_lookup(indices, (name, narity), module_name, true)
|
||||
}
|
||||
addr => {
|
||||
@@ -1370,16 +1402,16 @@ impl MachineState {
|
||||
&SystemClauseType::TruncateIfNoLiftedHeapGrowth => {
|
||||
self.truncate_if_no_lifted_heap_diff(|_| Addr::Con(Constant::EmptyList))
|
||||
}
|
||||
&SystemClauseType::ClearAttributeGoals => {
|
||||
self.attr_var_init.attribute_goals.clear();
|
||||
}
|
||||
&SystemClauseType::CloneAttributeGoals => {
|
||||
let attr_goals = self.attr_var_init.attribute_goals.clone();
|
||||
self.fetch_attribute_goals(attr_goals);
|
||||
}
|
||||
&SystemClauseType::FetchAttributeGoals => {
|
||||
let mut attr_goals = mem::replace(&mut self.attr_var_init.attribute_goals, vec![]);
|
||||
|
||||
attr_goals.sort_unstable_by(|a1, a2| self.compare_term_test(a1, a2));
|
||||
self.term_dedup(&mut attr_goals);
|
||||
|
||||
let attr_goals = Addr::HeapCell(self.heap.to_list(attr_goals.into_iter()));
|
||||
let target = self[temp_v!(1)].clone();
|
||||
|
||||
self.unify(attr_goals, target);
|
||||
let attr_goals = mem::replace(&mut self.attr_var_init.attribute_goals, vec![]);
|
||||
self.fetch_attribute_goals(attr_goals);
|
||||
}
|
||||
&SystemClauseType::GetAttributedVariableList => {
|
||||
let attr_var = self.store(self.deref(self[temp_v!(1)].clone()));
|
||||
@@ -1643,11 +1675,32 @@ impl MachineState {
|
||||
}
|
||||
};
|
||||
}
|
||||
&SystemClauseType::RedoAttrVarBindings => {
|
||||
let bindings = mem::replace(&mut self.attr_var_init.bindings, vec![]);
|
||||
&SystemClauseType::ClearAttrVarBindings => {
|
||||
self.attr_var_init.bindings.clear();
|
||||
}
|
||||
&SystemClauseType::RedoAttrVarBinding => {
|
||||
let var = self.store(self.deref(self[temp_v!(1)].clone()));
|
||||
let value = self.store(self.deref(self[temp_v!(2)].clone()));
|
||||
|
||||
for (h, addr) in bindings {
|
||||
self.heap[h] = HeapCellValue::Addr(addr);
|
||||
match var {
|
||||
Addr::AttrVar(h) => {
|
||||
if let Addr::AttrVar(h1) = value {
|
||||
self.heap[h] = HeapCellValue::Addr(Addr::AttrVar(h1));
|
||||
|
||||
// append h's attributes list to h1's.
|
||||
let mut l = h1 + 1;
|
||||
|
||||
while let Addr::Lis(l1) = self.store(self.deref(self.heap[l].as_addr(l))) {
|
||||
l = l1 + 1;
|
||||
}
|
||||
|
||||
self.heap[l] = HeapCellValue::Addr(Addr::HeapCell(h + 1));
|
||||
self.trail(TrailRef::Ref(Ref::HeapCell(l)));
|
||||
} else {
|
||||
self.heap[h] = HeapCellValue::Addr(value);
|
||||
}
|
||||
}
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
&SystemClauseType::ResetGlobalVarAtKey => {
|
||||
@@ -1676,6 +1729,7 @@ impl MachineState {
|
||||
copy_term(
|
||||
CopyBallTerm::new(&mut self.stack, &mut self.heap, &mut ball.stub),
|
||||
value,
|
||||
AttrVarPolicy::DeepCopy,
|
||||
);
|
||||
|
||||
let offset = self[temp_v!(3)].clone();
|
||||
@@ -1930,11 +1984,13 @@ impl MachineState {
|
||||
&SystemClauseType::ReadTerm => {
|
||||
readline::set_prompt(false);
|
||||
self.read_term(current_input_stream, indices)?;
|
||||
},
|
||||
}
|
||||
&SystemClauseType::ResetBlock => {
|
||||
let addr = self.deref(self[temp_v!(1)].clone());
|
||||
self.reset_block(addr);
|
||||
}
|
||||
&SystemClauseType::ResetContinuationMarker => {
|
||||
}
|
||||
&SystemClauseType::SetBall =>
|
||||
self.set_ball(),
|
||||
&SystemClauseType::SetSeed => {
|
||||
@@ -1981,6 +2037,7 @@ impl MachineState {
|
||||
copy_term(
|
||||
CopyBallTerm::new(&mut self.stack, &mut self.heap, &mut ball.stub),
|
||||
value,
|
||||
AttrVarPolicy::DeepCopy,
|
||||
);
|
||||
|
||||
indices.global_variables.insert(key, (ball, None));
|
||||
@@ -2001,6 +2058,7 @@ impl MachineState {
|
||||
copy_term(
|
||||
CopyBallTerm::new(&mut self.stack, &mut self.heap, &mut ball.stub),
|
||||
value.clone(),
|
||||
AttrVarPolicy::DeepCopy,
|
||||
);
|
||||
|
||||
let stub = ball.copy_and_align(h);
|
||||
|
||||
Reference in New Issue
Block a user