3 * Copyright (c) 1991-1994, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "You see: Mr. Drogo, he married poor Miss Primula Brandybuck. She was
12 * our Mr. Bilbo's first cousin on the mother's side (her mother being the
13 * youngest of the Old Took's daughters); and Mr. Drogo was his second
14 * cousin. So Mr. Frodo is his first *and* second cousin, once removed
15 * either way, as the saying is, if you follow me." --the Gaffer
21 #define USE_OP_MASK /* Turned on by default in 5.002beta1h */
25 * In the following definition, the ", (OP *) op" is just to make the compiler
26 * think the expression is of the right type: croak actually does a Siglongjmp.
28 #define CHECKOP(type,op) \
29 ((op_mask && op_mask[type]) \
30 ? (croak("%s trapped by operation mask", op_desc[type]), (OP*)op) \
31 : (*check[type])((OP*)op))
33 #define CHECKOP(type,op) (*check[type])(op)
34 #endif /* USE_OP_MASK */
36 static I32 list_assignment _((OP *op));
37 static OP *bad_type _((I32 n, char *t, char *name, OP *kid));
38 static OP *modkids _((OP *op, I32 type));
39 static OP *no_fh_allowed _((OP *op));
40 static OP *scalarboolean _((OP *op));
41 static OP *too_few_arguments _((OP *op, char* name));
42 static OP *too_many_arguments _((OP *op, char* name));
43 static void null _((OP* op));
44 static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, U32 seq,
45 CV* startcv, I32 cx_ix));
51 SV* tmpsv = sv_newmortal();
52 gv_efullname3(tmpsv, CvGV(cv), Nullch);
53 return SvPV(tmpsv,na);
60 sprintf(tokenbuf,"Missing comma after first argument to %s function",
61 op_desc[op->op_type]);
67 too_few_arguments(op, name)
71 sprintf(tokenbuf,"Not enough arguments for %s", name);
77 too_many_arguments(op, name)
81 sprintf(tokenbuf,"Too many arguments for %s", name);
87 bad_type(n, t, name, kid)
93 sprintf(tokenbuf, "Type of arg %d to %s must be %s (not %s)",
94 (int) n, name, t, op_desc[kid->op_type]);
103 int type = op->op_type;
104 if (type != OP_AELEM && type != OP_HELEM) {
105 sprintf(tokenbuf, "Can't use subscript on %s", op_desc[type]);
107 if (type == OP_RV2HV || type == OP_ENTERSUB)
108 warn("(Did you mean $ or @ instead of %c?)\n",
109 type == OP_RV2HV ? '%' : '&');
113 /* "register" allocation */
122 if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) {
123 if (!isPRINT(name[1]))
124 sprintf(name+1, "^%c", toCTRL(name[1])); /* XXX tokenbuf, really */
125 croak("Can't use global %s in \"my\"",name);
127 if (AvFILL(comppad_name) >= 0) {
128 SV **svp = AvARRAY(comppad_name);
129 for (off = AvFILL(comppad_name); off > comppad_name_floor; off--) {
132 && SvIVX(sv) == 999999999 /* var is in open scope */
133 && strEQ(name, SvPVX(sv)))
135 warn("\"my\" variable %s masks earlier declaration in same scope", name);
140 off = pad_alloc(OP_PADSV, SVs_PADMY);
142 sv_upgrade(sv, SVt_PVNV);
144 av_store(comppad_name, off, sv);
145 SvNVX(sv) = (double)999999999;
146 SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */
147 if (!min_intro_pending)
148 min_intro_pending = off;
149 max_intro_pending = off;
151 av_store(comppad, off, (SV*)newAV());
152 else if (*name == '%')
153 av_store(comppad, off, (SV*)newHV());
154 SvPADMY_on(curpad[off]);
159 #ifndef CAN_PROTOTYPE
160 pad_findlex(name, newoff, seq, startcv, cx_ix)
167 pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
174 register CONTEXT *cx;
177 for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
178 AV* curlist = CvPADLIST(cv);
179 SV** svp = av_fetch(curlist, 0, FALSE);
181 if (!svp || *svp == &sv_undef)
184 svp = AvARRAY(curname);
185 for (off = AvFILL(curname); off > 0; off--) {
186 if ((sv = svp[off]) &&
189 seq > I_32(SvNVX(sv)) &&
190 strEQ(SvPVX(sv), name))
199 return 0; /* don't clone inactive stack frame */
202 oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
203 oldsv = *av_fetch(oldpad, off, TRUE);
204 if (!newoff) { /* Not a mere clone operation. */
205 SV *sv = NEWSV(1103,0);
206 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
207 sv_upgrade(sv, SVt_PVNV);
209 av_store(comppad_name, newoff, sv);
210 SvNVX(sv) = (double)curcop->cop_seq;
211 SvIVX(sv) = 999999999; /* A ref, intro immediately */
212 SvFLAGS(sv) |= SVf_FAKE;
213 /* "It's closures all the way down." */
218 bcv && bcv != cv && !CvCLONE(bcv);
219 bcv = CvOUTSIDE(bcv))
223 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
229 /* Nothing in current lexical context--try eval's context, if any.
230 * This is necessary to let the perldb get at lexically scoped variables.
231 * XXX This will also probably interact badly with eval tree caching.
235 for (i = cx_ix; i >= 0; i--) {
237 switch (cx->cx_type) {
239 if (i == 0 && saweval) {
240 seq = cxstack[saweval].blk_oldcop->cop_seq;
241 return pad_findlex(name, newoff, seq, main_cv, 0);
245 if (cx->blk_eval.old_op_type != OP_ENTEREVAL &&
246 cx->blk_eval.old_op_type != OP_ENTERTRY)
247 return 0; /* require must have its own scope */
254 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
255 saweval = i; /* so we know where we were called from */
258 seq = cxstack[saweval].blk_oldcop->cop_seq;
259 return pad_findlex(name, newoff, seq, cv, i-1);
272 SV **svp = AvARRAY(comppad_name);
273 U32 seq = cop_seqmax;
275 /* The one we're looking for is probably just before comppad_name_fill. */
276 for (off = AvFILL(comppad_name); off > 0; off--) {
277 if ((sv = svp[off]) &&
280 seq > I_32(SvNVX(sv)) &&
281 strEQ(SvPVX(sv), name))
283 return (PADOFFSET)off;
287 /* See if it's in a nested scope */
288 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
300 SV **svp = AvARRAY(comppad_name);
302 if (min_intro_pending && fill < min_intro_pending) {
303 for (off = max_intro_pending; off >= min_intro_pending; off--) {
304 if ((sv = svp[off]) && sv != &sv_undef)
305 warn("%s never introduced", SvPVX(sv));
308 /* "Deintroduce" my variables that are leaving with this scope. */
309 for (off = AvFILL(comppad_name); off > fill; off--) {
310 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
311 SvIVX(sv) = cop_seqmax;
316 pad_alloc(optype,tmptype)
323 if (AvARRAY(comppad) != curpad)
324 croak("panic: pad_alloc");
325 if (pad_reset_pending)
327 if (tmptype & SVs_PADMY) {
329 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
330 } while (SvPADBUSY(sv)); /* need a fresh one */
331 retval = AvFILL(comppad);
334 SV **names = AvARRAY(comppad_name);
335 SSize_t names_fill = AvFILL(comppad_name);
338 * "foreach" index vars temporarily become aliases to non-"my"
339 * values. Thus we must skip, not just pad values that are
340 * marked as current pad values, but also those with names.
342 if (++padix <= names_fill &&
343 (sv = names[padix]) && sv != &sv_undef)
345 sv = *av_fetch(comppad, padix, TRUE);
346 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
351 SvFLAGS(sv) |= tmptype;
352 curpad = AvARRAY(comppad);
353 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
354 return (PADOFFSET)retval;
358 #ifndef CAN_PROTOTYPE
363 #endif /* CAN_PROTOTYPE */
366 croak("panic: pad_sv po");
367 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad sv %d\n", po));
368 return curpad[po]; /* eventually we'll turn this into a macro */
372 #ifndef CAN_PROTOTYPE
376 pad_free(PADOFFSET po)
377 #endif /* CAN_PROTOTYPE */
381 if (AvARRAY(comppad) != curpad)
382 croak("panic: pad_free curpad");
384 croak("panic: pad_free po");
385 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad free %d\n", po));
386 if (curpad[po] && curpad[po] != &sv_undef)
387 SvPADTMP_off(curpad[po]);
393 #ifndef CAN_PROTOTYPE
397 pad_swipe(PADOFFSET po)
398 #endif /* CAN_PROTOTYPE */
400 if (AvARRAY(comppad) != curpad)
401 croak("panic: pad_swipe curpad");
403 croak("panic: pad_swipe po");
404 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad swipe %d\n", po));
405 SvPADTMP_off(curpad[po]);
406 curpad[po] = NEWSV(1107,0);
407 SvPADTMP_on(curpad[po]);
417 if (AvARRAY(comppad) != curpad)
418 croak("panic: pad_reset curpad");
419 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad reset\n"));
420 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
421 for (po = AvMAX(comppad); po > padix_floor; po--) {
422 if (curpad[po] && curpad[po] != &sv_undef)
423 SvPADTMP_off(curpad[po]);
427 pad_reset_pending = FALSE;
436 register OP *kid, *nextkid;
438 if (!op || op->op_seq == (U16)-1)
441 if (op->op_flags & OPf_KIDS) {
442 for (kid = cUNOP->op_first; kid; kid = nextkid) {
443 nextkid = kid->op_sibling; /* Get before next freeing kid */
448 switch (op->op_type) {
450 op->op_targ = 0; /* Was holding old type, if any. */
453 op->op_targ = 0; /* Was holding hints. */
457 SvREFCNT_dec(cGVOP->op_gv);
461 Safefree(cCOP->cop_label);
462 SvREFCNT_dec(cCOP->cop_filegv);
465 SvREFCNT_dec(cSVOP->op_sv);
471 if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
475 Safefree(cPVOP->op_pv);
478 op_free(cPMOP->op_pmreplroot);
482 pregfree(cPMOP->op_pmregexp);
483 SvREFCNT_dec(cPMOP->op_pmshort);
490 pad_free(op->op_targ);
499 if (op->op_type != OP_NULL && op->op_targ > 0)
500 pad_free(op->op_targ);
501 op->op_targ = op->op_type;
502 op->op_type = OP_NULL;
503 op->op_ppaddr = ppaddr[OP_NULL];
506 /* Contextualizers */
508 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
519 /* establish postfix order */
520 if (cUNOP->op_first) {
521 op->op_next = LINKLIST(cUNOP->op_first);
522 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
524 kid->op_next = LINKLIST(kid->op_sibling);
540 if (op && op->op_flags & OPf_KIDS) {
541 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
552 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
553 line_t oldline = curcop->cop_line;
555 if (copline != NOLINE)
556 curcop->cop_line = copline;
557 warn("Found = in conditional, should be ==");
558 curcop->cop_line = oldline;
569 /* assumes no premature commitment */
570 if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
574 op->op_flags &= ~OPf_LIST;
575 op->op_flags |= OPf_KNOW;
577 switch (op->op_type) {
579 if (op->op_private & OPpREPEAT_DOLIST)
580 null(((LISTOP*)cBINOP->op_first)->op_first);
581 scalar(cBINOP->op_first);
586 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
590 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
591 if (!kPMOP->op_pmreplroot)
592 deprecate("implicit split to @_");
599 if (op->op_flags & OPf_KIDS) {
600 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
606 scalar(cLISTOP->op_first);
611 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
631 if (!op || error_count)
633 if (op->op_flags & OPf_LIST)
636 op->op_flags |= OPf_KNOW;
638 switch (op->op_type) {
640 if (!(opargs[op->op_type] & OA_FOLDCONST))
644 if (op->op_flags & OPf_STACKED)
717 if (!(op->op_private & OPpLVAL_INTRO))
718 useless = op_desc[op->op_type];
725 if (!(op->op_private & OPpLVAL_INTRO) &&
726 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
727 useless = "a variable";
732 curcop = ((COP*)op); /* for warning below */
738 useless = "a constant";
739 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
741 else if (SvPOK(sv)) {
742 if (strnEQ(SvPVX(sv), "di", 2) ||
743 strnEQ(SvPVX(sv), "ds", 2) ||
744 strnEQ(SvPVX(sv), "ig", 2))
748 null(op); /* don't execute a constant */
749 SvREFCNT_dec(sv); /* don't even remember it */
753 op->op_type = OP_PREINC; /* pre-increment is faster */
754 op->op_ppaddr = ppaddr[OP_PREINC];
758 op->op_type = OP_PREDEC; /* pre-decrement is faster */
759 op->op_ppaddr = ppaddr[OP_PREDEC];
765 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
769 if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
770 curcop = ((COP*)op); /* for warning below */
771 if (op->op_flags & OPf_STACKED)
776 if (!(op->op_flags & OPf_KIDS))
782 op->op_private |= OPpLEAVE_VOID;
785 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
789 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
790 if (!kPMOP->op_pmreplroot)
791 deprecate("implicit split to @_");
795 op->op_private |= OPpLEAVE_VOID;
798 if (useless && dowarn)
799 warn("Useless use of %s in void context", useless);
808 if (op && op->op_flags & OPf_KIDS) {
809 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
821 /* assumes no premature commitment */
822 if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
826 op->op_flags |= (OPf_KNOW | OPf_LIST);
828 switch (op->op_type) {
831 list(cBINOP->op_first);
836 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
843 if (!(op->op_flags & OPf_KIDS))
845 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
846 list(cBINOP->op_first);
847 return gen_constant_list(op);
854 list(cLISTOP->op_first);
858 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
877 if (op->op_type == OP_LINESEQ ||
878 op->op_type == OP_SCOPE ||
879 op->op_type == OP_LEAVE ||
880 op->op_type == OP_LEAVETRY)
882 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
883 if (kid->op_sibling) {
889 op->op_flags &= ~OPf_PARENS;
890 if (hints & HINT_BLOCK_SCOPE)
891 op->op_flags |= OPf_PARENS;
894 op = newOP(OP_STUB, 0);
904 if (op && op->op_flags & OPf_KIDS) {
905 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
921 if (!op || error_count)
924 switch (op->op_type) {
926 if (!(op->op_private & (OPpCONST_ARYBASE)))
928 if (eval_start && eval_start->op_type == OP_CONST) {
929 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
933 SAVEI32(compiling.cop_arybase);
934 compiling.cop_arybase = 0;
936 else if (type == OP_REFGEN)
939 croak("That use of $[ is unsupported");
942 if (op->op_flags & OPf_PARENS)
946 if ((type == OP_UNDEF || type == OP_REFGEN) &&
947 !(op->op_flags & OPf_STACKED)) {
948 op->op_type = OP_RV2CV; /* entersub => rv2cv */
949 op->op_ppaddr = ppaddr[OP_RV2CV];
950 assert(cUNOP->op_first->op_type == OP_NULL);
951 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
957 /* grep, foreach, subcalls, refgen */
958 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
960 sprintf(tokenbuf, "Can't modify %s in %s",
961 op_desc[op->op_type],
962 type ? op_desc[type] : "local");
986 if (!(op->op_flags & OPf_STACKED))
992 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
998 if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
1000 return op; /* Treat \(@foo) like ordinary list. */
1004 ref(cUNOP->op_first, op->op_type);
1016 if (!type && cUNOP->op_first->op_type != OP_GV)
1017 croak("Can't localize a reference");
1018 ref(cUNOP->op_first, op->op_type);
1031 if (type == OP_REFGEN && op->op_flags & OPf_PARENS)
1032 return op; /* Treat \(@foo) like ordinary list. */
1037 croak("Can't localize lexical variable %s",
1038 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
1045 if (type != OP_SASSIGN)
1051 pad_free(op->op_targ);
1052 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
1053 assert(SvTYPE(PAD_SV(op->op_targ)) == SVt_NULL);
1054 if (op->op_flags & OPf_KIDS)
1055 mod(cBINOP->op_first->op_sibling, type);
1060 ref(cBINOP->op_first, op->op_type);
1067 if (op->op_flags & OPf_KIDS)
1068 mod(cLISTOP->op_last, type);
1072 if (!(op->op_flags & OPf_KIDS))
1074 if (op->op_targ != OP_LIST) {
1075 mod(cBINOP->op_first, type);
1080 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1084 op->op_flags |= OPf_MOD;
1086 if (type == OP_AASSIGN || type == OP_SASSIGN)
1087 op->op_flags |= OPf_SPECIAL|OPf_REF;
1089 op->op_private |= OPpLVAL_INTRO;
1090 op->op_flags &= ~OPf_SPECIAL;
1092 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1093 op->op_flags |= OPf_REF;
1103 if (op && op->op_flags & OPf_KIDS) {
1104 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1117 if (!op || error_count)
1120 switch (op->op_type) {
1122 if ((type == OP_DEFINED) &&
1123 !(op->op_flags & OPf_STACKED)) {
1124 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1125 op->op_ppaddr = ppaddr[OP_RV2CV];
1126 assert(cUNOP->op_first->op_type == OP_NULL);
1127 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1128 op->op_flags |= OPf_SPECIAL;
1133 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1137 ref(cUNOP->op_first, op->op_type);
1140 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1141 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1142 : type == OP_RV2HV ? OPpDEREF_HV
1144 op->op_flags |= OPf_MOD;
1150 op->op_flags |= OPf_REF;
1153 ref(cUNOP->op_first, op->op_type);
1158 op->op_flags |= OPf_REF;
1163 if (!(op->op_flags & OPf_KIDS))
1165 ref(cBINOP->op_first, type);
1169 ref(cBINOP->op_first, op->op_type);
1170 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1171 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1172 : type == OP_RV2HV ? OPpDEREF_HV
1174 op->op_flags |= OPf_MOD;
1182 if (!(op->op_flags & OPf_KIDS))
1184 ref(cLISTOP->op_last, type);
1200 if (!op || error_count)
1204 if (type == OP_LIST) {
1205 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1208 else if (type != OP_PADSV &&
1211 type != OP_PUSHMARK)
1213 sprintf(tokenbuf, "Can't declare %s in my", op_desc[op->op_type]);
1217 op->op_flags |= OPf_MOD;
1218 op->op_private |= OPpLVAL_INTRO;
1227 o->op_flags |= OPf_PARENS;
1232 bind_match(type, left, right)
1239 if (right->op_type == OP_MATCH ||
1240 right->op_type == OP_SUBST ||
1241 right->op_type == OP_TRANS) {
1242 right->op_flags |= OPf_STACKED;
1243 if (right->op_type != OP_MATCH)
1244 left = mod(left, right->op_type);
1245 if (right->op_type == OP_TRANS)
1246 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1248 op = prepend_elem(right->op_type, scalar(left), right);
1250 return newUNOP(OP_NOT, 0, scalar(op));
1254 return bind_match(type, left,
1255 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1264 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1265 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1273 if (o->op_flags & OPf_PARENS || perldb || tainting) {
1274 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1275 o->op_type = OP_LEAVE;
1276 o->op_ppaddr = ppaddr[OP_LEAVE];
1279 if (o->op_type == OP_LINESEQ) {
1281 o->op_type = OP_SCOPE;
1282 o->op_ppaddr = ppaddr[OP_SCOPE];
1283 kid = ((LISTOP*)o)->op_first;
1284 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1285 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1290 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1300 int retval = savestack_ix;
1301 SAVEI32(comppad_name_floor);
1303 if ((comppad_name_fill = AvFILL(comppad_name)) > 0)
1304 comppad_name_floor = comppad_name_fill;
1306 comppad_name_floor = 0;
1308 SAVEI32(min_intro_pending);
1309 SAVEI32(max_intro_pending);
1310 min_intro_pending = 0;
1311 SAVEI32(comppad_name_fill);
1312 SAVEI32(padix_floor);
1313 padix_floor = padix;
1314 pad_reset_pending = FALSE;
1316 hints &= ~HINT_BLOCK_SCOPE;
1321 block_end(floor, seq)
1325 int needblockscope = hints & HINT_BLOCK_SCOPE;
1326 OP* retval = scalarseq(seq);
1328 pad_reset_pending = FALSE;
1330 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1331 pad_leavemy(comppad_name_fill);
1341 eval_root = newUNOP(OP_LEAVEEVAL, ((in_eval & 4) ? OPf_SPECIAL : 0), op);
1342 eval_start = linklist(eval_root);
1343 eval_root->op_next = 0;
1351 main_root = scope(sawparens(scalarvoid(op)));
1352 curcop = &compiling;
1353 main_start = LINKLIST(main_root);
1354 main_root->op_next = 0;
1366 if (o->op_flags & OPf_PARENS)
1370 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1372 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1373 if (*s == ';' || *s == '=')
1374 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1381 return mod(o, OP_NULL); /* a bit kludgey */
1388 if (o->op_type == OP_LIST) {
1389 o = convert(OP_JOIN, 0,
1390 prepend_elem(OP_LIST,
1391 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1402 I32 type = o->op_type;
1405 if (opargs[type] & OA_RETSCALAR)
1407 if (opargs[type] & OA_TARGET)
1408 o->op_targ = pad_alloc(type, SVs_PADTMP);
1410 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1411 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1413 if (!(opargs[type] & OA_FOLDCONST))
1417 goto nope; /* Don't try to run w/ errors */
1419 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1420 if (curop->op_type != OP_CONST &&
1421 curop->op_type != OP_LIST &&
1422 curop->op_type != OP_SCALAR &&
1423 curop->op_type != OP_NULL &&
1424 curop->op_type != OP_PUSHMARK) {
1429 curop = LINKLIST(o);
1434 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1435 pad_swipe(o->op_targ);
1436 else if (SvTEMP(sv)) { /* grab mortal temp? */
1437 (void)SvREFCNT_inc(sv);
1441 if (type == OP_RV2GV)
1442 return newGVOP(OP_GV, 0, (GV*)sv);
1444 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1446 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1451 SvIOK_off(sv); /* undo SvIV() damage */
1453 return newSVOP(OP_CONST, 0, sv);
1457 if (!(opargs[type] & OA_OTHERINT))
1460 if (!(hints & HINT_INTEGER)) {
1461 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1464 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1465 if (curop->op_type == OP_CONST) {
1466 if (SvIOK(((SVOP*)curop)->op_sv))
1470 if (opargs[curop->op_type] & OA_RETINTEGER)
1474 o->op_ppaddr = ppaddr[++(o->op_type)];
1481 gen_constant_list(o)
1485 I32 oldtmps_floor = tmps_floor;
1489 return o; /* Don't attempt to run with errors */
1491 op = curop = LINKLIST(o);
1497 tmps_floor = oldtmps_floor;
1499 o->op_type = OP_RV2AV;
1500 o->op_ppaddr = ppaddr[OP_RV2AV];
1501 curop = ((UNOP*)o)->op_first;
1502 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1509 convert(type, flags, op)
1517 if (!op || op->op_type != OP_LIST)
1518 op = newLISTOP(OP_LIST, 0, op, Nullop);
1520 op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1522 if (!(opargs[type] & OA_MARK))
1523 null(cLISTOP->op_first);
1526 op->op_ppaddr = ppaddr[type];
1527 op->op_flags |= flags;
1529 op = CHECKOP(type, op);
1530 if (op->op_type != type)
1533 if (cLISTOP->op_children < 7) {
1534 /* XXX do we really need to do this if we're done appending?? */
1535 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1537 cLISTOP->op_last = last; /* in case check substituted last arg */
1540 return fold_constants(op);
1543 /* List constructors */
1546 append_elem(type, first, last)
1557 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1558 return newLISTOP(type, 0, first, last);
1560 if (first->op_flags & OPf_KIDS)
1561 ((LISTOP*)first)->op_last->op_sibling = last;
1563 first->op_flags |= OPf_KIDS;
1564 ((LISTOP*)first)->op_first = last;
1566 ((LISTOP*)first)->op_last = last;
1567 ((LISTOP*)first)->op_children++;
1572 append_list(type, first, last)
1583 if (first->op_type != type)
1584 return prepend_elem(type, (OP*)first, (OP*)last);
1586 if (last->op_type != type)
1587 return append_elem(type, (OP*)first, (OP*)last);
1589 first->op_last->op_sibling = last->op_first;
1590 first->op_last = last->op_last;
1591 first->op_children += last->op_children;
1592 if (first->op_children)
1593 last->op_flags |= OPf_KIDS;
1600 prepend_elem(type, first, last)
1611 if (last->op_type == type) {
1612 if (type == OP_LIST) { /* already a PUSHMARK there */
1613 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1614 ((LISTOP*)last)->op_first->op_sibling = first;
1617 if (!(last->op_flags & OPf_KIDS)) {
1618 ((LISTOP*)last)->op_last = first;
1619 last->op_flags |= OPf_KIDS;
1621 first->op_sibling = ((LISTOP*)last)->op_first;
1622 ((LISTOP*)last)->op_first = first;
1624 ((LISTOP*)last)->op_children++;
1628 return newLISTOP(type, 0, first, last);
1636 return newOP(OP_STUB, 0);
1643 if (!op || op->op_type != OP_LIST)
1644 op = newLISTOP(OP_LIST, 0, op, Nullop);
1650 newLISTOP(type, flags, first, last)
1658 Newz(1101, listop, 1, LISTOP);
1660 listop->op_type = type;
1661 listop->op_ppaddr = ppaddr[type];
1662 listop->op_children = (first != 0) + (last != 0);
1663 listop->op_flags = flags;
1667 else if (!first && last)
1670 first->op_sibling = last;
1671 listop->op_first = first;
1672 listop->op_last = last;
1673 if (type == OP_LIST) {
1675 pushop = newOP(OP_PUSHMARK, 0);
1676 pushop->op_sibling = first;
1677 listop->op_first = pushop;
1678 listop->op_flags |= OPf_KIDS;
1680 listop->op_last = pushop;
1682 else if (listop->op_children)
1683 listop->op_flags |= OPf_KIDS;
1694 Newz(1101, op, 1, OP);
1696 op->op_ppaddr = ppaddr[type];
1697 op->op_flags = flags;
1700 op->op_private = 0 + (flags >> 8);
1701 if (opargs[type] & OA_RETSCALAR)
1703 if (opargs[type] & OA_TARGET)
1704 op->op_targ = pad_alloc(type, SVs_PADTMP);
1705 return CHECKOP(type, op);
1709 newUNOP(type, flags, first)
1717 first = newOP(OP_STUB, 0);
1718 if (opargs[type] & OA_MARK)
1719 first = force_list(first);
1721 Newz(1101, unop, 1, UNOP);
1722 unop->op_type = type;
1723 unop->op_ppaddr = ppaddr[type];
1724 unop->op_first = first;
1725 unop->op_flags = flags | OPf_KIDS;
1726 unop->op_private = 1 | (flags >> 8);
1728 unop = (UNOP*) CHECKOP(type, unop);
1732 return fold_constants((OP *) unop);
1736 newBINOP(type, flags, first, last)
1743 Newz(1101, binop, 1, BINOP);
1746 first = newOP(OP_NULL, 0);
1748 binop->op_type = type;
1749 binop->op_ppaddr = ppaddr[type];
1750 binop->op_first = first;
1751 binop->op_flags = flags | OPf_KIDS;
1754 binop->op_private = 1 | (flags >> 8);
1757 binop->op_private = 2 | (flags >> 8);
1758 first->op_sibling = last;
1761 binop = (BINOP*)CHECKOP(type, binop);
1765 binop->op_last = last = binop->op_first->op_sibling;
1767 return fold_constants((OP *)binop);
1771 pmtrans(op, expr, repl)
1776 SV *tstr = ((SVOP*)expr)->op_sv;
1777 SV *rstr = ((SVOP*)repl)->op_sv;
1780 register U8 *t = (U8*)SvPV(tstr, tlen);
1781 register U8 *r = (U8*)SvPV(rstr, rlen);
1786 register short *tbl;
1788 tbl = (short*)cPVOP->op_pv;
1789 complement = op->op_private & OPpTRANS_COMPLEMENT;
1790 delete = op->op_private & OPpTRANS_DELETE;
1791 /* squash = op->op_private & OPpTRANS_SQUASH; */
1794 Zero(tbl, 256, short);
1795 for (i = 0; i < tlen; i++)
1797 for (i = 0, j = 0; i < 256; i++) {
1813 if (!rlen && !delete) {
1816 for (i = 0; i < 256; i++)
1818 for (i = 0, j = 0; i < tlen; i++,j++) {
1821 if (tbl[t[i]] == -1)
1827 if (tbl[t[i]] == -1)
1838 newPMOP(type, flags)
1844 Newz(1101, pmop, 1, PMOP);
1845 pmop->op_type = type;
1846 pmop->op_ppaddr = ppaddr[type];
1847 pmop->op_flags = flags;
1848 pmop->op_private = 0 | (flags >> 8);
1850 if (hints & HINT_LOCALE)
1851 pmop->op_pmpermflags = (pmop->op_pmflags |= PMf_LOCALE);
1853 /* link into pm list */
1854 if (type != OP_TRANS && curstash) {
1855 pmop->op_pmnext = HvPMROOT(curstash);
1856 HvPMROOT(curstash) = pmop;
1863 pmruntime(op, expr, repl)
1871 if (op->op_type == OP_TRANS)
1872 return pmtrans(op, expr, repl);
1876 if (expr->op_type == OP_CONST) {
1878 SV *pat = ((SVOP*)expr)->op_sv;
1879 char *p = SvPV(pat, plen);
1880 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1881 sv_setpvn(pat, "\\s+", 3);
1882 p = SvPV(pat, plen);
1883 pm->op_pmflags |= PMf_SKIPWHITE;
1885 pm->op_pmregexp = pregcomp(p, p + plen, pm);
1886 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1887 pm->op_pmflags |= PMf_WHITE;
1892 if (pm->op_pmflags & PMf_KEEP)
1893 expr = newUNOP(OP_REGCMAYBE,0,expr);
1895 Newz(1101, rcop, 1, LOGOP);
1896 rcop->op_type = OP_REGCOMP;
1897 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1898 rcop->op_first = scalar(expr);
1899 rcop->op_flags |= OPf_KIDS;
1900 rcop->op_private = 1;
1901 rcop->op_other = op;
1903 /* establish postfix order */
1904 if (pm->op_pmflags & PMf_KEEP) {
1906 rcop->op_next = expr;
1907 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1910 rcop->op_next = LINKLIST(expr);
1911 expr->op_next = (OP*)rcop;
1914 prepend_elem(op->op_type, scalar((OP*)rcop), op);
1919 if (pm->op_pmflags & PMf_EVAL)
1921 else if (repl->op_type == OP_CONST)
1925 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1926 if (opargs[curop->op_type] & OA_DANGEROUS) {
1927 if (curop->op_type == OP_GV) {
1928 GV *gv = ((GVOP*)curop)->op_gv;
1929 if (strchr("&`'123456789+", *GvENAME(gv)))
1932 else if (curop->op_type == OP_RV2CV)
1934 else if (curop->op_type == OP_RV2SV ||
1935 curop->op_type == OP_RV2AV ||
1936 curop->op_type == OP_RV2HV ||
1937 curop->op_type == OP_RV2GV) {
1938 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1941 else if (curop->op_type == OP_PADSV ||
1942 curop->op_type == OP_PADAV ||
1943 curop->op_type == OP_PADHV ||
1944 curop->op_type == OP_PADANY) {
1953 if (curop == repl) {
1954 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1955 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
1956 prepend_elem(op->op_type, scalar(repl), op);
1959 Newz(1101, rcop, 1, LOGOP);
1960 rcop->op_type = OP_SUBSTCONT;
1961 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1962 rcop->op_first = scalar(repl);
1963 rcop->op_flags |= OPf_KIDS;
1964 rcop->op_private = 1;
1965 rcop->op_other = op;
1967 /* establish postfix order */
1968 rcop->op_next = LINKLIST(repl);
1969 repl->op_next = (OP*)rcop;
1971 pm->op_pmreplroot = scalar((OP*)rcop);
1972 pm->op_pmreplstart = LINKLIST(rcop);
1981 newSVOP(type, flags, sv)
1987 Newz(1101, svop, 1, SVOP);
1988 svop->op_type = type;
1989 svop->op_ppaddr = ppaddr[type];
1991 svop->op_next = (OP*)svop;
1992 svop->op_flags = flags;
1993 if (opargs[type] & OA_RETSCALAR)
1995 if (opargs[type] & OA_TARGET)
1996 svop->op_targ = pad_alloc(type, SVs_PADTMP);
1997 return CHECKOP(type, svop);
2001 newGVOP(type, flags, gv)
2007 Newz(1101, gvop, 1, GVOP);
2008 gvop->op_type = type;
2009 gvop->op_ppaddr = ppaddr[type];
2010 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
2011 gvop->op_next = (OP*)gvop;
2012 gvop->op_flags = flags;
2013 if (opargs[type] & OA_RETSCALAR)
2015 if (opargs[type] & OA_TARGET)
2016 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
2017 return CHECKOP(type, gvop);
2021 newPVOP(type, flags, pv)
2027 Newz(1101, pvop, 1, PVOP);
2028 pvop->op_type = type;
2029 pvop->op_ppaddr = ppaddr[type];
2031 pvop->op_next = (OP*)pvop;
2032 pvop->op_flags = flags;
2033 if (opargs[type] & OA_RETSCALAR)
2035 if (opargs[type] & OA_TARGET)
2036 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2037 return CHECKOP(type, pvop);
2046 save_hptr(&curstash);
2047 save_item(curstname);
2052 name = SvPV(sv, len);
2053 curstash = gv_stashpvn(name,len,TRUE);
2054 sv_setpvn(curstname, name, len);
2058 sv_setpv(curstname,"<none>");
2066 utilize(aver, floor, version, id, arg)
2079 if (id->op_type != OP_CONST)
2080 croak("Module name must be constant");
2084 if(version != Nullop) {
2085 SV *vesv = ((SVOP*)version)->op_sv;
2087 if (arg == Nullop && !SvNIOK(vesv)) {
2094 if (version->op_type != OP_CONST || !SvNIOK(vesv))
2095 croak("Version number must be constant number");
2097 /* Make copy of id so we don't free it twice */
2098 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2100 /* Fake up a method call to VERSION */
2101 meth = newSVOP(OP_CONST, 0, newSVpv("VERSION", 7));
2102 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2103 append_elem(OP_LIST,
2104 prepend_elem(OP_LIST, pack, list(version)),
2105 newUNOP(OP_METHOD, 0, meth)));
2109 /* Fake up an import/unimport */
2110 if (arg && arg->op_type == OP_STUB)
2111 imop = arg; /* no import on explicit () */
2112 else if(SvNIOK(((SVOP*)id)->op_sv)) {
2113 imop = Nullop; /* use 5.0; */
2116 /* Make copy of id so we don't free it twice */
2117 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2118 meth = newSVOP(OP_CONST, 0,
2120 ? newSVpv("import", 6)
2121 : newSVpv("unimport", 8)
2123 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2124 append_elem(OP_LIST,
2125 prepend_elem(OP_LIST, pack, list(arg)),
2126 newUNOP(OP_METHOD, 0, meth)));
2129 /* Fake up a require */
2130 rqop = newUNOP(OP_REQUIRE, 0, id);
2132 /* Fake up the BEGIN {}, which does its thing immediately. */
2134 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2136 append_elem(OP_LINESEQ,
2137 append_elem(OP_LINESEQ,
2138 newSTATEOP(0, Nullch, rqop),
2139 newSTATEOP(0, Nullch, veop)),
2140 newSTATEOP(0, Nullch, imop) ));
2147 newSLICEOP(flags, subscript, listval)
2152 return newBINOP(OP_LSLICE, flags,
2153 list(force_list(subscript)),
2154 list(force_list(listval)) );
2164 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2165 op = cUNOP->op_first;
2167 if (op->op_type == OP_COND_EXPR) {
2168 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2169 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2174 yyerror("Assignment to both a list and a scalar");
2178 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2179 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2180 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2183 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2186 if (op->op_type == OP_RV2SV)
2193 newASSIGNOP(flags, left, optype, right)
2202 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2203 return newLOGOP(optype, 0,
2204 mod(scalar(left), optype),
2205 newUNOP(OP_SASSIGN, 0, scalar(right)));
2208 return newBINOP(optype, OPf_STACKED,
2209 mod(scalar(left), optype), scalar(right));
2213 if (list_assignment(left)) {
2215 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2216 left = mod(left, OP_AASSIGN);
2224 op = newBINOP(OP_AASSIGN, flags,
2225 list(force_list(right)),
2226 list(force_list(left)) );
2227 op->op_private = 0 | (flags >> 8);
2228 if (!(left->op_private & OPpLVAL_INTRO)) {
2229 static int generation = 100;
2233 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2234 if (opargs[curop->op_type] & OA_DANGEROUS) {
2235 if (curop->op_type == OP_GV) {
2236 GV *gv = ((GVOP*)curop)->op_gv;
2237 if (gv == defgv || SvCUR(gv) == generation)
2239 SvCUR(gv) = generation;
2241 else if (curop->op_type == OP_PADSV ||
2242 curop->op_type == OP_PADAV ||
2243 curop->op_type == OP_PADHV ||
2244 curop->op_type == OP_PADANY) {
2245 SV **svp = AvARRAY(comppad_name);
2246 SV *sv = svp[curop->op_targ];
2247 if (SvCUR(sv) == generation)
2249 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2251 else if (curop->op_type == OP_RV2CV)
2253 else if (curop->op_type == OP_RV2SV ||
2254 curop->op_type == OP_RV2AV ||
2255 curop->op_type == OP_RV2HV ||
2256 curop->op_type == OP_RV2GV) {
2257 if (lastop->op_type != OP_GV) /* funny deref? */
2266 op->op_private = OPpASSIGN_COMMON;
2268 if (right && right->op_type == OP_SPLIT) {
2270 if ((tmpop = ((LISTOP*)right)->op_first) &&
2271 tmpop->op_type == OP_PUSHRE)
2273 PMOP *pm = (PMOP*)tmpop;
2274 if (left->op_type == OP_RV2AV &&
2275 !(left->op_private & OPpLVAL_INTRO) &&
2276 !(op->op_private & OPpASSIGN_COMMON) )
2278 tmpop = ((UNOP*)left)->op_first;
2279 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2280 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2281 pm->op_pmflags |= PMf_ONCE;
2282 tmpop = ((UNOP*)op)->op_first; /* to list (nulled) */
2283 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2284 tmpop->op_sibling = Nullop; /* don't free split */
2285 right->op_next = tmpop->op_next; /* fix starting loc */
2286 op_free(op); /* blow off assign */
2287 right->op_flags &= ~(OPf_KNOW|OPf_LIST);
2288 /* "I don't know and I don't care." */
2293 if (modcount < 10000 &&
2294 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2296 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2298 sv_setiv(sv, modcount+1);
2306 right = newOP(OP_UNDEF, 0);
2307 if (right->op_type == OP_READLINE) {
2308 right->op_flags |= OPf_STACKED;
2309 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2312 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2313 op = newBINOP(OP_SASSIGN, flags,
2314 scalar(right), mod(scalar(left), OP_SASSIGN) );
2326 newSTATEOP(flags, label, op)
2331 U32 seq = intro_my();
2334 Newz(1101, cop, 1, COP);
2335 if (perldb && curcop->cop_line && curstash != debstash) {
2336 cop->op_type = OP_DBSTATE;
2337 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2340 cop->op_type = OP_NEXTSTATE;
2341 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2343 cop->op_flags = flags;
2344 cop->op_private = 0 | (flags >> 8);
2345 cop->op_next = (OP*)cop;
2348 cop->cop_label = label;
2349 hints |= HINT_BLOCK_SCOPE;
2352 cop->cop_arybase = curcop->cop_arybase;
2354 if (copline == NOLINE)
2355 cop->cop_line = curcop->cop_line;
2357 cop->cop_line = copline;
2360 cop->cop_filegv = GvREFCNT_inc(curcop->cop_filegv);
2361 cop->cop_stash = curstash;
2363 if (perldb && curstash != debstash) {
2364 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2365 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2366 (void)SvIOK_on(*svp);
2368 SvSTASH(*svp) = (HV*)cop;
2372 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2375 /* "Introduce" my variables to visible status. */
2383 if (! min_intro_pending)
2386 svp = AvARRAY(comppad_name);
2387 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2388 if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2389 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2390 SvNVX(sv) = (double)cop_seqmax;
2393 min_intro_pending = 0;
2394 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2395 return cop_seqmax++;
2399 newLOGOP(type, flags, first, other)
2408 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2409 return newBINOP(type, flags, scalar(first), scalar(other));
2411 scalarboolean(first);
2412 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2413 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2414 if (type == OP_AND || type == OP_OR) {
2420 first = cUNOP->op_first;
2422 first->op_next = op->op_next;
2423 cUNOP->op_first = Nullop;
2427 if (first->op_type == OP_CONST) {
2428 if (dowarn && (first->op_private & OPpCONST_BARE))
2429 warn("Probable precedence problem on %s", op_desc[type]);
2430 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2439 else if (first->op_type == OP_WANTARRAY) {
2449 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2450 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2452 Newz(1101, logop, 1, LOGOP);
2454 logop->op_type = type;
2455 logop->op_ppaddr = ppaddr[type];
2456 logop->op_first = first;
2457 logop->op_flags = flags | OPf_KIDS;
2458 logop->op_other = LINKLIST(other);
2459 logop->op_private = 1 | (flags >> 8);
2461 /* establish postfix order */
2462 logop->op_next = LINKLIST(first);
2463 first->op_next = (OP*)logop;
2464 first->op_sibling = other;
2466 op = newUNOP(OP_NULL, 0, (OP*)logop);
2467 other->op_next = op;
2473 newCONDOP(flags, first, trueop, falseop)
2483 return newLOGOP(OP_AND, 0, first, trueop);
2485 return newLOGOP(OP_OR, 0, first, falseop);
2487 scalarboolean(first);
2488 if (first->op_type == OP_CONST) {
2489 if (SvTRUE(((SVOP*)first)->op_sv)) {
2500 else if (first->op_type == OP_WANTARRAY) {
2504 Newz(1101, condop, 1, CONDOP);
2506 condop->op_type = OP_COND_EXPR;
2507 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2508 condop->op_first = first;
2509 condop->op_flags = flags | OPf_KIDS;
2510 condop->op_true = LINKLIST(trueop);
2511 condop->op_false = LINKLIST(falseop);
2512 condop->op_private = 1 | (flags >> 8);
2514 /* establish postfix order */
2515 condop->op_next = LINKLIST(first);
2516 first->op_next = (OP*)condop;
2518 first->op_sibling = trueop;
2519 trueop->op_sibling = falseop;
2520 op = newUNOP(OP_NULL, 0, (OP*)condop);
2522 trueop->op_next = op;
2523 falseop->op_next = op;
2529 newRANGE(flags, left, right)
2539 Newz(1101, condop, 1, CONDOP);
2541 condop->op_type = OP_RANGE;
2542 condop->op_ppaddr = ppaddr[OP_RANGE];
2543 condop->op_first = left;
2544 condop->op_flags = OPf_KIDS;
2545 condop->op_true = LINKLIST(left);
2546 condop->op_false = LINKLIST(right);
2547 condop->op_private = 1 | (flags >> 8);
2549 left->op_sibling = right;
2551 condop->op_next = (OP*)condop;
2552 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2553 flop = newUNOP(OP_FLOP, 0, flip);
2554 op = newUNOP(OP_NULL, 0, flop);
2557 left->op_next = flip;
2558 right->op_next = flop;
2560 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2561 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2562 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2563 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2565 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2566 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2569 if (!flip->op_private || !flop->op_private)
2570 linklist(op); /* blow off optimizer unless constant */
2576 newLOOPOP(flags, debuggable, expr, block)
2584 int once = block && block->op_flags & OPf_SPECIAL &&
2585 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2588 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2589 return block; /* do {} while 0 does once */
2590 else if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)
2591 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2594 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2595 op = newLOGOP(OP_AND, 0, expr, listop);
2597 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2599 if (once && op != listop)
2600 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2603 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2605 op->op_flags |= flags;
2607 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2612 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2626 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2627 expr = newUNOP(OP_DEFINED, 0,
2628 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2632 block = newOP(OP_NULL, 0);
2635 next = LINKLIST(cont);
2637 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2639 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2640 redo = LINKLIST(listop);
2643 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2644 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2645 op_free(expr); /* oops, it's a while (0) */
2647 return Nullop; /* (listop already freed by newLOGOP) */
2649 ((LISTOP*)listop)->op_last->op_next = condop =
2650 (op == listop ? redo : LINKLIST(op));
2658 Newz(1101,loop,1,LOOP);
2659 loop->op_type = OP_ENTERLOOP;
2660 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2661 loop->op_private = 0;
2662 loop->op_next = (OP*)loop;
2665 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2667 loop->op_redoop = redo;
2668 loop->op_lastop = op;
2671 loop->op_nextop = next;
2673 loop->op_nextop = op;
2675 op->op_flags |= flags;
2676 op->op_private |= (flags >> 8);
2681 #ifndef CAN_PROTOTYPE
2682 newFOROP(flags,label,forline,sv,expr,block,cont)
2691 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2692 #endif /* CAN_PROTOTYPE */
2700 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2701 sv->op_type = OP_RV2GV;
2702 sv->op_ppaddr = ppaddr[OP_RV2GV];
2704 else if (sv->op_type == OP_PADSV) { /* private variable */
2705 padoff = sv->op_targ;
2710 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
2713 sv = newGVOP(OP_GV, 0, defgv);
2715 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
2716 expr = scalar(ref(expr, OP_ITER));
2717 iterflags |= OPf_STACKED;
2719 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
2720 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2722 assert(!loop->op_next);
2723 Renew(loop, 1, LOOP);
2724 loop->op_targ = padoff;
2725 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2726 newOP(OP_ITER, 0), block, cont));
2730 newLOOPEX(type, label)
2735 if (type != OP_GOTO || label->op_type == OP_CONST) {
2736 op = newPVOP(type, 0, savepv(
2737 label->op_type == OP_CONST
2738 ? SvPVx(((SVOP*)label)->op_sv, na)
2743 if (label->op_type == OP_ENTERSUB)
2744 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2745 op = newUNOP(type, OPf_STACKED, label);
2747 hints |= HINT_BLOCK_SCOPE;
2755 if (!CvXSUB(cv) && CvROOT(cv)) {
2757 croak("Can't undef active subroutine");
2764 op_free(CvROOT(cv));
2765 CvROOT(cv) = Nullop;
2768 SvREFCNT_dec(CvGV(cv));
2770 SvREFCNT_dec(CvOUTSIDE(cv));
2771 CvOUTSIDE(cv) = Nullcv;
2772 if (CvPADLIST(cv)) {
2773 I32 i = AvFILL(CvPADLIST(cv));
2775 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2779 SvREFCNT_dec((SV*)CvPADLIST(cv));
2780 CvPADLIST(cv) = Nullav;
2784 #ifdef DEBUG_CLOSURES
2789 CV *outside = CvOUTSIDE(cv);
2790 AV* padlist = CvPADLIST(cv);
2791 AV* pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
2792 AV* pad = (AV*)*av_fetch(padlist, 1, FALSE);
2793 SV** pname = AvARRAY(pad_name);
2794 SV** ppad = AvARRAY(pad);
2797 PerlIO_printf(Perl_debug_log, "\tCV=0x%p (%s), OUTSIDE=0x%p (%s)\n",
2798 cv, CvANON(cv) ? "ANON" : GvNAME(CvGV(cv)),
2799 outside, CvANON(outside) ? "ANON" : GvNAME(CvGV(outside)));
2801 for (ix = 1; ix <= AvFILL(pad); ix++) {
2802 if (SvPOK(pname[ix]))
2803 PerlIO_printf(Perl_debug_log, "\t%4d. 0x%p (\"%s\")\n",
2804 ix, ppad[ix], SvPVX(pname[ix]))
2807 #endif /* DEBUG_CLOSURES */
2810 cv_clone2(proto, outside)
2816 AV* protopadlist = CvPADLIST(proto);
2817 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2818 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2819 SV** pname = AvARRAY(protopad_name);
2820 SV** ppad = AvARRAY(protopad);
2829 cv = compcv = (CV*)NEWSV(1104,0);
2830 sv_upgrade((SV *)cv, SVt_PVCV);
2835 CvFILEGV(cv) = CvFILEGV(proto);
2836 CvGV(cv) = GvREFCNT_inc(CvGV(proto));
2837 CvSTASH(cv) = CvSTASH(proto);
2838 CvROOT(cv) = CvROOT(proto);
2839 CvSTART(cv) = CvSTART(proto);
2841 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
2845 comppadlist = newAV();
2846 AvREAL_off(comppadlist);
2847 av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
2848 av_store(comppadlist, 1, (SV*)comppad);
2849 CvPADLIST(cv) = comppadlist;
2850 av_fill(comppad, AvFILL(protopad));
2851 curpad = AvARRAY(comppad);
2853 av = newAV(); /* will be @_ */
2855 av_store(comppad, 0, (SV*)av);
2856 AvFLAGS(av) = AVf_REIFY;
2858 for (ix = AvFILL(protopad); ix > 0; ix--) {
2860 if (pname[ix] != &sv_undef) {
2861 char *name = SvPVX(pname[ix]); /* XXX */
2862 if (SvFLAGS(pname[ix]) & SVf_FAKE) { /* lexical from outside? */
2863 I32 off = pad_findlex(name, ix, SvIVX(pname[ix]),
2864 CvOUTSIDE(cv), cxstack_ix);
2866 curpad[ix] = SvREFCNT_inc(ppad[ix]);
2868 croak("panic: cv_clone: %s", name);
2870 else { /* our own lexical */
2872 /* anon code -- we'll come back for it */
2873 sv = SvREFCNT_inc(ppad[ix]);
2875 else if (*name == '@')
2877 else if (*name == '%')
2893 /* Now that vars are all in place, clone nested closures. */
2895 for (ix = AvFILL(protopad); ix > 0; ix--) {
2896 if (pname[ix] != &sv_undef
2897 && !(SvFLAGS(pname[ix]) & SVf_FAKE)
2898 && *SvPVX(pname[ix]) == '&'
2899 && CvCLONE(ppad[ix]))
2901 CV *kid = cv_clone2((CV*)ppad[ix], cv);
2902 SvREFCNT_dec(ppad[ix]);
2905 curpad[ix] = (SV*)kid;
2909 #ifdef DEBUG_CLOSURES
2910 PerlIO_printf(Perl_debug_log, "Cloned from:\n");
2912 PerlIO_printf(Perl_debug_log, " to:\n");
2924 return cv_clone2(proto, CvOUTSIDE(proto));
2934 if(cv && SvPOK(cv) && !SvCUR(cv)) {
2935 for (o = CvSTART(cv); o; o = o->op_next) {
2936 OPCODE type = o->op_type;
2938 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
2940 if (type == OP_LEAVESUB || type == OP_RETURN)
2942 if (type != OP_CONST || sv)
2945 sv = ((SVOP*)o)->op_sv;
2952 newSUB(floor,op,proto,block)
2959 char *name = op ? SvPVx(cSVOP->op_sv, na) : "__ANON__";
2960 GV* gv = gv_fetchpv(name, GV_ADDMULTI, SVt_PVCV);
2967 if (cv = GvCV(gv)) {
2969 cv = 0; /* just a cached method */
2970 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
2971 SV* const_sv = cv_const_sv(cv);
2973 char *p = proto ? SvPVx(((SVOP*)proto)->op_sv, na) : Nullch;
2975 if((!proto != !SvPOK(cv)) || (p && strNE(SvPV((SV*)cv,na), p))) {
2976 warn("Prototype mismatch: (%s) vs (%s)",
2977 SvPOK(cv) ? SvPV((SV*)cv,na) : "none",
2981 if ((const_sv || dowarn) && strNE(name, "BEGIN")) {/* already defined (or promised)? */
2982 line_t oldline = curcop->cop_line;
2984 curcop->cop_line = copline;
2985 warn(const_sv ? "Constant subroutine %s redefined"
2986 : "Subroutine %s redefined",name);
2987 curcop->cop_line = oldline;
2993 if (cv) { /* must reuse cv if autoloaded */
2995 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
2996 CvOUTSIDE(compcv) = 0;
2997 CvPADLIST(cv) = CvPADLIST(compcv);
2998 CvPADLIST(compcv) = 0;
2999 if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
3000 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
3001 SvREFCNT_dec(compcv);
3008 CvFILEGV(cv) = curcop->cop_filegv;
3009 CvGV(cv) = GvREFCNT_inc(gv);
3010 CvSTASH(cv) = curstash;
3013 char *p = SvPVx(((SVOP*)proto)->op_sv, na);
3014 sv_setpv((SV*)cv, p);
3030 av = newAV(); /* Will be @_ */
3032 av_store(comppad, 0, (SV*)av);
3033 AvFLAGS(av) = AVf_REIFY;
3035 for (ix = AvFILL(comppad); ix > 0; ix--) {
3036 if (!SvPADMY(curpad[ix]))
3037 SvPADTMP_on(curpad[ix]);
3040 if (AvFILL(comppad_name) < AvFILL(comppad))
3041 av_store(comppad_name, AvFILL(comppad), Nullsv);
3043 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
3044 CvSTART(cv) = LINKLIST(CvROOT(cv));
3045 CvROOT(cv)->op_next = 0;
3047 if (s = strrchr(name,':'))
3051 if (strEQ(s, "BEGIN") && !error_count) {
3052 line_t oldline = compiling.cop_line;
3056 SAVESPTR(compiling.cop_filegv);
3060 av_push(beginav, (SV *)cv);
3061 DEBUG_x( dump_sub(gv) );
3062 rs = SvREFCNT_inc(nrs);
3065 if (GvCV(gv) == cv) { /* Detach it. */
3067 GvCV(gv) = 0; /* Was above calllist, why? IZ */
3071 curcop = &compiling;
3072 curcop->cop_line = oldline; /* might have recursed to yylex */
3075 else if (strEQ(s, "END") && !error_count) {
3078 av_unshift(endav, 1);
3079 av_store(endav, 0, SvREFCNT_inc(cv));
3081 if (perldb && curstash != debstash) {
3083 SV *tmpstr = sv_newmortal();
3084 static GV *db_postponed;
3088 sprintf(buf,"%s:%ld",SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
3089 sv = newSVpv(buf,0);
3091 sprintf(buf,"%ld",(long)curcop->cop_line);
3093 gv_efullname3(tmpstr, gv, Nullch);
3094 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
3095 if (!db_postponed) {
3096 db_postponed = gv_fetchpv("DB::postponed", TRUE, SVt_PVHV);
3098 hv = GvHVn(db_postponed);
3099 if (HvFILL(hv) >= 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
3100 && (cv = GvCV(db_postponed))) {
3105 perl_call_sv((SV*)cv, G_DISCARD);
3112 GvCV(gv) = 0; /* Will remember in SVOP instead. */
3120 newXSUB(name, ix, subaddr, filename)
3126 CV* cv = newXS(name, (void(*)())subaddr, filename);
3128 CvXSUBANY(cv).any_i32 = ix;
3134 newXS(name, subaddr, filename)
3136 void (*subaddr) _((CV*));
3140 GV *gv = gv_fetchpv((name ? name : "__ANON__"), GV_ADDMULTI, SVt_PVCV);
3145 if (cv = GvCV(gv)) {
3147 cv = 0; /* just a cached method */
3148 else if (CvROOT(cv) || CvXSUB(cv)) { /* already defined? */
3150 line_t oldline = curcop->cop_line;
3152 curcop->cop_line = copline;
3153 warn("Subroutine %s redefined",name);
3154 curcop->cop_line = oldline;
3160 if (cv) { /* must reuse cv if autoloaded */
3161 assert(SvREFCNT(CvGV(cv)) > 1);
3162 SvREFCNT_dec(CvGV(cv));
3165 cv = (CV*)NEWSV(1105,0);
3166 sv_upgrade((SV *)cv, SVt_PVCV);
3169 CvGV(cv) = GvREFCNT_inc(gv);
3171 CvFILEGV(cv) = gv_fetchfile(filename);
3172 CvXSUB(cv) = subaddr;
3175 else if (s = strrchr(name,':'))
3179 if (strEQ(s, "BEGIN")) {
3182 av_push(beginav, SvREFCNT_inc(gv));
3184 else if (strEQ(s, "END")) {
3187 av_unshift(endav, 1);
3188 av_store(endav, 0, SvREFCNT_inc(gv));
3191 GvCV(gv) = 0; /* Will remember elsewhere instead. */
3198 newFORM(floor,op,block)
3209 name = SvPVx(cSVOP->op_sv, na);
3212 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3214 if (cv = GvFORM(gv)) {
3216 line_t oldline = curcop->cop_line;
3218 curcop->cop_line = copline;
3219 warn("Format %s redefined",name);
3220 curcop->cop_line = oldline;
3226 CvGV(cv) = GvREFCNT_inc(gv);
3227 CvFILEGV(cv) = curcop->cop_filegv;
3229 for (ix = AvFILL(comppad); ix > 0; ix--) {
3230 if (!SvPADMY(curpad[ix]))
3231 SvPADTMP_on(curpad[ix]);
3234 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3235 CvSTART(cv) = LINKLIST(CvROOT(cv));
3236 CvROOT(cv)->op_next = 0;
3248 return newUNOP(OP_REFGEN, 0,
3249 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3256 return newUNOP(OP_REFGEN, 0,
3257 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3261 newANONSUB(floor, proto, block)
3266 return newUNOP(OP_REFGEN, 0,
3267 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3274 switch (o->op_type) {
3276 o->op_type = OP_PADAV;
3277 o->op_ppaddr = ppaddr[OP_PADAV];
3278 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3281 o->op_type = OP_RV2AV;
3282 o->op_ppaddr = ppaddr[OP_RV2AV];
3287 warn("oops: oopsAV");
3297 switch (o->op_type) {
3300 o->op_type = OP_PADHV;
3301 o->op_ppaddr = ppaddr[OP_PADHV];
3302 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3306 o->op_type = OP_RV2HV;
3307 o->op_ppaddr = ppaddr[OP_RV2HV];
3312 warn("oops: oopsHV");
3322 if (o->op_type == OP_PADANY) {
3323 o->op_type = OP_PADAV;
3324 o->op_ppaddr = ppaddr[OP_PADAV];
3327 return newUNOP(OP_RV2AV, 0, scalar(o));
3335 if (type == OP_MAPSTART)
3336 return newUNOP(OP_NULL, 0, o);
3337 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3344 if (o->op_type == OP_PADANY) {
3345 o->op_type = OP_PADHV;
3346 o->op_ppaddr = ppaddr[OP_PADHV];
3349 return newUNOP(OP_RV2HV, 0, scalar(o));
3356 croak("NOT IMPL LINE %d",__LINE__);
3366 return newUNOP(OP_RV2CV, flags, scalar(o));
3373 if (o->op_type == OP_PADANY) {
3374 o->op_type = OP_PADSV;
3375 o->op_ppaddr = ppaddr[OP_PADSV];
3378 return newUNOP(OP_RV2SV, 0, scalar(o));
3381 /* Check routines. */
3390 name = NEWSV(1106,0);
3391 sv_upgrade(name, SVt_PVNV);
3392 sv_setpvn(name, "&", 1);
3395 ix = pad_alloc(op->op_type, SVs_PADMY);
3396 av_store(comppad_name, ix, name);
3397 av_store(comppad, ix, cSVOP->op_sv);
3398 SvPADMY_on(cSVOP->op_sv);
3399 cSVOP->op_sv = Nullsv;
3400 cSVOP->op_targ = ix;
3408 op->op_private = hints;
3416 if (cUNOP->op_first->op_type == OP_CONCAT)
3417 op->op_flags |= OPf_STACKED;
3425 if (op->op_flags & OPf_KIDS) {
3428 op = modkids(ck_fun(op), op->op_type);
3429 kid = cUNOP->op_first;
3430 newop = kUNOP->op_first->op_sibling;
3432 (newop->op_sibling ||
3433 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3434 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3435 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3439 op_free(kUNOP->op_first);
3440 kUNOP->op_first = newop;
3442 op->op_ppaddr = ppaddr[++op->op_type];
3452 if (op->op_flags & OPf_KIDS) {
3453 OP *kid = cUNOP->op_first;
3454 if (kid->op_type == OP_HSLICE)
3455 op->op_private |= OPpSLICE;
3456 else if (kid->op_type != OP_HELEM)
3457 croak("%s argument is not a HASH element or slice",
3458 op_desc[op->op_type]);
3468 I32 type = op->op_type;
3470 if (op->op_flags & OPf_KIDS) {
3471 if (cLISTOP->op_first->op_type == OP_STUB) {
3473 op = newUNOP(type, OPf_SPECIAL,
3474 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3485 hints |= HINT_BLOCK_SCOPE;
3486 if (op->op_flags & OPf_KIDS) {
3487 SVOP *kid = (SVOP*)cUNOP->op_first;
3490 op->op_flags &= ~OPf_KIDS;
3493 else if (kid->op_type == OP_LINESEQ) {
3496 kid->op_next = op->op_next;
3497 cUNOP->op_first = 0;
3500 Newz(1101, enter, 1, LOGOP);
3501 enter->op_type = OP_ENTERTRY;
3502 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3503 enter->op_private = 0;
3505 /* establish postfix order */
3506 enter->op_next = (OP*)enter;
3508 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3509 op->op_type = OP_LEAVETRY;
3510 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3511 enter->op_other = op;
3517 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3519 op->op_targ = (PADOFFSET)hints;
3528 if (op->op_flags & OPf_STACKED) {
3530 kid = cUNOP->op_first->op_sibling;
3531 if (kid->op_type == OP_RV2GV)
3544 if (op->op_flags & OPf_KIDS) {
3545 OP *kid = cUNOP->op_first;
3546 if (kid->op_type != OP_HELEM)
3547 croak("%s argument is not a HASH element", op_desc[op->op_type]);
3557 o = fold_constants(o);
3558 if (o->op_type == OP_CONST)
3567 SVOP *kid = (SVOP*)cUNOP->op_first;
3569 op->op_private |= (hints & HINT_STRICT_REFS);
3570 if (kid->op_type == OP_CONST) {
3571 int iscv = (op->op_type==OP_RV2CV)*2;
3573 kid->op_type = OP_GV;
3574 for (gv = 0; !gv; iscv++) {
3576 * This is a little tricky. We only want to add the symbol if we
3577 * didn't add it in the lexer. Otherwise we get duplicate strict
3578 * warnings. But if we didn't add it in the lexer, we must at
3579 * least pretend like we wanted to add it even if it existed before,
3580 * or we get possible typo warnings. OPpCONST_ENTERED says
3581 * whether the lexer already added THIS instance of this symbol.
3583 gv = gv_fetchpv(SvPVx(kid->op_sv, na),
3584 iscv | !(kid->op_private & OPpCONST_ENTERED),
3587 : op->op_type == OP_RV2SV
3589 : op->op_type == OP_RV2AV
3591 : op->op_type == OP_RV2HV
3595 SvREFCNT_dec(kid->op_sv);
3596 kid->op_sv = SvREFCNT_inc(gv);
3605 I32 type = op->op_type;
3607 if (op->op_flags & OPf_REF)
3610 if (op->op_flags & OPf_KIDS) {
3611 SVOP *kid = (SVOP*)cUNOP->op_first;
3613 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3614 OP *newop = newGVOP(type, OPf_REF,
3615 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3622 if (type == OP_FTTTY)
3623 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3626 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3639 int type = op->op_type;
3640 register I32 oa = opargs[type] >> OASHIFT;
3642 if (op->op_flags & OPf_STACKED) {
3643 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3646 return no_fh_allowed(op);
3649 if (op->op_flags & OPf_KIDS) {
3650 tokid = &cLISTOP->op_first;
3651 kid = cLISTOP->op_first;
3652 if (kid->op_type == OP_PUSHMARK ||
3653 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3655 tokid = &kid->op_sibling;
3656 kid = kid->op_sibling;
3658 if (!kid && opargs[type] & OA_DEFGV)
3659 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3663 sibl = kid->op_sibling;
3677 if (kid->op_type == OP_CONST &&
3678 (kid->op_private & OPpCONST_BARE)) {
3679 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3680 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3681 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3683 warn("Array @%s missing the @ in argument %d of %s()",
3684 name, numargs, op_desc[type]);
3687 kid->op_sibling = sibl;
3690 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3691 bad_type(numargs, "array", op_desc[op->op_type], kid);
3695 if (kid->op_type == OP_CONST &&
3696 (kid->op_private & OPpCONST_BARE)) {
3697 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3698 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3699 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3701 warn("Hash %%%s missing the %% in argument %d of %s()",
3702 name, numargs, op_desc[type]);
3705 kid->op_sibling = sibl;
3708 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3709 bad_type(numargs, "hash", op_desc[op->op_type], kid);
3714 OP *newop = newUNOP(OP_NULL, 0, kid);
3715 kid->op_sibling = 0;
3717 newop->op_next = newop;
3719 kid->op_sibling = sibl;
3724 if (kid->op_type != OP_GV) {
3725 if (kid->op_type == OP_CONST &&
3726 (kid->op_private & OPpCONST_BARE)) {
3727 OP *newop = newGVOP(OP_GV, 0,
3728 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3734 kid->op_sibling = 0;
3735 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3737 kid->op_sibling = sibl;
3743 mod(scalar(kid), type);
3747 tokid = &kid->op_sibling;
3748 kid = kid->op_sibling;
3750 op->op_private |= numargs;
3752 return too_many_arguments(op,op_desc[op->op_type]);
3755 else if (opargs[type] & OA_DEFGV) {
3757 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3761 while (oa & OA_OPTIONAL)
3763 if (oa && oa != OA_LIST)
3764 return too_few_arguments(op,op_desc[op->op_type]);
3773 GV *gv = gv_fetchpv("glob", FALSE, SVt_PVCV);
3775 if (gv && GvIMPORTED_CV(gv)) {
3776 op->op_type = OP_LIST;
3777 op->op_ppaddr = ppaddr[OP_LIST];
3778 op = newUNOP(OP_ENTERSUB, OPf_STACKED,
3779 append_elem(OP_LIST, op,
3780 scalar(newUNOP(OP_RV2CV, 0,
3781 newGVOP(OP_GV, 0, gv)))));
3784 gv = newGVgen("main");
3786 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3797 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3799 op->op_ppaddr = ppaddr[OP_GREPSTART];
3800 Newz(1101, gwop, 1, LOGOP);
3802 if (op->op_flags & OPf_STACKED) {
3805 kid = cLISTOP->op_first->op_sibling;
3806 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3809 kid->op_next = (OP*)gwop;
3810 op->op_flags &= ~OPf_STACKED;
3812 kid = cLISTOP->op_first->op_sibling;
3813 if (type == OP_MAPWHILE)
3820 kid = cLISTOP->op_first->op_sibling;
3821 if (kid->op_type != OP_NULL)
3822 croak("panic: ck_grep");
3823 kid = kUNOP->op_first;
3825 gwop->op_type = type;
3826 gwop->op_ppaddr = ppaddr[type];
3827 gwop->op_first = listkids(op);
3828 gwop->op_flags |= OPf_KIDS;
3829 gwop->op_private = 1;
3830 gwop->op_other = LINKLIST(kid);
3831 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3832 kid->op_next = (OP*)gwop;
3834 kid = cLISTOP->op_first->op_sibling;
3835 if (!kid || !kid->op_sibling)
3836 return too_few_arguments(op,op_desc[op->op_type]);
3837 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
3838 mod(kid, OP_GREPSTART);
3847 if (op->op_flags & OPf_KIDS) {
3848 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3849 if (kid && kid->op_type == OP_CONST)
3850 fbm_compile(((SVOP*)kid)->op_sv);
3859 /* XXX length optimization goes here */
3867 return modkids(ck_fun(op), op->op_type);
3874 return refkids(ck_fun(op), op->op_type);
3883 kid = cLISTOP->op_first;
3885 op = force_list(op);
3886 kid = cLISTOP->op_first;
3888 if (kid->op_type == OP_PUSHMARK)
3889 kid = kid->op_sibling;
3890 if (kid && op->op_flags & OPf_STACKED)
3891 kid = kid->op_sibling;
3892 else if (kid && !kid->op_sibling) { /* print HANDLE; */
3893 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
3894 op->op_flags |= OPf_STACKED; /* make it a filehandle */
3895 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
3896 cLISTOP->op_first->op_sibling = kid;
3897 cLISTOP->op_last = kid;
3898 kid = kid->op_sibling;
3903 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3909 if (hints & HINT_LOCALE)
3910 op->op_private |= OPpLOCALE;
3924 if (hints & HINT_LOCALE)
3925 op->op_private |= OPpLOCALE;
3937 if (hints & HINT_LOCALE)
3938 op->op_private |= OPpLOCALE;
3948 cPMOP->op_pmflags |= PMf_RUNTIME;
3949 cPMOP->op_pmpermflags |= PMf_RUNTIME;
3964 if (cBINOP->op_first->op_flags & OPf_PARENS) {
3965 op->op_private |= OPpREPEAT_DOLIST;
3966 cBINOP->op_first = force_list(cBINOP->op_first);
3977 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
3978 SVOP *kid = (SVOP*)cUNOP->op_first;
3980 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3982 for (s = SvPVX(kid->op_sv); *s; s++) {
3983 if (*s == ':' && s[1] == ':') {
3985 Move(s+2, s+1, strlen(s+2)+1, char);
3986 --SvCUR(kid->op_sv);
3989 sv_catpvn(kid->op_sv, ".pm", 3);
3999 croak("NOT IMPL LINE %d",__LINE__);
4009 if (op->op_flags & OPf_KIDS) {
4010 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4011 if (kid && kid->op_sibling) {
4012 op->op_type = OP_SSELECT;
4013 op->op_ppaddr = ppaddr[OP_SSELECT];
4015 return fold_constants(op);
4019 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4020 if (kid && kid->op_type == OP_RV2GV)
4021 kid->op_private &= ~HINT_STRICT_REFS;
4029 I32 type = op->op_type;
4031 if (!(op->op_flags & OPf_KIDS)) {
4033 return newUNOP(type, 0,
4034 scalar(newUNOP(OP_RV2AV, 0,
4035 scalar(newGVOP(OP_GV, 0, subline
4037 : gv_fetchpv("ARGV", TRUE, SVt_PVAV) )))));
4039 return scalar(modkids(ck_fun(op), type));
4048 if (hints & HINT_LOCALE)
4049 op->op_private |= OPpLOCALE;
4052 if (op->op_flags & OPf_STACKED) {
4053 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4055 kid = kUNOP->op_first; /* get past rv2gv */
4057 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
4059 if (kid->op_type == OP_SCOPE) {
4063 else if (kid->op_type == OP_LEAVE) {
4064 if (op->op_type == OP_SORT) {
4065 null(kid); /* wipe out leave */
4068 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
4069 if (k->op_next == kid)
4074 kid->op_next = 0; /* just disconnect the leave */
4075 k = kLISTOP->op_first;
4079 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4080 null(kid); /* wipe out rv2gv */
4081 if (op->op_type == OP_SORT)
4085 op->op_flags |= OPf_SPECIAL;
4099 if (op->op_flags & OPf_STACKED)
4100 return no_fh_allowed(op);
4102 kid = cLISTOP->op_first;
4103 if (kid->op_type != OP_NULL)
4104 croak("panic: ck_split");
4105 kid = kid->op_sibling;
4106 op_free(cLISTOP->op_first);
4107 cLISTOP->op_first = kid;
4109 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
4110 cLISTOP->op_last = kid; /* There was only one element previously */
4113 if (kid->op_type != OP_MATCH) {
4114 OP *sibl = kid->op_sibling;
4115 kid->op_sibling = 0;
4116 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
4117 if (cLISTOP->op_first == cLISTOP->op_last)
4118 cLISTOP->op_last = kid;
4119 cLISTOP->op_first = kid;
4120 kid->op_sibling = sibl;
4123 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
4124 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
4128 kid->op_type = OP_PUSHRE;
4129 kid->op_ppaddr = ppaddr[OP_PUSHRE];
4132 if (!kid->op_sibling)
4133 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4135 kid = kid->op_sibling;
4138 if (!kid->op_sibling)
4139 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
4141 kid = kid->op_sibling;
4144 if (kid->op_sibling)
4145 return too_many_arguments(op,op_desc[op->op_type]);
4154 OP *prev = ((cUNOP->op_first->op_sibling)
4155 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first;
4156 OP *o = prev->op_sibling;
4163 for (cvop = o; cvop->op_sibling; cvop = cvop->op_sibling) ;
4164 if (cvop->op_type == OP_RV2CV) {
4166 op->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
4167 null(cvop); /* disable rv2cv */
4168 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
4169 if (tmpop->op_type == OP_GV) {
4170 cv = GvCV(tmpop->op_sv);
4171 if (cv && SvPOK(cv) && !(op->op_private & OPpENTERSUB_AMPER))
4172 proto = SvPV((SV*)cv,na);
4175 op->op_private |= (hints & HINT_STRICT_REFS);
4176 if (perldb && curstash != debstash)
4177 op->op_private |= OPpENTERSUB_DB;
4182 return too_many_arguments(op, CvNAME(cv));
4200 if (o->op_type != OP_REFGEN && o->op_type != OP_UNDEF)
4201 bad_type(arg, "block", CvNAME(cv), o);
4206 if (o->op_type == OP_RV2GV)
4210 o = newUNOP(OP_RV2GV, 0, kid);
4211 o->op_sibling = kid->op_sibling;
4212 kid->op_sibling = 0;
4213 prev->op_sibling = o;
4221 if (o->op_type != OP_RV2GV)
4222 bad_type(arg, "symbol", CvNAME(cv), o);
4225 if (o->op_type != OP_RV2CV)
4226 bad_type(arg, "sub", CvNAME(cv), o);
4229 if (o->op_type != OP_RV2SV && o->op_type != OP_PADSV)
4230 bad_type(arg, "scalar", CvNAME(cv), o);
4233 if (o->op_type != OP_RV2AV && o->op_type != OP_PADAV)
4234 bad_type(arg, "array", CvNAME(cv), o);
4237 if (o->op_type != OP_RV2HV && o->op_type != OP_PADHV)
4238 bad_type(arg, "hash", CvNAME(cv), o);
4242 o = newUNOP(OP_REFGEN, 0, kid);
4243 o->op_sibling = kid->op_sibling;
4244 kid->op_sibling = 0;
4245 prev->op_sibling = o;
4256 croak("Malformed prototype for %s: %s",
4257 CvNAME(cv),SvPV((SV*)cv,na));
4262 mod(o, OP_ENTERSUB);
4266 if (proto && !optional && *proto == '$')
4267 return too_few_arguments(op, CvNAME(cv));
4275 SvREADONLY_on(cSVOP->op_sv);
4283 if (op->op_flags & OPf_KIDS) {
4284 SVOP *kid = (SVOP*)cUNOP->op_first;
4286 if (kid->op_type == OP_NULL)
4287 kid = (SVOP*)kid->op_sibling;
4289 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
4290 op->op_flags |= OPf_SPECIAL;
4295 /* A peephole optimizer. We visit the ops in the order they're to execute. */
4301 register OP* oldop = 0;
4302 if (!o || o->op_seq)
4307 for (; o; o = o->op_next) {
4313 switch (o->op_type) {
4316 curcop = ((COP*)o); /* for warnings */
4317 o->op_seq = op_seqmax++;
4328 if (o->op_next->op_type == OP_STRINGIFY)
4330 o->op_seq = op_seqmax++;
4333 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
4334 o->op_seq = op_seqmax++;
4335 break; /* Scalar stub must produce undef. List stub is noop */
4339 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4340 curcop = ((COP*)op);
4346 if (oldop && o->op_next) {
4347 oldop->op_next = o->op_next;
4350 o->op_seq = op_seqmax++;
4354 if (o->op_next->op_type == OP_RV2SV) {
4355 if (!(o->op_next->op_private & OPpDEREF)) {
4357 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4358 o->op_next = o->op_next->op_next;
4359 o->op_type = OP_GVSV;
4360 o->op_ppaddr = ppaddr[OP_GVSV];
4363 else if (o->op_next->op_type == OP_RV2AV) {
4364 OP* pop = o->op_next->op_next;
4366 if (pop->op_type == OP_CONST &&
4367 (op = pop->op_next) &&
4368 pop->op_next->op_type == OP_AELEM &&
4369 !(pop->op_next->op_private & (OPpDEREF|OPpLVAL_INTRO)) &&
4370 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4374 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4378 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4379 o->op_next = pop->op_next->op_next;
4380 o->op_type = OP_AELEMFAST;
4381 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4382 o->op_private = (U8)i;
4383 GvAVn((GV*)(((SVOP*)o)->op_sv));
4386 o->op_seq = op_seqmax++;
4393 o->op_seq = op_seqmax++;
4394 peep(cLOGOP->op_other);
4398 o->op_seq = op_seqmax++;
4399 peep(cCONDOP->op_true);
4400 peep(cCONDOP->op_false);
4404 o->op_seq = op_seqmax++;
4405 peep(cLOOP->op_redoop);
4406 peep(cLOOP->op_nextop);
4407 peep(cLOOP->op_lastop);
4412 o->op_seq = op_seqmax++;
4413 peep(cPMOP->op_pmreplstart);
4417 o->op_seq = op_seqmax++;
4418 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
4419 if (o->op_next->op_sibling &&
4420 o->op_next->op_sibling->op_type != OP_DIE) {
4421 line_t oldline = curcop->cop_line;
4423 curcop->cop_line = ((COP*)o->op_next)->cop_line;
4424 warn("Statement unlikely to be reached");
4425 warn("(Maybe you meant system() when you said exec()?)\n");
4426 curcop->cop_line = oldline;
4431 o->op_seq = op_seqmax++;