forked from TrueCloudLab/neoneo-go
Merge pull request #1338 from nspcc-dev/fix/interop
compiler: allow to alias interop packages
This commit is contained in:
commit
e920b9e572
3 changed files with 28 additions and 2 deletions
|
@ -226,7 +226,7 @@ func isSyscall(fun *funcScope) bool {
|
||||||
if fun.selector == nil || fun.pkg == nil || !isInteropPath(fun.pkg.Path()) {
|
if fun.selector == nil || fun.pkg == nil || !isInteropPath(fun.pkg.Path()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
_, ok := syscalls[fun.selector.Name][fun.name]
|
_, ok := syscalls[fun.pkg.Name()][fun.name]
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -873,7 +873,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.CALLA)
|
emit.Opcode(c.prog.BinWriter, opcode.CALLA)
|
||||||
}
|
}
|
||||||
case isSyscall(f):
|
case isSyscall(f):
|
||||||
c.convertSyscall(n, f.selector.Name, f.name)
|
c.convertSyscall(n, f.pkg.Name(), f.name)
|
||||||
default:
|
default:
|
||||||
emit.Call(c.prog.BinWriter, opcode.CALLL, f.label)
|
emit.Call(c.prog.BinWriter, opcode.CALLL, f.label)
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,19 @@ func TestFromAddress(t *testing.T) {
|
||||||
|
|
||||||
eval(t, src, append(addr1.BytesBE(), addr2.BytesBE()...))
|
eval(t, src, append(addr1.BytesBE(), addr2.BytesBE()...))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("AliasPackage", func(t *testing.T) {
|
||||||
|
src := `
|
||||||
|
package foo
|
||||||
|
import uu "github.com/nspcc-dev/neo-go/pkg/interop/util"
|
||||||
|
func Main() []byte {
|
||||||
|
addr1 := uu.FromAddress("` + as1 + `")
|
||||||
|
addr2 := uu.FromAddress("` + as2 + `")
|
||||||
|
sum := append(addr1, addr2...)
|
||||||
|
return sum
|
||||||
|
}`
|
||||||
|
eval(t, src, append(addr1.BytesBE(), addr2.BytesBE()...))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func spawnVM(t *testing.T, ic *interop.Context, src string) *vm.VM {
|
func spawnVM(t *testing.T, ic *interop.Context, src string) *vm.VM {
|
||||||
|
@ -167,6 +180,19 @@ func TestAppCall(t *testing.T) {
|
||||||
|
|
||||||
assertResult(t, v, big.NewInt(42))
|
assertResult(t, v, big.NewInt(42))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("AliasPackage", func(t *testing.T) {
|
||||||
|
src := `package foo
|
||||||
|
import ee "github.com/nspcc-dev/neo-go/pkg/interop/engine"
|
||||||
|
func Main() int {
|
||||||
|
var addr = []byte(` + fmt.Sprintf("%#v", string(ih.BytesBE())) + `)
|
||||||
|
result := ee.AppCall(addr, "add3", 39)
|
||||||
|
return result.(int)
|
||||||
|
}`
|
||||||
|
v := spawnVM(t, ic, src)
|
||||||
|
require.NoError(t, v.Run())
|
||||||
|
assertResult(t, v, big.NewInt(42))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAppCallScript(h string) string {
|
func getAppCallScript(h string) string {
|
||||||
|
|
Loading…
Reference in a new issue