no :: in func decls

This commit is contained in:
2026-06-30 19:31:26 +02:00
parent ae5af37b85
commit 07c560b750
107 changed files with 580 additions and 520 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
# innermost enclosing loop. Each section returns a distinct code on failure so
# a regression points at the broken behaviour; success falls through to 42.
main :: func() i32 {
main func() i32 {
# 1. `break` out of a `while` once i reaches 5.
i i32 = 0
a i32 = 0
@@ -1,7 +1,7 @@
# Milestone 6: compound assignment (`+=`, `-=`, `*=`, `/=`) and the binary
# arithmetic operators `-`, `*`, `/` with multiplicative precedence.
check_float :: func() i32 {
check_float func() i32 {
x f64 = 10.0
x /= 4.0 # 2.5
x *= 2.0 # 5.0
@@ -13,7 +13,7 @@ check_float :: func() i32 {
return 0
}
check_unsigned :: func() i32 {
check_unsigned func() i32 {
n u32 = 100
n /= 7 # 14 (truncating integer division)
n -= 4 # 10
@@ -23,7 +23,7 @@ check_unsigned :: func() i32 {
return 0
}
main :: func() i32 {
main func() i32 {
total i32 = 0
total += 10 # 10
total -= 3 # 7
@@ -1,11 +1,11 @@
# Milestone 5: conditional optional unwrapping, guards, and multi-unwrap.
observe :: func(counter @mut i32, value ?i32) ?i32 {
observe func(counter @mut i32, value ?i32) ?i32 {
counter^ = counter^ + 1
return value
}
main :: func() i32 {
main func() i32 {
total i32 = 0
# present optional scalar -> binds v to the unwrapped value
@@ -1,4 +1,4 @@
main :: func() void {
main func() void {
value i8 :: 127 + 1
_ = value
}
+1 -1
View File
@@ -1,3 +1,3 @@
main :: func() void {
main func() void {
_ = 127 + 1
}
@@ -1,3 +1,3 @@
main :: func() void {
main func() void {
_ = 9223372036854775807 + 1
}
+4 -4
View File
@@ -1,9 +1,9 @@
# Milestone 5 foundation: booleans, comparisons, logical ops, if/else if/else.
printf :: c_func(format *c_char, ...) c_int
printf c_func(format *c_char, ...) c_int
# Returns a distinct code per range using if / else if / else and comparisons.
classify :: func(n i32) i32 {
classify func(n i32) i32 {
if n < 0 {
return 1
} else if n == 0 {
@@ -17,12 +17,12 @@ classify :: func(n i32) i32 {
# A bool-returning function with a visible side effect, used to prove
# short-circuit evaluation: it must only print when actually evaluated.
noisy :: func() bool {
noisy func() bool {
_ = printf("rhs-evaluated\n")
return true
}
main :: func() i32 {
main func() i32 {
total i32 = 0
# comparisons drive if / else if / else
+1 -1
View File
@@ -1,6 +1,6 @@
a int :: b
b int :: a
main :: func() void {
main func() void {
_ = 1
}
+1 -1
View File
@@ -1,6 +1,6 @@
a int :: b
b int :: a
main :: func() void {
main func() void {
_ = a
}
+3 -3
View File
@@ -6,7 +6,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 {
spill_check func() i32 {
x i32 = 5
defer x = 999
return x
@@ -14,7 +14,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 {
enclosing_defer_check func() i32 {
v i32 = 0
defer v = v + 100
for 0..3 |i| {
@@ -24,7 +24,7 @@ enclosing_defer_check :: func() i32 {
return v # 0->1 (i=0 fall-through), ->2 (i=1 break); the +100 runs after capture
}
main :: func() i32 {
main func() i32 {
# 1. return value captured before defers run.
if (spill_check() != 5) return 101
+1 -1
View File
@@ -1,5 +1,5 @@
UserID :: distinct u32
make :: func(value u32) UserID {
make func(value u32) UserID {
return UserID(value)
}
+2 -2
View File
@@ -12,11 +12,11 @@ WrappedID :: distinct LocalID
static_id LocalID :: LocalID(42)
take :: func(value LocalID) LocalID {
take func(value LocalID) LocalID {
return value
}
main :: func() i32 {
main func() i32 {
id LocalID :: LocalID(7)
copy LocalID = take(id)
maybe ?LocalID = copy
+1 -1
View File
@@ -3,6 +3,6 @@ Animal :: enum {
cat
}
favorite :: func() Animal {
favorite func() Animal {
return .cat
}
+3 -3
View File
@@ -8,15 +8,15 @@ State :: enum(u16) {
initial State :: State.started
same :: func(left State, right State) bool {
same func(left State, right State) bool {
return left == right
}
identity :: c_func(value State) State {
identity c_func(value State) State {
return value
}
main :: func() i32 {
main func() i32 {
state State = identity(.running)
values [2]State :: [.started, State.stopped]
animal animals.Animal :: animals.Animal.dog
+6 -6
View File
@@ -28,37 +28,37 @@ BoxB :: union(enum) {
Box :: alias BoxA | BoxB
maybe :: func(value i32) i32 ! BasicError {
maybe func(value i32) i32 ! BasicError {
if (value == 0) return .bad
return value + 1
}
via_try :: func(value i32) i32 ! BasicError {
via_try func(value i32) i32 ! BasicError {
unwrapped :: try maybe(value)
return unwrapped + 1
}
with_detail :: func(value i32) i32 ! DetailError {
with_detail func(value i32) i32 ! DetailError {
if (value == 0) return DetailError{ code = 5 }
if (value == 1) return .empty
return value
}
pick :: func(value Both) i32 {
pick func(value Both) i32 {
match value {
.left: return 10
.right: return 20
}
}
payload :: func(value Box) i32 {
payload func(value Box) i32 {
match value {
.a |n|: return n
.b: return 3
}
}
main :: func() i32 {
main func() i32 {
acc i32 = 0
a :: maybe(0) catch 7
+2 -2
View File
@@ -1,10 +1,10 @@
# Milestone 5: ranges and sequence for loops.
pass :: func(value range) range {
pass func(value range) range {
return value
}
main :: func() i32 {
main func() i32 {
total i32 = 0
items [3]mut i32 = [1, 2, 3]
+2 -2
View File
@@ -1,11 +1,11 @@
make_range :: func(calls @mut i32, end usize) range {
make_range func(calls @mut i32, end usize) range {
calls^ = calls^ + 1
return 0..end
}
global_range :: 0..1
main :: func() i32 {
main func() i32 {
total i32 = 0
first u8 = 254
@@ -1,9 +1,9 @@
bad int = 1
read_bad :: func() int {
read_bad func() int {
return bad
}
derived :: read_bad()
main :: func() void {}
main func() void {}
@@ -1,11 +1,11 @@
bad int = 1
read_bad :: func() int {
read_bad func() int {
return bad
}
derived :: read_bad()
main :: func() void {
main func() void {
_ = derived
}
@@ -1,11 +1,11 @@
bad int = 4
read_bad :: func() int {
read_bad func() int {
return bad
}
derived int :: read_bad()
main :: func() void {
main func() void {
_ = 1
}
@@ -1,11 +1,11 @@
bad int = 4
read_bad :: func() int {
read_bad func() int {
return bad
}
derived int :: read_bad()
main :: func() void {
main func() void {
_ = derived
}
@@ -1,7 +1,7 @@
broken :: func(value int) int {
broken func(value int) int {
return missing + value
}
main :: func() void {
main func() void {
_ = 1
}
@@ -1,5 +1,5 @@
bad int = 4
main :: func() void {
main func() void {
_ = 1
}
@@ -1,7 +1,7 @@
broken :: func(value int) int {
broken func(value int) int {
return missing + value
}
main :: func() void {
main func() void {
_ = broken(1)
}
@@ -1,5 +1,5 @@
bad int = 4
main :: func() void {
main func() void {
_ = bad
}
+1 -1
View File
@@ -1,3 +1,3 @@
main :: func() i32 {
main func() i32 {
return 4
}
+1 -1
View File
@@ -1,3 +1,3 @@
main :: func() int {
main func() int {
return 3
}
@@ -1,12 +1,12 @@
take :: func(value i8) i8 {
take func(value i8) i8 {
return value
}
bad_return :: func() i8 {
bad_return func() i8 {
return missing
}
main :: func() void {
main func() void {
_ = take(missing)
_ = bad_return()
}
+5 -5
View File
@@ -30,7 +30,7 @@ Box :: union(enum) {
# Statement match with payload capture; every variant returns, so the function needs
# no trailing return (the desugared if/else chain covers all paths).
describe :: func(d Data) i32 {
describe func(d Data) i32 {
match d {
.dog |age|: return age + 1
.bird |wingspan|: return wingspan + 2
@@ -38,7 +38,7 @@ describe :: func(d Data) i32 {
}
# Value match: single-expression arms yield implicitly, a block arm yields explicitly.
area :: func(s Shape) i32 {
area func(s Shape) i32 {
result :: match s {
.square |side|: side * side
.circle |r|: {
@@ -51,18 +51,18 @@ area :: func(s Shape) i32 {
# Same-type multi-pattern capture: `.dog` and `.bird` are both i32, so one capture binds
# either payload (read once at the union's shared carrier offset).
payload_of :: func(d Data) i32 {
payload_of func(d Data) i32 {
v :: match d {
.dog, .bird |n|: n
}
return v
}
make_box :: func() Box {
make_box func() Box {
return Box{ point = Point{ x = 4, y = 0 } }
}
main :: func() i32 {
main func() i32 {
acc i32 = 0
dog Data = Data{ dog = 9 }
+1 -1
View File
@@ -1,4 +1,4 @@
main :: func() i32 {
main func() i32 {
value i32 = 1
value = value + 2
return value
+2 -2
View File
@@ -1,7 +1,7 @@
take :: func(value i8) i8 {
take func(value i8) i8 {
return value
}
main :: func() void {
main func() void {
_ = take(128)
}
+1 -1
View File
@@ -1 +1 @@
main :: func() i32 { return 7 }
main func() i32 { return 7 }
+1 -1
View File
@@ -1,4 +1,4 @@
main :: func() void {
main func() void {
value i8 = 127
_ = value + 1
}
+3 -3
View File
@@ -2,15 +2,15 @@
x int :: 2
sum_c :: c_func(a, b int) int {
sum_c c_func(a, b int) int {
return a + b
}
sum_brolang :: func(a, b int) int {
sum_brolang func(a, b int) int {
return a + b
}
main :: func() void {
main func() void {
y int = 4
a_add_b_c :: sum_c(1, 2)
a_add_b_brolang :: sum_brolang(1, 2)
+2 -2
View File
@@ -1,10 +1,10 @@
make_value :: func() int {
make_value func() int {
return 40 + 2
}
answer int :: make_value()
main :: func() i32 {
main func() i32 {
_ = answer
return 0
}
+1 -1
View File
@@ -1,4 +1,4 @@
main :: func() i32 {
main func() i32 {
values [2;0]i32 :: [101, 101]
array_pointer :: &values
suffix [;0]i32 :: array_pointer[1..]
+1 -1
View File
@@ -15,7 +15,7 @@ Thing :: union(enum) {
b f64
}
main :: func() i32 {
main func() i32 {
x Data = Data{ bird = 37 }
y Thing = Thing{ a = 5 }
return x.bird + y.a
+1 -1
View File
@@ -3,7 +3,7 @@ Val :: union {
f f64
}
main :: func() i32 {
main func() i32 {
x Val = Val{ n = 42 }
return x.n
}
+2 -2
View File
@@ -1,13 +1,13 @@
# Milestone 5: boolean while loops with optional post-iteration updates.
return_before_update :: func() i32 {
return_before_update func() i32 {
i i32 = 0
while true : i = i + 1 {
return i
}
}
main :: func() i32 {
main func() i32 {
total i32 = 0
# ordinary condition and update
+24 -24
View File
@@ -8,7 +8,7 @@
# --- value blocks (milestone 20) ---------------------------------------------
# Untyped `::`: the local's type is the yield's natural type.
basic :: func() i32 {
basic func() i32 {
x :: {
a :: 20
b :: 22
@@ -18,7 +18,7 @@ basic :: func() i32 {
}
# Typed `T =`: the yield coerces to the annotation.
typed :: func() i64 {
typed func() i64 {
x i64 = {
yield 100
}
@@ -27,7 +27,7 @@ typed :: func() i64 {
# The yielded value is captured before defers run: the defer mutates a block
# local, but the captured value is unchanged.
spill :: func() i32 {
spill func() i32 {
v :: {
n i32 = 5
defer n = 999
@@ -37,7 +37,7 @@ spill :: func() i32 {
}
# Reassignment into an existing mutable local.
reassign :: func() i32 {
reassign func() i32 {
r i32 = 0
r = {
yield 7
@@ -48,7 +48,7 @@ reassign :: func() i32 {
# --- value if-statements (milestone 20.5) ------------------------------------
# Untyped `::` over an `else if` chain; the first branch fixes the type.
vif_untyped :: func(sel i32) i32 {
vif_untyped func(sel i32) i32 {
r :: if (sel == 0) {
yield 10
} else if (sel == 1) {
@@ -60,13 +60,13 @@ vif_untyped :: func(sel i32) i32 {
}
# Typed `T =`: every branch coerces to the annotation.
vif_typed :: func(sel i32) i32 {
vif_typed func(sel i32) i32 {
r i32 = if (sel == 0) { yield 100 } else { yield 200 }
return r
}
# Assigned into an existing local.
vif_reassign :: func(sel i32) i32 {
vif_reassign func(sel i32) i32 {
r i32 = 0
r = if (sel == 0) { yield 7 } else { yield 9 }
return r
@@ -74,7 +74,7 @@ vif_reassign :: func(sel i32) i32 {
# A branch is a full value block: leading statements + a defer captured before
# the yield.
vif_defer :: func() i32 {
vif_defer func() i32 {
r :: if (true) {
n i32 = 5
defer n = 999
@@ -90,7 +90,7 @@ vif_defer :: func() i32 {
# Labeled `for` used as a value: `yield :blk i` exits early with a value, the
# trailing `yield none` supplies the value when the loop completes. The `{i,
# none}` yields resolve the result to an optional.
loop_search :: func() i32 {
loop_search func() i32 {
# first i in 0..10 whose square exceeds 40 (6*6=36 no, 7*7=49 yes -> 7).
idx :: for 0..10 |i| blk: {
if (i * i > 40) yield :blk i
@@ -104,7 +104,7 @@ loop_search :: func() i32 {
}
# Same loop, but nothing matches -> the fall-through `yield none` is the result.
loop_none :: func() i32 {
loop_none func() i32 {
idx :: for 0..10 |i| blk: {
if (i > 100) yield :blk i
yield none
@@ -117,7 +117,7 @@ loop_none :: func() i32 {
}
# Labeled `while` value loop (label follows the `: update` clause).
loop_while :: func() i32 {
loop_while func() i32 {
n i32 = 0
found :: while n < 100 : n += 1 blk: {
if (n == 8) yield :blk n
@@ -134,7 +134,7 @@ loop_while :: func() i32 {
# A branch may exit on every path (here `return`) instead of yielding; the slot
# read after the `if` is only reached on the yielding path.
vif_return :: func(sel i32) i32 {
vif_return func(sel i32) i32 {
r :: if (sel == 0) {
yield 10
} else {
@@ -144,7 +144,7 @@ vif_return :: func(sel i32) i32 {
}
# unwrap-`if` as a value source: present -> transform, absent -> default.
vif_unwrap :: func(opt ?i32) i32 {
vif_unwrap func(opt ?i32) i32 {
r :: if opt |v| {
yield v * 2
} else {
@@ -154,14 +154,14 @@ vif_unwrap :: func(opt ?i32) i32 {
}
# The simple "unwrap or fallback" case is just `orelse` (already a plain expression).
orelse_value :: func(opt ?i32) i32 {
orelse_value func(opt ?i32) i32 {
r :: opt orelse 7
return r
}
# Untyped value loop where `none` is yielded (in a labeled yield) before any
# concrete value: the element type still resolves to ?<i> from `yield :blk i`.
loop_none_first :: func() i32 {
loop_none_first func() i32 {
r :: for 0..10 |i| blk: {
if (i > 100) yield :blk none
if (i * i > 40) yield :blk i # first concrete yield: i == 7
@@ -178,7 +178,7 @@ loop_none_first :: func() i32 {
# A labeled value block: `yield :blk` exits the block (past a nested `if`) with a
# value. Every path must yield.
lblock :: func(sel i32) i32 {
lblock func(sel i32) i32 {
r :: blk: {
base :: 10
if (sel == 0) {
@@ -192,7 +192,7 @@ lblock :: func(sel i32) i32 {
# An early `yield :blk` skips the rest of the block; the value is captured before
# the block's defer runs.
lblock_defer :: func() i32 {
lblock_defer func() i32 {
r :: blk: {
n i32 = 5
defer n = 999
@@ -203,7 +203,7 @@ lblock_defer :: func() i32 {
}
# A labeled block whose `{T, none}` yields resolve the result to an optional.
lblock_optional :: func(present i32) i32 {
lblock_optional func(present i32) i32 {
r :: blk: {
if (present == 0) yield :blk none
yield :blk 8
@@ -215,7 +215,7 @@ lblock_optional :: func(present i32) i32 {
}
# `yield :outer v` exits an OUTER value loop from inside an inner loop.
yield_outer :: func(target i32) i32 {
yield_outer func(target i32) i32 {
found :: for 0..3 |row| outer: {
for 0..3 |col| {
if (row * 3 + col == target) yield :outer (row * 10 + col)
@@ -229,7 +229,7 @@ yield_outer :: func(target i32) i32 {
}
# Plain `break :outer` exits an outer loop from an inner loop.
break_outer :: func() i32 {
break_outer func() i32 {
count i32 = 0
for 0..3 |a| outer: {
for 0..3 |b| {
@@ -241,7 +241,7 @@ break_outer :: func() i32 {
}
# A labeled block *statement* (not a value source): `break :blk` exits it early.
stmt_block :: func(early i32) i32 {
stmt_block func(early i32) i32 {
x i32 = 0
blk: {
x = 1
@@ -253,7 +253,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 {
stmt_block_escape func() i32 {
hits i32 = 0
search: {
defer hits += 1000
@@ -267,7 +267,7 @@ stmt_block_escape :: func() i32 {
}
# Item B: a `none` yielded before a concrete `yield :blk` that references a block local.
lblock_local :: func() i32 {
lblock_local func() i32 {
r :: blk: {
val :: 9
if (false) yield :blk none
@@ -279,7 +279,7 @@ lblock_local :: func() i32 {
return -1
}
main :: func() i32 {
main func() i32 {
if (basic() != 42) return 101
if (typed() != 100) return 102
if (spill() != 5) return 103