compiler: process _ as a special variable

It is more convenient to drop values inside `emitStoreVar` because this
makes other code has less special cases.
This commit is contained in:
Evgenii Stratonikov 2020-05-19 18:15:03 +03:00
parent 3926456d86
commit fdb217ec81

View file

@ -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: