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
+4
View File
@@ -2,6 +2,10 @@ module Std::Iter {
import Std::Array::*;
// SAFETY: Iter<T> stores a raw *T pointer to the source array's element buffer.
// The iterator MUST NOT outlive the source Array<T>. Modifying the source array
// (e.g. Array_Push which may reallocate the buffer) while an iterator is active
// will result in a dangling pointer and undefined behavior.
struct Iter<T> {
data: *T,
len: uint,
+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;
}
+14 -19
View File
@@ -3,48 +3,46 @@ module Std::Result {
extern func bux_exit(code: int);
enum Result {
Ok(int),
Err(String),
enum Result<T, E> {
Ok(T),
Err(E),
}
func Result_NewOk(value: int) -> Result {
let r: Result = Result { tag: Result_Ok };
func Result_NewOk<T, E>(value: T) -> Result<T, E> {
let r: Result<T, E> = Result { tag: Result_Ok };
r.data.Ok_0 = value;
return r;
}
func Result_NewErr(msg: String) -> Result {
let r: Result = Result { tag: Result_Err };
func Result_NewErr<T, E>(msg: E) -> Result<T, E> {
let r: Result<T, E> = Result { tag: Result_Err };
r.data.Err_0 = msg;
return r;
}
func Result_IsOk(r: Result) -> bool {
func Result_IsOk<T, E>(r: Result<T, E>) -> bool {
return r.tag == Result_Ok;
}
func Result_IsErr(r: Result) -> bool {
func Result_IsErr<T, E>(r: Result<T, E>) -> bool {
return r.tag == Result_Err;
}
func Result_Unwrap(r: Result) -> int {
func Result_Unwrap<T, E>(r: Result<T, E>) -> T {
if r.tag != Result_Ok {
PrintLine("panic: unwrap on Err");
return 0;
}
return r.data.Ok_0;
}
func Result_UnwrapOr(r: Result, fallback: int) -> int {
func Result_UnwrapOr<T, E>(r: Result<T, E>, fallback: T) -> T {
if r.tag == Result_Ok {
return r.data.Ok_0;
}
return fallback;
}
/* Unwrap Ok or panic with a custom message */
func Result_Expect(r: Result, msg: String) -> int {
func Result_Expect<T, E>(r: Result<T, E>, msg: String) -> T {
if r.tag != Result_Ok {
PrintLine(msg);
bux_exit(1);
@@ -52,17 +50,14 @@ module Std::Result {
return r.data.Ok_0;
}
/* Extract Err payload (panics if Ok) */
func Result_UnwrapErr(r: Result) -> String {
func Result_UnwrapErr<T, E>(r: Result<T, E>) -> E {
if r.tag != Result_Err {
PrintLine("panic: unwrap_err on Ok");
return "";
}
return r.data.Err_0;
}
/* If r is Ok return it, otherwise return other */
func Result_Or(r: Result, other: Result) -> Result {
func Result_Or<T, E>(r: Result<T, E>, other: Result<T, E>) -> Result<T, E> {
if r.tag == Result_Ok {
return r;
}