Files
sx/examples/0105-types-flags.sx
agra d8076b9333 lang: rename signed integer types sN -> iN
Surface rename of the signed integer family: s1..s64 become i1..i64
(u1..u64, usize, isize unchanged). 'string' keeps the s-prefix arm in
name classification; width parsing moves to the i-prefix arm next to
isize.

Internal TypeId tags follow the surface (.s8/.s16/.s32/.s64 ->
.i8/.i16/.i32/.i64), as do mono-key mangle fragments (ptr_i64,
tu_i64_bool) and all display/diagnostic formatting (i{d}).

Migrated in the same sweep: stdlib + examples + issue repros + FFI C
companions (shared symbol names like ffi_id_i64), expected
stdout/stderr/ir snapshots, specs.md, readme.md, CLAUDE.md/AGENTS.md,
implementation_plan.md, docs/, issue writeups. Vendored stb_image and
historical flow state left untouched.

zig build test: 426/426; examples suite: 595/595.
2026-06-12 09:31:53 +03:00

70 lines
1.6 KiB
Plaintext

#import "modules/std.sx";
// Auto power-of-2 values: read=1, write=2, execute=4
Perms :: enum flags {
read;
write;
execute;
}
// Explicit values with u32 backing type (e.g. for C interop)
WindowFlags :: enum flags u32 {
vsync :: 64;
resizable :: 4;
hidden :: 128;
}
// Backing type on plain enums too
Color :: enum u8 { red; green; blue; }
check_perms :: (p: Perms) {
print(" checking: {}\n", p);
if p & .read { print(" - can read\n"); }
if p & .write { print(" - can write\n"); }
if p & .execute { print(" - can execute\n"); }
}
main :: () {
// Combine flags with |
p :Perms = .read | .write;
print("perms: {}\n", p);
// Test individual flags with &
check_perms(p);
// All flags
all :Perms = .read | .write | .execute;
print("\nall: {}\n", all);
check_perms(all);
// Single flag
r :Perms = .read;
print("\nread only: {}\n", r);
check_perms(r);
// Pass flags to functions, match on them
print("\nmatch on flags:\n");
f :Perms = .execute;
if f == {
case .read: print(" read\n");
case .write: print(" write\n");
case .execute: print(" execute\n");
}
// Explicit values
w :WindowFlags = .vsync | .resizable;
print("\nwindow: {}\n", w);
print("raw value: {}\n", cast(i64) w);
// Backing type on plain enums
c :Color = .blue;
print("\ncolor: {}\n", c);
print("raw: {}\n", cast(i64) c);
// Bitwise ops work on plain integers too
x := 0xFF & 0x0F;
y := 1 | 2 | 4;
print("\n0xFF & 0x0F = {}\n", x);
print("1 | 2 | 4 = {}\n", y);
}