mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
compiler: allow to inline var arg functions
This commit is contained in:
parent
339187a56d
commit
6e560c6c9f
4 changed files with 57 additions and 4 deletions
|
@ -892,10 +892,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
typ, ok := c.typeOf(n.Fun).(*types.Signature)
|
||||
if ok && typ.Variadic() && !n.Ellipsis.IsValid() {
|
||||
// pack variadic args into an array only if last argument is not of form `...`
|
||||
varSize := len(n.Args) - typ.Params().Len() + 1
|
||||
c.emitReverse(varSize)
|
||||
emit.Int(c.prog.BinWriter, int64(varSize))
|
||||
emit.Opcodes(c.prog.BinWriter, opcode.PACK)
|
||||
varSize := c.packVarArgs(n, typ)
|
||||
numArgs -= varSize - 1
|
||||
}
|
||||
c.emitReverse(numArgs)
|
||||
|
@ -1232,6 +1229,16 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
return c
|
||||
}
|
||||
|
||||
// packVarArgs packs variadic arguments into an array
|
||||
// and returns amount of arguments packed.
|
||||
func (c *codegen) packVarArgs(n *ast.CallExpr, typ *types.Signature) int {
|
||||
varSize := len(n.Args) - typ.Params().Len() + 1
|
||||
c.emitReverse(varSize)
|
||||
emit.Int(c.prog.BinWriter, int64(varSize))
|
||||
emit.Opcodes(c.prog.BinWriter, opcode.PACK)
|
||||
return varSize
|
||||
}
|
||||
|
||||
// processDefers emits code for `defer` statements.
|
||||
// TRY-related opcodes handle exception as follows:
|
||||
// 1. CATCH block is executed only if exception has occurred.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue