Changeset 4213

Show
Ignore:
Timestamp:
04/21/08 09:25:05 (3 months ago)
Author:
pmoura
Message:
Added support for checking arithmetic expressions for calls to non-portable function calls when using the "portability" compiler flag.
Location:
trunk
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4196 r4213  
    205205:- dynamic('$lgt_pp_calls_pred_'/4).            % '$lgt_pp_calls_pred_'(Functor, Arity, TFunctor, TArity) 
    206206:- dynamic('$lgt_non_portable_call_'/2).        % '$lgt_non_portable_call_'(Functor, Arity) 
     207:- dynamic('$lgt_non_portable_function_'/2).    % '$lgt_non_portable_function_'(Functor, Arity) 
    207208 
    208209:- dynamic('$lgt_pp_defs_nt_'/2).               % '$lgt_pp_defs_nt_'(Functor, Arity) 
     
    47524753    retractall('$lgt_pp_calls_pred_'(_, _, _, _)), 
    47534754    retractall('$lgt_non_portable_call_'(_, _)), 
     4755    retractall('$lgt_non_portable_function_'(_, _)), 
    47544756    retractall('$lgt_pp_defs_nt_'(_, _)), 
    47554757    retractall('$lgt_pp_calls_nt_'(_, _)), 
     
    71987200 
    71997201 
     7202% arithmetic predicates (portability checks) 
     7203 
     7204'$lgt_tr_body'(_ is Exp, _, _, _) :- 
     7205    '$lgt_check_non_portable_functions'(Exp), 
     7206    fail. 
     7207'$lgt_tr_body'(Exp1 =:= Exp2, _, _, _) :- 
     7208    '$lgt_check_non_portable_functions'(Exp1), 
     7209    '$lgt_check_non_portable_functions'(Exp2), 
     7210    fail. 
     7211'$lgt_tr_body'(Exp1 =\= Exp2, _, _, _) :- 
     7212    '$lgt_check_non_portable_functions'(Exp1), 
     7213    '$lgt_check_non_portable_functions'(Exp2), 
     7214    fail. 
     7215'$lgt_tr_body'(Exp1 < Exp2, _, _, _) :- 
     7216    '$lgt_check_non_portable_functions'(Exp1), 
     7217    '$lgt_check_non_portable_functions'(Exp2), 
     7218    fail. 
     7219'$lgt_tr_body'(Exp1 =< Exp2, _, _, _) :- 
     7220    '$lgt_check_non_portable_functions'(Exp1), 
     7221    '$lgt_check_non_portable_functions'(Exp2), 
     7222    fail. 
     7223'$lgt_tr_body'(Exp1 > Exp2, _, _, _) :- 
     7224    '$lgt_check_non_portable_functions'(Exp1), 
     7225    '$lgt_check_non_portable_functions'(Exp2), 
     7226    fail. 
     7227'$lgt_tr_body'(Exp1 >= Exp2, _, _, _) :- 
     7228    '$lgt_check_non_portable_functions'(Exp1), 
     7229    '$lgt_check_non_portable_functions'(Exp2), 
     7230    fail. 
     7231 
     7232 
    72007233% Logtalk and Prolog built-in (meta-)predicates 
    72017234 
     
    75537586 
    75547587'$lgt_compiler_db_pred_ind_chk'(_). 
     7588 
     7589 
     7590 
     7591% '$lgt_check_non_portable_functions'(@term) 
     7592% 
     7593% checks an arithmetic expression for calls to non-standard Prolog functions 
     7594 
     7595 
     7596'$lgt_check_non_portable_functions'(Exp) :- 
     7597    var(Exp), 
     7598    !. 
     7599 
     7600'$lgt_check_non_portable_functions'(Exp) :- 
     7601    number(Exp), 
     7602    !. 
     7603 
     7604'$lgt_check_non_portable_functions'(Exp) :- 
     7605    '$lgt_iso_spec_function'(Exp), 
     7606    !, 
     7607    Exp =.. [_| Exps], 
     7608    '$lgt_check_non_portable_function_args'(Exps). 
     7609 
     7610'$lgt_check_non_portable_functions'(Exp) :- 
     7611    functor(Exp, Functor, Arity), 
     7612    (   '$lgt_non_portable_function_'(Functor, Arity) -> 
     7613        true 
     7614    ;   assertz('$lgt_non_portable_function_'(Functor, Arity)) 
     7615    ), 
     7616    Exp =.. [_| Exps], 
     7617    '$lgt_check_non_portable_function_args'(Exps). 
     7618 
     7619 
     7620'$lgt_check_non_portable_function_args'([]). 
     7621 
     7622'$lgt_check_non_portable_function_args'([Exp| Exps]) :- 
     7623    '$lgt_check_non_portable_functions'(Exp), 
     7624    '$lgt_check_non_portable_function_args'(Exps). 
    75557625 
    75567626 
     
    86098679        '$lgt_report_misspelt_calls', 
    86108680        '$lgt_report_non_portable_calls', 
     8681        '$lgt_report_non_portable_functions', 
    86118682        '$lgt_report_unknown_entities' 
    86128683    ;   true 
     
    1015310224    functor(Pred, Functor, Arity), 
    1015410225    \+ '$lgt_pp_redefined_built_in_'(Pred, _, _, _, _). 
     10226 
     10227 
     10228 
     10229% report non-portable arithmetic function calls in the body of object and category predicates 
     10230 
     10231'$lgt_report_non_portable_functions' :- 
     10232    '$lgt_compiler_flag'(portability, warning), 
     10233    setof(Functor/Arity, '$lgt_non_portable_function_'(Functor, Arity), Functions), 
     10234    '$lgt_inc_compile_warnings_counter', 
     10235    nl, 
     10236    (   Functions = [_] -> 
     10237        write('  WARNING!  Call to non-standard Prolog built-in arithmetic function: ') 
     10238    ;   write('  WARNING!  Calls to non-standard Prolog built-in arithmetic functions: ') 
     10239    ), 
     10240    '$lgt_writeq_list'(Functions), 
     10241    !. 
     10242 
     10243'$lgt_report_non_portable_functions'. 
    1015510244 
    1015610245 
     
    1270612795'$lgt_iso_spec_pred'(halt). 
    1270712796'$lgt_iso_spec_pred'(halt(_)). 
     12797 
     12798 
     12799 
     12800 
     12801%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
     12802% 
     12803%  table of ISO specified arithmetic functions 
     12804% 
     12805%  (used for portability checking) 
     12806% 
     12807%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
     12808 
     12809 
     12810 
     12811'$lgt_iso_spec_function'('-'(_)). 
     12812'$lgt_iso_spec_function'('+'(_, _)). 
     12813'$lgt_iso_spec_function'('-'(_, _)). 
     12814'$lgt_iso_spec_function'('*'(_, _)). 
     12815'$lgt_iso_spec_function'('/'(_, _)). 
     12816'$lgt_iso_spec_function'('//'(_, _)). 
     12817'$lgt_iso_spec_function'(rem(_, _)). 
     12818'$lgt_iso_spec_function'(mod(_, _)). 
     12819'$lgt_iso_spec_function'('/\\'(_, _)). 
     12820'$lgt_iso_spec_function'('\\/'(_, _)). 
     12821'$lgt_iso_spec_function'('\\'(_, _)). 
     12822'$lgt_iso_spec_function'('<<'(_, _)). 
     12823'$lgt_iso_spec_function'('>>'(_, _)). 
     12824'$lgt_iso_spec_function'('**'(_, _)). 
     12825 
     12826'$lgt_iso_spec_function'(abs(_)). 
     12827'$lgt_iso_spec_function'(sign(_)). 
     12828'$lgt_iso_spec_function'(sqrt(_)). 
     12829'$lgt_iso_spec_function'(atan(_)). 
     12830'$lgt_iso_spec_function'(cos(_)). 
     12831'$lgt_iso_spec_function'(sin(_)). 
     12832'$lgt_iso_spec_function'(exp(_)). 
     12833'$lgt_iso_spec_function'(log(_)). 
     12834'$lgt_iso_spec_function'(float(_)). 
     12835'$lgt_iso_spec_function'(ceiling(_)). 
     12836'$lgt_iso_spec_function'(floor(_)). 
     12837'$lgt_iso_spec_function'(round(_)). 
     12838'$lgt_iso_spec_function'(truncate(_)). 
     12839'$lgt_iso_spec_function'(float_fractional_part(_)). 
     12840'$lgt_iso_spec_function'(float_integer_part(_)). 
    1270812841 
    1270912842 
  • trunk/manuals/index.html

    r4212 r4213  
    3232    <div class="copyright"> 
    3333        <span>Copyright &copy; <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> &mdash; <a href="http://logtalk.org">Logtalk.org</a></span><br/>  
    34         <span>Last updated on: April 19, 2008</span> 
     34        <span>Last updated on: April 21, 2008</span> 
    3535    </div> 
    3636    <div class="navbottom"> 
  • trunk/manuals/userman/errors.html

    r3650 r4213  
    9090 
    9191<p> 
    92 A warning will be reported if a predicate clause contains a call to a non-ISO defined built-in predicate. 
     92A warning will be reported if a predicate clause contains a call to a non-ISO specified built-in predicate or to a non-ISO specified arithmetic function. 
    9393</p> 
    9494 
     
    126126    <div class="copyright"> 
    127127        <span>Copyright &copy; <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> &mdash; <a href="http://logtalk.org">Logtalk.org</a></span><br/>  
    128         <span>Last updated on: April 14, 2007</span> 
     128        <span>Last updated on: April 21, 2008</span> 
    129129    </div> 
    130130    <div class="navbottom"> 
  • trunk/manuals/userman/index.html

    r4206 r4213  
    302302    <div class="copyright"> 
    303303        <span>Copyright &copy; <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> &mdash; <a href="http://logtalk.org">Logtalk.org</a></span><br/> 
    304         <span>Last updated on: April 9, 2008</span> 
     304        <span>Last updated on: April 21, 2008</span> 
    305305    </div> 
    306306    <div class="navbottom"> 
  • trunk/manuals/userman/predicates.html

    r4194 r4213  
    660660</p> 
    661661<p> 
    662 When calling non-standard Prolog built-in predicates, you may run into portability problems while trying your applications with different back-end Prolog compilers (non-standard predicates are often specific to a Prolog compiler). You may use the Logtalk compiler flag <a title="Consult user manual" href="running.html#options"><code>portability/1</code></a> to help check for problematic calls in your code. 
     662When calling non-standard Prolog built-in predicates or using non-standard Prolog arithmetic functions, you may run into portability problems while trying your applications with different back-end Prolog compilers (non-standard predicates and non-standard arithmetic functions are often specific to a Prolog compiler). You may use the Logtalk compiler flag <a title="Consult user manual" href="running.html#options"><code>portability/1</code></a> to help check for problematic calls in your code. 
    663663</p> 
    664664 
     
    676676    <div class="copyright"> 
    677677        <span>Copyright &copy; <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> &mdash; <a href="http://logtalk.org">Logtalk.org</a></span><br/>  
    678         <span>Last updated on: April 7, 2008</span> 
     678        <span>Last updated on: April 21, 2008</span> 
    679679    </div> 
    680680    <div class="navbottom"> 
  • trunk/manuals/userman/programming.html

    r4039 r4213  
    9999 
    100100<p> 
    101 Logtalk is compatible with almost all modern Prolog compilers. However, this does not necessarily imply that your Logtalk programs will have the same level of portability. If possible, you should only use in your programs Logtalk built-in predicates and ISO Prolog defined built-in predicates. If you need to use built-in predicates that may not be available in other Prolog compilers, you should try to encapsulate the non-portable code in a small number of objects and provide a portable <strong>interface</strong> for that code through the use of Logtalk protocols. An example will be code that access operating-system specific features. The Logtalk compiler can warn you of the use of non-ISO defined built-in predicates by using the <code>portability/1</code> compiler flag. 
     101Logtalk is compatible with almost all modern Prolog compilers. However, this does not necessarily imply that your Logtalk programs will have the same level of portability. If possible, you should only use in your programs Logtalk built-in predicates and ISO Prolog specified built-in predicates and arithmetic functions. If you need to use built-in predicates (or built-in arithmetic functions) that may not be available in other Prolog compilers, you should try to encapsulate the non-portable code in a small number of objects and provide a portable <strong>interface</strong> for that code through the use of Logtalk protocols. An example will be code that access operating-system specific features. The Logtalk compiler can warn you of the use of non-ISO specified built-in predicates and arithmetic functions by using the <code>portability/1</code> compiler flag. 
    102102</p> 
    103103 
     
    123123</p> 
    124124 
    125 <h3 id="programming_style">Coding style guidlines</h3> 
     125<h3 id="programming_style">Coding style guidelines</h3> 
    126126 
    127127<p> 
     
    163163    <div class="copyright"> 
    164164        <span>Copyright &copy; <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> &mdash; <a href="http://logtalk.org">Logtalk.org</a></span><br/>  
    165         <span>Last updated on: January 21, 2008</span> 
     165        <span>Last updated on: April 21, 2008</span> 
    166166    </div> 
    167167    <div class="navbottom"> 
  • trunk/manuals/userman/running.html

    r4206 r4213  
    119119    <dl> 
    120120        <dt><code>portability(Option)</code></dt> 
    121             <dd>Controls the non-ISO specified built-in predicate calls warnings. Possible option values are <code>warning</code> and <code>silent</code> (the usual default).</dd> 
     121            <dd>Controls the non-ISO specified built-in predicate and non-ISO specified built-in arithmetic function calls warnings. Possible option values are <code>warning</code> and <code>silent</code> (the usual default).</dd> 
    122122    </dl> 
    123123    <dl> 
     
    515515    <div class="copyright"> 
    516516        <span>Copyright &copy; <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> &mdash; <a href="http://logtalk.org">Logtalk.org</a></span><br/>  
    517         <span>Last updated on: April 9, 2008</span> 
     517        <span>Last updated on: April 21, 2008</span> 
    518518    </div> 
    519519    <div class="navbottom"> 
  • trunk/manuals/userman/userman.header

    r4212 r4213  
    3636        <span>http://logtalk.org/</span> 
    3737    </p> 
    38     <p class="date">Last updated on April 19, 2008</p> 
     38    <p class="date">Last updated on April 21, 2008</p> 
    3939</div> 
    4040 
  • trunk/RELEASE_NOTES.txt

    r4210 r4213  
    1212 
    13132.31.5 - April ??, 2008 
     14 
     15    Added support for checking arithmetic expressions for calls to  
     16    non-portable function calls when using the "portability" compiler  
     17    flag. 
    1418 
    1519    Updated the implementation of the threaded/1 built-in predicate to