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.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#import "modules/std/test.sx";
|
||||
pkg :: #import "tests/fixtures/testpkg";
|
||||
|
||||
Point :: struct { x, y: s32; }
|
||||
Point :: struct { x, y: i32; }
|
||||
|
||||
Color :: enum { red; green; blue; }
|
||||
|
||||
@@ -16,7 +16,7 @@ Shape :: enum {
|
||||
|
||||
Overlay :: union {
|
||||
f: f32;
|
||||
i: s32;
|
||||
i: i32;
|
||||
}
|
||||
|
||||
Vec2 :: union {
|
||||
@@ -25,17 +25,17 @@ Vec2 :: union {
|
||||
}
|
||||
|
||||
Defaults :: struct {
|
||||
a: s32;
|
||||
b: s32 = 99;
|
||||
c: s32 = ---;
|
||||
a: i32;
|
||||
b: i32 = 99;
|
||||
c: i32 = ---;
|
||||
}
|
||||
|
||||
OptNode :: struct {
|
||||
value: s32;
|
||||
next: ?s32;
|
||||
value: i32;
|
||||
next: ?i32;
|
||||
}
|
||||
|
||||
OptInner :: struct { val: s32; }
|
||||
OptInner :: struct { val: i32; }
|
||||
|
||||
OptOuter :: struct { inner: ?OptInner; }
|
||||
|
||||
@@ -49,23 +49,23 @@ WindowFlags :: enum flags u32 { vsync :: 64; resizable :: 4; hidden :: 128; }
|
||||
|
||||
// --- Top-level functions ---
|
||||
|
||||
add :: (a: s32, b: s32) -> s32 { a + b }
|
||||
add :: (a: i32, b: i32) -> i32 { a + b }
|
||||
|
||||
mul :: (a: s32, b: s32) -> s32 { a * b }
|
||||
mul :: (a: i32, b: i32) -> i32 { a * b }
|
||||
|
||||
identity :: (x: $T) -> T { x }
|
||||
|
||||
pair_add :: (a: $T, b: $U) -> s64 {
|
||||
cast(s64) a + cast(s64) b
|
||||
pair_add :: (a: $T, b: $U) -> i64 {
|
||||
cast(i64) a + cast(i64) b
|
||||
}
|
||||
|
||||
typed_sum :: (..args: []s32) -> s32 {
|
||||
typed_sum :: (..args: []i32) -> i32 {
|
||||
result := 0;
|
||||
for args (it) { result = result + it; }
|
||||
result
|
||||
}
|
||||
|
||||
apply :: (f: (s32, s32) -> s32, x: s32, y: s32) -> s32 {
|
||||
apply :: (f: (i32, i32) -> i32, x: i32, y: i32) -> i32 {
|
||||
f(x, y)
|
||||
}
|
||||
|
||||
@@ -73,11 +73,11 @@ void_return :: () {
|
||||
return;
|
||||
}
|
||||
|
||||
implicit_return :: (x: s32) -> s32 {
|
||||
implicit_return :: (x: i32) -> i32 {
|
||||
x * 2
|
||||
}
|
||||
|
||||
early_return :: (x: s32) -> s32 {
|
||||
early_return :: (x: i32) -> i32 {
|
||||
if x > 10 { return 99; }
|
||||
x
|
||||
}
|
||||
@@ -86,7 +86,7 @@ vec3 :: (x: f32, y: f32, z: f32) -> Vector(3, f32) {
|
||||
.[x, y, z]
|
||||
}
|
||||
|
||||
point_sum :: (p: Point) -> s32 { p.x + p.y }
|
||||
point_sum :: (p: Point) -> i32 { p.x + p.y }
|
||||
|
||||
// #run compile-time constants
|
||||
|
||||
@@ -100,19 +100,19 @@ CT_CHAIN :: #run add(CT_VAL, 5);
|
||||
// #run compile-time optional tests
|
||||
|
||||
// #run compile-time optional tests
|
||||
ct_opt_coalesce :: () -> s32 {
|
||||
x: ?s32 = 42;
|
||||
y: ?s32 = null;
|
||||
ct_opt_coalesce :: () -> i32 {
|
||||
x: ?i32 = 42;
|
||||
y: ?i32 = null;
|
||||
return (x ?? 0) + (y ?? 99);
|
||||
}
|
||||
|
||||
ct_opt_unwrap :: () -> s32 {
|
||||
x: ?s32 = 77;
|
||||
ct_opt_unwrap :: () -> i32 {
|
||||
x: ?i32 = 77;
|
||||
return x!;
|
||||
}
|
||||
|
||||
ct_opt_guard :: () -> s32 {
|
||||
x: ?s32 = 10;
|
||||
ct_opt_guard :: () -> i32 {
|
||||
x: ?i32 = 10;
|
||||
if x == null { return -1; }
|
||||
return x;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ SmokeErr :: error { Empty, BadDigit, Overflow }
|
||||
// value-carrying, named set: raise three tags or succeed
|
||||
|
||||
// value-carrying, named set: raise three tags or succeed
|
||||
sm_parse :: (n: s32) -> (s32, !SmokeErr) {
|
||||
sm_parse :: (n: i32) -> (i32, !SmokeErr) {
|
||||
if n < 0 { raise error.BadDigit; }
|
||||
if n == 0 { raise error.Empty; }
|
||||
if n > 99 { raise error.Overflow; }
|
||||
@@ -159,7 +159,7 @@ sm_check :: (ok: bool) -> ! {
|
||||
// multi-value, inferred set: `try` propagates; the SCC pass absorbs SmokeErr
|
||||
|
||||
// multi-value, inferred set: `try` propagates; the SCC pass absorbs SmokeErr
|
||||
sm_pair :: (a: s32, b: s32) -> (s32, s32, !) {
|
||||
sm_pair :: (a: i32, b: i32) -> (i32, i32, !) {
|
||||
x := try sm_parse(a);
|
||||
y := try sm_parse(b);
|
||||
return (x, y);
|
||||
@@ -168,7 +168,7 @@ sm_pair :: (a: s32, b: s32) -> (s32, s32, !) {
|
||||
// `catch` block that diverges (logs the tag, then returns a fallback)
|
||||
|
||||
// `catch` block that diverges (logs the tag, then returns a fallback)
|
||||
sm_or_default :: (n: s32) -> s32 {
|
||||
sm_or_default :: (n: i32) -> i32 {
|
||||
return sm_parse(n) catch (e) {
|
||||
print(" logged {}\n", e);
|
||||
return -1;
|
||||
@@ -178,7 +178,7 @@ sm_or_default :: (n: s32) -> s32 {
|
||||
// `onfail` + `defer` interleave: cleanup runs only on the error path
|
||||
|
||||
// `onfail` + `defer` interleave: cleanup runs only on the error path
|
||||
sm_acquire :: (fail: bool) -> (s32, !) {
|
||||
sm_acquire :: (fail: bool) -> (i32, !) {
|
||||
defer print(" smoke defer A\n");
|
||||
onfail print(" smoke onfail B\n");
|
||||
if fail { raise error.Acquire; }
|
||||
@@ -188,7 +188,7 @@ sm_acquire :: (fail: bool) -> (s32, !) {
|
||||
// `or`-chain: try a, fall to try b; propagate if both fail
|
||||
|
||||
// `or`-chain: try a, fall to try b; propagate if both fail
|
||||
sm_first :: (a: s32, b: s32) -> (s32, !) {
|
||||
sm_first :: (a: i32, b: i32) -> (i32, !) {
|
||||
v := try sm_parse(a) or try sm_parse(b);
|
||||
return v;
|
||||
}
|
||||
@@ -198,52 +198,52 @@ sm_first :: (a: s32, b: s32) -> (s32, !) {
|
||||
// --- Foreign function binding ---
|
||||
libc :: #library "c";
|
||||
|
||||
c_abs :: (n: s32) -> s32 #foreign libc "abs";
|
||||
c_abs :: (n: i32) -> i32 #foreign libc "abs";
|
||||
|
||||
// --- Protocol declarations (Phase 1: static dispatch only) ---
|
||||
|
||||
Counter :: protocol {
|
||||
inc :: ();
|
||||
get :: () -> s32;
|
||||
get :: () -> i32;
|
||||
}
|
||||
|
||||
Summable :: protocol {
|
||||
sum :: () -> s32;
|
||||
sum :: () -> i32;
|
||||
}
|
||||
|
||||
SimpleCounter :: struct { val: s32; }
|
||||
SimpleCounter :: struct { val: i32; }
|
||||
|
||||
impl Counter for SimpleCounter {
|
||||
inc :: (self: *SimpleCounter) { self.val += 1; }
|
||||
get :: (self: *SimpleCounter) -> s32 { self.val }
|
||||
get :: (self: *SimpleCounter) -> i32 { self.val }
|
||||
}
|
||||
|
||||
impl Summable for Point {
|
||||
sum :: (self: *Point) -> s32 { self.x + self.y }
|
||||
sum :: (self: *Point) -> i32 { self.x + self.y }
|
||||
}
|
||||
|
||||
// Phase 2: #inline protocol for dynamic dispatch
|
||||
|
||||
// Phase 2: #inline protocol for dynamic dispatch
|
||||
Adder :: protocol #inline {
|
||||
add :: (n: s32);
|
||||
value :: () -> s32;
|
||||
add :: (n: i32);
|
||||
value :: () -> i32;
|
||||
}
|
||||
|
||||
Accumulator :: struct {
|
||||
total: s32;
|
||||
total: i32;
|
||||
}
|
||||
|
||||
impl Adder for Accumulator {
|
||||
add :: (self: *Accumulator, n: s32) { self.total += n; }
|
||||
value :: (self: *Accumulator) -> s32 { self.total }
|
||||
add :: (self: *Accumulator, n: i32) { self.total += n; }
|
||||
value :: (self: *Accumulator) -> i32 { self.total }
|
||||
}
|
||||
|
||||
Doubler :: struct { val: s32; }
|
||||
Doubler :: struct { val: i32; }
|
||||
|
||||
impl Adder for Doubler {
|
||||
add :: (self: *Doubler, n: s32) { self.val = self.val + n + n; }
|
||||
value :: (self: *Doubler) -> s32 { self.val }
|
||||
add :: (self: *Doubler, n: i32) { self.val = self.val + n + n; }
|
||||
value :: (self: *Doubler) -> i32 { self.val }
|
||||
}
|
||||
|
||||
// Phase 4: default methods
|
||||
@@ -257,7 +257,7 @@ Repeater :: protocol {
|
||||
}
|
||||
}
|
||||
|
||||
Printer :: struct { count: s32; }
|
||||
Printer :: struct { count: i32; }
|
||||
|
||||
impl Repeater for Printer {
|
||||
say :: (self: *Printer, msg: string) {
|
||||
@@ -270,18 +270,18 @@ impl Repeater for Printer {
|
||||
|
||||
// P4 edge: Chained default→default calls
|
||||
Chained :: protocol {
|
||||
base :: (msg: string) -> s32;
|
||||
wrap :: (msg: string) -> s32 {
|
||||
base :: (msg: string) -> i32;
|
||||
wrap :: (msg: string) -> i32 {
|
||||
self.base(msg) + 1
|
||||
}
|
||||
double_wrap :: (msg: string) -> s32 {
|
||||
double_wrap :: (msg: string) -> i32 {
|
||||
self.wrap(msg) + self.wrap(msg)
|
||||
}
|
||||
}
|
||||
|
||||
ChainImpl :: struct { val: s32; }
|
||||
ChainImpl :: struct { val: i32; }
|
||||
impl Chained for ChainImpl {
|
||||
base :: (self: *ChainImpl, msg: string) -> s32 {
|
||||
base :: (self: *ChainImpl, msg: string) -> i32 {
|
||||
self.val += 1;
|
||||
msg.len
|
||||
}
|
||||
@@ -310,8 +310,8 @@ impl Cloneable for Point {
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for s64 {
|
||||
eq :: (self: *s64, other: s64) -> bool {
|
||||
impl Eq for i64 {
|
||||
eq :: (self: *i64, other: i64) -> bool {
|
||||
self.* == other
|
||||
}
|
||||
}
|
||||
@@ -324,11 +324,11 @@ are_equal :: ($T: Type/Eq, a: T, b: T) -> bool {
|
||||
}
|
||||
|
||||
Hashable :: protocol {
|
||||
hash :: () -> s64;
|
||||
hash :: () -> i64;
|
||||
}
|
||||
|
||||
impl Hashable for Point {
|
||||
hash :: (self: *Point) -> s64 {
|
||||
hash :: (self: *Point) -> i64 {
|
||||
xx self.x * 31 + xx self.y
|
||||
}
|
||||
}
|
||||
@@ -341,7 +341,7 @@ eq_and_hash :: ($T: Type/Eq/Hashable, a: T, b: T) -> bool {
|
||||
// P6.4: inline constraint syntax ($T/Protocol)
|
||||
|
||||
// P6.4: inline constraint syntax ($T/Protocol)
|
||||
sum_of_inline :: (a: $T/Summable, b: T) -> s32 {
|
||||
sum_of_inline :: (a: $T/Summable, b: T) -> i32 {
|
||||
a.sum() + b.sum()
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ Pair :: struct ($T: Type) {
|
||||
}
|
||||
|
||||
impl Summable for Pair($T) {
|
||||
sum :: (self: *Pair(T)) -> s32 {
|
||||
sum :: (self: *Pair(T)) -> i32 {
|
||||
xx self.a + xx self.b
|
||||
}
|
||||
}
|
||||
@@ -381,10 +381,10 @@ Phys :: struct {
|
||||
|
||||
// Init block test struct
|
||||
Builder :: struct {
|
||||
total: s32;
|
||||
count: s32;
|
||||
total: i32;
|
||||
count: i32;
|
||||
|
||||
add :: (self: *Builder, val: s32) {
|
||||
add :: (self: *Builder, val: i32) {
|
||||
self.total += val;
|
||||
self.count += 1;
|
||||
}
|
||||
@@ -393,9 +393,9 @@ Builder :: struct {
|
||||
// Global variable for address-of test
|
||||
|
||||
// Global variable for address-of test
|
||||
g_smoke_val : s32 = 42;
|
||||
g_smoke_val : i32 = 42;
|
||||
|
||||
write_to_ptr :: (p: *s32) {
|
||||
write_to_ptr :: (p: *i32) {
|
||||
p.* = 99;
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ main :: () {
|
||||
|
||||
// P2.2: pass protocol value to function
|
||||
{
|
||||
use_adder :: (a: Adder, n: s32) -> s32 {
|
||||
use_adder :: (a: Adder, n: i32) -> i32 {
|
||||
a.add(n);
|
||||
a.value()
|
||||
}
|
||||
@@ -467,7 +467,7 @@ main :: () {
|
||||
|
||||
// P3.2: vtable protocol passed to function
|
||||
{
|
||||
use_counter :: (c: Counter) -> s32 {
|
||||
use_counter :: (c: Counter) -> i32 {
|
||||
c.inc();
|
||||
c.inc();
|
||||
c.get()
|
||||
@@ -574,14 +574,14 @@ main :: () {
|
||||
|
||||
// P7.1: impl for generic struct
|
||||
{
|
||||
p := Pair(s32).{ a = 10, b = 20 };
|
||||
p := Pair(i32).{ a = 10, b = 20 };
|
||||
print("P7.1: {}\n", p.sum());
|
||||
}
|
||||
|
||||
// P7.2: generic struct impl with different type arg
|
||||
{
|
||||
p1 := Pair(s32).{ a = 3, b = 7 };
|
||||
p2 := Pair(s64).{ a = 100, b = 200 };
|
||||
p1 := Pair(i32).{ a = 3, b = 7 };
|
||||
p2 := Pair(i64).{ a = 100, b = 200 };
|
||||
print("P7.2: {} {}\n", p1.sum(), p2.sum());
|
||||
}
|
||||
|
||||
@@ -603,14 +603,14 @@ main :: () {
|
||||
|
||||
// P2.7: xx on inline struct literal (no intermediate variable)
|
||||
{
|
||||
use_adder :: (a: Adder) -> s32 { a.add(10); a.value() }
|
||||
use_adder :: (a: Adder) -> i32 { a.add(10); a.value() }
|
||||
result := use_adder(xx Accumulator.{ total = 5 });
|
||||
print("P2.7: {}\n", result);
|
||||
}
|
||||
|
||||
// P3.3: xx on inline struct literal with vtable protocol
|
||||
{
|
||||
use_counter :: (c: Counter) -> s32 { c.inc(); c.inc(); c.get() }
|
||||
use_counter :: (c: Counter) -> i32 { c.inc(); c.inc(); c.get() }
|
||||
result := use_counter(xx SimpleCounter.{ val = 100 });
|
||||
print("P3.3: {}\n", result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user