forked from TrueCloudLab/neoneo-go
compiler: allow to use copy()
return value
This commit is contained in:
parent
3d8c7af66c
commit
3af7ce8c6b
2 changed files with 18 additions and 0 deletions
|
@ -1455,6 +1455,14 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
||||||
emit.Int(c.prog.BinWriter, 3)
|
emit.Int(c.prog.BinWriter, 3)
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.ROLL)
|
emit.Opcode(c.prog.BinWriter, opcode.ROLL)
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.MIN)
|
emit.Opcode(c.prog.BinWriter, opcode.MIN)
|
||||||
|
if !c.scope.voidCalls[expr] {
|
||||||
|
// insert top item to the bottom of MEMCPY args, so that it is left on stack
|
||||||
|
emit.Opcode(c.prog.BinWriter, opcode.DUP)
|
||||||
|
emit.Int(c.prog.BinWriter, 6)
|
||||||
|
emit.Opcode(c.prog.BinWriter, opcode.REVERSEN)
|
||||||
|
emit.Int(c.prog.BinWriter, 5)
|
||||||
|
emit.Opcode(c.prog.BinWriter, opcode.REVERSEN)
|
||||||
|
}
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.MEMCPY)
|
emit.Opcode(c.prog.BinWriter, opcode.MEMCPY)
|
||||||
case "make":
|
case "make":
|
||||||
typ := c.typeOf(expr.Args[0])
|
typ := c.typeOf(expr.Args[0])
|
||||||
|
|
|
@ -427,4 +427,14 @@ func TestCopy(t *testing.T) {
|
||||||
}`
|
}`
|
||||||
eval(t, src, []byte{0, 3})
|
eval(t, src, []byte{0, 3})
|
||||||
})
|
})
|
||||||
|
t.Run("AssignToVariable", func(t *testing.T) {
|
||||||
|
src := `package foo
|
||||||
|
func Main() int {
|
||||||
|
src := []byte{3, 2, 1}
|
||||||
|
dst := make([]byte, 2)
|
||||||
|
n := copy(dst, src)
|
||||||
|
return n
|
||||||
|
}`
|
||||||
|
eval(t, src, big.NewInt(2))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue