Skip to content

Commit

Permalink
(core) moved native/2 and regtype/2 info to p_unit_db
Browse files Browse the repository at this point in the history
Src-commit: 9d7e822b655e3c5fff44e733e47573aca97ab060
  • Loading branch information
jfmc committed Aug 2, 2024
1 parent b98e56b commit 9b4f18b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
24 changes: 9 additions & 15 deletions core/lib/compiler/p_unit/p_unit.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1331,9 +1331,7 @@
retractall_fact(pl_output_op(_, _, _)),
retractall_fact(pl_output_package(_)),
%
retractall_fact(internal_pred_name(_,_,_)),
retractall_fact(p_unit:native(_,_)),
retractall_fact(regtype(_,_)). % local data
retractall_fact(internal_pred_name(_,_,_)).

% assert_curr_files([],[]).
% assert_curr_files([A|As],[M|Ms]):-
Expand Down Expand Up @@ -1714,11 +1712,7 @@

:- use_module(library(compiler/p_unit/unexpand), [unexpand_meta_calls/2]).

:- redefining(native/2). % also in basic_props % TODO: rename?
:- data native/2.
:- data regtype/2.

% Fill p_unit:native/2 and regtype/2 from assertions
% Fill pgm_native/2 and pgm_regtype/2 from assertions
init_props :-
% identify and assert native props (also fills pending init regtypes)
( % (failure-driven loop)
Expand Down Expand Up @@ -1749,7 +1743,7 @@
( % (failure-driven loop)
builtin(native(Goal,Prop),Native),
member(Native,Comp),
asserta_fact(p_unit:native(Goal,Prop)),
asserta_fact(pgm_native(Goal,Prop)),
fail
; true
),
Expand All @@ -1758,7 +1752,7 @@
member(Regtype,Comp),
\+ pending_init_regtype(Goal,_) ->
unexpand_meta_calls(Prop0,NProp0), % TODO: why? (JF)
asserta_fact(regtype(Goal,NProp0)),
asserta_fact(pgm_regtype(Goal,NProp0)),
assertz_fact(pending_init_regtype(Goal,NProp0))
; true
),
Expand All @@ -1767,7 +1761,7 @@

% Fill regtype definition
init_regtype(Head,NProp0) :-
%asserta_fact(regtype(Head,NProp0)),
%asserta_fact(pgm_regtype(Head,NProp0)),
%display(user_error, rt(Head,NProp0)), nl(user_error),
% TODO: equivalent to prop_to_native/2 in this case
( prop_to_native_(Head,NProp) -> true
Expand Down Expand Up @@ -1804,7 +1798,7 @@
prop_to_native(Prop,_NProp):-
var(Prop), !, throw(error(instantiation_error(Prop), prop_to_native/2)).
prop_to_native(Prop,NProp2):-
current_fact(regtype(Prop,NProp0)), !,
current_fact(pgm_regtype(Prop,NProp0)), !,
NProp2=regtype(NProp),
( prop_to_native_(Prop,NProp) -> true % TODO: why?
; NProp=NProp0
Expand All @@ -1814,7 +1808,7 @@

% TODO: Creates choicepoints. Intended?
prop_to_native_(Prop,NProp):-
current_fact(p_unit:native(Prop,NProp)).
current_fact(pgm_native(Prop,NProp)).
prop_to_native_(Prop,NProp):-
native_property(Prop,NProp). % builtin tables

Expand All @@ -1827,9 +1821,9 @@
native_to_prop(NProp2,Prop) :-
( NProp2 = regtype(NProp) -> RegType=yes ; NProp=NProp2, RegType=no ),
%
( current_fact(p_unit:native(Prop0,NProp)) -> Prop=Prop0 % TODO: bad indexing
( current_fact(pgm_native(Prop0,NProp)) -> Prop=Prop0 % TODO: bad indexing
; native_property(Prop0,NProp) -> Prop=Prop0 % builtin tables % TODO: bad indexing
; RegType=yes, current_fact(regtype(Prop0,NProp)) -> Prop=Prop0 % TODO: bad indexing
; RegType=yes, current_fact(pgm_regtype(Prop0,NProp)) -> Prop=Prop0 % TODO: bad indexing
; fail
).

Expand Down
11 changes: 10 additions & 1 deletion core/lib/compiler/p_unit/p_unit_db.pl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
:- export(impl_defines/2).
:- export(pgm_assertion_read/9).
:- export(pgm_prop_clause_read/7). % (for abolish_related_info/1)
:- export(pgm_native/2).
:- export(pgm_regtype/2).

:- data curr_module/1.
:- data curr_file/2.
Expand All @@ -84,6 +86,8 @@
:- data pgm_prop_clause_read/7.
:- data source_clause/3.
:- data locator/2.
:- data pgm_native/2.
:- data pgm_regtype/2.

% (libcache)
:- data lib_defines_module/2.
Expand All @@ -97,6 +101,8 @@
:- data lib_impl_defines/2.
:- data lib_assertion_read/9.
:- data lib_prop_clause_read/7.
:- data lib_native/2.
:- data lib_regtype/2.

% ---------------------------------------------------------------------------

Expand Down Expand Up @@ -129,7 +135,10 @@
:- doc(cleanup_assrt_db, "Cleanups the assrt database.").
cleanup_assrt_db :-
retractall_fact(pgm_assertion_read(_,_,_,_,_,_,_,_,_)),
retractall_fact(assertion_of(_,_,_,_,_,_,_,_,_)).
retractall_fact(assertion_of(_,_,_,_,_,_,_,_,_)),
% (extracted from assertions)
retractall_fact(pgm_native(_,_)),
retractall_fact(pgm_regtype(_,_)).

:- export(cleanup_clause_db/0). % TODO: needed for some clause rewrites
:- doc(cleanup_clause_db,"Cleans up the clause_db database.").
Expand Down

0 comments on commit 9b4f18b

Please sign in to comment.