compiler: load nil directly on inline

This commit is contained in:
Evgeniy Stratonikov 2021-02-05 17:26:26 +03:00
parent 3484025065
commit 57a0377c81
2 changed files with 7 additions and 0 deletions

View file

@ -230,6 +230,9 @@ func (c *codegen) emitLoadVar(pkg string, name string) {
if vi.tv.Value != nil {
c.emitLoadConst(vi.tv)
return
} else if vi.index == unspecifiedVarIndex {
emit.Opcodes(c.prog.BinWriter, opcode.PUSHNULL)
return
}
c.emitLoadByIndex(vi.refType, vi.index)
}

View file

@ -41,6 +41,10 @@ func (c *codegen) inlineCall(f *funcScope, n *ast.CallExpr) {
c.scope.vars.locals = newScope
c.scope.vars.addAlias(name, vi.refType, vi.index, vi.tv)
continue
} else if arg.Name == "nil" {
c.scope.vars.locals = newScope
c.scope.vars.addAlias(name, varLocal, unspecifiedVarIndex, types.TypeAndValue{})
continue
}
}
ast.Walk(c, n.Args[i])