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))
198 if (newoff && !CvUNIQUE(cv))
199 return 0; /* don't clone inactive sub's 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;
214 /* "It's closures all the way down." */
219 bcv && bcv != cv && !CvCLONE(bcv);
220 bcv = CvOUTSIDE(bcv))
225 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
231 /* Nothing in current lexical context--try eval's context, if any.
232 * This is necessary to let the perldb get at lexically scoped variables.
233 * XXX This will also probably interact badly with eval tree caching.
237 for (i = cx_ix; i >= 0; i--) {
239 switch (cx->cx_type) {
241 if (i == 0 && saweval) {
242 seq = cxstack[saweval].blk_oldcop->cop_seq;
243 return pad_findlex(name, newoff, seq, main_cv, 0);
247 if (cx->blk_eval.old_op_type != OP_ENTEREVAL &&
248 cx->blk_eval.old_op_type != OP_ENTERTRY)
249 return 0; /* require must have its own scope */
256 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
257 saweval = i; /* so we know where we were called from */
260 seq = cxstack[saweval].blk_oldcop->cop_seq;
261 return pad_findlex(name, newoff, seq, cv, i-1);
274 SV **svp = AvARRAY(comppad_name);
275 U32 seq = cop_seqmax;
277 /* The one we're looking for is probably just before comppad_name_fill. */
278 for (off = AvFILL(comppad_name); off > 0; off--) {
279 if ((sv = svp[off]) &&
282 seq > I_32(SvNVX(sv)) &&
283 strEQ(SvPVX(sv), name))
285 return (PADOFFSET)off;
289 /* See if it's in a nested scope */
290 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
302 SV **svp = AvARRAY(comppad_name);
304 if (min_intro_pending && fill < min_intro_pending) {
305 for (off = max_intro_pending; off >= min_intro_pending; off--) {
306 if ((sv = svp[off]) && sv != &sv_undef)
307 warn("%s never introduced", SvPVX(sv));
310 /* "Deintroduce" my variables that are leaving with this scope. */
311 for (off = AvFILL(comppad_name); off > fill; off--) {
312 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
313 SvIVX(sv) = cop_seqmax;
318 pad_alloc(optype,tmptype)
325 if (AvARRAY(comppad) != curpad)
326 croak("panic: pad_alloc");
327 if (pad_reset_pending)
329 if (tmptype & SVs_PADMY) {
331 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
332 } while (SvPADBUSY(sv)); /* need a fresh one */
333 retval = AvFILL(comppad);
336 SV **names = AvARRAY(comppad_name);
337 SSize_t names_fill = AvFILL(comppad_name);
340 * "foreach" index vars temporarily become aliases to non-"my"
341 * values. Thus we must skip, not just pad values that are
342 * marked as current pad values, but also those with names.
344 if (++padix <= names_fill &&
345 (sv = names[padix]) && sv != &sv_undef)
347 sv = *av_fetch(comppad, padix, TRUE);
348 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
353 SvFLAGS(sv) |= tmptype;
354 curpad = AvARRAY(comppad);
355 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
356 return (PADOFFSET)retval;
360 #ifndef CAN_PROTOTYPE
365 #endif /* CAN_PROTOTYPE */
368 croak("panic: pad_sv po");
369 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad sv %d\n", po));
370 return curpad[po]; /* eventually we'll turn this into a macro */
374 #ifndef CAN_PROTOTYPE
378 pad_free(PADOFFSET po)
379 #endif /* CAN_PROTOTYPE */
383 if (AvARRAY(comppad) != curpad)
384 croak("panic: pad_free curpad");
386 croak("panic: pad_free po");
387 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad free %d\n", po));
388 if (curpad[po] && curpad[po] != &sv_undef)
389 SvPADTMP_off(curpad[po]);
395 #ifndef CAN_PROTOTYPE
399 pad_swipe(PADOFFSET po)
400 #endif /* CAN_PROTOTYPE */
402 if (AvARRAY(comppad) != curpad)
403 croak("panic: pad_swipe curpad");
405 croak("panic: pad_swipe po");
406 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad swipe %d\n", po));
407 SvPADTMP_off(curpad[po]);
408 curpad[po] = NEWSV(1107,0);
409 SvPADTMP_on(curpad[po]);
419 if (AvARRAY(comppad) != curpad)
420 croak("panic: pad_reset curpad");
421 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad reset\n"));
422 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
423 for (po = AvMAX(comppad); po > padix_floor; po--) {
424 if (curpad[po] && curpad[po] != &sv_undef)
425 SvPADTMP_off(curpad[po]);
429 pad_reset_pending = FALSE;
438 register OP *kid, *nextkid;
440 if (!op || op->op_seq == (U16)-1)
443 if (op->op_flags & OPf_KIDS) {
444 for (kid = cUNOP->op_first; kid; kid = nextkid) {
445 nextkid = kid->op_sibling; /* Get before next freeing kid */
450 switch (op->op_type) {
452 op->op_targ = 0; /* Was holding old type, if any. */
455 op->op_targ = 0; /* Was holding hints. */
459 SvREFCNT_dec(cGVOP->op_gv);
463 Safefree(cCOP->cop_label);
464 SvREFCNT_dec(cCOP->cop_filegv);
467 SvREFCNT_dec(cSVOP->op_sv);
473 if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
477 Safefree(cPVOP->op_pv);
480 op_free(cPMOP->op_pmreplroot);
484 pregfree(cPMOP->op_pmregexp);
485 SvREFCNT_dec(cPMOP->op_pmshort);
492 pad_free(op->op_targ);
501 if (op->op_type != OP_NULL && op->op_targ > 0)
502 pad_free(op->op_targ);
503 op->op_targ = op->op_type;
504 op->op_type = OP_NULL;
505 op->op_ppaddr = ppaddr[OP_NULL];
508 /* Contextualizers */
510 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
521 /* establish postfix order */
522 if (cUNOP->op_first) {
523 op->op_next = LINKLIST(cUNOP->op_first);
524 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
526 kid->op_next = LINKLIST(kid->op_sibling);
542 if (op && op->op_flags & OPf_KIDS) {
543 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
554 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
555 line_t oldline = curcop->cop_line;
557 if (copline != NOLINE)
558 curcop->cop_line = copline;
559 warn("Found = in conditional, should be ==");
560 curcop->cop_line = oldline;
571 /* assumes no premature commitment */
572 if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
576 op->op_flags &= ~OPf_LIST;
577 op->op_flags |= OPf_KNOW;
579 switch (op->op_type) {
581 if (op->op_private & OPpREPEAT_DOLIST)
582 null(((LISTOP*)cBINOP->op_first)->op_first);
583 scalar(cBINOP->op_first);
588 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
592 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
593 if (!kPMOP->op_pmreplroot)
594 deprecate("implicit split to @_");
601 if (op->op_flags & OPf_KIDS) {
602 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
608 scalar(cLISTOP->op_first);
613 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
633 if (!op || error_count)
635 if (op->op_flags & OPf_LIST)
638 op->op_flags |= OPf_KNOW;
640 switch (op->op_type) {
642 if (!(opargs[op->op_type] & OA_FOLDCONST))
646 if (op->op_flags & OPf_STACKED)
719 if (!(op->op_private & OPpLVAL_INTRO))
720 useless = op_desc[op->op_type];
727 if (!(op->op_private & OPpLVAL_INTRO) &&
728 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
729 useless = "a variable";
734 curcop = ((COP*)op); /* for warning below */
740 useless = "a constant";
741 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
743 else if (SvPOK(sv)) {
744 if (strnEQ(SvPVX(sv), "di", 2) ||
745 strnEQ(SvPVX(sv), "ds", 2) ||
746 strnEQ(SvPVX(sv), "ig", 2))
750 null(op); /* don't execute a constant */
751 SvREFCNT_dec(sv); /* don't even remember it */
755 op->op_type = OP_PREINC; /* pre-increment is faster */
756 op->op_ppaddr = ppaddr[OP_PREINC];
760 op->op_type = OP_PREDEC; /* pre-decrement is faster */
761 op->op_ppaddr = ppaddr[OP_PREDEC];
767 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
771 if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
772 curcop = ((COP*)op); /* for warning below */
773 if (op->op_flags & OPf_STACKED)
778 if (!(op->op_flags & OPf_KIDS))
784 op->op_private |= OPpLEAVE_VOID;
787 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
791 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
792 if (!kPMOP->op_pmreplroot)
793 deprecate("implicit split to @_");
797 op->op_private |= OPpLEAVE_VOID;
800 if (useless && dowarn)
801 warn("Useless use of %s in void context", useless);
810 if (op && op->op_flags & OPf_KIDS) {
811 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
823 /* assumes no premature commitment */
824 if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
828 op->op_flags |= (OPf_KNOW | OPf_LIST);
830 switch (op->op_type) {
833 list(cBINOP->op_first);
838 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
845 if (!(op->op_flags & OPf_KIDS))
847 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
848 list(cBINOP->op_first);
849 return gen_constant_list(op);
856 list(cLISTOP->op_first);
860 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
879 if (op->op_type == OP_LINESEQ ||
880 op->op_type == OP_SCOPE ||
881 op->op_type == OP_LEAVE ||
882 op->op_type == OP_LEAVETRY)
884 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
885 if (kid->op_sibling) {
891 op->op_flags &= ~OPf_PARENS;
892 if (hints & HINT_BLOCK_SCOPE)
893 op->op_flags |= OPf_PARENS;
896 op = newOP(OP_STUB, 0);
906 if (op && op->op_flags & OPf_KIDS) {
907 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
923 if (!op || error_count)
926 switch (op->op_type) {
928 if (!(op->op_private & (OPpCONST_ARYBASE)))
930 if (eval_start && eval_start->op_type == OP_CONST) {
931 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
935 SAVEI32(compiling.cop_arybase);
936 compiling.cop_arybase = 0;
938 else if (type == OP_REFGEN)
941 croak("That use of $[ is unsupported");
944 if (op->op_flags & OPf_PARENS)
948 if ((type == OP_UNDEF || type == OP_REFGEN) &&
949 !(op->op_flags & OPf_STACKED)) {
950 op->op_type = OP_RV2CV; /* entersub => rv2cv */
951 op->op_ppaddr = ppaddr[OP_RV2CV];
952 assert(cUNOP->op_first->op_type == OP_NULL);
953 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
959 /* grep, foreach, subcalls, refgen */
960 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
962 sprintf(tokenbuf, "Can't modify %s in %s",
963 op_desc[op->op_type],
964 type ? op_desc[type] : "local");
988 if (!(op->op_flags & OPf_STACKED))
994 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1000 if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
1002 return op; /* Treat \(@foo) like ordinary list. */
1006 ref(cUNOP->op_first, op->op_type);
1018 if (!type && cUNOP->op_first->op_type != OP_GV)
1019 croak("Can't localize a reference");
1020 ref(cUNOP->op_first, op->op_type);
1033 if (type == OP_REFGEN && op->op_flags & OPf_PARENS)
1034 return op; /* Treat \(@foo) like ordinary list. */
1039 croak("Can't localize lexical variable %s",
1040 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
1047 if (type != OP_SASSIGN)
1053 pad_free(op->op_targ);
1054 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
1055 assert(SvTYPE(PAD_SV(op->op_targ)) == SVt_NULL);
1056 if (op->op_flags & OPf_KIDS)
1057 mod(cBINOP->op_first->op_sibling, type);
1062 ref(cBINOP->op_first, op->op_type);
1069 if (op->op_flags & OPf_KIDS)
1070 mod(cLISTOP->op_last, type);
1074 if (!(op->op_flags & OPf_KIDS))
1076 if (op->op_targ != OP_LIST) {
1077 mod(cBINOP->op_first, type);
1082 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1086 op->op_flags |= OPf_MOD;
1088 if (type == OP_AASSIGN || type == OP_SASSIGN)
1089 op->op_flags |= OPf_SPECIAL|OPf_REF;
1091 op->op_private |= OPpLVAL_INTRO;
1092 op->op_flags &= ~OPf_SPECIAL;
1094 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1095 op->op_flags |= OPf_REF;
1105 if (op && op->op_flags & OPf_KIDS) {
1106 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1119 if (!op || error_count)
1122 switch (op->op_type) {
1124 if ((type == OP_DEFINED) &&
1125 !(op->op_flags & OPf_STACKED)) {
1126 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1127 op->op_ppaddr = ppaddr[OP_RV2CV];
1128 assert(cUNOP->op_first->op_type == OP_NULL);
1129 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1130 op->op_flags |= OPf_SPECIAL;
1135 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1139 ref(cUNOP->op_first, op->op_type);
1142 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1143 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1144 : type == OP_RV2HV ? OPpDEREF_HV
1146 op->op_flags |= OPf_MOD;
1152 op->op_flags |= OPf_REF;
1155 ref(cUNOP->op_first, op->op_type);
1160 op->op_flags |= OPf_REF;
1165 if (!(op->op_flags & OPf_KIDS))
1167 ref(cBINOP->op_first, type);
1171 ref(cBINOP->op_first, op->op_type);
1172 if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) {
1173 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV
1174 : type == OP_RV2HV ? OPpDEREF_HV
1176 op->op_flags |= OPf_MOD;
1184 if (!(op->op_flags & OPf_KIDS))
1186 ref(cLISTOP->op_last, type);
1202 if (!op || error_count)
1206 if (type == OP_LIST) {
1207 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1210 else if (type != OP_PADSV &&
1213 type != OP_PUSHMARK)
1215 sprintf(tokenbuf, "Can't declare %s in my", op_desc[op->op_type]);
1219 op->op_flags |= OPf_MOD;
1220 op->op_private |= OPpLVAL_INTRO;
1229 o->op_flags |= OPf_PARENS;
1234 bind_match(type, left, right)
1241 if (right->op_type == OP_MATCH ||
1242 right->op_type == OP_SUBST ||
1243 right->op_type == OP_TRANS) {
1244 right->op_flags |= OPf_STACKED;
1245 if (right->op_type != OP_MATCH)
1246 left = mod(left, right->op_type);
1247 if (right->op_type == OP_TRANS)
1248 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1250 op = prepend_elem(right->op_type, scalar(left), right);
1252 return newUNOP(OP_NOT, 0, scalar(op));
1256 return bind_match(type, left,
1257 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1266 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1267 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1275 if (o->op_flags & OPf_PARENS || perldb || tainting) {
1276 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1277 o->op_type = OP_LEAVE;
1278 o->op_ppaddr = ppaddr[OP_LEAVE];
1281 if (o->op_type == OP_LINESEQ) {
1283 o->op_type = OP_SCOPE;
1284 o->op_ppaddr = ppaddr[OP_SCOPE];
1285 kid = ((LISTOP*)o)->op_first;
1286 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1287 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1292 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1302 int retval = savestack_ix;
1303 SAVEI32(comppad_name_floor);
1305 if ((comppad_name_fill = AvFILL(comppad_name)) > 0)
1306 comppad_name_floor = comppad_name_fill;
1308 comppad_name_floor = 0;
1310 SAVEI32(min_intro_pending);
1311 SAVEI32(max_intro_pending);
1312 min_intro_pending = 0;
1313 SAVEI32(comppad_name_fill);
1314 SAVEI32(padix_floor);
1315 padix_floor = padix;
1316 pad_reset_pending = FALSE;
1318 hints &= ~HINT_BLOCK_SCOPE;
1323 block_end(floor, seq)
1327 int needblockscope = hints & HINT_BLOCK_SCOPE;
1328 OP* retval = scalarseq(seq);
1330 pad_reset_pending = FALSE;
1332 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1333 pad_leavemy(comppad_name_fill);
1343 eval_root = newUNOP(OP_LEAVEEVAL, ((in_eval & 4) ? OPf_SPECIAL : 0), op);
1344 eval_start = linklist(eval_root);
1345 eval_root->op_next = 0;
1353 main_root = scope(sawparens(scalarvoid(op)));
1354 curcop = &compiling;
1355 main_start = LINKLIST(main_root);
1356 main_root->op_next = 0;
1368 if (o->op_flags & OPf_PARENS)
1372 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1374 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1375 if (*s == ';' || *s == '=')
1376 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1383 return mod(o, OP_NULL); /* a bit kludgey */
1390 if (o->op_type == OP_LIST) {
1391 o = convert(OP_JOIN, 0,
1392 prepend_elem(OP_LIST,
1393 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1404 I32 type = o->op_type;
1407 if (opargs[type] & OA_RETSCALAR)
1409 if (opargs[type] & OA_TARGET)
1410 o->op_targ = pad_alloc(type, SVs_PADTMP);
1412 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1413 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1415 if (!(opargs[type] & OA_FOLDCONST))
1419 goto nope; /* Don't try to run w/ errors */
1421 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1422 if (curop->op_type != OP_CONST &&
1423 curop->op_type != OP_LIST &&
1424 curop->op_type != OP_SCALAR &&
1425 curop->op_type != OP_NULL &&
1426 curop->op_type != OP_PUSHMARK) {
1431 curop = LINKLIST(o);
1436 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1437 pad_swipe(o->op_targ);
1438 else if (SvTEMP(sv)) { /* grab mortal temp? */
1439 (void)SvREFCNT_inc(sv);
1443 if (type == OP_RV2GV)
1444 return newGVOP(OP_GV, 0, (GV*)sv);
1446 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1448 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1453 SvIOK_off(sv); /* undo SvIV() damage */
1455 return newSVOP(OP_CONST, 0, sv);
1459 if (!(opargs[type] & OA_OTHERINT))
1462 if (!(hints & HINT_INTEGER)) {
1463 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1466 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1467 if (curop->op_type == OP_CONST) {
1468 if (SvIOK(((SVOP*)curop)->op_sv))
1472 if (opargs[curop->op_type] & OA_RETINTEGER)
1476 o->op_ppaddr = ppaddr[++(o->op_type)];
1483 gen_constant_list(o)
1487 I32 oldtmps_floor = tmps_floor;
1491 return o; /* Don't attempt to run with errors */
1493 op = curop = LINKLIST(o);
1499 tmps_floor = oldtmps_floor;
1501 o->op_type = OP_RV2AV;
1502 o->op_ppaddr = ppaddr[OP_RV2AV];
1503 curop = ((UNOP*)o)->op_first;
1504 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1511 convert(type, flags, op)
1519 if (!op || op->op_type != OP_LIST)
1520 op = newLISTOP(OP_LIST, 0, op, Nullop);
1522 op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1524 if (!(opargs[type] & OA_MARK))
1525 null(cLISTOP->op_first);
1528 op->op_ppaddr = ppaddr[type];
1529 op->op_flags |= flags;
1531 op = CHECKOP(type, op);
1532 if (op->op_type != type)
1535 if (cLISTOP->op_children < 7) {
1536 /* XXX do we really need to do this if we're done appending?? */
1537 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1539 cLISTOP->op_last = last; /* in case check substituted last arg */
1542 return fold_constants(op);
1545 /* List constructors */
1548 append_elem(type, first, last)
1559 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1560 return newLISTOP(type, 0, first, last);
1562 if (first->op_flags & OPf_KIDS)
1563 ((LISTOP*)first)->op_last->op_sibling = last;
1565 first->op_flags |= OPf_KIDS;
1566 ((LISTOP*)first)->op_first = last;
1568 ((LISTOP*)first)->op_last = last;
1569 ((LISTOP*)first)->op_children++;
1574 append_list(type, first, last)
1585 if (first->op_type != type)
1586 return prepend_elem(type, (OP*)first, (OP*)last);
1588 if (last->op_type != type)
1589 return append_elem(type, (OP*)first, (OP*)last);
1591 first->op_last->op_sibling = last->op_first;
1592 first->op_last = last->op_last;
1593 first->op_children += last->op_children;
1594 if (first->op_children)
1595 last->op_flags |= OPf_KIDS;
1602 prepend_elem(type, first, last)
1613 if (last->op_type == type) {
1614 if (type == OP_LIST) { /* already a PUSHMARK there */
1615 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1616 ((LISTOP*)last)->op_first->op_sibling = first;
1619 if (!(last->op_flags & OPf_KIDS)) {
1620 ((LISTOP*)last)->op_last = first;
1621 last->op_flags |= OPf_KIDS;
1623 first->op_sibling = ((LISTOP*)last)->op_first;
1624 ((LISTOP*)last)->op_first = first;
1626 ((LISTOP*)last)->op_children++;
1630 return newLISTOP(type, 0, first, last);
1638 return newOP(OP_STUB, 0);
1645 if (!op || op->op_type != OP_LIST)
1646 op = newLISTOP(OP_LIST, 0, op, Nullop);
1652 newLISTOP(type, flags, first, last)
1660 Newz(1101, listop, 1, LISTOP);
1662 listop->op_type = type;
1663 listop->op_ppaddr = ppaddr[type];
1664 listop->op_children = (first != 0) + (last != 0);
1665 listop->op_flags = flags;
1669 else if (!first && last)
1672 first->op_sibling = last;
1673 listop->op_first = first;
1674 listop->op_last = last;
1675 if (type == OP_LIST) {
1677 pushop = newOP(OP_PUSHMARK, 0);
1678 pushop->op_sibling = first;
1679 listop->op_first = pushop;
1680 listop->op_flags |= OPf_KIDS;
1682 listop->op_last = pushop;
1684 else if (listop->op_children)
1685 listop->op_flags |= OPf_KIDS;
1696 Newz(1101, op, 1, OP);
1698 op->op_ppaddr = ppaddr[type];
1699 op->op_flags = flags;
1702 op->op_private = 0 + (flags >> 8);
1703 if (opargs[type] & OA_RETSCALAR)
1705 if (opargs[type] & OA_TARGET)
1706 op->op_targ = pad_alloc(type, SVs_PADTMP);
1707 return CHECKOP(type, op);
1711 newUNOP(type, flags, first)
1719 first = newOP(OP_STUB, 0);
1720 if (opargs[type] & OA_MARK)
1721 first = force_list(first);
1723 Newz(1101, unop, 1, UNOP);
1724 unop->op_type = type;
1725 unop->op_ppaddr = ppaddr[type];
1726 unop->op_first = first;
1727 unop->op_flags = flags | OPf_KIDS;
1728 unop->op_private = 1 | (flags >> 8);
1730 unop = (UNOP*) CHECKOP(type, unop);
1734 return fold_constants((OP *) unop);
1738 newBINOP(type, flags, first, last)
1745 Newz(1101, binop, 1, BINOP);
1748 first = newOP(OP_NULL, 0);
1750 binop->op_type = type;
1751 binop->op_ppaddr = ppaddr[type];
1752 binop->op_first = first;
1753 binop->op_flags = flags | OPf_KIDS;
1756 binop->op_private = 1 | (flags >> 8);
1759 binop->op_private = 2 | (flags >> 8);
1760 first->op_sibling = last;
1763 binop = (BINOP*)CHECKOP(type, binop);
1767 binop->op_last = last = binop->op_first->op_sibling;
1769 return fold_constants((OP *)binop);
1773 pmtrans(op, expr, repl)
1778 SV *tstr = ((SVOP*)expr)->op_sv;
1779 SV *rstr = ((SVOP*)repl)->op_sv;
1782 register U8 *t = (U8*)SvPV(tstr, tlen);
1783 register U8 *r = (U8*)SvPV(rstr, rlen);
1788 register short *tbl;
1790 tbl = (short*)cPVOP->op_pv;
1791 complement = op->op_private & OPpTRANS_COMPLEMENT;
1792 delete = op->op_private & OPpTRANS_DELETE;
1793 /* squash = op->op_private & OPpTRANS_SQUASH; */
1796 Zero(tbl, 256, short);
1797 for (i = 0; i < tlen; i++)
1799 for (i = 0, j = 0; i < 256; i++) {
1815 if (!rlen && !delete) {
1818 for (i = 0; i < 256; i++)
1820 for (i = 0, j = 0; i < tlen; i++,j++) {
1823 if (tbl[t[i]] == -1)
1829 if (tbl[t[i]] == -1)
1840 newPMOP(type, flags)
1846 Newz(1101, pmop, 1, PMOP);
1847 pmop->op_type = type;
1848 pmop->op_ppaddr = ppaddr[type];
1849 pmop->op_flags = flags;
1850 pmop->op_private = 0 | (flags >> 8);
1852 if (hints & HINT_LOCALE)
1853 pmop->op_pmpermflags = (pmop->op_pmflags |= PMf_LOCALE);
1855 /* link into pm list */
1856 if (type != OP_TRANS && curstash) {
1857 pmop->op_pmnext = HvPMROOT(curstash);
1858 HvPMROOT(curstash) = pmop;
1865 pmruntime(op, expr, repl)
1873 if (op->op_type == OP_TRANS)
1874 return pmtrans(op, expr, repl);
1878 if (expr->op_type == OP_CONST) {
1880 SV *pat = ((SVOP*)expr)->op_sv;
1881 char *p = SvPV(pat, plen);
1882 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1883 sv_setpvn(pat, "\\s+", 3);
1884 p = SvPV(pat, plen);
1885 pm->op_pmflags |= PMf_SKIPWHITE;
1887 pm->op_pmregexp = pregcomp(p, p + plen, pm);
1888 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1889 pm->op_pmflags |= PMf_WHITE;
1894 if (pm->op_pmflags & PMf_KEEP)
1895 expr = newUNOP(OP_REGCMAYBE,0,expr);
1897 Newz(1101, rcop, 1, LOGOP);
1898 rcop->op_type = OP_REGCOMP;
1899 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1900 rcop->op_first = scalar(expr);
1901 rcop->op_flags |= OPf_KIDS;
1902 rcop->op_private = 1;
1903 rcop->op_other = op;
1905 /* establish postfix order */
1906 if (pm->op_pmflags & PMf_KEEP) {
1908 rcop->op_next = expr;
1909 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1912 rcop->op_next = LINKLIST(expr);
1913 expr->op_next = (OP*)rcop;
1916 prepend_elem(op->op_type, scalar((OP*)rcop), op);
1921 if (pm->op_pmflags & PMf_EVAL)
1923 else if (repl->op_type == OP_CONST)
1927 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1928 if (opargs[curop->op_type] & OA_DANGEROUS) {
1929 if (curop->op_type == OP_GV) {
1930 GV *gv = ((GVOP*)curop)->op_gv;
1931 if (strchr("&`'123456789+", *GvENAME(gv)))
1934 else if (curop->op_type == OP_RV2CV)
1936 else if (curop->op_type == OP_RV2SV ||
1937 curop->op_type == OP_RV2AV ||
1938 curop->op_type == OP_RV2HV ||
1939 curop->op_type == OP_RV2GV) {
1940 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1943 else if (curop->op_type == OP_PADSV ||
1944 curop->op_type == OP_PADAV ||
1945 curop->op_type == OP_PADHV ||
1946 curop->op_type == OP_PADANY) {
1955 if (curop == repl) {
1956 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1957 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
1958 prepend_elem(op->op_type, scalar(repl), op);
1961 Newz(1101, rcop, 1, LOGOP);
1962 rcop->op_type = OP_SUBSTCONT;
1963 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1964 rcop->op_first = scalar(repl);
1965 rcop->op_flags |= OPf_KIDS;
1966 rcop->op_private = 1;
1967 rcop->op_other = op;
1969 /* establish postfix order */
1970 rcop->op_next = LINKLIST(repl);
1971 repl->op_next = (OP*)rcop;
1973 pm->op_pmreplroot = scalar((OP*)rcop);
1974 pm->op_pmreplstart = LINKLIST(rcop);
1983 newSVOP(type, flags, sv)
1989 Newz(1101, svop, 1, SVOP);
1990 svop->op_type = type;
1991 svop->op_ppaddr = ppaddr[type];
1993 svop->op_next = (OP*)svop;
1994 svop->op_flags = flags;
1995 if (opargs[type] & OA_RETSCALAR)
1997 if (opargs[type] & OA_TARGET)
1998 svop->op_targ = pad_alloc(type, SVs_PADTMP);
1999 return CHECKOP(type, svop);
2003 newGVOP(type, flags, gv)
2009 Newz(1101, gvop, 1, GVOP);
2010 gvop->op_type = type;
2011 gvop->op_ppaddr = ppaddr[type];
2012 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
2013 gvop->op_next = (OP*)gvop;
2014 gvop->op_flags = flags;
2015 if (opargs[type] & OA_RETSCALAR)
2017 if (opargs[type] & OA_TARGET)
2018 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
2019 return CHECKOP(type, gvop);
2023 newPVOP(type, flags, pv)
2029 Newz(1101, pvop, 1, PVOP);
2030 pvop->op_type = type;
2031 pvop->op_ppaddr = ppaddr[type];
2033 pvop->op_next = (OP*)pvop;
2034 pvop->op_flags = flags;
2035 if (opargs[type] & OA_RETSCALAR)
2037 if (opargs[type] & OA_TARGET)
2038 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2039 return CHECKOP(type, pvop);
2048 save_hptr(&curstash);
2049 save_item(curstname);
2054 name = SvPV(sv, len);
2055 curstash = gv_stashpvn(name,len,TRUE);
2056 sv_setpvn(curstname, name, len);
2060 sv_setpv(curstname,"<none>");
2068 utilize(aver, floor, version, id, arg)
2081 if (id->op_type != OP_CONST)
2082 croak("Module name must be constant");
2086 if(version != Nullop) {
2087 SV *vesv = ((SVOP*)version)->op_sv;
2089 if (arg == Nullop && !SvNIOK(vesv)) {
2096 if (version->op_type != OP_CONST || !SvNIOK(vesv))
2097 croak("Version number must be constant number");
2099 /* Make copy of id so we don't free it twice */
2100 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2102 /* Fake up a method call to VERSION */
2103 meth = newSVOP(OP_CONST, 0, newSVpv("VERSION", 7));
2104 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2105 append_elem(OP_LIST,
2106 prepend_elem(OP_LIST, pack, list(version)),
2107 newUNOP(OP_METHOD, 0, meth)));
2111 /* Fake up an import/unimport */
2112 if (arg && arg->op_type == OP_STUB)
2113 imop = arg; /* no import on explicit () */
2114 else if(SvNIOK(((SVOP*)id)->op_sv)) {
2115 imop = Nullop; /* use 5.0; */
2118 /* Make copy of id so we don't free it twice */
2119 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2120 meth = newSVOP(OP_CONST, 0,
2122 ? newSVpv("import", 6)
2123 : newSVpv("unimport", 8)
2125 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2126 append_elem(OP_LIST,
2127 prepend_elem(OP_LIST, pack, list(arg)),
2128 newUNOP(OP_METHOD, 0, meth)));
2131 /* Fake up a require */
2132 rqop = newUNOP(OP_REQUIRE, 0, id);
2134 /* Fake up the BEGIN {}, which does its thing immediately. */
2136 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2138 append_elem(OP_LINESEQ,
2139 append_elem(OP_LINESEQ,
2140 newSTATEOP(0, Nullch, rqop),
2141 newSTATEOP(0, Nullch, veop)),
2142 newSTATEOP(0, Nullch, imop) ));
2149 newSLICEOP(flags, subscript, listval)
2154 return newBINOP(OP_LSLICE, flags,
2155 list(force_list(subscript)),
2156 list(force_list(listval)) );
2166 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2167 op = cUNOP->op_first;
2169 if (op->op_type == OP_COND_EXPR) {
2170 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2171 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2176 yyerror("Assignment to both a list and a scalar");
2180 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2181 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2182 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2185 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2188 if (op->op_type == OP_RV2SV)
2195 newASSIGNOP(flags, left, optype, right)
2204 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2205 return newLOGOP(optype, 0,
2206 mod(scalar(left), optype),
2207 newUNOP(OP_SASSIGN, 0, scalar(right)));
2210 return newBINOP(optype, OPf_STACKED,
2211 mod(scalar(left), optype), scalar(right));
2215 if (list_assignment(left)) {
2217 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2218 left = mod(left, OP_AASSIGN);
2226 op = newBINOP(OP_AASSIGN, flags,
2227 list(force_list(right)),
2228 list(force_list(left)) );
2229 op->op_private = 0 | (flags >> 8);
2230 if (!(left->op_private & OPpLVAL_INTRO)) {
2231 static int generation = 100;
2235 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2236 if (opargs[curop->op_type] & OA_DANGEROUS) {
2237 if (curop->op_type == OP_GV) {
2238 GV *gv = ((GVOP*)curop)->op_gv;
2239 if (gv == defgv || SvCUR(gv) == generation)
2241 SvCUR(gv) = generation;
2243 else if (curop->op_type == OP_PADSV ||
2244 curop->op_type == OP_PADAV ||
2245 curop->op_type == OP_PADHV ||
2246 curop->op_type == OP_PADANY) {
2247 SV **svp = AvARRAY(comppad_name);
2248 SV *sv = svp[curop->op_targ];
2249 if (SvCUR(sv) == generation)
2251 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2253 else if (curop->op_type == OP_RV2CV)
2255 else if (curop->op_type == OP_RV2SV ||
2256 curop->op_type == OP_RV2AV ||
2257 curop->op_type == OP_RV2HV ||
2258 curop->op_type == OP_RV2GV) {
2259 if (lastop->op_type != OP_GV) /* funny deref? */
2268 op->op_private = OPpASSIGN_COMMON;
2270 if (right && right->op_type == OP_SPLIT) {
2272 if ((tmpop = ((LISTOP*)right)->op_first) &&
2273 tmpop->op_type == OP_PUSHRE)
2275 PMOP *pm = (PMOP*)tmpop;
2276 if (left->op_type == OP_RV2AV &&
2277 !(left->op_private & OPpLVAL_INTRO) &&
2278 !(op->op_private & OPpASSIGN_COMMON) )
2280 tmpop = ((UNOP*)left)->op_first;
2281 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2282 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2283 pm->op_pmflags |= PMf_ONCE;
2284 tmpop = ((UNOP*)op)->op_first; /* to list (nulled) */
2285 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2286 tmpop->op_sibling = Nullop; /* don't free split */
2287 right->op_next = tmpop->op_next; /* fix starting loc */
2288 op_free(op); /* blow off assign */
2289 right->op_flags &= ~(OPf_KNOW|OPf_LIST);
2290 /* "I don't know and I don't care." */
2295 if (modcount < 10000 &&
2296 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2298 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2300 sv_setiv(sv, modcount+1);
2308 right = newOP(OP_UNDEF, 0);
2309 if (right->op_type == OP_READLINE) {
2310 right->op_flags |= OPf_STACKED;
2311 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2314 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2315 op = newBINOP(OP_SASSIGN, flags,
2316 scalar(right), mod(scalar(left), OP_SASSIGN) );
2328 newSTATEOP(flags, label, op)
2333 U32 seq = intro_my();
2336 Newz(1101, cop, 1, COP);
2337 if (perldb && curcop->cop_line && curstash != debstash) {
2338 cop->op_type = OP_DBSTATE;
2339 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2342 cop->op_type = OP_NEXTSTATE;
2343 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2345 cop->op_flags = flags;
2346 cop->op_private = 0 | (flags >> 8);
2347 cop->op_next = (OP*)cop;
2350 cop->cop_label = label;
2351 hints |= HINT_BLOCK_SCOPE;
2354 cop->cop_arybase = curcop->cop_arybase;
2356 if (copline == NOLINE)
2357 cop->cop_line = curcop->cop_line;
2359 cop->cop_line = copline;
2362 cop->cop_filegv = GvREFCNT_inc(curcop->cop_filegv);
2363 cop->cop_stash = curstash;
2365 if (perldb && curstash != debstash) {
2366 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2367 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2368 (void)SvIOK_on(*svp);
2370 SvSTASH(*svp) = (HV*)cop;
2374 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2377 /* "Introduce" my variables to visible status. */
2385 if (! min_intro_pending)
2388 svp = AvARRAY(comppad_name);
2389 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2390 if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2391 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2392 SvNVX(sv) = (double)cop_seqmax;
2395 min_intro_pending = 0;
2396 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2397 return cop_seqmax++;
2401 newLOGOP(type, flags, first, other)
2410 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2411 return newBINOP(type, flags, scalar(first), scalar(other));
2413 scalarboolean(first);
2414 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2415 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2416 if (type == OP_AND || type == OP_OR) {
2422 first = cUNOP->op_first;
2424 first->op_next = op->op_next;
2425 cUNOP->op_first = Nullop;
2429 if (first->op_type == OP_CONST) {
2430 if (dowarn && (first->op_private & OPpCONST_BARE))
2431 warn("Probable precedence problem on %s", op_desc[type]);
2432 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2441 else if (first->op_type == OP_WANTARRAY) {
2451 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2452 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2454 Newz(1101, logop, 1, LOGOP);
2456 logop->op_type = type;
2457 logop->op_ppaddr = ppaddr[type];
2458 logop->op_first = first;
2459 logop->op_flags = flags | OPf_KIDS;
2460 logop->op_other = LINKLIST(other);
2461 logop->op_private = 1 | (flags >> 8);
2463 /* establish postfix order */
2464 logop->op_next = LINKLIST(first);
2465 first->op_next = (OP*)logop;
2466 first->op_sibling = other;
2468 op = newUNOP(OP_NULL, 0, (OP*)logop);
2469 other->op_next = op;
2475 newCONDOP(flags, first, trueop, falseop)
2485 return newLOGOP(OP_AND, 0, first, trueop);
2487 return newLOGOP(OP_OR, 0, first, falseop);
2489 scalarboolean(first);
2490 if (first->op_type == OP_CONST) {
2491 if (SvTRUE(((SVOP*)first)->op_sv)) {
2502 else if (first->op_type == OP_WANTARRAY) {
2506 Newz(1101, condop, 1, CONDOP);
2508 condop->op_type = OP_COND_EXPR;
2509 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2510 condop->op_first = first;
2511 condop->op_flags = flags | OPf_KIDS;
2512 condop->op_true = LINKLIST(trueop);
2513 condop->op_false = LINKLIST(falseop);
2514 condop->op_private = 1 | (flags >> 8);
2516 /* establish postfix order */
2517 condop->op_next = LINKLIST(first);
2518 first->op_next = (OP*)condop;
2520 first->op_sibling = trueop;
2521 trueop->op_sibling = falseop;
2522 op = newUNOP(OP_NULL, 0, (OP*)condop);
2524 trueop->op_next = op;
2525 falseop->op_next = op;
2531 newRANGE(flags, left, right)
2541 Newz(1101, condop, 1, CONDOP);
2543 condop->op_type = OP_RANGE;
2544 condop->op_ppaddr = ppaddr[OP_RANGE];
2545 condop->op_first = left;
2546 condop->op_flags = OPf_KIDS;
2547 condop->op_true = LINKLIST(left);
2548 condop->op_false = LINKLIST(right);
2549 condop->op_private = 1 | (flags >> 8);
2551 left->op_sibling = right;
2553 condop->op_next = (OP*)condop;
2554 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2555 flop = newUNOP(OP_FLOP, 0, flip);
2556 op = newUNOP(OP_NULL, 0, flop);
2559 left->op_next = flip;
2560 right->op_next = flop;
2562 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2563 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2564 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2565 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2567 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2568 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2571 if (!flip->op_private || !flop->op_private)
2572 linklist(op); /* blow off optimizer unless constant */
2578 newLOOPOP(flags, debuggable, expr, block)
2586 int once = block && block->op_flags & OPf_SPECIAL &&
2587 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2590 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2591 return block; /* do {} while 0 does once */
2592 else if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)
2593 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2596 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2597 op = newLOGOP(OP_AND, 0, expr, listop);
2599 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2601 if (once && op != listop)
2602 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2605 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2607 op->op_flags |= flags;
2609 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2614 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2628 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2629 expr = newUNOP(OP_DEFINED, 0,
2630 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2634 block = newOP(OP_NULL, 0);
2637 next = LINKLIST(cont);
2639 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2641 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2642 redo = LINKLIST(listop);
2645 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2646 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2647 op_free(expr); /* oops, it's a while (0) */
2649 return Nullop; /* (listop already freed by newLOGOP) */
2651 ((LISTOP*)listop)->op_last->op_next = condop =
2652 (op == listop ? redo : LINKLIST(op));
2660 Newz(1101,loop,1,LOOP);
2661 loop->op_type = OP_ENTERLOOP;
2662 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2663 loop->op_private = 0;
2664 loop->op_next = (OP*)loop;
2667 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2669 loop->op_redoop = redo;
2670 loop->op_lastop = op;
2673 loop->op_nextop = next;
2675 loop->op_nextop = op;
2677 op->op_flags |= flags;
2678 op->op_private |= (flags >> 8);
2683 #ifndef CAN_PROTOTYPE
2684 newFOROP(flags,label,forline,sv,expr,block,cont)
2693 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2694 #endif /* CAN_PROTOTYPE */
2702 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2703 sv->op_type = OP_RV2GV;
2704 sv->op_ppaddr = ppaddr[OP_RV2GV];
2706 else if (sv->op_type == OP_PADSV) { /* private variable */
2707 padoff = sv->op_targ;
2712 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
2715 sv = newGVOP(OP_GV, 0, defgv);
2717 if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
2718 expr = scalar(ref(expr, OP_ITER));
2719 iterflags |= OPf_STACKED;
2721 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
2722 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2724 assert(!loop->op_next);
2725 Renew(loop, 1, LOOP);
2726 loop->op_targ = padoff;
2727 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2728 newOP(OP_ITER, 0), block, cont));
2732 newLOOPEX(type, label)
2737 if (type != OP_GOTO || label->op_type == OP_CONST) {
2738 op = newPVOP(type, 0, savepv(
2739 label->op_type == OP_CONST
2740 ? SvPVx(((SVOP*)label)->op_sv, na)
2745 if (label->op_type == OP_ENTERSUB)
2746 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2747 op = newUNOP(type, OPf_STACKED, label);
2749 hints |= HINT_BLOCK_SCOPE;
2757 if (!CvXSUB(cv) && CvROOT(cv)) {
2759 croak("Can't undef active subroutine");
2766 op_free(CvROOT(cv));
2767 CvROOT(cv) = Nullop;
2770 SvREFCNT_dec(CvGV(cv));
2772 SvREFCNT_dec(CvOUTSIDE(cv));
2773 CvOUTSIDE(cv) = Nullcv;
2774 if (CvPADLIST(cv)) {
2775 I32 i = AvFILL(CvPADLIST(cv));
2777 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2781 SvREFCNT_dec((SV*)CvPADLIST(cv));
2782 CvPADLIST(cv) = Nullav;
2786 #ifdef DEBUG_CLOSURES
2791 CV *outside = CvOUTSIDE(cv);
2792 AV* padlist = CvPADLIST(cv);
2793 AV* pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
2794 AV* pad = (AV*)*av_fetch(padlist, 1, FALSE);
2795 SV** pname = AvARRAY(pad_name);
2796 SV** ppad = AvARRAY(pad);
2799 PerlIO_printf(Perl_debug_log, "\tCV=0x%p (%s), OUTSIDE=0x%p (%s)\n",
2801 (CvANON(cv) ? "ANON"
2802 : (cv == main_cv) ? "MAIN"
2803 : CvUNIQUE(outside) ? "UNIQUE"
2804 : CvGV(cv) ? GvNAME(CvGV(cv)) : "?mystery?"),
2807 : CvANON(outside) ? "ANON"
2808 : (outside == main_cv) ? "MAIN"
2809 : CvUNIQUE(outside) ? "UNIQUE"
2810 : CvGV(outside) ? GvNAME(CvGV(outside)) : "?mystery?"));
2812 for (ix = 1; ix <= AvFILL(pad); ix++) {
2813 if (SvPOK(pname[ix]))
2814 PerlIO_printf(Perl_debug_log, "\t%4d. 0x%p (\"%s\" %ld-%ld)\n",
2815 ix, ppad[ix], SvPVX(pname[ix]),
2816 (long)I_32(SvNVX(pname[ix])),
2817 (long)SvIVX(pname[ix]));
2820 #endif /* DEBUG_CLOSURES */
2823 cv_clone2(proto, outside)
2829 AV* protopadlist = CvPADLIST(proto);
2830 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2831 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2832 SV** pname = AvARRAY(protopad_name);
2833 SV** ppad = AvARRAY(protopad);
2837 assert(!CvUNIQUE(proto));
2844 cv = compcv = (CV*)NEWSV(1104,0);
2845 sv_upgrade((SV *)cv, SVt_PVCV);
2850 CvFILEGV(cv) = CvFILEGV(proto);
2851 CvGV(cv) = GvREFCNT_inc(CvGV(proto));
2852 CvSTASH(cv) = CvSTASH(proto);
2853 CvROOT(cv) = CvROOT(proto);
2854 CvSTART(cv) = CvSTART(proto);
2856 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
2860 comppadlist = newAV();
2861 AvREAL_off(comppadlist);
2862 av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
2863 av_store(comppadlist, 1, (SV*)comppad);
2864 CvPADLIST(cv) = comppadlist;
2865 av_fill(comppad, AvFILL(protopad));
2866 curpad = AvARRAY(comppad);
2868 av = newAV(); /* will be @_ */
2870 av_store(comppad, 0, (SV*)av);
2871 AvFLAGS(av) = AVf_REIFY;
2873 for (ix = AvFILL(protopad); ix > 0; ix--) {
2875 if (pname[ix] != &sv_undef) {
2876 char *name = SvPVX(pname[ix]); /* XXX */
2877 if (SvFLAGS(pname[ix]) & SVf_FAKE) { /* lexical from outside? */
2878 I32 off = pad_findlex(name, ix, SvIVX(pname[ix]),
2879 CvOUTSIDE(cv), cxstack_ix);
2881 curpad[ix] = SvREFCNT_inc(ppad[ix]);
2883 croak("panic: cv_clone: %s", name);
2885 else { /* our own lexical */
2887 /* anon code -- we'll come back for it */
2888 sv = SvREFCNT_inc(ppad[ix]);
2890 else if (*name == '@')
2892 else if (*name == '%')
2908 /* Now that vars are all in place, clone nested closures. */
2910 for (ix = AvFILL(protopad); ix > 0; ix--) {
2911 if (pname[ix] != &sv_undef
2912 && !(SvFLAGS(pname[ix]) & SVf_FAKE)
2913 && *SvPVX(pname[ix]) == '&'
2914 && CvCLONE(ppad[ix]))
2916 CV *kid = cv_clone2((CV*)ppad[ix], cv);
2917 SvREFCNT_dec(ppad[ix]);
2920 curpad[ix] = (SV*)kid;
2924 #ifdef DEBUG_CLOSURES
2925 PerlIO_printf(Perl_debug_log, "Cloned inside:\n");
2927 PerlIO_printf(Perl_debug_log, " from:\n");
2929 PerlIO_printf(Perl_debug_log, " to:\n");
2941 return cv_clone2(proto, CvOUTSIDE(proto));
2951 if(cv && SvPOK(cv) && !SvCUR(cv)) {
2952 for (o = CvSTART(cv); o; o = o->op_next) {
2953 OPCODE type = o->op_type;
2955 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
2957 if (type == OP_LEAVESUB || type == OP_RETURN)
2959 if (type != OP_CONST || sv)
2962 sv = ((SVOP*)o)->op_sv;
2969 newSUB(floor,op,proto,block)
2976 char *name = op ? SvPVx(cSVOP->op_sv, na) : "__ANON__";
2977 GV* gv = gv_fetchpv(name, GV_ADDMULTI, SVt_PVCV);
2984 if (cv = GvCV(gv)) {
2986 cv = 0; /* just a cached method */
2987 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
2988 SV* const_sv = cv_const_sv(cv);
2990 char *p = proto ? SvPVx(((SVOP*)proto)->op_sv, na) : Nullch;
2992 if((!proto != !SvPOK(cv)) || (p && strNE(SvPV((SV*)cv,na), p))) {
2993 warn("Prototype mismatch: (%s) vs (%s)",
2994 SvPOK(cv) ? SvPV((SV*)cv,na) : "none",
2998 if ((const_sv || dowarn) && strNE(name, "BEGIN")) {/* already defined (or promised)? */
2999 line_t oldline = curcop->cop_line;
3001 curcop->cop_line = copline;
3002 warn(const_sv ? "Constant subroutine %s redefined"
3003 : "Subroutine %s redefined",name);
3004 curcop->cop_line = oldline;
3010 if (cv) { /* must reuse cv if autoloaded */
3012 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
3013 CvOUTSIDE(compcv) = 0;
3014 CvPADLIST(cv) = CvPADLIST(compcv);
3015 CvPADLIST(compcv) = 0;
3016 if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
3017 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
3018 SvREFCNT_dec(compcv);
3025 CvFILEGV(cv) = curcop->cop_filegv;
3026 CvGV(cv) = GvREFCNT_inc(gv);
3027 CvSTASH(cv) = curstash;
3030 char *p = SvPVx(((SVOP*)proto)->op_sv, na);
3031 sv_setpv((SV*)cv, p);
3047 av = newAV(); /* Will be @_ */
3049 av_store(comppad, 0, (SV*)av);
3050 AvFLAGS(av) = AVf_REIFY;
3052 for (ix = AvFILL(comppad); ix > 0; ix--) {
3053 if (!SvPADMY(curpad[ix]))
3054 SvPADTMP_on(curpad[ix]);
3057 if (AvFILL(comppad_name) < AvFILL(comppad))
3058 av_store(comppad_name, AvFILL(comppad), Nullsv);
3060 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
3061 CvSTART(cv) = LINKLIST(CvROOT(cv));
3062 CvROOT(cv)->op_next = 0;
3064 if (s = strrchr(name,':'))
3068 if (strEQ(s, "BEGIN") && !error_count) {
3069 line_t oldline = compiling.cop_line;
3073 SAVESPTR(compiling.cop_filegv);
3077 av_push(beginav, (SV *)cv);
3078 DEBUG_x( dump_sub(gv) );
3079 rs = SvREFCNT_inc(nrs);
3082 if (GvCV(gv) == cv) { /* Detach it. */
3084 GvCV(gv) = 0; /* Was above calllist, why? IZ */
3088 curcop = &compiling;
3089 curcop->cop_line = oldline; /* might have recursed to yylex */
3092 else if (strEQ(s, "END") && !error_count) {
3095 av_unshift(endav, 1);
3096 av_store(endav, 0, SvREFCNT_inc(cv));
3098 if (perldb && curstash != debstash) {
3100 SV *tmpstr = sv_newmortal();
3101 static GV *db_postponed;
3105 sprintf(buf,"%s:%ld",SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
3106 sv = newSVpv(buf,0);
3108 sprintf(buf,"%ld",(long)curcop->cop_line);
3110 gv_efullname3(tmpstr, gv, Nullch);
3111 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
3112 if (!db_postponed) {
3113 db_postponed = gv_fetchpv("DB::postponed", TRUE, SVt_PVHV);
3115 hv = GvHVn(db_postponed);
3116 if (HvFILL(hv) >= 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
3117 && (cv = GvCV(db_postponed))) {
3122 perl_call_sv((SV*)cv, G_DISCARD);
3129 GvCV(gv) = 0; /* Will remember in SVOP instead. */
3137 newXSUB(name, ix, subaddr, filename)
3143 CV* cv = newXS(name, (void(*)())subaddr, filename);
3145 CvXSUBANY(cv).any_i32 = ix;
3151 newXS(name, subaddr, filename)
3153 void (*subaddr) _((CV*));
3157 GV *gv = gv_fetchpv((name ? name : "__ANON__"), GV_ADDMULTI, SVt_PVCV);
3162 if (cv = GvCV(gv)) {
3164 cv = 0; /* just a cached method */
3165 else if (CvROOT(cv) || CvXSUB(cv)) { /* already defined? */
3167 line_t oldline = curcop->cop_line;
3169 curcop->cop_line = copline;
3170 warn("Subroutine %s redefined",name);
3171 curcop->cop_line = oldline;
3177 if (cv) { /* must reuse cv if autoloaded */
3178 assert(SvREFCNT(CvGV(cv)) > 1);
3179 SvREFCNT_dec(CvGV(cv));
3182 cv = (CV*)NEWSV(1105,0);
3183 sv_upgrade((SV *)cv, SVt_PVCV);
3186 CvGV(cv) = GvREFCNT_inc(gv);
3188 CvFILEGV(cv) = gv_fetchfile(filename);
3189 CvXSUB(cv) = subaddr;
3192 else if (s = strrchr(name,':'))
3196 if (strEQ(s, "BEGIN")) {
3199 av_push(beginav, SvREFCNT_inc(gv));
3201 else if (strEQ(s, "END")) {
3204 av_unshift(endav, 1);
3205 av_store(endav, 0, SvREFCNT_inc(gv));
3208 GvCV(gv) = 0; /* Will remember elsewhere instead. */
3215 newFORM(floor,op,block)
3226 name = SvPVx(cSVOP->op_sv, na);
3229 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3231 if (cv = GvFORM(gv)) {
3233 line_t oldline = curcop->cop_line;
3235 curcop->cop_line = copline;
3236 warn("Format %s redefined",name);
3237 curcop->cop_line = oldline;
3243 CvGV(cv) = GvREFCNT_inc(gv);
3244 CvFILEGV(cv) = curcop->cop_filegv;
3246 for (ix = AvFILL(comppad); ix > 0; ix--) {
3247 if (!SvPADMY(curpad[ix]))
3248 SvPADTMP_on(curpad[ix]);
3251 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3252 CvSTART(cv) = LINKLIST(CvROOT(cv));
3253 CvROOT(cv)->op_next = 0;
3265 return newUNOP(OP_REFGEN, 0,
3266 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3273 return newUNOP(OP_REFGEN, 0,
3274 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3278 newANONSUB(floor, proto, block)
3283 return newUNOP(OP_REFGEN, 0,
3284 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3291 switch (o->op_type) {
3293 o->op_type = OP_PADAV;
3294 o->op_ppaddr = ppaddr[OP_PADAV];
3295 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3298 o->op_type = OP_RV2AV;
3299 o->op_ppaddr = ppaddr[OP_RV2AV];
3304 warn("oops: oopsAV");
3314 switch (o->op_type) {
3317 o->op_type = OP_PADHV;
3318 o->op_ppaddr = ppaddr[OP_PADHV];
3319 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3323 o->op_type = OP_RV2HV;
3324 o->op_ppaddr = ppaddr[OP_RV2HV];
3329 warn("oops: oopsHV");
3339 if (o->op_type == OP_PADANY) {
3340 o->op_type = OP_PADAV;
3341 o->op_ppaddr = ppaddr[OP_PADAV];
3344 return newUNOP(OP_RV2AV, 0, scalar(o));
3352 if (type == OP_MAPSTART)
3353 return newUNOP(OP_NULL, 0, o);
3354 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3361 if (o->op_type == OP_PADANY) {
3362 o->op_type = OP_PADHV;
3363 o->op_ppaddr = ppaddr[OP_PADHV];
3366 return newUNOP(OP_RV2HV, 0, scalar(o));
3373 croak("NOT IMPL LINE %d",__LINE__);
3383 return newUNOP(OP_RV2CV, flags, scalar(o));
3390 if (o->op_type == OP_PADANY) {
3391 o->op_type = OP_PADSV;
3392 o->op_ppaddr = ppaddr[OP_PADSV];
3395 return newUNOP(OP_RV2SV, 0, scalar(o));
3398 /* Check routines. */
3407 name = NEWSV(1106,0);
3408 sv_upgrade(name, SVt_PVNV);
3409 sv_setpvn(name, "&", 1);
3412 ix = pad_alloc(op->op_type, SVs_PADMY);
3413 av_store(comppad_name, ix, name);
3414 av_store(comppad, ix, cSVOP->op_sv);
3415 SvPADMY_on(cSVOP->op_sv);
3416 cSVOP->op_sv = Nullsv;
3417 cSVOP->op_targ = ix;
3425 op->op_private = hints;
3433 if (cUNOP->op_first->op_type == OP_CONCAT)
3434 op->op_flags |= OPf_STACKED;
3442 if (op->op_flags & OPf_KIDS) {
3445 op = modkids(ck_fun(op), op->op_type);
3446 kid = cUNOP->op_first;
3447 newop = kUNOP->op_first->op_sibling;
3449 (newop->op_sibling ||
3450 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3451 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3452 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3456 op_free(kUNOP->op_first);
3457 kUNOP->op_first = newop;
3459 op->op_ppaddr = ppaddr[++op->op_type];
3469 if (op->op_flags & OPf_KIDS) {
3470 OP *kid = cUNOP->op_first;
3471 if (kid->op_type == OP_HSLICE)
3472 op->op_private |= OPpSLICE;
3473 else if (kid->op_type != OP_HELEM)
3474 croak("%s argument is not a HASH element or slice",
3475 op_desc[op->op_type]);
3485 I32 type = op->op_type;
3487 if (op->op_flags & OPf_KIDS) {
3488 if (cLISTOP->op_first->op_type == OP_STUB) {
3490 op = newUNOP(type, OPf_SPECIAL,
3491 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3502 hints |= HINT_BLOCK_SCOPE;
3503 if (op->op_flags & OPf_KIDS) {
3504 SVOP *kid = (SVOP*)cUNOP->op_first;
3507 op->op_flags &= ~OPf_KIDS;
3510 else if (kid->op_type == OP_LINESEQ) {
3513 kid->op_next = op->op_next;
3514 cUNOP->op_first = 0;
3517 Newz(1101, enter, 1, LOGOP);
3518 enter->op_type = OP_ENTERTRY;
3519 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3520 enter->op_private = 0;
3522 /* establish postfix order */
3523 enter->op_next = (OP*)enter;
3525 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3526 op->op_type = OP_LEAVETRY;
3527 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3528 enter->op_other = op;
3534 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3536 op->op_targ = (PADOFFSET)hints;
3545 if (op->op_flags & OPf_STACKED) {
3547 kid = cUNOP->op_first->op_sibling;
3548 if (kid->op_type == OP_RV2GV)
3561 if (op->op_flags & OPf_KIDS) {
3562 OP *kid = cUNOP->op_first;
3563 if (kid->op_type != OP_HELEM)
3564 croak("%s argument is not a HASH element", op_desc[op->op_type]);
3574 o = fold_constants(o);
3575 if (o->op_type == OP_CONST)
3584 SVOP *kid = (SVOP*)cUNOP->op_first;
3586 op->op_private |= (hints & HINT_STRICT_REFS);
3587 if (kid->op_type == OP_CONST) {
3588 int iscv = (op->op_type==OP_RV2CV)*2;
3590 kid->op_type = OP_GV;
3591 for (gv = 0; !gv; iscv++) {
3593 * This is a little tricky. We only want to add the symbol if we
3594 * didn't add it in the lexer. Otherwise we get duplicate strict
3595 * warnings. But if we didn't add it in the lexer, we must at
3596 * least pretend like we wanted to add it even if it existed before,
3597 * or we get possible typo warnings. OPpCONST_ENTERED says
3598 * whether the lexer already added THIS instance of this symbol.
3600 gv = gv_fetchpv(SvPVx(kid->op_sv, na),
3601 iscv | !(kid->op_private & OPpCONST_ENTERED),
3604 : op->op_type == OP_RV2SV
3606 : op->op_type == OP_RV2AV
3608 : op->op_type == OP_RV2HV
3612 SvREFCNT_dec(kid->op_sv);
3613 kid->op_sv = SvREFCNT_inc(gv);
3622 I32 type = op->op_type;
3624 if (op->op_flags & OPf_REF)
3627 if (op->op_flags & OPf_KIDS) {
3628 SVOP *kid = (SVOP*)cUNOP->op_first;
3630 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3631 OP *newop = newGVOP(type, OPf_REF,
3632 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3639 if (type == OP_FTTTY)
3640 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3643 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3656 int type = op->op_type;
3657 register I32 oa = opargs[type] >> OASHIFT;
3659 if (op->op_flags & OPf_STACKED) {
3660 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3663 return no_fh_allowed(op);
3666 if (op->op_flags & OPf_KIDS) {
3667 tokid = &cLISTOP->op_first;
3668 kid = cLISTOP->op_first;
3669 if (kid->op_type == OP_PUSHMARK ||
3670 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3672 tokid = &kid->op_sibling;
3673 kid = kid->op_sibling;
3675 if (!kid && opargs[type] & OA_DEFGV)
3676 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3680 sibl = kid->op_sibling;
3694 if (kid->op_type == OP_CONST &&
3695 (kid->op_private & OPpCONST_BARE)) {
3696 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3697 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3698 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3700 warn("Array @%s missing the @ in argument %d of %s()",
3701 name, numargs, op_desc[type]);
3704 kid->op_sibling = sibl;
3707 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3708 bad_type(numargs, "array", op_desc[op->op_type], kid);
3712 if (kid->op_type == OP_CONST &&
3713 (kid->op_private & OPpCONST_BARE)) {
3714 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3715 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3716 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3718 warn("Hash %%%s missing the %% in argument %d of %s()",
3719 name, numargs, op_desc[type]);
3722 kid->op_sibling = sibl;
3725 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3726 bad_type(numargs, "hash", op_desc[op->op_type], kid);
3731 OP *newop = newUNOP(OP_NULL, 0, kid);
3732 kid->op_sibling = 0;
3734 newop->op_next = newop;
3736 kid->op_sibling = sibl;
3741 if (kid->op_type != OP_GV) {
3742 if (kid->op_type == OP_CONST &&
3743 (kid->op_private & OPpCONST_BARE)) {
3744 OP *newop = newGVOP(OP_GV, 0,
3745 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3751 kid->op_sibling = 0;
3752 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3754 kid->op_sibling = sibl;
3760 mod(scalar(kid), type);
3764 tokid = &kid->op_sibling;
3765 kid = kid->op_sibling;
3767 op->op_private |= numargs;
3769 return too_many_arguments(op,op_desc[op->op_type]);
3772 else if (opargs[type] & OA_DEFGV) {
3774 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3778 while (oa & OA_OPTIONAL)
3780 if (oa && oa != OA_LIST)
3781 return too_few_arguments(op,op_desc[op->op_type]);
3790 GV *gv = gv_fetchpv("glob", FALSE, SVt_PVCV);
3792 if (gv && GvIMPORTED_CV(gv)) {
3793 op->op_type = OP_LIST;
3794 op->op_ppaddr = ppaddr[OP_LIST];
3795 op = newUNOP(OP_ENTERSUB, OPf_STACKED,
3796 append_elem(OP_LIST, op,
3797 scalar(newUNOP(OP_RV2CV, 0,
3798 newGVOP(OP_GV, 0, gv)))));
3801 gv = newGVgen("main");
3803 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3814 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3816 op->op_ppaddr = ppaddr[OP_GREPSTART];
3817 Newz(1101, gwop, 1, LOGOP);
3819 if (op->op_flags & OPf_STACKED) {
3822 kid = cLISTOP->op_first->op_sibling;
3823 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3826 kid->op_next = (OP*)gwop;
3827 op->op_flags &= ~OPf_STACKED;
3829 kid = cLISTOP->op_first->op_sibling;
3830 if (type == OP_MAPWHILE)
3837 kid = cLISTOP->op_first->op_sibling;
3838 if (kid->op_type != OP_NULL)
3839 croak("panic: ck_grep");
3840 kid = kUNOP->op_first;
3842 gwop->op_type = type;
3843 gwop->op_ppaddr = ppaddr[type];
3844 gwop->op_first = listkids(op);
3845 gwop->op_flags |= OPf_KIDS;
3846 gwop->op_private = 1;
3847 gwop->op_other = LINKLIST(kid);
3848 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3849 kid->op_next = (OP*)gwop;
3851 kid = cLISTOP->op_first->op_sibling;
3852 if (!kid || !kid->op_sibling)
3853 return too_few_arguments(op,op_desc[op->op_type]);
3854 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
3855 mod(kid, OP_GREPSTART);
3864 if (op->op_flags & OPf_KIDS) {
3865 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3866 if (kid && kid->op_type == OP_CONST)
3867 fbm_compile(((SVOP*)kid)->op_sv);
3876 /* XXX length optimization goes here */
3884 return modkids(ck_fun(op), op->op_type);
3891 return refkids(ck_fun(op), op->op_type);
3900 kid = cLISTOP->op_first;
3902 op = force_list(op);
3903 kid = cLISTOP->op_first;
3905 if (kid->op_type == OP_PUSHMARK)
3906 kid = kid->op_sibling;
3907 if (kid && op->op_flags & OPf_STACKED)
3908 kid = kid->op_sibling;
3909 else if (kid && !kid->op_sibling) { /* print HANDLE; */
3910 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
3911 op->op_flags |= OPf_STACKED; /* make it a filehandle */
3912 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
3913 cLISTOP->op_first->op_sibling = kid;
3914 cLISTOP->op_last = kid;
3915 kid = kid->op_sibling;
3920 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3926 if (hints & HINT_LOCALE)
3927 op->op_private |= OPpLOCALE;
3941 if (hints & HINT_LOCALE)
3942 op->op_private |= OPpLOCALE;
3954 if (hints & HINT_LOCALE)
3955 op->op_private |= OPpLOCALE;
3965 cPMOP->op_pmflags |= PMf_RUNTIME;
3966 cPMOP->op_pmpermflags |= PMf_RUNTIME;
3981 if (cBINOP->op_first->op_flags & OPf_PARENS) {
3982 op->op_private |= OPpREPEAT_DOLIST;
3983 cBINOP->op_first = force_list(cBINOP->op_first);
3994 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
3995 SVOP *kid = (SVOP*)cUNOP->op_first;
3997 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3999 for (s = SvPVX(kid->op_sv); *s; s++) {
4000 if (*s == ':' && s[1] == ':') {
4002 Move(s+2, s+1, strlen(s+2)+1, char);
4003 --SvCUR(kid->op_sv);
4006 sv_catpvn(kid->op_sv, ".pm", 3);
4016 croak("NOT IMPL LINE %d",__LINE__);
4026 if (op->op_flags & OPf_KIDS) {
4027 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4028 if (kid && kid->op_sibling) {
4029 op->op_type = OP_SSELECT;
4030 op->op_ppaddr = ppaddr[OP_SSELECT];
4032 return fold_constants(op);
4036 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4037 if (kid && kid->op_type == OP_RV2GV)
4038 kid->op_private &= ~HINT_STRICT_REFS;
4046 I32 type = op->op_type;
4048 if (!(op->op_flags & OPf_KIDS)) {
4050 return newUNOP(type, 0,
4051 scalar(newUNOP(OP_RV2AV, 0,
4052 scalar(newGVOP(OP_GV, 0, subline
4054 : gv_fetchpv("ARGV", TRUE, SVt_PVAV) )))));
4056 return scalar(modkids(ck_fun(op), type));
4065 if (hints & HINT_LOCALE)
4066 op->op_private |= OPpLOCALE;
4069 if (op->op_flags & OPf_STACKED) {
4070 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4072 kid = kUNOP->op_first; /* get past rv2gv */
4074 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
4076 if (kid->op_type == OP_SCOPE) {
4080 else if (kid->op_type == OP_LEAVE) {
4081 if (op->op_type == OP_SORT) {
4082 null(kid); /* wipe out leave */
4085 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
4086 if (k->op_next == kid)
4091 kid->op_next = 0; /* just disconnect the leave */
4092 k = kLISTOP->op_first;
4096 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
4097 null(kid); /* wipe out rv2gv */
4098 if (op->op_type == OP_SORT)
4102 op->op_flags |= OPf_SPECIAL;
4116 if (op->op_flags & OPf_STACKED)
4117 return no_fh_allowed(op);
4119 kid = cLISTOP->op_first;
4120 if (kid->op_type != OP_NULL)
4121 croak("panic: ck_split");
4122 kid = kid->op_sibling;
4123 op_free(cLISTOP->op_first);
4124 cLISTOP->op_first = kid;
4126 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
4127 cLISTOP->op_last = kid; /* There was only one element previously */
4130 if (kid->op_type != OP_MATCH) {
4131 OP *sibl = kid->op_sibling;
4132 kid->op_sibling = 0;
4133 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
4134 if (cLISTOP->op_first == cLISTOP->op_last)
4135 cLISTOP->op_last = kid;
4136 cLISTOP->op_first = kid;
4137 kid->op_sibling = sibl;
4140 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
4141 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
4145 kid->op_type = OP_PUSHRE;
4146 kid->op_ppaddr = ppaddr[OP_PUSHRE];
4149 if (!kid->op_sibling)
4150 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4152 kid = kid->op_sibling;
4155 if (!kid->op_sibling)
4156 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
4158 kid = kid->op_sibling;
4161 if (kid->op_sibling)
4162 return too_many_arguments(op,op_desc[op->op_type]);
4171 OP *prev = ((cUNOP->op_first->op_sibling)
4172 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first;
4173 OP *o = prev->op_sibling;
4180 for (cvop = o; cvop->op_sibling; cvop = cvop->op_sibling) ;
4181 if (cvop->op_type == OP_RV2CV) {
4183 op->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
4184 null(cvop); /* disable rv2cv */
4185 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
4186 if (tmpop->op_type == OP_GV) {
4187 cv = GvCV(tmpop->op_sv);
4188 if (cv && SvPOK(cv) && !(op->op_private & OPpENTERSUB_AMPER))
4189 proto = SvPV((SV*)cv,na);
4192 op->op_private |= (hints & HINT_STRICT_REFS);
4193 if (perldb && curstash != debstash)
4194 op->op_private |= OPpENTERSUB_DB;
4199 return too_many_arguments(op, CvNAME(cv));
4217 if (o->op_type != OP_REFGEN && o->op_type != OP_UNDEF)
4218 bad_type(arg, "block", CvNAME(cv), o);
4223 if (o->op_type == OP_RV2GV)
4227 o = newUNOP(OP_RV2GV, 0, kid);
4228 o->op_sibling = kid->op_sibling;
4229 kid->op_sibling = 0;
4230 prev->op_sibling = o;
4238 if (o->op_type != OP_RV2GV)
4239 bad_type(arg, "symbol", CvNAME(cv), o);
4242 if (o->op_type != OP_RV2CV)
4243 bad_type(arg, "sub", CvNAME(cv), o);
4246 if (o->op_type != OP_RV2SV && o->op_type != OP_PADSV)
4247 bad_type(arg, "scalar", CvNAME(cv), o);
4250 if (o->op_type != OP_RV2AV && o->op_type != OP_PADAV)
4251 bad_type(arg, "array", CvNAME(cv), o);
4254 if (o->op_type != OP_RV2HV && o->op_type != OP_PADHV)
4255 bad_type(arg, "hash", CvNAME(cv), o);
4259 o = newUNOP(OP_REFGEN, 0, kid);
4260 o->op_sibling = kid->op_sibling;
4261 kid->op_sibling = 0;
4262 prev->op_sibling = o;
4273 croak("Malformed prototype for %s: %s",
4274 CvNAME(cv),SvPV((SV*)cv,na));
4279 mod(o, OP_ENTERSUB);
4283 if (proto && !optional && *proto == '$')
4284 return too_few_arguments(op, CvNAME(cv));
4292 SvREADONLY_on(cSVOP->op_sv);
4300 if (op->op_flags & OPf_KIDS) {
4301 SVOP *kid = (SVOP*)cUNOP->op_first;
4303 if (kid->op_type == OP_NULL)
4304 kid = (SVOP*)kid->op_sibling;
4306 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
4307 op->op_flags |= OPf_SPECIAL;
4312 /* A peephole optimizer. We visit the ops in the order they're to execute. */
4318 register OP* oldop = 0;
4319 if (!o || o->op_seq)
4324 for (; o; o = o->op_next) {
4330 switch (o->op_type) {
4333 curcop = ((COP*)o); /* for warnings */
4334 o->op_seq = op_seqmax++;
4345 if (o->op_next->op_type == OP_STRINGIFY)
4347 o->op_seq = op_seqmax++;
4350 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
4351 o->op_seq = op_seqmax++;
4352 break; /* Scalar stub must produce undef. List stub is noop */
4356 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4357 curcop = ((COP*)op);
4363 if (oldop && o->op_next) {
4364 oldop->op_next = o->op_next;
4367 o->op_seq = op_seqmax++;
4371 if (o->op_next->op_type == OP_RV2SV) {
4372 if (!(o->op_next->op_private & OPpDEREF)) {
4374 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4375 o->op_next = o->op_next->op_next;
4376 o->op_type = OP_GVSV;
4377 o->op_ppaddr = ppaddr[OP_GVSV];
4380 else if (o->op_next->op_type == OP_RV2AV) {
4381 OP* pop = o->op_next->op_next;
4383 if (pop->op_type == OP_CONST &&
4384 (op = pop->op_next) &&
4385 pop->op_next->op_type == OP_AELEM &&
4386 !(pop->op_next->op_private & (OPpDEREF|OPpLVAL_INTRO)) &&
4387 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4391 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4395 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4396 o->op_next = pop->op_next->op_next;
4397 o->op_type = OP_AELEMFAST;
4398 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4399 o->op_private = (U8)i;
4400 GvAVn((GV*)(((SVOP*)o)->op_sv));
4403 o->op_seq = op_seqmax++;
4410 o->op_seq = op_seqmax++;
4411 peep(cLOGOP->op_other);
4415 o->op_seq = op_seqmax++;
4416 peep(cCONDOP->op_true);
4417 peep(cCONDOP->op_false);
4421 o->op_seq = op_seqmax++;
4422 peep(cLOOP->op_redoop);
4423 peep(cLOOP->op_nextop);
4424 peep(cLOOP->op_lastop);
4429 o->op_seq = op_seqmax++;
4430 peep(cPMOP->op_pmreplstart);
4434 o->op_seq = op_seqmax++;
4435 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
4436 if (o->op_next->op_sibling &&
4437 o->op_next->op_sibling->op_type != OP_DIE) {
4438 line_t oldline = curcop->cop_line;
4440 curcop->cop_line = ((COP*)o->op_next)->cop_line;
4441 warn("Statement unlikely to be reached");
4442 warn("(Maybe you meant system() when you said exec()?)\n");
4443 curcop->cop_line = oldline;
4448 o->op_seq = op_seqmax++;