Changeset 4578 for trunk/compiler

Show
Ignore:
Timestamp:
11/07/08 13:23:12 (2 months ago)
Author:
pmoura
Message:

Added conditional compilation support, as found in some Prolog compilers, using the new directives if/1, elif/1, else/0, and endif/0.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4574 r4578  
    266266:- dynamic('$lgt_pp_file_rclause_'/1).          % '$lgt_pp_file_rclause_'(Clause) 
    267267 
    268 :- dynamic('$lgt_pp_cc_if_found_'/0).           % '$lgt_pp_cc_if_found_' 
     268:- dynamic('$lgt_pp_cc_if_found_'/1).           % '$lgt_pp_cc_if_found_'(Goal) 
    269269:- dynamic('$lgt_pp_cc_skipping_'/0).           % '$lgt_pp_cc_skipping_' 
    270270:- dynamic('$lgt_pp_cc_mode_'/1).               % '$lgt_pp_cc_mode_'(Action) 
     
    47404740'$lgt_tr_file'(end_of_file, _, _, _, _) :- 
    47414741    '$lgt_pp_object_'(Obj, _, _, _, _, _, _, _, _, _, _), 
    4742     throw(entity_ending_directive_missing(object, Obj)). 
     4742    throw(directive_missing(end_object, object(Obj))). 
    47434743 
    47444744'$lgt_tr_file'(end_of_file, _, _, _, _) :- 
    47454745    '$lgt_pp_protocol_'(Ptc, _, _, _, _), 
    4746     throw(entity_ending_directive_missing(protocol, Ptc)). 
     4746    throw(directive_missing(end_protocol, protocol(Ptc))). 
    47474747 
    47484748'$lgt_tr_file'(end_of_file, _, _, _, _) :- 
    47494749    '$lgt_pp_category_'(Ctg, _, _, _, _, _), 
    4750     throw(entity_ending_directive_missing(category, Ctg)). 
     4750    throw(directive_missing(end_category, category(Ctg))). 
     4751 
     4752'$lgt_tr_file'(end_of_file, _, _, _, _) :- 
     4753    '$lgt_pp_cc_if_found_'(Goal), 
     4754    throw(directive_missing(endif, if(Goal))). 
    47514755 
    47524756'$lgt_tr_file'(end_of_file, _, _, _, _) :- 
     
    50345038    retractall('$lgt_pp_file_path_'(_, _)), 
    50355039    retractall('$lgt_pp_file_rclause_'(_)), 
    5036     retractall('$lgt_pp_cc_if_found_'), 
     5040    retractall('$lgt_pp_cc_if_found_'(_)), 
    50375041    retractall('$lgt_pp_cc_skipping_'), 
    50385042    retractall('$lgt_pp_cc_mode_'(_)). 
     
    53425346    '$lgt_pp_cc_mode_'(Value),                  % not top-level if 
    53435347    !, 
    5344     assertz('$lgt_pp_cc_if_found_'), 
     5348    asserta('$lgt_pp_cc_if_found_'(Goal)), 
    53455349    (   Value == seek ->                        % we're looking for an else 
    53465350        asserta('$lgt_pp_cc_mode_'(ignore))     % so ignore this if ... endif  
     
    53565360'$lgt_tr_directive'(if(Goal), _, _, _) :- 
    53575361    !, 
    5358     assertz('$lgt_pp_cc_if_found_'), 
     5362    asserta('$lgt_pp_cc_if_found_'(Goal)), 
    53595363    (   call(Goal) -> 
    53605364        asserta('$lgt_pp_cc_mode_'(skip)) 
     
    53735377 
    53745378'$lgt_tr_directive'(elif(Goal), _, _, _) :- 
    5375     \+ '$lgt_pp_cc_if_found_', 
     5379    \+ '$lgt_pp_cc_if_found_'(_), 
    53765380    throw(error(unmatched_directive, directive(elif(Goal)))). 
    53775381 
     
    53945398 
    53955399'$lgt_tr_directive'(else, _, _, _) :- 
    5396     \+ '$lgt_pp_cc_if_found_', 
     5400    \+ '$lgt_pp_cc_if_found_'(_), 
    53975401    throw(error(unmatched_directive, directive(else))). 
    53985402 
     
    54125416 
    54135417'$lgt_tr_directive'(endif, _, _, _) :- 
    5414     \+ '$lgt_pp_cc_if_found_', 
     5418    \+ '$lgt_pp_cc_if_found_'(_), 
    54155419    throw(error(unmatched_directive, directive(endif))). 
    54165420 
    54175421'$lgt_tr_directive'(endif, _, _, _) :- 
    5418     retract('$lgt_pp_cc_if_found_'), 
     5422    retract('$lgt_pp_cc_if_found_'(_)), 
    54195423    retract('$lgt_pp_cc_mode_'(Value)), 
    54205424    (   Value == ignore ->