Imported from CityOfZion/neo-storm (cbfc89972e977fa808e9f68c9ad5c6c18bef291d).
This commit is contained in:
Anthony De Meulemeester 2018-10-26 21:16:06 +02:00 committed by Roman Khimov
parent a765561b3a
commit 36b253872f

View file

@ -430,10 +430,29 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
if !isBuiltin { if !isBuiltin {
if numArgs == 2 { if numArgs == 2 {
emitOpcode(c.prog, vm.SWAP) emitOpcode(c.prog, vm.SWAP)
} } else if numArgs == 3 {
if numArgs == 3 {
emitInt(c.prog, 2) emitInt(c.prog, 2)
emitOpcode(c.prog, vm.XSWAP) emitOpcode(c.prog, vm.XSWAP)
} else {
half := int(numArgs / 2)
for i := 0; i < half; i++ {
to := numArgs - 1 - i
emitInt(c.prog, int64(to))
emitOpcode(c.prog, vm.PICK)
emitInt(c.prog, int64(i+1))
emitOpcode(c.prog, vm.PICK)
emitInt(c.prog, int64(to+2))
emitOpcode(c.prog, vm.XSWAP)
emitOpcode(c.prog, vm.DROP)
emitInt(c.prog, int64(i+1))
emitOpcode(c.prog, vm.XSWAP)
emitOpcode(c.prog, vm.DROP)
}
} }
} }