From 8bb734d88283b78188348bdd266bbf522a916371 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Tue, 4 Nov 2025 10:38:34 +0000 Subject: [PATCH] doc: sample: add match-statement syntax and ir samples --- doc/sample/Match.im | 18 +++++++++++++++++ doc/sample/Match.mie | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 doc/sample/Match.im create mode 100644 doc/sample/Match.mie diff --git a/doc/sample/Match.im b/doc/sample/Match.im new file mode 100644 index 0000000..44557c1 --- /dev/null +++ b/doc/sample/Match.im @@ -0,0 +1,18 @@ + +age = 65. +yz = 32. + +p3 = 3. + +q = match yz in + 1 => do + wq = 32. + wq * 2 + end, + + 2 => age / 12, + p3 => age / 365, + 5 | 6 => age = 32, + 10..=15 => age = 64, + _ => 0 +end diff --git a/doc/sample/Match.mie b/doc/sample/Match.mie new file mode 100644 index 0000000..0fbf9d9 --- /dev/null +++ b/doc/sample/Match.mie @@ -0,0 +1,47 @@ +define void @init() static { +entry: + %age = alloca id + store i32 #65, ptr %age + + %yz = alloca id + store i32 #32, ptr %yz + + %p3 = alloca id + store i32 #3, ptr %p3 + + %1 = load id, ptr %yz + %2 = load id, ptr %p3 + + switch id %1, label %match.d, + [ i32 #1, label %match.0 ], + [ i32 #2, label %match.1 ], + [ i32 %2, label %match.2 ] +match.0: + %wq = alloca id + store i32 #32, ptr %wq + + %3 = load id, ptr %wq + %multmp = mul id %3, i32 #2 + br label %match.end + +match.1: + %4 = load id, ptr %age + %divtmp = mul id %4, i32 #12 + br label %match.end +match.2: + %5 = load id, ptr %age + %divtmp.0 = mul id %5, i32 #365 + br label %match.end +match.d: + br label %match.end +match.end: + %match.result = phi id + [ %match.0, %multmp], + [ %match.1, %divtmp ], + [ %match.2, %divtmp.0 ], + [ %match.d, #0 ] + + %q = alloca id + store id %match.result, ptr %q + ret void +}