From 96f762062809ef1e3737d7c071739654cad32c0a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 30 Oct 2019 15:04:25 +0300 Subject: [PATCH] instead of `Enum.foo` require `.foo` if it's enough + some UI fixes --- vlib/compiler/comptime.v | 4 ++-- vlib/compiler/fn.v | 10 +++++----- vlib/compiler/main.v | 2 +- vlib/compiler/module_header.v | 8 +++++--- vlib/compiler/parser.v | 26 +++++++++++++++----------- vlib/compiler/token.v | 12 ++++++------ vlib/ui/ui_mac.v | 2 ++ 7 files changed, 36 insertions(+), 28 deletions(-) diff --git a/vlib/compiler/comptime.v b/vlib/compiler/comptime.v index 6f04492c53..41afcc59da 100644 --- a/vlib/compiler/comptime.v +++ b/vlib/compiler/comptime.v @@ -215,9 +215,9 @@ fn (p mut Parser) chash() { else if hash.contains('embed') { pos := hash.index('embed') + 5 file := hash[pos..] - if p.pref.build_mode != .default_mode { + //if p.pref.build_mode != .default_mode { p.genln('#include $file') - } + //} } else if hash.contains('define') { // Move defines on top diff --git a/vlib/compiler/fn.v b/vlib/compiler/fn.v index 39cc32875e..1ecf6a8d22 100644 --- a/vlib/compiler/fn.v +++ b/vlib/compiler/fn.v @@ -262,7 +262,7 @@ fn (p mut Parser) fn_decl() { p.register_var(receiver) } // +-/* methods - if p.tok in [TokenKind.plus, .minus, .mul] { + if p.tok in [.plus, .minus, .mul] { f.name = p.tok.str() p.next() } @@ -277,9 +277,9 @@ fn (p mut Parser) fn_decl() { // C function header def? (fn C.NSMakeRect(int,int,int,int)) is_c := f.name == 'C' && p.tok == .dot // Just fn signature? only builtin.v + default build mode - if p.pref.is_verbose { // p.pref.build_mode == .build_module { - println('\n\nfn_decl() name=$f.name receiver_typ=$receiver_typ nogen=$p.cgen.nogen') - } + //if p.pref.is_verbose { // p.pref.build_mode == .build_module { + //println('\n\nfn_decl() name=$f.name receiver_typ=$receiver_typ nogen=$p.cgen.nogen') + //} if is_c { p.check(.dot) f.name = p.check_name() @@ -348,7 +348,7 @@ fn (p mut Parser) fn_decl() { } // Returns a type? mut typ := 'void' - if p.tok in [TokenKind.name, .mul, .amp, .lsbr, .question, .lpar] { + if p.tok in [.name, .mul, .amp, .lsbr, .question, .lpar] { p.fgen(' ') typ = p.get_type() } diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index 08e1bfb77d..bea52eacfc 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -204,7 +204,7 @@ pub fn (v mut V) compile() { } // Main pass - cgen.pass = Pass.main + cgen.pass = .main if v.pref.is_debug { $if js { cgen.genln('const VDEBUG = 1;\n') diff --git a/vlib/compiler/module_header.v b/vlib/compiler/module_header.v index 83523e51d9..a4d10ca941 100644 --- a/vlib/compiler/module_header.v +++ b/vlib/compiler/module_header.v @@ -46,6 +46,8 @@ fn generate_vh(mod string) { //} filtered := vfiles.filter(it.ends_with('.v') && !it.ends_with('test.v') && !it.ends_with('_windows.v') && !it.ends_with('_win.v') && + !it.ends_with('_lin.v') && + !it.contains('/examples') && !it.contains('/js')) // TODO merge once filter allows it println(filtered) mut v := new_v(['foo.v']) @@ -62,9 +64,9 @@ fn generate_vh(mod string) { continue } match tok.tok { - TokenKind.key_fn { fns.writeln(generate_fn(p.tokens, i)) } - TokenKind.key_const { consts.writeln(generate_const(p.tokens, i)) } - TokenKind.key_struct { types.writeln(generate_type(p.tokens, i)) } + .key_fn { fns.writeln(generate_fn(p.tokens, i)) } + .key_const { consts.writeln(generate_const(p.tokens, i)) } + .key_struct { types.writeln(generate_type(p.tokens, i)) } } } } diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index fd3fa2266d..32c016033f 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -197,7 +197,7 @@ fn (p mut Parser) next() { p.prev_tok = p.tok p.scanner.prev_tok = p.tok if p.token_idx >= p.tokens.len { - p.tok = TokenKind.eof + p.tok = .eof p.lit = '' return } @@ -211,7 +211,7 @@ fn (p mut Parser) next() { fn (p & Parser) peek() TokenKind { if p.token_idx >= p.tokens.len - 2 { - return TokenKind.eof + return .eof } tok := p.tokens[p.token_idx] return tok.tok @@ -371,7 +371,8 @@ fn (p mut Parser) parse(pass Pass) { } .key_global { if !p.pref.translated && !p.pref.is_live && - !p.builtin_mod && !p.pref.building_v && !os.getwd().contains('/volt') { + !p.builtin_mod && !p.pref.building_v && + p.mod != 'ui' && !os.getwd().contains('/volt') { p.error('__global is only allowed in translated code') } p.next() @@ -760,7 +761,7 @@ fn (p mut Parser) get_type() string { p.fn_args(mut f) // Same line, it's a return type if p.scanner.line_nr == line_nr { - if p.tok in [TokenKind.name, .mul, .amp, .lsbr, .question, .lpar] { + if p.tok in [.name, .mul, .amp, .lsbr, .question, .lpar] { f.typ = p.get_type() } else { @@ -1639,6 +1640,9 @@ fn (p mut Parser) name_expr() string { if !enum_type.has_enum_val(val) { p.error('enum `$enum_type.name` does not have value `$val`') } + if p.expected_type == enum_type.name { + p.warn('`${enum_type.name}.$val` is unnecessary, use `.$val`') + } // println('enum val $val') p.gen(mod_gen_name(enum_type.mod) + '__' + enum_type.name + '_' + val)// `color = main__Color_green` @@ -2374,7 +2378,7 @@ fn (p mut Parser) expression() string { return 'int' } // + - | ^ - for p.tok in [TokenKind.plus, .minus, .pipe, .amp, .xor] { + for p.tok in [.plus, .minus, .pipe, .amp, .xor] { tok_op := p.tok if typ == 'bool' { p.error('operator ${p.tok.str()} not defined on bool ') @@ -3604,9 +3608,9 @@ if (!$tmp) { p.genln(';\n if (!$tmp) { g_test_fails++; - main__cb_assertion_failed( - tos3("$filename"), - $p.scanner.line_nr, + main__cb_assertion_failed( + tos3("$filename"), + $p.scanner.line_nr, tos3("$sourceline"), tos3("$p.cur_fn.name()") ); @@ -3615,9 +3619,9 @@ if (!$tmp) { // Maybe print all vars in a test function if it fails? } else { g_test_oks++; - main__cb_assertion_ok( - tos3("$filename"), - $p.scanner.line_nr, + main__cb_assertion_ok( + tos3("$filename"), + $p.scanner.line_nr, tos3("$sourceline"), tos3("$p.cur_fn.name()") ); diff --git a/vlib/compiler/token.v b/vlib/compiler/token.v index ddd84a3ac6..e28e0e2c25 100644 --- a/vlib/compiler/token.v +++ b/vlib/compiler/token.v @@ -257,17 +257,17 @@ fn (t TokenKind) str() string { } fn (t TokenKind) is_decl() bool { - return t in [TokenKind.key_enum, .key_interface, .key_fn, + return t in [.key_enum, .key_interface, .key_fn, .key_struct ,.key_type, .key_const, .key_import_const, .key_pub, .eof] } const ( AssignTokens = [ - TokenKind.assign, TokenKind.plus_assign, TokenKind.minus_assign, - TokenKind.mult_assign, TokenKind.div_assign, TokenKind.xor_assign, - TokenKind.mod_assign, - TokenKind.or_assign, TokenKind.and_assign, TokenKind.righ_shift_assign, - TokenKind.left_shift_assign + TokenKind.assign, .plus_assign, .minus_assign, + .mult_assign, .div_assign, .xor_assign, + .mod_assign, + .or_assign, .and_assign, .righ_shift_assign, + .left_shift_assign ] ) diff --git a/vlib/ui/ui_mac.v b/vlib/ui/ui_mac.v index 7496e21980..cc94f10d10 100644 --- a/vlib/ui/ui_mac.v +++ b/vlib/ui/ui_mac.v @@ -6,6 +6,8 @@ module ui #include #include +__global default_font *C.NSFont + fn focus_app(next, event, data voidptr) { #NSLog(@"2The hot key was pressed.");