no :: in func decls
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user