Changeset 4500 for trunk/compiler

Show
Ignore:
Timestamp:
10/12/08 08:36:44 (3 months ago)
Author:
pmoura
Message:

Modified the database built-in methods to allow initialization of static predicates for dynamic objects when the predicates are declared in "this". These changes simplify the initialization of dynamic objects when writing constructors. The dynamic objects must be descendants of "this".

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4498 r4500  
    22172217 
    22182218'$lgt_asserta_rule_chk'(Obj, (Head:-Body), Sender, TestScope, DclScope) :- 
    2219     '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, _, _, _), 
    2220     !, 
    2221     '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, Type, Meta, SCtn, DclScope), 
    2222     (   Type == (dynamic) -> 
     2219    '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, ObjType, _, _), 
     2220    !, 
     2221    '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, Meta, SCtn, DclScope), 
     2222    (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    22232223        (   (\+ \+ Scope = TestScope; Sender = SCtn) -> 
    22242224            '$lgt_assert_pred_def'(Obj, Def, DDef, Prefix, Head, GSender, GThis, GSelf, THead, _), 
     
    22512251 
    22522252'$lgt_asserta_fact_chk'(Obj, Head, Sender, TestScope, DclScope) :- 
    2253     '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, _, _, _), 
    2254     !, 
    2255     '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, Type, _, SCtn, DclScope), 
    2256     (   Type == (dynamic) -> 
     2253    '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, ObjType, _, _), 
     2254    !, 
     2255    '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, _, SCtn, DclScope), 
     2256    (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    22572257        (   (\+ \+ Scope = TestScope; Sender = SCtn)  -> 
    22582258            '$lgt_assert_pred_def'(Obj, Def, DDef, Prefix, Head, GSender, GThis, GSelf, THead, Update), 
     
    22612261                '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx), 
    22622262                asserta((THead :- '$lgt_dbg_fact'(Head, 0, DbgCtx))) 
    2263             ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, SCtn, DclScope, Sender, THead, DDef, Update), 
     2263            ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, SCtn, DclScope, PredType, Sender, THead, DDef, Update), 
    22642264                asserta(THead) 
    22652265            ) 
     
    23192319 
    23202320'$lgt_assertz_rule_chk'(Obj, (Head:-Body), Sender, TestScope, DclScope) :- 
    2321     '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, _, _, _), 
    2322     !, 
    2323     '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, Type, Meta, SCtn, DclScope), 
    2324     (   Type == (dynamic) -> 
     2321    '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, ObjType, _, _), 
     2322    !, 
     2323    '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, Meta, SCtn, DclScope), 
     2324    (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    23252325        (   (\+ \+ Scope = TestScope; Sender = SCtn)  -> 
    23262326            '$lgt_assert_pred_def'(Obj, Def, DDef, Prefix, Head, GSender, GThis, GSelf, THead, _), 
     
    23532353 
    23542354'$lgt_assertz_fact_chk'(Obj, Head, Sender, TestScope, DclScope) :- 
    2355     '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, _, _, _), 
    2356     !, 
    2357     '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, Type, _, SCtn, DclScope), 
    2358     (   Type == (dynamic) -> 
     2355    '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, ObjType, _, _), 
     2356    !, 
     2357    '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, _, SCtn, DclScope), 
     2358    (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    23592359        (   (\+ \+ Scope = TestScope; Sender = SCtn)  -> 
    23602360            '$lgt_assert_pred_def'(Obj, Def, DDef, Prefix, Head, GSender, GThis, GSelf, THead, Update), 
     
    23632363                '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx), 
    23642364                assertz((THead :- '$lgt_dbg_fact'(Head, 0, DbgCtx))) 
    2365             ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, SCtn, DclScope, Sender, THead, DDef, Update), 
     2365            ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, SCtn, DclScope, PredType, Sender, THead, DDef, Update), 
    23662366                assertz(THead) 
    23672367            ) 
     
    24512451 
    24522452'$lgt_clause_chk'(Obj, Head, Body, Sender, Scope) :- 
    2453     '$lgt_current_object_'(Obj, _, Dcl, Def, _, _, _, _, DDef, _, _, _, _), 
    2454     !, 
    2455     (   call_with_args(Dcl, Head, PScope, Type, _, _, _, SCtn, _) -> 
    2456         (   Type == (dynamic) -> 
     2453    '$lgt_current_object_'(Obj, _, Dcl, Def, _, _, _, _, DDef, _, ObjType, _, _), 
     2454    !, 
     2455    (   call_with_args(Dcl, Head, PScope, PredType, _, _, _, SCtn, _) -> 
     2456        (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    24572457            (   (\+ \+ PScope = Scope; Sender = SCtn) -> 
    24582458                (   (call_with_args(DDef, Head, _, _, _, Call); call_with_args(Def, Head, _, _, _, Call)) -> 
     
    25242524 
    25252525'$lgt_retract_var_body_chk'(Obj, (Head:-Body), Sender, Scope) :- 
    2526     '$lgt_current_object_'(Obj, _, Dcl, Def, _, _, _, _, DDef, _, _, _, _), 
    2527     !, 
    2528     (   call_with_args(Dcl, Head, PScope, Type, _, _, _, SCtn, _) -> 
    2529         (   Type == (dynamic) -> 
     2526    '$lgt_current_object_'(Obj, _, Dcl, Def, _, _, _, _, DDef, _, ObjType, _, _), 
     2527    !, 
     2528    (   call_with_args(Dcl, Head, PScope, PredType, _, _, _, SCtn, _) -> 
     2529        (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    25302530            (   (\+ \+ PScope = Scope; Sender = SCtn) -> 
    25312531                (   call_with_args(DDef, Head, _, _, _, Call) -> 
     
    25752575 
    25762576'$lgt_retract_rule_chk'(Obj, (Head:-Body), Sender, Scope) :- 
    2577     '$lgt_current_object_'(Obj, _, Dcl, Def, _, _, _, _, DDef, _, _, _, _), 
    2578     !, 
    2579     (   call_with_args(Dcl, Head, PScope, Type, _, _, _, SCtn, _) -> 
    2580         (   Type == (dynamic) -> 
     2577    '$lgt_current_object_'(Obj, _, Dcl, Def, _, _, _, _, DDef, _, ObjType, _, _), 
     2578    !, 
     2579    (   call_with_args(Dcl, Head, PScope, PredType, _, _, _, SCtn, _) -> 
     2580        (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    25812581            (   (\+ \+ PScope = Scope; Sender = SCtn) -> 
    25822582                (   call_with_args(DDef, Head, _, _, _, Call) -> 
     
    26142614 
    26152615'$lgt_retract_fact_chk'(Obj, Head, Sender, Scope) :- 
    2616     '$lgt_current_object_'(Obj, _, Dcl, Def, _, _, _, _, DDef, _, _, _, _), 
    2617     !, 
    2618     (   call_with_args(Dcl, Head, PScope, Type, _, _, _, SCtn, _) -> 
    2619         (   Type == (dynamic) -> 
     2616    '$lgt_current_object_'(Obj, _, Dcl, Def, _, _, _, _, DDef, _, ObjType, _, _), 
     2617    !, 
     2618    (   call_with_args(Dcl, Head, PScope, PredType, _, _, _, SCtn, _) -> 
     2619        (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    26202620            (   (\+ \+ PScope = Scope; Sender = SCtn) -> 
    26212621                (   call_with_args(DDef, Head, _, _, _, Call) -> 
    26222622                    (   '$lgt_debugging_'(Obj) -> 
    26232623                        retract((Call :- '$lgt_dbg_fact'(_, _, _))) 
    2624                     ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, SCtn, PScope, Sender, Call, DDef, true), 
     2624                    ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, SCtn, PScope, PredType, Sender, Call, DDef, true), 
    26252625                        retract(Call) 
    26262626                    ), 
     
    26292629                    (   '$lgt_debugging_'(Obj) -> 
    26302630                        retract((Call :- '$lgt_dbg_fact'(_, _, _))) 
    2631                     ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, PScope, Sender, Call), 
     2631                    ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, PScope, PredType, Sender, Call), 
    26322632                        retract(Call) 
    26332633                    ) 
     
    26462646            (   '$lgt_debugging_'(Obj) -> 
    26472647                retract((Call :- '$lgt_dbg_fact'(_, _, _))) 
    2648             ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, p, Sender, Call), 
     2648            ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, p, PredType, Sender, Call), 
    26492649                retract(Call) 
    26502650            ) 
     
    26792679 
    26802680'$lgt_retractall_chk'(Obj, Head, Sender, Scope) :- 
    2681     '$lgt_current_object_'(Obj, _, Dcl, Def, _, _, _, _, DDef, _, _, _, _), 
    2682     !, 
    2683     (   call_with_args(Dcl, Head, PScope, Type, _, _, _, SCtn, _) -> 
    2684         (   Type == (dynamic) -> 
     2681    '$lgt_current_object_'(Obj, _, Dcl, Def, _, _, _, _, DDef, _, ObjType, _, _), 
     2682    !, 
     2683    (   call_with_args(Dcl, Head, PScope, PredType, _, _, _, SCtn, _) -> 
     2684        (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    26852685            (   (\+ \+ PScope = Scope; Sender = SCtn) -> 
    26862686                (   call_with_args(DDef, Head, _, _, _, Call) -> 
     
    26902690                    (   '$lgt_debugging_'(Obj) -> 
    26912691                        true 
    2692                     ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, PScope, Sender, Call) 
     2692                    ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, PScope, PredType, Sender, Call) 
    26932693                    ), 
    26942694                    retractall(Call) 
     
    27092709            (   '$lgt_debugging_'(Obj) -> 
    27102710                true 
    2711             ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, p, Sender, Call) 
     2711            ;   '$lgt_add_db_lookup_cache_entry'(Obj, Head, p, PredType, Sender, Call) 
    27122712            ), 
    27132713            retractall(Call) 
     
    27302730 
    27312731 
    2732 % '$lgt_add_db_lookup_cache_entry'(@object_identifier, @callable, @callable, @object_identifier, @callable) 
     2732% '$lgt_add_db_lookup_cache_entry'(@object_identifier, @callable, @callable, +atom, @object_identifier, @callable) 
    27332733% 
    27342734% adds a new database lookup cache entry (when an update goal is not needed) 
    27352735 
    2736 '$lgt_add_db_lookup_cache_entry'(Obj, Head, Scope, Sender, Call) :- 
     2736'$lgt_add_db_lookup_cache_entry'(Obj, Head, Scope, Type, Sender, Call) :- 
    27372737    functor(Obj, OFunctor, OArity), 
    27382738    functor(GObj, OFunctor, OArity), 
     
    27442744    GCall =.. [_| ExtArgs], 
    27452745    '$lgt_unify_args'(Args, ExtArgs),  
    2746     (   Scope = p(p(p)) -> 
     2746    (   (Scope = p(p(p)), Type == (dynamic)) -> 
    27472747        asserta('$lgt_db_lookup_cache_'(GObj, GHead, _, GCall, true)) 
    27482748    ;   functor(Sender, SFunctor, SArity), 
     
    27522752 
    27532753 
    2754 % '$lgt_add_db_lookup_cache_entry'(@object_identifier, @callable, @callable, @callable, @object_identifier, @callable, +atom, +atom) 
     2754% '$lgt_add_db_lookup_cache_entry'(@object_identifier, @callable, @callable, @callable, +atom, @object_identifier, @callable, +atom, +atom) 
    27552755% 
    27562756% adds a new database lookup cache entry 
    27572757 
    2758 '$lgt_add_db_lookup_cache_entry'(Obj, Head, SCtn, Scope, Sender, Call, DDef, NeedsUpdate) :- 
     2758'$lgt_add_db_lookup_cache_entry'(Obj, Head, SCtn, Scope, Type, Sender, Call, DDef, NeedsUpdate) :- 
    27592759    functor(Obj, OFunctor, OArity), 
    27602760    functor(GObj, OFunctor, OArity), 
     
    27702770        functor(UCall, CFunctor, CArity), 
    27712771        UClause =.. [DDef, UHead, _, _, _, _], 
    2772         (   Scope = p(p(p)) -> 
     2772        (   (Scope = p(p(p)), Type == (dynamic)) -> 
    27732773            asserta('$lgt_db_lookup_cache_'(GObj, GHead, _, GCall, '$lgt_update_ddef_table_opt'(UHead, UCall, UClause))) 
    27742774        ;   functor(Sender, SFunctor, SArity), 
     
    27762776            asserta('$lgt_db_lookup_cache_'(GObj, GHead, GSender, GCall, '$lgt_update_ddef_table_opt'(UHead, UCall, UClause))) 
    27772777        ) 
    2778     ;   (   Scope = p(p(p)) -> 
     2778    ;   (   (Scope = p(p(p)), Type == (dynamic)) -> 
    27792779            asserta('$lgt_db_lookup_cache_'(GObj, GHead, _, GCall, true)) 
    27802780        ;   functor(Sender, SFunctor, SArity),