feat: generic enums, fix is-operator, Type_Eq, hardcoded limit diagnostics
ci / build (ubuntu) (push) Has been cancelled
ci / unit + fmt (push) Has been cancelled
ci / examples (push) Has been cancelled
ci / goldens + tools (push) Has been cancelled
ci / apps (push) Has been cancelled
ci / selfhost smoke (push) Has been cancelled
ci / macos smoke (push) Has been cancelled
ci / windows smoke (push) Has been cancelled
ci / CI gate (push) Has been cancelled
selfhost-loop / bootstrap determinism (push) Has been cancelled

- feat: generic enum support (parser, lowering, codegen — both selfhost + bootstrap)
  - enum Result<T,E> { Ok(T), Err(E) } parsing + monomorphization
  - tag constant mangling in monomorphized function bodies
  - data field access (l-value + r-value) for generated enum instances
  - multiple concrete instances in same file
  - HIR walker for enum reference mangling (selfhost + bootstrap)

- feat: stdlib Result<T,E> and Option<T> made truly generic
  - breaking: explicit type args required (Result<int, String>)

- fix: 'is' operator — lowering to hBinary tag comparison + C backend fallback
- fix: Type_Eq structural comparison (inner types for pointer/slice/tuple)
- fix: hardcoded limit diagnostics (>8 params/variants/captures now emit errors)
- docs: Iter<T> safety warning for dangling pointer
- docs: IMPROVEMENTS.md — comprehensive plan and changelog
- test: generic_enum example added to EXAMPLES

All tests pass (0 FAIL). Selfhost loop deterministic.
This commit is contained in:
2026-07-28 01:54:15 +03:00
parent fa1521a71e
commit d517c62380
15 changed files with 714 additions and 96 deletions
+11 -14
View File
@@ -3,46 +3,44 @@ module Std::Option {
extern func bux_exit(code: int);
enum Option {
Some(int),
enum Option<T> {
Some(T),
None,
}
func Option_NewSome(value: int) -> Option {
let o: Option = Option { tag: Option_Some };
func Option_NewSome<T>(value: T) -> Option<T> {
let o: Option<T> = Option { tag: Option_Some };
o.data.Some_0 = value;
return o;
}
func Option_NewNone() -> Option {
func Option_NewNone<T>() -> Option<T> {
return Option { tag: Option_None };
}
func Option_IsSome(o: Option) -> bool {
func Option_IsSome<T>(o: Option<T>) -> bool {
return o.tag == Option_Some;
}
func Option_IsNone(o: Option) -> bool {
func Option_IsNone<T>(o: Option<T>) -> bool {
return o.tag == Option_None;
}
func Option_Unwrap(o: Option) -> int {
func Option_Unwrap<T>(o: Option<T>) -> T {
if o.tag != Option_Some {
PrintLine("panic: unwrap on None");
return 0;
}
return o.data.Some_0;
}
func Option_UnwrapOr(o: Option, fallback: int) -> int {
func Option_UnwrapOr<T>(o: Option<T>, fallback: T) -> T {
if o.tag == Option_Some {
return o.data.Some_0;
}
return fallback;
}
/* Unwrap Some or panic with a custom message */
func Option_Expect(o: Option, msg: String) -> int {
func Option_Expect<T>(o: Option<T>, msg: String) -> T {
if o.tag != Option_Some {
PrintLine(msg);
bux_exit(1);
@@ -50,8 +48,7 @@ module Std::Option {
return o.data.Some_0;
}
/* If o is Some return it, otherwise return other */
func Option_Or(o: Option, other: Option) -> Option {
func Option_Or<T>(o: Option<T>, other: Option<T>) -> Option<T> {
if o.tag == Option_Some {
return o;
}