cl: _testpy/gcd

This commit is contained in:
xushiwei
2024-05-15 11:59:53 +08:00
parent 7881f3a53b
commit 9b742e777b
14 changed files with 311 additions and 51 deletions

View File

@@ -33,15 +33,19 @@ const (
)
func VArg() *types.Var {
return types.NewParam(0, nil, NameValist, types.Typ[types.Invalid])
return types.NewParam(0, nil, NameValist, types.NewSlice(tyAny))
}
func IsVArg(arg *types.Var) bool {
return arg.Name() == NameValist
}
func HasVArg(t *types.Tuple, n int) bool {
return n > 0 && IsVArg(t.At(n-1))
func HasVArg(t *types.Tuple, n int, sig *types.Signature) bool {
has := n > 0 && IsVArg(t.At(n-1))
if has && !sig.Variadic() { // TODO(xsw): remove this check
panic("HasVArg: varg must mark as variadic in signature")
}
return has
}
// -----------------------------------------------------------------------------
@@ -196,7 +200,7 @@ func newParams(fn Type, prog Program) (params []Type, hasVArg bool) {
sig := fn.raw.Type.(*types.Signature)
in := sig.Params()
if n := in.Len(); n > 0 {
if hasVArg = HasVArg(in, n); hasVArg {
if hasVArg = HasVArg(in, n, sig); hasVArg {
n--
}
params = make([]Type, n)