Changeset 4599 for trunk/compiler

Show
Ignore:
Timestamp:
11/21/08 12:47:26 (7 weeks ago)
Author:
pmoura
Message:

Added an expand_goal/2 built-in method to support explicit calls to the goal_expansion/2 user-defined hook. Updated the term expansion mechanism to allow the expansion to be a single term instead of a list of terms. Improved the documentation of the term and goal expansion predicates.

Added syntax coloring support for the new expand_goal/2 method to the supported text editors and syntax highlighters.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4598 r4599  
    255255 
    256256:- dynamic('$lgt_pp_hook_term_expansion_'/2).   % '$lgt_pp_hook_term_expansion_'(Term, Terms) 
    257 :- dynamic('$lgt_pp_hook_goal_expansion_'/2).   % '$lgt_pp_hook_goal_expansion_'(Term, Terms) 
     257:- dynamic('$lgt_pp_hook_goal_expansion_'/2).   % '$lgt_pp_hook_goal_expansion_'(Goal, EGoal) 
    258258 
    259259:- dynamic('$lgt_pp_threaded_'/0).              % '$lgt_pp_threaded_' 
     
    17721772        (   Obj == user ->                                          % to speed up entity compilation 
    17731773            TermExpansionGoal = term_expansion(Term, Terms), 
    1774             GoalExpansionGoal = goal_expansion(Term, Terms) 
     1774            GoalExpansionGoal = goal_expansion(Goal, EGoal) 
    17751775        ;   '$lgt_tr_msg'(term_expansion(Term, Terms), Obj, TermExpansionGoal, user), 
    1776             '$lgt_tr_msg'(goal_expansion(Term, Terms), Obj, GoalExpansionGoal, user) 
     1776            '$lgt_tr_msg'(goal_expansion(Goal, EGoal), Obj, GoalExpansionGoal, user) 
    17771777        ), 
    17781778        assertz(('$lgt_pp_hook_term_expansion_'(Term, Terms) :- catch(TermExpansionGoal, _, fail))), 
    1779         assertz(('$lgt_pp_hook_goal_expansion_'(Term, Terms) :- catch(GoalExpansionGoal, _, fail))) 
     1779        assertz(('$lgt_pp_hook_goal_expansion_'(Goal, EGoal) :- catch(GoalExpansionGoal, _, fail))) 
    17801780    ;   true 
    17811781    ). 
     
    29452945 
    29462946 
     2947 
    29472948% '$lgt_term_expansion'(+object_identifier, ?term, ?term, +object_identifier, @scope) 
    29482949% 
     
    29642965            true 
    29652966        ;   call_with_args(DDef, term_expansion(Term, Expansion), Obj, Obj, Obj, Call) 
     2967        ) 
     2968    ), 
     2969    !, 
     2970    once(Call). 
     2971 
     2972 
     2973 
     2974% '$lgt_expand_goal'(+object_identifier, ?term, ?term, +object_identifier, @scope) 
     2975% 
     2976% expand_goal/2 built-in method 
     2977 
     2978'$lgt_expand_goal'(Obj, Goal, Expansion, Sender, Scope) :- 
     2979    (    var(Goal) -> 
     2980         Expansion = Goal 
     2981    ;    '$lgt_goal_expansion'(Obj, Goal, Expand, Sender, Scope) -> 
     2982         Expansion = Expand 
     2983    ;    Expansion = Goal 
     2984    ).  
     2985 
     2986 
     2987 
     2988% '$lgt_goal_expansion'(+object_identifier, ?term, ?term, +object_identifier, @scope) 
     2989% 
     2990% calls the goal_expansion/2 user-defined predicate 
     2991% 
     2992% if there is a scope directive, then the call fails if the sender is not within scope; 
     2993% when there is no scope directive, then we call any local definition when the sender 
     2994% and the target object are the same 
     2995 
     2996'$lgt_goal_expansion'(Obj, Goal, Expansion, Sender, Scope) :- 
     2997    '$lgt_current_object_'(Obj, _, Dcl, Def, _, _, _, _, DDef, _, _), 
     2998    (   (   call_with_args(Dcl, goal_expansion(_, _), PScope, _, _, _, _, SCtn, _) -> 
     2999            (   (\+ \+ PScope = Scope; Sender = SCtn) -> 
     3000                call_with_args(Def, goal_expansion(Goal, Expansion), Sender, Obj, Obj, Call, _) 
     3001            ) 
     3002        ) 
     3003    ;   Obj = Sender, 
     3004        (   call_with_args(Def, goal_expansion(Goal, Expansion), Obj, Obj, Obj, Call) -> 
     3005            true 
     3006        ;   call_with_args(DDef, goal_expansion(Goal, Expansion), Obj, Obj, Obj, Call) 
    29663007        ) 
    29673008    ), 
     
    52785319 
    52795320 
    5280 % '$lgt_tr_term'(+term, +integer, @stream, @stream) 
     5321% '$lgt_tr_term'(@term, +integer, @stream, @stream) 
    52815322% 
    52825323% translates a source file term (clauses, directives, and grammar rules) 
     
    52955336 
    52965337 
    5297 % '$lgt_tr_expanded_terms'(+list, +integer, @stream, @stream) 
    5298 % 
    5299 % translates a list of source file terms 
    5300  
    5301 '$lgt_tr_expanded_terms'([], _, _, _). 
     5338% '$lgt_tr_expanded_terms'(@term, +integer, @stream, @stream) 
     5339% 
     5340% translates the expanded terms (which can be a list of terms) 
     5341 
     5342'$lgt_tr_expanded_terms'([], _, _, _) :- 
     5343    !. 
    53025344 
    53035345'$lgt_tr_expanded_terms'([Term| Terms], Line, Input, Output) :- 
     5346    !, 
    53045347    '$lgt_tr_expanded_term'(Term, Line, Input, Output), 
    53055348    '$lgt_tr_expanded_terms'(Terms, Line, Input, Output). 
     5349 
     5350'$lgt_tr_expanded_terms'(Term, Line, Input, Output) :- 
     5351    !, 
     5352    '$lgt_tr_expanded_term'(Term, Line, Input, Output). 
    53065353 
    53075354 
     
    76557702 
    76567703 
    7657 % DCG predicates 
     7704% term and goal expansion predicates 
    76587705 
    76597706'$lgt_tr_body'(expand_term(Term, Clause), '$lgt_expand_term'(This, Term, Clause, This, p(_)), '$lgt_dbg_goal'(expand_term(Term, Clause), '$lgt_expand_term'(This, Term, Clause, This, p(_)), DbgCtx), Ctx) :- 
     
    76617708    '$lgt_ctx_this'(Ctx, This), 
    76627709    '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). 
     7710 
     7711'$lgt_tr_body'(expand_goal(Goal, EGoal), '$lgt_expand_goal'(This, Goal, EGoal, This, p(_)), '$lgt_dbg_goal'(expand_goal(Goal, EGoal), '$lgt_expand_goal'(This, Goal, EGoal, This, p(_)), DbgCtx), Ctx) :- 
     7712    !, 
     7713    '$lgt_ctx_this'(Ctx, This), 
     7714    '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). 
     7715 
     7716 
     7717% DCG predicates 
    76637718 
    76647719'$lgt_tr_body'(phrase(GRBody, Input), '$lgt_phrase'(This, GRBody, Input, This, _), '$lgt_dbg_goal'(phrase(GRBody, Input), '$lgt_phrase'(This, GRBody, Input, This, _), DbgCtx), Ctx) :- 
     
    84458500 
    84468501 
    8447 % DCG predicates 
     8502% term and goal expansion predicates 
    84488503 
    84498504'$lgt_tr_msg'(expand_term(Term, Clause), Obj, '$lgt_expand_term'(Obj, Term, Clause, This, p(p(p))), This) :- 
    84508505    !. 
     8506 
     8507'$lgt_tr_msg'(expand_goal(Goal, EGoal), Obj, '$lgt_expand_goal'(Obj, Goal, EGoal, This, p(p(p))), This) :- 
     8508    !. 
     8509 
     8510 
     8511% DCG predicates 
    84518512 
    84528513'$lgt_tr_msg'(phrase(GRBody, List), Obj, '$lgt_phrase'(Obj, GRBody, List, This, p(p(p))), This) :- 
     
    86568717 
    86578718 
    8658  
    8659 % DCG predicates 
     8719% term and goal expansion predicates 
    86608720 
    86618721'$lgt_tr_self_msg'(expand_term(Term, Clause), '$lgt_expand_term'(Self, Term, Clause, This, p(_)), This, Self) :- 
    86628722    !. 
     8723 
     8724'$lgt_tr_self_msg'(expand_goal(Goal, EGoal), '$lgt_expand_goal'(Self, Goal, EGoal, This, p(_)), This, Self) :- 
     8725    !. 
     8726 
     8727 
     8728% DCG predicates 
    86638729 
    86648730'$lgt_tr_self_msg'(phrase(GRBody, List), '$lgt_phrase'(Self, GRBody, List, This, p(_)), This, Self) :- 
     
    1155711623 
    1155811624'$lgt_built_in_method'(expand_term(_, _), p(p(p))). 
     11625'$lgt_built_in_method'(expand_goal(_, _), p(p(p))). 
     11626 
    1155911627'$lgt_built_in_method'(phrase(_, _), p(p(p))). 
    1156011628'$lgt_built_in_method'(phrase(_, _, _), p(p(p))).