cli: add deterministic source formatter

This commit is contained in:
dev committed 2026-10-07 18:21:06 +03:00
1 parent d901d5227b
commit 462ddd2c5c
14 files changed
+787 -13

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
// Header stays before the module.
module fmt.layout
import std.option; // explicit import
// Generic declaration.
struct Pair<T: Copy> {
first: T,
second: T,
}
enum Choice<T: Copy> {
some(T),
none
}
fn identity(x: u64) -> u64 effects [] {
x
}
fn apply<T: Copy, F: fn(T) -> T effects []>(x: T) -> T effects [] {
return F(x);
}
fn main() -> u64 effects [] {
let pair = Pair::<u64> { first: 40u64, second: 2u64 }; // keep trailing
let bytes = b"//not a comment\x00";
let x = (pair.first + pair.second) * 1u64;
if x < 43u64 {
match Choice::<u64>::some(x) {
Choice::<u64>::some(v) => {
return apply::<u64, fn identity>(v);
}
Choice::<u64>::none => {
return 0u64;
}
}
} else {
return x >> 1u64;
}
} // final