delay premature set_switch_var_offset_* calls in retract_clause, add module resolution for asserta/assertz/retract/clause
This commit is contained in:
@@ -358,11 +358,11 @@ impl SystemClauseType {
|
|||||||
clause_name!("$load_compiled_library"),
|
clause_name!("$load_compiled_library"),
|
||||||
&SystemClauseType::REPL(REPLCodePtr::PushLoadStatePayload) =>
|
&SystemClauseType::REPL(REPLCodePtr::PushLoadStatePayload) =>
|
||||||
clause_name!("$push_load_state_payload"),
|
clause_name!("$push_load_state_payload"),
|
||||||
&SystemClauseType::REPL(REPLCodePtr::UserAsserta) =>
|
&SystemClauseType::REPL(REPLCodePtr::Asserta) =>
|
||||||
clause_name!("$asserta"),
|
clause_name!("$asserta"),
|
||||||
&SystemClauseType::REPL(REPLCodePtr::UserAssertz) =>
|
&SystemClauseType::REPL(REPLCodePtr::Assertz) =>
|
||||||
clause_name!("$assertz"),
|
clause_name!("$assertz"),
|
||||||
&SystemClauseType::REPL(REPLCodePtr::UserRetract) =>
|
&SystemClauseType::REPL(REPLCodePtr::Retract) =>
|
||||||
clause_name!("$retract_clause"),
|
clause_name!("$retract_clause"),
|
||||||
&SystemClauseType::REPL(REPLCodePtr::UseModule) =>
|
&SystemClauseType::REPL(REPLCodePtr::UseModule) =>
|
||||||
clause_name!("$use_module"),
|
clause_name!("$use_module"),
|
||||||
@@ -568,14 +568,11 @@ impl SystemClauseType {
|
|||||||
Some(SystemClauseType::REPL(REPLCodePtr::AddGoalExpansionClause)),
|
Some(SystemClauseType::REPL(REPLCodePtr::AddGoalExpansionClause)),
|
||||||
("$add_term_expansion_clause", 3) =>
|
("$add_term_expansion_clause", 3) =>
|
||||||
Some(SystemClauseType::REPL(REPLCodePtr::AddTermExpansionClause)),
|
Some(SystemClauseType::REPL(REPLCodePtr::AddTermExpansionClause)),
|
||||||
// ("$at_end_of_expansion", 0) => Some(SystemClauseType::AtEndOfExpansion),
|
|
||||||
("$atom_chars", 2) => Some(SystemClauseType::AtomChars),
|
("$atom_chars", 2) => Some(SystemClauseType::AtomChars),
|
||||||
("$atom_codes", 2) => Some(SystemClauseType::AtomCodes),
|
("$atom_codes", 2) => Some(SystemClauseType::AtomCodes),
|
||||||
("$atom_length", 2) => Some(SystemClauseType::AtomLength),
|
("$atom_length", 2) => Some(SystemClauseType::AtomLength),
|
||||||
// ("$abolish_module_clause", 3) => Some(SystemClauseType::AbolishModuleClause),
|
// ("$abolish_module_clause", 3) => Some(SystemClauseType::AbolishModuleClause),
|
||||||
("$bind_from_register", 2) => Some(SystemClauseType::BindFromRegister),
|
("$bind_from_register", 2) => Some(SystemClauseType::BindFromRegister),
|
||||||
// ("$module_asserta", 5) => Some(SystemClauseType::ModuleAssertDynamicPredicateToFront),
|
|
||||||
// ("$module_assertz", 5) => Some(SystemClauseType::ModuleAssertDynamicPredicateToBack),
|
|
||||||
("$call_continuation", 1) => Some(SystemClauseType::CallContinuation),
|
("$call_continuation", 1) => Some(SystemClauseType::CallContinuation),
|
||||||
("$char_code", 2) => Some(SystemClauseType::CharCode),
|
("$char_code", 2) => Some(SystemClauseType::CharCode),
|
||||||
("$char_type", 2) => Some(SystemClauseType::CharType),
|
("$char_type", 2) => Some(SystemClauseType::CharType),
|
||||||
@@ -608,8 +605,6 @@ impl SystemClauseType {
|
|||||||
("$peek_char", 2) => Some(SystemClauseType::PeekChar),
|
("$peek_char", 2) => Some(SystemClauseType::PeekChar),
|
||||||
("$peek_code", 2) => Some(SystemClauseType::PeekCode),
|
("$peek_code", 2) => Some(SystemClauseType::PeekCode),
|
||||||
("$is_partial_string", 1) => Some(SystemClauseType::IsPartialString),
|
("$is_partial_string", 1) => Some(SystemClauseType::IsPartialString),
|
||||||
// ("$expand_term", 2) => Some(SystemClauseType::ExpandTerm),
|
|
||||||
// ("$expand_goal", 2) => Some(SystemClauseType::ExpandGoal),
|
|
||||||
("$fetch_global_var", 2) => Some(SystemClauseType::FetchGlobalVar),
|
("$fetch_global_var", 2) => Some(SystemClauseType::FetchGlobalVar),
|
||||||
("$fetch_global_var_with_offset", 3) => Some(SystemClauseType::FetchGlobalVarWithOffset),
|
("$fetch_global_var_with_offset", 3) => Some(SystemClauseType::FetchGlobalVarWithOffset),
|
||||||
("$get_byte", 2) => Some(SystemClauseType::GetByte),
|
("$get_byte", 2) => Some(SystemClauseType::GetByte),
|
||||||
@@ -641,8 +636,6 @@ impl SystemClauseType {
|
|||||||
}
|
}
|
||||||
("$get_attr_list", 2) => Some(SystemClauseType::GetAttributedVariableList),
|
("$get_attr_list", 2) => Some(SystemClauseType::GetAttributedVariableList),
|
||||||
("$get_b_value", 1) => Some(SystemClauseType::GetBValue),
|
("$get_b_value", 1) => Some(SystemClauseType::GetBValue),
|
||||||
// ("$get_clause", 2) => Some(SystemClauseType::GetClause),
|
|
||||||
// ("$get_module_clause", 3) => Some(SystemClauseType::GetModuleClause),
|
|
||||||
("$get_lh_from_offset", 2) => Some(SystemClauseType::GetLiftedHeapFromOffset),
|
("$get_lh_from_offset", 2) => Some(SystemClauseType::GetLiftedHeapFromOffset),
|
||||||
("$get_lh_from_offset_diff", 3) => Some(SystemClauseType::GetLiftedHeapFromOffsetDiff),
|
("$get_lh_from_offset_diff", 3) => Some(SystemClauseType::GetLiftedHeapFromOffsetDiff),
|
||||||
("$get_double_quotes", 1) => Some(SystemClauseType::GetDoubleQuotes),
|
("$get_double_quotes", 1) => Some(SystemClauseType::GetDoubleQuotes),
|
||||||
@@ -656,8 +649,6 @@ impl SystemClauseType {
|
|||||||
("$cpu_now", 1) => Some(SystemClauseType::CpuNow),
|
("$cpu_now", 1) => Some(SystemClauseType::CpuNow),
|
||||||
("$current_time", 1) => Some(SystemClauseType::CurrentTime),
|
("$current_time", 1) => Some(SystemClauseType::CurrentTime),
|
||||||
("$module_exists", 1) => Some(SystemClauseType::ModuleExists),
|
("$module_exists", 1) => Some(SystemClauseType::ModuleExists),
|
||||||
// ("$module_retract_clause", 5) => Some(SystemClauseType::ModuleRetractClause),
|
|
||||||
// ("$module_head_is_dynamic", 2) => Some(SystemClauseType::ModuleHeadIsDynamic),
|
|
||||||
("$no_such_predicate", 2) => Some(SystemClauseType::NoSuchPredicate),
|
("$no_such_predicate", 2) => Some(SystemClauseType::NoSuchPredicate),
|
||||||
("$number_to_chars", 2) => Some(SystemClauseType::NumberToChars),
|
("$number_to_chars", 2) => Some(SystemClauseType::NumberToChars),
|
||||||
("$number_to_codes", 2) => Some(SystemClauseType::NumberToCodes),
|
("$number_to_codes", 2) => Some(SystemClauseType::NumberToCodes),
|
||||||
@@ -692,7 +683,6 @@ impl SystemClauseType {
|
|||||||
("$reset_cont_marker", 0) => Some(SystemClauseType::ResetContinuationMarker),
|
("$reset_cont_marker", 0) => Some(SystemClauseType::ResetContinuationMarker),
|
||||||
("$reset_global_var_at_key", 1) => Some(SystemClauseType::ResetGlobalVarAtKey),
|
("$reset_global_var_at_key", 1) => Some(SystemClauseType::ResetGlobalVarAtKey),
|
||||||
("$reset_global_var_at_offset", 3) => Some(SystemClauseType::ResetGlobalVarAtOffset),
|
("$reset_global_var_at_offset", 3) => Some(SystemClauseType::ResetGlobalVarAtOffset),
|
||||||
// ("$retract_clause", 4) => Some(SystemClauseType::RetractClause),
|
|
||||||
("$return_from_verify_attr", 0) => Some(SystemClauseType::ReturnFromVerifyAttr),
|
("$return_from_verify_attr", 0) => Some(SystemClauseType::ReturnFromVerifyAttr),
|
||||||
("$set_ball", 1) => Some(SystemClauseType::SetBall),
|
("$set_ball", 1) => Some(SystemClauseType::SetBall),
|
||||||
("$set_cp_by_default", 1) => Some(SystemClauseType::SetCutPointByDefault(temp_v!(1))),
|
("$set_cp_by_default", 1) => Some(SystemClauseType::SetCutPointByDefault(temp_v!(1))),
|
||||||
@@ -728,9 +718,9 @@ impl SystemClauseType {
|
|||||||
("$declare_module", 3) => Some(SystemClauseType::REPL(REPLCodePtr::DeclareModule)),
|
("$declare_module", 3) => Some(SystemClauseType::REPL(REPLCodePtr::DeclareModule)),
|
||||||
("$load_compiled_library", 2) => Some(SystemClauseType::REPL(REPLCodePtr::LoadCompiledLibrary)),
|
("$load_compiled_library", 2) => Some(SystemClauseType::REPL(REPLCodePtr::LoadCompiledLibrary)),
|
||||||
("$push_load_state_payload", 1) => Some(SystemClauseType::REPL(REPLCodePtr::PushLoadStatePayload)),
|
("$push_load_state_payload", 1) => Some(SystemClauseType::REPL(REPLCodePtr::PushLoadStatePayload)),
|
||||||
("$asserta", 4) => Some(SystemClauseType::REPL(REPLCodePtr::UserAsserta)),
|
("$asserta", 5) => Some(SystemClauseType::REPL(REPLCodePtr::Asserta)),
|
||||||
("$assertz", 4) => Some(SystemClauseType::REPL(REPLCodePtr::UserAssertz)),
|
("$assertz", 5) => Some(SystemClauseType::REPL(REPLCodePtr::Assertz)),
|
||||||
("$retract_clause", 3) => Some(SystemClauseType::REPL(REPLCodePtr::UserRetract)),
|
("$retract_clause", 4) => Some(SystemClauseType::REPL(REPLCodePtr::Retract)),
|
||||||
("$variant", 2) => Some(SystemClauseType::Variant),
|
("$variant", 2) => Some(SystemClauseType::Variant),
|
||||||
("$wam_instructions", 4) => Some(SystemClauseType::WAMInstructions),
|
("$wam_instructions", 4) => Some(SystemClauseType::WAMInstructions),
|
||||||
("$write_term", 7) => Some(SystemClauseType::WriteTerm),
|
("$write_term", 7) => Some(SystemClauseType::WriteTerm),
|
||||||
|
|||||||
@@ -742,13 +742,16 @@ setof(Template, Goal, Solution) :-
|
|||||||
).
|
).
|
||||||
|
|
||||||
'$module_clause'(H, B, Module) :-
|
'$module_clause'(H, B, Module) :-
|
||||||
( var(H) -> throw(error(instantiation_error, clause/2))
|
( var(H) ->
|
||||||
|
throw(error(instantiation_error, clause/2))
|
||||||
; functor(H, Name, Arity) ->
|
; functor(H, Name, Arity) ->
|
||||||
( Name == '.' ->
|
( Name == '.' ->
|
||||||
throw(error(type_error(callable, H), clause/2))
|
throw(error(type_error(callable, H), clause/2))
|
||||||
|
; '$no_such_predicate'(Module, H) ->
|
||||||
|
'$fail'
|
||||||
; '$head_is_dynamic'(Module, H) ->
|
; '$head_is_dynamic'(Module, H) ->
|
||||||
'$clause_body_is_valid'(B),
|
'$clause_body_is_valid'(B),
|
||||||
Module:'$clause'(H, B) %%TODO: how do we show this exists?
|
Module:'$clause'(H, B)
|
||||||
; throw(error(permission_error(access, private_procedure, Name/Arity),
|
; throw(error(permission_error(access, private_procedure, Name/Arity),
|
||||||
clause/2))
|
clause/2))
|
||||||
)
|
)
|
||||||
@@ -781,24 +784,19 @@ clause(H, B) :-
|
|||||||
; throw(error(type_error(callable, H), clause/2))
|
; throw(error(type_error(callable, H), clause/2))
|
||||||
).
|
).
|
||||||
|
|
||||||
call_module_asserta(Head, Body, Name, Arity, Module) :-
|
call_asserta(Head, Body, Name, Arity, Module) :-
|
||||||
'$clause_body_is_valid'(Body),
|
'$clause_body_is_valid'(Body),
|
||||||
functor(VarHead, Name, Arity),
|
functor(_, Name, Arity),
|
||||||
findall((VarHead :- VarBody), builtins:clause(Module:VarHead, VarBody), Clauses),
|
'$asserta'(Head, Body, Name, Arity, Module).
|
||||||
'$module_asserta'((Head :- Body), Clauses, Name, Arity, Module).
|
|
||||||
|
|
||||||
call_asserta(Head, Body, Name, Arity) :-
|
|
||||||
'$clause_body_is_valid'(Body),
|
|
||||||
functor(VarHead, Name, Arity),
|
|
||||||
'$asserta'(Head, Body, Name, Arity).
|
|
||||||
|
|
||||||
module_asserta_clause(Head, Body, Module) :-
|
module_asserta_clause(Head, Body, Module) :-
|
||||||
( var(Head) -> throw(error(instantiation_error, asserta/1))
|
( var(Head) ->
|
||||||
|
throw(error(instantiation_error, asserta/1))
|
||||||
; functor(Head, Name, Arity),
|
; functor(Head, Name, Arity),
|
||||||
atom(Name),
|
atom(Name),
|
||||||
Name \== '.' ->
|
Name \== '.' ->
|
||||||
( '$module_head_is_dynamic'(Head, Module) ->
|
( '$head_is_dynamic'(Module, Head) ->
|
||||||
call_module_asserta(Head, Body, Name, Arity, Module)
|
call_asserta(Head, Body, Name, Arity, Module)
|
||||||
; throw(error(permission_error(modify, static_procedure, Name/Arity), asserta/1))
|
; throw(error(permission_error(modify, static_procedure, Name/Arity), asserta/1))
|
||||||
)
|
)
|
||||||
; throw(error(type_error(callable, Head), asserta/1))
|
; throw(error(type_error(callable, Head), asserta/1))
|
||||||
@@ -815,9 +813,9 @@ asserta_clause(Head, Body) :-
|
|||||||
arg(2, Head, F),
|
arg(2, Head, F),
|
||||||
module_asserta_clause(F, Body, Module)
|
module_asserta_clause(F, Body, Module)
|
||||||
; '$no_such_predicate'(user, Head) ->
|
; '$no_such_predicate'(user, Head) ->
|
||||||
call_asserta(Head, Body, Name, Arity)
|
call_asserta(Head, Body, Name, Arity, user)
|
||||||
; '$head_is_dynamic'(user, Head) ->
|
; '$head_is_dynamic'(user, Head) ->
|
||||||
call_asserta(Head, Body, Name, Arity)
|
call_asserta(Head, Body, Name, Arity, user)
|
||||||
; throw(error(permission_error(modify, static_procedure, Name/Arity), asserta/1))
|
; throw(error(permission_error(modify, static_procedure, Name/Arity), asserta/1))
|
||||||
)
|
)
|
||||||
; throw(error(type_error(callable, Head), asserta/1))
|
; throw(error(type_error(callable, Head), asserta/1))
|
||||||
@@ -826,18 +824,12 @@ asserta_clause(Head, Body) :-
|
|||||||
asserta(Clause) :-
|
asserta(Clause) :-
|
||||||
( Clause \= (_ :- _) ->
|
( Clause \= (_ :- _) ->
|
||||||
Head = Clause,
|
Head = Clause,
|
||||||
Body = true, asserta_clause(Head, Body)
|
Body = true,
|
||||||
|
asserta_clause(Head, Body)
|
||||||
; Clause = (Head :- Body) ->
|
; Clause = (Head :- Body) ->
|
||||||
asserta_clause(Head, Body)
|
asserta_clause(Head, Body)
|
||||||
).
|
).
|
||||||
|
|
||||||
% NOT MODIFIED.
|
|
||||||
call_module_assertz(Head, Body, Name, Arity, Module) :-
|
|
||||||
'$clause_body_is_valid'(Body),
|
|
||||||
functor(VarHead, Name, Arity),
|
|
||||||
findall((VarHead :- VarBody), builtins:clause(Module:VarHead, VarBody), Clauses),
|
|
||||||
'$module_assertz'((Head :- Body), Clauses, Name, Arity, Module).
|
|
||||||
|
|
||||||
module_assertz_clause(Head, Body, Module) :-
|
module_assertz_clause(Head, Body, Module) :-
|
||||||
( var(Head) ->
|
( var(Head) ->
|
||||||
throw(error(instantiation_error, assertz/1))
|
throw(error(instantiation_error, assertz/1))
|
||||||
@@ -845,17 +837,18 @@ module_assertz_clause(Head, Body, Module) :-
|
|||||||
atom(Name),
|
atom(Name),
|
||||||
Name \== '.' ->
|
Name \== '.' ->
|
||||||
( '$head_is_dynamic'(Module, Head) ->
|
( '$head_is_dynamic'(Module, Head) ->
|
||||||
call_module_assertz(Head, Body, Name, Arity, Module)
|
call_assertz(Head, Body, Name, Arity, Module)
|
||||||
; throw(error(permission_error(modify, static_procedure, Name/Arity), assertz/1))
|
; throw(error(permission_error(modify, static_procedure, Name/Arity),
|
||||||
|
assertz/1))
|
||||||
)
|
)
|
||||||
; throw(error(type_error(callable, Head), assertz/1))
|
; throw(error(type_error(callable, Head), assertz/1))
|
||||||
).
|
).
|
||||||
|
|
||||||
% MODIFIED.
|
|
||||||
call_assertz(Head, Body, Name, Arity) :-
|
call_assertz(Head, Body, Name, Arity, Module) :-
|
||||||
'$clause_body_is_valid'(Body),
|
'$clause_body_is_valid'(Body),
|
||||||
functor(VarHead, Name, Arity),
|
functor(_, Name, Arity),
|
||||||
'$assertz'(Head, Body, Name, Arity).
|
'$assertz'(Head, Body, Name, Arity, Module).
|
||||||
|
|
||||||
assertz_clause(Head, Body) :-
|
assertz_clause(Head, Body) :-
|
||||||
( var(Head) ->
|
( var(Head) ->
|
||||||
@@ -869,10 +862,11 @@ assertz_clause(Head, Body) :-
|
|||||||
arg(2, Head, F),
|
arg(2, Head, F),
|
||||||
module_assertz_clause(F, Body, Module)
|
module_assertz_clause(F, Body, Module)
|
||||||
; '$no_such_predicate'(user, Head) ->
|
; '$no_such_predicate'(user, Head) ->
|
||||||
call_assertz(Head, Body, Name, Arity)
|
call_assertz(Head, Body, Name, Arity, user)
|
||||||
; '$head_is_dynamic'(user, Head) ->
|
; '$head_is_dynamic'(user, Head) ->
|
||||||
call_assertz(Head, Body, Name, Arity)
|
call_assertz(Head, Body, Name, Arity, user)
|
||||||
; throw(error(permission_error(modify, static_procedure, Name/Arity), assertz/1))
|
; throw(error(permission_error(modify, static_procedure, Name/Arity),
|
||||||
|
assertz/1))
|
||||||
)
|
)
|
||||||
; throw(error(type_error(callable, Head), assertz/1))
|
; throw(error(type_error(callable, Head), assertz/1))
|
||||||
).
|
).
|
||||||
@@ -889,18 +883,18 @@ assertz(Clause) :-
|
|||||||
|
|
||||||
module_retract_clauses([Clause|Clauses0], Head, Body, Name, Arity, Module) :-
|
module_retract_clauses([Clause|Clauses0], Head, Body, Name, Arity, Module) :-
|
||||||
functor(VarHead, Name, Arity),
|
functor(VarHead, Name, Arity),
|
||||||
findall((VarHead :- VarBody), builtins:clause(Module:VarHead, VarBody), Clauses1),
|
findall((VarHead :- VarBody), Module:clause(Module:VarHead, VarBody), Clauses1),
|
||||||
first_match_index(Clauses1, (Head :- Body), 0, N),
|
first_match_index(Clauses1, (Head :- Body), 0, N),
|
||||||
( Clauses0 == [] -> !
|
( Clauses0 == [] -> !
|
||||||
; true
|
; true
|
||||||
),
|
),
|
||||||
'$module_retract_clause'(Name, Arity, N, Clauses1, Module).
|
'$retract_clause'(Name, Arity, N, Module).
|
||||||
|
|
||||||
module_retract_clauses([_|Clauses0], Head, Body, Name, Arity, Module) :-
|
module_retract_clauses([_|Clauses0], Head, Body, Name, Arity, Module) :-
|
||||||
module_retract_clauses(Clauses0, Head, Body, Name, Arity, Module).
|
module_retract_clauses(Clauses0, Head, Body, Name, Arity, Module).
|
||||||
|
|
||||||
call_module_retract(Head, Body, Name, Arity, Module) :-
|
call_module_retract(Head, Body, Name, Arity, Module) :-
|
||||||
findall((Head :- Body), builtins:clause(Module:Head, Body), Clauses),
|
findall((Head :- Body), Module:clause(Module:Head, Body), Clauses),
|
||||||
module_retract_clauses(Clauses, Head, Body, Name, Arity, Module).
|
module_retract_clauses(Clauses, Head, Body, Name, Arity, Module).
|
||||||
|
|
||||||
retract_module_clause(Head, Body, Module) :-
|
retract_module_clause(Head, Body, Module) :-
|
||||||
@@ -909,7 +903,7 @@ retract_module_clause(Head, Body, Module) :-
|
|||||||
; functor(Head, Name, Arity),
|
; functor(Head, Name, Arity),
|
||||||
atom(Name),
|
atom(Name),
|
||||||
Name \== '.' ->
|
Name \== '.' ->
|
||||||
( '$module_head_is_dynamic'(Head, Module) ->
|
( '$head_is_dynamic'(Module, Head) ->
|
||||||
call_module_retract(Head, Body, Name, Arity, Module)
|
call_module_retract(Head, Body, Name, Arity, Module)
|
||||||
; throw(error(permission_error(modify, static_procedure, Name/Arity), retract/1))
|
; throw(error(permission_error(modify, static_procedure, Name/Arity), retract/1))
|
||||||
)
|
)
|
||||||
@@ -932,7 +926,7 @@ retract_clauses([Clause | Clauses0], Head, Body, Name, Arity) :-
|
|||||||
( Clauses0 == [] -> !
|
( Clauses0 == [] -> !
|
||||||
; true
|
; true
|
||||||
),
|
),
|
||||||
'$retract_clause'(Name, Arity, N).
|
'$retract_clause'(Name, Arity, N, user).
|
||||||
|
|
||||||
retract_clauses([_ | Clauses0], Head, Body, Name, Arity) :-
|
retract_clauses([_ | Clauses0], Head, Body, Name, Arity) :-
|
||||||
retract_clauses(Clauses0, Head, Body, Name, Arity).
|
retract_clauses(Clauses0, Head, Body, Name, Arity).
|
||||||
|
|||||||
@@ -1448,13 +1448,6 @@ impl<'a> LoadState<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set_switch_var_offset(
|
|
||||||
code,
|
|
||||||
later_indexing_loc,
|
|
||||||
lower_bound_clause_start - later_indexing_loc,
|
|
||||||
&mut self.retraction_info,
|
|
||||||
);
|
|
||||||
|
|
||||||
result = merge_indexed_subsequences(
|
result = merge_indexed_subsequences(
|
||||||
code,
|
code,
|
||||||
skeleton,
|
skeleton,
|
||||||
@@ -1470,15 +1463,15 @@ impl<'a> LoadState<'a> {
|
|||||||
&mut skeleton.clauses[lower_bound ..],
|
&mut skeleton.clauses[lower_bound ..],
|
||||||
&mut self.retraction_info,
|
&mut self.retraction_info,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
_ => {
|
set_switch_var_offset(
|
||||||
set_switch_var_offset_to_choice_instr(
|
|
||||||
code,
|
code,
|
||||||
target_indexing_loc,
|
later_indexing_loc,
|
||||||
lower_bound_clause_start - target_indexing_loc,
|
lower_bound_clause_start - later_indexing_loc,
|
||||||
&mut self.retraction_info,
|
&mut self.retraction_info,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
result = merge_indexed_subsequences(
|
result = merge_indexed_subsequences(
|
||||||
code,
|
code,
|
||||||
skeleton,
|
skeleton,
|
||||||
@@ -1494,6 +1487,13 @@ impl<'a> LoadState<'a> {
|
|||||||
&mut skeleton.clauses[lower_bound ..],
|
&mut skeleton.clauses[lower_bound ..],
|
||||||
&mut self.retraction_info,
|
&mut self.retraction_info,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
set_switch_var_offset_to_choice_instr(
|
||||||
|
code,
|
||||||
|
target_indexing_loc,
|
||||||
|
lower_bound_clause_start - target_indexing_loc,
|
||||||
|
&mut self.retraction_info,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1581,6 +1581,7 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
|||||||
fn compile_clause_clauses<ClauseIter: Iterator<Item=(Term, Term)>>(
|
fn compile_clause_clauses<ClauseIter: Iterator<Item=(Term, Term)>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
key: PredicateKey,
|
key: PredicateKey,
|
||||||
|
compilation_target: CompilationTarget,
|
||||||
clause_clauses: ClauseIter,
|
clause_clauses: ClauseIter,
|
||||||
append_or_prepend: AppendOrPrepend,
|
append_or_prepend: AppendOrPrepend,
|
||||||
) -> Result<(), SessionError> {
|
) -> Result<(), SessionError> {
|
||||||
@@ -1596,9 +1597,19 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let compilation_target = mem::replace(
|
let clause_clause_compilation_target =
|
||||||
|
match compilation_target {
|
||||||
|
CompilationTarget::User => {
|
||||||
|
CompilationTarget::Module(clause_name!("builtins"))
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
compilation_target.clone()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let old_compilation_target = mem::replace(
|
||||||
&mut self.load_state.compilation_target,
|
&mut self.load_state.compilation_target,
|
||||||
CompilationTarget::Module(clause_name!("builtins")),
|
clause_clause_compilation_target,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut clause_clause_locs = sdeq![];
|
let mut clause_clause_locs = sdeq![];
|
||||||
@@ -1615,7 +1626,7 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
self.load_state.compilation_target = compilation_target;
|
self.load_state.compilation_target = old_compilation_target;
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1676,7 +1687,7 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.load_state.compilation_target = compilation_target;
|
self.load_state.compilation_target = old_compilation_target;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1704,7 +1715,14 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
|||||||
|
|
||||||
if is_dynamic {
|
if is_dynamic {
|
||||||
let iter = mem::replace(&mut self.clause_clauses, vec![]).into_iter();
|
let iter = mem::replace(&mut self.clause_clauses, vec![]).into_iter();
|
||||||
self.compile_clause_clauses(key, iter, AppendOrPrepend::Append)?;
|
let compilation_target = self.load_state.compilation_target.clone();
|
||||||
|
|
||||||
|
self.compile_clause_clauses(
|
||||||
|
key,
|
||||||
|
compilation_target,
|
||||||
|
iter,
|
||||||
|
AppendOrPrepend::Append,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(self.predicates.clear())
|
Ok(self.predicates.clear())
|
||||||
|
|||||||
@@ -1360,14 +1360,26 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate)
|
pub(crate)
|
||||||
fn compile_user_assert(&mut self, append_or_prepend: AppendOrPrepend) {
|
fn compile_assert(&mut self, append_or_prepend: AppendOrPrepend) {
|
||||||
let key =
|
let key = self.machine_st.read_predicate_key(
|
||||||
self.machine_st.read_predicate_key(
|
|
||||||
self.machine_st[temp_v!(3)],
|
self.machine_st[temp_v!(3)],
|
||||||
self.machine_st[temp_v!(4)],
|
self.machine_st[temp_v!(4)],
|
||||||
);
|
);
|
||||||
|
|
||||||
let compile_user_assert = || {
|
let module_name = atom_from!(
|
||||||
|
self.machine_st,
|
||||||
|
self.machine_st.store(self.machine_st.deref(
|
||||||
|
self.machine_st[temp_v!(5)]
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
let compilation_target =
|
||||||
|
match module_name.as_str() {
|
||||||
|
"user" => CompilationTarget::User,
|
||||||
|
_ => CompilationTarget::Module(module_name),
|
||||||
|
};
|
||||||
|
|
||||||
|
let compile_assert = || {
|
||||||
let mut loader = Loader::new(LiveTermStream::new(ListingSource::User), self);
|
let mut loader = Loader::new(LiveTermStream::new(ListingSource::User), self);
|
||||||
|
|
||||||
let head = loader.read_term_from_heap(temp_v!(1))?;
|
let head = loader.read_term_from_heap(temp_v!(1))?;
|
||||||
@@ -1384,23 +1396,28 @@ impl Machine {
|
|||||||
loader.incremental_compile_clause(
|
loader.incremental_compile_clause(
|
||||||
key.clone(),
|
key.clone(),
|
||||||
asserted_clause,
|
asserted_clause,
|
||||||
CompilationTarget::User,
|
compilation_target.clone(),
|
||||||
false,
|
false,
|
||||||
append_or_prepend,
|
append_or_prepend,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// if a new predicate was just created, make it dynamic.
|
// if a new predicate was just created, make it dynamic.
|
||||||
loader.load_state.wam.indices.get_predicate_skeleton(
|
loader.load_state.wam.indices.get_predicate_skeleton(
|
||||||
&loader.load_state.compilation_target,
|
&compilation_target,
|
||||||
&key,
|
&key,
|
||||||
).map(|skeleton| skeleton.is_dynamic = true);
|
).map(|skeleton| skeleton.is_dynamic = true);
|
||||||
|
|
||||||
loader.compile_clause_clauses(key, std::iter::once((head, body)), append_or_prepend)?;
|
loader.compile_clause_clauses(
|
||||||
|
key,
|
||||||
|
compilation_target,
|
||||||
|
std::iter::once((head, body)),
|
||||||
|
append_or_prepend,
|
||||||
|
)?;
|
||||||
|
|
||||||
LiveTermStream::evacuate(loader)
|
LiveTermStream::evacuate(loader)
|
||||||
};
|
};
|
||||||
|
|
||||||
match compile_user_assert() {
|
match compile_assert() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -1416,7 +1433,7 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate)
|
pub(crate)
|
||||||
fn retract_user_clause(&mut self) {
|
fn retract_clause(&mut self) {
|
||||||
let key =
|
let key =
|
||||||
self.machine_st.read_predicate_key(
|
self.machine_st.read_predicate_key(
|
||||||
self.machine_st[temp_v!(1)],
|
self.machine_st[temp_v!(1)],
|
||||||
@@ -1436,18 +1453,44 @@ impl Machine {
|
|||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
let retract_user_clause = || {
|
let module_name = atom_from!(
|
||||||
|
self.machine_st,
|
||||||
|
self.machine_st.store(self.machine_st.deref(
|
||||||
|
self.machine_st[temp_v!(4)]
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
let compilation_target =
|
||||||
|
match module_name.as_str() {
|
||||||
|
"user" => CompilationTarget::User,
|
||||||
|
_ => CompilationTarget::Module(module_name),
|
||||||
|
};
|
||||||
|
|
||||||
|
let clause_clause_compilation_target =
|
||||||
|
match &compilation_target {
|
||||||
|
CompilationTarget::User => {
|
||||||
|
CompilationTarget::Module(clause_name!("builtins"))
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
compilation_target.clone()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let retract_clause = || {
|
||||||
let mut loader = Loader::new(LiveTermStream::new(ListingSource::User), self);
|
let mut loader = Loader::new(LiveTermStream::new(ListingSource::User), self);
|
||||||
|
loader.load_state.compilation_target = compilation_target;
|
||||||
|
|
||||||
let clause_clause_loc = loader.load_state.retract_clause(key, target_pos);
|
let clause_clause_loc = loader.load_state.retract_clause(key, target_pos);
|
||||||
|
|
||||||
let clause_assert_margin =
|
let clause_assert_margin =
|
||||||
loader.load_state.wam.indices.modules.get(&clause_name!("builtins"))
|
loader.load_state.wam.indices.modules
|
||||||
.map(|builtins| builtins.clause_assert_margin)
|
.get(&clause_clause_compilation_target.module_name())
|
||||||
|
.map(|module| module.clause_assert_margin)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let target_pos =
|
let target_pos =
|
||||||
match loader.load_state.wam.indices.get_predicate_skeleton(
|
match loader.load_state.wam.indices.get_predicate_skeleton(
|
||||||
&CompilationTarget::Module(clause_name!("builtins")),
|
&clause_clause_compilation_target,
|
||||||
&(clause_name!("$clause"), 2),
|
&(clause_name!("$clause"), 2),
|
||||||
) {
|
) {
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
@@ -1463,8 +1506,9 @@ impl Machine {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if result < clause_assert_margin {
|
if result < clause_assert_margin {
|
||||||
loader.load_state.wam.indices.modules.get_mut(&clause_name!("builtins"))
|
loader.load_state.wam.indices.modules
|
||||||
.map(|builtins| builtins.clause_assert_margin -= 1);
|
.get_mut(&clause_clause_compilation_target.module_name())
|
||||||
|
.map(|module| module.clause_assert_margin -= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
@@ -1474,19 +1518,13 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
loader.load_state.compilation_target = clause_clause_compilation_target;
|
||||||
let compilation_target = mem::replace(
|
|
||||||
&mut loader.load_state.compilation_target,
|
|
||||||
CompilationTarget::Module(clause_name!("builtins")),
|
|
||||||
);
|
|
||||||
|
|
||||||
loader.load_state.retract_clause((clause_name!("$clause"), 2), target_pos);
|
loader.load_state.retract_clause((clause_name!("$clause"), 2), target_pos);
|
||||||
loader.load_state.compilation_target = compilation_target;
|
|
||||||
|
|
||||||
LiveTermStream::evacuate(loader)
|
LiveTermStream::evacuate(loader)
|
||||||
};
|
};
|
||||||
|
|
||||||
match retract_user_clause() {
|
match retract_clause() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
@@ -525,9 +525,9 @@ pub enum REPLCodePtr {
|
|||||||
DiscontiguousProperty,
|
DiscontiguousProperty,
|
||||||
DynamicProperty,
|
DynamicProperty,
|
||||||
CompilePendingPredicates,
|
CompilePendingPredicates,
|
||||||
UserAsserta,
|
Asserta,
|
||||||
UserAssertz,
|
Assertz,
|
||||||
UserRetract,
|
Retract,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
|||||||
@@ -494,14 +494,14 @@ impl Machine {
|
|||||||
REPLCodePtr::CompilePendingPredicates => {
|
REPLCodePtr::CompilePendingPredicates => {
|
||||||
self.compile_pending_predicates();
|
self.compile_pending_predicates();
|
||||||
}
|
}
|
||||||
REPLCodePtr::UserAssertz => {
|
REPLCodePtr::Assertz => {
|
||||||
self.compile_user_assert(AppendOrPrepend::Append);
|
self.compile_assert(AppendOrPrepend::Append);
|
||||||
}
|
}
|
||||||
REPLCodePtr::UserAsserta => {
|
REPLCodePtr::Asserta => {
|
||||||
self.compile_user_assert(AppendOrPrepend::Prepend);
|
self.compile_assert(AppendOrPrepend::Prepend);
|
||||||
}
|
}
|
||||||
REPLCodePtr::UserRetract => {
|
REPLCodePtr::Retract => {
|
||||||
self.retract_user_clause();
|
self.retract_clause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,15 +14,15 @@
|
|||||||
'$repl'([_|Args0]) :-
|
'$repl'([_|Args0]) :-
|
||||||
\+ argv(_),
|
\+ argv(_),
|
||||||
( append(Args1, ["--"|Args2], Args0) ->
|
( append(Args1, ["--"|Args2], Args0) ->
|
||||||
asserta(argv(Args2)),
|
asserta('$toplevel':argv(Args2)),
|
||||||
Args = Args1
|
Args = Args1
|
||||||
; asserta(argv([])),
|
; asserta('$toplevel':argv([])),
|
||||||
Args = Args0
|
Args = Args0
|
||||||
),
|
),
|
||||||
delegate_task(Args, []),
|
delegate_task(Args, []),
|
||||||
repl.
|
repl.
|
||||||
'$repl'(_) :-
|
'$repl'(_) :-
|
||||||
( \+ argv(_) -> asserta(argv([]))
|
( \+ argv(_) -> asserta('$toplevel':argv([]))
|
||||||
; true
|
; true
|
||||||
),
|
),
|
||||||
repl.
|
repl.
|
||||||
|
|||||||
12
src/write.rs
12
src/write.rs
@@ -26,12 +26,12 @@ impl fmt::Display for REPLCodePtr {
|
|||||||
write!(f, "REPLCodePtr::AddGoalExpansionClause"),
|
write!(f, "REPLCodePtr::AddGoalExpansionClause"),
|
||||||
REPLCodePtr::AddTermExpansionClause =>
|
REPLCodePtr::AddTermExpansionClause =>
|
||||||
write!(f, "REPLCodePtr::AddTermExpansionClause"),
|
write!(f, "REPLCodePtr::AddTermExpansionClause"),
|
||||||
REPLCodePtr::UserAssertz =>
|
REPLCodePtr::Assertz =>
|
||||||
write!(f, "REPLCodePtr::UserAssertz"),
|
write!(f, "REPLCodePtr::Assertz"),
|
||||||
REPLCodePtr::UserAsserta =>
|
REPLCodePtr::Asserta =>
|
||||||
write!(f, "REPLCodePtr::UserAsserta"),
|
write!(f, "REPLCodePtr::Asserta"),
|
||||||
REPLCodePtr::UserRetract =>
|
REPLCodePtr::Retract =>
|
||||||
write!(f, "REPLCodePtr::UserRetract"),
|
write!(f, "REPLCodePtr::Retract"),
|
||||||
REPLCodePtr::ClauseToEvacuable =>
|
REPLCodePtr::ClauseToEvacuable =>
|
||||||
write!(f, "REPLCodePtr::ClauseToEvacuable"),
|
write!(f, "REPLCodePtr::ClauseToEvacuable"),
|
||||||
REPLCodePtr::ConcludeLoad =>
|
REPLCodePtr::ConcludeLoad =>
|
||||||
|
|||||||
Reference in New Issue
Block a user