feat: multi-instance closures, richer stdlib, and Rust-style diagnostics
Introduce fat function pointers (BuxFn {code, env}) so capturing closures
are heap-allocated per value in both bootstrap and selfhost. Expand
Array/Map/Set/String/Test/Result APIs, add proper tuple codegen and
error snippets with multi-char underlines, golden diagnostic tests, and
LSP diagnostics via buxc check.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
module Std::Option {
|
||||
import Std::Io::{PrintLine};
|
||||
|
||||
extern func bux_exit(code: int);
|
||||
|
||||
enum Option {
|
||||
Some(int),
|
||||
None,
|
||||
@@ -39,4 +41,21 @@ func Option_UnwrapOr(o: Option, fallback: int) -> int {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/* Unwrap Some or panic with a custom message */
|
||||
func Option_Expect(o: Option, msg: String) -> int {
|
||||
if o.tag != Option_Some {
|
||||
PrintLine(msg);
|
||||
bux_exit(1);
|
||||
}
|
||||
return o.data.Some_0;
|
||||
}
|
||||
|
||||
/* If o is Some return it, otherwise return other */
|
||||
func Option_Or(o: Option, other: Option) -> Option {
|
||||
if o.tag == Option_Some {
|
||||
return o;
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user