compiler: support make()
This commit is contained in:
parent
d8badd9a8d
commit
0f11116040
5 changed files with 70 additions and 3 deletions
|
@ -1305,6 +1305,24 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "make":
|
||||
typ := c.typeOf(expr.Args[0])
|
||||
switch {
|
||||
case isMap(typ):
|
||||
emit.Opcode(c.prog.BinWriter, opcode.NEWMAP)
|
||||
default:
|
||||
if len(expr.Args) == 3 {
|
||||
c.prog.Err = fmt.Errorf("`make()` with a capacity argument is not supported")
|
||||
return
|
||||
}
|
||||
ast.Walk(c, expr.Args[1])
|
||||
if isByteSlice(typ) {
|
||||
emit.Opcode(c.prog.BinWriter, opcode.NEWBUFFER)
|
||||
} else {
|
||||
neoT := toNeoType(typ.(*types.Slice).Elem())
|
||||
emit.Instruction(c.prog.BinWriter, opcode.NEWARRAYT, []byte{byte(neoT)})
|
||||
}
|
||||
}
|
||||
case "len":
|
||||
emit.Opcode(c.prog.BinWriter, opcode.DUP)
|
||||
emit.Opcode(c.prog.BinWriter, opcode.ISNULL)
|
||||
|
@ -1397,6 +1415,9 @@ func transformArgs(fun ast.Expr, args []ast.Expr) []ast.Expr {
|
|||
if f.Name == "panic" {
|
||||
return args[1:]
|
||||
}
|
||||
if f.Name == "make" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return args
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue