replace silly `exit(reason string)` with `exit(code int)`
parent
0d1d5612ae
commit
06a4dfa290
|
@ -4,12 +4,8 @@
|
|||
|
||||
module builtin
|
||||
|
||||
pub fn exit(reason string) {
|
||||
if reason == '' {
|
||||
panic('exit empty reason')
|
||||
}
|
||||
println('exit(): $reason')
|
||||
C.exit(0)
|
||||
pub fn exit(code int) {
|
||||
C.exit(1)
|
||||
}
|
||||
|
||||
// isnil returns true if an object is nil (only for C objects).
|
||||
|
|
|
@ -17,8 +17,6 @@ struct CGen {
|
|||
fns []string
|
||||
so_fns []string
|
||||
consts_init []string
|
||||
// tmp_lines []string
|
||||
// tmp_lines_pos int
|
||||
lines []string
|
||||
is_user bool
|
||||
mut:
|
||||
|
@ -30,19 +28,13 @@ mut:
|
|||
is_tmp bool
|
||||
fn_main string
|
||||
stash string
|
||||
// st_start_pos int
|
||||
}
|
||||
|
||||
fn new_cgen(out_name_c string) *CGen {
|
||||
// println('NEW CGENN($out_name_c)')
|
||||
// println('$LANG_TMP/$out_name_c')
|
||||
gen := &CGen {
|
||||
out_path: '$TmpPath/$out_name_c'
|
||||
out: os.create_file('$TmpPath/$out_name_c')
|
||||
}
|
||||
for i := 0; i < 10; i++ {
|
||||
// gen.tmp_lines.push('')
|
||||
}
|
||||
return gen
|
||||
}
|
||||
|
||||
|
@ -51,7 +43,6 @@ fn (g mut CGen) genln(s string) {
|
|||
return
|
||||
}
|
||||
if g.is_tmp {
|
||||
// if g.tmp_lines_pos > 0 {
|
||||
g.tmp_line = '$g.tmp_line $s\n'
|
||||
return
|
||||
}
|
||||
|
@ -61,16 +52,13 @@ fn (g mut CGen) genln(s string) {
|
|||
g.prev_line = g.cur_line
|
||||
g.cur_line = ''
|
||||
}
|
||||
// g.lines << s
|
||||
}
|
||||
|
||||
fn (g mut CGen) gen(s string) {
|
||||
// if g.nogen || g.run == RunType.RUN_DECLS {
|
||||
if g.nogen || g.run == RUN_DECLS {
|
||||
return
|
||||
}
|
||||
if g.is_tmp {
|
||||
// if g.tmp_lines_pos > 0 {
|
||||
g.tmp_line = '$g.tmp_line $s'
|
||||
}
|
||||
else {
|
||||
|
@ -82,18 +70,16 @@ fn (g mut CGen) save() {
|
|||
s := g.lines.join('\n')
|
||||
g.out.appendln(s)
|
||||
g.out.close()
|
||||
// os.system('clang-format -i $g.out_path')
|
||||
}
|
||||
|
||||
fn (g mut CGen) start_tmp() {
|
||||
if g.is_tmp {
|
||||
println(g.tmp_line)
|
||||
os.exit('start_tmp() already started. cur_line="$g.cur_line"')
|
||||
println('start_tmp() already started. cur_line="$g.cur_line"')
|
||||
exit(1)
|
||||
}
|
||||
// kg.tmp_lines_pos++
|
||||
g.tmp_line = ''
|
||||
// g.tmp_lines[g.tmp_lines_pos] = ''
|
||||
// g.tmp_lines.set(g.tmp_lines_pos, '')
|
||||
g.is_tmp = true
|
||||
}
|
||||
|
||||
|
@ -101,15 +87,10 @@ fn (g mut CGen) end_tmp() string {
|
|||
g.is_tmp = false
|
||||
res := g.tmp_line
|
||||
g.tmp_line = ''
|
||||
// g.tmp_lines_pos--
|
||||
// g.tmp_line = g.tmp_lines[g.tmp_lines_pos]
|
||||
return res
|
||||
}
|
||||
|
||||
fn (g mut CGen) add_placeholder() int {
|
||||
// g.genln('/*placeholder*/')
|
||||
// g.genln('')
|
||||
// return g.lines.len - 1
|
||||
if g.is_tmp {
|
||||
return g.tmp_line.len
|
||||
}
|
||||
|
@ -133,10 +114,10 @@ fn (g mut CGen) set_placeholder(pos int, val string) {
|
|||
// g.genln('')
|
||||
}
|
||||
|
||||
// /////////////////////
|
||||
fn (g mut CGen) add_placeholder2() int {
|
||||
if g.is_tmp {
|
||||
exit('tmp in addp2')
|
||||
println('tmp in addp2')
|
||||
exit(1)
|
||||
}
|
||||
g.lines << ''
|
||||
return g.lines.len - 1
|
||||
|
@ -147,65 +128,16 @@ fn (g mut CGen) set_placeholder2(pos int, val string) {
|
|||
return
|
||||
}
|
||||
if g.is_tmp {
|
||||
exit('tmp in setp2')
|
||||
println('tmp in setp2')
|
||||
exit(1)
|
||||
}
|
||||
g.lines[pos] = val
|
||||
}
|
||||
|
||||
// /////////////////
|
||||
// fn (g mut CGen) cut_lines_after(pos int) string {
|
||||
// end := g.lines.len
|
||||
// lines := g.lines.slice_fast(pos, end)
|
||||
// body := lines.join('\n')
|
||||
// g.lines = g.lines.slice_fast(0, pos)
|
||||
// return body
|
||||
// }
|
||||
// fn (g mut CGen) set_prev_line(val string) {
|
||||
// g.lines.set(g.lines.len - 3, val)
|
||||
// }
|
||||
// ////fn (g mut CGen) go_back() {
|
||||
// ////g.stash = g.prev_line + g.cur_line
|
||||
// g.lines.set(g.lin
|
||||
// ////}
|
||||
// fn (g mut CGen) end_statement() {
|
||||
// last_lines := g.lines.slice_fast(g.st_start_pos, g.lines.len - 1)
|
||||
// mut merged := last_lines.join(' ')
|
||||
// merged += '/* M $last_lines.len */'
|
||||
// merged = merged.replace('\n', '')
|
||||
// // zero last N lines instead of deleting them
|
||||
// for i := g.st_start_pos; i < g.lines.len; i++ {
|
||||
// g.lines.set(i, '')
|
||||
// }
|
||||
// g.lines.set(g.lines.len - 1, merged)
|
||||
// // g.genln('')
|
||||
// g.st_start_pos = g.lines.len - 1
|
||||
// // os.exitkmerged)
|
||||
// }
|
||||
// fn (g mut CGen) prepend_type(typ string) {
|
||||
// g.cur_line = typ.add(g.cur_line)
|
||||
// g.cur_line='!!!'
|
||||
// }
|
||||
fn (g mut CGen) insert_before(val string) {
|
||||
// g.cur_line = val.add(g.cur_line)
|
||||
// return
|
||||
// val += '/*inserted*/'
|
||||
g.lines.insert(g.lines.len - 1, val)
|
||||
}
|
||||
|
||||
// fn (g mut CGen) swap_last_lines() {
|
||||
// return
|
||||
// if g.run == RUN_DECLS {
|
||||
// return
|
||||
// }
|
||||
// i := g.lines.len - 1
|
||||
// j := i - 1
|
||||
// tmp := g.lines[i]
|
||||
// // println('lines i = $tmp')
|
||||
// // println('lines j = ${g.lines[j]}')
|
||||
// // // os.exit('')
|
||||
// g.lines.set(i, g.lines[j])
|
||||
// g.lines.set(j, tmp)
|
||||
// }
|
||||
fn (g mut CGen) register_thread_fn(wrapper_name, wrapper_text, struct_text string) {
|
||||
for arg in g.thread_args {
|
||||
if arg.contains(wrapper_name) {
|
||||
|
@ -216,14 +148,6 @@ fn (g mut CGen) register_thread_fn(wrapper_name, wrapper_text, struct_text strin
|
|||
g.thread_args << wrapper_text
|
||||
}
|
||||
|
||||
/*
|
||||
fn (g mut CGen) delete_all_after(pos int) {
|
||||
if pos > g.cur_line.len - 1 {
|
||||
return
|
||||
}
|
||||
g.cur_line = g.cur_line.substr(0, pos)
|
||||
}
|
||||
*/
|
||||
fn (c mut V) prof_counters() string {
|
||||
mut res := []string
|
||||
// Global fns
|
||||
|
|
|
@ -115,10 +115,12 @@ fn main() {
|
|||
if args.contains('fmt') {
|
||||
file := args.last()
|
||||
if !os.file_exists(file) {
|
||||
os.exit1('"$file" does not exist')
|
||||
println('"$file" does not exist')
|
||||
exit(1)
|
||||
}
|
||||
if !file.ends_with('.v') {
|
||||
os.exit1('v fmt can only be used on .v files')
|
||||
println('v fmt can only be used on .v files')
|
||||
exit(1)
|
||||
}
|
||||
println('vfmt is temporarily disabled')
|
||||
return
|
||||
|
@ -136,7 +138,7 @@ fn main() {
|
|||
// Generate the docs and exit
|
||||
if args.contains('doc') {
|
||||
// c.gen_doc_html_for_module(args.last())
|
||||
os.exit('')
|
||||
exit(0)
|
||||
}
|
||||
c.compile()
|
||||
}
|
||||
|
@ -380,7 +382,8 @@ string _STR_TMP(const char *fmt, ...) {
|
|||
if ret != 0 {
|
||||
s := os.system(cmd)
|
||||
println(s)
|
||||
os.exit1('ret not 0, exiting')
|
||||
println('ret not 0, exiting')
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -414,7 +417,7 @@ fn (c mut V) cc() {
|
|||
libs = '$TmpPath/vlib/builtin.o'
|
||||
if !os.file_exists(libs) {
|
||||
println('`builtin.o` not found')
|
||||
exit('')
|
||||
exit(1)
|
||||
}
|
||||
for imp in c.table.imports {
|
||||
if imp == 'webview' {
|
||||
|
@ -504,7 +507,7 @@ mut args := ''
|
|||
'/usr/lib/x86_64-linux-gnu/crtn.o')
|
||||
println(ress)
|
||||
if ress.contains('error:') {
|
||||
os.exit1('')
|
||||
os.exit(1)
|
||||
}
|
||||
println('linux cross compilation done. resulting binary: "$c.out_name"')
|
||||
}
|
||||
|
@ -585,7 +588,8 @@ fn (c mut V) add_user_v_files() {
|
|||
}
|
||||
}
|
||||
if user_files.len == 0 {
|
||||
exit('No input .v files')
|
||||
println('No input .v files')
|
||||
exit(1)
|
||||
}
|
||||
if c.is_verbose {
|
||||
c.log('user_files:')
|
||||
|
@ -703,7 +707,8 @@ fn new_v(args[]string) *V {
|
|||
is_test := dir.ends_with('_test.v')
|
||||
is_script := dir.ends_with('.v')
|
||||
if is_script && !os.file_exists(dir) {
|
||||
exit('`$dir` does not exist')
|
||||
println('`$dir` does not exist')
|
||||
exit(1)
|
||||
}
|
||||
// No -o provided? foo.v => foo
|
||||
if out_name == 'a.out' && dir.ends_with('.v') {
|
||||
|
|
|
@ -456,14 +456,13 @@ fn (s mut Scanner) scan() ScanRes {
|
|||
}
|
||||
|
||||
fn (s &Scanner) error(msg string) {
|
||||
// println('!! SCANNER ERROR: $msg')
|
||||
file := s.file_path.all_after('/')
|
||||
println('panic: $file:${s.line_nr + 1}')
|
||||
println(msg)
|
||||
// os.print_backtrace()
|
||||
// println(file)
|
||||
// println(s.file_path)
|
||||
os.exit1(' ')
|
||||
exit(1)
|
||||
}
|
||||
|
||||
// println('array out of bounds $idx len=$a.len')
|
||||
|
|
|
@ -634,7 +634,8 @@ fn (table &Table) cgen_name_type_pair(name, typ string) string {
|
|||
else if typ.starts_with('fn (') {
|
||||
T := table.find_type(typ)
|
||||
if T.name == '' {
|
||||
os.exit1('this should never happen')
|
||||
println('this should never happen')
|
||||
exit(1)
|
||||
}
|
||||
str_args := T.func.str_args(table)
|
||||
return '$T.func.typ (*$name)( $str_args /*FFF*/ )'
|
||||
|
|
11
os/os.v
11
os/os.v
|
@ -315,15 +315,8 @@ pub fn getenv(key string) string {
|
|||
return tos2(s)
|
||||
}
|
||||
|
||||
fn exit(reason string) {
|
||||
println('exit(): $reason')
|
||||
log(reason)
|
||||
C.exit(0)
|
||||
}
|
||||
|
||||
fn exit1(reason string) {
|
||||
println('exit(): $reason')
|
||||
C.exit(1)
|
||||
fn exit(code int) {
|
||||
C.exit(code)
|
||||
}
|
||||
|
||||
// `file_exists` returns true if `path` exists.
|
||||
|
|
Loading…
Reference in New Issue