From 3d2c266980fc9d8ae9bcb22c8028e376e10176e2 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 14 Sep 2019 18:54:55 +0300 Subject: [PATCH] compiler: -autofree flag --- compiler/main.v | 2 ++ compiler/parser.v | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/main.v b/compiler/main.v index 6943dda40e..6ff39267b7 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -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 diff --git a/compiler/parser.v b/compiler/parser.v index a458d80d8f..0c5e9da68f 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -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() != '' {