TestFuncCall

This commit is contained in:
xushiwei
2024-04-19 00:05:57 +08:00
parent a966e02273
commit c784a2e63b
7 changed files with 188 additions and 58 deletions

View File

@@ -103,29 +103,39 @@ type Global = *aGlobal
// the generic method. TypeArgs() refers to [string,U] or [string,int],
// respectively, and is nil in the generic method.
type aFunction struct {
impl llvm.Value
Type
Expr
prog Program
params []Type
ret Type
}
type Function = *aFunction
func newFunction(fn llvm.Value, t Type, prog Program) Function {
ret := &aFunction{fn, t, prog, newParams(t, prog)}
return ret
params, ret := newParamsAndRet(t, prog)
return &aFunction{Expr{fn, t}, prog, params, ret}
}
func newParams(fn Type, prog Program) []Type {
in := fn.t.(*types.Signature).Params()
n := in.Len()
ret := make([]Type, n)
for i := 0; i < n; i++ {
ret[i] = prog.llvmType(in.At(i).Type())
func newParamsAndRet(fn Type, prog Program) (params []Type, ret Type) {
sig := fn.t.(*types.Signature)
in := sig.Params()
if n := in.Len(); n > 0 {
params = make([]Type, n)
for i := 0; i < n; i++ {
params[i] = prog.llvmType(in.At(i).Type())
}
}
return ret
out := sig.Results()
switch n := out.Len(); n {
case 0:
ret = prog.Void()
case 1:
ret = prog.llvmType(out.At(0).Type())
default:
ret = &aType{prog.toLLVMTuple(out), out, vkTuple}
}
return
}
func (p Function) Param(i int) Expr {