feat: stdlib daily APIs, macro tt/type paste, riscv64 cross smoke
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
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.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user