File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1086,7 +1086,23 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
10861086 old_inside_assign_fn_var := g.inside_assign_fn_var
10871087 g.inside_assign_fn_var = val is ast.PrefixExpr && val.op == .amp
10881088 && is_fn_var
1089- g.expr (val)
1089+ mut nval := val
1090+ if val is ast.PrefixExpr && val.right is ast.CallExpr {
1091+ call_expr := val.right as ast.CallExpr
1092+ if call_expr.name == 'new_array_from_c_array' {
1093+ nval = call_expr
1094+ if ! var_type.has_flag (.shared_f) {
1095+ g.write ('HEAP(${g .styp (var_type .clear_ref ())}, ' )
1096+ }
1097+ g.expr (nval)
1098+ if ! var_type.has_flag (.shared_f) {
1099+ g.write (')' )
1100+ }
1101+ }
1102+ }
1103+ if nval == val {
1104+ g.expr (nval)
1105+ }
10901106 g.inside_assign_fn_var = old_inside_assign_fn_var
10911107 }
10921108 if ! is_fn_var && is_auto_heap && ! is_option_auto_heap
Original file line number Diff line number Diff line change @@ -5864,13 +5864,16 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
58645864 g.write ('&' .repeat (ptr_cnt))
58655865 }
58665866 }
5867+ old_inside_cast := g.inside_cast
58675868 if node_typ == ast.voidptr_type && node.expr is ast.ArrayInit
58685869 && (node.expr as ast.ArrayInit ).is_fixed {
5870+ g.inside_cast = false
58695871 expr_styp := g.styp (node.expr_type)
58705872 g.write ('(${expr_styp })' )
58715873 }
58725874 g.expr (node.expr)
58735875 g.inside_assign_fn_var = old_inside_assign_fn_var
5876+ g.inside_cast = old_inside_cast
58745877 g.write ('))' )
58755878 }
58765879 }
@@ -7887,8 +7890,12 @@ fn (mut g Gen) get_type(typ ast.Type) ast.Type {
78877890
78887891fn (mut g Gen) size_of (node ast.SizeOf) {
78897892 typ := g.type_resolver.typeof_type (node.expr, g.get_type (node.typ))
7890- node_typ := g.unwrap_generic (typ)
7893+ mut node_typ := g.unwrap_generic (typ)
78917894 sym := g.table.sym (node_typ)
7895+ if sym.kind == .function {
7896+ // todo fix fn type with fn name now
7897+ node_typ = ast.voidptr_type
7898+ }
78927899 if sym.language == .v && sym.kind in [.placeholder, .any] {
78937900 g.error ('unknown type `${sym .name }`' , node.pos)
78947901 }
Original file line number Diff line number Diff line change @@ -524,6 +524,10 @@ fn (mut w Walker) expr(node_ ast.Expr) {
524524 }
525525 ast.ComptimeCall {
526526 w.expr (node.left)
527+ for args in node.args {
528+ w.expr (args.expr)
529+ }
530+ w.expr (node.or_block)
527531 if node.is_vweb {
528532 w.stmts (node.veb_tmpl.stmts)
529533 }
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ pub fn (mut t Transformer) array_init(mut node ast.ArrayInit) ast.Expr {
1818 if node.has_init {
1919 node.init_expr = t.expr (mut node.init_expr)
2020 }
21- if ! t.pref.new_transform || t.skip_array_transform || node.is_fixed || t.inside_in
22- || node.has_len || node.has_cap || node.exprs.len == 0 {
21+ if t.pref.backend == .js_node || ! t.pref.new_transform || t.skip_array_transform
22+ || node.is_fixed || t.inside_in || node. has_len || node.has_cap || node.exprs.len == 0 {
2323 return node
2424 }
2525 // For C and native transform into a function call `builtin__new_array_from_c_array_noscan(...)` etc
@@ -52,7 +52,7 @@ pub fn (mut t Transformer) array_init(mut node ast.ArrayInit) ast.Expr {
5252 typ: fixed_array_typ
5353 elem_type: node.elem_type
5454 exprs: node.exprs
55- expr_types: node.exprs. map ( it . type ())
55+ expr_types: node.expr_types
5656 }
5757 typ: ast.voidptr_type
5858 typname: 'voidptr'
Original file line number Diff line number Diff line change @@ -625,6 +625,13 @@ pub fn (mut t Transformer) expr(mut node ast.Expr) ast.Expr {
625625 for mut stmt in node.stmts {
626626 stmt = t.stmt (mut stmt)
627627 }
628+ if node.stmts.len > 0 {
629+ // todo fix [] => new_array_from_c_array() now
630+ mut stmt := node.stmts.last ()
631+ if stmt is ast.ExprStmt && stmt.expr is ast.CallExpr {
632+ ((stmt as ast.ExprStmt ).expr as ast.CallExpr ).is_return_used = true
633+ }
634+ }
628635 }
629636 ast.ParExpr {
630637 mut inner_expr := t.expr (mut node.expr)
You can’t perform that action at this time.
0 commit comments