allow late dynamic declaration for predicates (#1205)

This commit is contained in:
Mark Thom
2022-01-13 20:30:29 -07:00
parent bc5125b719
commit f3e5f7879d
2 changed files with 27 additions and 113 deletions

View File

@@ -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>;