aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGravatar Moon Flower <moon@coffin.ir> 2025-02-27 14:49:26 +0330
committerGravatar Moon Flower <moon@coffin.ir> 2025-02-27 14:49:26 +0330
commit98b554584d06d85f20e10905efb96e4dd5f7c820 (patch)
tree0dc9ca8737c4caddbd4163d83f179913fc9629b7 /main.c
parentmain.m4 -> moonshine.m4 (diff)
Slight revamp + Algebraic data types
Diffstat (limited to 'main.c')
-rw-r--r--main.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/main.c b/main.c
index de8da5c..f49b452 100644
--- a/main.c
+++ b/main.c
@@ -3,18 +3,16 @@
#define __MOONSHINE_LIBC_WARNINGS
#include "moonshine.h"
-void cleanup_free(var* input) { print("Deallocation logic goes here ", input); }
-
-#define auto_free __attribute__((cleanup(cleanup_free)))
-
-#define create(type, name, ...) \
- auto_free var cat(name, _parent) = __VA_ARGS__; \
- type name = cat(name, _parent);
+datatype(binarytree, ((leaf, int), (node, binarytree *, int, binarytree *) ));
int main() {
- create(t(int), proof_of_concept, new(int));
+ const auto tree = instance(binarytree, leaf, 3);
- print("Neat, right? ", proof_of_concept);
+ match(tree) {
+ of(leaf, v) print("Leafy ", v);
+ of(node, _, v, _) print("Nodey ", v);
+ other() print("Idk man");
+ }
return 0;
}