introduce a better binding scheme for attributed variables
This commit is contained in:
@@ -208,24 +208,24 @@ 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);
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
&SystemClauseType::DeleteHeadAttribute => {
|
||||
let addr = self.store(self.deref(self[temp_v!(1)].clone()));
|
||||
|
||||
|
||||
match addr {
|
||||
Addr::AttrVar(_, attr_var) => {
|
||||
let addr = self.heap[attr_var].as_addr(attr_var).clone();
|
||||
Addr::AttrVar(h) => {
|
||||
let addr = self.heap[h+1].as_addr(h+1).clone();
|
||||
let addr = self.store(self.deref(addr));
|
||||
|
||||
|
||||
match addr {
|
||||
Addr::Lis(l) => {
|
||||
self.heap[attr_var] = HeapCellValue::Addr(Addr::HeapCell(l+1));
|
||||
self.trail(TrailRef::AttrVarLink(attr_var, Addr::Lis(l)));
|
||||
self.heap[h+1] = HeapCellValue::Addr(Addr::HeapCell(l+1));
|
||||
self.trail(TrailRef::AttrVarLink(h+1, Addr::Lis(l)));
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
@@ -270,27 +270,16 @@ impl MachineState {
|
||||
&SystemClauseType::GetAttributedVariableList => {
|
||||
let attr_var = self.store(self.deref(self[temp_v!(1)].clone()));
|
||||
let mut attr_var_list = match attr_var {
|
||||
Addr::AttrVar(_, attr_var_list) => attr_var_list,
|
||||
Addr::AttrVar(h) => h + 1,
|
||||
attr_var @ Addr::HeapCell(_) | attr_var @ Addr::StackCell(..) => {
|
||||
// create an AttrVar in the heap.
|
||||
let h = self.heap.h;
|
||||
|
||||
self.heap.push(HeapCellValue::Addr(Addr::AttrVar(h, h + 2)));
|
||||
|
||||
self.heap.push(HeapCellValue::Addr(Addr::AttrVar(h)));
|
||||
self.heap.push(HeapCellValue::Addr(Addr::HeapCell(h + 1)));
|
||||
self.heap.push(HeapCellValue::Addr(Addr::HeapCell(h + 2)));
|
||||
|
||||
match attr_var.as_var().unwrap() {
|
||||
Ref::HeapCell(r) => {
|
||||
self.heap[r] = HeapCellValue::Addr(Addr::HeapCell(h));
|
||||
self.trail(TrailRef::HeapCell(r));
|
||||
},
|
||||
Ref::StackCell(fr, sc) => {
|
||||
self.and_stack[fr][sc] = Addr::HeapCell(h);
|
||||
self.trail(TrailRef::StackCell(fr, sc));
|
||||
}
|
||||
}
|
||||
|
||||
h + 2
|
||||
self.bind(Ref::AttrVar(h), attr_var);
|
||||
h + 1
|
||||
},
|
||||
_ => {
|
||||
self.fail = true;
|
||||
@@ -298,8 +287,8 @@ impl MachineState {
|
||||
}
|
||||
};
|
||||
|
||||
let list_var = self[temp_v!(2)].clone();
|
||||
self.unify(Addr::HeapCell(attr_var_list), list_var);
|
||||
let list_addr = self[temp_v!(2)].clone();
|
||||
self.unify(Addr::HeapCell(attr_var_list), list_addr);
|
||||
},
|
||||
&SystemClauseType::GetDoubleQuotes => {
|
||||
let a1 = self[temp_v!(1)].clone();
|
||||
|
||||
Reference in New Issue
Block a user