instead of `Enum.foo` require `.foo` if it's enough + some UI fixes

pull/2592/head
Alexander Medvednikov 2019-10-30 15:04:25 +03:00
parent 9abbfa7862
commit 96f7620628
7 changed files with 36 additions and 28 deletions

View File

@ -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

View File

@ -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()
}

View File

@ -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')

View File

@ -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)) }
}
}
}

View File

@ -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 ')

View File

@ -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
]
)

View File

@ -6,6 +6,8 @@ module ui
#include <Cocoa/Cocoa.h>
#include <Carbon/Carbon.h>
__global default_font *C.NSFont
fn focus_app(next, event, data voidptr) {
#NSLog(@"2The hot key was pressed.");