>>> "SIGOURE" == SIGOURE Benoit <sigoure.benoit(a)lrde.epita.fr> writes:
> /!\ Backward compatibility broken!
What do you mean by "broken"? Should I read "b0rken"?
I would like to suggest that for-from loops be sugar for for-in
loops.
I would like to suggest the possibility to use ranges with for-in
loops, which might already be the case.
Finally, I suggest supporting Cartesian products of ranges.
Finally, I suggest that
for x from 0 to X - 1 do
for y from 0 to Y - 1 do
could be written as
for (x, y) in (0 .. X - 1, 0 .. Y - 1)
or something like that. Maybe
for x, y in 0 .. X - 1 x 0 .. Y - 1
where x is the Cartesian product? Nah. Make them tuples? I.e., use
[] again?
for x, y in [0 .. X - 1][0 .. Y - 1]
I like this, since it basically means that arrays are nothing both
variables indexed over ranges that can now be multidimensional.
Je pense qu'il faut vraiment généraliser l'existence des ranges, voire
même, peut-être, introduire un type range. En tous les cas, il me
semble que les rand devraient prendre un range, et du coup, au lieu de
rand (42, 51)
il faudrait écrire
rand (42 .. 51)
et, tu l'auras compris
rand (42)
donne toujours 42, et
rand (42, 51)
renvoie soit 42, soit 51.
>>> "SIGOURE" == SIGOURE Benoit <sigoure.benoit(a)lrde.epita.fr> writes:
> NOTE for rivf.xpm: `X' is a reserved keyword in PRISM (!).
Are you sure? I'd say it is in the properties section.
>>> "SIGOURE" == SIGOURE Benoit <sigoure.benoit(a)lrde.epita.fr> writes:
> Add declaration lists.
Am I understanding this is an XRM feature, not an RM feature?
https://svn.lrde.epita.fr/svn/xrm/trunk
Index: ChangeLog
from SIGOURE Benoit <sigoure.benoit(a)lrde.epita.fr>
Detect overlapping declarations of arrays.
Consider the following case:
x[1][1] : [0..2] init 2;
x[1][1,2] : [0..3] init 3;
Here, we're declaring the array `x' in two parts. As we can see, the
second part overlaps with the first. Moreover the, overlapping part
has a different definition in both declarations. This is now caught
and reported as an error.
* src/str/array-decl-desugar.str: Detect overlapping declarations.
* doc/user-guide.txt: Bring up to date.
doc/user-guide.txt | 2 -
src/str/array-decl-desugar.str | 48 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 47 insertions(+), 3 deletions(-)
Index: src/str/array-decl-desugar.str
--- src/str/array-decl-desugar.str (revision 80)
+++ src/str/array-decl-desugar.str (working copy)
@@ -33,13 +33,57 @@
*/
<fetch-idf> array-access => idf
; <desugar-array-access> array-access => aa-list
- ; rules(DeclaredIdentifier: Identifier(idf) -> aa-list)
- ; desugared-array-access-list-to-identifier-list(|idf)
+ ; where(check-decl-overlaps-previous-decl(|idf, aa-list) => old-aa-list)
+ ; <conc>(old-aa-list, aa-list) => new-aa-list
+ ; rules(DeclaredIdentifier: Identifier(idf) -> new-aa-list)
+ ; <desugared-array-access-list-to-identifier-list(|idf)> aa-list
; map({var-name:
?var-name
; <build-dec(|var-name)> data
})
+ /** @internal
+ ** Check whether the current array declaration overlaps with a previous
+ ** array declaration. The dimensions declared in the current decl are
+ ** in aa-list. We fetch previously declared dimensions (if any) using the
+ ** DR DeclaredIdentifier. If one of the dimensions in aa-list is the same
+ ** as one of those previously declared, the current declaration overlaps
+ ** with a previous one (=> error!).
+ **
+ ** @return the list of previously declared dimensions (if any) or an empty
+ ** list otherwise.
+ */
+ check-decl-overlaps-previous-decl(|idf, aa-list) =
+ if <DeclaredIdentifier> Identifier(idf) => old-aa-list then
+ /* Here old-aa-list contains the dimensions already defined for `idf'. */
+ if !old-aa-list => [_|_] then // if the list is not empty ...
+ /* ... then we already had a definition for that idf, check that
+ * both definitions don't overlap. */
+ !old-aa-list
+ /* ok now we must check if one of the dimensions in aa-list is
+ * also present in the current term (which is list of dimensions
+ * already defined). If one of them is present in both lists, the
+ * current definition overlaps a former definition. */
+ ; map({old-dim:
+ ?old-dim // for each old-dim in old-aa-list...
+ /* ... check whether old-dim is somewhere in aa-list */
+ ; <map(try(?old-dim; error-overlapping-dim(|idf, aa-list)))> aa-list
+ })
+ ; !old-aa-list
+ else // return an empty list
+ ![]
+ end
+ else // ditto.
+ ![]
+ end
+
+ error-overlapping-dim(|idf, aa-list) =
+ err-msg(|["Invalid declaration of array `", idf, "'. This array is ",
+ "declared in multiple parts which overlap."])
+ ; debug(!"Overlapping dimension: ")
+ ; <debug(!"Dimensions already declared for that array: ")> aa-list
+ ; <xtc-exit> 5
+
/** Builders. */
rules
Index: doc/user-guide.txt
--- doc/user-guide.txt (revision 80)
+++ doc/user-guide.txt (working copy)
@@ -101,7 +101,7 @@
- 2: error with meta-vars (eg: undefined meta-var, redefined meta-var)
- 3: arithmetic error when evaluating code (eg: division/modulo by 0)
- 4: invalid call to a builtin (eg: rand(1,2,3))
- - 5: invalid array access (eg: subscript is not a positive integer)
+ - 5: errors related with arrays (eg: subscript is not a positive integer)
- 6: invalid call to a parameterized formula (eg: not enough arguments)
- 42: internal compiler error (please send a bug report)
- 51: not yet implemented