ref: af63c8fc4082fca2b5148cb55a6870ac926660e4
parent: a2644d1d980e0f1c5439dce7764f0d051cf4cc41
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jan 6 19:10:17 EST 2019
Change indexed array literal syntax.
--- a/doc/lang.txt
+++ b/doc/lang.txt
@@ -998,7 +998,7 @@
tuplit: "(" tuplelts ")"
structelts: ("." ident "=" expr)+
- arrayelts: (expr ":" expr | expr)*
+ arrayelts: ("." "[" expr "]" "=" expr | expr)*
tupelts: expr ("," expr)* [","]
Sequence literals are used to initialize either a structure
@@ -1026,7 +1026,7 @@
An unindexed initializer sequence is simply a comma separated
list of values. An indexed initializer sequence contains a
- '#number=value' comma separated sequence, which indicates the
+ '.[index]=value' comma separated sequence, which indicates the
index of the array into which the value is inserted. A named
initializer sequence contains a comma separated list of
'.name=value' pairs.
@@ -1039,7 +1039,7 @@
[.a = 42, .b="str"]
Example: Array literal:
- [1,2,3], [2:3, 1:2, 0:1], []
+ [1,2,3], [.[2] = 3, .[1] = 2, .[0] = 1], []
Example: Tuple literals:
(1,), (1,'b',"three")
--- a/lib/crypto/x25519.myr
+++ b/lib/crypto/x25519.myr
@@ -477,14 +477,14 @@
* q: a point of the curve (short form)
*/
const cmult = {resultx, resultz, n, q
- var a : felem[19] = [0:0, 18:0]
- var b : felem[19] = [0:1, 18:0]
- var c : felem[19] = [0:1, 18:0]
- var d : felem[19] = [0:0, 18:0]
- var e : felem[19] = [0:0, 18:0]
- var f : felem[19] = [0:1, 18:0]
- var g : felem[19] = [0:0, 18:0]
- var h : felem[19] = [0:1, 18:0]
+ var a : felem[19] = [.[0] = 0, .[18] = 0]
+ var b : felem[19] = [.[0] = 1, .[18] = 0]
+ var c : felem[19] = [.[0] = 1, .[18] = 0]
+ var d : felem[19] = [.[0] = 0, .[18] = 0]
+ var e : felem[19] = [.[0] = 0, .[18] = 0]
+ var f : felem[19] = [.[0] = 1, .[18] = 0]
+ var g : felem[19] = [.[0] = 0, .[18] = 0]
+ var h : felem[19] = [.[0] = 1, .[18] = 0]
var nqpqx = a[:]
var nqpqz = b[:]
var nqx = c[:]
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -963,8 +963,8 @@
;
arrayelt: expr optendlns {$$ = $1;}
- | expr Tcolon expr optendlns {
- $$ = mkidxinit($2->loc, $1, $3);
+ | Tdot Tosqbrac expr Tcsqbrac Tasn expr optendlns {
+ $$ = mkidxinit($1->loc, $3, $6);
}
;
--- a/test/arraylit.myr
+++ b/test/arraylit.myr
@@ -2,6 +2,10 @@
/* checks we can make indexed array literals. exits with 3. */
const main = {
- var a = [0: 1, 2: 3, 1: 2]
+ var a = [
+ .[0] = 1,
+ .[2] = 3,
+ .[1] = 2,
+ ]
std.exit(a[2])
}