Files
spl/stage1/test11_enum.spl
2026-07-06 10:44:01 +08:00

31 lines
619 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* ===== 模块5复合类型 =====
* test11_enum — 枚举
* 难度3/5
* 验证点enum 定义、简单枚举值、带数据枚举变体
*/
#[extern("vm")] fn vm_printf(fmt: *u8, ...) void;
type Color = enum {
Red,
Green,
Blue,
}
type Expr = enum {
val: i32,
add: struct { left: *Expr, right: *Expr },
tag: Tag,
type Tag = enum {
TagA,
TagB,
TagC,
}
}
fn main() i32 {
vm_printf("enum values: %d %d %d\n", Color.Red, Color.Green, Color.Blue);
vm_printf("enum values: %d %d %d\n", Expr.Tag.TagA, Expr.Tag.TagB, Expr.Tag.TagC);
ret 0;
}