mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
compiler: allow to inline global variables
This commit is contained in:
parent
6e560c6c9f
commit
cf459002f7
3 changed files with 36 additions and 0 deletions
|
@ -40,6 +40,7 @@ func TestInline(t *testing.T) {
|
|||
func sum(a, b int) int {
|
||||
return 42
|
||||
}
|
||||
var Num = 1
|
||||
func Main() int {
|
||||
%s
|
||||
}`
|
||||
|
@ -107,6 +108,11 @@ func TestInline(t *testing.T) {
|
|||
checkCallCount(t, src, 0, 1)
|
||||
eval(t, src, big.NewInt(42))
|
||||
})
|
||||
t.Run("globals", func(t *testing.T) {
|
||||
src := fmt.Sprintf(srcTmpl, `return inline.Concat(Num)`)
|
||||
checkCallCount(t, src, 0, 1)
|
||||
eval(t, src, big.NewInt(221))
|
||||
})
|
||||
}
|
||||
|
||||
func TestInlineConversion(t *testing.T) {
|
||||
|
@ -133,3 +139,25 @@ func TestInlineConversion(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, b2, b1)
|
||||
}
|
||||
|
||||
func TestInlineConversionQualified(t *testing.T) {
|
||||
src1 := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
|
||||
var A = 1
|
||||
func Main() int {
|
||||
return inline.Concat(A)
|
||||
}`
|
||||
b1, err := compiler.Compile("foo.go", strings.NewReader(src1))
|
||||
require.NoError(t, err)
|
||||
|
||||
src2 := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
|
||||
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline/b"
|
||||
var A = 1
|
||||
func Main() int {
|
||||
return A * 100 + b.A * 10 + inline.A
|
||||
}`
|
||||
b2, err := compiler.Compile("foo.go", strings.NewReader(src2))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, b2, b1)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue