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:
@@ -0,0 +1,32 @@
|
||||
// Tuple types: (T, U), return, field access via .0 / .1
|
||||
import Std::Io::{PrintLine, PrintInt};
|
||||
import Std::Test::{Test_AssertEqInt, Test_Pass};
|
||||
|
||||
func MakePair(a: int, b: int) -> (int, int) {
|
||||
return (a, b);
|
||||
}
|
||||
|
||||
func Swap(t: (int, int)) -> (int, int) {
|
||||
return (t.1, t.0);
|
||||
}
|
||||
|
||||
func Main() -> int {
|
||||
let t: (int, int) = MakePair(10, 20);
|
||||
Test_AssertEqInt(t.0, 10);
|
||||
Test_AssertEqInt(t.1, 20);
|
||||
|
||||
let s: (int, int) = Swap(t);
|
||||
Test_AssertEqInt(s.0, 20);
|
||||
Test_AssertEqInt(s.1, 10);
|
||||
|
||||
let lit: (int, int) = (7, 8);
|
||||
Test_AssertEqInt(lit.0, 7);
|
||||
Test_AssertEqInt(lit.1, 8);
|
||||
|
||||
PrintInt(t.0);
|
||||
PrintLine("");
|
||||
PrintInt(t.1);
|
||||
PrintLine("");
|
||||
Test_Pass("tuples");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user