allow late dynamic declaration for predicates (#1205)
This commit is contained in:
@@ -2167,8 +2167,31 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
skeleton.core.clause_clause_locs.push_front(loc);
|
||||
}
|
||||
}
|
||||
None if append_or_prepend.is_append() => {
|
||||
let mut skeleton = PredicateSkeleton::new();
|
||||
|
||||
for loc in locs_vec {
|
||||
skeleton.core.clause_clause_locs.push_back(loc);
|
||||
}
|
||||
|
||||
self.add_extensible_predicate(
|
||||
(atom!("$clause"), 2),
|
||||
skeleton,
|
||||
clause_clause_compilation_target,
|
||||
);
|
||||
}
|
||||
None => {
|
||||
unreachable!();
|
||||
let mut skeleton = PredicateSkeleton::new();
|
||||
|
||||
for loc in locs_vec.into_iter().rev() {
|
||||
skeleton.core.clause_clause_locs.push_back(loc);
|
||||
}
|
||||
|
||||
self.add_extensible_predicate(
|
||||
(atom!("$clause"), 2),
|
||||
skeleton,
|
||||
clause_clause_compilation_target,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2315,8 +2338,10 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
if predicate_info.is_dynamic {
|
||||
LS::machine_st(&mut self.payload).global_clock += 1;
|
||||
|
||||
let clause_clauses_len = self.payload.clause_clauses.len();
|
||||
let clauses_vec: Vec<_> = self.payload
|
||||
.clause_clauses.drain(0..predicates_len).collect();
|
||||
.clause_clauses.drain(0..std::cmp::min(predicates_len, clause_clauses_len))
|
||||
.collect();
|
||||
|
||||
self.compile_clause_clauses(
|
||||
key,
|
||||
|
||||
@@ -126,117 +126,6 @@ impl Default for CodeIndex {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq)]
|
||||
pub enum REPLCodePtr {
|
||||
AddDiscontiguousPredicate,
|
||||
AddDynamicPredicate,
|
||||
AddMultifilePredicate,
|
||||
AddGoalExpansionClause,
|
||||
AddTermExpansionClause,
|
||||
AddInSituFilenameModule,
|
||||
ClauseToEvacuable,
|
||||
ScopedClauseToEvacuable,
|
||||
ConcludeLoad,
|
||||
DeclareModule,
|
||||
LoadCompiledLibrary,
|
||||
LoadContextSource,
|
||||
LoadContextFile,
|
||||
LoadContextDirectory,
|
||||
LoadContextModule,
|
||||
LoadContextStream,
|
||||
PopLoadContext,
|
||||
PopLoadStatePayload,
|
||||
PushLoadContext,
|
||||
PushLoadStatePayload,
|
||||
UseModule,
|
||||
BuiltInProperty,
|
||||
MetaPredicateProperty,
|
||||
MultifileProperty,
|
||||
DiscontiguousProperty,
|
||||
DynamicProperty,
|
||||
AbolishClause,
|
||||
Asserta,
|
||||
Assertz,
|
||||
Retract,
|
||||
IsConsistentWithTermQueue,
|
||||
FlushTermQueue,
|
||||
RemoveModuleExports,
|
||||
AddNonCountedBacktracking,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum CodePtr {
|
||||
BuiltInClause(BuiltInClauseType, usize), // local is the successor call.
|
||||
CallN(usize, usize, bool), // arity, local, last call.
|
||||
Local(usize),
|
||||
REPL(REPLCodePtr, usize), // the REPL code, the return pointer.
|
||||
VerifyAttrInterrupt(usize), // location of the verify attribute interrupt code in the CodeDir.
|
||||
}
|
||||
|
||||
impl CodePtr {
|
||||
pub(crate) fn local(&self) -> usize {
|
||||
match self {
|
||||
&CodePtr::BuiltInClause(_, ref local) |
|
||||
&CodePtr::CallN(_, ref local, _) |
|
||||
&CodePtr::Local(ref local) => *local,
|
||||
&CodePtr::VerifyAttrInterrupt(p) => p,
|
||||
&CodePtr::REPL(_, p) => p,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assign_if_local(&self, cp: &mut usize) {
|
||||
match self {
|
||||
CodePtr::Local(local) => *cp = *local,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<usize> for CodePtr {
|
||||
type Output = CodePtr;
|
||||
|
||||
fn add(self, rhs: usize) -> Self::Output {
|
||||
match self {
|
||||
p @ CodePtr::REPL(..) | p @ CodePtr::VerifyAttrInterrupt(_) => {
|
||||
p
|
||||
}
|
||||
CodePtr::Local(local) => CodePtr::Local(local + rhs),
|
||||
CodePtr::BuiltInClause(_, local) | CodePtr::CallN(_, local, _) => {
|
||||
CodePtr::Local(local + rhs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign<usize> for CodePtr {
|
||||
fn add_assign(&mut self, rhs: usize) {
|
||||
match self {
|
||||
&mut CodePtr::VerifyAttrInterrupt(_) => {}
|
||||
&mut CodePtr::Local(ref mut local) => *local += rhs,
|
||||
_ => *self = CodePtr::Local(self.local() + rhs),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SubAssign<usize> for CodePtr {
|
||||
#[inline]
|
||||
fn sub_assign(&mut self, rhs: usize) {
|
||||
match self {
|
||||
CodePtr::Local(ref mut local) => *local -= rhs,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CodePtr {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
CodePtr::Local(0)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
pub(crate) type HeapVarDict = IndexMap<Rc<String>, HeapCellValue, FxBuildHasher>;
|
||||
pub(crate) type AllocVarDict = IndexMap<Rc<String>, VarData, FxBuildHasher>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user