MCPcopy Index your code
hub / github.com/yuin/gopher-lua / compileFuncCallExpr

Function compileFuncCallExpr

compile.go:1680–1731  ·  view source on GitHub ↗

}}}

(context *funcContext, reg int, expr *ast.FuncCallExpr, ec *expcontext)

Source from the content-addressed store, hash-verified

1678} // }}}
1679
1680func compileFuncCallExpr(context *funcContext, reg int, expr *ast.FuncCallExpr, ec *expcontext) int { // {{{
1681 funcreg := reg
1682 if ec.ctype == ecLocal && ec.reg == (int(context.Proto.NumParameters)-1) {
1683 funcreg = ec.reg
1684 reg = ec.reg
1685 }
1686 argc := len(expr.Args)
1687 islastvararg := false
1688 name := "(anonymous)"
1689
1690 if expr.Func != nil { // hoge.func()
1691 reg += compileExpr(context, reg, expr.Func, ecnone(0))
1692 name = getExprName(context, expr.Func)
1693 } else { // hoge:method()
1694 b := reg
1695 compileExprWithMVPropagation(context, expr.Receiver, &reg, &b)
1696 c := loadRk(context, &reg, expr, LString(expr.Method))
1697 context.Code.AddABC(OP_SELF, funcreg, b, c, sline(expr))
1698 // increments a register for an implicit "self"
1699 reg = b + 1
1700 reg2 := funcreg + 2
1701 if reg2 > reg {
1702 reg = reg2
1703 }
1704 argc += 1
1705 name = string(expr.Method)
1706 }
1707
1708 for i, ar := range expr.Args {
1709 islastvararg = (i == len(expr.Args)-1) && isVarArgReturnExpr(ar)
1710 if islastvararg {
1711 compileExpr(context, reg, ar, ecnone(-2))
1712 } else {
1713 reg += compileExpr(context, reg, ar, ecnone(0))
1714 }
1715 }
1716 b := argc + 1
1717 if islastvararg {
1718 b = 0
1719 }
1720 context.Code.AddABC(OP_CALL, funcreg, b, ec.varargopt+2, sline(expr))
1721 context.Proto.DbgCalls = append(context.Proto.DbgCalls, DbgCall{Pc: context.Code.LastPC(), Name: name})
1722
1723 if ec.varargopt == 0 && shouldmove(ec, funcreg) {
1724 context.Code.AddABC(OP_MOVE, ec.reg, funcreg, 0, sline(expr))
1725 return 1
1726 }
1727 if context.RegTop() > (funcreg+2+ec.varargopt) || ec.varargopt < -1 {
1728 return 0
1729 }
1730 return ec.varargopt + 1
1731} // }}}
1732
1733func loadRk(context *funcContext, reg *int, expr ast.Expr, cnst LValue) int { // {{{
1734 cindex := context.ConstIndex(cnst)

Callers 2

compileStmtFunction · 0.85
compileExprFunction · 0.85

Calls 12

compileExprFunction · 0.85
ecnoneFunction · 0.85
getExprNameFunction · 0.85
loadRkFunction · 0.85
LStringTypeAlias · 0.85
slineFunction · 0.85
isVarArgReturnExprFunction · 0.85
shouldmoveFunction · 0.85
AddABCMethod · 0.80
LastPCMethod · 0.80
RegTopMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…