aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/data/static.ll33
-rw-r--r--test/data/static.yx26
2 files changed, 59 insertions, 0 deletions
diff --git a/test/data/static.ll b/test/data/static.ll
new file mode 100644
index 0000000..8327280
--- /dev/null
+++ b/test/data/static.ll
@@ -0,0 +1,33 @@
+@x = internal global i64 0
+@foo.bar = internal global i64 42
+@foo.baz = internal global float 0.000000e+00
+@bar.x = internal global i128 1000
+@baz.nested.x = internal global i16 0
+@baz.x = internal global i128 1000
+@baz.y = internal global i64 42
+
+define void @foo() {
+entry:
+ %load = load i64, ptr @foo.bar, align 8
+ %mul = mul i64 %load, 2
+ store i64 %mul, ptr @foo.bar, align 8
+ ret void
+}
+
+define i128 @bar() {
+entry:
+ %load = load i128, ptr @bar.x, align 16
+ ret i128 %load
+}
+
+define void @baz.nested() {
+entry:
+ store i16 16, ptr @baz.nested.x, align 2
+ ret void
+}
+
+define i128 @baz() {
+entry:
+ %load = load i128, ptr @baz.x, align 16
+ ret i128 %load
+}
diff --git a/test/data/static.yx b/test/data/static.yx
new file mode 100644
index 0000000..8f39a6e
--- /dev/null
+++ b/test/data/static.yx
@@ -0,0 +1,26 @@
+x: int;
+
+/* You can define static local variables and use them */
+foo :: () {
+ static bar := 42;
+ static baz: f32;
+
+ bar = bar * 2;
+}
+
+/* Static locals can shadow other globals */
+bar :: () u128 {
+ static x: u128 = 1'000;
+ return x;
+}
+
+/* Shadowing works in nested functions */
+baz :: () u128 {
+ static x: u128 = 1'000;
+ static y := 42;
+ nested :: () {
+ static x: i16;
+ x = 16;
+ }
+ return x;
+}