about summary refs log tree commit diff
path: root/examples/22.src
diff options
context:
space:
mode:
authorBaitinq <[email protected]>2025-05-25 22:49:18 +0200
committerBaitinq <[email protected]>2025-05-25 22:49:53 +0200
commitf5904b62012ca475c14ad55b7f2c0b0c5c48b362 (patch)
tree890b3f1274b8dab2e7e2a2052d7d452fa3ca6db2 /examples/22.src
parentExamples: Fix example 21 (diff)
downloadinterpreter-f5904b62012ca475c14ad55b7f2c0b0c5c48b362.tar.gz
interpreter-f5904b62012ca475c14ad55b7f2c0b0c5c48b362.tar.bz2
interpreter-f5904b62012ca475c14ad55b7f2c0b0c5c48b362.zip
Feature: Start adding structs support
Diffstat (limited to 'examples/22.src')
-rw-r--r--examples/22.src34
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/22.src b/examples/22.src
new file mode 100644
index 0000000..9d73d1a
--- /dev/null
+++ b/examples/22.src
@@ -0,0 +1,34 @@
+import "!stdlib.src";
+
+/* declare new struct type */
+let test = struct {
+	 x: i64,
+	 y: *i8,
+	 z: bool
+};
+
+let main = () => i64 {
+	/* instanciate new struct. instanciating fields isn't supported here */
+	let inst = test{};
+	inst.x = 2;
+	inst.y = "hello";
+	inst.z = true;
+
+	println("Inst x: %d", inst.x);
+	println("Inst y: %s", inst.y);
+	println("Inst z: %d", inst.z);
+
+	return 0;
+};
+
+/*
+
+Expected stdout:
+
+2
+hello
+1
+
+Expected return: 0
+
+*/