return my_var_g(aTHX_ OP_PADSV, flags, padoff);
}
-static SV *mkbits1(pTHX_ size_t n) {
- size_t bytes = n / 8, bits = n % 8;
- SV *sv = newSV(bytes + !!bits);
- char *p = SvPVX(sv), *q = p;
- while (bytes--) {
- *p++ = '\xff';
- }
- if (bits) {
- *p++ = (1u << bits) - 1;
- }
- *p = '\0';
- SvCUR_set(sv, p - q);
- SvPOK_on(sv);
- return sv;
-}
-
-static OP *mkvecbits(pTHX_ PADOFFSET padoff, size_t i) {
- OP *first, *mid, *last, *vec;
-
- last = newSVOP(OP_CONST, 0, newSViv(1));
- first = last;
-
- mid = newSVOP(OP_CONST, 0, newSViv(i));
- mid->op_sibling = first;
- first = mid;
-
- mid = my_var(aTHX_ 0, padoff);
- mid->op_sibling = first;
-
- first = newOP(OP_PUSHMARK, 0);
-
- vec = newLISTOP(OP_VEC, 0, first, mid);
- vec->op_targ = pad_alloc(OP_VEC, SVs_PADTMP);
- ((LISTOP *)vec)->op_last = last;
- op_null(((LISTOP *)vec)->op_first);
-
- return vec;
-}
-
-static OP *mkargselem(pTHX_ OP *index) {
- OP *args = newAVREF(newGVOP(OP_GV, 0, PL_defgv));
- args->op_flags |= OPf_REF;
-
- return newBINOP(OP_AELEM, 0, args, index);
-}
-
-static OP *mkargselemv(pTHX_ PADOFFSET v) {
- return mkargselem(aTHX_ my_var(aTHX_ 0, v));
-}
-
static OP *mkhvelem(pTHX_ PADOFFSET h, OP *k) {
OP *hv = my_var_g(aTHX_ OP_PADHV, OPf_REF, h);
return newBINOP(OP_HELEM, 0, hv, k);
*prelude_sentinel = op_append_list(OP_LINESEQ, *prelude_sentinel, newSTATEOP(0, NULL, clear));
}
}
-
- if (count_named_params(param_spec) && 0) {
- int nameblock_ix;
- OP *nameblock;
- PADOFFSET vb, vc, vi, vk;
- int vb_is_str, vc_is_str;
-
- {
- OP *lhs;
- size_t i, lim;
-
- lhs = NULL;
-
- for (i = 0, lim = param_spec->named_required.used; i < lim; i++) {
- OP *const var = my_var(
- aTHX_
- OPf_MOD | OPf_WANT_LIST | (OPpLVAL_INTRO << 8),
- param_spec->named_required.data[i].padoff
- );
- lhs = op_append_elem(OP_LIST, lhs, var);
- }
-
- for (i = 0, lim = param_spec->named_optional.used; i < lim; i++) {
- OP *const var = my_var(
- aTHX_
- OPf_MOD | OPf_WANT_LIST | (OPpLVAL_INTRO << 8),
- param_spec->named_optional.data[i].param.padoff
- );
- lhs = op_append_elem(OP_LIST, lhs, var);
- }
-
- lhs->op_flags |= OPf_PARENS;
- *prelude_sentinel = op_append_list(
- OP_LINESEQ, *prelude_sentinel,
- lhs
- );
- }
-
- nameblock = NULL;
- nameblock_ix = S_block_start(aTHX_ TRUE);
-
- {
- OP *decl, *var;
-
- decl = NULL;
-
- vb_is_str = param_spec->named_required.used > UV_BITS;
- if (!param_spec->named_required.used || !(spec->flags & FLAG_CHECK_NARGS)) {
- vb = 0;
- } else {
- var = newOP(OP_PADSV, OPf_MOD | (OPpLVAL_INTRO << 8));
- var->op_targ = vb = pad_add_name_pvs("$__B", 0, NULL, NULL);
- var = newASSIGNOP(OPf_STACKED, var, 0, newSVOP(OP_CONST, 0, vb_is_str ? newSVpvs("") : newSVuv(0)));
- decl = op_append_list(OP_LINESEQ, decl, newSTATEOP(0, NULL, var));
- }
-
- vc_is_str = param_spec->named_optional.used > UV_BITS;
- if (!param_spec->named_optional.used) {
- vc = 0;
- } else {
- var = newOP(OP_PADSV, OPf_MOD | (OPpLVAL_INTRO << 8));
- var->op_targ = vc = pad_add_name_pvs("$__C", 0, NULL, NULL);
- var = newASSIGNOP(OPf_STACKED, var, 0, newSVOP(OP_CONST, 0, vc_is_str ? newSVpvs("") : newSVuv(0)));
- decl = op_append_list(OP_LINESEQ, decl, newSTATEOP(0, NULL, var));
- }
-
- var = newOP(OP_PADSV, OPf_MOD | (OPpLVAL_INTRO << 8));
- var->op_targ = vk = pad_add_name_pvs("$__K", 0, NULL, NULL);
- decl = op_append_list(OP_LINESEQ, decl, newSTATEOP(0, NULL, var));
-
- var = newOP(OP_PADSV, OPf_MOD | (OPpLVAL_INTRO << 8));
- var->op_targ = vi = pad_add_name_pvs("$__I", 0, NULL, NULL);
- var = newASSIGNOP(OPf_STACKED, var, 0, newSVOP(OP_CONST, 0, newSViv(count_positional_params(param_spec))));
- decl = op_append_list(OP_LINESEQ, decl, newSTATEOP(0, NULL, var));
-
- nameblock = op_append_list(OP_LINESEQ, nameblock, decl);
- }
-
- {
- OP *loop;
-
- loop = NULL;
-
- loop = op_append_list(
- OP_LINESEQ,
- loop,
- newSTATEOP(
- 0, NULL,
- newASSIGNOP(
- OPf_STACKED,
- my_var(aTHX_ 0, vk),
- 0,
- mkargselemv(aTHX_ vi)
- )
- )
- );
-
- {
- OP *nest;
- size_t i;
-
- if (param_spec->slurpy.name) {
- if (SvPV_nolen(param_spec->slurpy.name)[0] == '@') {
- OP *first, *mid, *last;
-
- last = mkargselem(
- aTHX_
- newBINOP(
- OP_ADD, 0,
- my_var(aTHX_ 0, vi),
- newSVOP(OP_CONST, 0, newSViv(1))
- )
- );
- mid = last;
-
- first = my_var(aTHX_ 0, vk);
- first->op_sibling = mid;
- mid = first;
-
- first = my_var_g(aTHX_ OP_PADAV, 0, param_spec->slurpy.padoff);
- first->op_sibling = mid;
- mid = first;
-
- first = newOP(OP_PUSHMARK, 0);
- nest = newLISTOP(OP_PUSH, 0, first, mid);
- nest->op_targ = pad_alloc(OP_PUSH, SVs_PADTMP);
- ((LISTOP *)nest)->op_last = last;
- } else {
- nest = newASSIGNOP(
- OPf_STACKED,
- newBINOP(
- OP_HELEM, 0,
- my_var_g(aTHX_ OP_PADHV, 0, param_spec->slurpy.padoff),
- my_var(aTHX_ 0, vk)
- ),
- 0,
- mkargselem(
- aTHX_
- newBINOP(
- OP_ADD, 0,
- my_var(aTHX_ 0, vi),
- newSVOP(OP_CONST, 0, newSViv(1))
- )
- )
- );
- }
- } else if (spec->flags & FLAG_CHECK_NARGS) {
- OP *err, *croak;
-
- err = newSVOP(OP_CONST, 0,
- newSVpvf("In %"SVf": no such named parameter: ", SVfARG(declarator)));
- err = newBINOP(
- OP_CONCAT, 0,
- err,
- my_var(aTHX_ 0, vk)
- );
-
- croak = newCVREF(OPf_WANT_SCALAR,
- newGVOP(OP_GV, 0, gv_fetchpvs("Carp::croak", 0, SVt_PVCV)));
- nest = newUNOP(OP_ENTERSUB, OPf_STACKED,
- op_append_elem(OP_LIST, err, croak));
- } else {
- nest = NULL;
- }
-
- for (i = param_spec->named_optional.used; i--; ) {
- Param *cur = ¶m_spec->named_optional.data[i].param;
- size_t dn;
- char *dp = SvPV(cur->name, dn);
- OP *vec;
-
- if (!(spec->flags & FLAG_CHECK_NARGS)) {
- vec = NULL;
- } else if (vc_is_str) {
- vec = newASSIGNOP(
- OPf_STACKED,
- mkvecbits(aTHX_ vc, i),
- 0,
- newSVOP(OP_CONST, 0, newSViv(1))
- );
- } else {
- vec = newASSIGNOP(
- OPf_STACKED,
- my_var(aTHX_ 0, vc),
- OP_BIT_OR,
- newSVOP(OP_CONST, 0, newSVuv((UV)1 << i))
- );
- }
-
- nest = newCONDOP(
- 0,
- newBINOP(
- OP_SEQ, 0,
- my_var(aTHX_ 0, vk),
- newSVOP(OP_CONST, 0, newSVpvn_utf8(dp + 1, dn - 1, SvUTF8(cur->name)))
- ),
- op_append_list(
- OP_LINESEQ,
- newASSIGNOP(
- OPf_STACKED,
- my_var(aTHX_ 0, cur->padoff),
- 0,
- mkargselem(
- aTHX_
- newBINOP(
- OP_ADD, 0,
- my_var(aTHX_ 0, vi),
- newSVOP(OP_CONST, 0, newSViv(1))
- )
- )
- ),
- vec
- ),
- nest
- );
- }
-
- for (i = param_spec->named_required.used; i--; ) {
- Param *cur = ¶m_spec->named_required.data[i];
- size_t dn;
- char *dp = SvPV(cur->name, dn);
- OP *vec;
-
- if (!(spec->flags & FLAG_CHECK_NARGS)) {
- vec = NULL;
- } else if (vb_is_str) {
- vec = newASSIGNOP(
- OPf_STACKED,
- mkvecbits(aTHX_ vb, i),
- 0,
- newSVOP(OP_CONST, 0, newSViv(1))
- );
- } else {
- vec = newASSIGNOP(
- OPf_STACKED,
- my_var(aTHX_ 0, vb),
- OP_BIT_OR,
- newSVOP(OP_CONST, 0, newSVuv((UV)1 << i))
- );
- }
-
- nest = newCONDOP(
- 0,
- newBINOP(
- OP_SEQ, 0,
- my_var(aTHX_ 0, vk),
- newSVOP(OP_CONST, 0, newSVpvn_utf8(dp + 1, dn - 1, SvUTF8(cur->name)))
- ),
- op_append_list(
- OP_LINESEQ,
- newASSIGNOP(
- OPf_STACKED,
- my_var(aTHX_ 0, cur->padoff),
- 0,
- mkargselem(
- aTHX_
- newBINOP(
- OP_ADD, 0,
- my_var(aTHX_ 0, vi),
- newSVOP(OP_CONST, 0, newSViv(1))
- )
- )
- ),
- vec
- ),
- nest
- );
- }
-
- loop = op_append_elem(OP_LINESEQ, loop, newSTATEOP(0, NULL, nest));
- }
-
- loop = newWHILEOP(
- 0, 1,
- NULL,
- newBINOP(
- OP_LT, 0,
- my_var(aTHX_ 0, vi),
- newAVREF(newGVOP(OP_GV, 0, PL_defgv))
- ),
- loop,
- newASSIGNOP(
- OPf_STACKED,
- my_var(aTHX_ 0, vi),
- OP_ADD,
- newSVOP(OP_CONST, 0, newSViv(2))
- ),
- 0
- );
-
- nameblock = op_append_list(OP_LINESEQ, nameblock, newSTATEOP(0, NULL, loop));
- }
-
- if (param_spec->named_required.used && (spec->flags & FLAG_CHECK_NARGS)) {
- OP *cond, *err, *croak, *join;
-
- {
- size_t i, lim;
- OP *first, *mid, *last;
-
- last = newNULLLIST();
- mid = last;
-
- for (i = param_spec->named_required.used; i--; ) {
- OP *cur;
- SV *sv = param_spec->named_required.data[i].name;
- size_t n;
- char *p = SvPV(sv, n);
- cur = newCONDOP(
- 0,
- vb_is_str
- ? mkvecbits(aTHX_ vb, i)
- : newBINOP(OP_BIT_AND, 0, my_var(aTHX_ 0, vb), newSVOP(OP_CONST, 0, newSVuv((UV)1 << i)))
- ,
- newNULLLIST(),
- newSVOP(OP_CONST, 0, newSVpvn_utf8(p + 1, n - 1, SvUTF8(sv)))
- );
- cur->op_sibling = mid;
- mid = cur;
- }
-
- first = newSVOP(OP_CONST, 0, newSVpvs(", "));
- first->op_sibling = mid;
- mid = first;
-
- first = newOP(OP_PUSHMARK, 0);
-
- join = newLISTOP(OP_JOIN, 0, first, mid);
- join->op_targ = pad_alloc(OP_JOIN, SVs_PADTMP);
- ((LISTOP *)join)->op_last = last;
- }
-
- err = newSVOP(
- OP_CONST, 0,
- newSVpvf("In %"SVf": missing named parameter(s): ", SVfARG(declarator))
- );
- err = newBINOP(OP_CONCAT, 0, err, join);
- croak = newCVREF(
- OPf_WANT_SCALAR,
- newGVOP(OP_GV, 0, gv_fetchpvs("Carp::croak", 0, SVt_PVCV))
- );
- err = newUNOP(
- OP_ENTERSUB,
- OPf_STACKED,
- op_append_elem(OP_LIST, err, croak)
- );
- if (vb_is_str) {
- cond = newBINOP(
- OP_SNE, 0,
- my_var(aTHX_ 0, vb),
- newSVOP(OP_CONST, 0, mkbits1(aTHX_ param_spec->named_required.used))
- );
- } else {
- cond = newBINOP(
- OP_NE, 0,
- my_var(aTHX_ 0, vb),
- newSVOP(
- OP_CONST, 0,
- newSVuv(
- param_spec->named_required.used == UV_BITS
- ? ~(UV)0
- : ((UV)1 << param_spec->named_required.used) - 1
- )
- )
- );
- }
- err = newCONDOP(
- 0,
- cond,
- err,
- NULL
- );
-
- nameblock = op_append_list(OP_LINESEQ, nameblock, err);
- }
-
- if (param_spec->named_optional.used) {
- size_t i, lim;
-
- for (i = 0, lim = param_spec->named_optional.used; i < lim; i++) {
- ParamInit *const cur = ¶m_spec->named_optional.data[i];
- OP *init, *cond;
-
- init = newASSIGNOP(
- OPf_STACKED,
- my_var(aTHX_ 0, cur->param.padoff),
- 0,
- cur->init
- );
- cur->init = NULL;
-
- cond = vc_is_str
- ? mkvecbits(aTHX_ vc, i)
- : newBINOP(OP_BIT_AND, 0, my_var(aTHX_ 0, vc), newSVOP(OP_CONST, 0, newSVuv((UV)1 << i)))
- ;
-
- init = newCONDOP(0, cond, NULL, init);
-
- nameblock = op_append_list(OP_LINESEQ, nameblock, newSTATEOP(0, NULL, init));
- }
- }
-
- nameblock = S_block_end(aTHX_ nameblock_ix, nameblock);
- nameblock = op_scope(nameblock);
-
- *prelude_sentinel = op_append_list(OP_LINESEQ, *prelude_sentinel, nameblock);
- }
}
/* finally let perl parse the actual subroutine body */