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
45 lines
813 B
Plaintext
45 lines
813 B
Plaintext
module Std::Result {
|
|
import Std::Io::{PrintLine};
|
|
|
|
enum Result {
|
|
Ok(int),
|
|
Err(String),
|
|
}
|
|
|
|
func Result_NewOk(value: int) -> Result {
|
|
let r: Result = Result { tag: Result_Ok };
|
|
r.data.Ok_0 = value;
|
|
return r;
|
|
}
|
|
|
|
func Result_NewErr(msg: String) -> Result {
|
|
let r: Result = Result { tag: Result_Err };
|
|
r.data.Err_0 = msg;
|
|
return r;
|
|
}
|
|
|
|
func Result_IsOk(r: Result) -> bool {
|
|
return r.tag == Result_Ok;
|
|
}
|
|
|
|
func Result_IsErr(r: Result) -> bool {
|
|
return r.tag == Result_Err;
|
|
}
|
|
|
|
func Result_Unwrap(r: Result) -> int {
|
|
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 {
|
|
if r.tag == Result_Ok {
|
|
return r.data.Ok_0;
|
|
}
|
|
return fallback;
|
|
}
|
|
|
|
}
|