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

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