Evaluating of constant expressions at compile time
A constant expression can have arithmetic operations, (almost?) any intrinsic function etc. Such expressions can be used in defining parameters, such as:
integer, parameter :: dp = kind(0.d0)
real(dp), parameter :: pi = 4 * atan(1.0_dp)
Such expressions should be evaluated in ast_to_src.cpp
when encountered. Intrinsic functions should be called from the runtime library (at compile time). One can have a higher accuracy versions of functions like atan
(GFortran does it that way).
The evaluated version (possibly with the unevaluated version) should be stored in ASR. Then when it is referenced, say in real(dp)
, one does not have to evaluate it anymore, and simply obtains the evaluated value right away from ASR.
Edited by Ondřej Čertík