all: re-enable -prealloc
							parent
							
								
									2ea187fb85
								
							
						
					
					
						commit
						a1073105e1
					
				| 
						 | 
					@ -136,6 +136,7 @@ pub fn malloc(n int) byteptr {
 | 
				
			||||||
		panic('malloc(<=0)')
 | 
							panic('malloc(<=0)')
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$if prealloc {
 | 
						$if prealloc {
 | 
				
			||||||
 | 
							//println('p')
 | 
				
			||||||
		res := g_m2_ptr
 | 
							res := g_m2_ptr
 | 
				
			||||||
		unsafe {
 | 
							unsafe {
 | 
				
			||||||
			g_m2_ptr += n
 | 
								g_m2_ptr += n
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,8 +15,8 @@ import v.depgraph
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	c_reserved = ['delete', 'exit', 'link', 'unix', 'error', 'calloc', 'malloc', 'free', 'panic',
 | 
						c_reserved = ['delete', 'exit', 'link', 'unix', 'error', 'calloc', 'malloc', 'free', 'panic',
 | 
				
			||||||
		'auto', 'char', 'default', 'do', 'double', 'extern', 'float', 'inline', 'int', 'long', 'register',
 | 
							'auto', 'char', 'default', 'do', 'double', 'extern', 'float', 'inline', 'int', 'long', 'register',
 | 
				
			||||||
		'restrict', 'short', 'signed', 'sizeof', 'static', 'switch', 'typedef', 'union', 'unsigned',
 | 
							'restrict', 'short', 'signed', 'sizeof', 'static', 'switch', 'typedef', 'union', 'unsigned', 'void',
 | 
				
			||||||
		'void', 'volatile', 'while', 'new', 'namespace', 'class', 'typename']
 | 
							'volatile', 'while', 'new', 'namespace', 'class', 'typename']
 | 
				
			||||||
	// same order as in token.Kind
 | 
						// same order as in token.Kind
 | 
				
			||||||
	cmp_str    = ['eq', 'ne', 'gt', 'lt', 'ge', 'le']
 | 
						cmp_str    = ['eq', 'ne', 'gt', 'lt', 'ge', 'le']
 | 
				
			||||||
	// when operands are switched
 | 
						// when operands are switched
 | 
				
			||||||
| 
						 | 
					@ -286,6 +286,9 @@ pub fn (mut g Gen) init() {
 | 
				
			||||||
		g.comptime_defines.writeln('#define _VAUTOFREE (1)')
 | 
							g.comptime_defines.writeln('#define _VAUTOFREE (1)')
 | 
				
			||||||
		// g.comptime_defines.writeln('unsigned char* g_cur_str;')
 | 
							// g.comptime_defines.writeln('unsigned char* g_cur_str;')
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if g.pref.prealloc {
 | 
				
			||||||
 | 
							g.comptime_defines.writeln('#define _VPREALLOC (1)')
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if g.pref.is_livemain || g.pref.is_liveshared {
 | 
						if g.pref.is_livemain || g.pref.is_liveshared {
 | 
				
			||||||
		g.generate_hotcode_reloading_declarations()
 | 
							g.generate_hotcode_reloading_declarations()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -968,13 +971,11 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type, expected_type table.Type)
 | 
				
			||||||
				g.write('/* sum type cast */ ($exp_styp) {.obj = ')
 | 
									g.write('/* sum type cast */ ($exp_styp) {.obj = ')
 | 
				
			||||||
				g.expr(expr)
 | 
									g.expr(expr)
 | 
				
			||||||
				g.write(', .typ = $got_idx /* $got_sym.name */}')
 | 
									g.write(', .typ = $got_idx /* $got_sym.name */}')
 | 
				
			||||||
			}
 | 
								} else {
 | 
				
			||||||
			else {
 | 
					 | 
				
			||||||
				g.write('/* sum type cast */ ($exp_styp) {.obj = memdup(&($got_styp[]) {')
 | 
									g.write('/* sum type cast */ ($exp_styp) {.obj = memdup(&($got_styp[]) {')
 | 
				
			||||||
				g.expr(expr)
 | 
									g.expr(expr)
 | 
				
			||||||
				g.write('}, sizeof($got_styp)), .typ = $got_idx /* $got_sym.name */}')
 | 
									g.write('}, sizeof($got_styp)), .typ = $got_idx /* $got_sym.name */}')
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -1073,16 +1074,30 @@ fn (mut g Gen) gen_assert_metainfo(a ast.AssertStmt) string {
 | 
				
			||||||
fn (mut g Gen) gen_assert_single_expr(e ast.Expr, t table.Type) {
 | 
					fn (mut g Gen) gen_assert_single_expr(e ast.Expr, t table.Type) {
 | 
				
			||||||
	unknown_value := '*unknown value*'
 | 
						unknown_value := '*unknown value*'
 | 
				
			||||||
	match e {
 | 
						match e {
 | 
				
			||||||
		ast.CallExpr { g.write(ctoslit(unknown_value)) }
 | 
							ast.CallExpr {
 | 
				
			||||||
		ast.CastExpr { g.write(ctoslit(unknown_value)) }
 | 
								g.write(ctoslit(unknown_value))
 | 
				
			||||||
		ast.IndexExpr { g.write(ctoslit(unknown_value)) }
 | 
							}
 | 
				
			||||||
		ast.PrefixExpr { g.write(ctoslit(unknown_value)) }
 | 
							ast.CastExpr {
 | 
				
			||||||
		ast.MatchExpr { g.write(ctoslit(unknown_value)) }
 | 
								g.write(ctoslit(unknown_value))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							ast.IndexExpr {
 | 
				
			||||||
 | 
								g.write(ctoslit(unknown_value))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							ast.PrefixExpr {
 | 
				
			||||||
 | 
								g.write(ctoslit(unknown_value))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							ast.MatchExpr {
 | 
				
			||||||
 | 
								g.write(ctoslit(unknown_value))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		ast.Type {
 | 
							ast.Type {
 | 
				
			||||||
			sym := g.table.get_type_symbol(t)
 | 
								sym := g.table.get_type_symbol(t)
 | 
				
			||||||
			g.write(ctoslit('$sym.name'))
 | 
								g.write(ctoslit('$sym.name'))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else { g.gen_expr_to_string(e, t) or { g.write(ctoslit('[$err]')) } }
 | 
							else {
 | 
				
			||||||
 | 
								g.gen_expr_to_string(e, t) or {
 | 
				
			||||||
 | 
									g.write(ctoslit('[$err]'))
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	g.write(' /* typeof: ' + typeof(e) + ' type: ' + t.str() + ' */ ')
 | 
						g.write(' /* typeof: ' + typeof(e) + ' type: ' + t.str() + ' */ ')
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1152,14 +1167,13 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
 | 
				
			||||||
						arg_len := func.func.args.len
 | 
											arg_len := func.func.args.len
 | 
				
			||||||
						for j, arg in func.func.args {
 | 
											for j, arg in func.func.args {
 | 
				
			||||||
							arg_type := g.table.get_type_symbol(arg.typ)
 | 
												arg_type := g.table.get_type_symbol(arg.typ)
 | 
				
			||||||
							g.write('${arg_type.str()} ${arg.name}')
 | 
												g.write('$arg_type.str() $arg.name')
 | 
				
			||||||
							if j < arg_len - 1 {
 | 
												if j < arg_len - 1 {
 | 
				
			||||||
								g.write(', ')
 | 
													g.write(', ')
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
						g.writeln(') = $left.name;')
 | 
											g.writeln(') = $left.name;')
 | 
				
			||||||
					}
 | 
										} else {
 | 
				
			||||||
					else {
 | 
					 | 
				
			||||||
						styp := g.typ(var_type)
 | 
											styp := g.typ(var_type)
 | 
				
			||||||
						g.writeln('$styp _var_$left.pos.pos = $left.name;')
 | 
											g.writeln('$styp _var_$left.pos.pos = $left.name;')
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
| 
						 | 
					@ -2112,7 +2126,7 @@ fn (mut g Gen) lock_expr(node ast.LockExpr) {
 | 
				
			||||||
		deref := if id.is_mut { '->' } else { '.' }
 | 
							deref := if id.is_mut { '->' } else { '.' }
 | 
				
			||||||
		lock_prefix := if node.is_rlock { `r` } else { `w` }
 | 
							lock_prefix := if node.is_rlock { `r` } else { `w` }
 | 
				
			||||||
		lock_prefixes << lock_prefix // keep for unlock
 | 
							lock_prefixes << lock_prefix // keep for unlock
 | 
				
			||||||
		g.writeln('sync__RwMutex_${lock_prefix:c}_lock(${name}${deref}mtx);')
 | 
							g.writeln('sync__RwMutex_${lock_prefix:c}_lock($name${deref}mtx);')
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	g.stmts(node.stmts)
 | 
						g.stmts(node.stmts)
 | 
				
			||||||
	// unlock in reverse order
 | 
						// unlock in reverse order
 | 
				
			||||||
| 
						 | 
					@ -2121,7 +2135,7 @@ fn (mut g Gen) lock_expr(node ast.LockExpr) {
 | 
				
			||||||
		lock_prefix := lock_prefixes[i]
 | 
							lock_prefix := lock_prefixes[i]
 | 
				
			||||||
		name := id.name
 | 
							name := id.name
 | 
				
			||||||
		deref := if id.is_mut { '->' } else { '.' }
 | 
							deref := if id.is_mut { '->' } else { '.' }
 | 
				
			||||||
		g.writeln('sync__RwMutex_${lock_prefix:c}_unlock(${name}${deref}mtx);')
 | 
							g.writeln('sync__RwMutex_${lock_prefix:c}_unlock($name${deref}mtx);')
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2863,7 +2877,9 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
 | 
				
			||||||
		fields = struct_init.fields
 | 
							fields = struct_init.fields
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	*/
 | 
						*/
 | 
				
			||||||
	if is_multiline { g.indent++ }
 | 
						if is_multiline {
 | 
				
			||||||
 | 
							g.indent++
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	// User set fields
 | 
						// User set fields
 | 
				
			||||||
	mut initialized := false
 | 
						mut initialized := false
 | 
				
			||||||
	for i, field in struct_init.fields {
 | 
						for i, field in struct_init.fields {
 | 
				
			||||||
| 
						 | 
					@ -2929,7 +2945,6 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					g.write(',')
 | 
										g.write(',')
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					 | 
				
			||||||
				initialized = true
 | 
									initialized = true
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -2947,11 +2962,12 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				g.write(',')
 | 
									g.write(',')
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					 | 
				
			||||||
			initialized = true
 | 
								initialized = true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if is_multiline { g.indent-- }
 | 
						if is_multiline {
 | 
				
			||||||
 | 
							g.indent--
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	// if struct_init.fields.len == 0 && info.fields.len == 0 {
 | 
						// if struct_init.fields.len == 0 && info.fields.len == 0 {
 | 
				
			||||||
	if !initialized {
 | 
						if !initialized {
 | 
				
			||||||
		g.write('\n#ifndef __cplusplus\n0\n#endif\n')
 | 
							g.write('\n#ifndef __cplusplus\n0\n#endif\n')
 | 
				
			||||||
| 
						 | 
					@ -3105,6 +3121,10 @@ fn (mut g Gen) write_init_function() {
 | 
				
			||||||
		// mb_size := if s_str_buf_size == '' { 1 } else { s_str_buf_size.int() }
 | 
							// mb_size := if s_str_buf_size == '' { 1 } else { s_str_buf_size.int() }
 | 
				
			||||||
		// g.writeln('g_str_buf = malloc( ${mb_size} * 1024 * 1000 );')
 | 
							// g.writeln('g_str_buf = malloc( ${mb_size} * 1024 * 1000 );')
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if g.pref.prealloc {
 | 
				
			||||||
 | 
							g.writeln('g_m2_buf = malloc(50 * 1000 * 1000);')
 | 
				
			||||||
 | 
							g.writeln('g_m2_ptr = g_m2_buf;')
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	g.writeln('\tbuiltin_init();')
 | 
						g.writeln('\tbuiltin_init();')
 | 
				
			||||||
	g.writeln('\tvinit_string_literals();')
 | 
						g.writeln('\tvinit_string_literals();')
 | 
				
			||||||
	//
 | 
						//
 | 
				
			||||||
| 
						 | 
					@ -3788,7 +3808,7 @@ fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) string {
 | 
				
			||||||
			return '__GLIBC__'
 | 
								return '__GLIBC__'
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		'prealloc' {
 | 
							'prealloc' {
 | 
				
			||||||
			return 'VPREALLOC'
 | 
								return '_VPREALLOC'
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		'no_bounds_checking' {
 | 
							'no_bounds_checking' {
 | 
				
			||||||
			return 'CUSTOM_DEFINE_no_bounds_checking'
 | 
								return 'CUSTOM_DEFINE_no_bounds_checking'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -195,6 +195,9 @@ pub fn parse_args(args []string) (&Preferences, string) {
 | 
				
			||||||
			'-usecache' {
 | 
								'-usecache' {
 | 
				
			||||||
				res.use_cache = true
 | 
									res.use_cache = true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								'-prealloc' {
 | 
				
			||||||
 | 
									res.prealloc = true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			'-keepc' {
 | 
								'-keepc' {
 | 
				
			||||||
				eprintln('-keepc is deprecated. V always keeps the generated .tmp.c files now.')
 | 
									eprintln('-keepc is deprecated. V always keeps the generated .tmp.c files now.')
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue