1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen,ast: reduce memory usage for compiling larger V programs

This commit is contained in:
Delyan Angelov 2023-07-15 17:18:21 +03:00
parent 2e3384aaef
commit 11bffc957a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 21 additions and 11 deletions

View File

@ -349,7 +349,7 @@ pub mut:
end_comments []Comment // comments that after const field
// the comptime_expr_value field is filled by the checker, when it has enough
// info to evaluate the constant at compile time
comptime_expr_value ComptTimeConstValue = empty_comptime_const_expr()
comptime_expr_value ComptTimeConstValue = empty_comptime_const_expr
}
// const declaration
@ -1006,9 +1006,9 @@ pub mut:
or_block OrExpr
ct_left_value_evaled bool
ct_left_value ComptTimeConstValue = empty_comptime_const_expr()
ct_left_value ComptTimeConstValue = empty_comptime_const_expr
ct_right_value_evaled bool
ct_right_value ComptTimeConstValue = empty_comptime_const_expr()
ct_right_value ComptTimeConstValue = empty_comptime_const_expr
before_op_comments []Comment
after_op_comments []Comment

View File

@ -15,9 +15,7 @@ pub type ComptTimeConstValue = EmptyExpr
| u8
| voidptr
pub fn empty_comptime_const_expr() ComptTimeConstValue {
return EmptyExpr(0)
}
pub const empty_comptime_const_expr = ComptTimeConstValue(EmptyExpr(0))
pub fn (val ComptTimeConstValue) i8() ?i8 {
x := val.i64()?

View File

@ -493,7 +493,9 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
concrete_types := (left_sym.info as ast.Struct).concrete_types
mut method_name := left_sym.cname + '_' + util.replace_op(extracted_op)
method_name = g.generic_fn_name(concrete_types, method_name)
g.write(' = ${method_name}(')
g.write(' = ')
g.write(method_name)
g.write('(')
g.expr(left)
g.write(', ')
g.expr(val)
@ -504,7 +506,9 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
&& !left_sym.has_method(extracted_op) {
g.write(' = ')
g.expr(left)
g.write(' ${extracted_op} ')
g.write(' ')
g.write(extracted_op)
g.write(' ')
g.expr(val)
g.write(';')
return
@ -631,7 +635,11 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
g.writeln(';')
}
} else if !g.is_arraymap_set && !str_add && !op_overloaded {
g.write(' ${op} ')
// ordinary `=` in `x = 2 * y;`
// Note, that this branch *deliberately does not use interpolation*
g.write(' ')
g.write(op.str())
g.write(' ')
} else if str_add || op_overloaded {
g.write(', ')
}

View File

@ -1016,7 +1016,9 @@ fn (mut g Gen) gen_is_none_check(node ast.InfixExpr) {
g.write(' ')
g.write('${left_var}.state')
}
g.write(' ${node.op.str()} ')
g.write(' ')
g.write(node.op.str())
g.write(' ')
g.write('2') // none state
}
@ -1030,7 +1032,9 @@ fn (mut g Gen) gen_plain_infix_expr(node ast.InfixExpr) {
g.write('*')
}
g.expr(node.left)
g.write(' ${node.op.str()} ')
g.write(' ')
g.write(node.op.str())
g.write(' ')
if node.right_type.is_ptr() && node.right.is_auto_deref_var() {
g.write('*')
g.expr(node.right)