forked from TrueCloudLab/neoneo-go
compiler: make interface{}() conversions possible
This commit is contained in:
parent
ec3d1fae59
commit
6deb77a77a
3 changed files with 18 additions and 0 deletions
|
@ -25,6 +25,9 @@ a dialect of Go rather than a complete port of the language:
|
||||||
in variables and returning the result.
|
in variables and returning the result.
|
||||||
* lambdas are supported, but closures are not.
|
* lambdas are supported, but closures are not.
|
||||||
* maps are supported, but valid map keys are booleans, integers and strings with length <= 64
|
* maps are supported, but valid map keys are booleans, integers and strings with length <= 64
|
||||||
|
* converting value to interface type doesn't change the underlying type,
|
||||||
|
original value will always be used, therefore it never panics and always "succeeds";
|
||||||
|
it's up to the programmer whether it's a correct use of a value
|
||||||
|
|
||||||
## VM API (interop layer)
|
## VM API (interop layer)
|
||||||
Compiler translates interop function calls into NEO VM syscalls or (for custom
|
Compiler translates interop function calls into NEO VM syscalls or (for custom
|
||||||
|
|
|
@ -944,6 +944,11 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
||||||
ast.Walk(c, n.Args[0])
|
ast.Walk(c, n.Args[0])
|
||||||
c.emitConvert(stackitem.BufferT)
|
c.emitConvert(stackitem.BufferT)
|
||||||
return nil
|
return nil
|
||||||
|
case *ast.InterfaceType:
|
||||||
|
// It's a type conversion into some interface. Programmer is responsible
|
||||||
|
// for the conversion to be appropriate, just load the arg.
|
||||||
|
ast.Walk(c, n.Args[0])
|
||||||
|
return nil
|
||||||
case *ast.FuncLit:
|
case *ast.FuncLit:
|
||||||
isLiteral = true
|
isLiteral = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,3 +147,13 @@ func TestTypeConversionString(t *testing.T) {
|
||||||
}`
|
}`
|
||||||
eval(t, src, []byte("lamao"))
|
eval(t, src, []byte("lamao"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInterfaceTypeConversion(t *testing.T) {
|
||||||
|
src := `package foo
|
||||||
|
func Main() int {
|
||||||
|
a := 1
|
||||||
|
b := interface{}(a).(int)
|
||||||
|
return b
|
||||||
|
}`
|
||||||
|
eval(t, src, big.NewInt(1))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue