forked from TrueCloudLab/neoneo-go
compiler: support delete()
builtin
This commit is contained in:
parent
18369c489e
commit
7483e3b054
3 changed files with 23 additions and 1 deletions
|
@ -14,7 +14,7 @@ import (
|
|||
|
||||
var (
|
||||
// Go language builtin functions.
|
||||
goBuiltins = []string{"len", "append", "panic", "make", "copy", "recover"}
|
||||
goBuiltins = []string{"len", "append", "panic", "make", "copy", "recover", "delete"}
|
||||
// Custom builtin utility functions.
|
||||
customBuiltins = []string{
|
||||
"FromAddress", "Equals",
|
||||
|
|
|
@ -1527,6 +1527,8 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
|||
}
|
||||
emit.Opcode(c.prog.BinWriter, opcode.PUSHNULL)
|
||||
c.emitStoreByIndex(varGlobal, c.exceptionIndex)
|
||||
case "delete":
|
||||
emit.Opcode(c.prog.BinWriter, opcode.REMOVE)
|
||||
case "ToInteger", "ToByteArray", "ToBool":
|
||||
typ := stackitem.IntegerT
|
||||
switch name {
|
||||
|
|
|
@ -55,6 +55,26 @@ var mapTestCases = []testCase{
|
|||
`,
|
||||
[]byte("Valera"),
|
||||
},
|
||||
{
|
||||
"delete key",
|
||||
`package foo
|
||||
func Main() int {
|
||||
m := map[int]int{1: 2, 3: 4}
|
||||
delete(m, 1)
|
||||
return len(m)
|
||||
}`,
|
||||
big.NewInt(1),
|
||||
},
|
||||
{
|
||||
"delete missing key",
|
||||
`package foo
|
||||
func Main() int {
|
||||
m := map[int]int{3: 4}
|
||||
delete(m, 1)
|
||||
return len(m)
|
||||
}`,
|
||||
big.NewInt(1),
|
||||
},
|
||||
}
|
||||
|
||||
func TestMaps(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue