https://svn.lrde.epita.fr/svn/xrm/trunk
Index: ChangeLog
from SIGOURE Benoit <sigoure.benoit(a)lrde.epita.fr>
Fix static_rand.
* src/str/xrm-to-prism.str: Evaluate static_rand calls at the end of
the transformation pipeline (that is, after meta-code evaluation).
* src/str/prism-desugar.str: Evaluate static_rand in prism-desugar.
* src/str/builtin-rand.str: Introduce EvalStaticRand.
* TODO: Add something to do.
TODO | 3 +++
src/str/builtin-rand.str | 2 +-
src/str/prism-desugar.str | 2 ++
src/str/xrm-to-prism.str | 2 +-
4 files changed, 7 insertions(+), 2 deletions(-)
Index: src/str/xrm-to-prism.str
--- src/str/xrm-to-prism.str (revision 49)
+++ src/str/xrm-to-prism.str (working copy)
@@ -78,7 +78,7 @@
* This must come AFTER collect-static-const-decl since we might need
* to expand an arrays which rely on static const variables.
*/
- ; topdown(try(array-decl-desugar))
+ ; topdown(try(array-decl-desugar); try(EvalStaticRand))
; notice-msg(|"xrm-to-prism: array declarations desugared")
/* flatten nested lists */
Index: src/str/prism-desugar.str
--- src/str/prism-desugar.str (revision 49)
+++ src/str/prism-desugar.str (working copy)
@@ -2,6 +2,7 @@
imports
PRISM
reals
+ builtin-rand
strategies
@@ -25,6 +26,7 @@
<+ EvalLt <+ EvalLtEq <+ EvalGt <+ EvalGtEq <+ EvalEq <+
EvalNotEq
<+ EvalAnd <+ EvalOr
<+ EvalMin <+ EvalMax <+ EvalFloor <+ EvalCeil <+ EvalPow <+
EvalMod
+ <+ (EvalStaticRand; IntToDouble)
)
; topdown(try(SimplifyDoubles <+ TruncateDouble))
Index: src/str/builtin-rand.str
--- src/str/builtin-rand.str (revision 49)
+++ src/str/builtin-rand.str (working copy)
@@ -66,7 +66,7 @@
/* save this module in a DR for later retrieval */
; rules(RandGenModules:+ _ -> rand-gen-module)
- EvalRand:
+ EvalStaticRand:
StaticRand(args) -> Int(rand-val)
where check-rand-args(|"static_rand", args) => (from, to)
; rand(|<string-to-int> from, <string-to-int> to)
Index: TODO
--- TODO (revision 49)
+++ TODO (working copy)
@@ -30,6 +30,9 @@
static const int N = -1; will issue an error such as "undeclared meta
variable N" whereas the real problem is that array[N] couldn't be expanded.
+ * Rewrite src/lib/native/rand.c in Stratego. (This has been written in C
+ because I failed to make it work properly in Stratego :|)
+
## ---------- ##
## Extensions ##
## ---------- ##