remove Option wrapper from cached_query
This commit is contained in:
@@ -40,7 +40,8 @@ fn print_code(code: &Code) {
|
||||
}
|
||||
|
||||
// throw errors if declaration or query found.
|
||||
fn compile_relation(tl: &TopLevel, non_counted_bt: bool, flags: MachineFlags) -> Result<Code, ParserError>
|
||||
fn compile_relation(tl: &TopLevel, non_counted_bt: bool, flags: MachineFlags)
|
||||
-> Result<Code, ParserError>
|
||||
{
|
||||
let mut cg = CodeGenerator::<DebrayAllocator>::new(non_counted_bt, flags);
|
||||
|
||||
@@ -307,7 +308,6 @@ impl ListingCompiler {
|
||||
let wam_indices = &mut wam.indices;
|
||||
|
||||
let atom_tbl = wam_indices.atom_tbl.clone();
|
||||
|
||||
let mut worker = TopLevelBatchWorker::new(src, atom_tbl.clone(), flags,
|
||||
wam_indices, &mut wam.policies,
|
||||
&mut wam.code_repo);
|
||||
|
||||
@@ -41,15 +41,15 @@
|
||||
:- op(700, xfx, >=).
|
||||
:- op(700, xfx, =<).
|
||||
|
||||
% conditional operators.
|
||||
:- op(1050, xfy, ->).
|
||||
:- op(1100, xfy, ;).
|
||||
|
||||
% control.
|
||||
:- op(700, xfx, =).
|
||||
:- op(900, fy, \+).
|
||||
:- op(700, xfx, =..).
|
||||
|
||||
% conditional operators.
|
||||
:- op(1050, xfy, ->).
|
||||
:- op(1100, xfy, ;).
|
||||
|
||||
% term comparison.
|
||||
:- op(700, xfx, ==).
|
||||
:- op(700, xfx, \==).
|
||||
|
||||
@@ -101,7 +101,7 @@ impl IndexStore {
|
||||
}
|
||||
|
||||
pub struct CodeRepo {
|
||||
cached_query: Option<Code>,
|
||||
cached_query: Code,
|
||||
pub(super) goal_expanders: Code,
|
||||
pub(super) term_expanders: Code,
|
||||
pub(super) code: Code,
|
||||
@@ -112,7 +112,7 @@ impl CodeRepo {
|
||||
#[inline]
|
||||
fn new() -> Self {
|
||||
CodeRepo {
|
||||
cached_query: None,
|
||||
cached_query: vec![],
|
||||
goal_expanders: Code::new(),
|
||||
term_expanders: Code::new(),
|
||||
code: Code::new(),
|
||||
@@ -122,10 +122,7 @@ impl CodeRepo {
|
||||
|
||||
#[inline]
|
||||
fn size_of_cached_query(&self) -> usize {
|
||||
match &self.cached_query {
|
||||
&Some(ref query) => query.len(),
|
||||
_ => 0
|
||||
}
|
||||
self.cached_query.len()
|
||||
}
|
||||
|
||||
fn lookup_instr<'a>(&'a self, last_call: bool, p: &CodePtr) -> Option<RefOrOwned<'a, Line>>
|
||||
@@ -144,9 +141,10 @@ impl CodeRepo {
|
||||
None
|
||||
},
|
||||
&CodePtr::Local(LocalCodePtr::TopLevel(_, p)) =>
|
||||
match &self.cached_query {
|
||||
&Some(ref cq) => Some(RefOrOwned::Borrowed(&cq[p])),
|
||||
&None => None
|
||||
if p < self.cached_query.len() {
|
||||
Some(RefOrOwned::Borrowed(&self.cached_query[p]))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
&CodePtr::Local(LocalCodePtr::DirEntry(p)) =>
|
||||
Some(RefOrOwned::Borrowed(&self.code[p])),
|
||||
@@ -191,12 +189,7 @@ impl Index<LocalCodePtr> for CodeRepo {
|
||||
|
||||
fn index(&self, ptr: LocalCodePtr) -> &Self::Output {
|
||||
match ptr {
|
||||
LocalCodePtr::TopLevel(_, p) => {
|
||||
match &self.cached_query {
|
||||
&Some(ref cq) => &cq[p],
|
||||
&None => panic!("Out-of-bounds top level index.")
|
||||
}
|
||||
},
|
||||
LocalCodePtr::TopLevel(_, p) => &self.cached_query[p],
|
||||
LocalCodePtr::DirEntry(p) => &self.code[p],
|
||||
LocalCodePtr::UserGoalExpansion(p) => &self.goal_expanders[p],
|
||||
LocalCodePtr::UserTermExpansion(p) => &self.term_expanders[p]
|
||||
@@ -370,7 +363,7 @@ impl Machine {
|
||||
{
|
||||
let mut heap_locs = HashMap::new();
|
||||
|
||||
self.code_repo.cached_query = Some(code);
|
||||
self.code_repo.cached_query = code;
|
||||
self.machine_st.run_query(&mut self.indices, &mut self.policies, &self.code_repo, &alloc_locs, &mut heap_locs);
|
||||
|
||||
if self.machine_st.fail {
|
||||
|
||||
@@ -230,7 +230,7 @@ impl MachineState {
|
||||
|
||||
let code = vec![call_clause!(ClauseType::Hook(hook), 2, 0, true)];
|
||||
|
||||
code_repo.cached_query = Some(code);
|
||||
code_repo.cached_query = code;
|
||||
self.run_query(indices, policies, code_repo, &AllocVarDict::new(), &mut HeapVarDict::new());
|
||||
|
||||
if self.fail {
|
||||
|
||||
Reference in New Issue
Block a user