diff --git a/compiler/cc.v b/compiler/cc.v index ba07751e01..7874e6cbe6 100644 --- a/compiler/cc.v +++ b/compiler/cc.v @@ -129,7 +129,7 @@ fn (v mut V) cc() { // Output executable name a << '-o "$v.out_name"' if os.dir_exists(v.out_name) { - cerror('\'$v.out_name\' is a directory') + verror('\'$v.out_name\' is a directory') } // macOS code can include objective C TODO remove once objective C is replaced with C if v.os == .mac { @@ -176,12 +176,12 @@ fn (v mut V) cc() { println(cmd) } ticks := time.ticks() - res := os.exec(cmd) or { cerror(err) return } + res := os.exec(cmd) or { verror(err) return } if res.exit_code != 0 { if res.exit_code == 127 { // the command could not be found by the system - cerror('C compiler error, while attempting to run: \n' + + verror('C compiler error, while attempting to run: \n' + '-----------------------------------------------------------\n' + '$cmd\n' + '-----------------------------------------------------------\n' + @@ -200,7 +200,7 @@ fn (v mut V) cc() { println('') } } - cerror('C error. This should never happen. ' + + verror('C error. This should never happen. ' + 'Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose') } diff := time.ticks() - ticks @@ -224,7 +224,7 @@ fn (v mut V) cc() { obj_file + ' /usr/lib/x86_64-linux-gnu/libc.so ' + '/usr/lib/x86_64-linux-gnu/crtn.o') or { - cerror(err) + verror(err) return } println(ress.output) diff --git a/compiler/cgen.v b/compiler/cgen.v index 74fc3aaf03..12206e51af 100644 --- a/compiler/cgen.v +++ b/compiler/cgen.v @@ -259,7 +259,7 @@ fn build_thirdparty_obj_file(path string, moduleflags []CFlag) { cmd := '$cc $cc_thirdparty_options $btarget -c -o "$obj_path" $cfiles $atarget ' res := os.exec(cmd) or { println('failed thirdparty object build cmd: $cmd') - cerror(err) + verror(err) return } println(res.output) @@ -278,7 +278,7 @@ fn os_name_to_ifdef(name string) string { case 'android': return '__BIONIC__' case 'js': return '_VJS' } - cerror('bad os ifdef name "$name"') + verror('bad os ifdef name "$name"') return '' } @@ -290,7 +290,7 @@ fn platform_postfix_to_ifdefguard(name string) string { case '_lin.v': return '#ifdef __linux__' case '_mac.v': return '#ifdef __APPLE__' } - cerror('bad platform_postfix "$name"') + verror('bad platform_postfix "$name"') return '' } @@ -346,7 +346,7 @@ fn sort_structs(types []Type) []Type { // sort graph dep_graph_sorted := dep_graph.resolve() if !dep_graph_sorted.acyclic { - cerror('error: cgen.sort_structs() DGNAC.\nplease create a new issue here: https://github.com/vlang/v/issues and tag @joe-conigliaro') + verror('error: cgen.sort_structs() DGNAC.\nplease create a new issue here: https://github.com/vlang/v/issues and tag @joe-conigliaro') } // sort types mut types_sorted := []Type diff --git a/compiler/fn.v b/compiler/fn.v index 8971716acf..60a11d43bf 100644 --- a/compiler/fn.v +++ b/compiler/fn.v @@ -935,12 +935,12 @@ fn (p mut Parser) fn_call_args(f mut Fn) &Fn { // Add `&` or `*` before an argument? if !is_interface { // Dereference - if got.contains('*') && !expected.contains('*') { + if got.ends_with('*') && !expected.ends_with('*') { p.cgen.set_placeholder(ph, '*') } // Reference // TODO ptr hacks. DOOM hacks, fix please. - if !got.contains('*') && expected.contains('*') && got != 'voidptr' { + if !got.ends_with('*') && expected.ends_with('*') && got != 'voidptr' { // Special case for mutable arrays. We can't `&` function results, // have to use `(array[]){ expr }` hack. if expected.starts_with('array_') && expected.ends_with('*') { diff --git a/compiler/main.v b/compiler/main.v index 9661799766..76a9c93209 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -219,7 +219,7 @@ fn (v mut V) add_parser(parser Parser) { fn (v mut V) compile() { // Emily: Stop people on linux from being able to build with msvc if os.user_os() != 'windows' && v.os == .msvc { - cerror('Cannot build with msvc on ${os.user_os()}') + verror('Cannot build with msvc on ${os.user_os()}') } mut cgen := v.cgen @@ -431,11 +431,11 @@ string _STR_TMP(const char *fmt, ...) { } else if v.pref.is_test { if v.table.main_exists() { - cerror('test files cannot have function `main`') + verror('test files cannot have function `main`') } // make sure there's at least on test function if !v.table.has_at_least_one_test_fn() { - cerror('test files need to have at least one test function') + verror('test files need to have at least one test function') } // Generate `main` which calls every single test function cgen.genln('int main() { init_consts();') @@ -492,9 +492,9 @@ fn (v V) run_compiled_executable_and_exit() { fn (v &V) v_files_from_dir(dir string) []string { mut res := []string if !os.file_exists(dir) { - cerror('$dir doesn\'t exist') + verror('$dir doesn\'t exist') } else if !os.dir_exists(dir) { - cerror('$dir isn\'t a directory') + verror('$dir isn\'t a directory') } mut files := os.ls(dir) if v.pref.is_verbose { @@ -593,7 +593,7 @@ fn (v mut V) add_v_files_to_compile() { import_path := '$ModPath/vlib/$mod_path' vfiles := v.v_files_from_dir(import_path) if vfiles.len == 0 { - cerror('cannot import module $mod (no .v files in "$import_path").') + verror('cannot import module $mod (no .v files in "$import_path").') } // Add all imports referenced by these libs for file in vfiles { @@ -613,7 +613,7 @@ fn (v mut V) add_v_files_to_compile() { import_path := v.find_module_path(mod) vfiles := v.v_files_from_dir(import_path) if vfiles.len == 0 { - cerror('cannot import module $mod (no .v files in "$import_path").') + verror('cannot import module $mod (no .v files in "$import_path").') } // Add all imports referenced by these libs for file in vfiles { @@ -632,7 +632,7 @@ fn (v mut V) add_v_files_to_compile() { deps_resolved := dep_graph.resolve() if !deps_resolved.acyclic { deps_resolved.display() - cerror('Import cycle detected.') + verror('Import cycle detected.') } // add imports in correct order for mod in deps_resolved.imports() { @@ -928,7 +928,7 @@ fn update_v() { println('Updating V...') vroot := os.dir(os.executable()) s := os.exec('git -C "$vroot" pull --rebase origin master') or { - cerror(err) + verror(err) return } println(s.output) @@ -939,13 +939,13 @@ fn update_v() { } os.mv('$vroot/v.exe', v_backup_file) s2 := os.exec('"$vroot/make.bat"') or { - cerror(err) + verror(err) return } println(s2.output) } $else { s2 := os.exec('make -C "$vroot"') or { - cerror(err) + verror(err) return } println(s2.output) @@ -978,20 +978,20 @@ fn install_v(args[]string) { //println('Building vget...') os.chdir(vroot + '/tools') vgetcompilation := os.exec('$vexec -o $vget vget.v') or { - cerror(err) + verror(err) return } if vgetcompilation.exit_code != 0 { - cerror( vgetcompilation.output ) + verror( vgetcompilation.output ) return } } vgetresult := os.exec('$vget ' + names.join(' ')) or { - cerror(err) + verror(err) return } if vgetresult.exit_code != 0 { - cerror( vgetresult.output ) + verror( vgetresult.output ) return } } @@ -1086,7 +1086,7 @@ fn create_symlink() { } } -pub fn cerror(s string) { +pub fn verror(s string) { println('V error: $s') os.flush_stdout() exit(1) diff --git a/compiler/modules.v b/compiler/modules.v index 62374f9aef..cf050a7677 100644 --- a/compiler/modules.v +++ b/compiler/modules.v @@ -45,7 +45,7 @@ fn (v &V) find_module_path(mod string) string { if !os.dir_exists(import_path) { import_path = '$ModPath/$mod_path' if !os.dir_exists(import_path){ - cerror('module "$mod" not found') + verror('module "$mod" not found') } } return import_path diff --git a/compiler/msvc.v b/compiler/msvc.v index bea072fdb6..f6bd5aafd6 100644 --- a/compiler/msvc.v +++ b/compiler/msvc.v @@ -202,7 +202,7 @@ fn find_msvc() ?MsvcResult { } } $else { - cerror('Cannot find msvc on this OS') + verror('Cannot find msvc on this OS') return error('msvc not found') } } @@ -213,7 +213,7 @@ pub fn (v mut V) cc_msvc() { if !v.pref.is_debug && v.out_name_c != 'v.c' && v.out_name_c != 'v_macos.c' { os.rm(v.out_name_c) } - cerror('Cannot find MSVC on this OS.') + verror('Cannot find MSVC on this OS.') return } @@ -345,11 +345,11 @@ pub fn (v mut V) cc_msvc() { res := os.exec(cmd) or { println(err) - cerror('msvc error') + verror('msvc error') return } if res.exit_code != 0 { - cerror(res.output) + verror(res.output) } // println(res) // println('C OUTPUT:') @@ -398,7 +398,7 @@ fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []CFlag) { //NB: the quotes above ARE balanced. println('thirdparty cmd line: $cmd') res := os.exec(cmd) or { - cerror(err) + verror(err) return } println(res.output) @@ -425,7 +425,7 @@ fn (cflags []CFlag) msvc_string_flags() MsvcStringFlags { // by the compiler if flag.name == '-l' { if flag.value.ends_with('.dll') { - cerror('MSVC cannot link against a dll (`#flag -l $flag.value`)') + verror('MSVC cannot link against a dll (`#flag -l $flag.value`)') } // MSVC has no method of linking against a .dll // TODO: we should look for .defs aswell diff --git a/compiler/parser.v b/compiler/parser.v index f2fbceb8d8..4782ee22f2 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -287,7 +287,7 @@ fn (p mut Parser) parse(pass Pass) { } if false && !p.first_pass() && p.fileis('main.v') { out := os.create('/var/tmp/fmt.v') or { - cerror('failed to create fmt.v') + verror('failed to create fmt.v') return } out.writeln(p.scanner.fmt_out.str()) @@ -490,7 +490,7 @@ fn key_to_type_cat(tok Token) TypeCategory { case Token.key_union: return TypeCategory.union_ //Token.key_ => return .interface_ } - cerror('Unknown token: $tok') + verror('Unknown token: $tok') return TypeCategory.builtin } @@ -1115,11 +1115,7 @@ fn (p mut Parser) close_scope() { mut i := p.var_idx - 1 for ; i >= 0; i-- { v := p.local_vars[i] - //if p.cur_fn.name == 'main' { - //println('var in main $v.name $v.typ $v.is_alloc ptr=$v.ptr') - //} if v.scope_level ≠ p.cur_fn.scope_level { - // println('breaking. "$v.name" v.scope_level=$v.scope_level') break } // Clean up memory, only do this if -autofree was passed for now @@ -1129,14 +1125,16 @@ fn (p mut Parser) close_scope() { free_fn = 'v_array_free' } else if v.typ == 'string' { free_fn = 'v_string_free' - continue + //if p.fileis('str.v') { + //println('freeing str $v.name') + //} + //continue } else if v.ptr || v.typ.ends_with('*') { free_fn = 'v_ptr_free' //continue } else { continue } - //if false && p.returns { if p.returns { if !v.is_returned && v.typ != 'FILE*' { //!v.is_c { prev_line := p.cgen.lines[p.cgen.lines.len-2] @@ -1407,8 +1405,10 @@ fn (p mut Parser) var_decl() { scanner_pos: var_scanner_pos line_nr: var_scanner_pos.line_nr }) + //if p.fileis('str.v') { + //if p.is_alloc { println('REG VAR IS ALLOC $name') } + //} } - //if p.is_alloc { println('REG VAR IS ALLOC $name') } p.var_decl_name = '' p.is_empty_c_struct_init = false } @@ -2673,7 +2673,7 @@ fn (p mut Parser) string_expr() { p.gen('_STR_TMP($format$args)') } else { - // Otherwise do ugly len counting + allocation + sprintf + // Otherwise do len counting + allocation + sprintf p.gen('_STR($format$args)') } } @@ -3808,7 +3808,7 @@ fn (p mut Parser) check_unused_imports() { if output == '' { return } output = '$p.file_path: the following imports were never used:$output' if p.pref.is_prod { - cerror(output) + verror(output) } else { println('warning: $output') } diff --git a/compiler/query.v b/compiler/query.v index c57853701e..3272342030 100644 --- a/compiler/query.v +++ b/compiler/query.v @@ -23,7 +23,7 @@ fn sql_params2params_gen(sql_params []string, sql_types []string, qprefix string }else if paramtype == 'string' { params_gen += '${qprefix}params[$i] = ${param}.str;\n' }else{ - cerror('orm: only int and string variable types are supported in queries') + verror('orm: only int and string variable types are supported in queries') } } } diff --git a/compiler/repl.v b/compiler/repl.v index 9ce19bb70b..ff133750e1 100644 --- a/compiler/repl.v +++ b/compiler/repl.v @@ -124,7 +124,7 @@ fn run_repl() []string { source_code := r.functions.join('\n') + r.lines.join('\n') + '\n' + line os.write_file(file, source_code) s := os.exec('$vexe run $file -repl') or { - cerror(err) + verror(err) return []string } vals := s.output.split('\n') @@ -143,7 +143,7 @@ fn run_repl() []string { temp_source_code := r.functions.join('\n') + r.lines.join('\n') + r.temp_lines.join('\n') + '\n' + temp_line os.write_file(temp_file, temp_source_code) s := os.exec('$vexe run $temp_file -repl') or { - cerror(err) + verror(err) return []string } if !func_call && s.exit_code == 0 { diff --git a/compiler/scanner.v b/compiler/scanner.v index b1292313e2..fe9991b0a6 100644 --- a/compiler/scanner.v +++ b/compiler/scanner.v @@ -38,11 +38,11 @@ mut: fn new_scanner(file_path string) &Scanner { if !os.file_exists(file_path) { - cerror('"$file_path" doesn\'t exist') + verror('"$file_path" doesn\'t exist') } mut raw_text := os.read_file(file_path) or { - cerror('scanner: failed to open "$file_path"') + verror('scanner: failed to open "$file_path"') return 0 } diff --git a/compiler/table.v b/compiler/table.v index 0c8173cb7f..4fcf8790c1 100644 --- a/compiler/table.v +++ b/compiler/table.v @@ -389,7 +389,7 @@ fn (t mut Table) rewrite_type(typ Type) { fn (table mut Table) add_field(type_name, field_name, field_type string, is_mut bool, attr string, access_mod AccessMod) { if type_name == '' { print_backtrace() - cerror('add_field: empty type') + verror('add_field: empty type') } mut t := table.typesmap[type_name] t.fields << Var { @@ -449,7 +449,7 @@ fn (p mut Parser) add_method(type_name string, f Fn) { } if type_name == '' { print_backtrace() - cerror('add_method: empty type') + verror('add_method: empty type') } // TODO table.typesmap[type_name].methods << f mut t := p.table.typesmap[type_name] @@ -763,7 +763,7 @@ fn (t &Table) fn_gen_types(fn_name string) []string { return f.types } } - cerror('function $fn_name not found') + verror('function $fn_name not found') return []string } @@ -870,7 +870,7 @@ fn (fit mut FileImportTable) register_alias(alias string, mod string) { // NOTE: come back here // if alias in fit.imports && fit.imports[alias] == mod {} if alias in fit.imports && fit.imports[alias] != mod { - cerror('cannot import $mod as $alias: import name $alias already in use in "${fit.file_path}".') + verror('cannot import $mod as $alias: import name $alias already in use in "${fit.file_path}".') } if mod.contains('.internal.') { mod_parts := mod.split('.') @@ -881,7 +881,7 @@ fn (fit mut FileImportTable) register_alias(alias string, mod string) { } internal_parent := internal_mod_parts.join('.') if !fit.module_name.starts_with(internal_parent) { - cerror('module $mod can only be imported internally by libs.') + verror('module $mod can only be imported internally by libs.') } } fit.imports[alias] = mod