add preliminary support for verify_attributes/3
This commit is contained in:
@@ -143,7 +143,7 @@ pub fn compile_term(wam: &mut Machine, packet: TopLevelPacket) -> EvalSession
|
|||||||
Err(e) => EvalSession::from(e)
|
Err(e) => EvalSession::from(e)
|
||||||
},
|
},
|
||||||
TopLevelPacket::Decl(TopLevel::Declaration(decl), _) => {
|
TopLevelPacket::Decl(TopLevel::Declaration(decl), _) => {
|
||||||
let mut compiler = ListingCompiler::new(&wam.code_repo, wam.code_size());
|
let mut compiler = ListingCompiler::new(&wam.code_repo);
|
||||||
let indices = try_eval_session!(compile_decl(wam, &mut compiler, decl));
|
let indices = try_eval_session!(compile_decl(wam, &mut compiler, decl));
|
||||||
|
|
||||||
try_eval_session!(compiler.add_code(wam, vec![], indices));
|
try_eval_session!(compiler.add_code(wam, vec![], indices));
|
||||||
@@ -162,7 +162,6 @@ struct GatherResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct ListingCompiler {
|
pub struct ListingCompiler {
|
||||||
code_size_offset: usize,
|
|
||||||
non_counted_bt_preds: HashSet<PredicateKey>,
|
non_counted_bt_preds: HashSet<PredicateKey>,
|
||||||
module: Option<Module>,
|
module: Option<Module>,
|
||||||
user_term_dir: TermDir,
|
user_term_dir: TermDir,
|
||||||
@@ -172,9 +171,8 @@ pub struct ListingCompiler {
|
|||||||
|
|
||||||
impl ListingCompiler {
|
impl ListingCompiler {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(code_repo: &CodeRepo, code_size_offset: usize) -> Self {
|
pub fn new(code_repo: &CodeRepo) -> Self {
|
||||||
ListingCompiler {
|
ListingCompiler {
|
||||||
code_size_offset,
|
|
||||||
non_counted_bt_preds: HashSet::new(),
|
non_counted_bt_preds: HashSet::new(),
|
||||||
module: None,
|
module: None,
|
||||||
user_term_dir: TermDir::new(),
|
user_term_dir: TermDir::new(),
|
||||||
@@ -252,7 +250,7 @@ impl ListingCompiler {
|
|||||||
|
|
||||||
let non_counted_bt = self.non_counted_bt_preds.contains(&(name.clone(), arity));
|
let non_counted_bt = self.non_counted_bt_preds.contains(&(name.clone(), arity));
|
||||||
|
|
||||||
let p = code.len() + self.code_size_offset;
|
let p = code.len() + wam.code_size();
|
||||||
let mut decl_code = compile_relation(&TopLevel::Predicate(decl), non_counted_bt,
|
let mut decl_code = compile_relation(&TopLevel::Predicate(decl), non_counted_bt,
|
||||||
wam.machine_flags())?;
|
wam.machine_flags())?;
|
||||||
|
|
||||||
@@ -468,7 +466,7 @@ pub fn compile_special_form<R: Read>(wam: &mut Machine, src: R) -> Result<Code,
|
|||||||
let mut indices = default_index_store!(wam.indices.atom_tbl.clone());
|
let mut indices = default_index_store!(wam.indices.atom_tbl.clone());
|
||||||
setup_indices(wam, &mut indices)?;
|
setup_indices(wam, &mut indices)?;
|
||||||
|
|
||||||
let mut compiler = ListingCompiler::new(&wam.code_repo, 0);
|
let mut compiler = ListingCompiler::new(&wam.code_repo);
|
||||||
let results = compiler.gather_items(wam, src, &mut indices)?;
|
let results = compiler.gather_items(wam, src, &mut indices)?;
|
||||||
|
|
||||||
compiler.generate_code(results.worker_results, wam, &mut indices.code_dir)
|
compiler.generate_code(results.worker_results, wam, &mut indices.code_dir)
|
||||||
@@ -477,7 +475,7 @@ pub fn compile_special_form<R: Read>(wam: &mut Machine, src: R) -> Result<Code,
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn compile_listing<R: Read>(wam: &mut Machine, src: R, indices: IndexStore) -> EvalSession
|
pub fn compile_listing<R: Read>(wam: &mut Machine, src: R, indices: IndexStore) -> EvalSession
|
||||||
{
|
{
|
||||||
let mut compiler = ListingCompiler::new(&wam.code_repo, wam.code_size());
|
let mut compiler = ListingCompiler::new(&wam.code_repo);
|
||||||
|
|
||||||
match compile_work(&mut compiler, wam, src, indices) {
|
match compile_work(&mut compiler, wam, src, indices) {
|
||||||
EvalSession::Error(e) => EvalSession::Error(compiler.drop_expansions(wam, e)),
|
EvalSession::Error(e) => EvalSession::Error(compiler.drop_expansions(wam, e)),
|
||||||
|
|||||||
@@ -216,7 +216,6 @@ pub struct CodeRepo {
|
|||||||
pub(super) term_expanders: Code,
|
pub(super) term_expanders: Code,
|
||||||
pub(super) code: Code,
|
pub(super) code: Code,
|
||||||
pub(super) in_situ_code: Code,
|
pub(super) in_situ_code: Code,
|
||||||
pub(super) verify_attrs_code: Code,
|
|
||||||
pub(super) term_dir: TermDir
|
pub(super) term_dir: TermDir
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -924,7 +923,8 @@ impl From<(usize, ClauseName)> for CodeIndex {
|
|||||||
pub enum CodePtr {
|
pub enum CodePtr {
|
||||||
BuiltInClause(BuiltInClauseType, LocalCodePtr), // local is the successor call.
|
BuiltInClause(BuiltInClauseType, LocalCodePtr), // local is the successor call.
|
||||||
CallN(usize, LocalCodePtr), // arity, local.
|
CallN(usize, LocalCodePtr), // arity, local.
|
||||||
Local(LocalCodePtr)
|
Local(LocalCodePtr),
|
||||||
|
VerifyAttrInterrupt(usize) // location of the verify attribute interrupt code in the CodeDir.
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CodePtr {
|
impl CodePtr {
|
||||||
@@ -932,7 +932,8 @@ impl CodePtr {
|
|||||||
match self {
|
match self {
|
||||||
&CodePtr::BuiltInClause(_, ref local)
|
&CodePtr::BuiltInClause(_, ref local)
|
||||||
| &CodePtr::CallN(_, ref local)
|
| &CodePtr::CallN(_, ref local)
|
||||||
| &CodePtr::Local(ref local) => local.clone()
|
| &CodePtr::Local(ref local) => local.clone(),
|
||||||
|
&CodePtr::VerifyAttrInterrupt(p) => LocalCodePtr::DirEntry(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -946,7 +947,7 @@ pub enum LocalCodePtr {
|
|||||||
UserTermExpansion(usize)
|
UserTermExpansion(usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LocalCodePtr {
|
impl LocalCodePtr {
|
||||||
pub fn assign_if_local(&mut self, cp: CodePtr) {
|
pub fn assign_if_local(&mut self, cp: CodePtr) {
|
||||||
match cp {
|
match cp {
|
||||||
CodePtr::Local(local) => *self = local,
|
CodePtr::Local(local) => *self = local,
|
||||||
@@ -1023,6 +1024,7 @@ impl Add<usize> for CodePtr {
|
|||||||
|
|
||||||
fn add(self, rhs: usize) -> Self::Output {
|
fn add(self, rhs: usize) -> Self::Output {
|
||||||
match self {
|
match self {
|
||||||
|
p @ CodePtr::VerifyAttrInterrupt(_) => p,
|
||||||
CodePtr::Local(local) => CodePtr::Local(local + rhs),
|
CodePtr::Local(local) => CodePtr::Local(local + rhs),
|
||||||
CodePtr::CallN(_, local) | CodePtr::BuiltInClause(_, local) => CodePtr::Local(local + rhs),
|
CodePtr::CallN(_, local) | CodePtr::BuiltInClause(_, local) => CodePtr::Local(local + rhs),
|
||||||
}
|
}
|
||||||
@@ -1032,6 +1034,7 @@ impl Add<usize> for CodePtr {
|
|||||||
impl AddAssign<usize> for CodePtr {
|
impl AddAssign<usize> for CodePtr {
|
||||||
fn add_assign(&mut self, rhs: usize) {
|
fn add_assign(&mut self, rhs: usize) {
|
||||||
match self {
|
match self {
|
||||||
|
&mut CodePtr::VerifyAttrInterrupt(_) => {},
|
||||||
&mut CodePtr::Local(ref mut local) => *local += rhs,
|
&mut CodePtr::Local(ref mut local) => *local += rhs,
|
||||||
_ => *self = CodePtr::Local(self.local() + rhs)
|
_ => *self = CodePtr::Local(self.local() + rhs)
|
||||||
}
|
}
|
||||||
@@ -1073,6 +1076,20 @@ impl Heap {
|
|||||||
self.heap.clear();
|
self.heap.clear();
|
||||||
self.h = 0;
|
self.h = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_list<Iter: Iterator<Item=Addr>>(&mut self, values: Iter) -> usize {
|
||||||
|
let head_addr = self.h;
|
||||||
|
|
||||||
|
for value in values {
|
||||||
|
let h = self.h;
|
||||||
|
|
||||||
|
self.push(HeapCellValue::Addr(Addr::Lis(h+1)));
|
||||||
|
self.push(HeapCellValue::Addr(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
self.push(HeapCellValue::Addr(Addr::Con(Constant::EmptyList)));
|
||||||
|
head_addr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index<usize> for Heap {
|
impl Index<usize> for Heap {
|
||||||
|
|||||||
@@ -1,24 +1,98 @@
|
|||||||
|
use prolog::machine::*;
|
||||||
|
|
||||||
pub static VERIFY_ATTRS: &str = "
|
pub static VERIFY_ATTRS: &str = "
|
||||||
iterate([Var-Value|Bindings]) :-
|
iterate([Var|VarBindings], [Value|ValueBindings]) :-
|
||||||
'$get_attr_list'(Var, Ls),
|
'$get_attr_list'(Var, Ls),
|
||||||
call_verify_attributes(Ls, Var, Value),
|
call_verify_attributes(Ls, Var, Value),
|
||||||
iterate(Bindings),
|
iterate(VarBindings, ValueBindings),
|
||||||
'$restore_p_from_sfcp'.
|
'$restore_p_from_sfcp'.
|
||||||
iterate([]).
|
iterate([], []).
|
||||||
|
|
||||||
call_verify_attributes(Attrs, _, _) :-
|
call_verify_attributes(Attrs, _, _) :-
|
||||||
var(Attrs), !.
|
var(Attrs), !.
|
||||||
call_verify_attributes([Attr|Attrs], Var, Value) :-
|
call_verify_attributes([Attr|Attrs], Var, Value) :-
|
||||||
'$module_of'(M, Attr), % write the owning module Attr to M.
|
'$module_of'(M, Attr), % write the owning module Attr to M.
|
||||||
catch(M:verify_attribute(Var, Value, Goals), error(existence_error(procedure, _), _), true),
|
catch(M:verify_attributes(Var, Value, Goals),
|
||||||
call_verify_attribute_goals(Goals),
|
error(evaluation_error((M:verify_attributes)/3), verify_attributes/3),
|
||||||
|
true),
|
||||||
|
call_verify_attributes_goals(Goals),
|
||||||
call_verify_attributes(Attrs, Var, Value).
|
call_verify_attributes(Attrs, Var, Value).
|
||||||
|
|
||||||
call_verify_attribute_goals(Goals) :-
|
call_verify_attributes_goals(Goals) :-
|
||||||
var(Goals), throw(error(instantiation_error, call_verify_attribute_goals/1)).
|
var(Goals), throw(error(instantiation_error, call_verify_attributes_goals/1)).
|
||||||
call_verify_attribute_goals([Goal|Goals]) :-
|
call_verify_attributes_goals([Goal|Goals]) :-
|
||||||
call(Goal),
|
call(Goal), !,
|
||||||
call_verify_attribute_goals(Goals).
|
call_verify_attributes_goals(Goals).
|
||||||
call_verify_attribute_goals([]).
|
call_verify_attributes_goals([]).
|
||||||
";
|
";
|
||||||
|
|
||||||
|
pub(super) type Bindings = Vec<(usize, Addr)>;
|
||||||
|
|
||||||
|
pub(super) struct AttrVarInitializer {
|
||||||
|
pub(super) bindings: Bindings,
|
||||||
|
pub(super) registers: Registers,
|
||||||
|
pub(super) special_form_cp: CodePtr,
|
||||||
|
pub(super) verify_attrs_loc: usize
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AttrVarInitializer {
|
||||||
|
pub(super) fn new(p: usize) -> Self {
|
||||||
|
AttrVarInitializer {
|
||||||
|
bindings: vec![],
|
||||||
|
verify_attrs_loc: p,
|
||||||
|
special_form_cp: CodePtr::VerifyAttrInterrupt(p),
|
||||||
|
registers: vec![Addr::HeapCell(0); MAX_ARITY + 1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn reset(&mut self) {
|
||||||
|
self.special_form_cp = CodePtr::VerifyAttrInterrupt(self.verify_attrs_loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MachineState {
|
||||||
|
pub(super) fn add_attr_var_binding(&mut self, h: usize, addr: Addr)
|
||||||
|
{
|
||||||
|
self.attr_var_init.bindings.push((h, addr));
|
||||||
|
|
||||||
|
if let &CodePtr::VerifyAttrInterrupt(_) = &self.p {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mem::swap(&mut self.attr_var_init.special_form_cp, &mut self.p);
|
||||||
|
self.attr_var_init.special_form_cp += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super)
|
||||||
|
fn verify_attributes(&mut self)
|
||||||
|
{
|
||||||
|
/* STEP 1: Undo bindings in machine (DONE)
|
||||||
|
STEP 2: Write the list of bindings to two lists in the heap, one for vars, one for values. (DONE)
|
||||||
|
STEP 3: Swap the machine's Registers for attr_var_init's Registers. (DONE)
|
||||||
|
STEP 4: Pass the addresses of the lists to iterate in the attr_vars special form. (DONE)
|
||||||
|
STEP 5: Restore AttrVarInitializer::special_form_cp to self.p (DONE).
|
||||||
|
STEP 6: Swap the bindings' Registers back for the machine's Registers. (DONE)
|
||||||
|
STEP 7: Redo the bindings. (DONE)
|
||||||
|
STEP 8: Continue.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (h, _) in &self.attr_var_init.bindings {
|
||||||
|
self.heap[*h] = HeapCellValue::Addr(Addr::AttrVar(*h));
|
||||||
|
}
|
||||||
|
|
||||||
|
let (var_list_addr, value_list_addr) = {
|
||||||
|
let iter = self.attr_var_init.bindings.iter().map(|(ref h, _)| Addr::AttrVar(*h));
|
||||||
|
let var_list_addr = Addr::HeapCell(self.heap.to_list(iter));
|
||||||
|
|
||||||
|
let iter = self.attr_var_init.bindings.iter().map(|(_, ref addr)| addr.clone());
|
||||||
|
let value_list_addr = Addr::HeapCell(self.heap.to_list(iter));
|
||||||
|
|
||||||
|
(var_list_addr, value_list_addr)
|
||||||
|
};
|
||||||
|
|
||||||
|
mem::swap(&mut self.registers, &mut self.attr_var_init.registers);
|
||||||
|
|
||||||
|
self[temp_v!(1)] = var_list_addr;
|
||||||
|
self[temp_v!(2)] = value_list_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use prolog_parser::string_list::*;
|
|||||||
use prolog::instructions::*;
|
use prolog::instructions::*;
|
||||||
use prolog::and_stack::*;
|
use prolog::and_stack::*;
|
||||||
use prolog::copier::*;
|
use prolog::copier::*;
|
||||||
use prolog::machine::IndexStore;
|
use prolog::machine::{AttrVarInitializer, IndexStore};
|
||||||
use prolog::machine::machine_errors::*;
|
use prolog::machine::machine_errors::*;
|
||||||
use prolog::num::{BigInt, BigUint, Zero, One};
|
use prolog::num::{BigInt, BigUint, Zero, One};
|
||||||
use prolog::or_stack::*;
|
use prolog::or_stack::*;
|
||||||
@@ -206,7 +206,7 @@ pub struct MachineState {
|
|||||||
pub(super) e: usize,
|
pub(super) e: usize,
|
||||||
pub(super) num_of_args: usize,
|
pub(super) num_of_args: usize,
|
||||||
pub(super) cp: LocalCodePtr,
|
pub(super) cp: LocalCodePtr,
|
||||||
pub(super) special_form_cp: CodePtr,
|
pub(super) attr_var_init: AttrVarInitializer,
|
||||||
pub(super) fail: bool,
|
pub(super) fail: bool,
|
||||||
pub(crate) heap: Heap,
|
pub(crate) heap: Heap,
|
||||||
pub(super) mode: MachineMode,
|
pub(super) mode: MachineMode,
|
||||||
@@ -231,14 +231,14 @@ impl MachineState {
|
|||||||
self.cp.assign_if_local(self.p.clone() + 1);
|
self.cp.assign_if_local(self.p.clone() + 1);
|
||||||
self.num_of_args = arity;
|
self.num_of_args = arity;
|
||||||
self.b0 = self.b;
|
self.b0 = self.b;
|
||||||
self.p = dir_entry!(p);
|
self.p = dir_entry!(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_at_index(&mut self, arity: usize, p: usize)
|
fn execute_at_index(&mut self, arity: usize, p: usize)
|
||||||
{
|
{
|
||||||
self.num_of_args = arity;
|
self.num_of_args = arity;
|
||||||
self.b0 = self.b;
|
self.b0 = self.b;
|
||||||
self.p = dir_entry!(p);
|
self.p = dir_entry!(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super)
|
pub(super)
|
||||||
@@ -246,8 +246,8 @@ impl MachineState {
|
|||||||
last_call: bool)
|
last_call: bool)
|
||||||
-> CallResult
|
-> CallResult
|
||||||
{
|
{
|
||||||
let (name, arity) = key;
|
let (name, arity) = key;
|
||||||
|
|
||||||
if let Some(ref idx) = indices.get_code_index((name.clone(), arity), module_name.clone())
|
if let Some(ref idx) = indices.get_code_index((name.clone(), arity), module_name.clone())
|
||||||
{
|
{
|
||||||
if let IndexPtr::Index(compiled_tl_index) = idx.0.borrow().0 {
|
if let IndexPtr::Index(compiled_tl_index) = idx.0.borrow().0 {
|
||||||
@@ -256,15 +256,15 @@ impl MachineState {
|
|||||||
} else {
|
} else {
|
||||||
self.call_at_index(arity, compiled_tl_index);
|
self.call_at_index(arity, compiled_tl_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let h = self.heap.h;
|
let h = self.heap.h;
|
||||||
let stub = MachineError::functor_stub(name.clone(), arity);
|
let stub = MachineError::functor_stub(name.clone(), arity);
|
||||||
let err = MachineError::module_resolution_error(h, module_name, name, arity);
|
let err = MachineError::module_resolution_error(h, module_name, name, arity);
|
||||||
|
|
||||||
return Err(self.error_form(err, stub));
|
return Err(self.error_form(err, stub));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -615,7 +615,7 @@ pub(crate) trait CallPolicy: Any {
|
|||||||
list.sort_unstable_by(|a1, a2| machine_st.compare_term_test(a1, a2));
|
list.sort_unstable_by(|a1, a2| machine_st.compare_term_test(a1, a2));
|
||||||
machine_st.term_dedup(&mut list);
|
machine_st.term_dedup(&mut list);
|
||||||
|
|
||||||
let heap_addr = Addr::HeapCell(machine_st.to_list(list.into_iter()));
|
let heap_addr = Addr::HeapCell(machine_st.heap.to_list(list.into_iter()));
|
||||||
|
|
||||||
let r2 = machine_st[temp_v!(2)].clone();
|
let r2 = machine_st[temp_v!(2)].clone();
|
||||||
machine_st.unify(r2, heap_addr);
|
machine_st.unify(r2, heap_addr);
|
||||||
@@ -637,7 +637,7 @@ pub(crate) trait CallPolicy: Any {
|
|||||||
key_pairs.sort_by(|a1, a2| machine_st.compare_term_test(&a1.0, &a2.0));
|
key_pairs.sort_by(|a1, a2| machine_st.compare_term_test(&a1.0, &a2.0));
|
||||||
|
|
||||||
let key_pairs = key_pairs.into_iter().map(|kp| kp.1);
|
let key_pairs = key_pairs.into_iter().map(|kp| kp.1);
|
||||||
let heap_addr = Addr::HeapCell(machine_st.to_list(key_pairs));
|
let heap_addr = Addr::HeapCell(machine_st.heap.to_list(key_pairs));
|
||||||
|
|
||||||
let r2 = machine_st[temp_v!(2)].clone();
|
let r2 = machine_st[temp_v!(2)].clone();
|
||||||
machine_st.unify(r2, heap_addr);
|
machine_st.unify(r2, heap_addr);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use prolog::and_stack::*;
|
|||||||
use prolog::copier::*;
|
use prolog::copier::*;
|
||||||
use prolog::heap_iter::*;
|
use prolog::heap_iter::*;
|
||||||
use prolog::heap_print::*;
|
use prolog::heap_print::*;
|
||||||
use prolog::machine::IndexStore;
|
use prolog::machine::{AttrVarInitializer, IndexStore};
|
||||||
use prolog::machine::machine_errors::*;
|
use prolog::machine::machine_errors::*;
|
||||||
use prolog::machine::machine_state::*;
|
use prolog::machine::machine_state::*;
|
||||||
use prolog::num::{Integer, Signed, ToPrimitive, Zero};
|
use prolog::num::{Integer, Signed, ToPrimitive, Zero};
|
||||||
@@ -40,7 +40,7 @@ impl MachineState {
|
|||||||
e: 0,
|
e: 0,
|
||||||
num_of_args: 0,
|
num_of_args: 0,
|
||||||
cp: LocalCodePtr::default(),
|
cp: LocalCodePtr::default(),
|
||||||
special_form_cp: CodePtr::default(),
|
attr_var_init: AttrVarInitializer::new(0),
|
||||||
fail: false,
|
fail: false,
|
||||||
heap: Heap::with_capacity(256),
|
heap: Heap::with_capacity(256),
|
||||||
mode: MachineMode::Write,
|
mode: MachineMode::Write,
|
||||||
@@ -102,16 +102,16 @@ impl MachineState {
|
|||||||
match addr.as_var() {
|
match addr.as_var() {
|
||||||
Some(Ref::HeapCell(hc)) => {
|
Some(Ref::HeapCell(hc)) => {
|
||||||
self.heap[hc] = HeapCellValue::Addr(Addr::AttrVar(h));
|
self.heap[hc] = HeapCellValue::Addr(Addr::AttrVar(h));
|
||||||
self.trail(TrailRef::from(Ref::HeapCell(hc)));
|
self.trail(TrailRef::Ref(Ref::HeapCell(hc)));
|
||||||
},
|
},
|
||||||
Some(Ref::StackCell(fr, sc)) => {
|
Some(Ref::StackCell(fr, sc)) => {
|
||||||
self.and_stack[fr][sc] = Addr::AttrVar(h);
|
self.and_stack[fr][sc] = Addr::AttrVar(h);
|
||||||
self.trail(TrailRef::from(Ref::StackCell(fr, sc)));
|
self.trail(TrailRef::Ref(Ref::StackCell(fr, sc)));
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
// TODO: set up writing to the attribute queue here.
|
self.add_attr_var_binding(h, addr.clone());
|
||||||
self.heap[h] = HeapCellValue::Addr(addr);
|
self.heap[h] = HeapCellValue::Addr(addr);
|
||||||
self.trail(TrailRef::from(Ref::AttrVar(h)));
|
self.trail(TrailRef::Ref(Ref::AttrVar(h)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1941,20 +1941,6 @@ impl MachineState {
|
|||||||
*list = result;
|
*list = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn to_list<Iter: Iterator<Item=Addr>>(&mut self, values: Iter) -> usize {
|
|
||||||
let head_addr = self.heap.h;
|
|
||||||
|
|
||||||
for value in values {
|
|
||||||
let h = self.heap.h;
|
|
||||||
|
|
||||||
self.heap.push(HeapCellValue::Addr(Addr::Lis(h+1)));
|
|
||||||
self.heap.push(HeapCellValue::Addr(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.heap.push(HeapCellValue::Addr(Addr::Con(Constant::EmptyList)));
|
|
||||||
head_addr
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn try_from_list(&self, r: RegType, caller: MachineStub)
|
pub(super) fn try_from_list(&self, r: RegType, caller: MachineStub)
|
||||||
-> Result<Vec<Addr>, MachineStub>
|
-> Result<Vec<Addr>, MachineStub>
|
||||||
{
|
{
|
||||||
@@ -2364,7 +2350,7 @@ impl MachineState {
|
|||||||
self.pstr_tr = 0;
|
self.pstr_tr = 0;
|
||||||
self.p = CodePtr::default();
|
self.p = CodePtr::default();
|
||||||
self.cp = LocalCodePtr::default();
|
self.cp = LocalCodePtr::default();
|
||||||
self.special_form_cp = CodePtr::default();
|
self.attr_var_init.reset();
|
||||||
self.num_of_args = 0;
|
self.num_of_args = 0;
|
||||||
|
|
||||||
self.fail = false;
|
self.fail = false;
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ impl CodeRepo {
|
|||||||
term_expanders: Code::new(),
|
term_expanders: Code::new(),
|
||||||
code: Code::new(),
|
code: Code::new(),
|
||||||
in_situ_code: Code::new(),
|
in_situ_code: Code::new(),
|
||||||
verify_attrs_code: Code::new(),
|
|
||||||
term_dir: TermDir::new()
|
term_dir: TermDir::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,7 +201,10 @@ impl CodeRepo {
|
|||||||
&CodePtr::CallN(arity, _) => {
|
&CodePtr::CallN(arity, _) => {
|
||||||
let call_clause = call_clause!(ClauseType::CallN, arity, 0, last_call);
|
let call_clause = call_clause!(ClauseType::CallN, arity, 0, last_call);
|
||||||
Some(RefOrOwned::Owned(call_clause))
|
Some(RefOrOwned::Owned(call_clause))
|
||||||
}
|
},
|
||||||
|
&CodePtr::VerifyAttrInterrupt(p) =>
|
||||||
|
Some(RefOrOwned::Borrowed(&self.code[p])),
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,7 +240,7 @@ impl Index<LocalCodePtr> for CodeRepo {
|
|||||||
LocalCodePtr::TopLevel(_, p) => &self.cached_query[p],
|
LocalCodePtr::TopLevel(_, p) => &self.cached_query[p],
|
||||||
LocalCodePtr::DirEntry(p) => &self.code[p],
|
LocalCodePtr::DirEntry(p) => &self.code[p],
|
||||||
LocalCodePtr::UserGoalExpansion(p) => &self.goal_expanders[p],
|
LocalCodePtr::UserGoalExpansion(p) => &self.goal_expanders[p],
|
||||||
LocalCodePtr::UserTermExpansion(p) => &self.term_expanders[p]
|
LocalCodePtr::UserTermExpansion(p) => &self.term_expanders[p],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,7 +323,11 @@ static ATTS: &str = include_str!("../lib/atts.pl");
|
|||||||
impl Machine {
|
impl Machine {
|
||||||
fn compile_special_forms(&mut self) {
|
fn compile_special_forms(&mut self) {
|
||||||
match compile_special_form(self, VERIFY_ATTRS.as_bytes()) {
|
match compile_special_form(self, VERIFY_ATTRS.as_bytes()) {
|
||||||
Ok(code) => self.code_repo.verify_attrs_code = code,
|
Ok(code) => {
|
||||||
|
self.machine_st.attr_var_init.verify_attrs_loc = self.code_repo.code.len();
|
||||||
|
self.machine_st.attr_var_init.reset();
|
||||||
|
self.code_repo.code.extend(code.into_iter());
|
||||||
|
},
|
||||||
Err(_e) => panic!("Machine::compile_special_forms() failed")
|
Err(_e) => panic!("Machine::compile_special_forms() failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -580,6 +586,13 @@ impl MachineState {
|
|||||||
if p < code_repo.in_situ_code.len() => {},
|
if p < code_repo.in_situ_code.len() => {},
|
||||||
CodePtr::Local(_) =>
|
CodePtr::Local(_) =>
|
||||||
break,
|
break,
|
||||||
|
CodePtr::VerifyAttrInterrupt(p) => {
|
||||||
|
self.verify_attributes();
|
||||||
|
|
||||||
|
self.num_of_args = 2;
|
||||||
|
self.b0 = self.b;
|
||||||
|
self.p = CodePtr::Local(LocalCodePtr::DirEntry(p));
|
||||||
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use prolog::num::{ToPrimitive, Zero};
|
|||||||
use prolog::num::bigint::{BigInt};
|
use prolog::num::bigint::{BigInt};
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use std::mem;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
struct BrentAlgState {
|
struct BrentAlgState {
|
||||||
@@ -442,7 +443,17 @@ impl MachineState {
|
|||||||
CWILCallPolicy.")
|
CWILCallPolicy.")
|
||||||
},
|
},
|
||||||
&SystemClauseType::RestoreCodePtrFromSpecialFormCP => {
|
&SystemClauseType::RestoreCodePtrFromSpecialFormCP => {
|
||||||
self.p = self.special_form_cp.clone();
|
self.p = mem::replace(&mut self.attr_var_init.special_form_cp,
|
||||||
|
CodePtr::VerifyAttrInterrupt(self.attr_var_init.verify_attrs_loc));
|
||||||
|
mem::swap(&mut self.registers, &mut self.attr_var_init.registers);
|
||||||
|
|
||||||
|
let mut bindings = vec![];
|
||||||
|
mem::swap(&mut bindings, &mut self.attr_var_init.bindings);
|
||||||
|
|
||||||
|
for (h, addr) in bindings {
|
||||||
|
self.heap[h] = HeapCellValue::Addr(addr);
|
||||||
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
},
|
},
|
||||||
&SystemClauseType::RestoreCutPolicy => {
|
&SystemClauseType::RestoreCutPolicy => {
|
||||||
|
|||||||
Reference in New Issue
Block a user