cgen: fix cross assign in closure (#14549)
parent
7dcc19df55
commit
c0ef6dbde8
|
@ -625,12 +625,13 @@ fn (mut g Gen) gen_cross_var_assign(node &ast.AssignStmt) {
|
||||||
ast.Ident {
|
ast.Ident {
|
||||||
left_typ := node.left_types[i]
|
left_typ := node.left_types[i]
|
||||||
left_sym := g.table.sym(left_typ)
|
left_sym := g.table.sym(left_typ)
|
||||||
|
anon_ctx := if g.anon_fn { '$closure_ctx->' } else { '' }
|
||||||
if left_sym.kind == .function {
|
if left_sym.kind == .function {
|
||||||
g.write_fn_ptr_decl(left_sym.info as ast.FnType, '_var_$left.pos.pos')
|
g.write_fn_ptr_decl(left_sym.info as ast.FnType, '_var_$left.pos.pos')
|
||||||
g.writeln(' = ${c_name(left.name)};')
|
g.writeln(' = $anon_ctx${c_name(left.name)};')
|
||||||
} else {
|
} else {
|
||||||
styp := g.typ(left_typ)
|
styp := g.typ(left_typ)
|
||||||
g.writeln('$styp _var_$left.pos.pos = ${c_name(left.name)};')
|
g.writeln('$styp _var_$left.pos.pos = $anon_ctx${c_name(left.name)};')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast.IndexExpr {
|
ast.IndexExpr {
|
||||||
|
|
|
@ -10,8 +10,7 @@ fn sma(period int) fn (f64) f64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
sum += input - storage[i]
|
sum += input - storage[i]
|
||||||
storage[i] = input
|
storage[i], i = input, (i + 1) % period
|
||||||
i = (i + 1) % period
|
|
||||||
return sum / f64(storage.len)
|
return sum / f64(storage.len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue