This commit is contained in:
2026-06-23 17:22:41 +02:00
parent f16f352d1e
commit 2f68fc966a
16 changed files with 809 additions and 38 deletions
+24 -1
View File
@@ -125,7 +125,14 @@
floats follow IEEE (`fadd`/`fsub`/`fmul`/`fdiv`, no trap)
- constant folding (global initializers) covers `-`, `*`, `/` alongside `+`
7. enums (native and c interop) (see below)
7. enums (native and c interop) (implemented; see below)
- native enums are nominal value types with integer runtime representations
- unbacked enums are non-empty, dense, zero-based, and use the smallest fitting unsigned backing
- explicitly backed enums require an integer type and strictly increasing literal values
- enum members support `Type.member`, `package.Type.member`, and contextual `.member`
- enum values support storage, calls/returns, and same-type equality/inequality
- explicitly backed native enums use their backing ABI in `c_func` signatures and variadic promotion
- imported C enum types alias libclang's target-selected integer backing and enumerators import as package constants
8. distinct types (implemented; see below)
- nominal declarations preserve identity across packages and reuse the backing runtime representation
@@ -255,3 +262,19 @@ Nat :: enum(u8) {
dog_tag1 Animal :: Animal.dog
dog_tag2 Animal :: .dog # type inferred
```
Unbacked enums cannot assign explicit values. Backed enum values must be decimal integer
literals, fit the backing type, and increase strictly; gaps are allowed.
Native enum types remain distinct from integers and from other enum types. They support
`==` and `!=`, but not arithmetic, ordering, casts, or backing-value extraction.
C enums follow C/Zig import semantics rather than native enum semantics:
```
native :: import "native.h"
value native.Imported_Enum :: native.IMPORTED_ENUM_VALUE
```
The imported enum type is an alias of its target-selected C integer backing, and imported
enumerators are package-level constants.