d517c62380
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.
68 lines
1.6 KiB
Plaintext
68 lines
1.6 KiB
Plaintext
module Std::Result {
|
|
import Std::Io::{PrintLine};
|
|
|
|
extern func bux_exit(code: int);
|
|
|
|
enum Result<T, E> {
|
|
Ok(T),
|
|
Err(E),
|
|
}
|
|
|
|
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<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<T, E>(r: Result<T, E>) -> bool {
|
|
return r.tag == Result_Ok;
|
|
}
|
|
|
|
func Result_IsErr<T, E>(r: Result<T, E>) -> bool {
|
|
return r.tag == Result_Err;
|
|
}
|
|
|
|
func Result_Unwrap<T, E>(r: Result<T, E>) -> T {
|
|
if r.tag != Result_Ok {
|
|
PrintLine("panic: unwrap on Err");
|
|
}
|
|
return r.data.Ok_0;
|
|
}
|
|
|
|
func Result_UnwrapOr<T, E>(r: Result<T, E>, fallback: T) -> T {
|
|
if r.tag == Result_Ok {
|
|
return r.data.Ok_0;
|
|
}
|
|
return fallback;
|
|
}
|
|
|
|
func Result_Expect<T, E>(r: Result<T, E>, msg: String) -> T {
|
|
if r.tag != Result_Ok {
|
|
PrintLine(msg);
|
|
bux_exit(1);
|
|
}
|
|
return r.data.Ok_0;
|
|
}
|
|
|
|
func Result_UnwrapErr<T, E>(r: Result<T, E>) -> E {
|
|
if r.tag != Result_Err {
|
|
PrintLine("panic: unwrap_err on Ok");
|
|
}
|
|
return r.data.Err_0;
|
|
}
|
|
|
|
func Result_Or<T, E>(r: Result<T, E>, other: Result<T, E>) -> Result<T, E> {
|
|
if r.tag == Result_Ok {
|
|
return r;
|
|
}
|
|
return other;
|
|
}
|
|
|
|
}
|