implement dynamic, multifile, and discontiguous properties and callable type checking for predicate_property/2

This commit is contained in:
Mark Thom
2021-02-05 02:16:14 -07:00
parent 804858d736
commit 2d7f31a60d
6 changed files with 154 additions and 9 deletions

View File

@@ -549,6 +549,7 @@ impl<'a> Drop for LoadState<'a> {
}
}
}
// TODO: necessary? unnecessary?
// self.wam.code_repo.code.truncate(self.retraction_info.orig_code_extent);
}
@@ -1543,6 +1544,108 @@ impl Machine {
}
}
pub(crate)
fn dynamic_property(&mut self) {
let module_name = atom_from!(
self.machine_st,
self.machine_st.store(self.machine_st.deref(
self.machine_st[temp_v!(1)]
))
);
let key =
self.machine_st.read_predicate_key(
self.machine_st[temp_v!(2)],
self.machine_st[temp_v!(3)],
);
let compilation_target =
match module_name.as_str() {
"user" => CompilationTarget::User,
_ => CompilationTarget::Module(module_name),
};
match self.indices.get_predicate_skeleton(
&compilation_target,
&key,
) {
Some(skeleton) => {
self.machine_st.fail = !skeleton.is_dynamic;
}
None => {
self.machine_st.fail = true;
}
}
}
pub(crate)
fn multifile_property(&mut self) {
let module_name = atom_from!(
self.machine_st,
self.machine_st.store(self.machine_st.deref(
self.machine_st[temp_v!(1)]
))
);
let key =
self.machine_st.read_predicate_key(
self.machine_st[temp_v!(2)],
self.machine_st[temp_v!(3)],
);
let compilation_target =
match module_name.as_str() {
"user" => CompilationTarget::User,
_ => CompilationTarget::Module(module_name),
};
match self.indices.get_predicate_skeleton(
&compilation_target,
&key,
) {
Some(skeleton) => {
self.machine_st.fail = !skeleton.is_multifile;
}
None => {
self.machine_st.fail = true;
}
}
}
pub(crate)
fn discontiguous_property(&mut self) {
let module_name = atom_from!(
self.machine_st,
self.machine_st.store(self.machine_st.deref(
self.machine_st[temp_v!(1)]
))
);
let key =
self.machine_st.read_predicate_key(
self.machine_st[temp_v!(2)],
self.machine_st[temp_v!(3)],
);
let compilation_target =
match module_name.as_str() {
"user" => CompilationTarget::User,
_ => CompilationTarget::Module(module_name),
};
match self.indices.get_predicate_skeleton(
&compilation_target,
&key,
) {
Some(skeleton) => {
self.machine_st.fail = !skeleton.is_discontiguous;
}
None => {
self.machine_st.fail = true;
}
}
}
pub(crate)
fn builtin_property(&mut self) {
let key =

View File

@@ -505,7 +505,6 @@ pub enum REPLCodePtr {
AddDynamicPredicate,
AddGoalExpansionClause,
AddTermExpansionClause,
BuiltInProperty,
ClauseToEvacuable,
ConcludeLoad,
DeclareModule,
@@ -520,7 +519,11 @@ pub enum REPLCodePtr {
PushLoadContext,
PushLoadStatePayload,
UseModule,
BuiltInProperty,
MetaPredicateProperty,
MultifileProperty,
DiscontiguousProperty,
DynamicProperty,
CompilePendingPredicates,
UserAsserta,
UserAssertz,

View File

@@ -258,7 +258,7 @@ impl Machine {
for arity in 1 .. 66 {
let key = (clause_name!("call"), arity);
match loader.code_dir.get(&key).cloned() {
match loader.code_dir.get(&key) {
Some(src_code_index) => {
let target_code_index = target_module.code_dir
.entry(key.clone())
@@ -482,6 +482,15 @@ impl Machine {
REPLCodePtr::BuiltInProperty => {
self.builtin_property();
}
REPLCodePtr::MultifileProperty => {
self.multifile_property();
}
REPLCodePtr::DiscontiguousProperty => {
self.discontiguous_property();
}
REPLCodePtr::DynamicProperty => {
self.dynamic_property();
}
REPLCodePtr::CompilePendingPredicates => {
self.compile_pending_predicates();
}