switch deprecation notice

pull/1755/head
Alexander Medvednikov 2019-08-27 01:25:37 +03:00
parent ab0a78a498
commit a43b831965
2 changed files with 21 additions and 15 deletions

View File

@ -727,15 +727,16 @@ fn new_v(args[]string) *V {
} }
} }
else { else {
switch target_os { _os = match target_os {
case 'linux': _os = .linux 'linux' => { OS.linux }
case 'windows': _os = .windows 'windows' => { OS.windows }
case 'mac': _os = .mac 'mac' => { OS.mac }
case 'freebsd': _os = .freebsd 'freebsd' => { OS.freebsd }
case 'openbsd': _os = .openbsd 'openbsd' => { OS.openbsd }
case 'netbsd': _os = .netbsd 'netbsd' => { OS.netbsd }
case 'dragonfly': _os = .dragonfly 'dragonfly' => { OS.dragonfly }
case 'msvc': _os = .msvc 'msvc' => { OS.msvc }
else => { OS.linux }
} }
} }
builtins := [ builtins := [

View File

@ -779,6 +779,10 @@ if p.scanner.line_comment != '' {
} }
} }
fn (p mut Parser) warn(s string) {
println('warning: $p.file_name:$p.scanner.line_nr ' + s)
}
fn (p mut Parser) error(s string) { fn (p mut Parser) error(s string) {
// Dump all vars and types for debugging // Dump all vars and types for debugging
if p.pref.is_debug { if p.pref.is_debug {
@ -2796,7 +2800,7 @@ fn (p mut Parser) array_init() string {
// Due to a tcc bug, the length needs to be specified. // Due to a tcc bug, the length needs to be specified.
// GCC crashes if it is. // GCC crashes if it is.
cast := if p.pref.ccompiler == 'tcc' { '($typ[$i])' } else { '($typ[])' } cast := if p.pref.ccompiler == 'tcc' { '($typ[$i])' } else { '($typ[])' }
p.cgen.set_placeholder(new_arr_ph, p.cgen.set_placeholder(new_arr_ph,
'$new_arr($i, $i, sizeof($typ), $cast { ') '$new_arr($i, $i, sizeof($typ), $cast { ')
//} //}
} }
@ -3292,6 +3296,7 @@ fn (p mut Parser) for_st() {
fn (p mut Parser) switch_statement() { fn (p mut Parser) switch_statement() {
if p.tok == .key_switch { if p.tok == .key_switch {
//p.warn('`switch` was replaced `match`, it will be removed soon')
p.check(.key_switch) p.check(.key_switch)
} else { } else {
p.check(.key_match) p.check(.key_match)
@ -3358,7 +3363,7 @@ fn (p mut Parser) switch_statement() {
p.returns = false // only get here when no default, so return is not guaranteed p.returns = false // only get here when no default, so return is not guaranteed
} }
// Returns typ if used as expession // Returns typ if used as expession
fn (p mut Parser) match_statement(is_expr bool) string { fn (p mut Parser) match_statement(is_expr bool) string {
p.check(.key_match) p.check(.key_match)
p.cgen.start_tmp() p.cgen.start_tmp()
@ -3373,7 +3378,7 @@ fn (p mut Parser) match_statement(is_expr bool) string {
mut i := 0 mut i := 0
mut all_cases_return := true mut all_cases_return := true
// stores typ of resulting variable // stores typ of resulting variable
mut res_typ := '' mut res_typ := ''
defer { defer {
@ -3381,8 +3386,8 @@ fn (p mut Parser) match_statement(is_expr bool) string {
} }
for p.tok != .rcbr { for p.tok != .rcbr {
if p.tok == .key_else { if p.tok == .key_else {
p.check(.key_else) p.check(.key_else)
p.check(.arrow) p.check(.arrow)
// unwrap match if there is only else // unwrap match if there is only else
@ -3467,7 +3472,7 @@ fn (p mut Parser) match_statement(is_expr bool) string {
p.gen(') || (') p.gen(') || (')
} }
if typ == 'string' { if typ == 'string' {
// TODO: use tmp variable // TODO: use tmp variable
// p.gen('string_eq($tmp_var, ') // p.gen('string_eq($tmp_var, ')
p.gen('string_eq($tmp_var, ') p.gen('string_eq($tmp_var, ')