run vfmt on array.v

pull/3141/head
Alexander Medvednikov 2019-12-18 20:07:32 +03:00
parent 9e11de4a8c
commit 1cef83aea4
5 changed files with 46 additions and 43 deletions

View File

@ -1,7 +1,6 @@
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module builtin
import strings
@ -28,13 +27,11 @@ fn new_array(mylen, cap, elm_size int) array {
return arr
}
// TODO
pub fn make(len, cap, elm_size int) array {
return new_array(len, cap, elm_size)
}
// Private function, used by V (`nums := [1, 2, 3]`)
fn new_array_from_c_array(len, cap, elm_size int, c_array voidptr) array {
cap_ := if cap == 0 {1}else {cap}
@ -64,7 +61,9 @@ fn new_array_from_c_array_no_alloc(len, cap, elm_size int, c_array voidptr) arra
fn (a mut array) ensure_cap(required int) {
if required > a.cap {
mut cap := if a.cap == 0 {2}else {a.cap * 2}
for required > cap { cap *= 2 }
for required > cap {
cap *= 2
}
if a.cap == 0 {
a.data = calloc(cap * a.element_size)
}
@ -344,7 +343,8 @@ pub fn (a []bool) str() string {
val := a[i]
if val {
sb.write('true')
} else {
}
else {
sb.write('false')
}
if i < a.len - 1 {

View File

@ -27,6 +27,9 @@ fn (v &V) no_cc_installed() bool {
}
fn (v mut V) cc() {
if os.executable().contains('vfmt') {
return
}
v.build_thirdparty_obj_files()
vexe := vexe_path()
vdir := os.dir(vexe)

View File

@ -454,7 +454,7 @@ fn (p mut Parser) fn_decl() {
p.genln('; // $f.name')
}
// Generic functions are inserted as needed from the call site
if f.is_generic {
if f.is_generic && !p.scanner.is_fmt {
if p.first_pass() {
if !p.scanner.is_vh {
gpidx := p.v.get_file_parser_index(p.file_path) or {
@ -1271,7 +1271,7 @@ fn (p mut Parser) fn_call_args(f mut Fn) {
p.error('wrong number of arguments in call to `${f.str_for_error()}`')
}
p.check(.rpar)
if f.is_generic {
if f.is_generic && !p.scanner.is_fmt {
type_map := p.extract_type_inst(f, saved_args)
p.dispatch_generic_fn_instance(mut f, &type_map)
}

View File

@ -124,7 +124,7 @@ pub mut:
comptime_define string // -D vfmt for `if $vfmt {`
fast bool // use tcc/x64 codegen
enable_globals bool // allow __global for low level code
is_fmt bool
//is_fmt bool
is_bare bool
user_mod_path string // `v -user_mod_path /Users/user/modules` adds a new lookup path for imported modules
@ -1093,7 +1093,7 @@ pub fn new_v(args[]string) &V {
ccompiler: find_c_compiler()
building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v.v' || dir.contains('vlib'))
comptime_define: comptime_define
is_fmt: comptime_define == 'vfmt'
//is_fmt: comptime_define == 'vfmt'
user_mod_path: user_mod_path
vlib_path: vlib_path
vpath: vpath

View File

@ -130,11 +130,11 @@ fn (p mut Parser) fmt_dec() {
}
[if vfmt]
fn (p mut Scanner) init_fmt() {
fn (s mut Scanner) init_fmt() {
// Right now we can't do `$if vfmt {`, so I'm using
// a conditional function init_fmt to set this flag.
// This function will only be called if `-d vfmt` is passed.
p.is_fmt = true
s.is_fmt = true
}
[if vfmt]
@ -243,7 +243,7 @@ fn (p &Parser) gen_fmt() {
if s == '' {
return
}
if !p.file_name.contains('fn.v') {return}
if !p.file_name.contains('parser.v') {return}
path := os.tmpdir() + '/' + p.file_name
println('generating ${path}')
mut out := os.create(path) or {