-prealloc
parent
88cde6e4e6
commit
ef562413cd
|
@ -108,18 +108,20 @@ pub fn malloc(n int) byteptr {
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
panic('malloc(<0)')
|
panic('malloc(<0)')
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
$if debug {
|
$if debug {
|
||||||
res := g_m2_ptr
|
res := g_m2_ptr
|
||||||
g_m2_ptr += n
|
g_m2_ptr += n
|
||||||
nr_mallocs++
|
nr_mallocs++
|
||||||
return res
|
return res
|
||||||
} $else {
|
} $else {
|
||||||
|
*/
|
||||||
ptr := C.malloc(n)
|
ptr := C.malloc(n)
|
||||||
if ptr == 0 {
|
if ptr == 0 {
|
||||||
panic('malloc($n) failed')
|
panic('malloc($n) failed')
|
||||||
}
|
}
|
||||||
return ptr
|
return ptr
|
||||||
}
|
//}
|
||||||
/*
|
/*
|
||||||
TODO
|
TODO
|
||||||
#ifdef VPLAY
|
#ifdef VPLAY
|
||||||
|
|
|
@ -82,6 +82,9 @@ fn (p mut Parser) comp_time() {
|
||||||
else if name == 'debug' {
|
else if name == 'debug' {
|
||||||
p.comptime_if_block('VDEBUG')
|
p.comptime_if_block('VDEBUG')
|
||||||
}
|
}
|
||||||
|
else if name == 'prealloc' {
|
||||||
|
p.comptime_if_block('VPREALLOC')
|
||||||
|
}
|
||||||
else if name == 'tinyc' {
|
else if name == 'tinyc' {
|
||||||
p.comptime_if_block('__TINYC__')
|
p.comptime_if_block('__TINYC__')
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,7 @@ pub mut:
|
||||||
vpath string
|
vpath string
|
||||||
x64 bool
|
x64 bool
|
||||||
output_cross_c bool
|
output_cross_c bool
|
||||||
|
prealloc bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should be called by main at the end of the compilation process, to cleanup
|
// Should be called by main at the end of the compilation process, to cleanup
|
||||||
|
@ -419,7 +420,7 @@ fn (v mut V) generate_init() {
|
||||||
// vlib can't have `init_consts()`
|
// vlib can't have `init_consts()`
|
||||||
v.cgen.genln('void init() {
|
v.cgen.genln('void init() {
|
||||||
g_str_buf=malloc(1000);
|
g_str_buf=malloc(1000);
|
||||||
#if VDEBUG
|
#if VPREALLOC
|
||||||
g_m2_buf = malloc(50 * 1000 * 1000);
|
g_m2_buf = malloc(50 * 1000 * 1000);
|
||||||
g_m2_ptr = g_m2_buf;
|
g_m2_ptr = g_m2_buf;
|
||||||
puts("allocated 50 mb");
|
puts("allocated 50 mb");
|
||||||
|
@ -528,7 +529,7 @@ pub fn (v mut V) generate_main() {
|
||||||
cgen.genln(' main__main();')
|
cgen.genln(' main__main();')
|
||||||
if !v.pref.is_bare {
|
if !v.pref.is_bare {
|
||||||
cgen.genln('free(g_str_buf);')
|
cgen.genln('free(g_str_buf);')
|
||||||
cgen.genln('#if VDEBUG')
|
cgen.genln('#if VPREALLOC')
|
||||||
cgen.genln('free(g_m2_buf);')
|
cgen.genln('free(g_m2_buf);')
|
||||||
cgen.genln('puts("freed mem buf");')
|
cgen.genln('puts("freed mem buf");')
|
||||||
cgen.genln('#endif')
|
cgen.genln('#endif')
|
||||||
|
@ -663,7 +664,7 @@ pub fn (v mut V) add_v_files_to_compile() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v.pref.is_verbose { v.log('v.add_v_files_to_compile > builtin_files: $builtin_files') }
|
if v.pref.is_verbose { v.log('v.add_v_files_to_compile > builtin_files: $builtin_files') }
|
||||||
|
|
||||||
// Parse builtin imports
|
// Parse builtin imports
|
||||||
for file in builtin_files {
|
for file in builtin_files {
|
||||||
// add builtins first
|
// add builtins first
|
||||||
|
@ -1076,6 +1077,7 @@ pub fn new_v(args[]string) &V {
|
||||||
is_bare: '-freestanding' in args
|
is_bare: '-freestanding' in args
|
||||||
x64: '-x64' in args
|
x64: '-x64' in args
|
||||||
output_cross_c: '-output-cross-platform-c' in args
|
output_cross_c: '-output-cross-platform-c' in args
|
||||||
|
prealloc: '-prealloc' in args
|
||||||
is_repl: is_repl
|
is_repl: is_repl
|
||||||
build_mode: build_mode
|
build_mode: build_mode
|
||||||
cflags: cflags
|
cflags: cflags
|
||||||
|
|
Loading…
Reference in New Issue