home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / TOOLS / ACC_DECL.LF < prev    next >
Text File  |  1996-06-04  |  4KB  |  188 lines

  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. %                   EXPANDING ACCUMULATORS AND HIDDEN ARGUMENTS.
  4. %
  5. % This file contains all the declarations used by the preprocessor
  6. %
  7. % Copyright 1992-1994 Digital Equipment Corporation
  8. % All Rights Reserved
  9. %
  10. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  11. %    $Id: acc_declarations.lf,v 1.2 1994/12/08 23:49:07 duchier Exp $    
  12.  
  13. module("acc_declarations") ?
  14.  
  15. public(acc_info,pred_info,pass_info,
  16.        clear_acc_def,
  17.        is_passed,is_acc,expandable,
  18.        get_acc_info,get_pass_info,list_of_accs,
  19.        dcg,
  20.        check_expansion_flag,
  21.        set_error_expander,reset_error_expander,
  22.        non_expanded_warning) ?
  23.  
  24. persistent(accumulators) ?
  25. persistent(passed_arguments) ?
  26. persistent(predicates_info) ?
  27. persistent(check_expansion_flag) ?
  28.  
  29. check_expansion_flag <<- false ?
  30.  
  31. %%% accumulator declaration
  32.  
  33. non_strict(acc_info) ?
  34.  
  35. associate_expanders(acc_info,acc_info_expander) ?
  36. acc_info_expander(X,in_clauses => In,out_clauses => In) :-
  37.     X.
  38.  
  39.  
  40. acc_info(Acc,Term,In,Out,
  41.      acc_pred => Acc_pred, 
  42.      in_name => InName, out_name => OutName,
  43.      in_start => InStart, out_start => OutStart) :-
  44.     AS = psi2str(Acc),
  45.     InName = {strcon("in_",AS);@},
  46.     OutName = {strcon("out_",AS);@},
  47.     !,
  48.     cond( has_feature(Acc,accumulators),
  49.           overriding_warning(Acc)
  50.         ),
  51.     accumulators.Acc <<- @(Acc,Term,In,Out,
  52.                    acc_pred => Acc_pred, 
  53.                    in_name => InName, out_name => OutName, 
  54.                    in_start => InStart,
  55.                    out_start => OutStart).
  56.  
  57.  
  58. X:get_acc_info(Acc) :-
  59.     cond( has_feature(Acc,accumulators,AccInfo),
  60.           X = copy_term(AccInfo),
  61.           fail
  62.         ).
  63.  
  64. is_acc(Acc) -> has_feature(Acc,accumulators).
  65.  
  66.  
  67.  
  68. %%% pred_info
  69.  
  70. pred_info(X,Y) :-
  71.     cond( X :< list,
  72.           pred_list_info(X,Y),
  73.           pred_info2(X,Y)
  74.         ).
  75. pred_list_info([A|B],Y) :-
  76.     !,
  77.     pred_info2(A,Y),
  78.     pred_list_info(B,Y).
  79. pred_list_info([]).
  80.  
  81. pred_info2(X,Y) :-
  82.     ( check_expansion_flag,!,
  83.       remove_expanders(X,error_expander),
  84.       add_expanders_a(X,error_expander)
  85.     ;
  86.       succeed
  87.     ),
  88.     cond( Y :< list,
  89.           acc_list_info(Y,combined_name(X)),
  90.           predicates_info.combined_name(X).Y <<- true
  91.         ).
  92.  
  93. acc_list_info([A|B],X) :-
  94.     !,
  95.     predicates_info.X.A <<- true,
  96.     acc_list_info(B,X).
  97. acc_list_info([]).
  98.  
  99.  
  100. associate_expanders(pred_info,pred_info_expander) ?
  101. pred_info_expander(X,in_clauses => In,out_clauses => In) :-
  102.     X.
  103.  
  104. expandable(X) -> has_feature(combined_name(X),predicates_info).
  105.  
  106.  
  107. %%% pass_info
  108.  
  109. non_strict(pass_info) ?
  110. pass_info(P,X,V,start=>I,acc_pred => Pred) :-
  111.     passed_arguments.P <<- @(P,X,V,start => I,acc_pred => Pred).
  112.  
  113. X:get_pass_info(P) :- cond( has_feature(P,passed_arguments,PassInfo),
  114.                 X = copy_term(PassInfo),
  115.                 fail
  116.               ).
  117.  
  118. associate_expanders(pass_info,pass_info_expander) ?
  119. pass_info_expander(X,in_clauses => In,out_clauses => In) :-
  120.     X.
  121.  
  122. is_passed(Pass) -> has_feature(Pass,passed_arguments).
  123.  
  124. %%% Utilities
  125.  
  126. %%% clear_acc_def: retract '*acc_info*' declarations...
  127.  
  128. clear_acc_def(X) :-
  129.     cond( X :< list,
  130.         maprel(clear_one_def,X),
  131.         clear_one_def(X)
  132.     ).
  133.  
  134. clear_one_def(X) :-
  135.     accumulators.X <<- @(false).
  136.  
  137. list_of_accs(PredName,Bool) -> L |
  138.     AllAccs = cond( has_feature(combined_name(PredName),
  139.                     predicates_info,Accs),
  140.             Accs,
  141.             @),
  142.     F = features(AllAccs,current_module),
  143.     cond(Bool,
  144.          cond( has_feature(dcg,AllAccs),
  145.            L = F,
  146.            L = [dcg|F]
  147.          ),
  148.          L = F
  149.         ).
  150.  
  151.  
  152. %%% Dealing with forgotten expansions:
  153.  
  154. error_expander(A,file => File,line => Line,
  155.            in_clauses => [A|Out],out_clauses => Out) :-
  156.     non_expanded_warning(A,File,Line).
  157.  
  158.  
  159. set_error_expander :-
  160.     maprel(set_check_exp,features(predicates_info,current_module)).
  161.  
  162.  
  163. reset_error_expander :-
  164.     maprel(reset_check_exp,features(predicates_info,current_module)).
  165.  
  166.  
  167. set_check_exp(A) :-
  168.     remove_expanders(A,error_expander),
  169.     add_expanders_a(A,error_expander).
  170.  
  171. reset_check_exp(A) :-
  172.     remove_expanders(A,error_expander).
  173.  
  174. %%%
  175.  
  176. overriding_warning(Acc) :- quiet,!.
  177. overriding_warning(Acc) :-
  178.     write_err("*** Warning: overriding previous declaration",
  179.           " of accumulator ",Acc),
  180.     nl_err.
  181.  
  182. non_expanded_warning(A,File,Line) :- quiet,!.
  183. non_expanded_warning(A,File,Line) :-
  184.     write_err("*** Warning: ",root_sort(A)),nl_err,
  185.     write_err("             is not expanded in file ",File,
  186.           " near line ",Line,"."),
  187.     nl_err.
  188.