compiler: -autofree flag

pull/1977/head
Alexander Medvednikov 2019-09-14 18:54:55 +03:00
parent 079dcd1fff
commit 3d2c266980
2 changed files with 4 additions and 4 deletions

View File

@ -98,6 +98,7 @@ mut:
// You can also quote several options at the same time: -cflags '-Os -fno-inline-small-functions'.
ccompiler string // the name of the used C compiler
building_v bool
autofree bool
}
fn main() {
@ -803,6 +804,7 @@ fn new_v(args[]string) &V {
show_c_cmd: '-show_c_cmd' in args
translated: 'translated' in args
is_run: 'run' in args
autofree: 'autofree' in args
is_repl: is_repl
build_mode: build_mode
cflags: cflags

View File

@ -1067,9 +1067,8 @@ fn (p mut Parser) close_scope() {
// println('breaking. "$v.name" v.scope_level=$v.scope_level')
break
}
// Clean up memory, only do this for V compiler for now
//if p.os != .windows {
if p.pref.building_v && v.is_alloc && !p.pref.is_test {
// Clean up memory, only do this if -autofree was passed for now
if p.pref.autofree && v.is_alloc && !p.pref.is_test {
mut free_fn := 'free'
if v.typ.starts_with('array_') {
free_fn = 'v_array_free'
@ -1092,7 +1091,6 @@ fn (p mut Parser) close_scope() {
} else {
p.genln('$free_fn($v.name); // close_scope free')
}
//}
}
}
if p.cur_fn.defer_text.last() != '' {