Browse Source

Merge remote-tracking branch 'upstream/master'

master
Luna 2 years ago
parent
commit
a6984617aa
  1. 2
      compiler/cc.v
  2. 27
      compiler/main.v
  3. 23
      compiler/parser.v
  4. 30
      compiler/table.v

2
compiler/cc.v

@ -39,7 +39,7 @@ fn (v mut V) cc() {
else {
a << '-g'
}
if v.os != .msvc {
if v.os != .msvc && v.os != .freebsd {
a << '-Werror=implicit-function-declaration'
}

27
compiler/main.v

@ -83,7 +83,6 @@ mut:
is_prod bool // use "-O2"
is_verbose bool // print extra information with `v.log()`
obfuscate bool // `v -obf program.v`, renames functions to "f_XXX"
is_play bool // playground mode
is_repl bool
is_run bool
show_c_cmd bool // `v -show_c_cmd` prints the C command to build program.v.c
@ -212,9 +211,6 @@ fn (v mut V) compile() {
}
// Main pass
cgen.pass = Pass.main
if v.pref.is_play {
cgen.genln('#define VPLAY (1) ')
}
if v.pref.is_debug {
cgen.genln('#define VDEBUG (1) ')
}
@ -700,16 +696,15 @@ fn new_v(args[]string) *V {
}
}
else {
_os = match target_os {
'linux' => { OS.linux }
'windows' => { OS.windows }
'mac' => { OS.mac }
'freebsd' => { OS.freebsd }
'openbsd' => { OS.openbsd }
'netbsd' => { OS.netbsd }
'dragonfly' => { OS.dragonfly }
'msvc' => { OS.msvc }
else => { OS.linux }
switch target_os {
case 'linux': _os = .linux
case 'windows': _os = .windows
case 'mac': _os = .mac
case 'freebsd': _os = .freebsd
case 'openbsd': _os = .openbsd
case 'netbsd': _os = .netbsd
case 'dragonfly': _os = .dragonfly
case 'msvc': _os = .msvc
}
}
builtins := [
@ -758,7 +753,6 @@ fn new_v(args[]string) *V {
is_test: is_test
is_script: is_script
is_so: args.contains('-shared')
is_play: args.contains('play')
is_prod: args.contains('-prod')
is_verbose: args.contains('-verbose')
is_debuggable: args.contains('-g') // -debuggable implys debug
@ -779,9 +773,6 @@ fn new_v(args[]string) *V {
if pref.is_verbose || pref.is_debug {
println('C compiler=$pref.ccompiler')
}
if pref.is_play {
println('Playground')
}
if pref.is_so {
out_name_c = out_name.all_after('/') + '_shared_lib.c'
}

23
compiler/parser.v

@ -779,10 +779,6 @@ 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) {
// Dump all vars and types for debugging
if p.pref.is_debug {
@ -1458,11 +1454,6 @@ fn (p mut Parser) name_expr() string {
if ptr || deref {
p.next()
}
if deref {
if p.pref.is_play && !p.builtin_mod {
p.error('dereferencing is temporarily disabled on the playground, will be fixed soon')
}
}
mut name := p.lit
p.fgen(name)
// known_type := p.table.known_type(name)
@ -1840,7 +1831,6 @@ struct $typ.name {
}
if !p.builtin_mod && p.mod != typ.mod {
}
// if p.pref.is_play && field.access_mod ==.private && !p.builtin_mod && p.mod != typ.mod {
// Don't allow `arr.data`
if field.access_mod == .private && !p.builtin_mod && !p.pref.translated && p.mod != typ.mod {
// println('$typ.name :: $field.name ')
@ -2800,7 +2790,7 @@ fn (p mut Parser) array_init() string {
// Due to a tcc bug, the length needs to be specified.
// GCC crashes if it is.
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 { ')
//}
}
@ -3296,7 +3286,6 @@ fn (p mut Parser) for_st() {
fn (p mut Parser) switch_statement() {
if p.tok == .key_switch {
//p.warn('`switch` was replaced `match`, it will be removed soon')
p.check(.key_switch)
} else {
p.check(.key_match)
@ -3363,7 +3352,7 @@ fn (p mut Parser) switch_statement() {
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 {
p.check(.key_match)
p.cgen.start_tmp()
@ -3378,7 +3367,7 @@ fn (p mut Parser) match_statement(is_expr bool) string {
mut i := 0
mut all_cases_return := true
// stores typ of resulting variable
// stores typ of resulting variable
mut res_typ := ''
defer {
@ -3386,8 +3375,8 @@ fn (p mut Parser) match_statement(is_expr bool) string {
}
for p.tok != .rcbr {
if p.tok == .key_else {
p.check(.key_else)
if p.tok == .key_else {
p.check(.key_else)
p.check(.arrow)
// unwrap match if there is only else
@ -3472,7 +3461,7 @@ fn (p mut Parser) match_statement(is_expr bool) string {
p.gen(') || (')
}
if typ == 'string' {
if typ == 'string' {
// TODO: use tmp variable
// p.gen('string_eq($tmp_var, ')
p.gen('string_eq($tmp_var, ')

30
compiler/table.v

@ -531,10 +531,6 @@ fn (p mut Parser) _check_types(got_, expected_ string, throw bool) bool {
}
// Todo void* allows everything right now
if got=='void*' || expected=='void*' {// || got == 'cvoid' || expected == 'cvoid' {
// if !p.builtin_mod {
if p.pref.is_play {
return false
}
return true
}
// TODO only allow numeric consts to be assigned to bytes, and
@ -570,20 +566,18 @@ fn (p mut Parser) _check_types(got_, expected_ string, throw bool) bool {
return true
}
// NsColor* return 0
if !p.pref.is_play {
if expected.ends_with('*') && got == 'int' {
return true
}
// if got == 'T' || got.contains('<T>') {
// return true
// }
// if expected == 'T' || expected.contains('<T>') {
// return true
// }
// Allow pointer arithmetic
if expected=='void*' && got=='int' {
return true
}
if expected.ends_with('*') && got == 'int' {
return true
}
// if got == 'T' || got.contains('<T>') {
// return true
// }
// if expected == 'T' || expected.contains('<T>') {
// return true
// }
// Allow pointer arithmetic
if expected=='void*' && got=='int' {
return true
}
expected = expected.replace('*', '')
got = got.replace('*', '')

Loading…
Cancel
Save