Changeset 4524 for trunk/compiler

Show
Ignore:
Timestamp:
10/20/08 19:20:18 (3 months ago)
Author:
pmoura
Message:

Added an optimization and security compiler option, "complements", that allows objects to be compiled with support for complementing categories either enabled or disabled. The default value (set in the config files) is "off" (disabled).

Added an optimization and security compiler option, "dynamic_declarations", that allows objects to be compiled with support for dynamic declaration of predicates (using the built-in database methods asserta/1 and assertz/1) either enabled or disabled. The default value (set in the config files) is "off" (disabled).

Updated the "complements" example to use the new "complements" compiler option. Update the "dynpred" example to use the new "dynamic_declarations" compiler option.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4521 r4524  
    22372237    '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, ObjType), 
    22382238    !, 
    2239     '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, Meta, SCtn, DclScope), 
     2239    '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, Meta, SCtn, DclScope, Obj::asserta((Head:-Body)), Sender), 
    22402240    (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    22412241        (   (\+ \+ Scope = TestScope; Sender = SCtn) -> 
     
    22712271    '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, ObjType), 
    22722272    !, 
    2273     '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, _, SCtn, DclScope), 
     2273    '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, _, SCtn, DclScope, Obj::asserta(Head), Sender), 
    22742274    (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    22752275        (   (\+ \+ Scope = TestScope; Sender = SCtn)  -> 
     
    23392339    '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, ObjType), 
    23402340    !, 
    2341     '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, Meta, SCtn, DclScope), 
     2341    '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, Meta, SCtn, DclScope, Obj::assertz((Head:-Body)), Sender), 
    23422342    (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    23432343        (   (\+ \+ Scope = TestScope; Sender = SCtn)  -> 
     
    23732373    '$lgt_current_object_'(Obj, Prefix, Dcl, Def, _, _, _, DDcl, DDef, _, ObjType), 
    23742374    !, 
    2375     '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, _, SCtn, DclScope), 
     2375    '$lgt_assert_pred_dcl'(Dcl, DDcl, Head, Scope, PredType, _, SCtn, DclScope, Obj::assertz(Head), Sender), 
    23762376    (   (PredType == (dynamic); ObjType == (dynamic), Sender = SCtn) -> 
    23772377        (   (\+ \+ Scope = TestScope; Sender = SCtn)  -> 
     
    24012401% get or set (if doesn't exist) the declaration for an asserted predicate 
    24022402 
    2403 '$lgt_assert_pred_dcl'(Dcl, DDcl, Pred, Scope, Type, Meta, SCtn, DclScope) :- 
     2403'$lgt_assert_pred_dcl'(Dcl, DDcl, Pred, Scope, Type, Meta, SCtn, DclScope, Goal, Sender) :- 
    24042404    (   call_with_args(Dcl, Pred, Scope, Type, Meta, _, _, SCtn, _) -> 
    24052405        true 
    24062406    ;   % no previous predicate declaration: 
    2407         '$lgt_assert_ddcl_clause'(DDcl, Pred, DclScope), 
    2408         (Scope, Type, Meta) = (DclScope, (dynamic), no) 
     2407        (   DDcl == nil -> 
     2408            % object doesn't supports dynamic declaration of new predicates: 
     2409            throw(error(permission_error(modify, object_protocol, Pred), Goal, Sender)) 
     2410        ;   '$lgt_assert_ddcl_clause'(DDcl, Pred, DclScope), 
     2411            (Scope, Type, Meta) = (DclScope, (dynamic), no) 
     2412        ) 
    24092413    ). 
    24102414 
     
    94189422    assertz('$lgt_pp_directive_'(dynamic(IDcl/8))), 
    94199423    assertz('$lgt_pp_directive_'(dynamic(IDef/6))), 
    9420     assertz('$lgt_pp_directive_'(dynamic(DDcl/2))), 
     9424    (   '$lgt_compiler_flag'(dynamic_declarations, on) -> 
     9425        assertz('$lgt_pp_directive_'(dynamic(DDcl/2))) 
     9426    ;   true 
     9427    ), 
    94219428    assertz('$lgt_pp_directive_'(dynamic(DDef/5))), 
    94229429    assertz('$lgt_pp_directive_'(dynamic(Rnm/3))), 
     
    94389445'$lgt_gen_static_object_dynamic_directives' :- 
    94399446    '$lgt_pp_object_'(_, Prefix, _, _, _, _, _, DDcl, DDef, _, _), 
    9440     assertz('$lgt_pp_directive_'(dynamic(DDcl/2))), 
     9447    (   '$lgt_compiler_flag'(dynamic_declarations, on) -> 
     9448        assertz('$lgt_pp_directive_'(dynamic(DDcl/2))) 
     9449    ;   true 
     9450    ), 
    94419451    assertz('$lgt_pp_directive_'(dynamic(DDef/5))), 
    94429452    '$lgt_pp_dynamic_'(Functor, Arity), 
     
    97849794    BodyDcl =.. [Dcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized], 
    97859795    assertz('$lgt_pp_dcl_'((HeadDcl:-BodyDcl))), 
    9786     HeadDDcl =.. [Dcl, Pred, Scope, (dynamic), no, no, no, Obj, Obj], 
    9787     BodyDDcl =.. [DDcl, Pred, Scope], 
    9788     assertz('$lgt_pp_dcl_'((HeadDDcl:-BodyDDcl))). 
     9796    (   '$lgt_compiler_flag'(dynamic_declarations, on) -> 
     9797        HeadDDcl =.. [Dcl, Pred, Scope, (dynamic), no, no, no, Obj, Obj], 
     9798        BodyDDcl =.. [DDcl, Pred, Scope], 
     9799        assertz('$lgt_pp_dcl_'((HeadDDcl:-BodyDDcl))) 
     9800    ;   true 
     9801    ). 
    97899802 
    97909803'$lgt_gen_prototype_linking_dcl_clauses'(false) :- 
    97919804    '$lgt_pp_object_'(Obj, _, Dcl, _, _, _, _, DDcl, _, _, _) -> 
    9792     HeadDDcl =.. [Dcl, Pred, Scope, (dynamic), no, no, no, Obj, Obj], 
    9793     BodyDDcl =.. [DDcl, Pred, Scope], 
    9794     assertz('$lgt_pp_dcl_'((HeadDDcl:-BodyDDcl))). 
     9805    (   '$lgt_compiler_flag'(dynamic_declarations, on) -> 
     9806        HeadDDcl =.. [Dcl, Pred, Scope, (dynamic), no, no, no, Obj, Obj], 
     9807        BodyDDcl =.. [DDcl, Pred, Scope], 
     9808        assertz('$lgt_pp_dcl_'((HeadDDcl:-BodyDDcl))) 
     9809    ;   HeadDDcl =.. [Dcl, _, _, _, _, _, _, _, _], 
     9810        assertz('$lgt_pp_dcl_'((HeadDDcl:-fail))) 
     9811    ). 
    97959812 
    97969813 
     
    98419858 
    98429859'$lgt_gen_prototype_imports_dcl_clauses' :- 
    9843     '$lgt_pp_object_'(Obj, _, ODcl, _, _, _, _, _, _, _, _) -> 
    9844     Head =.. [ODcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Obj, Ctn], 
    9845     Lookup = '$lgt_complemented_object'(Obj, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Ctn), 
    9846     assertz('$lgt_pp_dcl_'((Head:-Lookup))). 
     9860    (   '$lgt_compiler_flag'(complements, on) -> 
     9861        '$lgt_pp_object_'(Obj, _, ODcl, _, _, _, _, _, _, _, _) -> 
     9862        Head =.. [ODcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Obj, Ctn], 
     9863        Lookup = '$lgt_complemented_object'(Obj, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Ctn), 
     9864        assertz('$lgt_pp_dcl_'((Head:-Lookup))) 
     9865    ;   true 
     9866    ). 
    98479867 
    98489868 
     
    99169936 
    99179937'$lgt_gen_prototype_imports_def_clauses' :- 
    9918     '$lgt_pp_object_'(Obj, _, _, ODef, _, _, _, _, _, _, _) -> 
    9919     Head =.. [ODef, Pred, Sender, Obj, Self, Call, Ctn], 
    9920     Lookup = '$lgt_complemented_object'(Pred, Sender, Obj, Self, Call, Ctn), 
    9921     assertz('$lgt_pp_fdef_'((Head:-Lookup))). 
     9938    (   '$lgt_compiler_flag'(complements, on) -> 
     9939        '$lgt_pp_object_'(Obj, _, _, ODef, _, _, _, _, _, _, _) -> 
     9940        Head =.. [ODef, Pred, Sender, Obj, Self, Call, Ctn], 
     9941        Lookup = '$lgt_complemented_object'(Pred, Sender, Obj, Self, Call, Ctn), 
     9942        assertz('$lgt_pp_fdef_'((Head:-Lookup))) 
     9943    ;   true 
     9944    ). 
    99229945 
    99239946 
     
    1003210055    BodyDcl =.. [Dcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized], 
    1003310056    assertz('$lgt_pp_dcl_'((HeadDcl:-BodyDcl))), 
    10034     HeadDDcl =.. [IDcl, Pred, Scope, (dynamic), no, no, no, Obj, Obj], 
    10035     BodyDDcl =.. [DDcl, Pred, Scope], 
    10036     assertz('$lgt_pp_dcl_'((HeadDDcl:-BodyDDcl))). 
     10057    (   '$lgt_compiler_flag'(dynamic_declarations, on) -> 
     10058        HeadDDcl =.. [IDcl, Pred, Scope, (dynamic), no, no, no, Obj, Obj], 
     10059        BodyDDcl =.. [DDcl, Pred, Scope], 
     10060        assertz('$lgt_pp_dcl_'((HeadDDcl:-BodyDDcl))) 
     10061    ;   true 
     10062    ). 
    1003710063 
    1003810064'$lgt_gen_ic_linking_idcl_clauses'(false) :- 
    1003910065    '$lgt_pp_object_'(Obj, _, _, _, _, IDcl, _, DDcl, _, _, _) -> 
    10040     HeadDDcl =.. [IDcl, Pred, Scope, (dynamic), no, no, no, Obj, Obj], 
    10041     BodyDDcl =.. [DDcl, Pred, Scope], 
    10042     assertz('$lgt_pp_dcl_'((HeadDDcl:-BodyDDcl))). 
     10066    (   '$lgt_compiler_flag'(dynamic_declarations, on) -> 
     10067        HeadDDcl =.. [IDcl, Pred, Scope, (dynamic), no, no, no, Obj, Obj], 
     10068        BodyDDcl =.. [DDcl, Pred, Scope], 
     10069        assertz('$lgt_pp_dcl_'((HeadDDcl:-BodyDDcl))) 
     10070    ;   HeadDDcl =.. [IDcl, _, _, _, _, _, _, _, _], 
     10071        assertz('$lgt_pp_dcl_'((HeadDDcl:-fail))) 
     10072    ). 
    1004310073 
    1004410074 
     
    1008910119 
    1009010120'$lgt_gen_ic_category_idcl_clauses' :- 
    10091     '$lgt_pp_object_'(Obj, _, _, _, _, OIDcl, _, _, _, _, _) -> 
    10092     Head =.. [OIDcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Obj, Ctn], 
    10093     Lookup = '$lgt_complemented_object'(Obj, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Ctn), 
    10094     assertz('$lgt_pp_dcl_'((Head:-Lookup))). 
     10121    (   '$lgt_compiler_flag'(complements, on) -> 
     10122        '$lgt_pp_object_'(Obj, _, _, _, _, OIDcl, _, _, _, _, _) -> 
     10123        Head =.. [OIDcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Obj, Ctn], 
     10124        Lookup = '$lgt_complemented_object'(Obj, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Ctn), 
     10125        assertz('$lgt_pp_dcl_'((Head:-Lookup))) 
     10126    ;   true 
     10127    ). 
    1009510128 
    1009610129 
     
    1016510198 
    1016610199'$lgt_gen_ic_imports_def_clauses' :- 
    10167     '$lgt_pp_object_'(Obj, _, _, ODef, _, _, _, _, _, _, _) -> 
    10168     Head =.. [ODef, Pred, Sender, Obj, Self, Call, Ctn], 
    10169     Lookup = '$lgt_complemented_object'(Pred, Sender, Obj, Self, Call, Ctn), 
    10170     assertz('$lgt_pp_fdef_'((Head:-Lookup))). 
     10200    (   '$lgt_compiler_flag'(complements, on) -> 
     10201        '$lgt_pp_object_'(Obj, _, _, ODef, _, _, _, _, _, _, _) -> 
     10202        Head =.. [ODef, Pred, Sender, Obj, Self, Call, Ctn], 
     10203        Lookup = '$lgt_complemented_object'(Pred, Sender, Obj, Self, Call, Ctn), 
     10204        assertz('$lgt_pp_fdef_'((Head:-Lookup))) 
     10205    ;   true 
     10206    ). 
    1017110207 
    1017210208 
     
    1022810264 
    1022910265'$lgt_gen_ic_category_idef_clauses' :- 
    10230     '$lgt_pp_object_'(Obj, _, _, _, _, _, OIDef, _, _, _, _) -> 
    10231     Head =.. [OIDef, Pred, Sender, Obj, Self, Call, Ctn], 
    10232     Lookup = '$lgt_complemented_object'(Pred, Sender, Obj, Self, Call, Ctn), 
    10233     assertz('$lgt_pp_fdef_'((Head:-Lookup))). 
     10266    (   '$lgt_compiler_flag'(complements, on) -> 
     10267        '$lgt_pp_object_'(Obj, _, _, _, _, _, OIDef, _, _, _, _) -> 
     10268        Head =.. [OIDef, Pred, Sender, Obj, Self, Call, Ctn], 
     10269        Lookup = '$lgt_complemented_object'(Pred, Sender, Obj, Self, Call, Ctn), 
     10270        assertz('$lgt_pp_fdef_'((Head:-Lookup))) 
     10271    ;   true 
     10272    ). 
    1023410273 
    1023510274 
     
    1102311062        atom_concat(Prefix, '_idcl', IDcl), 
    1102411063        atom_concat(Prefix, '_idef', IDef), 
    11025         atom_concat(Prefix, '_ddcl', DDcl), 
     11064        (   '$lgt_compiler_flag'(dynamic_declarations, on) -> 
     11065            atom_concat(Prefix, '_ddcl', DDcl) 
     11066        ;   DDcl = nil 
     11067        ), 
    1102611068        atom_concat(Prefix, '_ddef', DDef), 
    1102711069        atom_concat(Prefix, '_alias', Rnm) 
     
    1169811740'$lgt_valid_flag'(tmpdir). 
    1169911741'$lgt_valid_flag'(hook). 
     11742'$lgt_valid_flag'(complements). 
     11743'$lgt_valid_flag'(dynamic_declarations). 
    1170011744'$lgt_valid_flag'(events). 
    1170111745'$lgt_valid_flag'(code_prefix). 
     
    1177911823'$lgt_valid_flag_value'(debug, on) :- !. 
    1178011824'$lgt_valid_flag_value'(debug, off) :- !. 
     11825 
     11826'$lgt_valid_flag_value'(complements, on) :- !. 
     11827'$lgt_valid_flag_value'(complements, off) :- !. 
     11828 
     11829'$lgt_valid_flag_value'(dynamic_declarations, on) :- !. 
     11830'$lgt_valid_flag_value'(dynamic_declarations, off) :- !. 
    1178111831 
    1178211832'$lgt_valid_flag_value'(events, on) :- !. 
     
    1385113901    '$lgt_default_flag'(debug, Debug), 
    1385213902    write('  Compile entities in debug mode (debug):                     '), writeq(Debug), nl, 
     13903    '$lgt_default_flag'(complements, Complements), 
     13904    write('  Complementing category support (complements):               '), write(Complements), nl, 
     13905    '$lgt_default_flag'(dynamic_declarations, DynamicDeclarations), 
     13906    write('  Dynamic declarations support (dynamic_declarations):        '), write(DynamicDeclarations), nl, 
    1385313907    '$lgt_default_flag'(events, Events), 
    1385413908    write('  Compile messages with event support (events):               '), write(Events), nl,