mutable decl syntax change

This commit is contained in:
2026-08-05 21:19:41 +02:00
parent 88b94197c9
commit 081a3fd5df
74 changed files with 870 additions and 733 deletions
@@ -1,5 +1,5 @@
main func() i32 {
n usize = 4
items [n]mut i32 = undefined
n usize := 4
items [n]mut i32 := undefined
return 0
}
+6 -6
View File
@@ -10,7 +10,7 @@ State :: struct {
diagnostics std.ArrayList(ScanDiagnostic)
}
arrlist_test std.ArrayList(Token) = arraylist.init(mem.c_allocator)
arrlist_test std.ArrayList(Token) := arraylist.init(mem.c_allocator)
init func(allocator mem.Allocator) State {
return State {
@@ -44,11 +44,11 @@ run func() i32 ! mem.AllocError {
state State :: init(mem.c_allocator)
_ = state
values std.ArrayList(i32) = arraylist.init(mem.c_allocator)
values std.ArrayList(i32) := arraylist.init(mem.c_allocator)
defer arraylist.deinit(&values)
if (values.items.len != 0 or values.capacity != 0) return 1
i usize = 0
i usize := 0
while i < 20 : i += 1 {
arraylist.append(&values, i32(i)) catch |_| {
return .out_of_memory
@@ -71,7 +71,7 @@ run func() i32 ! mem.AllocError {
}
if (values.items.len != 1 or values.items[0] != 7 or values.capacity != capacity) return 7
empty_values arraylist.ArrayList([0]u8) = arraylist.init(mem.c_allocator)
empty_values arraylist.ArrayList([0]u8) := arraylist.init(mem.c_allocator)
defer arraylist.deinit(&empty_values)
zero [0]u8 :: []
arraylist.append(&empty_values, zero) catch |_| {
@@ -79,8 +79,8 @@ run func() i32 ! mem.AllocError {
}
if (empty_values.items.len != 1) return 8
failed arraylist.ArrayList(i32) = arraylist.init(i32, fail_allocator)
failed_as_expected bool = false
failed arraylist.ArrayList(i32) := arraylist.init(i32, fail_allocator)
failed_as_expected bool := false
arraylist.append(&failed, 1) catch |_| {
failed_as_expected = true
}
+2 -2
View File
@@ -18,7 +18,7 @@ c_count_shift func(value u8, count c_uint) u8 {
c_count_fold u8 :: c_count_shift(3, 2)
main func() i32 {
buffer Buffer = undefined
buffer Buffer := undefined
if (folded != 0) return 1
if (contextual != 255) return 28
if (contextual_shift != 128) return 29
@@ -50,7 +50,7 @@ main func() i32 {
if ((c_ushort(240) xor c_ushort(255)) != 15) return 26
if ((c_longlong(64) <<| 60) != maxval!(c_longlong)) return 27
value u8 = 3
value u8 := 3
value <<= 2
value |= 1
value xor= 5
+6 -6
View File
@@ -7,8 +7,8 @@
main func() i32 {
# 1. `break` out of a `while` once i reaches 5.
i i32 = 0
a i32 = 0
i i32 := 0
a i32 := 0
while i < 100 : i += 1 {
if (i == 5) break
a += 1
@@ -16,7 +16,7 @@ main func() i32 {
if (a != 5) return 101
# 2. `continue` past n == 3 while summing 0..9 (45 - 3 = 42).
b i32 = 0
b i32 := 0
for 0..10 |n| {
if (n == 3) continue
b = b + n
@@ -25,7 +25,7 @@ main func() i32 {
# 3. Nested loops: the inner `break` exits only the inner loop, so the outer
# loop still runs all three iterations (each contributing one y == 0 pass).
c i32 = 0
c i32 := 0
for 0..3 |x| {
for 0..3 |y| {
if (y == 1) break
@@ -38,7 +38,7 @@ main func() i32 {
# 4. `continue` on the final element of an inclusive range bounded by the
# element type's maximum must exit cleanly, not overflow the increment.
hi u8 :: 255
d i32 = 0
d i32 := 0
for 0..=hi |v| {
if (v == 255) continue
d += 1
@@ -47,7 +47,7 @@ main func() i32 {
# 5. `while true` is exitable via `break` (so it is not an infinite loop and
# the code after it is reachable).
e i32 = 0
e i32 := 0
while true {
e += 1
if (e == 7) break
@@ -1,7 +1,7 @@
# Compound assignment (`+=`, `-=`, `*=`, `/=`) and explicit integer division.
check_float func() i32 {
x f64 = 10.0
x f64 := 10.0
x /= 4.0 # 2.5
x *= 2.0 # 5.0
x -= 1.0 # 4.0
@@ -13,7 +13,7 @@ check_float func() i32 {
}
check_unsigned func() i32 {
n u32 = 100
n u32 := 100
n = divtrunc!(n, 7) # 14
n -= 4 # 10
if n == 10 {
@@ -23,7 +23,7 @@ check_unsigned func() i32 {
}
main func() i32 {
total i32 = 0
total i32 := 0
total += 10 # 10
total -= 3 # 7
total *= 4 # 28
@@ -33,7 +33,7 @@ main func() i32 {
total = total + 2 * 3 - 4
# compound assignment as a while-loop update
i i32 = 0
i i32 := 0
while i < 5 : i += 1 {
total += 1 # +5 => 21
}
+1 -1
View File
@@ -15,7 +15,7 @@ nested func(value int) int {
}
make_array func($N usize) [N]u8 {
data [N]u8 = undefined
data [N]u8 := undefined
return data
}
@@ -14,13 +14,13 @@ id func($T type, value T) T {
}
buffer func($T type, $N usize, value T) [N]T {
data [N]T = undefined
data [N]T := undefined
_ = value
return data
}
zero func($T type) T {
value T = undefined
value T := undefined
return value
}
@@ -86,12 +86,12 @@ main func() i32 {
if fixed_len(&fixed) != 3 {
return 7
}
assigned i32 = 1
assigned i32 := 1
assigned = zero()
_ = assigned
_ = take_i32(zero())
_ = return_zero()
optional ?u32 = null
optional ?u32 := null
if !same_type(?u32, optional) {
return 8
}
+11 -11
View File
@@ -32,8 +32,8 @@ make_point func() Point {
}
sum_loop func(limit i32) i32 {
total i32 = 0
i i32 = 0
total i32 := 0
i i32 := 0
while i < limit {
i += 1
if i == 2 {
@@ -45,8 +45,8 @@ sum_loop func(limit i32) i32 {
}
sum_for func() i32 {
total i32 = 0
values [_]i32 = [1, 2, 3]
total i32 := 0
values [_]i32 := [1, 2, 3]
for values |value, index| {
total += value + index
}
@@ -54,7 +54,7 @@ sum_for func() i32 {
}
defer_value func() i32 {
value i32 = 1
value i32 := 1
{
defer value += 10
value += 1
@@ -140,7 +140,7 @@ use_try func() i32 ! Error {
}
ct_errdefer func(fail bool) i32 ! Error {
trace i32 = 0
trace i32 := 0
defer trace = trace * 10 + 1
errdefer |err| {
if (err == .bad) trace = trace * 10 + 2
@@ -151,7 +151,7 @@ ct_errdefer func(fail bool) i32 ! Error {
}
ct_try_errdefer func() i32 ! Error {
trace i32 = 0
trace i32 := 0
defer trace = trace * 10 + 4
errdefer |err| {
if (err == .bad) trace = trace * 10 + 5
@@ -185,20 +185,20 @@ alias_add func(left @mut i32, right @mut i32) void {
}
storage_mutation func() i32 {
values [3]mut i32 = [1, 2, 3]
values [3]mut i32 := [1, 2, 3]
values[0] += 1
bump_ptr(&values[1])
view []mut i32 = values[..]
view []mut i32 := values[..]
for view |@item| {
item^ += 1
}
pointer *mut i32 = view.ptr
pointer *mut i32 := view.ptr
pointer[2] += 1
alias_add(&values[0], &view[0])
box Box = Box { point = Point { x = 2, y = 3 } }
box Box := Box { point = Point { x = 2, y = 3 } }
match box {
.point |@p|: p.x += values[1]
.empty: values[0] = values[0]
@@ -1,5 +1,5 @@
make_array func($N usize) [N]u8 {
data [N]u8 = undefined
data [N]u8 := undefined
return data
}
@@ -6,10 +6,10 @@ observe func(counter @mut i32, value ?i32) ?i32 {
}
main func() i32 {
total i32 = 0
total i32 := 0
# present optional scalar -> binds v to the unwrapped value
a ?i32 = 40
a ?i32 := 40
if a |v| {
total = total + v # 40
} else {
@@ -17,7 +17,7 @@ main func() i32 {
}
# null -> else branch taken; the binding is not in scope there
b ?i32 = null
b ?i32 := null
if b |v| {
total = total + v
} else {
@@ -25,20 +25,20 @@ main func() i32 {
}
# optional pointer present -> binds q to a non-null @i32; deref proves it
n i32 = 0
p ?@i32 = &n
n i32 := 0
p ?@i32 := &n
if p |q| {
total = total + q^ # +0
}
# optional pointer null -> skipped
z ?@i32 = null
z ?@i32 := null
if z |_| {
total = total + 1000
}
# guarded multi-unwrap exposes every capture to the guard and then-block
age ?i32 = 2
age ?i32 := 2
if a and age |value, years : value + years == 42| {
total = total
} else {
@@ -46,7 +46,7 @@ main func() i32 {
}
# parenthesized chains and three-value unwraps are equivalent
bonus ?i32 = 0
bonus ?i32 := 0
if (a and age and bonus) |value, years, extra : value + years + extra == 42| {
total = total
} else {
@@ -64,7 +64,7 @@ main func() i32 {
}
# a failed unwrap prevents later expressions from being evaluated
calls i32 = 0
calls i32 := 0
if b and observe(&calls, age) |missing, observed| {
total = total + missing + observed
}
+3 -3
View File
@@ -23,7 +23,7 @@ noisy func() bool {
}
main func() i32 {
total i32 = 0
total i32 := 0
# comparisons drive if / else if / else
total = total + classify(-5) # 1
@@ -45,9 +45,9 @@ main func() i32 {
}
# block scoping: inner bindings do not escape the block
x i32 = 1
x i32 := 1
if x == 1 {
inner_x i32 = 100
inner_x i32 := 100
if inner_x == 100 {
total = total + 5 # 40
}
+9 -9
View File
@@ -7,7 +7,7 @@
# The return value is captured before defers run, so the mutation here does not
# change what is returned (Zig semantics).
spill_check func() i32 {
x i32 = 5
x i32 := 5
defer x = 999
return x
}
@@ -15,7 +15,7 @@ spill_check func() i32 {
# A function-scope defer runs only at function exit; a `break` runs the loop-body
# defer but NOT the enclosing function-scope defer.
enclosing_defer_check func() i32 {
v i32 = 0
v i32 := 0
defer v = v + 100
for 0..3 |i| {
defer v = v + 1
@@ -89,7 +89,7 @@ main func() i32 {
if (spill_check() != 5) return 101
# 2. LIFO ordering, run at end of each loop iteration.
r i32 = 0
r i32 := 0
for 0..1 |i| {
defer r = r * 2 + 1 # registered first -> runs last
defer r = r * 2 # registered second -> runs first
@@ -99,16 +99,16 @@ main func() i32 {
# 3. scoped bare block + scoped defer (defer fires at the closing brace, and
# the block-local is not visible afterwards).
a i32 = 1
a i32 := 1
{
defer a = 4
c i32 = 3
c i32 := 3
_ = c
}
if (a != 4) return 103
# 4. `defer { ... }` block: all its statements run (in order) at scope close.
s i32 = 0
s i32 := 0
{
defer {
s = s + 1
@@ -119,7 +119,7 @@ main func() i32 {
if (s != 60) return 104 # 5 -> 6 -> 60
# 5. `break` flushes the loop-body defer.
bc i32 = 0
bc i32 := 0
for 0..5 |i| {
defer bc = bc + 1
if (i == 2) break
@@ -127,7 +127,7 @@ main func() i32 {
if (bc != 3) return 105 # i=0,1 fall-through + i=2 break
# 6. `continue` flushes the loop-body defer.
cc i32 = 0
cc i32 := 0
for 0..3 |i| {
defer cc = cc + 1
if (i == 1) continue
@@ -139,7 +139,7 @@ main func() i32 {
if (enclosing_defer_check() != 2) return 107
# 8. errdefer is skipped on success; ordinary defers stay interleaved.
trace i32 = 0
trace i32 := 0
if ((explicit_cleanup(false, &trace) catch 0) != 7 or trace != 31) return 108
# 9. Explicit errors run errdefer and expose the captured error.
+12 -12
View File
@@ -24,9 +24,9 @@ take func(value LocalID) LocalID {
main func() i32 {
id LocalID :: LocalID(7)
copy LocalID = take(id)
maybe ?LocalID = copy
pointer @LocalID = &copy
copy LocalID := take(id)
maybe ?LocalID := copy
pointer @LocalID := &copy
point PointID :: PointID(Point { x = 1, y = 2 })
bytes Bytes :: Bytes([3, 4])
wrapped WrappedID :: WrappedID(id)
@@ -64,15 +64,15 @@ main func() i32 {
return 8
}
arithmetic Signed = Signed(4)
arithmetic Signed := Signed(4)
arithmetic += 3
arithmetic -= 2
arithmetic *= 5
fraction Real = Real(3.0)
fraction Real := Real(3.0)
fraction /= 2.0
if arithmetic != 25 or fraction != 1.5 { return 9 }
bits Mask = Mask(3)
bits Mask := Mask(3)
bits |= 8
bits xor= 2
bits &= 9
@@ -81,18 +81,18 @@ main func() i32 {
bits <<|= u8(5)
if bits != 255 { return 10 }
values [10]u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
values [10]u8 := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
if values[LocalID(4)] != 4 { return 11 }
section []u8 = values[LocalID(2)..LocalID(5)]
section []u8 := values[LocalID(2)..LocalID(5)]
if section.len != 3 or section[usize(0)] != 2 or section[usize(2)] != 4 { return 12 }
if u32(id) != 7 or usize(id) != 7 or f64(id) != 7.0 { return 13 }
extracted LocalID = LocalID(wrapped)
extracted LocalID := LocalID(wrapped)
if extracted != id { return 14 }
minimum Signed = minval!(Signed)
maximum Mask = maxval!(Mask)
nested_max WrappedID = maxval!(WrappedID)
minimum Signed := minval!(Signed)
maximum Mask := maxval!(Mask)
nested_max WrappedID := maxval!(WrappedID)
if i32(minimum) != minval!(i32) or u8(maximum) != 255 or u32(nested_max) != maxval!(u32) {
return 15
}
+1 -1
View File
@@ -17,7 +17,7 @@ identity c_func(value State) State {
}
main func() i32 {
state State = identity(.running)
state State := identity(.running)
values [2]State :: [.started, State.stopped]
animal animals.Animal :: animals.Animal.dog
if same(state, .running) and
+4 -4
View File
@@ -125,7 +125,7 @@ inline_detail func(value i32) i32 ! union(enum) {
}
main func() i32 {
acc i32 = 0
acc i32 := 0
a :: maybe(0) catch 7
b :: maybe(4) catch 99
@@ -166,11 +166,11 @@ main func() i32 {
acc = acc + a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p
acc = acc + pick(.left)
r Right = .right
r Right := .right
acc = acc + pick(r)
box BoxA = .a{8}
box BoxA := .a{8}
acc = acc + payload(box)
empty BoxB = .b
empty BoxB := .b
acc = acc + payload(empty)
acc = acc + payload(.a{9})
+3 -3
View File
@@ -5,9 +5,9 @@ pass func(value range) range {
}
main func() i32 {
total i32 = 0
total i32 := 0
items [3]mut i32 = [1, 2, 3]
items [3]mut i32 := [1, 2, 3]
for items |item, index| {
total = total + item
_ = index
@@ -17,7 +17,7 @@ main func() i32 {
item^ = item^ + 1
}
view []mut i32 = items[..]
view []mut i32 := items[..]
for view |@item, index| {
item^ = item^ + 1
_ = index
+10 -10
View File
@@ -6,23 +6,23 @@ make_range func(calls @mut i32, end usize) range {
global_range :: 0..1
main func() i32 {
total i32 = 0
total i32 := 0
first u8 = 254
last u8 = 255
first u8 := 254
last u8 := 255
for first..=last |value| {
_ = value
total = total + 1
}
signed_start i8 = -2
signed_end i8 = 1
signed_start i8 := -2
signed_end i8 := 1
for signed_start..signed_end |value| {
_ = value
total = total + 1
}
limit usize = 3
limit usize := 3
for 0..(limit + 1) |value| {
_ = value
total = total + 1
@@ -41,19 +41,19 @@ main func() i32 {
total = total + 100
}
empty [0]i32 = []
empty [0]i32 := []
for empty |value| {
_ = value
total = total + 100
}
pointed i32 = 3
pointers [1]@mut i32 = [&pointed]
pointed i32 := 3
pointers [1]@mut i32 := [&pointed]
for pointers |pointer| {
total = total + pointer^
}
calls i32 = 0
calls i32 := 0
for make_range(&calls, 2) |value| {
_ = value
total = total + 1
@@ -1,6 +1,6 @@
main func() i32 {
items [3]mut i32 = undefined
i int = 1
items [3]mut i32 := undefined
i int := 1
items[i] = 42
return 0
}
@@ -1,6 +1,6 @@
main func() i32 {
items [3]mut i32 = undefined
i i32 = 1
items [3]mut i32 := undefined
i i32 := 1
items[i] = 42
return 0
}
+5 -5
View File
@@ -68,8 +68,8 @@ main func() i32 {
return 2
}
a Value = .number{41}
b Value = .number{41}
a Value := .number{41}
b Value := .number{41}
if !equal_value(a, b) or equal_value(a, .pair{left = 41, right = 0}) {
return 3
}
@@ -78,8 +78,8 @@ main func() i32 {
return 4
}
pair_a Value = .pair{left = 2, right = 3}
pair_b Value = .pair{left = 2, right = 3}
pair_a Value := .pair{left = 2, right = 3}
pair_b Value := .pair{left = 2, right = 3}
if !equal_value(pair_a, pair_b) or !equal_value(.empty, .empty) {
return 5
}
@@ -88,7 +88,7 @@ main func() i32 {
return 6
}
empty Value = .empty
empty Value := .empty
increment(&empty)
return 0
}
@@ -1,4 +1,4 @@
bad int = 4
bad int := 4
read_bad func() int {
return bad
+2 -2
View File
@@ -85,7 +85,7 @@ bad_writer func() io.Writer {
}
rejects_bad_read func() bool {
buffer [1]mut u8 = [0]
buffer [1]mut u8 := [0]
_ = io.read(bad_reader(), buffer[..]) catch |err| {
return err == .read_failed
}
@@ -108,7 +108,7 @@ rejects_bad_write func() bool {
main func(init process.Init) i32 {
system io.Io :: init.io
buffer [2]mut u8 = [0, 0]
buffer [2]mut u8 := [0, 0]
count usize :: io.read(ok_reader(), buffer[..]) catch 0
if count != 2 or buffer[0] != 'o' or buffer[1] != 'k' {
return 1
+9 -9
View File
@@ -63,18 +63,18 @@ make_box func() Box {
}
main func() i32 {
acc i32 = 0
acc i32 := 0
dog Data = Data{ dog = 9 }
bird Data = Data{ bird = 38 }
dog Data := Data{ dog = 9 }
bird Data := Data{ bird = 38 }
acc = acc + describe(dog) + describe(bird) # 10 + 40 = 50
# same-type multi-pattern capture
acc = acc + payload_of(dog) + payload_of(bird) # 9 + 38 = 47
# enum statement match, exhaustive, with a multi-pattern arm
a Animal = .bird
rank i32 = 0
a Animal := .bird
rank i32 := 0
match a {
.dog, .cat: rank = 1
.bird: rank = 3
@@ -89,7 +89,7 @@ main func() i32 {
acc = acc + legs # +2
# scalar match: a range arm, a multi-literal arm, and a mandatory else
bucket i32 = 0
bucket i32 := 0
match rank {
0..3: bucket = 1 # exclusive 0,1,2 — does not include 3
3, 4: bucket = 5 # rank is 3
@@ -98,8 +98,8 @@ main func() i32 {
acc = acc + bucket # +5
# void-payload variant: contextual construction (`.empty` coerces to Box) + no-capture arm
e Box = .empty
hit i32 = 0
e Box := .empty
hit i32 := 0
match e {
.point |pt|: hit = pt.x
.empty: hit = 7
@@ -107,7 +107,7 @@ main func() i32 {
acc = acc + hit # +7
# pointer capture mutates the subject's payload in place
b Box = Box{ point = Point{ x = 1, y = 2 } }
b Box := Box{ point = Point{ x = 1, y = 2 } }
match b {
.point |@p|: p.x = 10
.empty: hit = hit
@@ -1,7 +1,7 @@
mem :: import "@std/mem"
raw_allocator_test func() i32 {
resized ?*mut u8 = mem.raw_realloc(mem.c_allocator, null, 0, 4, 1)
resized ?*mut u8 := mem.raw_realloc(mem.c_allocator, null, 0, 4, 1)
if resized |bytes| {
bytes[0] = 10
bytes[1] = 20
@@ -11,7 +11,7 @@ raw_allocator_test func() i32 {
return 20
}
grown ?*mut u8 = mem.raw_realloc(mem.c_allocator, resized, 4, 8, 1)
grown ?*mut u8 := mem.raw_realloc(mem.c_allocator, resized, 4, 8, 1)
if grown |bytes| {
resized = grown
if bytes[0] != 10 or bytes[1] != 20 or bytes[2] != 30 or bytes[3] != 40 {
@@ -23,7 +23,7 @@ raw_allocator_test func() i32 {
return 22
}
shrunk ?*mut u8 = mem.raw_realloc(mem.c_allocator, resized, 8, 2, 1)
shrunk ?*mut u8 := mem.raw_realloc(mem.c_allocator, resized, 8, 2, 1)
if shrunk |bytes| {
resized = shrunk
if bytes[0] != 10 or bytes[1] != 20 {
@@ -35,7 +35,7 @@ raw_allocator_test func() i32 {
return 24
}
invalid ?*mut u8 = mem.raw_realloc(mem.c_allocator, resized, 2, 4, 24)
invalid ?*mut u8 := mem.raw_realloc(mem.c_allocator, resized, 2, 4, 24)
if invalid |memory| {
mem.raw_free(mem.c_allocator, memory, 4, 24)
mem.raw_free(mem.c_allocator, resized, 2, 1)
@@ -54,14 +54,14 @@ raw_allocator_test func() i32 {
return 27
}
over_aligned ?*mut u8 = mem.raw_alloc(mem.c_allocator, 4, 32)
over_aligned ?*mut u8 := mem.raw_alloc(mem.c_allocator, 4, 32)
if over_aligned |bytes| {
bytes[0] = 11
bytes[1] = 22
} else {
return 28
}
over_aligned_grown ?*mut u8 = mem.raw_realloc(mem.c_allocator, over_aligned, 4, 8, 32)
over_aligned_grown ?*mut u8 := mem.raw_realloc(mem.c_allocator, over_aligned, 4, 8, 32)
if over_aligned_grown |bytes| {
if bytes[0] != 11 or bytes[1] != 22 {
mem.raw_free(mem.c_allocator, over_aligned_grown, 8, 32)
@@ -73,19 +73,19 @@ raw_allocator_test func() i32 {
return 30
}
zero_alignment ?*mut u8 = mem.raw_alloc(mem.c_allocator, 8, 0)
zero_alignment ?*mut u8 := mem.raw_alloc(mem.c_allocator, 8, 0)
if zero_alignment |memory| {
mem.raw_free(mem.c_allocator, memory, 8, 0)
return 1
}
bad_alignment ?*mut u8 = mem.raw_alloc(mem.c_allocator, 8, 24)
bad_alignment ?*mut u8 := mem.raw_alloc(mem.c_allocator, 8, 24)
if bad_alignment |memory| {
mem.raw_free(mem.c_allocator, memory, 8, 24)
return 2
}
aligned ?*mut u8 = mem.raw_alloc(mem.c_allocator, 64, 32)
aligned ?*mut u8 := mem.raw_alloc(mem.c_allocator, 64, 32)
defer mem.raw_free(mem.c_allocator, aligned, 64, 32)
if aligned |bytes| {
bytes[0] = 1
+16 -16
View File
@@ -21,9 +21,9 @@ task_list_init func(allocator mem.Allocator) TaskList {
}
alloc_i32s func(allocator mem.Allocator, count usize) ?[]mut i32 {
fallback [1]mut i32 = undefined
failed bool = false
values []mut i32 = mem.alloc(allocator, count) catch |_| {
fallback [1]mut i32 := undefined
failed bool := false
values []mut i32 := mem.alloc(allocator, count) catch |_| {
failed = true
yield (&fallback).ptr[..0]
}
@@ -42,14 +42,14 @@ task_list_reserve func(list @mut TaskList, capacity usize) bool {
return true
}
new_ids ?[]mut i32 = alloc_i32s(list.allocator, capacity)
new_priorities ?[]mut i32 = alloc_i32s(list.allocator, capacity)
new_durations ?[]mut i32 = alloc_i32s(list.allocator, capacity)
new_ids ?[]mut i32 := alloc_i32s(list.allocator, capacity)
new_priorities ?[]mut i32 := alloc_i32s(list.allocator, capacity)
new_durations ?[]mut i32 := alloc_i32s(list.allocator, capacity)
if (new_ids and new_priorities and new_durations) |ids, priorities, durations| {
if list.len > 0 {
if (list.ids and list.priorities and list.durations) |old_ids, old_priorities, old_durations| {
i usize = 0
i usize := 0
while i < list.len : i += 1 {
ids[i] = old_ids[i]
priorities[i] = old_priorities[i]
@@ -82,7 +82,7 @@ task_list_reserve func(list @mut TaskList, capacity usize) bool {
task_list_push func(list @mut TaskList, id i32, priority i32, duration i32) bool {
if list.len == list.capacity {
new_capacity usize = 2
new_capacity usize := 2
if list.capacity != 0 {
new_capacity = list.capacity * 2
}
@@ -92,7 +92,7 @@ task_list_push func(list @mut TaskList, id i32, priority i32, duration i32) bool
}
if (list.ids and list.priorities and list.durations) |ids, priorities, durations| {
index usize = list.len
index usize := list.len
ids[index] = id
priorities[index] = priority
durations[index] = duration
@@ -113,11 +113,11 @@ task_list_best_id func(list @mut TaskList) i32 {
}
if (list.ids and list.priorities and list.durations) |ids, priorities, durations| {
best_index usize = 0
best_score i32 = task_score(priorities[0], durations[0])
i usize = 1
best_index usize := 0
best_score i32 := task_score(priorities[0], durations[0])
i usize := 1
while i < list.len : i += 1 {
score i32 = task_score(priorities[i], durations[i])
score i32 := task_score(priorities[i], durations[i])
if score > best_score {
best_score = score
best_index = i
@@ -130,9 +130,9 @@ task_list_best_id func(list @mut TaskList) i32 {
}
task_list_total_duration func(list @mut TaskList) i32 {
total i32 = 0
total i32 := 0
if list.durations |durations| {
i usize = 0
i usize := 0
while i < list.len : i += 1 {
total += durations[i]
}
@@ -152,7 +152,7 @@ task_list_deinit func(list @mut TaskList) void {
}
task_list_test func() i32 {
tasks TaskList = task_list_init(mem.c_allocator)
tasks TaskList := task_list_init(mem.c_allocator)
defer task_list_deinit(&tasks)
if task_list_push(&tasks, 101, 3, 5) == false {
+14 -14
View File
@@ -30,8 +30,8 @@ hide probe_vtable mem.AllocatorVTable :: mem.AllocatorVTable {
typed_allocator_test func() i32 {
if (sizeof!(mem.Allocator) != 16) return 31
first_calls [1]mut usize = [0]
second_calls [1]mut usize = [0]
first_calls [1]mut usize := [0]
second_calls [1]mut usize := [0]
first_allocator mem.Allocator :: mem.Allocator {
context = &first_calls,
vtable = &probe_vtable,
@@ -47,9 +47,9 @@ typed_allocator_test func() i32 {
_ = mem.raw_alloc(second_allocator, 1, 1)
if (first_calls[0] != 3 or second_calls[0] != 1) return 32
i32_fallback [1]mut i32 = undefined
empty_failed bool = false
empty []mut i32 = mem.alloc(first_allocator, 0) catch |_| {
i32_fallback [1]mut i32 := undefined
empty_failed bool := false
empty []mut i32 := mem.alloc(first_allocator, 0) catch |_| {
empty_failed = true
yield (&i32_fallback).ptr[..0]
}
@@ -57,9 +57,9 @@ typed_allocator_test func() i32 {
mem.free(first_allocator, empty)
if (first_calls[0] != 3) return 33
zero_sized_fallback [1]mut [0]u8 = undefined
zero_sized_failed bool = false
zero_sized []mut [0]u8 = mem.alloc([0]u8, first_allocator, 3) catch |_| {
zero_sized_fallback [1]mut [0]u8 := undefined
zero_sized_failed bool := false
zero_sized []mut [0]u8 := mem.alloc([0]u8, first_allocator, 3) catch |_| {
zero_sized_failed = true
yield (&zero_sized_fallback).ptr[..0]
}
@@ -68,22 +68,22 @@ typed_allocator_test func() i32 {
mem.free([0]u8, first_allocator, zero_sized)
if (first_calls[0] != 3) return 35
u64_fallback [1]mut u64 = undefined
overflow_fallback_failed bool = false
overflow_fallback []mut u64 = mem.alloc(first_allocator, 0) catch |_| {
u64_fallback [1]mut u64 := undefined
overflow_fallback_failed bool := false
overflow_fallback []mut u64 := mem.alloc(first_allocator, 0) catch |_| {
overflow_fallback_failed = true
yield (&u64_fallback).ptr[..0]
}
if (overflow_fallback_failed) return 37
overflow_failed bool = false
overflow_failed bool := false
_ = mem.alloc(u64, first_allocator, maxval!(usize)) catch |_| {
overflow_failed = true
yield overflow_fallback
}
if (overflow_failed == false or first_calls[0] != 3) return 40
typed_failed bool = false
typed []mut i32 = mem.alloc(mem.c_allocator, 4) catch |_| {
typed_failed bool := false
typed []mut i32 := mem.alloc(mem.c_allocator, 4) catch |_| {
typed_failed = true
yield (&i32_fallback).ptr[..0]
}
+6 -6
View File
@@ -48,26 +48,26 @@ score_for func(k Kind) i32 {
}
main func() i32 {
items [LEN]mut i32 = undefined
items [LEN]mut i32 := undefined
items[0] = 10
items[1] = 20
idx u8 = 2
idx u8 := 2
items[idx] = items[0] + items[1]
if (items[2] != 30) return 1
native_i i32 = 12
native_i i32 := 12
if (take_c_int(native_i) != 12) return 2
native_u u8 = 7
native_u u8 := 7
if (take_c_uchar(native_u) != 7) return 3
native_f f32 = 3.25
native_f f32 := 3.25
cf :: take_c_float(native_f)
if (cf < 3.0 or cf > 4.0) return 4
if (cf == 0.0) return 5
native_d f64 = 5.0
native_d f64 := 5.0
cd :: take_c_double(native_d)
if (cd != 5.0) return 6
+2 -2
View File
@@ -86,8 +86,8 @@ main func(init process.Init) i32 {
}
writer io.Writer :: io.stdout(init.io)
positive f64 = 1.0
zero f64 = 0.0
positive f64 := 1.0
zero f64 := 0.0
infinity f64 :: positive / zero
nan f64 :: zero / zero
io.print(writer, "{} {} {} {} {s} {d} {b} {o} {x} {X} {c} {e} {{}} {d} {b} {} {} {e}\n", {
+6 -6
View File
@@ -2,11 +2,11 @@ Point :: struct {
x i32
}
counter int = 0
ratio float = 1
span range = 0..2
point Point = Point { x = 1 }
values [_]mut i32 = [10, 20]
counter := i32(0)
ratio := 1.0
span := 0..2
point Point := Point { x = 1 }
values [_]mut i32 := [10, 20]
bump func(value @mut i32) void {
value^ += 1
@@ -19,7 +19,7 @@ main func() i32 {
point.x += counter
values[1] = point.x
total i32 = counter + point.x + values[1]
total i32 := counter + point.x + values[1]
for span |i| {
total += i
}
+1 -1
View File
@@ -1,5 +1,5 @@
main func() i32 {
value i32 = 1
value := i32(1)
value = value + 2
return value
}
+1 -1
View File
@@ -1,4 +1,4 @@
main func() void {
value i8 = 127
value i8 := 127
_ = value + 1
}
+1 -1
View File
@@ -11,7 +11,7 @@ sum_brolang func(a, b int) int {
}
main func() void {
y int = 4
y int := 4
a_add_b_c :: sum_c(1, 2)
a_add_b_brolang :: sum_brolang(1, 2)
_ = y
+1 -1
View File
@@ -1,5 +1,5 @@
main func() i32 {
flag bool = true
flag bool := true
value :: i32(flag)
return value
}
+2 -2
View File
@@ -16,7 +16,7 @@ Thing :: union(enum) {
}
main func() i32 {
x Data = Data{ bird = 37 }
y Thing = Thing{ a = 5 }
x Data := Data{ bird = 37 }
y Thing := Thing{ a = 5 }
return x.bird + y.a
}
+4 -4
View File
@@ -9,7 +9,7 @@ format func() []u8 {
}
sum func($T type, value T) i32 {
total i32 = 0
total i32 := 0
match typeinfo!(T) {
.record |record|: inline for record.fields |field| {
total += i32(field!(value, field.name))
@@ -20,7 +20,7 @@ sum func($T type, value T) i32 {
}
static_control func($T type, value T) i32 {
total i32 = 0
total i32 := 0
match typeinfo!(T) {
.record |record|: inline for record.fields |field| {
{
@@ -49,7 +49,7 @@ row_value func(row Row) i32 {
}
static_aggregates func() i32 {
total i32 = 0
total i32 := 0
inline for {Row {value = 2}, Row {value = 40}} |row| {
total += row_value(row)
}
@@ -57,7 +57,7 @@ static_aggregates func() i32 {
}
main func() i32 {
numbers Numbers = Numbers {1, 2, 39}
numbers Numbers := Numbers {1, 2, 39}
singleton :: {42,}
empty :: {}
block_value :: {
+1 -1
View File
@@ -4,6 +4,6 @@ Val :: union {
}
main func() i32 {
x Val = Val{ n = 42 }
x Val := Val{ n = 42 }
return x.n
}
+3 -3
View File
@@ -1,8 +1,8 @@
warn_only func(value i32, unused i32) i32 {
local i32 = 1
write_only i32 = 2
local i32 := 1
write_only i32 := 2
write_only = 3
consumed i32 = value
consumed i32 := value
_ = consumed
return value
}
+8 -8
View File
@@ -1,31 +1,31 @@
# Milestone 5: boolean while loops with optional post-iteration updates.
return_before_update func() i32 {
i i32 = 0
i i32 := 0
while true : i = i + 1 {
return i
}
}
main func() i32 {
total i32 = 0
total i32 := 0
# ordinary condition and update
i u32 = 0
i u32 := 0
while i < 5 : i = i + 1 {
total = total + 2
}
# equivalent parenthesized header
j u32 = 0
j u32 := 0
while (j < 4) : (j = j + 1) {
total = total + 3
}
# nested loops and body-local storage
outer u32 = 0
outer u32 := 0
while outer < 2 : outer = outer + 1 {
inner u32 = 0
inner u32 := 0
while inner < 3 : inner = inner + 1 {
total = total + 2
}
@@ -33,9 +33,9 @@ main func() i32 {
# Body-local storage stays scoped to the body. The update still targets
# the mutable k declared before the loop.
k u32 = 0
k u32 := 0
while k < 4 : k = k + 1 {
body_k u32 = 100
body_k u32 := 100
if body_k == 100 {
total = total + 2
}
+12 -12
View File
@@ -19,7 +19,7 @@ basic func() i32 {
# Typed `T =`: the yield coerces to the annotation.
typed func() i64 {
x i64 = {
x i64 := {
yield 100
}
return x
@@ -29,7 +29,7 @@ typed func() i64 {
# local, but the captured value is unchanged.
spill func() i32 {
v :: {
n i32 = 5
n i32 := 5
defer n = 999
yield n
}
@@ -38,7 +38,7 @@ spill func() i32 {
# Reassignment into an existing mutable local.
reassign func() i32 {
r i32 = 0
r i32 := 0
r = {
yield 7
}
@@ -61,13 +61,13 @@ vif_untyped func(sel i32) i32 {
# Typed `T =`: every branch coerces to the annotation.
vif_typed func(sel i32) i32 {
r i32 = if (sel == 0) { yield 100 } else { yield 200 }
r i32 := if (sel == 0) { yield 100 } else { yield 200 }
return r
}
# Assigned into an existing local.
vif_reassign func(sel i32) i32 {
r i32 = 0
r i32 := 0
r = if (sel == 0) { yield 7 } else { yield 9 }
return r
}
@@ -76,7 +76,7 @@ vif_reassign func(sel i32) i32 {
# the yield.
vif_defer func() i32 {
r :: if (true) {
n i32 = 5
n i32 := 5
defer n = 999
yield n
} else {
@@ -123,7 +123,7 @@ loop_none func() i32 {
# Labeled `while` value loop (label follows the `: update` clause).
loop_while func() i32 {
n i32 = 0
n i32 := 0
found :: while n < 100 : n += 1 blk: {
if (n == 8) yield :blk n
yield null
@@ -199,7 +199,7 @@ lblock func(sel i32) i32 {
# the block's defer runs.
lblock_defer func() i32 {
r :: blk: {
n i32 = 5
n i32 := 5
defer n = 999
if (true) yield :blk n
yield :blk 0
@@ -235,7 +235,7 @@ yield_outer func(target i32) i32 {
# Plain `break :outer` exits an outer loop from an inner loop.
break_outer func() i32 {
count i32 = 0
count i32 := 0
for 0..3 |a| outer: {
for 0..3 |b| {
count += 1
@@ -247,7 +247,7 @@ break_outer func() i32 {
# A labeled block *statement* (not a value source): `break :blk` exits it early.
stmt_block func(early i32) i32 {
x i32 = 0
x i32 := 0
blk: {
x = 1
if (early == 1) break :blk
@@ -259,7 +259,7 @@ stmt_block func(early i32) i32 {
# `break :search` escapes a nested loop and the block in one jump; the block's
# defer still runs on the way out.
stmt_block_escape func() i32 {
hits i32 = 0
hits i32 := 0
search: {
defer hits += 1000
for 0..10 |i| {
@@ -273,7 +273,7 @@ stmt_block_escape func() i32 {
# A labeled block can also be exited through an ordinary nested block.
stmt_block_nested func() i32 {
hits i32 = 0
hits i32 := 0
outer: {
{
hits = 1