From 57a0377c8119b90609045aa6bcb881e2b4f2fc8e Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Fri, 5 Feb 2021 17:26:26 +0300 Subject: [PATCH] compiler: load `nil` directly on inline --- pkg/compiler/codegen.go | 3 +++ pkg/compiler/inline.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index ea96ef834..a9b62d8cd 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -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) } diff --git a/pkg/compiler/inline.go b/pkg/compiler/inline.go index 417e5b857..55e0c8364 100644 --- a/pkg/compiler/inline.go +++ b/pkg/compiler/inline.go @@ -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])