Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-12-06 13:52:57 -06:00
commit 528ccf1523
782 files changed
+145156

No files matched your search

@@ -0,0 +1,28 @@
import std::io;
# A type parameter known to be an instance of a generic taking a pack has the
# generic's shape, its pack the type arguments from there on, and the shape's
# types are bounded as the generic bounds its parameters. One bounded by
# `pointer` is a `*T::target`, which `*x` reads, and writes where `if const
# T::mutable` says it does.
type strip_pointer<T> = match const T { pointer => strip_pointer<T::target>, else => T };
struct tagged<H, Ts...> where H: integer { var head: H; }
def tagged<H, Ts...>::first(&this): H { return this.head; }
struct pair<A, B> where A: ordered { var a: A; var b: B; }
def pair<A, B>::smaller(&this, other: A): bool { return this.a < other; }
def head_of<T>(x: &T): u64 { if const T is tagged { return x.first() as u64 + T::args.length; } return 0; }
def less<T>(x: &T): bool { if const T is pair { return x.smaller(x.a); } return false; }
def read<T>(x: T): T::target where T: pointer { return *x; }
def write<T>(x: T, v: T::target): bool where T: pointer { if const T::mutable { *x = v; return true; } return false; }
def stripped<T>(x: T): strip_pointer<T> { if const T is pointer { return stripped(*x); } return x; }
def main(): void {
val t := tagged::<u8, bool, i64>{ head = 7 };
val p := pair::<i32, bool>{ a = 3, b = true };
var n: i32 = 4;
val q: *mut i32 = &mut n;
val qq: **mut i32 = &q;
val r: *i32 = &n;
println($"{head_of(&t)} {head_of(&n)} {less(&p)} {read(q)} {write(q, 9)} {write(r, 1)} {n} {stripped(qq)}");
}