From fdb217ec817d07a3fee789d9b18bb6ae67bc90b0 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 19 May 2020 18:15:03 +0300 Subject: [PATCH] compiler: process _ as a special variable It is more convenient to drop values inside `emitStoreVar` because this makes other code has less special cases. --- pkg/compiler/codegen.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 7f7c2758b..39659d6b3 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -207,6 +207,10 @@ func (c *codegen) emitLoadVar(name string) { // emitStoreVar stores top value from the evaluation stack in the specified variable. func (c *codegen) emitStoreVar(name string) { + if name == "_" { + emit.Opcode(c.prog.BinWriter, opcode.DROP) + return + } t, i := c.getVarIndex(name) _, base := getBaseOpcode(t) if i < 7 { @@ -401,12 +405,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor { if i == 0 || !multiRet { ast.Walk(c, n.Rhs[i]) } - - if t.Name == "_" { - emit.Opcode(c.prog.BinWriter, opcode.DROP) - } else { - c.emitStoreVar(t.Name) - } + c.emitStoreVar(t.Name) } case *ast.SelectorExpr: