aboutsummaryrefslogtreecommitdiff
path: root/docs/language.md
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-31 19:58:56 +0200
committerhachem <im@hachem.wtf>2026-08-31 19:58:56 +0200
commit5b06b0e4b8effaacd23308d6a6b26c525e7d3af4 (patch)
tree351155777028e604845d3dfec27d3caf3b22257f /docs/language.md
parentcbdb9073480c3e4d8a088b306c23406cf42e25c0 (diff)
feat: add enums and structs
Diffstat (limited to 'docs/language.md')
-rw-r--r--docs/language.md33
1 files changed, 33 insertions, 0 deletions
diff --git a/docs/language.md b/docs/language.md
index 43b6246..5e75c54 100644
--- a/docs/language.md
+++ b/docs/language.md
@@ -59,6 +59,39 @@ const AREA = 8 * 6 // 48
data message = "type shi.\n" // message -> address, message.len -> 10
```
+## Enums and structs
+
+Both describe compile-time values reached with `Name.member`, which folds to an integer.
+
+`enum` names a set of constants numbered from 0:
+
+```hdass
+enum Status
+{
+ Ok, // 0
+ Warn, // 1
+ Fail // 2
+}
+
+rax = Status.Fail // mov rax, 2
+```
+
+`struct` describes a packed memory layout (no padding). Fields are `name` or `name: size`, where size defaults to `qword`. `Name.field` is the field's byte offset, and `Name.size` is the total size.
+
+```hdass
+struct Point
+{
+ x // qword, offset 0
+ y // qword, offset 8
+ flag: byte // offset 16
+}
+
+rsi += Point.y // add rsi, 8
+rax = Point.size // mov rax, 17
+```
+
+A struct is layout only — it allocates nothing. Pair it with a `stack` buffer and pointer arithmetic (see [examples/records.hdass](../examples/records.hdass)).
+
## Procedures
`proc` groups a body. Parameters name registers — `value` below is `rdi`.