0dade151d2
Bootstrap compiler improvements: - Extract findStdlibDir() to remove hardcoded path and deduplicate - Extract prepareProject()/mergeProject() to share code between cmdCheck/cmdBuild - Fix C backend to emit warning on unknown types instead of silent 'int' - Clean up all unused imports across 7 modules - Makefile: add strip, debug target, clean-all, selfhost strip QBE removal: - Remove vendor/qbe/ (74K lines) - Remove compiler/selfhost/qbe_backend.bux, nim_backend.bux Stdlib improvements: - Add Result.bux + Option.bux modules - Fix Json.bux memory leak (removed double String_Copy) - Add missing imports in Crypto.bux (Alloc/Free) and Test.bux (PrintLine/PrintInt) - Clean stale buxc_debug binary
43 lines
773 B
Plaintext
43 lines
773 B
Plaintext
module Std::Option {
|
|
import Std::Io::{PrintLine};
|
|
|
|
enum Option {
|
|
Some(int),
|
|
None,
|
|
}
|
|
|
|
func Option_NewSome(value: int) -> Option {
|
|
let o: Option = Option { tag: Option_Some };
|
|
o.data.Some_0 = value;
|
|
return o;
|
|
}
|
|
|
|
func Option_NewNone() -> Option {
|
|
return Option { tag: Option_None };
|
|
}
|
|
|
|
func Option_IsSome(o: Option) -> bool {
|
|
return o.tag == Option_Some;
|
|
}
|
|
|
|
func Option_IsNone(o: Option) -> bool {
|
|
return o.tag == Option_None;
|
|
}
|
|
|
|
func Option_Unwrap(o: Option) -> int {
|
|
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 {
|
|
if o.tag == Option_Some {
|
|
return o.data.Some_0;
|
|
}
|
|
return fallback;
|
|
}
|
|
|
|
}
|