add built_in to predicate_property

This commit is contained in:
Mark Thom
2021-02-02 15:03:14 -07:00
parent 814c034683
commit 8900df6f13
7 changed files with 60 additions and 9 deletions

View File

@@ -398,6 +398,8 @@ impl SystemClauseType {
clause_name!("$prolog_lc_stream"),
&SystemClauseType::REPL(REPLCodePtr::MetaPredicateProperty) =>
clause_name!("$cpp_meta_predicate_property"),
&SystemClauseType::REPL(REPLCodePtr::BuiltInProperty) =>
clause_name!("$cpp_built_in_property"),
&SystemClauseType::REPL(REPLCodePtr::CompilePendingPredicates) =>
clause_name!("$compile_pending_predicates"),
&SystemClauseType::Close => clause_name!("$close"),
@@ -770,6 +772,7 @@ impl SystemClauseType {
("$prolog_lc_module", 1) => Some(SystemClauseType::REPL(REPLCodePtr::LoadContextModule)),
("$prolog_lc_stream", 1) => Some(SystemClauseType::REPL(REPLCodePtr::LoadContextStream)),
("$cpp_meta_predicate_property", 4) => Some(SystemClauseType::REPL(REPLCodePtr::MetaPredicateProperty)),
("$cpp_built_in_property", 2) => Some(SystemClauseType::REPL(REPLCodePtr::BuiltInProperty)),
("$compile_pending_predicates", 1) => Some(SystemClauseType::REPL(REPLCodePtr::CompilePendingPredicates)),
_ => None,
}

View File

@@ -16,11 +16,13 @@ phrase(GRBody, S0) :-
phrase(GRBody, S0, S) :-
( var(GRBody) -> throw(error(instantiation_error, phrase/3))
( var(GRBody) ->
throw(error(instantiation_error, phrase/3))
; strip_module(GRBody, _, GRBody0),
dcg_constr(GRBody0) ->
phrase_(GRBody0, S0, S)
; functor(GRBody, _, _) -> call(GRBody, S0, S)
; functor(GRBody, _, _) ->
call(GRBody, S0, S)
; throw(error(type_error(callable, GRBody), phrase/3))
).
@@ -49,6 +51,7 @@ phrase_(phrase(NonTerminal), S0, S) :-
phrase_([T|Ts], S0, S) :-
append([T|Ts], S, S0).
% The same version of the below two dcg_rule clauses, but with module scoping.
dcg_rule(( M:NonTerminal, Terminals --> GRBody ), ( M:Head :- Body )) :-
dcg_non_terminal(NonTerminal, S0, S, Head),

View File

@@ -112,7 +112,7 @@ load_loop(Stream, Evacuable) :-
).
inner_meta_specs((:), HeadArg, InnerHeadArgs, InnerMetaSpecs) :-
inner_meta_specs(0, HeadArg, InnerHeadArgs, InnerMetaSpecs) :-
!,
predicate_property(HeadArg, meta_predicate(InnerMetaSpecs)),
HeadArg =.. [_ | InnerHeadArgs].
@@ -334,9 +334,9 @@ use_module(Module, Exports, Evacuable) :-
check_predicate_property(meta_predicate, Module, Name, Arity, MetaPredicateTerm) :-
must_be(atom, Name),
must_be(integer, Arity),
'$cpp_meta_predicate_property'(Module, Name, Arity, MetaPredicateTerm).
check_predicate_property(built_in, _, Name, Arity, built_in) :-
'$cpp_built_in_property'(Name, Arity).
extract_predicate_property(Property, PropertyType) :-
@@ -355,7 +355,10 @@ predicate_property(Callable, Property) :-
check_predicate_property(PropertyType, Module, Name, Arity, Property)
; functor(Callable, Name, Arity),
extract_predicate_property(Property, PropertyType),
prolog_load_context(module, Module),
( prolog_load_context(module, Module) ->
true
; Module = user
),
check_predicate_property(PropertyType, Module, Name, Arity, Property)
).
@@ -392,15 +395,14 @@ expand_subgoal(UnexpandedGoals, MS, Module, ExpandedGoals, HeadVars) :-
expand_module_name(ESG0, M, ESG) :-
( var(ESG0) ->
ESG = M:ESG0
; ESG0 = _:ESG1 ->
; ESG0 = _:_ ->
ESG = ESG0
; ESG = M:ESG0
).
expand_meta_predicate_subgoals([SG | SGs], [MS | MSs], M, [ESG | ESGs], HeadVars) :-
( ( MS == (:)
; integer(MS),
( ( integer(MS),
MS >= 0
) ->
( var(SG),

View File

@@ -1530,6 +1530,43 @@ impl Machine {
}
}
pub(crate)
fn builtin_property(&mut self) {
let key =
self.machine_st.read_predicate_key(
self.machine_st[temp_v!(1)],
self.machine_st[temp_v!(2)],
);
match ClauseType::from(key.0, key.1, None) {
ClauseType::BuiltIn(_) | ClauseType::Inlined(..) | ClauseType::CallN => {
return;
}
ClauseType::Named(ref name, arity, _) => {
if let Some(module) = self.indices.modules.get(&(clause_name!("builtins"))) {
self.machine_st.fail = !module.code_dir.contains_key(
&(name.clone(), arity),
);
return;
}
}
ClauseType::Op(ref name, ref op_desc, _) => {
if let Some(module) = self.indices.modules.get(&(clause_name!("builtins"))) {
self.machine_st.fail = !module.code_dir.contains_key(
&(name.clone(), op_desc.arity()),
);
return;
}
}
_ => {
}
}
self.machine_st.fail = true;
}
pub(crate)
fn compile_pending_predicates(&mut self) {
let (mut loader, evacuable_h) = self.loader_from_heap_evacuable(temp_v!(1));

View File

@@ -505,6 +505,7 @@ pub enum REPLCodePtr {
AddDynamicPredicate,
AddGoalExpansionClause,
AddTermExpansionClause,
BuiltInProperty,
ClauseToEvacuable,
ConcludeLoad,
DeclareModule,

View File

@@ -463,6 +463,9 @@ impl Machine {
REPLCodePtr::MetaPredicateProperty => {
self.meta_predicate_property();
}
REPLCodePtr::BuiltInProperty => {
self.builtin_property();
}
REPLCodePtr::CompilePendingPredicates => {
self.compile_pending_predicates();
}

View File

@@ -26,6 +26,8 @@ impl fmt::Display for REPLCodePtr {
write!(f, "REPLCodePtr::AddGoalExpansionClause"),
REPLCodePtr::AddTermExpansionClause =>
write!(f, "REPLCodePtr::AddTermExpansionClause"),
REPLCodePtr::BuiltInProperty =>
write!(f, "REPLCodePtr::BuiltInProperty"),
REPLCodePtr::UserAssertz =>
write!(f, "REPLCodePtr::UserAssertz"),
REPLCodePtr::UserAsserta =>