added arrow notation test
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 29 Aug 2022 13:28:00 +0000 (08:28 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 29 Aug 2022 13:28:00 +0000 (08:28 -0500)
tests/arrow_notation [new file with mode: 0644]
tests/arrow_notation.onyx [new file with mode: 0644]

diff --git a/tests/arrow_notation b/tests/arrow_notation
new file mode 100644 (file)
index 0000000..c5ad214
--- /dev/null
@@ -0,0 +1,3 @@
+(4, 6)
+(4, 6)
+(4, 6)
diff --git a/tests/arrow_notation.onyx b/tests/arrow_notation.onyx
new file mode 100644 (file)
index 0000000..5bffa29
--- /dev/null
@@ -0,0 +1,43 @@
+#load "core/std"
+
+use core
+
+#tag conv.Custom_Format.{format}
+V2 :: struct {
+    x, y: i32;
+
+    add :: (v1, v2: V2) => V2.{v1.x+v2.x, v1.y+v2.y};
+
+    add_inplace :: (v1: ^V2, v2: V2) {
+        v1.x += v2.x;
+        v1.y += v2.y;
+    }
+
+    format :: (output: ^conv.Format_Output, _: ^conv.Format, v: ^V2) {
+        conv.format(output, "({}, {})", v.x, v.y); 
+    }
+}
+
+main :: () {
+    {
+        // L-Values
+
+        v := V2.{1, 2};
+        println(v->add(.{3, 4}));
+
+
+        v->add_inplace(.{3, 4});
+        println(v);
+    }
+
+    {
+        // R-Value
+        out := (V2.{1, 2})->add(.{3, 4});
+        println(out);
+
+        // This does work because you can take the address of a struct literal.
+        // However, there is no way to retrieve the value of the sturct literal
+        // after this operation, so nothing can be printed.
+        (V2.{1, 2})->add_inplace(.{3, 4});
+    }
+}
\ No newline at end of file