parser: deprecate short struct init (#10842)
parent
dc045806f9
commit
ad3835b598
|
@ -122,7 +122,7 @@ fn measure(cmd string, description string) int {
|
||||||
mut runs := []int{}
|
mut runs := []int{}
|
||||||
for r in 0 .. 5 {
|
for r in 0 .. 5 {
|
||||||
println(' Sample ${r + 1}/5')
|
println(' Sample ${r + 1}/5')
|
||||||
sw := time.new_stopwatch({})
|
sw := time.new_stopwatch()
|
||||||
exec(cmd)
|
exec(cmd)
|
||||||
runs << int(sw.elapsed().milliseconds())
|
runs << int(sw.elapsed().milliseconds())
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ pub fn (mut ts TestSession) append_message(kind MessageKind, msg string) {
|
||||||
|
|
||||||
pub fn (mut ts TestSession) print_messages() {
|
pub fn (mut ts TestSession) print_messages() {
|
||||||
empty := term.header(' ', ' ')
|
empty := term.header(' ', ' ')
|
||||||
mut print_msg_time := time.new_stopwatch({})
|
mut print_msg_time := time.new_stopwatch()
|
||||||
for {
|
for {
|
||||||
// get a message from the channel of messages to be printed:
|
// get a message from the channel of messages to be printed:
|
||||||
mut rmessage := <-ts.nmessages
|
mut rmessage := <-ts.nmessages
|
||||||
|
|
|
@ -245,7 +245,7 @@ fn (mut context Context) run() {
|
||||||
if context.warmup > 0 && run_warmups < context.commands.len {
|
if context.warmup > 0 && run_warmups < context.commands.len {
|
||||||
for i in 1 .. context.warmup + 1 {
|
for i in 1 .. context.warmup + 1 {
|
||||||
print('${context.cgoback}warming up run: ${i:4}/${context.warmup:-4} for ${cmd:-50s} took ${duration:6} ms ...')
|
print('${context.cgoback}warming up run: ${i:4}/${context.warmup:-4} for ${cmd:-50s} took ${duration:6} ms ...')
|
||||||
mut sw := time.new_stopwatch({})
|
mut sw := time.new_stopwatch()
|
||||||
res := os.execute(cmd)
|
res := os.execute(cmd)
|
||||||
if res.exit_code != 0 {
|
if res.exit_code != 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -261,7 +261,7 @@ fn (mut context Context) run() {
|
||||||
if context.show_output {
|
if context.show_output {
|
||||||
print(' | result: ${oldres:s}')
|
print(' | result: ${oldres:s}')
|
||||||
}
|
}
|
||||||
mut sw := time.new_stopwatch({})
|
mut sw := time.new_stopwatch()
|
||||||
res := scripting.exec(cmd) or { continue }
|
res := scripting.exec(cmd) or { continue }
|
||||||
duration = int(sw.elapsed().milliseconds())
|
duration = int(sw.elapsed().milliseconds())
|
||||||
if res.exit_code != 0 {
|
if res.exit_code != 0 {
|
||||||
|
|
|
@ -17,7 +17,7 @@ const vtest_nocleanup = os.getenv('VTEST_NOCLEANUP').bool()
|
||||||
fn main() {
|
fn main() {
|
||||||
mut commands := get_all_commands()
|
mut commands := get_all_commands()
|
||||||
// summary
|
// summary
|
||||||
sw := time.new_stopwatch({})
|
sw := time.new_stopwatch()
|
||||||
for mut cmd in commands {
|
for mut cmd in commands {
|
||||||
cmd.run()
|
cmd.run()
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ fn (mut cmd Command) run() {
|
||||||
if cmd.label != '' {
|
if cmd.label != '' {
|
||||||
println(term.header_left(cmd.label, '*'))
|
println(term.header_left(cmd.label, '*'))
|
||||||
}
|
}
|
||||||
sw := time.new_stopwatch({})
|
sw := time.new_stopwatch()
|
||||||
cmd.ecode = os.system(cmd.line)
|
cmd.ecode = os.system(cmd.line)
|
||||||
spent := sw.elapsed().milliseconds()
|
spent := sw.elapsed().milliseconds()
|
||||||
println('> Running: "$cmd.line" took: $spent ms ... ' +
|
println('> Running: "$cmd.line" took: $spent ms ... ' +
|
||||||
|
|
|
@ -73,9 +73,9 @@ fn main() {
|
||||||
context.expand_all_paths()
|
context.expand_all_paths()
|
||||||
mut fails := 0
|
mut fails := 0
|
||||||
mut panics := 0
|
mut panics := 0
|
||||||
sw := time.new_stopwatch({})
|
sw := time.new_stopwatch()
|
||||||
for path in context.all_paths {
|
for path in context.all_paths {
|
||||||
filesw := time.new_stopwatch({})
|
filesw := time.new_stopwatch()
|
||||||
context.start_printing()
|
context.start_printing()
|
||||||
new_fails, new_panics := context.process_whole_file_in_worker(path)
|
new_fails, new_panics := context.process_whole_file_in_worker(path)
|
||||||
fails += new_fails
|
fails += new_fails
|
||||||
|
|
|
@ -4045,7 +4045,7 @@ You can also use stopwatches to measure just portions of your code explicitly:
|
||||||
import time
|
import time
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
sw := time.new_stopwatch({})
|
sw := time.new_stopwatch()
|
||||||
println('Hello world')
|
println('Hello world')
|
||||||
println('Greeting the world took: ${sw.elapsed().nanoseconds()}ns')
|
println('Greeting the world took: ${sw.elapsed().nanoseconds()}ns')
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,8 +127,8 @@ struct Perf {
|
||||||
mut:
|
mut:
|
||||||
frame int
|
frame int
|
||||||
frame_old int
|
frame_old int
|
||||||
frame_sw time.StopWatch = time.new_stopwatch({})
|
frame_sw time.StopWatch = time.new_stopwatch()
|
||||||
second_sw time.StopWatch = time.new_stopwatch({})
|
second_sw time.StopWatch = time.new_stopwatch()
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Pos {
|
struct Pos {
|
||||||
|
@ -450,7 +450,7 @@ fn (p Prediction) str() string {
|
||||||
fn (mut app App) ai_move() {
|
fn (mut app App) ai_move() {
|
||||||
mut predictions := [4]Prediction{}
|
mut predictions := [4]Prediction{}
|
||||||
mut is_valid := false
|
mut is_valid := false
|
||||||
think_watch := time.new_stopwatch({})
|
think_watch := time.new_stopwatch()
|
||||||
for move in possible_moves {
|
for move in possible_moves {
|
||||||
move_idx := int(move)
|
move_idx := int(move)
|
||||||
predictions[move_idx].move = move
|
predictions[move_idx].move = move
|
||||||
|
@ -499,21 +499,21 @@ fn (mut app App) ai_move() {
|
||||||
fn (app &App) label_format(kind LabelKind) gx.TextCfg {
|
fn (app &App) label_format(kind LabelKind) gx.TextCfg {
|
||||||
match kind {
|
match kind {
|
||||||
.points {
|
.points {
|
||||||
return {
|
return gx.TextCfg{
|
||||||
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
|
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
|
||||||
align: .left
|
align: .left
|
||||||
size: app.ui.font_size / 2
|
size: app.ui.font_size / 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.moves {
|
.moves {
|
||||||
return {
|
return gx.TextCfg{
|
||||||
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
|
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
|
||||||
align: .right
|
align: .right
|
||||||
size: app.ui.font_size / 2
|
size: app.ui.font_size / 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.tile {
|
.tile {
|
||||||
return {
|
return gx.TextCfg{
|
||||||
color: app.theme.text_color
|
color: app.theme.text_color
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .middle
|
vertical_align: .middle
|
||||||
|
@ -521,7 +521,7 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.victory {
|
.victory {
|
||||||
return {
|
return gx.TextCfg{
|
||||||
color: app.theme.victory_color
|
color: app.theme.victory_color
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .middle
|
vertical_align: .middle
|
||||||
|
@ -529,7 +529,7 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.game_over {
|
.game_over {
|
||||||
return {
|
return gx.TextCfg{
|
||||||
color: app.theme.game_over_color
|
color: app.theme.game_over_color
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .middle
|
vertical_align: .middle
|
||||||
|
@ -537,7 +537,7 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.score_end {
|
.score_end {
|
||||||
return {
|
return gx.TextCfg{
|
||||||
color: gx.white
|
color: gx.white
|
||||||
align: .center
|
align: .center
|
||||||
vertical_align: .middle
|
vertical_align: .middle
|
||||||
|
@ -823,8 +823,8 @@ fn on_event(e &gg.Event, mut app App) {
|
||||||
.touches_began {
|
.touches_began {
|
||||||
if e.num_touches > 0 {
|
if e.num_touches > 0 {
|
||||||
t := e.touches[0]
|
t := e.touches[0]
|
||||||
app.touch.start = {
|
app.touch.start = Touch{
|
||||||
pos: {
|
pos: Pos{
|
||||||
x: int(t.pos_x / app.ui.dpi_scale)
|
x: int(t.pos_x / app.ui.dpi_scale)
|
||||||
y: int(t.pos_y / app.ui.dpi_scale)
|
y: int(t.pos_y / app.ui.dpi_scale)
|
||||||
}
|
}
|
||||||
|
@ -835,8 +835,8 @@ fn on_event(e &gg.Event, mut app App) {
|
||||||
.touches_ended {
|
.touches_ended {
|
||||||
if e.num_touches > 0 {
|
if e.num_touches > 0 {
|
||||||
t := e.touches[0]
|
t := e.touches[0]
|
||||||
app.touch.end = {
|
app.touch.end = Touch{
|
||||||
pos: {
|
pos: Pos{
|
||||||
x: int(t.pos_x / app.ui.dpi_scale)
|
x: int(t.pos_x / app.ui.dpi_scale)
|
||||||
y: int(t.pos_y / app.ui.dpi_scale)
|
y: int(t.pos_y / app.ui.dpi_scale)
|
||||||
}
|
}
|
||||||
|
@ -846,8 +846,8 @@ fn on_event(e &gg.Event, mut app App) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.mouse_down {
|
.mouse_down {
|
||||||
app.touch.start = {
|
app.touch.start = Touch{
|
||||||
pos: {
|
pos: Pos{
|
||||||
x: int(e.mouse_x / app.ui.dpi_scale)
|
x: int(e.mouse_x / app.ui.dpi_scale)
|
||||||
y: int(e.mouse_y / app.ui.dpi_scale)
|
y: int(e.mouse_y / app.ui.dpi_scale)
|
||||||
}
|
}
|
||||||
|
@ -855,8 +855,8 @@ fn on_event(e &gg.Event, mut app App) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.mouse_up {
|
.mouse_up {
|
||||||
app.touch.end = {
|
app.touch.end = Touch{
|
||||||
pos: {
|
pos: Pos{
|
||||||
x: int(e.mouse_x / app.ui.dpi_scale)
|
x: int(e.mouse_x / app.ui.dpi_scale)
|
||||||
y: int(e.mouse_y / app.ui.dpi_scale)
|
y: int(e.mouse_y / app.ui.dpi_scale)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,5 +32,5 @@ pub fn (mut particle Particle) tick(mut rocket Rocket, mut ctx gg.Context) {
|
||||||
particle.pos += particle.vel
|
particle.pos += particle.vel
|
||||||
particle.draw(mut ctx)
|
particle.draw(mut ctx)
|
||||||
|
|
||||||
particle.accel = {}
|
particle.accel = Vector{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub fn (mut rocket Rocket) tick(mut ctx gg.Context) {
|
||||||
rocket.pos += rocket.vel
|
rocket.pos += rocket.vel
|
||||||
rocket.draw(mut ctx)
|
rocket.draw(mut ctx)
|
||||||
|
|
||||||
rocket.accel = {}
|
rocket.accel = Vector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
for mut particle in rocket.particles {
|
for mut particle in rocket.particles {
|
||||||
|
@ -50,10 +50,10 @@ pub fn (mut rocket Rocket) tick(mut ctx gg.Context) {
|
||||||
pub fn new_rocket() Rocket {
|
pub fn new_rocket() Rocket {
|
||||||
return Rocket{
|
return Rocket{
|
||||||
color: random_color()
|
color: random_color()
|
||||||
pos: {
|
pos: Vector{
|
||||||
x: rand.f32_in_range(50, get_params().width - 50)
|
x: rand.f32_in_range(50, get_params().width - 50)
|
||||||
}
|
}
|
||||||
vel: {
|
vel: Vector{
|
||||||
x: rand.f32_in_range(-1.5, 1.5)
|
x: rand.f32_in_range(-1.5, 1.5)
|
||||||
y: rand.f32_in_range(5, 7)
|
y: rand.f32_in_range(5, 7)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub fn random_vector_in_circle() Vector {
|
||||||
theta := rand.f32n(2 * math.pi)
|
theta := rand.f32n(2 * math.pi)
|
||||||
y := rand.f32()
|
y := rand.f32()
|
||||||
|
|
||||||
return {
|
return Vector{
|
||||||
x: f32(y * math.sin(theta))
|
x: f32(y * math.sin(theta))
|
||||||
y: f32(y * math.cos(theta))
|
y: f32(y * math.cos(theta))
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ fn init(mut app App) {
|
||||||
|
|
||||||
// worker simulates a workload. This should be run in a separate thread.
|
// worker simulates a workload. This should be run in a separate thread.
|
||||||
fn worker(mut app App) {
|
fn worker(mut app App) {
|
||||||
stopwatch := time.new_stopwatch({})
|
stopwatch := time.new_stopwatch()
|
||||||
mut elapsed := stopwatch.elapsed()
|
mut elapsed := stopwatch.elapsed()
|
||||||
// Do heavy operations here - like invoking a path finding algorithm, load an image or similar.
|
// Do heavy operations here - like invoking a path finding algorithm, load an image or similar.
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import math
|
||||||
import sokol.audio
|
import sokol.audio
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sw = time.new_stopwatch({})
|
sw = time.new_stopwatch()
|
||||||
sw_start_ms = sw.elapsed().milliseconds()
|
sw_start_ms = sw.elapsed().milliseconds()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ mut:
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_color() tui.Color {
|
fn random_color() tui.Color {
|
||||||
return {
|
return tui.Color{
|
||||||
r: byte(rand.intn(256))
|
r: byte(rand.intn(256))
|
||||||
g: byte(rand.intn(256))
|
g: byte(rand.intn(256))
|
||||||
b: byte(rand.intn(256))
|
b: byte(rand.intn(256))
|
||||||
|
@ -32,7 +32,7 @@ fn event(e &tui.Event, x voidptr) {
|
||||||
match e.typ {
|
match e.typ {
|
||||||
.mouse_down {
|
.mouse_down {
|
||||||
app.is_drag = true
|
app.is_drag = true
|
||||||
app.cur_rect = {
|
app.cur_rect = Rect{
|
||||||
c: random_color()
|
c: random_color()
|
||||||
x: e.x
|
x: e.x
|
||||||
y: e.y
|
y: e.y
|
||||||
|
|
|
@ -156,20 +156,20 @@ fn event(event &ui.Event, x voidptr) {
|
||||||
app.is_dragging = false
|
app.is_dragging = false
|
||||||
}
|
}
|
||||||
.mouse_drag {
|
.mouse_drag {
|
||||||
app.mouse_pos = {
|
app.mouse_pos = Point{
|
||||||
x: event.x
|
x: event.x
|
||||||
y: event.y
|
y: event.y
|
||||||
}
|
}
|
||||||
app.paint(event)
|
app.paint(event)
|
||||||
}
|
}
|
||||||
.mouse_move {
|
.mouse_move {
|
||||||
app.mouse_pos = {
|
app.mouse_pos = Point{
|
||||||
x: event.x
|
x: event.x
|
||||||
y: event.y
|
y: event.y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.mouse_scroll {
|
.mouse_scroll {
|
||||||
app.mouse_pos = {
|
app.mouse_pos = Point{
|
||||||
x: event.x
|
x: event.x
|
||||||
y: event.y
|
y: event.y
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,9 +147,9 @@ fn (b Buffer) view(from int, to int) View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
raw := lines.join('\n')
|
raw := lines.join('\n')
|
||||||
return {
|
return View{
|
||||||
raw: raw.replace('\t', strings.repeat(` `, b.tab_width))
|
raw: raw.replace('\t', strings.repeat(` `, b.tab_width))
|
||||||
cursor: {
|
cursor: Cursor{
|
||||||
pos_x: x
|
pos_x: x
|
||||||
pos_y: b.cursor.pos_y
|
pos_y: b.cursor.pos_y
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ fn (mut v Vec) randomize(min_x int, min_y int, max_x int, max_y int) {
|
||||||
// part of snake's body representation
|
// part of snake's body representation
|
||||||
struct BodyPart {
|
struct BodyPart {
|
||||||
mut:
|
mut:
|
||||||
pos Vec = {
|
pos Vec = Vec{
|
||||||
x: block_size
|
x: block_size
|
||||||
y: block_size
|
y: block_size
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ fn (s Snake) draw() {
|
||||||
// rat representation
|
// rat representation
|
||||||
struct Rat {
|
struct Rat {
|
||||||
mut:
|
mut:
|
||||||
pos Vec = {
|
pos Vec = Vec{
|
||||||
x: block_size
|
x: block_size
|
||||||
y: block_size
|
y: block_size
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,8 +119,8 @@ mut:
|
||||||
// frame/time counters:
|
// frame/time counters:
|
||||||
frame int
|
frame int
|
||||||
frame_old int
|
frame_old int
|
||||||
frame_sw time.StopWatch = time.new_stopwatch({})
|
frame_sw time.StopWatch = time.new_stopwatch()
|
||||||
second_sw time.StopWatch = time.new_stopwatch({})
|
second_sw time.StopWatch = time.new_stopwatch()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remap(v f32, min f32, max f32, new_min f32, new_max f32) f32 {
|
fn remap(v f32, min f32, max f32, new_min f32, new_max f32) f32 {
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub mut:
|
||||||
// new_benchmark returns a `Benchmark` instance on the stack.
|
// new_benchmark returns a `Benchmark` instance on the stack.
|
||||||
pub fn new_benchmark() Benchmark {
|
pub fn new_benchmark() Benchmark {
|
||||||
return Benchmark{
|
return Benchmark{
|
||||||
bench_timer: time.new_stopwatch({})
|
bench_timer: time.new_stopwatch()
|
||||||
verbose: true
|
verbose: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ pub fn new_benchmark() Benchmark {
|
||||||
// new_benchmark_no_cstep returns a new `Benchmark` instance with step counting disabled.
|
// new_benchmark_no_cstep returns a new `Benchmark` instance with step counting disabled.
|
||||||
pub fn new_benchmark_no_cstep() Benchmark {
|
pub fn new_benchmark_no_cstep() Benchmark {
|
||||||
return Benchmark{
|
return Benchmark{
|
||||||
bench_timer: time.new_stopwatch({})
|
bench_timer: time.new_stopwatch()
|
||||||
verbose: true
|
verbose: true
|
||||||
no_cstep: true
|
no_cstep: true
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ pub fn new_benchmark_no_cstep() Benchmark {
|
||||||
// This is useful for long-lived use of `Benchmark` instances.
|
// This is useful for long-lived use of `Benchmark` instances.
|
||||||
pub fn new_benchmark_pointer() &Benchmark {
|
pub fn new_benchmark_pointer() &Benchmark {
|
||||||
return &Benchmark{
|
return &Benchmark{
|
||||||
bench_timer: time.new_stopwatch({})
|
bench_timer: time.new_stopwatch()
|
||||||
verbose: true
|
verbose: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ pub fn (o Option) str() string {
|
||||||
pub fn error(s string) Option {
|
pub fn error(s string) Option {
|
||||||
return Option{
|
return Option{
|
||||||
state: 2
|
state: 2
|
||||||
err: {
|
err: Error{
|
||||||
msg: s
|
msg: s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ pub fn error(s string) Option {
|
||||||
pub fn error_with_code(s string, code int) Option {
|
pub fn error_with_code(s string, code int) Option {
|
||||||
return Option{
|
return Option{
|
||||||
state: 2
|
state: 2
|
||||||
err: {
|
err: Error{
|
||||||
msg: s
|
msg: s
|
||||||
code: code
|
code: code
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,7 +193,7 @@ pub fn (ctx &Context) draw_text(x int, y int, text_ string, cfg gx.TextCfg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (ctx &Context) draw_text_def(x int, y int, text string) {
|
pub fn (ctx &Context) draw_text_def(x int, y int, text string) {
|
||||||
ctx.draw_text(x, y, text, {})
|
ctx.draw_text(x, y, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub fn (mut r ReaderWriterImpl) write(buf []byte) ?int {
|
||||||
// make_readerwriter takes a rstream and a wstream and makes
|
// make_readerwriter takes a rstream and a wstream and makes
|
||||||
// an rwstream with them
|
// an rwstream with them
|
||||||
pub fn make_readerwriter(r Reader, w Writer) ReaderWriterImpl {
|
pub fn make_readerwriter(r Reader, w Writer) ReaderWriterImpl {
|
||||||
return {
|
return ReaderWriterImpl{
|
||||||
r: r
|
r: r
|
||||||
w: w
|
w: w
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub fn temp_file(tfo TempFileOptions) ?(os.File, string) {
|
||||||
' could not create temporary file in "$d". Please ensure write permissions.')
|
' could not create temporary file in "$d". Please ensure write permissions.')
|
||||||
}
|
}
|
||||||
d = d.trim_right(os.path_separator)
|
d = d.trim_right(os.path_separator)
|
||||||
mut rng := rand.new_default({})
|
mut rng := rand.new_default()
|
||||||
prefix, suffix := prefix_and_suffix(tfo.pattern) or { return error(@FN + ' ' + err.msg) }
|
prefix, suffix := prefix_and_suffix(tfo.pattern) or { return error(@FN + ' ' + err.msg) }
|
||||||
for retry := 0; retry < util.retries; retry++ {
|
for retry := 0; retry < util.retries; retry++ {
|
||||||
path := os.join_path(d, prefix + random_number(mut rng) + suffix)
|
path := os.join_path(d, prefix + random_number(mut rng) + suffix)
|
||||||
|
@ -60,7 +60,7 @@ pub fn temp_dir(tdo TempFileOptions) ?string {
|
||||||
' could not create temporary directory "$d". Please ensure write permissions.')
|
' could not create temporary directory "$d". Please ensure write permissions.')
|
||||||
}
|
}
|
||||||
d = d.trim_right(os.path_separator)
|
d = d.trim_right(os.path_separator)
|
||||||
mut rng := rand.new_default({})
|
mut rng := rand.new_default()
|
||||||
prefix, suffix := prefix_and_suffix(tdo.pattern) or { return error(@FN + ' ' + err.msg) }
|
prefix, suffix := prefix_and_suffix(tdo.pattern) or { return error(@FN + ' ' + err.msg) }
|
||||||
for retry := 0; retry < util.retries; retry++ {
|
for retry := 0; retry < util.retries; retry++ {
|
||||||
path := os.join_path(d, prefix + random_number(mut rng) + suffix)
|
path := os.join_path(d, prefix + random_number(mut rng) + suffix)
|
||||||
|
|
|
@ -26,7 +26,7 @@ fn testsuite_end() {
|
||||||
|
|
||||||
fn test_temp_file() {
|
fn test_temp_file() {
|
||||||
// Test defaults
|
// Test defaults
|
||||||
mut f, mut path := util.temp_file({}) or {
|
mut f, mut path := util.temp_file() or {
|
||||||
assert false
|
assert false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ fn test_temp_file() {
|
||||||
|
|
||||||
fn test_temp_dir() {
|
fn test_temp_dir() {
|
||||||
// Test defaults
|
// Test defaults
|
||||||
mut path := util.temp_dir({}) or {
|
mut path := util.temp_dir() or {
|
||||||
assert false
|
assert false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ const (
|
||||||
fn new_ip6(port u16, addr [16]byte) Addr {
|
fn new_ip6(port u16, addr [16]byte) Addr {
|
||||||
a := Addr{
|
a := Addr{
|
||||||
f: u16(AddrFamily.ip6)
|
f: u16(AddrFamily.ip6)
|
||||||
addr: {
|
addr: AddrData{
|
||||||
Ip6: {
|
Ip6: Ip6{
|
||||||
port: u16(C.htons(port))
|
port: u16(C.htons(port))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,8 @@ fn new_ip6(port u16, addr [16]byte) Addr {
|
||||||
fn new_ip(port u16, addr [4]byte) Addr {
|
fn new_ip(port u16, addr [4]byte) Addr {
|
||||||
a := Addr{
|
a := Addr{
|
||||||
f: u16(AddrFamily.ip)
|
f: u16(AddrFamily.ip)
|
||||||
addr: {
|
addr: AddrData{
|
||||||
Ip: {
|
Ip: Ip{
|
||||||
port: u16(C.htons(port))
|
port: u16(C.htons(port))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ fn temp_unix() ?Addr {
|
||||||
// close it
|
// close it
|
||||||
// remove it
|
// remove it
|
||||||
// then reuse the filename
|
// then reuse the filename
|
||||||
mut file, filename := util.temp_file({}) ?
|
mut file, filename := util.temp_file() ?
|
||||||
file.close()
|
file.close()
|
||||||
os.rm(filename) ?
|
os.rm(filename) ?
|
||||||
addrs := resolve_addrs(filename, .unix, .udp) ?
|
addrs := resolve_addrs(filename, .unix, .udp) ?
|
||||||
|
@ -203,8 +203,8 @@ pub fn resolve_ipaddrs(addr string, family AddrFamily, typ SocketType) ?[]Addr {
|
||||||
match AddrFamily(result.ai_family) {
|
match AddrFamily(result.ai_family) {
|
||||||
.ip, .ip6 {
|
.ip, .ip6 {
|
||||||
new_addr := Addr{
|
new_addr := Addr{
|
||||||
addr: {
|
addr: AddrData{
|
||||||
Ip6: {}
|
Ip6: Ip6{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -246,8 +246,8 @@ fn (a Addr) str() string {
|
||||||
|
|
||||||
pub fn addr_from_socket_handle(handle int) Addr {
|
pub fn addr_from_socket_handle(handle int) Addr {
|
||||||
addr := Addr{
|
addr := Addr{
|
||||||
addr: {
|
addr: AddrData{
|
||||||
Ip6: {}
|
Ip6: Ip6{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size := sizeof(addr)
|
size := sizeof(addr)
|
||||||
|
|
|
@ -165,8 +165,8 @@ pub fn (mut c TcpConn) wait_for_write() ? {
|
||||||
|
|
||||||
pub fn (c &TcpConn) peer_addr() ?Addr {
|
pub fn (c &TcpConn) peer_addr() ?Addr {
|
||||||
mut addr := Addr{
|
mut addr := Addr{
|
||||||
addr: {
|
addr: AddrData{
|
||||||
Ip6: {}
|
Ip6: Ip6{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mut size := sizeof(Addr)
|
mut size := sizeof(Addr)
|
||||||
|
@ -217,8 +217,8 @@ pub fn listen_tcp(family AddrFamily, saddr string) ?&TcpListener {
|
||||||
|
|
||||||
pub fn (mut l TcpListener) accept() ?&TcpConn {
|
pub fn (mut l TcpListener) accept() ?&TcpConn {
|
||||||
addr := Addr{
|
addr := Addr{
|
||||||
addr: {
|
addr: AddrData{
|
||||||
Ip6: {}
|
Ip6: Ip6{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size := sizeof(Addr)
|
size := sizeof(Addr)
|
||||||
|
|
|
@ -104,8 +104,8 @@ pub fn (mut c UdpConn) write_to_string(addr Addr, s string) ?int {
|
||||||
// read reads from the socket into buf up to buf.len returning the number of bytes read
|
// read reads from the socket into buf up to buf.len returning the number of bytes read
|
||||||
pub fn (mut c UdpConn) read(mut buf []byte) ?(int, Addr) {
|
pub fn (mut c UdpConn) read(mut buf []byte) ?(int, Addr) {
|
||||||
mut addr := Addr{
|
mut addr := Addr{
|
||||||
addr: {
|
addr: AddrData{
|
||||||
Ip6: {}
|
Ip6: Ip6{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
len := sizeof(Addr)
|
len := sizeof(Addr)
|
||||||
|
@ -206,8 +206,8 @@ fn new_udp_socket(local_addr Addr) ?&UdpSocket {
|
||||||
handle: sockfd
|
handle: sockfd
|
||||||
l: local_addr
|
l: local_addr
|
||||||
r: Addr{
|
r: Addr{
|
||||||
addr: {
|
addr: AddrData{
|
||||||
Ip6: {}
|
Ip6: Ip6{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,8 +246,8 @@ fn new_udp_socket_for_remote(raddr Addr) ?&UdpSocket {
|
||||||
panic('Invalid family')
|
panic('Invalid family')
|
||||||
// Appease compiler
|
// Appease compiler
|
||||||
Addr{
|
Addr{
|
||||||
addr: {
|
addr: AddrData{
|
||||||
Ip6: {}
|
Ip6: Ip6{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ pub struct NormalConfigStruct {
|
||||||
|
|
||||||
// normal_pair returns a pair of normally distributed random numbers with the mean mu
|
// normal_pair returns a pair of normally distributed random numbers with the mean mu
|
||||||
// and standard deviation sigma. If not specified, mu is 0 and sigma is 1. Intended usage is
|
// and standard deviation sigma. If not specified, mu is 0 and sigma is 1. Intended usage is
|
||||||
// `x, y := normal_pair(mu: mean, sigma: stdev)`, or `x, y := normal_pair({})`.
|
// `x, y := normal_pair(mu: mean, sigma: stdev)`, or `x, y := normal_pair()`.
|
||||||
pub fn normal_pair(config NormalConfigStruct) (f64, f64) {
|
pub fn normal_pair(config NormalConfigStruct) (f64, f64) {
|
||||||
if config.sigma <= 0 {
|
if config.sigma <= 0 {
|
||||||
panic('The standard deviation has to be positive.')
|
panic('The standard deviation has to be positive.')
|
||||||
|
@ -66,7 +66,7 @@ pub fn normal_pair(config NormalConfigStruct) (f64, f64) {
|
||||||
|
|
||||||
// normal returns a normally distributed random number with the mean mu and standard deviation
|
// normal returns a normally distributed random number with the mean mu and standard deviation
|
||||||
// sigma. If not specified, mu is 0 and sigma is 1. Intended usage is
|
// sigma. If not specified, mu is 0 and sigma is 1. Intended usage is
|
||||||
// `x := normal(mu: mean, sigma: etdev)` or `x := normal({})`.
|
// `x := normal(mu: mean, sigma: etdev)` or `x := normal()`.
|
||||||
// **NOTE:** If you are generating a lot of normal variates, use `the normal_pair` function
|
// **NOTE:** If you are generating a lot of normal variates, use `the normal_pair` function
|
||||||
// instead. This function discards one of the two variates generated by the `normal_pair` function.
|
// instead. This function discards one of the two variates generated by the `normal_pair` function.
|
||||||
pub fn normal(config NormalConfigStruct) f64 {
|
pub fn normal(config NormalConfigStruct) f64 {
|
||||||
|
|
|
@ -49,7 +49,7 @@ __global (
|
||||||
|
|
||||||
// init initializes the default RNG.
|
// init initializes the default RNG.
|
||||||
fn init() {
|
fn init() {
|
||||||
default_rng = new_default({})
|
default_rng = new_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
// new_default returns a new instance of the default RNG. If the seed is not provided, the current time will be used to seed the instance.
|
// new_default returns a new instance of the default RNG. If the seed is not provided, the current time will be used to seed the instance.
|
||||||
|
|
|
@ -32,7 +32,7 @@ fn main() {
|
||||||
nrec := os.args[2].int()
|
nrec := os.args[2].int()
|
||||||
buflen := os.args[3].int()
|
buflen := os.args[3].int()
|
||||||
nobj := os.args[4].int()
|
nobj := os.args[4].int()
|
||||||
stopwatch := time.new_stopwatch({})
|
stopwatch := time.new_stopwatch()
|
||||||
ch := chan int{cap: buflen}
|
ch := chan int{cap: buflen}
|
||||||
resch := chan i64{}
|
resch := chan i64{}
|
||||||
mut no := nobj
|
mut no := nobj
|
||||||
|
|
|
@ -36,7 +36,7 @@ mut:
|
||||||
|
|
||||||
fn do_rec(ch chan int, id int, mut ctx Context) {
|
fn do_rec(ch chan int, id int, mut ctx Context) {
|
||||||
eprintln('start of do_rec id: $id')
|
eprintln('start of do_rec id: $id')
|
||||||
mut timer_sw_x := time.new_stopwatch({})
|
mut timer_sw_x := time.new_stopwatch()
|
||||||
mut tmp := int(0)
|
mut tmp := int(0)
|
||||||
mut i := int(0)
|
mut i := int(0)
|
||||||
// NB: a single receiver thread can get slightly more
|
// NB: a single receiver thread can get slightly more
|
||||||
|
@ -69,7 +69,7 @@ fn do_rec(ch chan int, id int, mut ctx Context) {
|
||||||
|
|
||||||
fn do_send(ch chan int, id int, mut ctx Context) {
|
fn do_send(ch chan int, id int, mut ctx Context) {
|
||||||
eprintln('start of do_send id: $id')
|
eprintln('start of do_send id: $id')
|
||||||
mut timer_sw_x := time.new_stopwatch({})
|
mut timer_sw_x := time.new_stopwatch()
|
||||||
n_iters := ctx.n_iters
|
n_iters := ctx.n_iters
|
||||||
base := n_iters * id // sender events can not overlap
|
base := n_iters * id // sender events can not overlap
|
||||||
for i := 0; i < n_iters; i++ {
|
for i := 0; i < n_iters; i++ {
|
||||||
|
|
|
@ -86,7 +86,7 @@ fn test_select_blocks() {
|
||||||
a: 13
|
a: 13
|
||||||
}
|
}
|
||||||
sem.wait()
|
sem.wait()
|
||||||
stopwatch := time.new_stopwatch({})
|
stopwatch := time.new_stopwatch()
|
||||||
go f1(ch1, ch2, ch3, ch4, ch5, mut sem)
|
go f1(ch1, ch2, ch3, ch4, ch5, mut sem)
|
||||||
sem.wait()
|
sem.wait()
|
||||||
elapsed_ms := f64(stopwatch.elapsed()) / time.millisecond
|
elapsed_ms := f64(stopwatch.elapsed()) / time.millisecond
|
||||||
|
|
|
@ -648,7 +648,7 @@ pub fn channel_select(mut channels []&Channel, dir []Direction, mut objrefs []vo
|
||||||
stopwatch := if timeout == time.infinite || timeout <= 0 {
|
stopwatch := if timeout == time.infinite || timeout <= 0 {
|
||||||
time.StopWatch{}
|
time.StopWatch{}
|
||||||
} else {
|
} else {
|
||||||
time.new_stopwatch({})
|
time.new_stopwatch()
|
||||||
}
|
}
|
||||||
mut event_idx := -1 // negative index means `timed out`
|
mut event_idx := -1 // negative index means `timed out`
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import time
|
||||||
// time than you have specified. To avoid false positives from CI test
|
// time than you have specified. To avoid false positives from CI test
|
||||||
// failures, some of the asserts will be run only if you pass `-d stopwatch`
|
// failures, some of the asserts will be run only if you pass `-d stopwatch`
|
||||||
fn test_stopwatch_works_as_intended() {
|
fn test_stopwatch_works_as_intended() {
|
||||||
mut sw := time.new_stopwatch({})
|
mut sw := time.new_stopwatch()
|
||||||
// sample code that you want to measure:
|
// sample code that you want to measure:
|
||||||
println('Hello world')
|
println('Hello world')
|
||||||
time.sleep(1 * time.millisecond)
|
time.sleep(1 * time.millisecond)
|
||||||
|
@ -15,7 +15,7 @@ fn test_stopwatch_works_as_intended() {
|
||||||
|
|
||||||
fn test_stopwatch_time_between_pause_and_start_should_be_skipped_in_elapsed() {
|
fn test_stopwatch_time_between_pause_and_start_should_be_skipped_in_elapsed() {
|
||||||
println('Testing pause function')
|
println('Testing pause function')
|
||||||
mut sw := time.new_stopwatch({})
|
mut sw := time.new_stopwatch()
|
||||||
time.sleep(10 * time.millisecond) // A
|
time.sleep(10 * time.millisecond) // A
|
||||||
eprintln('Elapsed after 10ms nap: ${sw.elapsed().milliseconds()}ms')
|
eprintln('Elapsed after 10ms nap: ${sw.elapsed().milliseconds()}ms')
|
||||||
assert sw.elapsed().milliseconds() >= 8 // sometimes it sleeps for 9ms on windows..
|
assert sw.elapsed().milliseconds() >= 8 // sometimes it sleeps for 9ms on windows..
|
||||||
|
|
|
@ -556,7 +556,7 @@ fn (mut t Table) check_for_already_registered_symbol(typ TypeSymbol, existing_id
|
||||||
.placeholder {
|
.placeholder {
|
||||||
// override placeholder
|
// override placeholder
|
||||||
// println('overriding type placeholder `$typ.name`')
|
// println('overriding type placeholder `$typ.name`')
|
||||||
t.type_symbols[existing_idx] = {
|
t.type_symbols[existing_idx] = TypeSymbol{
|
||||||
...typ
|
...typ
|
||||||
methods: ex_type.methods
|
methods: ex_type.methods
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub fn compile(command string, pref &pref.Preferences) {
|
||||||
println('builder.compile() pref:')
|
println('builder.compile() pref:')
|
||||||
// println(pref)
|
// println(pref)
|
||||||
}
|
}
|
||||||
mut sw := time.new_stopwatch({})
|
mut sw := time.new_stopwatch()
|
||||||
match pref.backend {
|
match pref.backend {
|
||||||
.c { b.compile_c() }
|
.c { b.compile_c() }
|
||||||
.js_node, .js_freestanding, .js_browser { b.compile_js() }
|
.js_node, .js_freestanding, .js_browser { b.compile_js() }
|
||||||
|
|
|
@ -1988,7 +1988,7 @@ pub fn (mut c Checker) check_expected_arg_count(mut call_expr ast.CallExpr, f &a
|
||||||
last_sym := c.table.get_type_symbol(last_typ)
|
last_sym := c.table.get_type_symbol(last_typ)
|
||||||
if last_sym.kind == .struct_ {
|
if last_sym.kind == .struct_ {
|
||||||
// allow empty trailing struct syntax arg (`f()` where `f` is `fn(ConfigStruct)`)
|
// allow empty trailing struct syntax arg (`f()` where `f` is `fn(ConfigStruct)`)
|
||||||
call_expr.args << {
|
call_expr.args << ast.CallArg{
|
||||||
expr: ast.StructInit{
|
expr: ast.StructInit{
|
||||||
typ: last_typ
|
typ: last_typ
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,11 @@ vlib/v/checker/tests/array_or_map_assign_err.vv:5:5: error: use `array2 = array1
|
||||||
4 | mut a3 := []int{}
|
4 | mut a3 := []int{}
|
||||||
5 | a3 = a1
|
5 | a3 = a1
|
||||||
| ^
|
| ^
|
||||||
6 |
|
6 |
|
||||||
7 | m1 := {'one': 1}
|
7 | m1 := map{'one': 1}
|
||||||
vlib/v/checker/tests/array_or_map_assign_err.vv:8:8: error: cannot copy map: call `move` or `clone` method (or use a reference)
|
vlib/v/checker/tests/array_or_map_assign_err.vv:8:8: error: cannot copy map: call `move` or `clone` method (or use a reference)
|
||||||
6 |
|
6 |
|
||||||
7 | m1 := {'one': 1}
|
7 | m1 := map{'one': 1}
|
||||||
8 | m2 := m1
|
8 | m2 := m1
|
||||||
| ~~
|
| ~~
|
||||||
9 | mut m3 := map[string]int{}
|
9 | mut m3 := map[string]int{}
|
||||||
|
@ -24,10 +24,10 @@ vlib/v/checker/tests/array_or_map_assign_err.vv:10:7: error: cannot copy map: ca
|
||||||
9 | mut m3 := map[string]int{}
|
9 | mut m3 := map[string]int{}
|
||||||
10 | m3 = m1
|
10 | m3 = m1
|
||||||
| ~~
|
| ~~
|
||||||
11 |
|
11 |
|
||||||
12 | _ = a2
|
12 | _ = a2
|
||||||
vlib/v/checker/tests/array_or_map_assign_err.vv:25:8: error: cannot copy map: call `move` or `clone` method (or use a reference)
|
vlib/v/checker/tests/array_or_map_assign_err.vv:25:8: error: cannot copy map: call `move` or `clone` method (or use a reference)
|
||||||
23 |
|
23 |
|
||||||
24 | fn foo(mut m map[string]int) {
|
24 | fn foo(mut m map[string]int) {
|
||||||
25 | m2 := m
|
25 | m2 := m
|
||||||
| ^
|
| ^
|
||||||
|
|
|
@ -4,7 +4,7 @@ fn main() {
|
||||||
mut a3 := []int{}
|
mut a3 := []int{}
|
||||||
a3 = a1
|
a3 = a1
|
||||||
|
|
||||||
m1 := {'one': 1}
|
m1 := map{'one': 1}
|
||||||
m2 := m1
|
m2 := m1
|
||||||
mut m3 := map[string]int{}
|
mut m3 := map[string]int{}
|
||||||
m3 = m1
|
m3 = m1
|
||||||
|
@ -12,7 +12,7 @@ fn main() {
|
||||||
_ = a2
|
_ = a2
|
||||||
_ = m2
|
_ = m2
|
||||||
|
|
||||||
mut m := {'foo':1}
|
mut m := map{'foo':1}
|
||||||
foo(mut m)
|
foo(mut m)
|
||||||
|
|
||||||
_ = a3
|
_ = a3
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
vlib/v/checker/tests/for_in_map_one_variable_err.vv:3:6: error: declare a key and a value variable when ranging a map: `for key, val in map {`
|
vlib/v/checker/tests/for_in_map_one_variable_err.vv:3:6: error: declare a key and a value variable when ranging a map: `for key, val in map {`
|
||||||
use `_` if you do not need the variable
|
use `_` if you do not need the variable
|
||||||
1 | fn main() {
|
1 | fn main() {
|
||||||
2 | kvs := {'foo':'bar'}
|
2 | kvs := map{'foo':'bar'}
|
||||||
3 | for k in kvs {
|
3 | for k in kvs {
|
||||||
| ^
|
| ^
|
||||||
4 | println('$k')
|
4 | println('$k')
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
kvs := {'foo':'bar'}
|
kvs := map{'foo':'bar'}
|
||||||
for k in kvs {
|
for k in kvs {
|
||||||
println('$k')
|
println('$k')
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ vlib/v/checker/tests/for_in_mut_val_type.vv:7:15: error: `a2` is immutable, it c
|
||||||
9 | }
|
9 | }
|
||||||
vlib/v/checker/tests/for_in_mut_val_type.vv:11:18: error: `m` is immutable, it cannot be changed
|
vlib/v/checker/tests/for_in_mut_val_type.vv:11:18: error: `m` is immutable, it cannot be changed
|
||||||
9 | }
|
9 | }
|
||||||
10 | m := {'aa': 1, 'bb': 2}
|
10 | m := map{'aa': 1, 'bb': 2}
|
||||||
11 | for _, mut j in m {
|
11 | for _, mut j in m {
|
||||||
| ^
|
| ^
|
||||||
12 | j *= 2
|
12 | j *= 2
|
||||||
|
@ -33,10 +33,10 @@ vlib/v/checker/tests/for_in_mut_val_type.vv:17:15: error: array literal is immut
|
||||||
| ~~~~~~~~~~
|
| ~~~~~~~~~~
|
||||||
18 | j *= 2
|
18 | j *= 2
|
||||||
19 | }
|
19 | }
|
||||||
vlib/v/checker/tests/for_in_mut_val_type.vv:20:18: error: map literal is immutable, it cannot be changed
|
vlib/v/checker/tests/for_in_mut_val_type.vv:20:21: error: map literal is immutable, it cannot be changed
|
||||||
18 | j *= 2
|
18 | j *= 2
|
||||||
19 | }
|
19 | }
|
||||||
20 | for _, mut j in {'aa': 1, 'bb': 2} {
|
20 | for _, mut j in map{'aa': 1, 'bb': 2} {
|
||||||
| ~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~
|
||||||
21 | j *= 2
|
21 | j *= 2
|
||||||
22 | }
|
22 | }
|
|
@ -7,7 +7,7 @@ fn main() {
|
||||||
for mut j in a2 {
|
for mut j in a2 {
|
||||||
j *= 2
|
j *= 2
|
||||||
}
|
}
|
||||||
m := {'aa': 1, 'bb': 2}
|
m := map{'aa': 1, 'bb': 2}
|
||||||
for _, mut j in m {
|
for _, mut j in m {
|
||||||
j *= 2
|
j *= 2
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ fn main() {
|
||||||
for mut j in [1, 2, 3]! {
|
for mut j in [1, 2, 3]! {
|
||||||
j *= 2
|
j *= 2
|
||||||
}
|
}
|
||||||
for _, mut j in {'aa': 1, 'bb': 2} {
|
for _, mut j in map{'aa': 1, 'bb': 2} {
|
||||||
j *= 2
|
j *= 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ type Int = int
|
||||||
fn main() {
|
fn main() {
|
||||||
a_i := [1, 2, 3]
|
a_i := [1, 2, 3]
|
||||||
a_s := ['1', '2', '3']
|
a_s := ['1', '2', '3']
|
||||||
m := {
|
m := map{
|
||||||
'test': 1
|
'test': 1
|
||||||
}
|
}
|
||||||
s := 'abcd'
|
s := 'abcd'
|
||||||
|
|
|
@ -4,13 +4,13 @@ vlib/v/checker/tests/map_delete.vv:5:11: error: cannot use `int literal` as `str
|
||||||
5 | m.delete(1)
|
5 | m.delete(1)
|
||||||
| ^
|
| ^
|
||||||
6 | m.delete(1, 2)
|
6 | m.delete(1, 2)
|
||||||
7 | m2 := {
|
7 | m2 := map{
|
||||||
vlib/v/checker/tests/map_delete.vv:6:4: error: expected 1 argument, but got 2
|
vlib/v/checker/tests/map_delete.vv:6:4: error: expected 1 argument, but got 2
|
||||||
4 | }
|
4 | }
|
||||||
5 | m.delete(1)
|
5 | m.delete(1)
|
||||||
6 | m.delete(1, 2)
|
6 | m.delete(1, 2)
|
||||||
| ~~~~~~~~~~~~
|
| ~~~~~~~~~~~~
|
||||||
7 | m2 := {
|
7 | m2 := map{
|
||||||
8 | '1': 1
|
8 | '1': 1
|
||||||
vlib/v/checker/tests/map_delete.vv:10:2: error: `m2` is immutable, declare it with `mut` to make it mutable
|
vlib/v/checker/tests/map_delete.vv:10:2: error: `m2` is immutable, declare it with `mut` to make it mutable
|
||||||
8 | '1': 1
|
8 | '1': 1
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
mut m := {
|
mut m := map{
|
||||||
'1': 1
|
'1': 1
|
||||||
}
|
}
|
||||||
m.delete(1)
|
m.delete(1)
|
||||||
m.delete(1, 2)
|
m.delete(1, 2)
|
||||||
m2 := {
|
m2 := map{
|
||||||
'1': 1
|
'1': 1
|
||||||
}
|
}
|
||||||
m2.delete('1')
|
m2.delete('1')
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ vlib/v/checker/tests/map_init_key_duplicate_err.vv:5:3: error: duplicate key "fo
|
||||||
| ~~~~~
|
| ~~~~~
|
||||||
6 | }
|
6 | }
|
||||||
7 | println(a)
|
7 | println(a)
|
||||||
vlib/v/checker/tests/map_init_key_duplicate_err.vv:9:15: error: duplicate key "2" in map literal
|
vlib/v/checker/tests/map_init_key_duplicate_err.vv:9:18: error: duplicate key "2" in map literal
|
||||||
7 | println(a)
|
7 | println(a)
|
||||||
8 |
|
8 |
|
||||||
9 | _ = {2:0 3:0 2:0}
|
9 | _ = map{2:0 3:0 2:0}
|
||||||
| ^
|
| ^
|
||||||
10 | }
|
10 | }
|
|
@ -1,10 +1,10 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
a := {
|
a := map{
|
||||||
'foo': 'bar'
|
'foo': 'bar'
|
||||||
'abc': 'abc'
|
'abc': 'abc'
|
||||||
'foo': 'bar'
|
'foo': 'bar'
|
||||||
}
|
}
|
||||||
println(a)
|
println(a)
|
||||||
|
|
||||||
_ = {2:0 3:0 2:0}
|
_ = map{2:0 3:0 2:0}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
vlib/v/checker/tests/map_init_wrong_type.vv:3:15: error: invalid map value: expected `f32`, not `float literal`
|
vlib/v/checker/tests/map_init_wrong_type.vv:3:18: error: invalid map value: expected `f32`, not `float literal`
|
||||||
1 | fn main() {
|
1 | fn main() {
|
||||||
2 | mut a := map[string]f32{}
|
2 | mut a := map[string]f32{}
|
||||||
3 | a = { 'x': 12.3 }
|
3 | a = map{ 'x': 12.3 }
|
||||||
| ~~~~
|
| ~~~~
|
||||||
4 | _ = {2:0 3:0 "hi":0}
|
4 | _ = map{2:0 3:0 "hi":0}
|
||||||
5 | _ = {2:0 3:`@` 4:0}
|
5 | _ = map{2:0 3:`@` 4:0}
|
||||||
vlib/v/checker/tests/map_init_wrong_type.vv:4:17: error: invalid map key: expected `int`, not `string`
|
vlib/v/checker/tests/map_init_wrong_type.vv:4:20: error: invalid map key: expected `int`, not `string`
|
||||||
2 | mut a := map[string]f32{}
|
2 | mut a := map[string]f32{}
|
||||||
3 | a = { 'x': 12.3 }
|
3 | a = map{ 'x': 12.3 }
|
||||||
4 | _ = {2:0 3:0 "hi":0}
|
4 | _ = map{2:0 3:0 "hi":0}
|
||||||
| ~~~~
|
| ~~~~
|
||||||
5 | _ = {2:0 3:`@` 4:0}
|
5 | _ = map{2:0 3:`@` 4:0}
|
||||||
6 | _ = a
|
6 | _ = a
|
||||||
vlib/v/checker/tests/map_init_wrong_type.vv:5:15: error: invalid map value: expected `int`, not `rune`
|
vlib/v/checker/tests/map_init_wrong_type.vv:5:18: error: invalid map value: expected `int`, not `rune`
|
||||||
3 | a = { 'x': 12.3 }
|
3 | a = map{ 'x': 12.3 }
|
||||||
4 | _ = {2:0 3:0 "hi":0}
|
4 | _ = map{2:0 3:0 "hi":0}
|
||||||
5 | _ = {2:0 3:`@` 4:0}
|
5 | _ = map{2:0 3:`@` 4:0}
|
||||||
| ~~~
|
| ~~~
|
||||||
6 | _ = a
|
6 | _ = a
|
||||||
7 | }
|
7 | }
|
|
@ -1,7 +1,7 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
mut a := map[string]f32{}
|
mut a := map[string]f32{}
|
||||||
a = { 'x': 12.3 }
|
a = map{ 'x': 12.3 }
|
||||||
_ = {2:0 3:0 "hi":0}
|
_ = map{2:0 3:0 "hi":0}
|
||||||
_ = {2:0 3:`@` 4:0}
|
_ = map{2:0 3:`@` 4:0}
|
||||||
_ = a
|
_ = a
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
vlib/v/checker/tests/mut_map_get_value_address_err.vv:3:12: error: cannot take the address of map values
|
vlib/v/checker/tests/mut_map_get_value_address_err.vv:3:12: error: cannot take the address of map values
|
||||||
1 | fn main() {
|
1 | fn main() {
|
||||||
2 | mut m := {'key' : 3}
|
2 | mut m := map{'key' : 3}
|
||||||
3 | a := &m['key']
|
3 | a := &m['key']
|
||||||
| ~~~~~~~
|
| ~~~~~~~
|
||||||
4 | println(a)
|
4 | println(a)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
mut m := {'key' : 3}
|
mut m := map{'key' : 3}
|
||||||
a := &m['key']
|
a := &m['key']
|
||||||
println(a)
|
println(a)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
vlib/v/checker/tests/no_interface_instantiation_b.vv:6:12: error: cannot instantiate interface `Speaker`
|
vlib/v/checker/tests/no_interface_instantiation_b.vv:6:5: error: expected 1 arguments, but got 0
|
||||||
4 |
|
4 |
|
||||||
5 | fn main() {
|
5 | fn main() {
|
||||||
6 | my_fn({})
|
6 | my_fn()
|
||||||
| ^
|
| ~~~~~~~
|
||||||
7 | }
|
7 | }
|
|
@ -3,5 +3,5 @@ interface Speaker {}
|
||||||
fn my_fn(s Speaker) {}
|
fn my_fn(s Speaker) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
my_fn({})
|
my_fn()
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ fn a_val(a []int) int {
|
||||||
fn test_shared_as_value() {
|
fn test_shared_as_value() {
|
||||||
shared s := St{ a: 5 }
|
shared s := St{ a: 5 }
|
||||||
shared a := [3, 4, 6, 13, -23]
|
shared a := [3, 4, 6, 13, -23]
|
||||||
shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625}
|
shared m := map{'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625}
|
||||||
shared r := Qr{ a: 7 }
|
shared r := Qr{ a: 7 }
|
||||||
lock s {
|
lock s {
|
||||||
u := r.s_val(s)
|
u := r.s_val(s)
|
||||||
|
@ -55,7 +55,7 @@ fn test_shared_as_value() {
|
||||||
fn test_shared_as_mut() {
|
fn test_shared_as_mut() {
|
||||||
shared s := St{ a: 5 }
|
shared s := St{ a: 5 }
|
||||||
shared a := [3, 4, 6, 13, -23]
|
shared a := [3, 4, 6, 13, -23]
|
||||||
shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625}
|
shared m := map{'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625}
|
||||||
shared r := Qr{ a: 7 }
|
shared r := Qr{ a: 7 }
|
||||||
lock s {
|
lock s {
|
||||||
r.s_mut(mut s)
|
r.s_mut(mut s)
|
||||||
|
|
|
@ -1,14 +1,7 @@
|
||||||
vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv:5:4: error: mismatched types `&Foo` and `Foo`
|
vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv:5:4: error: mismatched types `&Foo` and `Foo`
|
||||||
3 | fn main() {
|
3 | fn main() {
|
||||||
4 | mut f := &Foo{ 10 }
|
4 | mut f := &Foo{ 10 }
|
||||||
5 | f = { x: 223344 }
|
5 | f = Foo{ x: 20 }
|
||||||
| ^
|
| ^
|
||||||
6 | f = Foo{ x: 20 }
|
6 | _ = f
|
||||||
7 | _ = f
|
7 | }
|
||||||
vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv:6:4: error: mismatched types `&Foo` and `Foo`
|
|
||||||
4 | mut f := &Foo{ 10 }
|
|
||||||
5 | f = { x: 223344 }
|
|
||||||
6 | f = Foo{ x: 20 }
|
|
||||||
| ^
|
|
||||||
7 | _ = f
|
|
||||||
8 | }
|
|
|
@ -2,7 +2,6 @@ struct Foo { x int }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut f := &Foo{ 10 }
|
mut f := &Foo{ 10 }
|
||||||
f = { x: 223344 }
|
|
||||||
f = Foo{ x: 20 }
|
f = Foo{ x: 20 }
|
||||||
_ = f
|
_ = f
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,7 +271,7 @@ fn work_processor(mut work sync.Channel, mut results sync.Channel) {
|
||||||
if !work.pop(&task) {
|
if !work.pop(&task) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
sw := time.new_stopwatch({})
|
sw := time.new_stopwatch()
|
||||||
task.execute()
|
task.execute()
|
||||||
task.took = sw.elapsed()
|
task.took = sw.elapsed()
|
||||||
results.push(&task)
|
results.push(&task)
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub fn (mut f Fmt) attrs(attrs []ast.Attr) {
|
||||||
sorted_attrs.sort(a.arg.len > b.arg.len)
|
sorted_attrs.sort(a.arg.len > b.arg.len)
|
||||||
for i, attr in sorted_attrs {
|
for i, attr in sorted_attrs {
|
||||||
if attr.arg.len == 0 {
|
if attr.arg.len == 0 {
|
||||||
f.single_line_attrs(sorted_attrs[i..], {})
|
f.single_line_attrs(sorted_attrs[i..])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
f.writeln('[$attr]')
|
f.writeln('[$attr]')
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) {
|
||||||
out_s += s
|
out_s += s
|
||||||
}
|
}
|
||||||
if !is_separate_line && f.indent > 0 {
|
if !is_separate_line && f.indent > 0 {
|
||||||
f.remove_new_line({}) // delete the generated \n
|
f.remove_new_line() // delete the generated \n
|
||||||
f.write(' ')
|
f.write(' ')
|
||||||
}
|
}
|
||||||
f.write(out_s)
|
f.write(out_s)
|
||||||
|
@ -73,7 +73,7 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) {
|
||||||
if end_break {
|
if end_break {
|
||||||
f.empty_line = true
|
f.empty_line = true
|
||||||
} else {
|
} else {
|
||||||
f.remove_new_line({})
|
f.remove_new_line()
|
||||||
}
|
}
|
||||||
f.write('*/')
|
f.write('*/')
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,7 +267,7 @@ pub fn (mut f Fmt) imports(imports []ast.Import) {
|
||||||
already_imported[import_text] = true
|
already_imported[import_text] = true
|
||||||
f.out_imports.writeln(import_text)
|
f.out_imports.writeln(import_text)
|
||||||
f.import_comments(imp.comments, inline: true)
|
f.import_comments(imp.comments, inline: true)
|
||||||
f.import_comments(imp.next_comments, {})
|
f.import_comments(imp.next_comments)
|
||||||
num_imports++
|
num_imports++
|
||||||
}
|
}
|
||||||
if num_imports > 0 {
|
if num_imports > 0 {
|
||||||
|
@ -855,7 +855,7 @@ pub fn (mut f Fmt) assert_stmt(node ast.AssertStmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) assign_stmt(node ast.AssignStmt) {
|
pub fn (mut f Fmt) assign_stmt(node ast.AssignStmt) {
|
||||||
f.comments(node.comments, {})
|
f.comments(node.comments)
|
||||||
for i, left in node.left {
|
for i, left in node.left {
|
||||||
f.expr(left)
|
f.expr(left)
|
||||||
if i < node.left.len - 1 {
|
if i < node.left.len - 1 {
|
||||||
|
@ -989,7 +989,7 @@ pub fn (mut f Fmt) defer_stmt(node ast.DeferStmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) expr_stmt(node ast.ExprStmt) {
|
pub fn (mut f Fmt) expr_stmt(node ast.ExprStmt) {
|
||||||
f.comments(node.comments, {})
|
f.comments(node.comments)
|
||||||
f.expr(node.expr)
|
f.expr(node.expr)
|
||||||
if !f.single_line_if {
|
if !f.single_line_if {
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
|
@ -1060,7 +1060,7 @@ pub fn (mut f Fmt) for_c_stmt(node ast.ForCStmt) {
|
||||||
f.expr(node.cond)
|
f.expr(node.cond)
|
||||||
f.write('; ')
|
f.write('; ')
|
||||||
f.stmt(node.inc)
|
f.stmt(node.inc)
|
||||||
f.remove_new_line({})
|
f.remove_new_line()
|
||||||
f.write(' {')
|
f.write(' {')
|
||||||
if node.stmts.len > 0 || node.pos.line_nr < node.pos.last_line {
|
if node.stmts.len > 0 || node.pos.line_nr < node.pos.last_line {
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
|
@ -1240,7 +1240,7 @@ pub fn (mut f Fmt) mod(mod ast.Module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) return_stmt(node ast.Return) {
|
pub fn (mut f Fmt) return_stmt(node ast.Return) {
|
||||||
f.comments(node.comments, {})
|
f.comments(node.comments)
|
||||||
f.write('return')
|
f.write('return')
|
||||||
if node.exprs.len > 0 {
|
if node.exprs.len > 0 {
|
||||||
f.write(' ')
|
f.write(' ')
|
||||||
|
@ -1643,7 +1643,7 @@ pub fn (mut f Fmt) at_expr(node ast.AtExpr) {
|
||||||
|
|
||||||
pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
|
pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
|
||||||
for arg in node.args {
|
for arg in node.args {
|
||||||
f.comments(arg.comments, {})
|
f.comments(arg.comments)
|
||||||
}
|
}
|
||||||
if node.is_method {
|
if node.is_method {
|
||||||
if node.name in ['map', 'filter'] {
|
if node.name in ['map', 'filter'] {
|
||||||
|
@ -1882,12 +1882,12 @@ pub fn (mut f Fmt) if_expr(node ast.IfExpr) {
|
||||||
for i, branch in node.branches {
|
for i, branch in node.branches {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
// first `if`
|
// first `if`
|
||||||
f.comments(branch.comments, {})
|
f.comments(branch.comments)
|
||||||
} else {
|
} else {
|
||||||
// `else`, close previous branch
|
// `else`, close previous branch
|
||||||
if branch.comments.len > 0 {
|
if branch.comments.len > 0 {
|
||||||
f.writeln('}')
|
f.writeln('}')
|
||||||
f.comments(branch.comments, {})
|
f.comments(branch.comments)
|
||||||
} else {
|
} else {
|
||||||
f.write('} ')
|
f.write('} ')
|
||||||
}
|
}
|
||||||
|
@ -2070,7 +2070,7 @@ fn (mut f Fmt) write_splitted_infix(conditions []string, penalties []int, ignore
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
f.remove_new_line({})
|
f.remove_new_line()
|
||||||
}
|
}
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
f.indent++
|
f.indent++
|
||||||
|
@ -2151,7 +2151,7 @@ pub fn (mut f Fmt) map_init(node ast.MapInit) {
|
||||||
}
|
}
|
||||||
f.writeln('map{')
|
f.writeln('map{')
|
||||||
f.indent++
|
f.indent++
|
||||||
f.comments(node.pre_cmnts, {})
|
f.comments(node.pre_cmnts)
|
||||||
mut max_field_len := 0
|
mut max_field_len := 0
|
||||||
for key in node.keys {
|
for key in node.keys {
|
||||||
if key.str().len > max_field_len {
|
if key.str().len > max_field_len {
|
||||||
|
@ -2177,7 +2177,7 @@ fn (mut f Fmt) match_branch(branch ast.MatchBranch, single_line bool) {
|
||||||
for j, expr in branch.exprs {
|
for j, expr in branch.exprs {
|
||||||
estr := f.node_str(expr).trim_space()
|
estr := f.node_str(expr).trim_space()
|
||||||
if f.line_len + estr.len + 2 > fmt.max_len[5] {
|
if f.line_len + estr.len + 2 > fmt.max_len[5] {
|
||||||
f.remove_new_line({})
|
f.remove_new_line()
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
}
|
}
|
||||||
f.write(estr)
|
f.write(estr)
|
||||||
|
@ -2204,7 +2204,7 @@ fn (mut f Fmt) match_branch(branch ast.MatchBranch, single_line bool) {
|
||||||
}
|
}
|
||||||
f.stmts(branch.stmts)
|
f.stmts(branch.stmts)
|
||||||
if single_line {
|
if single_line {
|
||||||
f.remove_new_line({})
|
f.remove_new_line()
|
||||||
f.writeln(' }')
|
f.writeln(' }')
|
||||||
} else {
|
} else {
|
||||||
f.writeln('}')
|
f.writeln('}')
|
||||||
|
@ -2221,7 +2221,7 @@ pub fn (mut f Fmt) match_expr(node ast.MatchExpr) {
|
||||||
}
|
}
|
||||||
f.writeln(' {')
|
f.writeln(' {')
|
||||||
f.indent++
|
f.indent++
|
||||||
f.comments(node.comments, {})
|
f.comments(node.comments)
|
||||||
mut single_line := true
|
mut single_line := true
|
||||||
for branch in node.branches {
|
for branch in node.branches {
|
||||||
if branch.stmts.len > 1 || branch.pos.line_nr < branch.pos.last_line {
|
if branch.stmts.len > 1 || branch.pos.line_nr < branch.pos.last_line {
|
||||||
|
|
|
@ -354,7 +354,7 @@ pub fn (mut f Fmt) struct_init(node ast.StructInit) {
|
||||||
single_line_fields = false
|
single_line_fields = false
|
||||||
f.out.go_back_to(fields_start)
|
f.out.go_back_to(fields_start)
|
||||||
f.line_len = fields_start
|
f.line_len = fields_start
|
||||||
f.remove_new_line({})
|
f.remove_new_line()
|
||||||
continue fields_loop
|
continue fields_loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ fn main() {
|
||||||
y: 0
|
y: 0
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
bar2_func({}, {})
|
bar2_func({})
|
||||||
bar2_func({ x: 's' },
|
bar2_func({ x: 's' },
|
||||||
x: 's'
|
x: 's'
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,7 +16,7 @@ fn main() {
|
||||||
x: 0
|
x: 0
|
||||||
y: 0
|
y: 0
|
||||||
})
|
})
|
||||||
bar2_func({}, {})
|
bar2_func({})
|
||||||
bar2_func({x: 's'}, {x: 's'})
|
bar2_func({x: 's'}, {x: 's'})
|
||||||
baz_func('foo', 'bar', x: 0
|
baz_func('foo', 'bar', x: 0
|
||||||
y: 0
|
y: 0
|
||||||
|
|
|
@ -89,7 +89,7 @@ fn test_select_blocks() {
|
||||||
a: 13
|
a: 13
|
||||||
}
|
}
|
||||||
sem.wait()
|
sem.wait()
|
||||||
stopwatch := time.new_stopwatch({})
|
stopwatch := time.new_stopwatch()
|
||||||
go f1(ch1, ch2, ch3, ch4, ch5, sem)
|
go f1(ch1, ch2, ch3, ch4, ch5, sem)
|
||||||
sem.wait()
|
sem.wait()
|
||||||
elapsed_ms := f64(stopwatch.elapsed()) / time.millisecond
|
elapsed_ms := f64(stopwatch.elapsed()) / time.millisecond
|
||||||
|
|
|
@ -6359,7 +6359,7 @@ static inline $interface_name I_${cctype}_to_Interface_${interface_name}($cctype
|
||||||
params_start_pos := g.out.len
|
params_start_pos := g.out.len
|
||||||
mut params := method.params.clone()
|
mut params := method.params.clone()
|
||||||
// hack to mutate typ
|
// hack to mutate typ
|
||||||
params[0] = {
|
params[0] = ast.Param{
|
||||||
...params[0]
|
...params[0]
|
||||||
typ: params[0].typ.set_nr_muls(1)
|
typ: params[0].typ.set_nr_muls(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ mut:
|
||||||
fn new_mappings() Mappings {
|
fn new_mappings() Mappings {
|
||||||
return Mappings{
|
return Mappings{
|
||||||
last: Mapping{
|
last: Mapping{
|
||||||
GenPosition: {
|
GenPosition: GenPosition{
|
||||||
gen_column: 0
|
gen_column: 0
|
||||||
gen_line: 0
|
gen_line: 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ fn elog(r &live.LiveReloadInfo, s string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_and_reload_shared_lib(mut r live.LiveReloadInfo) ?bool {
|
fn compile_and_reload_shared_lib(mut r live.LiveReloadInfo) ?bool {
|
||||||
sw := time.new_stopwatch({})
|
sw := time.new_stopwatch()
|
||||||
new_lib_path := compile_lib(mut r) or { return error('errors while compiling $r.original') }
|
new_lib_path := compile_lib(mut r) or { return error('errors while compiling $r.original') }
|
||||||
elog(r, '> compile_and_reload_shared_lib compiled: $new_lib_path')
|
elog(r, '> compile_and_reload_shared_lib compiled: $new_lib_path')
|
||||||
load_lib(mut r, new_lib_path)
|
load_lib(mut r, new_lib_path)
|
||||||
|
@ -68,7 +68,7 @@ fn compile_lib(mut r live.LiveReloadInfo) ?string {
|
||||||
new_lib_path, new_lib_path_with_extension := current_shared_library_path(mut r)
|
new_lib_path, new_lib_path_with_extension := current_shared_library_path(mut r)
|
||||||
cmd := '$r.vexe $r.vopts -o $new_lib_path $r.original'
|
cmd := '$r.vexe $r.vopts -o $new_lib_path $r.original'
|
||||||
elog(r, '> compilation cmd: $cmd')
|
elog(r, '> compilation cmd: $cmd')
|
||||||
cwatch := time.new_stopwatch({})
|
cwatch := time.new_stopwatch()
|
||||||
recompilation_result := os.execute(cmd)
|
recompilation_result := os.execute(cmd)
|
||||||
elog(r, 'compilation took: ${cwatch.elapsed().milliseconds()}ms')
|
elog(r, 'compilation took: ${cwatch.elapsed().milliseconds()}ms')
|
||||||
if recompilation_result.exit_code != 0 {
|
if recompilation_result.exit_code != 0 {
|
||||||
|
|
|
@ -128,7 +128,7 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme
|
||||||
p.next()
|
p.next()
|
||||||
mut comments := []ast.Comment{cap: 2 * left_comments.len + 1}
|
mut comments := []ast.Comment{cap: 2 * left_comments.len + 1}
|
||||||
comments << left_comments
|
comments << left_comments
|
||||||
comments << p.eat_comments({})
|
comments << p.eat_comments()
|
||||||
mut right_comments := []ast.Comment{}
|
mut right_comments := []ast.Comment{}
|
||||||
mut right := []ast.Expr{cap: left.len}
|
mut right := []ast.Expr{cap: left.len}
|
||||||
right, right_comments = p.expr_list()
|
right, right_comments = p.expr_list()
|
||||||
|
|
|
@ -45,14 +45,14 @@ fn (mut p Parser) array_init() ast.ArrayInit {
|
||||||
// [1,2,3] or [const]byte
|
// [1,2,3] or [const]byte
|
||||||
old_inside_array_lit := p.inside_array_lit
|
old_inside_array_lit := p.inside_array_lit
|
||||||
p.inside_array_lit = true
|
p.inside_array_lit = true
|
||||||
pre_cmnts = p.eat_comments({})
|
pre_cmnts = p.eat_comments()
|
||||||
for i := 0; p.tok.kind !in [.rsbr, .eof]; i++ {
|
for i := 0; p.tok.kind !in [.rsbr, .eof]; i++ {
|
||||||
exprs << p.expr(0)
|
exprs << p.expr(0)
|
||||||
ecmnts << p.eat_comments({})
|
ecmnts << p.eat_comments()
|
||||||
if p.tok.kind == .comma {
|
if p.tok.kind == .comma {
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
ecmnts.last() << p.eat_comments({})
|
ecmnts.last() << p.eat_comments()
|
||||||
}
|
}
|
||||||
p.inside_array_lit = old_inside_array_lit
|
p.inside_array_lit = old_inside_array_lit
|
||||||
line_nr := p.tok.line_nr
|
line_nr := p.tok.line_nr
|
||||||
|
@ -168,7 +168,7 @@ fn (mut p Parser) map_init() ast.MapInit {
|
||||||
mut keys := []ast.Expr{}
|
mut keys := []ast.Expr{}
|
||||||
mut vals := []ast.Expr{}
|
mut vals := []ast.Expr{}
|
||||||
mut comments := [][]ast.Comment{}
|
mut comments := [][]ast.Comment{}
|
||||||
pre_cmnts := p.eat_comments({})
|
pre_cmnts := p.eat_comments()
|
||||||
for p.tok.kind !in [.rcbr, .eof] {
|
for p.tok.kind !in [.rcbr, .eof] {
|
||||||
key := p.expr(0)
|
key := p.expr(0)
|
||||||
keys << key
|
keys << key
|
||||||
|
@ -178,7 +178,7 @@ fn (mut p Parser) map_init() ast.MapInit {
|
||||||
if p.tok.kind == .comma {
|
if p.tok.kind == .comma {
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
comments << p.eat_comments({})
|
comments << p.eat_comments()
|
||||||
}
|
}
|
||||||
return ast.MapInit{
|
return ast.MapInit{
|
||||||
keys: keys
|
keys: keys
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
|
||||||
is_stmt_ident := p.is_stmt_ident
|
is_stmt_ident := p.is_stmt_ident
|
||||||
p.is_stmt_ident = false
|
p.is_stmt_ident = false
|
||||||
if !p.pref.is_fmt {
|
if !p.pref.is_fmt {
|
||||||
p.eat_comments({})
|
p.eat_comments()
|
||||||
}
|
}
|
||||||
inside_array_lit := p.inside_array_lit
|
inside_array_lit := p.inside_array_lit
|
||||||
p.inside_array_lit = false
|
p.inside_array_lit = false
|
||||||
|
@ -297,18 +297,23 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.lcbr {
|
.lcbr {
|
||||||
|
// TODO: remove this when deprecation will be removed, vfmt should handle it for a while
|
||||||
// Map `{"age": 20}` or `{ x | foo:bar, a:10 }`
|
// Map `{"age": 20}` or `{ x | foo:bar, a:10 }`
|
||||||
p.next()
|
p.next()
|
||||||
if p.tok.kind in [.chartoken, .number, .string] {
|
if p.tok.kind in [.chartoken, .number, .string] {
|
||||||
// TODO deprecate
|
p.warn_with_pos("deprecated map syntax, use syntax like `map{'age': 20}`",
|
||||||
|
p.prev_tok.position())
|
||||||
node = p.map_init()
|
node = p.map_init()
|
||||||
} else {
|
} else {
|
||||||
// it should be a struct
|
// it should be a struct
|
||||||
if p.tok.kind == .name && p.peek_tok.kind == .pipe {
|
if p.tok.kind == .name && p.peek_tok.kind == .pipe {
|
||||||
|
// TODO: remove deprecated
|
||||||
p.warn_with_pos('use e.g. `...struct_var` instead', p.peek_tok.position())
|
p.warn_with_pos('use e.g. `...struct_var` instead', p.peek_tok.position())
|
||||||
node = p.assoc()
|
node = p.assoc()
|
||||||
} else if (p.tok.kind == .name && p.peek_tok.kind == .colon)
|
} else if (p.tok.kind == .name && p.peek_tok.kind == .colon)
|
||||||
|| p.tok.kind in [.rcbr, .comment, .ellipsis] {
|
|| p.tok.kind in [.rcbr, .comment, .ellipsis] {
|
||||||
|
p.warn_with_pos('short struct initalization is deprecated, use explicit struct name',
|
||||||
|
p.prev_tok.position())
|
||||||
node = p.struct_init(true) // short_syntax: true
|
node = p.struct_init(true) // short_syntax: true
|
||||||
} else if p.tok.kind == .name {
|
} else if p.tok.kind == .name {
|
||||||
p.next()
|
p.next()
|
||||||
|
|
|
@ -124,7 +124,7 @@ pub fn (mut p Parser) call_args() []ast.CallArg {
|
||||||
if is_mut {
|
if is_mut {
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
mut comments := p.eat_comments({})
|
mut comments := p.eat_comments()
|
||||||
arg_start_pos := p.tok.position()
|
arg_start_pos := p.tok.position()
|
||||||
mut array_decompose := false
|
mut array_decompose := false
|
||||||
if p.tok.kind == .ellipsis {
|
if p.tok.kind == .ellipsis {
|
||||||
|
@ -149,7 +149,7 @@ pub fn (mut p Parser) call_args() []ast.CallArg {
|
||||||
comments = []ast.Comment{}
|
comments = []ast.Comment{}
|
||||||
}
|
}
|
||||||
pos := arg_start_pos.extend(p.prev_tok.position())
|
pos := arg_start_pos.extend(p.prev_tok.position())
|
||||||
comments << p.eat_comments({})
|
comments << p.eat_comments()
|
||||||
args << ast.CallArg{
|
args << ast.CallArg{
|
||||||
is_mut: is_mut
|
is_mut: is_mut
|
||||||
share: ast.sharetype_from_flags(is_shared, is_atomic)
|
share: ast.sharetype_from_flags(is_shared, is_atomic)
|
||||||
|
|
|
@ -33,9 +33,9 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr {
|
||||||
p.tok.position()
|
p.tok.position()
|
||||||
}
|
}
|
||||||
if p.tok.kind == .key_else {
|
if p.tok.kind == .key_else {
|
||||||
comments << p.eat_comments({})
|
comments << p.eat_comments()
|
||||||
p.check(.key_else)
|
p.check(.key_else)
|
||||||
comments << p.eat_comments({})
|
comments << p.eat_comments()
|
||||||
if p.tok.kind == .key_match {
|
if p.tok.kind == .key_match {
|
||||||
p.error('cannot use `match` with `if` statements')
|
p.error('cannot use `match` with `if` statements')
|
||||||
return ast.IfExpr{}
|
return ast.IfExpr{}
|
||||||
|
@ -78,7 +78,7 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr {
|
||||||
p.error('cannot use `match` with `if` statements')
|
p.error('cannot use `match` with `if` statements')
|
||||||
return ast.IfExpr{}
|
return ast.IfExpr{}
|
||||||
}
|
}
|
||||||
comments << p.eat_comments({})
|
comments << p.eat_comments()
|
||||||
mut cond := ast.empty_expr()
|
mut cond := ast.empty_expr()
|
||||||
mut is_guard := false
|
mut is_guard := false
|
||||||
// `if x := opt() {`
|
// `if x := opt() {`
|
||||||
|
@ -90,9 +90,9 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr {
|
||||||
if p.scope.known_var(var_name) {
|
if p.scope.known_var(var_name) {
|
||||||
p.error_with_pos('redefinition of `$var_name`', var_pos)
|
p.error_with_pos('redefinition of `$var_name`', var_pos)
|
||||||
}
|
}
|
||||||
comments << p.eat_comments({})
|
comments << p.eat_comments()
|
||||||
p.check(.decl_assign)
|
p.check(.decl_assign)
|
||||||
comments << p.eat_comments({})
|
comments << p.eat_comments()
|
||||||
expr := p.expr(0)
|
expr := p.expr(0)
|
||||||
cond = ast.IfGuardExpr{
|
cond = ast.IfGuardExpr{
|
||||||
var_name: var_name
|
var_name: var_name
|
||||||
|
@ -110,7 +110,7 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr {
|
||||||
cond = p.expr(0)
|
cond = p.expr(0)
|
||||||
p.comp_if_cond = false
|
p.comp_if_cond = false
|
||||||
}
|
}
|
||||||
comments << p.eat_comments({})
|
comments << p.eat_comments()
|
||||||
end_pos := p.prev_tok.position()
|
end_pos := p.prev_tok.position()
|
||||||
body_pos := p.tok.position()
|
body_pos := p.tok.position()
|
||||||
p.inside_if = false
|
p.inside_if = false
|
||||||
|
@ -128,7 +128,7 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr {
|
||||||
if is_guard {
|
if is_guard {
|
||||||
p.close_scope()
|
p.close_scope()
|
||||||
}
|
}
|
||||||
comments = p.eat_comments({})
|
comments = p.eat_comments()
|
||||||
if is_comptime {
|
if is_comptime {
|
||||||
if p.tok.kind == .key_else {
|
if p.tok.kind == .key_else {
|
||||||
p.error('use `\$else` instead of `else` in compile-time `if` branches')
|
p.error('use `\$else` instead of `else` in compile-time `if` branches')
|
||||||
|
@ -167,7 +167,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
|
||||||
if !no_lcbr {
|
if !no_lcbr {
|
||||||
p.check(.lcbr)
|
p.check(.lcbr)
|
||||||
}
|
}
|
||||||
comments := p.eat_comments({}) // comments before the first branch
|
comments := p.eat_comments() // comments before the first branch
|
||||||
mut branches := []ast.MatchBranch{}
|
mut branches := []ast.MatchBranch{}
|
||||||
for p.tok.kind != .eof {
|
for p.tok.kind != .eof {
|
||||||
branch_first_pos := p.tok.position()
|
branch_first_pos := p.tok.position()
|
||||||
|
@ -187,7 +187,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
|
||||||
for {
|
for {
|
||||||
// Sum type match
|
// Sum type match
|
||||||
parsed_type := p.parse_type()
|
parsed_type := p.parse_type()
|
||||||
ecmnts << p.eat_comments({})
|
ecmnts << p.eat_comments()
|
||||||
types << parsed_type
|
types << parsed_type
|
||||||
exprs << ast.TypeNode{
|
exprs << ast.TypeNode{
|
||||||
typ: parsed_type
|
typ: parsed_type
|
||||||
|
@ -204,7 +204,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
|
||||||
for {
|
for {
|
||||||
p.inside_match_case = true
|
p.inside_match_case = true
|
||||||
expr := p.expr(0)
|
expr := p.expr(0)
|
||||||
ecmnts << p.eat_comments({})
|
ecmnts << p.eat_comments()
|
||||||
p.inside_match_case = false
|
p.inside_match_case = false
|
||||||
if p.tok.kind == .dotdot {
|
if p.tok.kind == .dotdot {
|
||||||
p.error_with_pos('match only supports inclusive (`...`) ranges, not exclusive (`..`)',
|
p.error_with_pos('match only supports inclusive (`...`) ranges, not exclusive (`..`)',
|
||||||
|
@ -238,7 +238,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
|
||||||
p.inside_match_body = false
|
p.inside_match_body = false
|
||||||
pos := branch_first_pos.extend_with_last_line(branch_last_pos, p.prev_tok.line_nr)
|
pos := branch_first_pos.extend_with_last_line(branch_last_pos, p.prev_tok.line_nr)
|
||||||
branch_pos := branch_first_pos.extend_with_last_line(p.tok.position(), p.tok.line_nr)
|
branch_pos := branch_first_pos.extend_with_last_line(p.tok.position(), p.tok.line_nr)
|
||||||
post_comments := p.eat_comments({})
|
post_comments := p.eat_comments()
|
||||||
branches << ast.MatchBranch{
|
branches << ast.MatchBranch{
|
||||||
exprs: exprs
|
exprs: exprs
|
||||||
ecmnts: ecmnts
|
ecmnts: ecmnts
|
||||||
|
@ -408,7 +408,7 @@ fn (mut p Parser) select_expr() ast.SelectExpr {
|
||||||
len: branch_last_pos.pos - branch_first_pos.pos + branch_last_pos.len
|
len: branch_last_pos.pos - branch_first_pos.pos + branch_last_pos.len
|
||||||
col: branch_first_pos.col
|
col: branch_first_pos.col
|
||||||
}
|
}
|
||||||
post_comments := p.eat_comments({})
|
post_comments := p.eat_comments()
|
||||||
pos.update_last_line(p.prev_tok.line_nr)
|
pos.update_last_line(p.prev_tok.line_nr)
|
||||||
if post_comments.len > 0 {
|
if post_comments.len > 0 {
|
||||||
pos.last_line = post_comments.last().pos.last_line
|
pos.last_line = post_comments.last().pos.last_line
|
||||||
|
|
|
@ -2830,7 +2830,7 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
|
||||||
mut fields := []ast.ConstField{}
|
mut fields := []ast.ConstField{}
|
||||||
mut comments := []ast.Comment{}
|
mut comments := []ast.Comment{}
|
||||||
for {
|
for {
|
||||||
comments = p.eat_comments({})
|
comments = p.eat_comments()
|
||||||
if is_block && p.tok.kind == .eof {
|
if is_block && p.tok.kind == .eof {
|
||||||
p.error('unexpected eof, expecting ´)´')
|
p.error('unexpected eof, expecting ´)´')
|
||||||
return ast.ConstDecl{}
|
return ast.ConstDecl{}
|
||||||
|
@ -2887,7 +2887,7 @@ fn (mut p Parser) return_stmt() ast.Return {
|
||||||
first_pos := p.tok.position()
|
first_pos := p.tok.position()
|
||||||
p.next()
|
p.next()
|
||||||
// no return
|
// no return
|
||||||
mut comments := p.eat_comments({})
|
mut comments := p.eat_comments()
|
||||||
if p.tok.kind == .rcbr {
|
if p.tok.kind == .rcbr {
|
||||||
return ast.Return{
|
return ast.Return{
|
||||||
comments: comments
|
comments: comments
|
||||||
|
@ -2926,7 +2926,7 @@ fn (mut p Parser) global_decl() ast.GlobalDecl {
|
||||||
mut fields := []ast.GlobalField{}
|
mut fields := []ast.GlobalField{}
|
||||||
mut comments := []ast.Comment{}
|
mut comments := []ast.Comment{}
|
||||||
for {
|
for {
|
||||||
comments = p.eat_comments({})
|
comments = p.eat_comments()
|
||||||
if is_block && p.tok.kind == .eof {
|
if is_block && p.tok.kind == .eof {
|
||||||
p.error('unexpected eof, expecting ´)´')
|
p.error('unexpected eof, expecting ´)´')
|
||||||
return ast.GlobalDecl{}
|
return ast.GlobalDecl{}
|
||||||
|
@ -3005,7 +3005,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
|
||||||
}
|
}
|
||||||
name := p.prepend_mod(enum_name)
|
name := p.prepend_mod(enum_name)
|
||||||
p.check(.lcbr)
|
p.check(.lcbr)
|
||||||
enum_decl_comments := p.eat_comments({})
|
enum_decl_comments := p.eat_comments()
|
||||||
mut vals := []string{}
|
mut vals := []string{}
|
||||||
// mut default_exprs := []ast.Expr{}
|
// mut default_exprs := []ast.Expr{}
|
||||||
mut fields := []ast.EnumField{}
|
mut fields := []ast.EnumField{}
|
||||||
|
@ -3027,7 +3027,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
|
||||||
expr: expr
|
expr: expr
|
||||||
has_expr: has_expr
|
has_expr: has_expr
|
||||||
comments: p.eat_comments(same_line: true)
|
comments: p.eat_comments(same_line: true)
|
||||||
next_comments: p.eat_comments({})
|
next_comments: p.eat_comments()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.top_level_statement_end()
|
p.top_level_statement_end()
|
||||||
|
@ -3132,7 +3132,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
|
||||||
mut type_end_pos := p.prev_tok.position()
|
mut type_end_pos := p.prev_tok.position()
|
||||||
type_pos = type_pos.extend(type_end_pos)
|
type_pos = type_pos.extend(type_end_pos)
|
||||||
p.next()
|
p.next()
|
||||||
sum_variants << {
|
sum_variants << ast.TypeNode{
|
||||||
typ: first_type
|
typ: first_type
|
||||||
pos: type_pos
|
pos: type_pos
|
||||||
}
|
}
|
||||||
|
@ -3144,7 +3144,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
|
||||||
prev_tok := p.prev_tok
|
prev_tok := p.prev_tok
|
||||||
type_end_pos = prev_tok.position()
|
type_end_pos = prev_tok.position()
|
||||||
type_pos = type_pos.extend(type_end_pos)
|
type_pos = type_pos.extend(type_end_pos)
|
||||||
sum_variants << {
|
sum_variants << ast.TypeNode{
|
||||||
typ: variant_type
|
typ: variant_type
|
||||||
pos: type_pos
|
pos: type_pos
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
||||||
} else if p.tok.kind == .key_module {
|
} else if p.tok.kind == .key_module {
|
||||||
if module_pos != -1 {
|
if module_pos != -1 {
|
||||||
p.error('redefinition of `module` section')
|
p.error('redefinition of `module` section')
|
||||||
return {}
|
return ast.StructDecl{}
|
||||||
}
|
}
|
||||||
p.next()
|
p.next()
|
||||||
p.check(.colon)
|
p.check(.colon)
|
||||||
|
@ -181,7 +181,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
||||||
// struct embedding
|
// struct embedding
|
||||||
type_pos = p.tok.position()
|
type_pos = p.tok.position()
|
||||||
typ = p.parse_type()
|
typ = p.parse_type()
|
||||||
ecomments := p.eat_comments({})
|
ecomments := p.eat_comments()
|
||||||
type_pos = type_pos.extend(p.prev_tok.position())
|
type_pos = type_pos.extend(p.prev_tok.position())
|
||||||
if !is_on_top {
|
if !is_on_top {
|
||||||
p.error_with_pos('struct embedding must be declared at the beginning of the struct body',
|
p.error_with_pos('struct embedding must be declared at the beginning of the struct body',
|
||||||
|
@ -223,7 +223,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
||||||
field_pos = field_start_pos.extend(type_pos)
|
field_pos = field_start_pos.extend(type_pos)
|
||||||
}
|
}
|
||||||
// Comments after type (same line)
|
// Comments after type (same line)
|
||||||
comments << p.eat_comments({})
|
comments << p.eat_comments()
|
||||||
if p.tok.kind == .lsbr {
|
if p.tok.kind == .lsbr {
|
||||||
// attrs are stored in `p.attrs`
|
// attrs are stored in `p.attrs`
|
||||||
p.attributes()
|
p.attributes()
|
||||||
|
@ -241,7 +241,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
has_default_expr = true
|
has_default_expr = true
|
||||||
comments << p.eat_comments({})
|
comments << p.eat_comments()
|
||||||
}
|
}
|
||||||
ast_fields << ast.StructField{
|
ast_fields << ast.StructField{
|
||||||
name: field_name
|
name: field_name
|
||||||
|
@ -337,11 +337,10 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit {
|
||||||
if !short_syntax {
|
if !short_syntax {
|
||||||
p.check(.lcbr)
|
p.check(.lcbr)
|
||||||
}
|
}
|
||||||
pre_comments := p.eat_comments({})
|
pre_comments := p.eat_comments()
|
||||||
mut fields := []ast.StructInitField{}
|
mut fields := []ast.StructInitField{}
|
||||||
mut i := 0
|
mut i := 0
|
||||||
no_keys := p.peek_tok.kind != .colon && p.tok.kind != .rcbr && p.tok.kind != .ellipsis // `Vec{a,b,c}
|
no_keys := p.peek_tok.kind != .colon && p.tok.kind != .rcbr && p.tok.kind != .ellipsis // `Vec{a,b,c}
|
||||||
// p.warn(is_short_syntax.str())
|
|
||||||
saved_is_amp := p.is_amp
|
saved_is_amp := p.is_amp
|
||||||
p.is_amp = false
|
p.is_amp = false
|
||||||
mut update_expr := ast.empty_expr()
|
mut update_expr := ast.empty_expr()
|
||||||
|
@ -391,7 +390,7 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit {
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
comments << p.eat_comments(same_line: true)
|
comments << p.eat_comments(same_line: true)
|
||||||
nline_comments << p.eat_comments({})
|
nline_comments << p.eat_comments()
|
||||||
if !is_update_expr {
|
if !is_update_expr {
|
||||||
fields << ast.StructInitField{
|
fields << ast.StructInitField{
|
||||||
name: field_name
|
name: field_name
|
||||||
|
@ -448,7 +447,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
||||||
generic_types := p.parse_generic_type_list()
|
generic_types := p.parse_generic_type_list()
|
||||||
// println('interface decl $interface_name')
|
// println('interface decl $interface_name')
|
||||||
p.check(.lcbr)
|
p.check(.lcbr)
|
||||||
pre_comments := p.eat_comments({})
|
pre_comments := p.eat_comments()
|
||||||
if modless_name in p.imported_symbols {
|
if modless_name in p.imported_symbols {
|
||||||
p.error_with_pos('cannot register interface `$interface_name`, this type was already imported',
|
p.error_with_pos('cannot register interface `$interface_name`, this type was already imported',
|
||||||
name_pos)
|
name_pos)
|
||||||
|
@ -488,7 +487,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
||||||
iface_pos := p.tok.position()
|
iface_pos := p.tok.position()
|
||||||
iface_name := p.tok.lit
|
iface_name := p.tok.lit
|
||||||
iface_type := p.parse_type()
|
iface_type := p.parse_type()
|
||||||
comments := p.eat_comments({})
|
comments := p.eat_comments()
|
||||||
ifaces << ast.InterfaceEmbedding{
|
ifaces << ast.InterfaceEmbedding{
|
||||||
name: iface_name
|
name: iface_name
|
||||||
typ: iface_type
|
typ: iface_type
|
||||||
|
@ -503,7 +502,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
||||||
if p.tok.kind == .key_mut {
|
if p.tok.kind == .key_mut {
|
||||||
if is_mut {
|
if is_mut {
|
||||||
p.error_with_pos('redefinition of `mut` section', p.tok.position())
|
p.error_with_pos('redefinition of `mut` section', p.tok.position())
|
||||||
return {}
|
return ast.InterfaceDecl{}
|
||||||
}
|
}
|
||||||
p.next()
|
p.next()
|
||||||
p.check(.colon)
|
p.check(.colon)
|
||||||
|
@ -554,7 +553,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
||||||
method.pos = method.pos.extend(method.return_type_pos)
|
method.pos = method.pos.extend(method.return_type_pos)
|
||||||
}
|
}
|
||||||
mcomments := p.eat_comments(same_line: true)
|
mcomments := p.eat_comments(same_line: true)
|
||||||
mnext_comments := p.eat_comments({})
|
mnext_comments := p.eat_comments()
|
||||||
method.comments = mcomments
|
method.comments = mcomments
|
||||||
method.next_comments = mnext_comments
|
method.next_comments = mnext_comments
|
||||||
methods << method
|
methods << method
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
vlib/v/parser/tests/anon_fn_return_type.vv:7:22: error: expected return type, not string `hi` for anonymous function
|
vlib/v/parser/tests/anon_fn_return_type.vv:7:22: error: expected return type, not string `hi` for anonymous function
|
||||||
5 | _ = fn (name string) flag.Flag
|
5 | _ = fn (name string) flag.Flag
|
||||||
6 | _ = fn (name string) flag.Flag {return {}}
|
6 | _ = fn (name string) flag.Flag {return flag.Flag{}}
|
||||||
7 | _ = fn (name string) "hi" + name
|
7 | _ = fn (name string) "hi" + name
|
||||||
| ~~~~
|
| ~~~~
|
||||||
8 |
|
8 |
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import flag
|
import flag
|
||||||
|
|
||||||
_ = fn (name string)
|
_ = fn (name string)
|
||||||
_ = fn (name string) {}
|
_ = fn (name string) {}
|
||||||
_ = fn (name string) flag.Flag
|
_ = fn (name string) flag.Flag
|
||||||
_ = fn (name string) flag.Flag {return {}}
|
_ = fn (name string) flag.Flag {return flag.Flag{}}
|
||||||
_ = fn (name string) "hi" + name
|
_ = fn (name string) "hi" + name
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
vlib/v/parser/tests/for_in_mut_key_of_map.vv:3:6: error: index of array or key of map cannot be mutated
|
vlib/v/parser/tests/for_in_mut_key_of_map.vv:3:6: error: index of array or key of map cannot be mutated
|
||||||
1 | fn main() {
|
1 | fn main() {
|
||||||
2 | mut m := {'foo': 1, 'bar': 2}
|
2 | mut m := map{'foo': 1, 'bar': 2}
|
||||||
3 | for mut k, _ in m {
|
3 | for mut k, _ in m {
|
||||||
| ~~~
|
| ~~~
|
||||||
4 | println(k)
|
4 | println(k)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
mut m := {'foo': 1, 'bar': 2}
|
mut m := map{'foo': 1, 'bar': 2}
|
||||||
for mut k, _ in m {
|
for mut k, _ in m {
|
||||||
println(k)
|
println(k)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ fn test_array_or() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_map_or() {
|
fn test_map_or() {
|
||||||
m := {
|
m := map{
|
||||||
'as': 3
|
'as': 3
|
||||||
'qw': 4
|
'qw': 4
|
||||||
'kl': 5
|
'kl': 5
|
||||||
|
|
|
@ -33,10 +33,10 @@ fn f_compiles2(d Data) []Data {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_match_in_fn_call() {
|
fn test_match_in_fn_call() {
|
||||||
println(f_doesnotcompile({}))
|
println(f_doesnotcompile())
|
||||||
assert f_doesnotcompile({}) == []Data{}
|
assert f_doesnotcompile() == []Data{}
|
||||||
println(f_compiles1({}))
|
println(f_compiles1())
|
||||||
assert f_compiles1({}) == []Data{}
|
assert f_compiles1() == []Data{}
|
||||||
println(f_compiles2({}))
|
println(f_compiles2())
|
||||||
assert f_compiles2({}) == []Data{}
|
assert f_compiles2() == []Data{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ fn test_semaphore() {
|
||||||
unsafe { abc[0]-- }
|
unsafe { abc[0]-- }
|
||||||
}
|
}
|
||||||
// wait for the 2 coroutines to finish using the semaphore
|
// wait for the 2 coroutines to finish using the semaphore
|
||||||
stopwatch := time.new_stopwatch({})
|
stopwatch := time.new_stopwatch()
|
||||||
mut elapsed := stopwatch.elapsed()
|
mut elapsed := stopwatch.elapsed()
|
||||||
if !sem.timed_wait(200 * time.millisecond) {
|
if !sem.timed_wait(200 * time.millisecond) {
|
||||||
// we should come here due to timeout
|
// we should come here due to timeout
|
||||||
|
|
|
@ -274,7 +274,7 @@ fn test_struct_literal_args() {
|
||||||
n: 10
|
n: 10
|
||||||
def: 20
|
def: 20
|
||||||
)
|
)
|
||||||
foo_config(10, {})
|
foo_config(10)
|
||||||
foo_config(10, n: 40)
|
foo_config(10, n: 40)
|
||||||
foo_config(40, n: 30, def: 40)
|
foo_config(40, n: 30, def: 40)
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub fn (pos Position) extend(end Position) Position {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (pos Position) extend_with_last_line(end Position, last_line int) Position {
|
pub fn (pos Position) extend_with_last_line(end Position, last_line int) Position {
|
||||||
return {
|
return Position{
|
||||||
len: end.pos - pos.pos + end.len
|
len: end.pos - pos.pos + end.len
|
||||||
line_nr: pos.line_nr
|
line_nr: pos.line_nr
|
||||||
last_line: last_line - 1
|
last_line: last_line - 1
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub fn timing_set_should_print(should_print bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut t Timers) start(name string) {
|
pub fn (mut t Timers) start(name string) {
|
||||||
mut sw := t.swatches[name] or { time.new_stopwatch({}) }
|
mut sw := t.swatches[name] or { time.new_stopwatch() }
|
||||||
sw.start()
|
sw.start()
|
||||||
t.swatches[name] = sw
|
t.swatches[name] = sw
|
||||||
}
|
}
|
||||||
|
|
|
@ -616,7 +616,7 @@ fn (mut tf TTF_File) read_offset_tables() {
|
||||||
mut i := 0
|
mut i := 0
|
||||||
for i < num_tables {
|
for i < num_tables {
|
||||||
tag := tf.get_string(4)
|
tag := tf.get_string(4)
|
||||||
tf.tables[tag] = {
|
tf.tables[tag] = Offset_Table{
|
||||||
checksum: tf.get_u32()
|
checksum: tf.get_u32()
|
||||||
offset: tf.get_u32()
|
offset: tf.get_u32()
|
||||||
length: tf.get_u32()
|
length: tf.get_u32()
|
||||||
|
|
Loading…
Reference in New Issue