divide atom tables by module
This commit is contained in:
@@ -307,7 +307,7 @@ pub(crate) trait CallPolicy: Any {
|
||||
machine_st.pstr_tr = machine_st.or_stack[b].pstr_tr;
|
||||
|
||||
machine_st.pstr_trail.truncate(machine_st.pstr_tr);
|
||||
|
||||
|
||||
machine_st.heap.truncate(machine_st.or_stack[b].h);
|
||||
|
||||
machine_st.hb = machine_st.heap.h;
|
||||
@@ -334,7 +334,7 @@ pub(crate) trait CallPolicy: Any {
|
||||
let curr_tr = machine_st.tr;
|
||||
|
||||
machine_st.unwind_trail(old_tr, curr_tr);
|
||||
machine_st.tr = machine_st.or_stack[b].tr;
|
||||
machine_st.tr = machine_st.or_stack[b].tr;
|
||||
|
||||
machine_st.trail.truncate(machine_st.tr);
|
||||
|
||||
@@ -345,7 +345,7 @@ pub(crate) trait CallPolicy: Any {
|
||||
machine_st.pstr_tr = machine_st.or_stack[b].pstr_tr;
|
||||
|
||||
machine_st.pstr_trail.truncate(machine_st.pstr_tr);
|
||||
|
||||
|
||||
machine_st.heap.truncate(machine_st.or_stack[b].h);
|
||||
|
||||
machine_st.hb = machine_st.heap.h;
|
||||
@@ -371,7 +371,7 @@ pub(crate) trait CallPolicy: Any {
|
||||
|
||||
machine_st.unwind_trail(old_tr, curr_tr);
|
||||
machine_st.tr = machine_st.or_stack[b].tr;
|
||||
|
||||
|
||||
machine_st.trail.truncate(machine_st.tr);
|
||||
|
||||
let old_pstr_tr = machine_st.or_stack[b].pstr_tr;
|
||||
@@ -381,7 +381,7 @@ pub(crate) trait CallPolicy: Any {
|
||||
machine_st.pstr_tr = machine_st.or_stack[b].pstr_tr;
|
||||
|
||||
machine_st.pstr_trail.truncate(machine_st.pstr_tr);
|
||||
|
||||
|
||||
machine_st.heap.truncate(machine_st.or_stack[b].h);
|
||||
machine_st.b = machine_st.or_stack[b].b;
|
||||
|
||||
@@ -410,7 +410,7 @@ pub(crate) trait CallPolicy: Any {
|
||||
|
||||
machine_st.unwind_trail(old_tr, curr_tr);
|
||||
machine_st.tr = machine_st.or_stack[b].tr;
|
||||
|
||||
|
||||
machine_st.trail.truncate(machine_st.tr);
|
||||
|
||||
let old_pstr_tr = machine_st.or_stack[b].pstr_tr;
|
||||
@@ -420,7 +420,7 @@ pub(crate) trait CallPolicy: Any {
|
||||
machine_st.pstr_tr = machine_st.or_stack[b].pstr_tr;
|
||||
|
||||
machine_st.pstr_trail.truncate(machine_st.pstr_tr);
|
||||
|
||||
|
||||
machine_st.heap.truncate(machine_st.or_stack[b].h);
|
||||
|
||||
machine_st.b = machine_st.or_stack[b].b;
|
||||
@@ -508,7 +508,7 @@ pub(crate) trait CallPolicy: Any {
|
||||
stub));
|
||||
},
|
||||
IndexPtr::Index(compiled_tl_index) =>
|
||||
execute_at_index(machine_st, arity, compiled_tl_index)
|
||||
execute_at_index(machine_st, arity, compiled_tl_index)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -685,12 +685,10 @@ pub(crate) trait CallPolicy: Any {
|
||||
}
|
||||
|
||||
fn call_n<'a>(&mut self, machine_st: &mut MachineState, arity: usize,
|
||||
indices: MachineCodeIndices<'a>) //code_dirs: CodeDirs)
|
||||
indices: MachineCodeIndices<'a>)
|
||||
-> CallResult
|
||||
{
|
||||
if let Some((name, arity)) = machine_st.setup_call_n(arity) {
|
||||
let user = clause_name!("user");
|
||||
|
||||
match ClauseType::from(name.clone(), arity, None) {
|
||||
ClauseType::CallN => {
|
||||
machine_st.handle_internal_call_n(arity);
|
||||
@@ -707,15 +705,18 @@ pub(crate) trait CallPolicy: Any {
|
||||
},
|
||||
ClauseType::Inlined(inlined) =>
|
||||
machine_st.execute_inlined(&inlined),
|
||||
ClauseType::Op(..) | ClauseType::Named(..) =>
|
||||
if let Some(idx) = indices.get_code_index((name.clone(), arity), user) {
|
||||
ClauseType::Op(..) | ClauseType::Named(..) => {
|
||||
let module = name.owning_module();
|
||||
|
||||
if let Some(idx) = indices.get_code_index((name.clone(), arity), module) {
|
||||
self.context_call(machine_st, name, arity, idx, indices)?;
|
||||
} else {
|
||||
let h = machine_st.heap.h;
|
||||
let stub = MachineError::functor_stub(clause_name!("call"), arity + 1);
|
||||
return Err(machine_st.error_form(MachineError::existence_error(h, name, arity),
|
||||
stub));
|
||||
},
|
||||
}
|
||||
},
|
||||
ClauseType::Hook(_) | ClauseType::System(_) => {
|
||||
let name = Addr::Con(Constant::Atom(name, None));
|
||||
let stub = MachineError::functor_stub(clause_name!("call"), arity + 1);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use prolog_parser::ast::*;
|
||||
use prolog_parser::string_list::StringList;
|
||||
use prolog_parser::tabled_rc::TabledData;
|
||||
|
||||
use prolog::instructions::*;
|
||||
use prolog::and_stack::*;
|
||||
@@ -14,7 +15,6 @@ use prolog::num::bigint::{BigInt, BigUint};
|
||||
use prolog::num::rational::Ratio;
|
||||
use prolog::or_stack::*;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::cmp::{max, Ordering};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::rc::Rc;
|
||||
@@ -34,7 +34,7 @@ macro_rules! try_or_fail {
|
||||
impl MachineState {
|
||||
pub(super) fn new() -> Self {
|
||||
MachineState {
|
||||
atom_tbl: Rc::new(RefCell::new(HashSet::new())),
|
||||
atom_tbl: TabledData::new(Rc::new("user".to_string())),
|
||||
s: 0,
|
||||
p: CodePtr::default(),
|
||||
b: 0,
|
||||
|
||||
@@ -62,17 +62,6 @@ pub struct Machine {
|
||||
cached_query: Option<Code>
|
||||
}
|
||||
|
||||
fn get_code_index(code_dir: &CodeDir, modules: &ModuleDir, key: PredicateKey, module: ClauseName)
|
||||
-> Option<CodeIndex>
|
||||
{
|
||||
match module.as_str() {
|
||||
"user" | "builtin" => code_dir.get(&key).cloned(),
|
||||
_ => modules.get(&module).and_then(|ref module| {
|
||||
module.code_dir.get(&key).cloned().map(CodeIndex::from)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<LocalCodePtr> for Machine {
|
||||
type Output = Line;
|
||||
|
||||
@@ -95,15 +84,22 @@ impl<'a> SubModuleUser for MachineCodeIndices<'a> {
|
||||
self.op_dir
|
||||
}
|
||||
|
||||
fn get_code_index(&self, key: PredicateKey, module: ClauseName) -> Option<CodeIndex> {
|
||||
get_code_index(&self.code_dir, &self.modules, key, module)
|
||||
fn get_code_index(&self, key: PredicateKey, module: ClauseName) -> Option<CodeIndex>
|
||||
{
|
||||
match module.as_str() {
|
||||
"user" | "builtin" => self.code_dir.get(&key).cloned(),
|
||||
_ => self.modules.get(&module).and_then(|ref module| {
|
||||
module.code_dir.get(&key).cloned().map(CodeIndex::from)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_code_index(&mut self, key: PredicateKey) {
|
||||
self.code_dir.remove(&key);
|
||||
}
|
||||
|
||||
fn insert_dir_entry(&mut self, name: ClauseName, arity: usize, idx: ModuleCodeIndex) {
|
||||
fn insert_dir_entry(&mut self, name: ClauseName, arity: usize, idx: ModuleCodeIndex)
|
||||
{
|
||||
if let Some(ref mut code_idx) = self.code_dir.get_mut(&(name.clone(), arity)) {
|
||||
if !code_idx.is_undefined() {
|
||||
println!("warning: overwriting {}/{}", &name, arity);
|
||||
@@ -120,7 +116,7 @@ impl<'a> SubModuleUser for MachineCodeIndices<'a> {
|
||||
static LISTS: &str = include_str!("../lib/lists.pl");
|
||||
static CONTROL: &str = include_str!("../lib/control.pl");
|
||||
static QUEUES: &str = include_str!("../lib/queues.pl");
|
||||
static ERROR: &str = include_str!("../lib/error.pl");
|
||||
static ERROR: &str = include_str!("../lib/error.pl");
|
||||
static TERMS: &str = include_str!("../lib/terms.pl");
|
||||
|
||||
impl Machine {
|
||||
@@ -221,7 +217,8 @@ impl Machine {
|
||||
|
||||
#[inline]
|
||||
pub fn remove_module(&mut self, module: &Module) {
|
||||
let mut indices = machine_code_indices!(&mut self.code_dir.borrow_mut(), &mut self.op_dir,
|
||||
let mut indices = machine_code_indices!(&mut self.code_dir.borrow_mut(),
|
||||
&mut self.op_dir,
|
||||
&mut self.modules);
|
||||
indices.remove_module(clause_name!("user"), module);
|
||||
}
|
||||
@@ -259,15 +256,15 @@ impl Machine {
|
||||
{
|
||||
let key = (clause_name!("term_expansion"), 2);
|
||||
let preds = self.term_dir.entry(key).or_insert(Predicate(vec![]));
|
||||
|
||||
|
||||
preds.0.push(clause);
|
||||
|
||||
|
||||
let mut cg = CodeGenerator::<DebrayAllocator>::new(false, self.ms.flags);
|
||||
let code = cg.compile_predicate(&preds.0)?;
|
||||
|
||||
Ok(self.term_expanders = code)
|
||||
}
|
||||
|
||||
|
||||
fn lookup_instr(&self, p: CodePtr) -> Option<Line> {
|
||||
match p {
|
||||
CodePtr::Local(LocalCodePtr::UserTermExpansion(p)) =>
|
||||
|
||||
@@ -24,6 +24,11 @@ impl<R: Read> TermStream<R> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_atom_tbl(&mut self, atom_tbl: TabledData<Atom>) {
|
||||
self.parser.set_atom_tbl(atom_tbl);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn add_to_top(&mut self, buf: &str) {
|
||||
self.parser.add_to_top(buf);
|
||||
|
||||
Reference in New Issue
Block a user