summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin@c9x.me>2018-07-17 08:57:58 +0000
committerOri Bernstein <ori@eigenstate.org>2018-07-19 21:29:35 -0700
commitf4a43f90e3ffe1712aec13566e8ac545da4161c4 (patch)
tree57a3edcd99ff2cae6ab74b6435af32d3182174ba /test
parent8a3e8add6e0180565312d1079395ad39de4d9ce3 (diff)
downloadmc-f4a43f90e3ffe1712aec13566e8ac545da4161c4.tar.gz
Support direct tuple access operators "tuple.N"
This patch adds tuple access expressions. If t is a tuple, its N-th component can be retrieved with the syntax t.N. Of course, the components are zero indexed. I believe the code also works if 't' is a pointer to a tuple (but I have not checked this).
Diffstat (limited to 'test')
-rw-r--r--test/tests1
-rw-r--r--test/tupleaccess.myr14
2 files changed, 15 insertions, 0 deletions
diff --git a/test/tests b/test/tests
index 0dcb843..2291b7e 100644
--- a/test/tests
+++ b/test/tests
@@ -135,6 +135,7 @@ B arraylit E 3
B structlit E 42
B livestructlit E 21
B tuple E 42
+B tupleaccess P 'a: 0, b: 5, c: 2'
B slgrow E 42
B tyrec E 42
B infer-named E 99
diff --git a/test/tupleaccess.myr b/test/tupleaccess.myr
new file mode 100644
index 0000000..cbd0f05
--- /dev/null
+++ b/test/tupleaccess.myr
@@ -0,0 +1,14 @@
+use std
+
+const foo = {
+ -> (1, 2, (3, 4))
+}
+
+const main = {
+ match foo()
+ | x:
+ x.0 = 0
+ (x.2).1 = 5
+ std.put("a: {}, b: {}, c: {}\n", x.0, x.2.1, foo().1)
+ ;;
+}