feat: try/unwrap payload types, LSP format, macro paste, freestanding runtime
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
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
- Type `?`/`!` as Result/Option Ok payload (not always int); fix unwrap C types - LSP 0.18 document formatting (bux fmt) + VS Code format-on-save - Macro `:type` generics (Array_New<$t>) and operators-only tt paste - Ship runtime_freestanding.c + BUX_RUNTIME=freestanding + smokes/examples
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// Operators-only `:tt` paste — `$op($a, $b)` → `a OP b`
|
||||
import Std::Io::{PrintLine, PrintInt};
|
||||
import Std::Test::{Test_AssertEqInt, Test_AssertEqBool, Test_Pass};
|
||||
|
||||
// Explicit op as call-site tt: apply_op!(+, 3, 4) → 7
|
||||
macro! apply_op {
|
||||
( $op:tt, $a:expr, $b:expr ) => { $op($a, $b) }
|
||||
}
|
||||
|
||||
// Juxta binary split: flip_op!(10 - 3) → 3 - 10
|
||||
macro! flip_op {
|
||||
( $a:expr, $op:tt, $b:expr ) => { $op($b, $a) }
|
||||
}
|
||||
|
||||
func Main() -> int {
|
||||
let sum: int = apply_op!(+, 3, 4);
|
||||
Test_AssertEqInt(sum, 7);
|
||||
|
||||
let prod: int = apply_op!(*, 6, 7);
|
||||
Test_AssertEqInt(prod, 42);
|
||||
|
||||
let diff: int = flip_op!(10 - 3);
|
||||
Test_AssertEqInt(diff, -7);
|
||||
|
||||
let eq: bool = apply_op!(==, 5, 5);
|
||||
Test_AssertEqBool(eq, true);
|
||||
|
||||
let lt: bool = apply_op!(<, 2, 9);
|
||||
Test_AssertEqBool(lt, true);
|
||||
|
||||
PrintInt(sum);
|
||||
PrintLine("");
|
||||
PrintInt(prod);
|
||||
PrintLine("");
|
||||
PrintInt(diff);
|
||||
PrintLine("");
|
||||
PrintLine("PASS macro_op_paste");
|
||||
Test_Pass("macro_op_paste");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Generics in `$t:type` + type-arg splice into Array_New<$t>
|
||||
import Std::Io::{PrintLine, PrintInt};
|
||||
import Std::Array::{Array, Array_New, Array_Push, Array_Get, Array_Len, Array_Free};
|
||||
import Std::Test::{Test_AssertEqInt, Test_Pass};
|
||||
|
||||
macro! size_of {
|
||||
( $t:type ) => { sizeof($t) as int }
|
||||
}
|
||||
|
||||
macro! new_array {
|
||||
( $t:type, $cap:expr ) => {
|
||||
Array_New<$t>($cap)
|
||||
}
|
||||
}
|
||||
|
||||
func Main() -> int {
|
||||
// Generic type fragment: Array<int>
|
||||
let sz: int = size_of!(Array<int>);
|
||||
PrintInt(sz);
|
||||
PrintLine("");
|
||||
if sz < 8 {
|
||||
PrintLine("FAIL size_of Array<int>");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// $t spliced into monomorphized call Array_New<$t>
|
||||
var a: Array<int> = new_array!(int, 4);
|
||||
Array_Push<int>(&a, 10);
|
||||
Array_Push<int>(&a, 20);
|
||||
Test_AssertEqInt(Array_Get<int>(&a, 0), 10);
|
||||
Test_AssertEqInt(Array_Get<int>(&a, 1), 20);
|
||||
Test_AssertEqInt(Array_Len<int>(&a) as int, 2);
|
||||
Array_Free<int>(&a);
|
||||
|
||||
let psz: int = size_of!(*int);
|
||||
if psz != 4 && psz != 8 {
|
||||
PrintLine("FAIL size_of *int");
|
||||
return 1;
|
||||
}
|
||||
|
||||
PrintLine("PASS macro_type_generic");
|
||||
Test_Pass("macro_type_generic");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Try operator `?` with generic Result<T,E> (non-int Ok payload).
|
||||
import Std::Io::{PrintLine};
|
||||
import Std::Result::{Result, Result_NewOk, Result_NewErr};
|
||||
import Std::String::{String_Eq};
|
||||
|
||||
func GetGreeting(name: String) -> Result<String, String> {
|
||||
if String_Eq(name, "") {
|
||||
return Result_NewErr<String, String>("empty name");
|
||||
}
|
||||
return Result_NewOk<String, String>("hello");
|
||||
}
|
||||
|
||||
func Greet(name: String) -> Result<String, String> {
|
||||
let g: String = GetGreeting(name)?;
|
||||
return Result_NewOk<String, String>(g);
|
||||
}
|
||||
|
||||
func Main() -> int {
|
||||
PrintLine("Try generic Result demo:");
|
||||
|
||||
let ok: Result<String, String> = Greet("bux");
|
||||
if ok.tag == Result_Ok {
|
||||
PrintLine(ok.data.Ok_0);
|
||||
}
|
||||
|
||||
let err: Result<String, String> = Greet("");
|
||||
if err.tag == Result_Err {
|
||||
PrintLine(err.data.Err_0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user