-/* return an optree that checks for too few or too many args -
- * used for subroutine signatures
- */
-OP *
-Perl_check_arity(pTHX_ int arity, bool max)
-{
- return
- newSTATEOP(0, NULL,
- newLOGOP(OP_OR, 0,
- newBINOP((max ? OP_LE : OP_GE), 0,
- scalar(newUNOP(OP_RV2AV, 0,
- newGVOP(OP_GV, 0, PL_defgv))
- ),
- newSVOP(OP_CONST, 0, newSViv(arity))
- ),
- op_convert_list(OP_DIE, 0,
- op_convert_list(OP_SPRINTF, 0,
- op_append_list(OP_LIST,
- newSVOP(OP_CONST, 0,
- max
- ? newSVpvs("Too many arguments for subroutine at %s line %d.\n")
- : newSVpvs("Too few arguments for subroutine at %s line %d.\n")
- ),
- newSLICEOP(0,
- op_append_list(OP_LIST,
- newSVOP(OP_CONST, 0, newSViv(1)),
- newSVOP(OP_CONST, 0, newSViv(2))),
- newOP(OP_CALLER, 0)
- )
- )
- )
- )
- )
- );
-}