final vfmt run before CI check

pull/3182/head
Alexander Medvednikov 2019-12-22 00:54:37 +03:00
parent 2b9392c46c
commit ef28a6b872
10 changed files with 92 additions and 86 deletions

View File

@ -70,19 +70,19 @@ fresh_vc:
rm -rf $(TMPVC) rm -rf $(TMPVC)
$(GITFASTCLONE) $(VCREPO) $(TMPVC) $(GITFASTCLONE) $(VCREPO) $(TMPVC)
#latest_tcc: $(TMPTCC)/.git/config latest_tcc: $(TMPTCC)/.git/config
#ifndef ANDROID ifndef ANDROID
#cd $(TMPTCC) && $(GITCLEANPULL) cd $(TMPTCC) && $(GITCLEANPULL)
#endif endif
#fresh_tcc: fresh_tcc:
#ifndef ANDROID ifndef ANDROID
#rm -rf $(TMPTCC) rm -rf $(TMPTCC)
#$(GITFASTCLONE) $(TCCREPO) $(TMPTCC) $(GITFASTCLONE) $(TCCREPO) $(TMPTCC)
#endif endif
#$(TMPTCC)/.git/config: $(TMPTCC)/.git/config:
#$(MAKE) fresh_tcc $(MAKE) fresh_tcc
$(TMPVC)/.git/config: $(TMPVC)/.git/config:
$(MAKE) fresh_vc $(MAKE) fresh_vc

View File

@ -400,3 +400,4 @@ fn C.WaitForSingleObject(voidptr, int) int
fn C.ReleaseMutex(voidptr) bool fn C.ReleaseMutex(voidptr) bool

View File

@ -476,16 +476,16 @@ fn (v &V) interface_table() string {
} }
} }
methods += '\n},\n\n' methods += '\n},\n\n'
// Speaker_Cat_index = 0 // Speaker_Cat_index = 0
concrete_type_name := gen_type.replace('*', '_ptr') concrete_type_name := gen_type.replace('*', '_ptr')
sb.writeln('int _${interface_name}_${concrete_type_name}_index = $i;') sb.writeln('int _${interface_name}_${concrete_type_name}_index = $i;')
} }
if t.gen_types.len > 0 { if t.gen_types.len > 0 {
// methods = '{TCCSKIP(0)}' // methods = '{TCCSKIP(0)}'
// } // }
sb.writeln('void* (* ${interface_name}_name_table[][$t.methods.len]) = ' + '{ \n $methods \n }; ') sb.writeln('void* (* ${interface_name}_name_table[][$t.methods.len]) = ' + '{ \n $methods \n }; ')
}else{ }
else {
// The line below is needed so that C compilation succeeds, // The line below is needed so that C compilation succeeds,
// even if no interface methods are called. // even if no interface methods are called.
// See https://github.com/zenith391/vgtk3/issues/7 // See https://github.com/zenith391/vgtk3/issues/7

View File

@ -227,7 +227,6 @@ fn (p mut Parser) name_expr() string {
p.string_expr() p.string_expr()
return 'charptr' return 'charptr'
} }
// known_type := p.table.known_type(name) // known_type := p.table.known_type(name)
orig_name := name orig_name := name
is_c := name == 'C' && p.peek() == .dot is_c := name == 'C' && p.peek() == .dot
@ -722,18 +721,13 @@ fn (p mut Parser) factor() string {
.key_offsetof { .key_offsetof {
p.next() p.next()
p.check(.lpar) p.check(.lpar)
offsetof_typ := p.get_type() offsetof_typ := p.get_type()
p.check(.comma) p.check(.comma)
member := p.check_name() member := p.check_name()
p.check(.rpar) p.check(.rpar)
p.gen('__offsetof($offsetof_typ, $member)') p.gen('__offsetof($offsetof_typ, $member)')
return 'int' return 'int'
} }
.amp, .dot, .mul { .amp, .dot, .mul {
// (dot is for enum vals: `.green`) // (dot is for enum vals: `.green`)
return p.name_expr() return p.name_expr()

View File

@ -473,7 +473,7 @@ fn (p mut Parser) fn_decl() {
p.table.register_fn(f) p.table.register_fn(f)
} }
} }
p.set_current_fn( EmptyFn ) p.set_current_fn(EmptyFn)
p.skip_fn_body() p.skip_fn_body()
return return
} }
@ -767,26 +767,28 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s
} }
f.is_used = true f.is_used = true
cgen_name := p.table.fn_gen_name(f) cgen_name := p.table.fn_gen_name(f)
p.next() // fn name p.next() // fn name
mut generic_param_types := []string mut generic_param_types := []string
if p.tok == .lt { if p.tok == .lt {
p.check(.lt) p.check(.lt)
for { for {
param_type := p.check_name() param_type := p.check_name()
generic_param_types << param_type generic_param_types << param_type
if p.tok != .comma { break } if p.tok != .comma {
break
}
p.check(.comma) p.check(.comma)
} }
p.check(.gt) p.check(.gt)
// mut i := p.token_idx // mut i := p.token_idx
// for { // for {
// if p.tokens[i].tok == .gt { // if p.tokens[i].tok == .gt {
// //p.error('explicit type arguments are not allowed; remove `<...>`') // //p.error('explicit type arguments are not allowed; remove `<...>`')
// } else if p.tokens[i].tok == .lpar { // } else if p.tokens[i].tok == .lpar {
// // probably a typo, do not concern the user with the above error message // // probably a typo, do not concern the user with the above error message
// break // break
// } // }
// i++ // i++
// } // }
} }
// if p.pref.is_prof { // if p.pref.is_prof {
@ -1013,7 +1015,7 @@ fn (p mut Parser) fn_call_args(f mut Fn, generic_param_types []string) {
file_path := cescaped_path(p.file_path) file_path := cescaped_path(p.file_path)
p.cgen.resetln(p.cgen.cur_line.replace('v_panic (', 'panic_debug ($p.scanner.line_nr, tos3("$file_path"), tos3("$mod_name"), tos2((byte *)"$fn_name"), ')) p.cgen.resetln(p.cgen.cur_line.replace('v_panic (', 'panic_debug ($p.scanner.line_nr, tos3("$file_path"), tos3("$mod_name"), tos2((byte *)"$fn_name"), '))
} }
//mut saved_args := []string // mut saved_args := []string
mut saved_args := generic_param_types mut saved_args := generic_param_types
for i, arg in f.args { for i, arg in f.args {
// Receiver is the first arg // Receiver is the first arg
@ -1026,19 +1028,16 @@ fn (p mut Parser) fn_call_args(f mut Fn, generic_param_types []string) {
// if f.args[0].typ.ends_with('*') { // if f.args[0].typ.ends_with('*') {
// p.gen('&/*119*/') // p.gen('&/*119*/')
// } // }
// pos := p.cgen.cur_line.index('/* ? */')
//pos := p.cgen.cur_line.index('/* ? */') // if pos > -1 {
//if pos > -1 { // expr := p.cgen.cur_line[pos..]
// expr := p.cgen.cur_line[pos..] // // TODO hack
// // TODO hack // // If current expression is a func call, generate the array hack
// // If current expression is a func call, generate the array hack // if expr.contains('(') {
// if expr.contains('(') { // p.cgen.set_placeholder(pos, '(${arg.typ[..arg.typ.len-1]}[]){')
// p.cgen.set_placeholder(pos, '(${arg.typ[..arg.typ.len-1]}[]){') // p.gen('}[0] ')
// p.gen('}[0] ') // }
// } // }
//}
continue continue
} }
// Reached the final vararg? Quit // Reached the final vararg? Quit
@ -1520,7 +1519,9 @@ fn (p mut Parser) dispatch_generic_fn_instance(f mut Fn, ti &TypeInst) {
} }
f.type_inst << *ti f.type_inst << *ti
p.table.register_fn(f) p.table.register_fn(f)
if f.is_method { f.name = f.receiver_typ + '_' + f.name } if f.is_method {
f.name = f.receiver_typ + '_' + f.name
}
rename_generic_fn_instance(mut f, ti) rename_generic_fn_instance(mut f, ti)
replace_generic_type_params(mut f, ti) replace_generic_type_params(mut f, ti)
// TODO: Handle case where type not defined yet, see above // TODO: Handle case where type not defined yet, see above
@ -1543,7 +1544,8 @@ fn (p mut Parser) dispatch_generic_fn_instance(f mut Fn, ti &TypeInst) {
gp.generic_dispatch = *ti gp.generic_dispatch = *ti
gp.next() gp.next()
gp.fn_decl() gp.fn_decl()
gp.generic_dispatch = TypeInst{} gp.generic_dispatch = TypeInst{
}
p.cgen.lines_extra << p.cgen.lines p.cgen.lines_extra << p.cgen.lines
p.restore_state(saved_state, false, true) p.restore_state(saved_state, false, true)
p.cgen.fns << '${p.fn_signature(f)};' p.cgen.fns << '${p.fn_signature(f)};'

View File

@ -156,15 +156,13 @@ pub fn (v &V) finalize_compilation() {
pub fn (v mut V) add_parser(parser Parser) int { pub fn (v mut V) add_parser(parser Parser) int {
pidx := v.parsers.len pidx := v.parsers.len
v.parsers << parser v.parsers << parser
file_path := if filepath.is_abs(parser.file_path) { file_path := if filepath.is_abs(parser.file_path) { parser.file_path } else { os.realpath(parser.file_path) }
parser.file_path } else { os.realpath(parser.file_path) }
v.file_parser_idx[file_path] = pidx v.file_parser_idx[file_path] = pidx
return pidx return pidx
} }
pub fn (v &V) get_file_parser_index(file string) ?int { pub fn (v &V) get_file_parser_index(file string) ?int {
file_path := if filepath.is_abs(file) { file_path := if filepath.is_abs(file) { file } else { os.realpath(file) }
file } else { os.realpath(file) }
if file_path in v.file_parser_idx { if file_path in v.file_parser_idx {
return v.file_parser_idx[file_path] return v.file_parser_idx[file_path]
} }
@ -1058,7 +1056,7 @@ pub fn new_v(args []string) &V {
is_live: '-live' in args is_live: '-live' in args
sanitize: '-sanitize' in args sanitize: '-sanitize' in args
// nofmt: '-nofmt' in args // nofmt: '-nofmt' in args
show_c_cmd: '-show_c_cmd' in args show_c_cmd: '-show_c_cmd' in args
translated: 'translated' in args translated: 'translated' in args
is_run: 'run' in args is_run: 'run' in args
@ -1077,7 +1075,7 @@ pub fn new_v(args []string) &V {
building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v.v' || dir.contains('vlib')) building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v.v' || dir.contains('vlib'))
comptime_define: comptime_define comptime_define: comptime_define
// is_fmt: comptime_define == 'vfmt' // is_fmt: comptime_define == 'vfmt'
user_mod_path: user_mod_path user_mod_path: user_mod_path
vlib_path: vlib_path vlib_path: vlib_path
vpath: vpath vpath: vpath

View File

@ -980,7 +980,7 @@ fn (p mut Parser) get_type() string {
// Register anon fn type // Register anon fn type
fn_typ := Type{ fn_typ := Type{
name: f.typ_str() // 'fn (int, int) string' name: f.typ_str() // 'fn (int, int) string'
mod: p.mod mod: p.mod
func: f func: f
} }
@ -1100,7 +1100,9 @@ fn (p mut Parser) get_type() string {
if type_param in p.generic_dispatch.inst { if type_param in p.generic_dispatch.inst {
typ = '${typ}_' + p.generic_dispatch.inst[type_param] typ = '${typ}_' + p.generic_dispatch.inst[type_param]
} }
if p.tok != .comma { break } if p.tok != .comma {
break
}
p.check(.comma) p.check(.comma)
} }
p.check(.gt) p.check(.gt)
@ -3020,7 +3022,9 @@ fn (p mut Parser) skip_block(inside_first_lcbr bool) {
} }
if p.tok == .rcbr { if p.tok == .rcbr {
cbr_depth-- cbr_depth--
if cbr_depth == 0 { break } if cbr_depth == 0 {
break
}
} }
p.next() p.next()
} }

View File

@ -889,3 +889,4 @@ fn (s &Scanner) validate_var_name(name string) {
s.error('bad variable name `$name`\n' + 'looks like you have a multi-word name without separating them with `_`' + '\nfor example, use `registration_date` instead of `registrationdate` ') s.error('bad variable name `$name`\n' + 'looks like you have a multi-word name without separating them with `_`' + '\nfor example, use `registration_date` instead of `registrationdate` ')
} }
} }

View File

@ -7,6 +7,8 @@ import (
strings strings
) )
// also unions and interfaces // also unions and interfaces
fn (p mut Parser) struct_decl(generic_param_types []string) { fn (p mut Parser) struct_decl(generic_param_types []string) {
decl_tok_idx := p.cur_tok_index() decl_tok_idx := p.cur_tok_index()
is_pub := p.tok == .key_pub is_pub := p.tok == .key_pub
@ -39,26 +41,25 @@ fn (p mut Parser) struct_decl(generic_param_types []string) {
if is_interface && !name.ends_with('er') { if is_interface && !name.ends_with('er') {
p.error('interface names temporarily have to end with `er` (e.g. `Speaker`, `Reader`)') p.error('interface names temporarily have to end with `er` (e.g. `Speaker`, `Reader`)')
} }
mut generic_types := map[string]string mut generic_types := map[string]string
mut is_generic := false mut is_generic := false
if p.tok == .lt { if p.tok == .lt {
p.check(.lt) p.check(.lt)
for i := 0; ; i++ { for i := 0; ; i++ {
if generic_param_types.len > 0 && i > generic_param_types.len-1 { if generic_param_types.len > 0 && i > generic_param_types.len - 1 {
p.error('mismatched generic type params') p.error('mismatched generic type params')
} }
type_param := p.check_name() type_param := p.check_name()
generic_types[type_param] = if generic_param_types.len > 0 { generic_types[type_param] = if generic_param_types.len > 0 { generic_param_types[i] } else { '' }
generic_param_types[i] } else { '' } if p.tok != .comma {
if p.tok != .comma { break } break
}
p.check(.comma) p.check(.comma)
} }
p.check(.gt) p.check(.gt)
is_generic = true is_generic = true
} }
is_generic_instance := is_generic && generic_param_types.len > 0 is_generic_instance := is_generic && generic_param_types.len > 0
is_c := name == 'C' && p.tok == .dot is_c := name == 'C' && p.tok == .dot
if is_c { if is_c {
/* /*
@ -101,10 +102,12 @@ fn (p mut Parser) struct_decl(generic_param_types []string) {
p.gen_typedef('typedef $kind $name $name;') p.gen_typedef('typedef $kind $name $name;')
} }
// TODO: handle error // TODO: handle error
parser_idx := p.v.get_file_parser_index(p.file_path) or { 0 } parser_idx := p.v.get_file_parser_index(p.file_path) or {
//if !p.scanner.is_vh { 0
// parser_idx = p.v.get_file_parser_index(p.file_path) or { panic('cant find parser idx for $p.file_path') } }
//} // if !p.scanner.is_vh {
// parser_idx = p.v.get_file_parser_index(p.file_path) or { panic('cant find parser idx for $p.file_path') }
// }
// Register the type // Register the type
mut is_ph := false mut is_ph := false
if typ.is_placeholder { if typ.is_placeholder {
@ -251,9 +254,14 @@ fn (p mut Parser) struct_decl(generic_param_types []string) {
// `pub` access mod // `pub` access mod
// access_mod := if is_pub_field { AccessMod.public } else { AccessMod.private} // access_mod := if is_pub_field { AccessMod.public } else { AccessMod.private}
p.fspace() p.fspace()
defer { if is_generic_instance { p.generic_dispatch=TypeInst{} } } defer {
if is_generic_instance {
p.generic_dispatch = TypeInst{
}
}
}
if is_generic_instance { if is_generic_instance {
p.generic_dispatch=TypeInst{ p.generic_dispatch = TypeInst{
inst: generic_types inst: generic_types
} }
} }
@ -312,8 +320,7 @@ fn (p mut Parser) struct_decl(generic_param_types []string) {
did_gen_something = true did_gen_something = true
is_mut := access_mod in [.private_mut, .public_mut, .global] is_mut := access_mod in [.private_mut, .public_mut, .global]
if p.first_pass() || is_generic { if p.first_pass() || is_generic {
p.table.add_field(typ.name, field_name, field_type, is_mut, p.table.add_field(typ.name, field_name, field_type, is_mut, attr, access_mod)
attr, access_mod)
} }
p.fgen_nl() // newline between struct fields p.fgen_nl() // newline between struct fields
} }
@ -337,7 +344,6 @@ fn (p mut Parser) struct_init(typ_ string) string {
if !t.is_public && t.mod != p.mod { if !t.is_public && t.mod != p.mod {
p.warn('type `$t.name` is private') p.warn('type `$t.name` is private')
} }
// generic struct init // generic struct init
if p.peek() == .lt { if p.peek() == .lt {
p.next() p.next()
@ -349,14 +355,15 @@ fn (p mut Parser) struct_init(typ_ string) string {
type_param = p.generic_dispatch.inst[type_param] type_param = p.generic_dispatch.inst[type_param]
} }
type_params << type_param type_params << type_param
if p.tok != .comma { break } if p.tok != .comma {
break
}
p.check(.comma) p.check(.comma)
} }
p.dispatch_generic_struct(mut t, type_params) p.dispatch_generic_struct(mut t, type_params)
t = p.table.find_type(t.name) t = p.table.find_type(t.name)
typ = t.name typ = t.name
} }
if p.gen_struct_init(typ, &t) { if p.gen_struct_init(typ, &t) {
return typ return typ
} }
@ -500,7 +507,7 @@ fn (p mut Parser) dispatch_generic_struct(t mut Type, type_params []string) {
mut generic_types := map[string]string mut generic_types := map[string]string
if t.name in p.table.generic_struct_params { if t.name in p.table.generic_struct_params {
mut i := 0 mut i := 0
for _,v in p.table.generic_struct_params[t.name] { for _, v in p.table.generic_struct_params[t.name] {
generic_types[v] = type_params[i] generic_types[v] = type_params[i]
i++ i++
} }
@ -510,7 +517,6 @@ fn (p mut Parser) dispatch_generic_struct(t mut Type, type_params []string) {
} }
p.cgen.typedefs << 'typedef struct $t.name $t.name;\n' p.cgen.typedefs << 'typedef struct $t.name $t.name;\n'
} }
mut gp := p.v.parsers[t.parser_idx] mut gp := p.v.parsers[t.parser_idx]
gp.is_vgen = true gp.is_vgen = true
saved_state := p.save_state() saved_state := p.save_state()

View File

@ -7,19 +7,19 @@ import strings
struct Table { struct Table {
pub mut: pub mut:
typesmap map[string]Type typesmap map[string]Type
consts []Var consts []Var
fns map[string]Fn fns map[string]Fn
obf_ids map[string]int // obf_ids['myfunction'] == 23 obf_ids map[string]int // obf_ids['myfunction'] == 23
modules []string // List of all modules registered by the application modules []string // List of all modules registered by the application
imports []string // List of all imports imports []string // List of all imports
cflags []CFlag // ['-framework Cocoa', '-lglfw3'] cflags []CFlag // ['-framework Cocoa', '-lglfw3']
fn_cnt int // atomic fn_cnt int // atomic
obfuscate bool obfuscate bool
varg_access []VargAccess varg_access []VargAccess
// enum_vals map[string][]string // enum_vals map[string][]string
// names []Name // names []Name
max_field_len map[string]int // for vfmt: max_field_len['Parser'] == 12 max_field_len map[string]int // for vfmt: max_field_len['Parser'] == 12
generic_struct_params map[string][]string generic_struct_params map[string][]string
} }