https://svn.lrde.epita.fr/svn/xrm/trunk
Index: ChangeLog
from SIGOURE Benoit <sigoure.benoit(a)lrde.epita.fr>
Simplify XRM's grammar.
The constructors for meta for loops and meta ifs had each two
different names depending whether they were found at top-level or
inside modules. This turned out to be a bad idea because it was
completely unecessary and made transformations harder (because
multiple different cases had to be addressed where a single one could
be enough).
From now on we also stop saying "static" for loops or "static" if
because "meta" seems more appropriate to qualify them and it sounds
better (buzzword inside! :P)
* src/lib/xrm/pp/xrm-staticif.str: Rename as...
* src/lib/xrm/pp/xrm-meta-if.str: This.
* src/lib/xrm/pp/xrm-staticfor.str: Rename as...
* src/lib/xrm/pp/xrm-meta-for.str: This. Allow for loops to have an
empty body.
* src/lib/xrm/pp/xrm-staticfor.meta: Rename as...
* src/lib/xrm/pp/xrm-meta-for.meta: This.
* src/lib/xrm/pp/xrm-staticif.meta: Rename as...
* src/lib/xrm/pp/xrm-meta-if.meta: This.
* src/lib/xrm/pp/xrm-to-abox.str: Update imports accordingly.
* src/str/xrm-front.str: Correct a typo.
* src/str/xrm-to-prism.str: Simplify the rules according to the above
grammar changes + s/static/meta/g
* src/syn/xrm/XRM-StaticIf.sdf: Rename as...
* src/syn/xrm/XRM-MetaIf.sdf: This.
* src/syn/xrm/XRM-StaticFor.sdf: Rename as...
* src/syn/xrm/XRM-MetaFor.sdf: This.
* src/syn/xrm/XRM-Main.sdf: Update imports accordingly.
* src/syn/xrm/StrategoXRM.sdf: Ditto + fix meta-vars.
* tests/xrm/inner-static-if.xpm: Reduce the number of iterations to
reduce the time needed to run make test and make the output more
human readable.
* tests/xrm/inner-static-for-step.xpm,
* tests/xrm/outer-static-if.xpm,
* tests/xrm/outer-static-for-step.xpm,
* tests/xrm/static-if.xpm,
* tests/xrm/inner-static-for.xpm,
* tests/xrm/static-for-step.xpm,
* tests/xrm/outer-static-for.xpm,
* tests/xrm/static-for.xpm: Ditto.
src/lib/xrm/pp/xrm-meta-for.str | 41 +++++++-----------------------
src/lib/xrm/pp/xrm-meta-if.str | 19 ++-----------
src/lib/xrm/pp/xrm-to-abox.str | 4 +-
src/str/xrm-front.str | 2 -
src/str/xrm-to-prism.str | 49 +++++++++++++-----------------------
src/syn/xrm/StrategoXRM.sdf | 13 +++++----
src/syn/xrm/XRM-Main.sdf | 4 +-
src/syn/xrm/XRM-MetaFor.sdf | 24 ++++++++---------
src/syn/xrm/XRM-MetaIf.sdf | 13 +++++----
tests/xrm/inner-static-for-step.xpm | 2 -
tests/xrm/inner-static-for.xpm | 2 -
tests/xrm/inner-static-if.xpm | 4 +-
tests/xrm/outer-static-for-step.xpm | 2 -
tests/xrm/outer-static-for.xpm | 2 -
tests/xrm/outer-static-if.xpm | 4 +-
tests/xrm/static-for-step.xpm | 4 +-
tests/xrm/static-for.xpm | 4 +-
tests/xrm/static-if.xpm | 8 ++---
18 files changed, 80 insertions(+), 121 deletions(-)
Index: src/lib/xrm/pp/xrm-to-abox.str
--- src/lib/xrm/pp/xrm-to-abox.str (revision 27)
+++ src/lib/xrm/pp/xrm-to-abox.str (working copy)
@@ -21,8 +21,8 @@
xrm-parenthesize
xrm-expression
xrm-module
- xrm-staticfor
- xrm-staticif
+ xrm-meta-for
+ xrm-meta-if
xrm-arrays
strategies
Index: src/lib/xrm/pp/xrm-meta-for.str
--- src/lib/xrm/pp/xrm-meta-for.str (revision 27)
+++ src/lib/xrm/pp/xrm-meta-for.str (working copy)
@@ -1,11 +1,13 @@
-module xrm-staticfor
+module xrm-meta-for
rules
- // "for" Identifier "from" Int "to" Int "do"
ModulesFileSection+ "end"
- // -> OuterStaticFor
+ // "for" Identifier "from" Int "to" Int "do"
ModulesFileSection* "end"
+ // -> MetaFor
+ // "for" Identifier "from" Int "to" Int "do"
DeclarationOrCommand* "end"
+ // -> MetaFor
prism-to-box:
- OuterStaticFor(idf, for-from, for-to, mfs-list)
+ MetaFor(idf, for-from, for-to, mfs-list)
-> box |[ V[ V is=2 [
H hs=1 [ KW["for"] ~idf
KW["from"] ~for-from
@@ -15,39 +17,16 @@
] ]|
// "for" Identifier "from" Int "to" Int "step"
Int "do"
- // ModulesFileSection+ "end" -> OuterStaticFor
- prism-to-box:
- OuterStaticFor(idf, for-from, for-to, for-step, mfs-list)
- -> box |[ V[ V is=2 [
- H hs=1 [ KW["for"] ~idf
- KW["from"] ~for-from
- KW["to"] ~for-to
- KW["step"] ~for-step KW["do"] ]
- ~*mfs-list // in the innermost V box
- ] KW["end"] // in the outermost V box
- ] ]|
-
- // "for" Identifier "from" Int "to" Int "do"
DeclarationOrCommand+ "end"
- // -> InnerStaticFor
- prism-to-box:
- InnerStaticFor(idf, for-from, for-to, dec-or-cmd-list)
- -> box |[ V[ V is=2 [
- H hs=1 [ KW["for"] ~idf
- KW["from"] ~for-from
- KW["to"] ~for-to KW["do"] ]
- ~*dec-or-cmd-list // in the innermost V box
- ] KW["end"] // in the outermost V box
- ] ]|
-
+ // ModulesFileSection* "end" -> MetaFor
// "for" Identifier "from" Int "to" Int "step"
Int "do"
- // DeclarationOrCommand+ "end" -> InnerStaticFor
+ // DeclarationOrCommand* "end" -> MetaFor
prism-to-box:
- InnerStaticFor(idf, for-from, for-to, for-step, dec-or-cmd-list)
+ MetaFor(idf, for-from, for-to, for-step, mfs-list)
-> box |[ V[ V is=2 [
H hs=1 [ KW["for"] ~idf
KW["from"] ~for-from
KW["to"] ~for-to
KW["step"] ~for-step KW["do"] ]
- ~*dec-or-cmd-list // in the innermost V box
+ ~*mfs-list // in the innermost V box
] KW["end"] // in the outermost V box
] ]|
Index: src/lib/xrm/pp/xrm-meta-if.str
--- src/lib/xrm/pp/xrm-meta-if.str (revision 27)
+++ src/lib/xrm/pp/xrm-meta-if.str (working copy)
@@ -1,28 +1,15 @@
-module xrm-staticif
+module xrm-meta-if
rules
prism-to-box:
- OuterStaticIf(condition, then-part)
+ MetaIf(condition, then-part)
-> V[ V is=2 [ H hs=1 [ KW["if"] ~condition KW["then"] ]
~*then-part ]
KW["end"]]
prism-to-box:
- OuterStaticIf(condition, then-part, else-part)
- -> V[ V is=2 [ H hs=1 [ KW["if"] ~condition KW["then"] ]
- ~*then-part ]
- V is=2 [ KW["else"] ~*else-part ]
- KW["end"]]
-
- prism-to-box:
- InnerStaticIf(condition, then-part)
- -> V[ V is=2 [ H hs=1 [ KW["if"] ~condition KW["then"] ]
- ~*then-part ]
- KW["end"]]
-
- prism-to-box:
- InnerStaticIf(condition, then-part, else-part)
+ MetaIf(condition, then-part, else-part)
-> V[ V is=2 [ H hs=1 [ KW["if"] ~condition KW["then"] ]
~*then-part ]
V is=2 [ KW["else"] ~*else-part ]
Index: src/str/xrm-front.str
--- src/str/xrm-front.str (revision 27)
+++ src/str/xrm-front.str (working copy)
@@ -142,7 +142,7 @@
<tool-doc>
[ Usage("xrm-front [OPTIONS]")
, Summary("Transforms an eXtended Reactive Module source file in a
- PRISM-equivalant abstract syntax tree (default) or source
+ PRISM-equivalent abstract syntax tree (default) or source
code. (see option -P)")
, OptionUsage()
, AutoReportBugs()
Index: src/str/xrm-to-prism.str
--- src/str/xrm-to-prism.str (revision 27)
+++ src/str/xrm-to-prism.str (working copy)
@@ -13,7 +13,7 @@
* and that they are not redefined twice in the same scope */
; check-meta-vars
- /* unroll static loops, eval static if */
+ /* unroll meta loops, eval meta if */
; eval-meta-code
/* flatten nested lists */
@@ -35,20 +35,13 @@
|[ e1 << e2 ]| -> |[ e1 * func(pow, 2, e2) ]|
xrm-to-prism-desugar:
- OuterStaticFor(identifier, from, to, body)
- -> OuterStaticFor(identifier, from, to, Int("1"), body)
-
- xrm-to-prism-desugar:
- InnerStaticFor(identifier, from, to, body)
- -> InnerStaticFor(identifier, from, to, Int("1"), body)
+ MetaFor(identifier, from, to, body)
+ -> MetaFor(identifier, from, to, Int("1"), body)
xrm-to-prism-desugar:
//|[ if e then m* end ]| -> |[ if e then m* else end ]|
- OuterStaticIf(e, m*) -> OuterStaticIf(e, m*, [])
-
- xrm-to-prism-desugar:
//|[ if e then s* end ]| -> |[ if e then s* else end ]|
- InnerStaticIf(e, s*) -> InnerStaticIf(e, s*, [])
+ MetaIf(e, m*) -> MetaIf(e, m*, [])
rules
@@ -76,7 +69,7 @@
** @param access-list List of Int()
*/
flatten-access-list(|idf, access-list) =
- /* eval static expressions in the access-list
+ /* eval meta expressions in the access-list
* eg: Plus(Int("1"), Int("2")) -> Int("3") */
<prism-desugar> access-list
@@ -149,15 +142,14 @@
strategies
check-meta-vars =
- check-static-for
- <+ check-static-if
+ check-meta-for
+ <+ check-meta-if
<+ ArrayAccess(id, check-all-identifers-are-meta-vars)
<+ ArrayAccessPrime(id, check-all-identifers-are-meta-vars)
<+ all(check-meta-vars)
- check-static-for =
- (?OuterStaticFor(new-meta-var, from, to, step, body)
- <+ ?InnerStaticFor(new-meta-var, from, to, step, body))
+ check-meta-for =
+ ?MetaFor(new-meta-var, from, to, step, body)
; where({| MetaVars:
<add-meta-var> new-meta-var
; <check-all-identifers-are-meta-vars> from
@@ -166,9 +158,8 @@
; <check-meta-vars> body
|})
- check-static-if =
- (?OuterStaticIf(condition, then-part, else-part)
- <+ ?InnerStaticIf(condition, then-part, else-part))
+ check-meta-if =
+ ?MetaIf(condition, then-part, else-part)
; where(
<check-all-identifers-are-meta-vars> condition
; <check-meta-vars> then-part
@@ -202,14 +193,13 @@
eval-meta-code =
eval-meta-if
- <+ unroll-static-loops
+ <+ unroll-meta-loops
<+ all(eval-meta-code)
strategies
eval-meta-if =
- (?OuterStaticIf(condition, then-part, else-part)
- <+ ?InnerStaticIf(condition, then-part, else-part))
+ ?MetaIf(condition, then-part, else-part)
/*DEBUG*/; say(!" @@@ eval-meta-if: starting:")
/*DEBUG*/; printf(|" condition = ", condition)
; where(<prism-desugar> condition => condition-value)
@@ -226,22 +216,21 @@
strategies
- unroll-static-loops =
- (?OuterStaticFor(meta-var, Int(from), Int(to), Int(step), body)
- <+ ?InnerStaticFor(meta-var, Int(from), Int(to), Int(step), body))
+ unroll-meta-loops =
+ ?MetaFor(meta-var, Int(from), Int(to), Int(step), body)
; where(check-loop-validity(|meta-var, from, to))
; {| MetaCode:
- /*DEBUG*/say(!" @@@ unroll-static-loops: starting:")
+ /*DEBUG*/say(!" @@@ unroll-meta-loops: starting:")
/*DEBUG*/; printf(|" meta-var = ", meta-var)
/*DEBUG*/; printf(|" from = ", from)
/*DEBUG*/; printf(|" to = ", to)
; where(<check-meta-var-unicity> meta-var)
; for-loop(gen-meta-code | from, to, step, [])
- /*DEBUG*/; say(!" ~~~ unroll-static-loops: before bagof-MetaModule")
+ /*DEBUG*/; say(!" ~~~ unroll-meta-loops: before bagof-MetaModule")
/*DEBUG*/; debug
; bagof-MetaCode
; reverse
- /*DEBUG*/; say(!" ~~~ unroll-static-loops: after bagof-MetaModule")
+ /*DEBUG*/; say(!" ~~~ unroll-meta-loops: after bagof-MetaModule")
/*DEBUG*/; debug
|}
@@ -258,7 +247,7 @@
gen-meta-code(|i, args) =
/*DEBUG*/say(!" ### gen-meta-code starting"); debug;
- (?for-kind#([meta-var, _, _, _, body]) <+ fatal-err-msg(|"ICE!"))
+ (?MetaFor(meta-var, _, _, _, body) <+ fatal-err-msg(|"ICE!"))
/*DEBUG*/; say(!" >>> gen-meta-code -- start -- current term
>>>")
/*DEBUG*/; debug
/*DEBUG*/; say(!" >>> gen-meta-code -- start -- iterator
>>>")
Index: src/syn/xrm/XRM-MetaIf.sdf
--- src/syn/xrm/XRM-MetaIf.sdf (revision 27)
+++ src/syn/xrm/XRM-MetaIf.sdf (working copy)
@@ -1,10 +1,10 @@
-module XRM-StaticIf
+module XRM-MetaIf
imports
PRISM-to-XRM
XRM-Module
exports
- %% EBNF Grammar: Static if-then-else
+ %% EBNF Grammar: Meta if-then-else
%% (* if-then-else at top-level *)
%% ModulesFileSection ::=
%% "if" Expression "then" ModulesFileSection
{ModulesFileSection} "end"
@@ -14,6 +14,7 @@
%% ModulesFileSection {ModulesFileSection}
%% "end"
%%
+ %% (* if-then-else inside modules *)
%% DeclarationOrCommand ::=
%% "if" Expression "then" DeclarationOrCommand
{DeclarationOrCommand} "end"
%% | "if" Expression "then"
@@ -25,23 +26,23 @@
context-free syntax
%% if-then at top-level
"if" Expression "then" ModulesFileSection* "end"
- -> ModulesFileSection {cons("OuterStaticIf")}
+ -> ModulesFileSection {cons("MetaIf")}
%% if-then-else at top-level
"if" Expression "then"
ModulesFileSection*
"else"
ModulesFileSection*
- "end" -> ModulesFileSection {cons("OuterStaticIf")}
+ "end" -> ModulesFileSection {cons("MetaIf")}
context-free syntax
%% if-then within modules
"if" Expression "then" DeclarationOrCommand* "end"
- -> DeclarationOrCommand {cons("InnerStaticIf")}
+ -> DeclarationOrCommand {cons("MetaIf")}
%% if-then-else within modules
"if" Expression "then"
DeclarationOrCommand*
"else"
DeclarationOrCommand*
- "end" -> DeclarationOrCommand {cons("InnerStaticIf")}
+ "end" -> DeclarationOrCommand {cons("MetaIf")}
Index: src/syn/xrm/StrategoXRM.sdf
--- src/syn/xrm/StrategoXRM.sdf (revision 27)
+++ src/syn/xrm/StrategoXRM.sdf (working copy)
@@ -6,6 +6,8 @@
PRISM-MetaCongruences
XRM-MetaVars
XRM-MetaCongruences
+ XRM-MetaFor
+ XRM-MetaIf
exports
context-free start-symbols StrategoModule
@@ -17,13 +19,14 @@
"|[" Expression "]|" -> StrategoTerm
{prefer,cons("ToTerm")}
"|[" Declaration "]|" -> StrategoTerm
{prefer,cons("ToTerm")}
"|[" Command "]|" -> StrategoTerm
{prefer,cons("ToTerm")}
- "|[" OuterStaticFor "]|" -> StrategoTerm
{prefer,cons("ToTerm")}
- "|[" InnerStaticFor "]|" -> StrategoTerm
{prefer,cons("ToTerm")}
+ "|[" MetaFor "]|" -> StrategoTerm
{prefer,cons("ToTerm")}
+ "|[" MetaIf "]|" -> StrategoTerm
{prefer,cons("ToTerm")}
context-free syntax
"~" StrategoTerm -> Expression {prefer,cons("FromTerm")}
- "~id:" StrategoTerm -> Identifier {prefer,cons("FromTerm")}
+ "~id:" StrategoTerm -> ID {prefer,cons("FromTerm")}
+ %% FIXME: the following rule is b0rken
"~id':" StrategoTerm -> IdentifierPrime
{prefer,cons("FromTerm")}
- "~int:" StrategoTerm -> Int {prefer,cons("FromTerm")}
- "~double:" StrategoTerm -> Double {prefer,cons("FromTerm")}
+ "~int:" StrategoTerm -> LInt {prefer,cons("FromTerm")}
+ "~double:" StrategoTerm -> LDouble {prefer,cons("FromTerm")}
Index: src/syn/xrm/XRM-Main.sdf
--- src/syn/xrm/XRM-Main.sdf (revision 27)
+++ src/syn/xrm/XRM-Main.sdf (working copy)
@@ -3,8 +3,8 @@
PRISM-to-XRM
XRM-Module
XRM-Expression
- XRM-StaticFor
- XRM-StaticIf
+ XRM-MetaFor
+ XRM-MetaIf
XRM-Literals
XRM-Declaration
XRM-Update
Index: src/syn/xrm/XRM-MetaFor.sdf
--- src/syn/xrm/XRM-MetaFor.sdf (revision 27)
+++ src/syn/xrm/XRM-MetaFor.sdf (working copy)
@@ -1,33 +1,33 @@
-module XRM-StaticFor
+module XRM-MetaFor
imports
PRISM-to-XRM
XRM-Module
exports
- %% EBNF Grammar: Static For Loops
- %% (* Static For loops at the top level *)
+ %% EBNF Grammar: Meta For Loops
+ %% (* Meta For loops at the top level *)
%% ModulesFileSection ::=
%% "for" Identifier "from" Int "to" Int
["step" Int] "do"
%% {ModulesFileSection} "end"
%%
- %% (* Static For loops inside modules *)
+ %% (* Meta For loops inside modules *)
%% DeclarationOrCommand ::=
%% "for" Identifier "from" Int "to" Int
["step" Int] "do"
%% {DeclarationOrCommand} "end"
context-free syntax
- %% OuterStaticFor can be found only at top-level
+ %% This MetaFor can be found only at top-level
%% So we can see it as a ModulesFileSection
- "for" Identifier "from" Int "to" Int "do"
ModulesFileSection+ "end"
- -> ModulesFileSection {cons("OuterStaticFor")}
+ "for" Identifier "from" Int "to" Int "do"
ModulesFileSection* "end"
+ -> ModulesFileSection {cons("MetaFor")}
"for" Identifier "from" Int "to" Int "step"
Int "do"
- ModulesFileSection+ "end" -> ModulesFileSection
{cons("OuterStaticFor")}
+ ModulesFileSection* "end" -> ModulesFileSection
{cons("MetaFor")}
- %% InnerStaticFor can be found only inside Modules
+ %% This MetaFor can be found only inside Modules
%% So we can see it as a DeclarationOrCommand
- "for" Identifier "from" Int "to" Int "do"
DeclarationOrCommand+ "end"
- -> DeclarationOrCommand {cons("InnerStaticFor")}
+ "for" Identifier "from" Int "to" Int "do"
DeclarationOrCommand* "end"
+ -> DeclarationOrCommand {cons("MetaFor")}
"for" Identifier "from" Int "to" Int "step"
Int "do"
- DeclarationOrCommand+ "end" -> DeclarationOrCommand
{cons("InnerStaticFor")}
+ DeclarationOrCommand* "end" -> DeclarationOrCommand
{cons("MetaFor")}
Index: tests/xrm/inner-static-if.xpm
--- tests/xrm/inner-static-if.xpm (revision 27)
+++ tests/xrm/inner-static-if.xpm (working copy)
@@ -1,8 +1,8 @@
probabilistic
module dummy
- for i from 0 to 42 do
- if i=0 | i=42 then
+ for i from 0 to 4 do
+ if i=0 | i=4 then
x[i] : [0..2];
else
x[i] : [0..1];
Index: tests/xrm/inner-static-for-step.xpm
--- tests/xrm/inner-static-for-step.xpm (revision 27)
+++ tests/xrm/inner-static-for-step.xpm (working copy)
@@ -1,7 +1,7 @@
probabilistic
module dummy
- for i from 0 to 42 step 2 do
+ for i from 0 to 4 step 2 do
x[i] : [0..1];
[] x[i]=0 -> x[i]'=1;
end
Index: tests/xrm/outer-static-if.xpm
--- tests/xrm/outer-static-if.xpm (revision 27)
+++ tests/xrm/outer-static-if.xpm (working copy)
@@ -1,7 +1,7 @@
probabilistic
-for i from 0 to 42 do
- if i<1 & i>41 then
+for i from 0 to 4 do
+ if i<1 | i>2 then
module dummy[i]
x[i] : [0..1];
[] x[i]=0 -> x[i]'=1;
Index: tests/xrm/outer-static-for-step.xpm
--- tests/xrm/outer-static-for-step.xpm (revision 27)
+++ tests/xrm/outer-static-for-step.xpm (working copy)
@@ -1,6 +1,6 @@
probabilistic
-for i from 0 to 42 step 2 do
+for i from 0 to 4 step 2 do
module dummy[i]
x[i] : [0..1];
[] x[i]=0 -> x[i]'=1;
Index: tests/xrm/static-if.xpm
--- tests/xrm/static-if.xpm (revision 27)
+++ tests/xrm/static-if.xpm (working copy)
@@ -1,10 +1,10 @@
probabilistic
-for i from 0 to 42 do
- if i<1 & i>41 then
+for i from 0 to 4 do
+ if i<1 | i>=3 then
module dummy[i]
- for j from 0 to 42 do
- if i=0 | i=42 then
+ for j from 6 to 10 do
+ if i=0 | i+j=7 then
x[i][j] : [0..2];
else
x[i][j] : [0..1];
Index: tests/xrm/inner-static-for.xpm
--- tests/xrm/inner-static-for.xpm (revision 27)
+++ tests/xrm/inner-static-for.xpm (working copy)
@@ -1,7 +1,7 @@
probabilistic
module dummy
- for i from 0 to 42 do
+ for i from 0 to 4 do
x[i] : [0..1];
[] x[i]=0 -> x[i]'=1;
end
Index: tests/xrm/static-for-step.xpm
--- tests/xrm/static-for-step.xpm (revision 27)
+++ tests/xrm/static-for-step.xpm (working copy)
@@ -1,8 +1,8 @@
probabilistic
-for i from 0 to 42 step 2 do
+for i from 0 to 4 step 2 do
module dummy[i]
- for j from 0 to 42 step 2 do
+ for j from 6 to 10 step 2 do
x[i][j] : [0..1];
[] x[i][j]=0 -> x[i][j]'=1;
end
Index: tests/xrm/outer-static-for.xpm
--- tests/xrm/outer-static-for.xpm (revision 27)
+++ tests/xrm/outer-static-for.xpm (working copy)
@@ -1,6 +1,6 @@
probabilistic
-for i from 0 to 42 do
+for i from 0 to 4 do
module dummy[i]
x[i] : [0..1];
[] x[i]=0 -> x[i]'=1;
Index: tests/xrm/static-for.xpm
--- tests/xrm/static-for.xpm (revision 27)
+++ tests/xrm/static-for.xpm (working copy)
@@ -1,8 +1,8 @@
probabilistic
-for i from 0 to 42 do
+for i from 0 to 4 do
module dummy[i]
- for j from 0 to 42 do
+ for j from 6 to 10 do
x[i][j] : [0..1];
[] x[i][j]=0 -> x[i][j]'=1;
end