Files
bux-lang/examples/macro_type.bux
T
dimgigov d60ce2bc3f
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
feat: stdlib daily APIs, macro tt/type paste, riscv64 cross smoke
Sessions 83–87: grow Array/Map/String/Test ergonomics; delimiter-balanced
and juxta :tt macros plus $t:type fragments; expression-level $(…),* in
templates; selfhost slice lits; riscv64/aarch64 cross smoke helper and
freestanding docs. Null-safe CBE type names and String_StartsWith.
2026-07-27 21:40:11 +03:00

56 lines
1.5 KiB
Plaintext

// Session 87 — `$t:type` fragment for sizeof / cast type positions
import Std::Io::{PrintLine, PrintInt};
import Std::Array::{Array, Array_New, Array_Push, Array_Get, Array_Len, Array_Reverse, Array_Free};
import Std::Test::{
Test_AssertEqInt, Test_AssertEqString, Test_AssertNeqString, Test_Pass
};
import Std::String::{String_ToUpper};
macro! size_of {
( $t:type ) => { sizeof($t) as int }
}
macro! cast_zero {
( $t:type ) => { 0 as $t }
}
func Main() -> int {
let a: int = size_of!(int);
let b: int = size_of!(*int);
PrintInt(a);
PrintLine("");
PrintInt(b);
PrintLine("");
// 4 or 8 depending on ABI
if a != 4 && a != 8 {
PrintLine("FAIL size_of int");
return 1;
}
if b != 4 && b != 8 {
PrintLine("FAIL size_of *int");
return 1;
}
let z: int = cast_zero!(int);
Test_AssertEqInt(z, 0);
// Array_Reverse + Test_AssertNeqString
var arr: Array<int> = Array_New<int>(4);
Array_Push<int>(&arr, 1);
Array_Push<int>(&arr, 2);
Array_Push<int>(&arr, 3);
Array_Reverse<int>(&arr);
Test_AssertEqInt(Array_Get<int>(&arr, 0), 3);
Test_AssertEqInt(Array_Get<int>(&arr, 1), 2);
Test_AssertEqInt(Array_Get<int>(&arr, 2), 1);
Test_AssertEqInt(Array_Len<int>(&arr) as int, 3);
Array_Free<int>(&arr);
Test_AssertEqString(String_ToUpper("ok"), "OK");
Test_AssertNeqString("a", "b");
PrintLine("PASS macro_type");
Test_Pass("macro_type");
return 0;
}