aboutsummaryrefslogtreecommitdiff
path: root/docs/history/50-adt
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
commitecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch)
tree70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /docs/history/50-adt
a
Diffstat (limited to 'docs/history/50-adt')
-rw-r--r--docs/history/50-adt/notes.md9
1 files changed, 9 insertions, 0 deletions
diff --git a/docs/history/50-adt/notes.md b/docs/history/50-adt/notes.md
new file mode 100644
index 0000000..a9e04da
--- /dev/null
+++ b/docs/history/50-adt/notes.md
@@ -0,0 +1,9 @@
+# 50 adt
+
+what was asked: tagged enums and pattern matching (task 34). the four design questions were answered: payload syntax `circle { int r; }`, match form `case circle(r):`, a missing member in a switch is a warning, and the tag is the word at offset 0. see design/adt.md.
+
+what landed: an enum can give its members fields. the enum becomes one struct: a tag word, then every member's fields, each named `member_field`, so every value is as big as the largest member. `shape.circle(3)` is a generated static constructor that returns an owned `shape*`. a switch over a `shape*` matches with `case circle(r):`, binds the fields in that arm only, and reads them through the same field access as any struct. a switch that leaves out a member, with no `default`, prints a warning on the line of the switch. the coverage check keeps a bit set of the tags a switch covers. two enums may use the same member name, since each keeps its own fields.
+
+checks: tests/tagenum.zc, tests/tagenum_warn.zc, tests/tagenum_two.zc (including a case inside an o3 loop), and three langerrors (explicit values on a member, a wrong number of bindings, a wrong number of constructor arguments). the fast suite passed 126 of 126, the lsp protocol checks 41 of 41 and the wasm checks 10 of 10. the enum output matched on the interpreter, the llvm backend and the arm64 jit under qemu.
+
+what did not: members with explicit values are rejected, not supported. a member with fields can't be matched without its binding list (the arm must bind every field). the constructor's owned result can't be passed straight to a borrowing parameter (the existing rule for `new`), so it has to go through a name first. the warning only fires with no `default`. the llvm and jit runs were done by hand, not from the test script.