stage3 ai编写新语法语义 同时提供fflush

This commit is contained in:
zzy committed 2026-11-05 09:48:43 +08:00
1 parent bb8761d392
commit 126b979f72
170 files changed
+10729 -3175

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
// 测试侧 Result:编译器核心不内置 Result。
comptime fn Result(T: type, E: type): type {
ret enum {
#ok
Ok: T,
#error
Err: E,
fn unwrap(@Self self: *@self): T {
match self.* {
.Ok(v) => { ret v; }
.Err(e) => { panic("called unwrap on Err"); ret undefined; }
}
}
fn expect(@Self self: *@self, msg: []u8): T {
match self.* {
.Ok(v) => { ret v; }
.Err(e) => { panic(msg); ret undefined; }
}
}
fn unwrap_or_else(@Self self: *@self, f: fn(): T): T {
match self.* {
.Ok(v) => { ret v; }
.Err(e) => { ret f(); }
}
}
};
}
fn main() {}