summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2019-01-07 00:10:17 -0800
committerOri Bernstein <ori@eigenstate.org>2019-01-07 00:10:17 -0800
commitaf63c8fc4082fca2b5148cb55a6870ac926660e4 (patch)
treefbc4a1129ed7e6c6f7de4ff0005dcc43e4c11319
parenta2644d1d980e0f1c5439dce7764f0d051cf4cc41 (diff)
downloadmc-af63c8fc4082fca2b5148cb55a6870ac926660e4.tar.gz
Change indexed array literal syntax.
-rw-r--r--doc/lang.txt6
-rw-r--r--lib/crypto/x25519.myr16
-rw-r--r--parse/gram.y4
-rw-r--r--test/arraylit.myr6
4 files changed, 18 insertions, 14 deletions
diff --git a/doc/lang.txt b/doc/lang.txt
index 4b7c482..0a38c00 100644
--- a/doc/lang.txt
+++ b/doc/lang.txt
@@ -998,7 +998,7 @@ TABLE OF CONTENTS:
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 @@ TABLE OF CONTENTS:
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 @@ TABLE OF CONTENTS:
[.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")
diff --git a/lib/crypto/x25519.myr b/lib/crypto/x25519.myr
index e4178e6..d267338 100644
--- a/lib/crypto/x25519.myr
+++ b/lib/crypto/x25519.myr
@@ -477,14 +477,14 @@ const fmonty = {x2, z2, x3, z3, x, z, xprime, zprime, qmqp
* 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[:]
diff --git a/parse/gram.y b/parse/gram.y
index 5836b0c..749d7a5 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -963,8 +963,8 @@ arrayelts
;
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);
}
;
diff --git a/test/arraylit.myr b/test/arraylit.myr
index e37e772..93a90ee 100644
--- a/test/arraylit.myr
+++ b/test/arraylit.myr
@@ -2,6 +2,10 @@ use std
/* 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])
}