Files
bux-lang/lib/Option.bux
T
dimgigov e87985e879
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
fix: is-operator, try with generic Result, Unwrap exits on panic
Desugar `is` to tag/value equality in bootstrap and selfhost so LIR
no longer drops hIs as false. Resolve monomorphized Result/Option type
names for `?` (_Tag/_Data). Call bux_exit(1) after Unwrap panic messages.
Add is_operator example and document follow-up fixes.
2026-07-28 05:25:11 +03:00

60 lines
1.3 KiB
Plaintext

module Std::Option {
import Std::Io::{PrintLine};
extern func bux_exit(code: int);
enum Option<T> {
Some(T),
None,
}
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<T>() -> Option<T> {
return Option { tag: Option_None };
}
func Option_IsSome<T>(o: Option<T>) -> bool {
return o.tag == Option_Some;
}
func Option_IsNone<T>(o: Option<T>) -> bool {
return o.tag == Option_None;
}
func Option_Unwrap<T>(o: Option<T>) -> T {
if o.tag != Option_Some {
PrintLine("panic: unwrap on None");
bux_exit(1);
}
return o.data.Some_0;
}
func Option_UnwrapOr<T>(o: Option<T>, fallback: T) -> T {
if o.tag == Option_Some {
return o.data.Some_0;
}
return fallback;
}
func Option_Expect<T>(o: Option<T>, msg: String) -> T {
if o.tag != Option_Some {
PrintLine(msg);
bux_exit(1);
}
return o.data.Some_0;
}
func Option_Or<T>(o: Option<T>, other: Option<T>) -> Option<T> {
if o.tag == Option_Some {
return o;
}
return other;
}
}