aboutsummaryrefslogtreecommitdiff
path: root/tests/programs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/programs')
-rw-r--r--tests/programs/embed.zc31
-rw-r--r--tests/programs/embed_top.zc21
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/programs/embed.zc b/tests/programs/embed.zc
new file mode 100644
index 0000000..d8d0ca3
--- /dev/null
+++ b/tests/programs/embed.zc
@@ -0,0 +1,31 @@
+namespace;
+include rt;
+
+// embed declarations: file bytes become globals and locals of the declared type.
+embed "tests/data/embed/text.txt" as text;
+embed "tests/data/embed/answer.bin" as int answer;
+embed "tests/data/embed/bytes.bin" as u8[] bytes;
+embed "tests/data/embed/bytes.bin" as i8[8] signed;
+embed "tests/data/embed/text.txt" as char* chars;
+embed "tests/data/embed/onehalf.f32" as f32 half;
+embed "tests/data/embed/bytes.bin" as char[] cs;
+embed "tests/data/embed/nul.bin" as bstr nul;
+embed "tests/data/embed/shorts.bin" as u16[] shorts;
+fn main() {
+ rt.put_s(text); rt.put_c(32);
+ rt.put_n(len(text)); rt.put_c(32);
+ rt.put_n(answer); rt.put_c(32);
+ rt.put_n(len(bytes)); rt.put_c(32); rt.put_n(bytes[4]); rt.put_c(32);
+ rt.put_n(len(signed)); rt.put_c(32); rt.put_n(signed[4]); rt.put_c(32); rt.put_n(signed[7]); rt.put_c(32);
+ rt.put_n(chars[6]); rt.put_c(32);
+ rt.put_n((int)(half * 10.0)); rt.put_c(32);
+ rt.put_n(len(cs)); rt.put_c(32); rt.put_n(cs[4]); rt.put_c(32);
+ rt.put_n(len(nul)); rt.put_c(32); rt.put_n(nul[2]); rt.put_c(32);
+ rt.put_n(shorts[0] + shorts[1] * 10 + shorts[2] * 100); rt.put_c(32);
+ embed "tests/data/embed/answer.bin" as int local;
+ embed "tests/data/embed/bytes.bin" as u8[] copy;
+ embed "tests/data/embed/text.txt" as lt;
+ copy[0] = 9;
+ rt.put_n(local + copy[0] + bytes[0] + len(lt)); rt.put_c(10);
+ return 0;
+}
diff --git a/tests/programs/embed_top.zc b/tests/programs/embed_top.zc
new file mode 100644
index 0000000..732566d
--- /dev/null
+++ b/tests/programs/embed_top.zc
@@ -0,0 +1,21 @@
+namespace;
+include rt;
+
+// embed declarations at the top level, the form stage 0 compiles into run-only images.
+embed "tests/data/embed/text.txt" as text;
+embed "tests/data/embed/answer.bin" as int answer;
+embed "tests/data/embed/bytes.bin" as u8[] bytes;
+embed "tests/data/embed/bytes.bin" as i8[8] signed;
+embed "tests/data/embed/text.txt" as char* chars;
+embed "tests/data/embed/bytes.bin" as char[] cs;
+embed "tests/data/embed/shorts.bin" as u16[] shorts;
+fn main() {
+ rt.put_s(text); rt.put_c(32);
+ rt.put_n(answer); rt.put_c(32);
+ rt.put_n(bytes[4]); rt.put_c(32);
+ rt.put_n(signed[4]); rt.put_c(32); rt.put_n(signed[7]); rt.put_c(32);
+ rt.put_n(chars[6]); rt.put_c(32);
+ rt.put_n(cs[4]); rt.put_c(32);
+ rt.put_n(shorts[0] + shorts[1] * 10 + shorts[2] * 100); rt.put_c(10);
+ return 0;
+}