mutable decl syntax change
This commit is contained in:
+11
-11
@@ -77,8 +77,8 @@ read_command func() Command {
|
||||
if IsMouseButtonPressed(MOUSE_BUTTON_LEFT) return .spawn{ GetMousePosition() }
|
||||
if IsKeyPressed(KEY_SPACE) return .clear
|
||||
|
||||
fx f32 = 0.0
|
||||
fy f32 = 0.0
|
||||
fx f32 := 0.0
|
||||
fy f32 := 0.0
|
||||
if IsKeyDown(KEY_A) fx -= FORCE
|
||||
if IsKeyDown(KEY_D) fx += FORCE
|
||||
if IsKeyDown(KEY_W) fy -= FORCE
|
||||
@@ -128,14 +128,14 @@ step func(b @mut Ball) void {
|
||||
|
||||
draw_ball func(b @Ball, highlight bool) void {
|
||||
col :: color_for(b.kind)
|
||||
center Vector2 = Vector2{ x = b.x, y = b.y }
|
||||
center Vector2 := Vector2{ x = b.x, y = b.y }
|
||||
match b.kind {
|
||||
.circle: DrawCircleV(center, b.radius, col)
|
||||
.square: DrawPoly(center, 4, b.radius, 45.0, col)
|
||||
.triangle: DrawPoly(center, 3, b.radius, 0.0, col)
|
||||
}
|
||||
if highlight {
|
||||
ring Color = Color{ r = 250, g = 245, b = 200, a = 255 }
|
||||
ring Color := Color{ r = 250, g = 245, b = 200, a = 255 }
|
||||
DrawPoly(center, 24, b.radius + RING_PAD, 0.0, ring)
|
||||
}
|
||||
}
|
||||
@@ -150,11 +150,11 @@ main func() i32 {
|
||||
`[click] spawn a shape [WASD/arrows] blow wind
|
||||
`[space] clear
|
||||
|
||||
balls [CAP]mut Ball = undefined
|
||||
count usize = 0 # number of live balls, in slots 0..count
|
||||
kc Kind = .circle # next kind to spawn
|
||||
spin f32 = 1.0 # rotates spawn velocity for variety
|
||||
at_cap bool = false # show the "at capacity" banner
|
||||
balls [CAP]mut Ball := undefined
|
||||
count usize := 0 # number of live balls, in slots 0..count
|
||||
kc Kind := .circle # next kind to spawn
|
||||
spin f32 := 1.0 # rotates spawn velocity for variety
|
||||
at_cap bool := false # show the "at capacity" banner
|
||||
|
||||
bg :: Color{ r = 24, g = 26, b = 34, a = 255 }
|
||||
text :: Color{ r = 225, g = 225, b = 230, a = 255 }
|
||||
@@ -209,7 +209,7 @@ main func() i32 {
|
||||
# --- which shape is under the cursor? (optional via a value-loop) ---
|
||||
mouse :: GetMousePosition()
|
||||
sel :: for 0..(count) |i| blk: {
|
||||
c Vector2 = Vector2{ x = balls[i].x, y = balls[i].y }
|
||||
c Vector2 := Vector2{ x = balls[i].x, y = balls[i].y }
|
||||
if CheckCollisionPointCircle(mouse, c, balls[i].radius) yield :blk i
|
||||
yield null
|
||||
}
|
||||
@@ -220,7 +220,7 @@ main func() i32 {
|
||||
|
||||
for (&balls) |@b, i| {
|
||||
if (i >= count) break
|
||||
hot bool = false
|
||||
hot bool := false
|
||||
if sel |s| {
|
||||
if (s == i) hot = true # true only for the hovered ball
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ hide append_token func(tokens @mut std.ArrayList(Token), kind Kind, start, end u
|
||||
}
|
||||
|
||||
lex func(source []u8, tokens @mut std.ArrayList(Token)) void ! mem.AllocError {
|
||||
cursor usize = 0
|
||||
cursor usize := 0
|
||||
while cursor < source.len {
|
||||
value u8 :: source[cursor]
|
||||
if value == ' ' or value == '\t' or value == '\r' {
|
||||
@@ -112,7 +112,7 @@ hide print_token func(source []u8, token Token) void {
|
||||
_ = c.printf("%-11s", kind_name(token.kind))
|
||||
if token.length != 0 {
|
||||
_ = c.printf(" `")
|
||||
i usize = 0
|
||||
i usize := 0
|
||||
while i < token.length : i += 1 {
|
||||
value u8 :: source[token.start + i]
|
||||
if value == '\n' {
|
||||
@@ -132,7 +132,7 @@ main func() i32 {
|
||||
` hello()
|
||||
`}
|
||||
|
||||
tokens std.ArrayList(Token) = arraylist.init(mem.c_allocator)
|
||||
tokens std.ArrayList(Token) := arraylist.init(mem.c_allocator)
|
||||
defer arraylist.deinit(&tokens)
|
||||
|
||||
lex(source, &tokens) catch |_| {
|
||||
|
||||
@@ -28,7 +28,7 @@ reserve func($T type, list @mut ArrayList(T), minimum_capacity usize) void ! mem
|
||||
return
|
||||
}
|
||||
|
||||
new_capacity usize = 8
|
||||
new_capacity usize := 8
|
||||
if list.capacity >= 8 {
|
||||
half usize :: divtrunc!(list.capacity, 2)
|
||||
if list.capacity > maxval!(usize) - half {
|
||||
|
||||
@@ -61,7 +61,7 @@ write func(writer Writer, bytes []u8) usize ! WriteError {
|
||||
}
|
||||
|
||||
write_all func(writer Writer, bytes []u8) void ! WriteError {
|
||||
offset usize = 0
|
||||
offset usize := 0
|
||||
while offset < bytes.len {
|
||||
count usize :: write(writer, bytes[offset..]) catch |err| {
|
||||
return err
|
||||
@@ -75,7 +75,7 @@ write_all func(writer Writer, bytes []u8) void ! WriteError {
|
||||
}
|
||||
|
||||
hide system_read func(_ ?*mut anyopaque, stream ReadStream, buffer []mut u8) usize ! ReadError {
|
||||
request usize = buffer.len
|
||||
request usize := buffer.len
|
||||
maximum usize :: usize(maxval!(c_long))
|
||||
if request > maximum {
|
||||
request = maximum
|
||||
@@ -93,7 +93,7 @@ hide system_read func(_ ?*mut anyopaque, stream ReadStream, buffer []mut u8) usi
|
||||
|
||||
hide system_write func(_ ?*mut anyopaque, stream WriteStream, bytes []u8) usize ! WriteError {
|
||||
fd c_int :: c_int(stream)
|
||||
request usize = bytes.len
|
||||
request usize := bytes.len
|
||||
maximum usize :: usize(maxval!(c_long))
|
||||
if request > maximum {
|
||||
request = maximum
|
||||
|
||||
@@ -32,7 +32,7 @@ eql func($T type, left, right []T) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
i usize = 0
|
||||
i usize := 0
|
||||
while i < left.len : i += 1 {
|
||||
if left[i] != right[i] {
|
||||
return false
|
||||
@@ -41,7 +41,7 @@ eql func($T type, left, right []T) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
hide empty_storage [1]mut u64 = [0]
|
||||
hide empty_storage [1]mut u64 := [0]
|
||||
|
||||
hide empty_slice func($T type, count usize) []mut T {
|
||||
pointer *mut T :: ptrcast!(T, (&empty_storage).ptr)
|
||||
@@ -65,7 +65,7 @@ alloc func($T type, allocator Allocator, count usize) []mut T ! AllocError {
|
||||
return .out_of_memory
|
||||
}
|
||||
|
||||
memory ?*mut u8 = raw_alloc(allocator, count * element_size, alignof!(T))
|
||||
memory ?*mut u8 := raw_alloc(allocator, count * element_size, alignof!(T))
|
||||
if memory |bytes| {
|
||||
pointer *mut T :: ptrcast!(T, bytes)
|
||||
return pointer[..count]
|
||||
@@ -90,13 +90,13 @@ realloc func($T type, allocator Allocator, memory []mut T, new_count usize) []mu
|
||||
return .out_of_memory
|
||||
}
|
||||
|
||||
old_memory ?*mut u8 = null
|
||||
old_size usize = 0
|
||||
old_memory ?*mut u8 := null
|
||||
old_size usize := 0
|
||||
if memory.len != 0 {
|
||||
old_memory = ptrcast!(u8, memory.ptr)
|
||||
old_size = memory.len * element_size
|
||||
}
|
||||
resized ?*mut u8 = raw_realloc(
|
||||
resized ?*mut u8 := raw_realloc(
|
||||
allocator,
|
||||
old_memory,
|
||||
old_size,
|
||||
@@ -123,9 +123,9 @@ hide power_of_two func(value usize) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
current usize = value
|
||||
current usize := value
|
||||
while current > 1 {
|
||||
half usize = divtrunc!(current, 2)
|
||||
half usize := divtrunc!(current, 2)
|
||||
if half * 2 != current {
|
||||
return false
|
||||
}
|
||||
@@ -144,8 +144,8 @@ hide c_alloc func(_ ?*mut anyopaque, size usize, alignment usize) ?*mut u8 {
|
||||
return ptrcast!(u8, c.malloc(c_ulong(size)))
|
||||
}
|
||||
|
||||
memory [1]mut ?*mut anyopaque = [null]
|
||||
status c_int = c.posix_memalign((&memory).ptr, c_ulong(alignment), c_ulong(size))
|
||||
memory [1]mut ?*mut anyopaque := [null]
|
||||
status c_int := c.posix_memalign((&memory).ptr, c_ulong(alignment), c_ulong(size))
|
||||
if status != 0 {
|
||||
return null
|
||||
}
|
||||
@@ -168,13 +168,13 @@ hide c_realloc func(_ ?*mut anyopaque, memory ?*mut u8, old_size usize, new_size
|
||||
return ptrcast!(u8, c.realloc(old_memory, c_ulong(new_size)))
|
||||
}
|
||||
|
||||
new_memory ?*mut u8 = c_alloc(null, new_size, alignment)
|
||||
new_memory ?*mut u8 := c_alloc(null, new_size, alignment)
|
||||
if new_memory |new_bytes| {
|
||||
copy_size usize = old_size
|
||||
copy_size usize := old_size
|
||||
if new_size < copy_size {
|
||||
copy_size = new_size
|
||||
}
|
||||
i usize = 0
|
||||
i usize := 0
|
||||
while i < copy_size : i += 1 {
|
||||
new_bytes[i] = old_memory[i]
|
||||
}
|
||||
|
||||
+4
-4
@@ -25,7 +25,7 @@ tier_bonus func(tier Tier) i32 {
|
||||
}
|
||||
|
||||
projected_score func(player Player) i32 {
|
||||
total i32 = player.score
|
||||
total i32 := player.score
|
||||
total += tier_bonus(player.tier)
|
||||
if player.active and player.streak > 2 {
|
||||
total += player.streak * 3
|
||||
@@ -42,8 +42,8 @@ apply_decay func(players []mut Player) void {
|
||||
}
|
||||
|
||||
best_player func(players []mut Player) ?@mut Player {
|
||||
best ?@mut Player = null
|
||||
best_score i32 = 0
|
||||
best ?@mut Player := null
|
||||
best_score i32 := 0
|
||||
|
||||
for players |@player| {
|
||||
score :: projected_score(player^)
|
||||
@@ -62,7 +62,7 @@ best_player func(players []mut Player) ?@mut Player {
|
||||
}
|
||||
|
||||
main func() i32 {
|
||||
players [4]mut Player = [
|
||||
players [4]mut Player := [
|
||||
Player { id = PlayerID(1), name = "Ada", tier = .gold, score = 41, streak = 4, active = true },
|
||||
Player { id = PlayerID(2), name = "Ken", tier = .silver, score = 56, streak = 1, active = true },
|
||||
Player { id = PlayerID(3), name = "Edsger", tier = .bronze, score = 64, streak = 0, active = false },
|
||||
|
||||
@@ -27,7 +27,7 @@ raw_free func(allocator Allocator, memory ?*mut u8, size usize, alignment usize)
|
||||
allocator.vtable.free(allocator.context, memory, size, alignment)
|
||||
}
|
||||
|
||||
hide empty_storage [1]mut u64 = [0]
|
||||
hide empty_storage [1]mut u64 := [0]
|
||||
|
||||
hide empty_slice func($T type, count usize) []mut T {
|
||||
pointer *mut T :: ptrcast!(T, (&empty_storage).ptr)
|
||||
@@ -47,7 +47,7 @@ alloc func($T type, allocator Allocator, count usize) []mut T ! AllocError {
|
||||
return .out_of_memory
|
||||
}
|
||||
|
||||
memory ?*mut u8 = raw_alloc(allocator, count * element_size, alignof!(T))
|
||||
memory ?*mut u8 := raw_alloc(allocator, count * element_size, alignof!(T))
|
||||
if memory |bytes| {
|
||||
pointer *mut T :: ptrcast!(T, bytes)
|
||||
return pointer[..count]
|
||||
@@ -68,9 +68,9 @@ hide power_of_two func(value usize) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
current usize = value
|
||||
current usize := value
|
||||
while current > 1 {
|
||||
half usize = current / 2
|
||||
half usize := current / 2
|
||||
if half * 2 != current {
|
||||
return false
|
||||
}
|
||||
@@ -89,8 +89,8 @@ hide c_alloc func(_ ?*mut anyopaque, size usize, alignment usize) ?*mut u8 {
|
||||
return ptrcast!(u8, c.malloc(c_ulong(size)))
|
||||
}
|
||||
|
||||
memory [1]mut ?*mut anyopaque = [null]
|
||||
status c_int = c.posix_memalign((&memory).ptr, c_ulong(alignment), c_ulong(size))
|
||||
memory [1]mut ?*mut anyopaque := [null]
|
||||
status c_int := c.posix_memalign((&memory).ptr, c_ulong(alignment), c_ulong(size))
|
||||
if status != 0 {
|
||||
return null
|
||||
}
|
||||
@@ -113,13 +113,13 @@ hide c_realloc func(_ ?*mut anyopaque, memory ?*mut u8, old_size usize, new_size
|
||||
return ptrcast!(u8, c.realloc(old_memory, c_ulong(new_size)))
|
||||
}
|
||||
|
||||
new_memory ?*mut u8 = c_alloc(null, new_size, alignment)
|
||||
new_memory ?*mut u8 := c_alloc(null, new_size, alignment)
|
||||
if new_memory |new_bytes| {
|
||||
copy_size usize = old_size
|
||||
copy_size usize := old_size
|
||||
if new_size < copy_size {
|
||||
copy_size = new_size
|
||||
}
|
||||
i usize = 0
|
||||
i usize := 0
|
||||
while i < copy_size : i += 1 {
|
||||
new_bytes[i] = old_memory[i]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user