examples: fix warnings when doing `./v -W -progress -check-syntax build-examples`

pull/6688/head
Delyan Angelov 2020-10-26 13:14:21 +02:00
parent a7e3092165
commit 9772eb7c96
14 changed files with 203 additions and 157 deletions

View File

@ -202,7 +202,7 @@ enum Direction {
// Utility functions // Utility functions
[inline] [inline]
fn min(a, b int) int { fn min(a int, b int) int {
if a < b { if a < b {
return a return a
} else { } else {
@ -211,7 +211,7 @@ fn min(a, b int) int {
} }
[inline] [inline]
fn max(a, b int) int { fn max(a int, b int) int {
if a > b { if a > b {
return a return a
} else { } else {
@ -229,7 +229,7 @@ fn abs(a int) int {
} }
[inline] [inline]
fn avg(a, b int) int { fn avg(a int, b int) int {
return (a + b) / 2 return (a + b) / 2
} }

View File

@ -2,10 +2,10 @@ import sync
import time import time
// Simulate expensive computing using sleep function // Simulate expensive computing using sleep function
fn expensive_computing(id, duration int, mut wg sync.WaitGroup) { fn expensive_computing(id int, duration int, mut wg sync.WaitGroup) {
println('Executing expensive computing task (${id})...') println('Executing expensive computing task ($id)...')
time.sleep_ms(duration) time.sleep_ms(duration)
println('Finish task ${id} on ${duration} ms') println('Finish task $id on $duration ms')
wg.done() wg.done()
} }

View File

@ -1,4 +1,5 @@
module main module main
import time import time
import automaton import automaton
@ -22,4 +23,3 @@ fn main() {
time.sleep_ms(100) time.sleep_ms(100)
} }
} }

View File

@ -10,46 +10,48 @@ const (
filled_color = gx.blue filled_color = gx.blue
) )
fn new_graphics() &gg.Context {
glfw.init_glfw()
return gg.new_context(gg.Cfg{
width: screen_width
height: screen_height
use_ortho: true
create_window: true
resizable: false
window_title: 'v life (with gg, glfw, gx)'
window_user_ptr: 0
})
}
const (
graphics = new_graphics()
)
[live] [live]
fn print_automaton(a &automaton.Automaton){ fn print_automaton(app &App) {
gg.clear(gx.white)
square_size := 18 square_size := 18
for y := 1; y<a.field.maxy; y++ { for y := 1; y < app.a.field.maxy; y++ {
for x := 1; x<a.field.maxx; x++ { for x := 1; x < app.a.field.maxx; x++ {
cell := a.field.get(x,y) cell := app.a.field.get(x, y)
if cell == 1 { if cell == 1 {
graphics.draw_rect(f32(square_size*x), f32(square_size*y), f32(square_size), app.gg.draw_rect(f32(square_size * x), f32(square_size * y), f32(square_size),
f32(square_size), filled_color) f32(square_size), filled_color)
} }
} }
} }
} }
struct App {
mut:
gg &gg.Context
a automaton.Automaton
}
fn frame(mut app App) {
app.gg.begin()
app.a.update()
print_automaton(app)
app.gg.end()
}
fn main() { fn main() {
mut a := automaton.gun() mut app := App{
for { gg: 0
if graphics.window.should_close() { graphics.window.destroy() break } a: automaton.gun()
gg.post_empty_event() // needed so the animation does not stop
///////////////////////////////////////////////
a.update()
print_automaton(a)
graphics.render()
} }
app.gg = gg.new_context({
bg_color: gx.white
frame_fn: frame
user_data: &app
width: screen_width
height: screen_height
use_ortho: true
create_window: true
resizable: false
window_title: 'v life (with gg, gx)'
})
app.gg.run()
} }

View File

@ -1,28 +1,33 @@
module automaton module automaton
// /////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////
pub struct A2D { pub struct A2D {
pub mut: pub mut:
maxx int maxx int
maxy int maxy int
data &int data &int
} }
[inline] pub fn (a &A2D) set(x,y int, newval int) {
[inline]
pub fn (a &A2D) set(x int, y int, newval int) {
unsafe { unsafe {
mut e := &int(0) mut e := &int(0)
e = a.data + y * a.maxx + x e = a.data + y * a.maxx + x
*e = newval *e = newval
} }
} }
[inline] pub fn (a &A2D) get(x,y int) int {
[inline]
pub fn (a &A2D) get(x int, y int) int {
unsafe { unsafe {
mut e := &int(0) mut e := &int(0)
e = a.data + y * a.maxx + x e = a.data + y * a.maxx + x
return *e return *e
} }
} }
[inline] pub fn (a &A2D) clear() {
[inline]
pub fn (a &A2D) clear() {
for y := 0; y < a.maxy; y++ { for y := 0; y < a.maxy; y++ {
for x := 0; x < a.maxx; x++ { for x := 0; x < a.maxx; x++ {
a.set(x, y, 0) a.set(x, y, 0)
@ -31,7 +36,6 @@ pub mut:
} }
// /////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////
pub struct Automaton { pub struct Automaton {
pub mut: pub mut:
field &A2D field &A2D
@ -47,32 +51,41 @@ fn new_automaton(f [][]int) Automaton {
} }
} }
size := (maxx * maxy) size := (maxx * maxy)
field := &A2D{ maxx: maxx maxy: maxy data: &int( vcalloc( 4 * (size) ) ) } field := &A2D{
new_field := &A2D{ maxx: maxx maxy: maxy data: &int( vcalloc( 4 * (size)) ) } maxx: maxx
maxy: maxy
data: &int(vcalloc(4 * (size)))
}
new_field := &A2D{
maxx: maxx
maxy: maxy
data: &int(vcalloc(4 * (size)))
}
for y in 0 .. field.maxy { for y in 0 .. field.maxy {
for x in 0 .. field.maxx { for x in 0 .. field.maxx {
field.set(x, y, f[y][x]) field.set(x, y, f[y][x])
} }
} }
return Automaton{ field: field new_field: new_field } return Automaton{
field: field
new_field: new_field
}
} }
pub fn (mut aa Automaton) update() { pub fn (mut aa Automaton) update() {
aa.new_field.clear() aa.new_field.clear()
for y := 1; y < aa.field.maxy; y++ { for y := 1; y < aa.field.maxy; y++ {
for x := 1; x < aa.field.maxx; x++ { for x := 1; x < aa.field.maxx; x++ {
moore_sum := ( 0 + moore_sum := (0 + aa.field.get(x - 1, y - 1) + aa.field.get(x, y - 1) + aa.field.get(x +
aa.field.get(x-1,y-1) + aa.field.get(x,y-1) + aa.field.get(x+1,y-1) + 1, y - 1) + aa.field.get(x - 1, y) + 0 + aa.field.get(x + 1, y) + aa.field.get(x - 1, y + 1) +
aa.field.get(x-1,y ) + 0 + aa.field.get(x+1,y ) + aa.field.get(x, y + 1) + aa.field.get(x + 1, y + 1))
aa.field.get(x-1,y+1) + aa.field.get(x,y+1) + aa.field.get(x+1,y+1)
)
cell := aa.field.get(x, y) cell := aa.field.get(x, y)
v := if cell == 1 { v := if cell == 1 { moore_sum in [2, 3] } else { moore_sum == 3 }
moore_sum in [2, 3] aa.new_field.set(x, y, if v {
1
} else { } else {
moore_sum == 3 0
} })
aa.new_field.set(x,y, if v { 1 } else { 0 })
} }
}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0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
] ]
return new_automaton(field) return new_automaton(field)
} }

View File

@ -7,12 +7,12 @@ fn main() {
hanoi(num, 'A', 'B', 'C') hanoi(num, 'A', 'B', 'C')
} }
fn move(n int, a, b string) int { fn move(n int, a string, b string) int {
println('Disc $n from $a to $b\...') println('Disc $n from $a to $b\...')
return 0 return 0
} }
fn hanoi(n int, a, b, c string) int { fn hanoi(n int, a string, b string, c string) int {
if n == 1 { if n == 1 {
move(1, a, c) move(1, a, c)
} else { } else {

View File

@ -1,13 +1,13 @@
import os import os
fn regex_match(src, pat string) bool { fn regex_match(src string, pat string) bool {
src_size := src.len + 1 src_size := src.len + 1
pat_size := pat.len + 1 pat_size := pat.len + 1
mut memo := [][]int{len: src_size, init: []int{len: pat_size, init: -1}} mut memo := [][]int{len: src_size, init: []int{len: pat_size, init: -1}}
return regex_match_core(src, pat, 0, 0, mut memo) return regex_match_core(src, pat, 0, 0, mut memo)
} }
fn regex_match_core(src, pat string, src_pos, pat_pos int, mut memo [][]int) bool { fn regex_match_core(src string, pat string, src_pos int, pat_pos int, mut memo [][]int) bool {
if memo[src_pos][pat_pos] != -1 { if memo[src_pos][pat_pos] != -1 {
return memo[src_pos][pat_pos] == 1 return memo[src_pos][pat_pos] == 1
} }

View File

@ -55,7 +55,7 @@ fn draw() {
// line(0, 0, 500, 500) // line(0, 0, 500, 500)
} }
fn draw_hollow_rect(x, y, w, h f32) { fn draw_hollow_rect(x f32, y f32, w f32, h f32) {
sgl.begin_line_strip() sgl.begin_line_strip()
sgl.v2f(x, y) sgl.v2f(x, y)
sgl.v2f(x + w, y) sgl.v2f(x + w, y)
@ -65,7 +65,7 @@ fn draw_hollow_rect(x, y, w, h f32) {
sgl.end() sgl.end()
} }
fn draw_filled_rect(x, y, w, h f32) { fn draw_filled_rect(x f32, y f32, w f32, h f32) {
sgl.begin_quads() sgl.begin_quads()
sgl.v2f(x, y) sgl.v2f(x, y)
sgl.v2f(x + w, y) sgl.v2f(x + w, y)

View File

@ -10,7 +10,7 @@ mut:
gg &gg.Context // used for drawing gg &gg.Context // used for drawing
} }
fn my_audio_stream_callback(buffer &f32, num_frames, num_channels int, mut acontext AppState) { fn my_audio_stream_callback(buffer &f32, num_frames int, num_channels int, mut acontext AppState) {
mut soundbuffer := buffer mut soundbuffer := buffer
for frame := 0; frame < num_frames; frame++ { for frame := 0; frame < num_frames; frame++ {
t := int(f32(acontext.frame_0 + frame) * 0.245) t := int(f32(acontext.frame_0 + frame) * 0.245)

View File

@ -8,11 +8,11 @@ const (
) )
[inline] [inline]
fn sintone(periods, frame, num_frames int) f32 { fn sintone(periods int, frame int, num_frames int) f32 {
return math.sinf(f32(periods) * (2 * math.pi) * f32(frame) / f32(num_frames)) return math.sinf(f32(periods) * (2 * math.pi) * f32(frame) / f32(num_frames))
} }
fn my_audio_stream_callback(buffer &f32, num_frames, num_channels int) { fn my_audio_stream_callback(buffer &f32, num_frames int, num_channels int) {
ms := sw.elapsed().milliseconds() - sw_start_ms ms := sw.elapsed().milliseconds() - sw_start_ms
unsafe { unsafe {
mut soundbuffer := buffer mut soundbuffer := buffer

View File

@ -37,7 +37,7 @@ fn play_sounds(files []string) ? {
} }
// //
fn audio_player_callback(buffer &f32, num_frames, num_channels int, mut p Player) { fn audio_player_callback(buffer &f32, num_frames int, num_channels int, mut p Player) {
if p.finished { if p.finished {
return return
} }
@ -48,9 +48,7 @@ fn audio_player_callback(buffer &f32, num_frames, num_channels int, mut p Player
p.finished = true p.finished = true
return return
} }
unsafe { unsafe {C.memcpy(buffer, &p.samples[p.pos], nsamples * int(sizeof(f32)))}
C.memcpy(buffer, &p.samples[p.pos], nsamples * int(sizeof(f32)))
}
p.pos += nsamples p.pos += nsamples
} }

View File

@ -14,7 +14,7 @@ import math
import os import os
import strconv import strconv
fn evala(i, j int) int { fn evala(i int, j int) int {
return ((i + j) * (i + j + 1) / 2 + i + 1) return ((i + j) * (i + j + 1) / 2 + i + 1)
} }
@ -42,7 +42,6 @@ fn a_times_transp(mut v []f64, u []f64) {
mut x := []f64{len: u.len, init: 0} mut x := []f64{len: u.len, init: 0}
times(mut x, u) times(mut x, u)
times_trans(mut v, x) times_trans(mut v, x)
} }
fn main() { fn main() {
@ -50,8 +49,7 @@ fn main() {
mut n := 0 mut n := 0
if args.len == 2 { if args.len == 2 {
n = strconv.atoi(args[1]) n = strconv.atoi(args[1])
} } else {
else {
n = 0 n = 0
} }
mut u := []f64{len: n, init: 1} mut u := []f64{len: n, init: 1}

View File

@ -11,19 +11,25 @@ fn main() {
println(term.bold(term.red('It Worked!'))) println(term.bold(term.red('It Worked!')))
} }
fn sleeping_line(x,y,size int, ch string) { fn sleeping_line(x int, y int, size int, ch string) {
mut i := 0 mut i := 0
for i < size { for i < size {
term.set_cursor_position(x: x+i, y: y) term.set_cursor_position({
x: x + i
y: y
})
print(term.bold(term.yellow(ch))) print(term.bold(term.yellow(ch)))
i++ i++
} }
} }
fn standing_line(x,y,size int, ch string) { fn standing_line(x int, y int, size int, ch string) {
mut i := 0 mut i := 0
for i < size { for i < size {
term.set_cursor_position(x: x, y: y+i) term.set_cursor_position({
x: x
y: y + i
})
print(term.bold(term.yellow(ch))) print(term.bold(term.yellow(ch)))
i++ i++
} }

View File

@ -89,7 +89,7 @@ fn get_bet(money int) int {
return bet return bet
} }
fn run_wheel(bet_nbr, _bet int) int { fn run_wheel(bet_nbr int, _bet int) int {
mut bet := _bet mut bet := _bet
winning_nbr := rand.intn(50) winning_nbr := rand.intn(50)
print('Roulette Wheel spinning... and stops on the number $winning_nbr which is a ') print('Roulette Wheel spinning... and stops on the number $winning_nbr which is a ')