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 > (I32)SvNVX(sv) &&
190 strEQ(SvPVX(sv), name))
192 I32 depth = CvDEPTH(cv) ? CvDEPTH(cv) : 1;
193 AV *oldpad = (AV*)*av_fetch(curlist, depth, FALSE);
194 SV *oldsv = *av_fetch(oldpad, off, TRUE);
195 if (!newoff) { /* Not a mere clone operation. */
196 SV *sv = NEWSV(1103,0);
197 newoff = pad_alloc(OP_PADSV, SVs_PADMY);
198 sv_upgrade(sv, SVt_PVNV);
200 av_store(comppad_name, newoff, sv);
201 SvNVX(sv) = (double)curcop->cop_seq;
202 SvIVX(sv) = 999999999; /* A ref, intro immediately */
203 SvFLAGS(sv) |= SVf_FAKE;
205 av_store(comppad, newoff, SvREFCNT_inc(oldsv));
212 /* Nothing in current lexical context--try eval's context, if any.
213 * This is necessary to let the perldb get at lexically scoped variables.
214 * XXX This will also probably interact badly with eval tree caching.
218 for (i = cx_ix; i >= 0; i--) {
220 switch (cx->cx_type) {
222 if (i == 0 && saweval) {
223 seq = cxstack[saweval].blk_oldcop->cop_seq;
224 return pad_findlex(name, newoff, seq, main_cv, 0);
228 if (cx->blk_eval.old_op_type != OP_ENTEREVAL &&
229 cx->blk_eval.old_op_type != OP_ENTERTRY)
230 return 0; /* require must have its own scope */
237 if (debstash && CvSTASH(cv) == debstash) { /* ignore DB'* scope */
238 saweval = i; /* so we know where we were called from */
241 seq = cxstack[saweval].blk_oldcop->cop_seq;
242 return pad_findlex(name, newoff, seq, cv, i-1);
255 SV **svp = AvARRAY(comppad_name);
256 U32 seq = cop_seqmax;
258 /* The one we're looking for is probably just before comppad_name_fill. */
259 for (off = AvFILL(comppad_name); off > 0; off--) {
260 if ((sv = svp[off]) &&
263 seq > (I32)SvNVX(sv) &&
264 strEQ(SvPVX(sv), name))
266 return (PADOFFSET)off;
270 /* See if it's in a nested scope */
271 off = pad_findlex(name, 0, seq, CvOUTSIDE(compcv), cxstack_ix);
283 SV **svp = AvARRAY(comppad_name);
285 if (min_intro_pending && fill < min_intro_pending) {
286 for (off = max_intro_pending; off >= min_intro_pending; off--) {
287 if ((sv = svp[off]) && sv != &sv_undef)
288 warn("%s never introduced", SvPVX(sv));
291 /* "Deintroduce" my variables that are leaving with this scope. */
292 for (off = AvFILL(comppad_name); off > fill; off--) {
293 if ((sv = svp[off]) && sv != &sv_undef && SvIVX(sv) == 999999999)
294 SvIVX(sv) = cop_seqmax;
299 pad_alloc(optype,tmptype)
306 if (AvARRAY(comppad) != curpad)
307 croak("panic: pad_alloc");
308 if (pad_reset_pending)
310 if (tmptype & SVs_PADMY) {
312 sv = *av_fetch(comppad, AvFILL(comppad) + 1, TRUE);
313 } while (SvPADBUSY(sv)); /* need a fresh one */
314 retval = AvFILL(comppad);
317 SV **names = AvARRAY(comppad_name);
318 SSize_t names_fill = AvFILL(comppad_name);
321 * "foreach" index vars temporarily become aliases to non-"my"
322 * values. Thus we must skip, not just pad values that are
323 * marked as current pad values, but also those with names.
325 if (++padix <= names_fill &&
326 (sv = names[padix]) && sv != &sv_undef)
328 sv = *av_fetch(comppad, padix, TRUE);
329 if (!(SvFLAGS(sv) & (SVs_PADTMP|SVs_PADMY)))
334 SvFLAGS(sv) |= tmptype;
335 curpad = AvARRAY(comppad);
336 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad alloc %ld for %s\n", (long) retval, op_name[optype]));
337 return (PADOFFSET)retval;
341 #ifndef CAN_PROTOTYPE
346 #endif /* CAN_PROTOTYPE */
349 croak("panic: pad_sv po");
350 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad sv %d\n", po));
351 return curpad[po]; /* eventually we'll turn this into a macro */
355 #ifndef CAN_PROTOTYPE
359 pad_free(PADOFFSET po)
360 #endif /* CAN_PROTOTYPE */
364 if (AvARRAY(comppad) != curpad)
365 croak("panic: pad_free curpad");
367 croak("panic: pad_free po");
368 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad free %d\n", po));
369 if (curpad[po] && curpad[po] != &sv_undef)
370 SvPADTMP_off(curpad[po]);
376 #ifndef CAN_PROTOTYPE
380 pad_swipe(PADOFFSET po)
381 #endif /* CAN_PROTOTYPE */
383 if (AvARRAY(comppad) != curpad)
384 croak("panic: pad_swipe curpad");
386 croak("panic: pad_swipe po");
387 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad swipe %d\n", po));
388 SvPADTMP_off(curpad[po]);
389 curpad[po] = NEWSV(1107,0);
390 SvPADTMP_on(curpad[po]);
400 if (AvARRAY(comppad) != curpad)
401 croak("panic: pad_reset curpad");
402 DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad reset\n"));
403 if (!tainting) { /* Can't mix tainted and non-tainted temporaries. */
404 for (po = AvMAX(comppad); po > padix_floor; po--) {
405 if (curpad[po] && curpad[po] != &sv_undef)
406 SvPADTMP_off(curpad[po]);
410 pad_reset_pending = FALSE;
419 register OP *kid, *nextkid;
421 if (!op || op->op_seq == (U16)-1)
424 if (op->op_flags & OPf_KIDS) {
425 for (kid = cUNOP->op_first; kid; kid = nextkid) {
426 nextkid = kid->op_sibling; /* Get before next freeing kid */
431 switch (op->op_type) {
433 op->op_targ = 0; /* Was holding old type, if any. */
436 op->op_targ = 0; /* Was holding hints. */
440 SvREFCNT_dec(cGVOP->op_gv);
444 SvREFCNT_dec(cCOP->cop_filegv);
446 /* case OP_ANONCODE: XXX breaks eval of anon subs in closures (cf. Opcode) */
448 SvREFCNT_dec(cSVOP->op_sv);
454 if (op->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
458 Safefree(cPVOP->op_pv);
461 op_free(cPMOP->op_pmreplroot);
465 pregfree(cPMOP->op_pmregexp);
466 SvREFCNT_dec(cPMOP->op_pmshort);
473 pad_free(op->op_targ);
482 if (op->op_type != OP_NULL && op->op_targ > 0)
483 pad_free(op->op_targ);
484 op->op_targ = op->op_type;
485 op->op_type = OP_NULL;
486 op->op_ppaddr = ppaddr[OP_NULL];
489 /* Contextualizers */
491 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
502 /* establish postfix order */
503 if (cUNOP->op_first) {
504 op->op_next = LINKLIST(cUNOP->op_first);
505 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling) {
507 kid->op_next = LINKLIST(kid->op_sibling);
523 if (op && op->op_flags & OPf_KIDS) {
524 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
535 op->op_type == OP_SASSIGN && cBINOP->op_first->op_type == OP_CONST) {
536 line_t oldline = curcop->cop_line;
538 if (copline != NOLINE)
539 curcop->cop_line = copline;
540 warn("Found = in conditional, should be ==");
541 curcop->cop_line = oldline;
552 /* assumes no premature commitment */
553 if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
557 op->op_flags &= ~OPf_LIST;
558 op->op_flags |= OPf_KNOW;
560 switch (op->op_type) {
562 if (op->op_private & OPpREPEAT_DOLIST)
563 null(((LISTOP*)cBINOP->op_first)->op_first);
564 scalar(cBINOP->op_first);
569 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
573 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
574 if (!kPMOP->op_pmreplroot)
575 deprecate("implicit split to @_");
582 if (op->op_flags & OPf_KIDS) {
583 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
589 scalar(cLISTOP->op_first);
594 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
614 if (!op || error_count)
616 if (op->op_flags & OPf_LIST)
619 op->op_flags |= OPf_KNOW;
621 switch (op->op_type) {
623 if (!(opargs[op->op_type] & OA_FOLDCONST))
627 if (op->op_flags & OPf_STACKED)
700 if (!(op->op_private & OPpLVAL_INTRO))
701 useless = op_desc[op->op_type];
708 if (!(op->op_private & OPpLVAL_INTRO) &&
709 (!op->op_sibling || op->op_sibling->op_type != OP_READLINE))
710 useless = "a variable";
715 curcop = ((COP*)op); /* for warning below */
721 useless = "a constant";
722 if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
724 else if (SvPOK(sv)) {
725 if (strnEQ(SvPVX(sv), "di", 2) ||
726 strnEQ(SvPVX(sv), "ds", 2) ||
727 strnEQ(SvPVX(sv), "ig", 2))
731 null(op); /* don't execute a constant */
732 SvREFCNT_dec(sv); /* don't even remember it */
736 op->op_type = OP_PREINC; /* pre-increment is faster */
737 op->op_ppaddr = ppaddr[OP_PREINC];
741 op->op_type = OP_PREDEC; /* pre-decrement is faster */
742 op->op_ppaddr = ppaddr[OP_PREDEC];
748 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
752 if (op->op_targ == OP_NEXTSTATE || op->op_targ == OP_DBSTATE)
753 curcop = ((COP*)op); /* for warning below */
754 if (op->op_flags & OPf_STACKED)
759 if (!(op->op_flags & OPf_KIDS))
765 op->op_private |= OPpLEAVE_VOID;
768 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
772 if ((kid = ((LISTOP*)op)->op_first) && kid->op_type == OP_PUSHRE) {
773 if (!kPMOP->op_pmreplroot)
774 deprecate("implicit split to @_");
778 op->op_private |= OPpLEAVE_VOID;
781 if (useless && dowarn)
782 warn("Useless use of %s in void context", useless);
791 if (op && op->op_flags & OPf_KIDS) {
792 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
804 /* assumes no premature commitment */
805 if (!op || (op->op_flags & OPf_KNOW) || op->op_type == OP_RETURN
809 op->op_flags |= (OPf_KNOW | OPf_LIST);
811 switch (op->op_type) {
814 list(cBINOP->op_first);
819 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
826 if (!(op->op_flags & OPf_KIDS))
828 if (!op->op_next && cUNOP->op_first->op_type == OP_FLOP) {
829 list(cBINOP->op_first);
830 return gen_constant_list(op);
837 list(cLISTOP->op_first);
841 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
860 if (op->op_type == OP_LINESEQ ||
861 op->op_type == OP_SCOPE ||
862 op->op_type == OP_LEAVE ||
863 op->op_type == OP_LEAVETRY)
865 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling) {
866 if (kid->op_sibling) {
872 op->op_flags &= ~OPf_PARENS;
873 if (hints & HINT_BLOCK_SCOPE)
874 op->op_flags |= OPf_PARENS;
877 op = newOP(OP_STUB, 0);
887 if (op && op->op_flags & OPf_KIDS) {
888 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
905 if (!op || error_count)
908 switch (op->op_type) {
910 if (!(op->op_private & (OPpCONST_ARYBASE)))
912 if (eval_start && eval_start->op_type == OP_CONST) {
913 compiling.cop_arybase = (I32)SvIV(((SVOP*)eval_start)->op_sv);
917 SAVEI32(compiling.cop_arybase);
918 compiling.cop_arybase = 0;
920 else if (type == OP_REFGEN)
923 croak("That use of $[ is unsupported");
926 if ((type == OP_UNDEF || type == OP_REFGEN) &&
927 !(op->op_flags & OPf_STACKED)) {
928 op->op_type = OP_RV2CV; /* entersub => rv2cv */
929 op->op_ppaddr = ppaddr[OP_RV2CV];
930 assert(cUNOP->op_first->op_type == OP_NULL);
931 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
937 /* grep, foreach, subcalls, refgen */
938 if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
940 sprintf(tokenbuf, "Can't modify %s in %s",
941 op_desc[op->op_type],
942 type ? op_desc[type] : "local");
966 if (!(op->op_flags & OPf_STACKED))
972 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
978 if (type == OP_REFGEN && op->op_flags & OPf_PARENS) {
980 return op; /* Treat \(@foo) like ordinary list. */
984 ref(cUNOP->op_first, op->op_type);
996 if (!type && cUNOP->op_first->op_type != OP_GV)
997 croak("Can't localize a reference");
998 ref(cUNOP->op_first, op->op_type);
1011 if (type == OP_REFGEN && op->op_flags & OPf_PARENS)
1012 return op; /* Treat \(@foo) like ordinary list. */
1017 croak("Can't localize lexical variable %s",
1018 SvPV(*av_fetch(comppad_name, op->op_targ, 4), na));
1025 if (type != OP_SASSIGN)
1038 pad_free(op->op_targ);
1039 op->op_targ = pad_alloc(op->op_type, SVs_PADMY);
1040 sv = PAD_SV(op->op_targ);
1041 sv_upgrade(sv, SVt_PVLV);
1042 sv_magic(sv, Nullsv, mtype, Nullch, 0);
1043 curpad[op->op_targ] = sv;
1044 if (op->op_flags & OPf_KIDS)
1045 mod(cBINOP->op_first->op_sibling, type);
1050 ref(cBINOP->op_first, op->op_type);
1057 if (op->op_flags & OPf_KIDS)
1058 mod(cLISTOP->op_last, type);
1062 if (!(op->op_flags & OPf_KIDS))
1064 if (op->op_targ != OP_LIST) {
1065 mod(cBINOP->op_first, type);
1070 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1074 op->op_flags |= OPf_MOD;
1076 if (type == OP_AASSIGN || type == OP_SASSIGN)
1077 op->op_flags |= OPf_SPECIAL|OPf_REF;
1079 op->op_private |= OPpLVAL_INTRO;
1080 op->op_flags &= ~OPf_SPECIAL;
1082 else if (type != OP_GREPSTART && type != OP_ENTERSUB)
1083 op->op_flags |= OPf_REF;
1093 if (op && op->op_flags & OPf_KIDS) {
1094 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1107 if (!op || error_count)
1110 switch (op->op_type) {
1112 if ((type == OP_DEFINED) &&
1113 !(op->op_flags & OPf_STACKED)) {
1114 op->op_type = OP_RV2CV; /* entersub => rv2cv */
1115 op->op_ppaddr = ppaddr[OP_RV2CV];
1116 assert(cUNOP->op_first->op_type == OP_NULL);
1117 null(((LISTOP*)cUNOP->op_first)->op_first); /* disable pushmark */
1118 op->op_flags |= OPf_SPECIAL;
1123 for (kid = cUNOP->op_first->op_sibling; kid; kid = kid->op_sibling)
1127 ref(cUNOP->op_first, op->op_type);
1130 if (type == OP_RV2AV || type == OP_RV2HV) {
1131 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1132 op->op_flags |= OPf_MOD;
1138 op->op_flags |= OPf_REF;
1141 ref(cUNOP->op_first, op->op_type);
1146 op->op_flags |= OPf_REF;
1151 if (!(op->op_flags & OPf_KIDS))
1153 ref(cBINOP->op_first, type);
1157 ref(cBINOP->op_first, op->op_type);
1158 if (type == OP_RV2AV || type == OP_RV2HV) {
1159 op->op_private |= (type == OP_RV2AV ? OPpDEREF_AV : OPpDEREF_HV);
1160 op->op_flags |= OPf_MOD;
1168 if (!(op->op_flags & OPf_KIDS))
1170 ref(cLISTOP->op_last, type);
1186 if (!op || error_count)
1190 if (type == OP_LIST) {
1191 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1194 else if (type != OP_PADSV &&
1197 type != OP_PUSHMARK)
1199 sprintf(tokenbuf, "Can't declare %s in my", op_desc[op->op_type]);
1203 op->op_flags |= OPf_MOD;
1204 op->op_private |= OPpLVAL_INTRO;
1213 o->op_flags |= OPf_PARENS;
1218 bind_match(type, left, right)
1225 if (right->op_type == OP_MATCH ||
1226 right->op_type == OP_SUBST ||
1227 right->op_type == OP_TRANS) {
1228 right->op_flags |= OPf_STACKED;
1229 if (right->op_type != OP_MATCH)
1230 left = mod(left, right->op_type);
1231 if (right->op_type == OP_TRANS)
1232 op = newBINOP(OP_NULL, OPf_STACKED, scalar(left), right);
1234 op = prepend_elem(right->op_type, scalar(left), right);
1236 return newUNOP(OP_NOT, 0, scalar(op));
1240 return bind_match(type, left,
1241 pmruntime(newPMOP(OP_MATCH, 0), right, Nullop));
1250 /* XXX need to optimize away NOT NOT here? Or do we let optimizer do it? */
1251 return newUNOP(OP_NOT, OPf_SPECIAL, scalar(op));
1259 if (o->op_flags & OPf_PARENS || perldb || tainting) {
1260 o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o);
1261 o->op_type = OP_LEAVE;
1262 o->op_ppaddr = ppaddr[OP_LEAVE];
1265 if (o->op_type == OP_LINESEQ) {
1267 o->op_type = OP_SCOPE;
1268 o->op_ppaddr = ppaddr[OP_SCOPE];
1269 kid = ((LISTOP*)o)->op_first;
1270 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){
1271 SvREFCNT_dec(((COP*)kid)->cop_filegv);
1276 o = newLISTOP(OP_SCOPE, 0, o, Nullop);
1286 int retval = savestack_ix;
1287 SAVEI32(comppad_name_floor);
1289 if ((comppad_name_fill = AvFILL(comppad_name)) > 0)
1290 comppad_name_floor = comppad_name_fill;
1292 comppad_name_floor = 0;
1294 SAVEI32(min_intro_pending);
1295 SAVEI32(max_intro_pending);
1296 min_intro_pending = 0;
1297 SAVEI32(comppad_name_fill);
1298 SAVEI32(padix_floor);
1299 padix_floor = padix;
1300 pad_reset_pending = FALSE;
1302 hints &= ~HINT_BLOCK_SCOPE;
1307 block_end(floor, seq)
1311 int needblockscope = hints & HINT_BLOCK_SCOPE;
1312 OP* retval = scalarseq(seq);
1314 pad_reset_pending = FALSE;
1316 hints |= HINT_BLOCK_SCOPE; /* propagate out */
1317 pad_leavemy(comppad_name_fill);
1327 eval_root = newUNOP(OP_LEAVEEVAL, ((in_eval & 4) ? OPf_SPECIAL : 0), op);
1328 eval_start = linklist(eval_root);
1329 eval_root->op_next = 0;
1337 main_root = scope(sawparens(scalarvoid(op)));
1338 curcop = &compiling;
1339 main_start = LINKLIST(main_root);
1340 main_root->op_next = 0;
1352 if (o->op_flags & OPf_PARENS)
1356 if (dowarn && bufptr > oldbufptr && bufptr[-1] == ',') {
1358 for (s = bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
1359 if (*s == ';' || *s == '=')
1360 warn("Parens missing around \"%s\" list", lex ? "my" : "local");
1367 return mod(o, OP_NULL); /* a bit kludgey */
1374 if (o->op_type == OP_LIST) {
1375 o = convert(OP_JOIN, 0,
1376 prepend_elem(OP_LIST,
1377 newSVREF(newGVOP(OP_GV, 0, gv_fetchpv(";", TRUE, SVt_PV))),
1388 I32 type = o->op_type;
1391 if (opargs[type] & OA_RETSCALAR)
1393 if (opargs[type] & OA_TARGET)
1394 o->op_targ = pad_alloc(type, SVs_PADTMP);
1396 if ((opargs[type] & OA_OTHERINT) && (hints & HINT_INTEGER))
1397 o->op_ppaddr = ppaddr[type = ++(o->op_type)];
1399 if (!(opargs[type] & OA_FOLDCONST))
1403 goto nope; /* Don't try to run w/ errors */
1405 for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
1406 if (curop->op_type != OP_CONST &&
1407 curop->op_type != OP_LIST &&
1408 curop->op_type != OP_SCALAR &&
1409 curop->op_type != OP_NULL &&
1410 curop->op_type != OP_PUSHMARK) {
1415 curop = LINKLIST(o);
1420 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
1421 pad_swipe(o->op_targ);
1422 else if (SvTEMP(sv)) { /* grab mortal temp? */
1423 (void)SvREFCNT_inc(sv);
1427 if (type == OP_RV2GV)
1428 return newGVOP(OP_GV, 0, (GV*)sv);
1430 if ((SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK)) == SVf_NOK) {
1432 if ((double)iv == SvNV(sv)) { /* can we smush double to int */
1437 SvIOK_off(sv); /* undo SvIV() damage */
1439 return newSVOP(OP_CONST, 0, sv);
1443 if (!(opargs[type] & OA_OTHERINT))
1446 if (!(hints & HINT_INTEGER)) {
1447 if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS))
1450 for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
1451 if (curop->op_type == OP_CONST) {
1452 if (SvIOK(((SVOP*)curop)->op_sv))
1456 if (opargs[curop->op_type] & OA_RETINTEGER)
1460 o->op_ppaddr = ppaddr[++(o->op_type)];
1467 gen_constant_list(o)
1471 I32 oldtmps_floor = tmps_floor;
1475 return o; /* Don't attempt to run with errors */
1477 op = curop = LINKLIST(o);
1483 tmps_floor = oldtmps_floor;
1485 o->op_type = OP_RV2AV;
1486 o->op_ppaddr = ppaddr[OP_RV2AV];
1487 curop = ((UNOP*)o)->op_first;
1488 ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*stack_sp--));
1495 convert(type, flags, op)
1503 if (!op || op->op_type != OP_LIST)
1504 op = newLISTOP(OP_LIST, 0, op, Nullop);
1506 op->op_flags &= ~(OPf_KNOW|OPf_LIST);
1508 if (!(opargs[type] & OA_MARK))
1509 null(cLISTOP->op_first);
1512 op->op_ppaddr = ppaddr[type];
1513 op->op_flags |= flags;
1515 op = CHECKOP(type, op);
1516 if (op->op_type != type)
1519 if (cLISTOP->op_children < 7) {
1520 /* XXX do we really need to do this if we're done appending?? */
1521 for (kid = cLISTOP->op_first; kid; kid = kid->op_sibling)
1523 cLISTOP->op_last = last; /* in case check substituted last arg */
1526 return fold_constants(op);
1529 /* List constructors */
1532 append_elem(type, first, last)
1543 if (first->op_type != type || type==OP_LIST && first->op_flags & OPf_PARENS)
1544 return newLISTOP(type, 0, first, last);
1546 if (first->op_flags & OPf_KIDS)
1547 ((LISTOP*)first)->op_last->op_sibling = last;
1549 first->op_flags |= OPf_KIDS;
1550 ((LISTOP*)first)->op_first = last;
1552 ((LISTOP*)first)->op_last = last;
1553 ((LISTOP*)first)->op_children++;
1558 append_list(type, first, last)
1569 if (first->op_type != type)
1570 return prepend_elem(type, (OP*)first, (OP*)last);
1572 if (last->op_type != type)
1573 return append_elem(type, (OP*)first, (OP*)last);
1575 first->op_last->op_sibling = last->op_first;
1576 first->op_last = last->op_last;
1577 first->op_children += last->op_children;
1578 if (first->op_children)
1579 last->op_flags |= OPf_KIDS;
1586 prepend_elem(type, first, last)
1597 if (last->op_type == type) {
1598 if (type == OP_LIST) { /* already a PUSHMARK there */
1599 first->op_sibling = ((LISTOP*)last)->op_first->op_sibling;
1600 ((LISTOP*)last)->op_first->op_sibling = first;
1603 if (!(last->op_flags & OPf_KIDS)) {
1604 ((LISTOP*)last)->op_last = first;
1605 last->op_flags |= OPf_KIDS;
1607 first->op_sibling = ((LISTOP*)last)->op_first;
1608 ((LISTOP*)last)->op_first = first;
1610 ((LISTOP*)last)->op_children++;
1614 return newLISTOP(type, 0, first, last);
1622 return newOP(OP_STUB, 0);
1629 if (!op || op->op_type != OP_LIST)
1630 op = newLISTOP(OP_LIST, 0, op, Nullop);
1636 newLISTOP(type, flags, first, last)
1644 Newz(1101, listop, 1, LISTOP);
1646 listop->op_type = type;
1647 listop->op_ppaddr = ppaddr[type];
1648 listop->op_children = (first != 0) + (last != 0);
1649 listop->op_flags = flags;
1653 else if (!first && last)
1656 first->op_sibling = last;
1657 listop->op_first = first;
1658 listop->op_last = last;
1659 if (type == OP_LIST) {
1661 pushop = newOP(OP_PUSHMARK, 0);
1662 pushop->op_sibling = first;
1663 listop->op_first = pushop;
1664 listop->op_flags |= OPf_KIDS;
1666 listop->op_last = pushop;
1668 else if (listop->op_children)
1669 listop->op_flags |= OPf_KIDS;
1680 Newz(1101, op, 1, OP);
1682 op->op_ppaddr = ppaddr[type];
1683 op->op_flags = flags;
1686 op->op_private = 0 + (flags >> 8);
1687 if (opargs[type] & OA_RETSCALAR)
1689 if (opargs[type] & OA_TARGET)
1690 op->op_targ = pad_alloc(type, SVs_PADTMP);
1691 return CHECKOP(type, op);
1695 newUNOP(type, flags, first)
1703 first = newOP(OP_STUB, 0);
1704 if (opargs[type] & OA_MARK)
1705 first = force_list(first);
1707 Newz(1101, unop, 1, UNOP);
1708 unop->op_type = type;
1709 unop->op_ppaddr = ppaddr[type];
1710 unop->op_first = first;
1711 unop->op_flags = flags | OPf_KIDS;
1712 unop->op_private = 1 | (flags >> 8);
1714 unop = (UNOP*) CHECKOP(type, unop);
1718 return fold_constants((OP *) unop);
1722 newBINOP(type, flags, first, last)
1729 Newz(1101, binop, 1, BINOP);
1732 first = newOP(OP_NULL, 0);
1734 binop->op_type = type;
1735 binop->op_ppaddr = ppaddr[type];
1736 binop->op_first = first;
1737 binop->op_flags = flags | OPf_KIDS;
1740 binop->op_private = 1 | (flags >> 8);
1743 binop->op_private = 2 | (flags >> 8);
1744 first->op_sibling = last;
1747 binop = (BINOP*)CHECKOP(type, binop);
1751 binop->op_last = last = binop->op_first->op_sibling;
1753 return fold_constants((OP *)binop);
1757 pmtrans(op, expr, repl)
1762 SV *tstr = ((SVOP*)expr)->op_sv;
1763 SV *rstr = ((SVOP*)repl)->op_sv;
1766 register U8 *t = (U8*)SvPV(tstr, tlen);
1767 register U8 *r = (U8*)SvPV(rstr, rlen);
1772 register short *tbl;
1774 tbl = (short*)cPVOP->op_pv;
1775 complement = op->op_private & OPpTRANS_COMPLEMENT;
1776 delete = op->op_private & OPpTRANS_DELETE;
1777 /* squash = op->op_private & OPpTRANS_SQUASH; */
1780 Zero(tbl, 256, short);
1781 for (i = 0; i < tlen; i++)
1783 for (i = 0, j = 0; i < 256; i++) {
1799 if (!rlen && !delete) {
1802 for (i = 0; i < 256; i++)
1804 for (i = 0, j = 0; i < tlen; i++,j++) {
1807 if (tbl[t[i]] == -1)
1813 if (tbl[t[i]] == -1)
1824 newPMOP(type, flags)
1830 Newz(1101, pmop, 1, PMOP);
1831 pmop->op_type = type;
1832 pmop->op_ppaddr = ppaddr[type];
1833 pmop->op_flags = flags;
1834 pmop->op_private = 0 | (flags >> 8);
1836 if (hints & HINT_LOCALE)
1837 pmop->op_pmpermflags = (pmop->op_pmflags |= PMf_LOCALE);
1839 /* link into pm list */
1840 if (type != OP_TRANS && curstash) {
1841 pmop->op_pmnext = HvPMROOT(curstash);
1842 HvPMROOT(curstash) = pmop;
1849 pmruntime(op, expr, repl)
1857 if (op->op_type == OP_TRANS)
1858 return pmtrans(op, expr, repl);
1862 if (expr->op_type == OP_CONST) {
1864 SV *pat = ((SVOP*)expr)->op_sv;
1865 char *p = SvPV(pat, plen);
1866 if ((op->op_flags & OPf_SPECIAL) && strEQ(p, " ")) {
1867 sv_setpvn(pat, "\\s+", 3);
1868 p = SvPV(pat, plen);
1869 pm->op_pmflags |= PMf_SKIPWHITE;
1871 pm->op_pmregexp = pregcomp(p, p + plen, pm);
1872 if (strEQ("\\s+", pm->op_pmregexp->precomp))
1873 pm->op_pmflags |= PMf_WHITE;
1878 if (pm->op_pmflags & PMf_KEEP)
1879 expr = newUNOP(OP_REGCMAYBE,0,expr);
1881 Newz(1101, rcop, 1, LOGOP);
1882 rcop->op_type = OP_REGCOMP;
1883 rcop->op_ppaddr = ppaddr[OP_REGCOMP];
1884 rcop->op_first = scalar(expr);
1885 rcop->op_flags |= OPf_KIDS;
1886 rcop->op_private = 1;
1887 rcop->op_other = op;
1889 /* establish postfix order */
1890 if (pm->op_pmflags & PMf_KEEP) {
1892 rcop->op_next = expr;
1893 ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
1896 rcop->op_next = LINKLIST(expr);
1897 expr->op_next = (OP*)rcop;
1900 prepend_elem(op->op_type, scalar((OP*)rcop), op);
1905 if (pm->op_pmflags & PMf_EVAL)
1907 else if (repl->op_type == OP_CONST)
1911 for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) {
1912 if (opargs[curop->op_type] & OA_DANGEROUS) {
1913 if (curop->op_type == OP_GV) {
1914 GV *gv = ((GVOP*)curop)->op_gv;
1915 if (strchr("&`'123456789+", *GvENAME(gv)))
1918 else if (curop->op_type == OP_RV2CV)
1920 else if (curop->op_type == OP_RV2SV ||
1921 curop->op_type == OP_RV2AV ||
1922 curop->op_type == OP_RV2HV ||
1923 curop->op_type == OP_RV2GV) {
1924 if (lastop && lastop->op_type != OP_GV) /*funny deref?*/
1927 else if (curop->op_type == OP_PADSV ||
1928 curop->op_type == OP_PADAV ||
1929 curop->op_type == OP_PADHV ||
1930 curop->op_type == OP_PADANY) {
1939 if (curop == repl) {
1940 pm->op_pmflags |= PMf_CONST; /* const for long enough */
1941 pm->op_pmpermflags |= PMf_CONST; /* const for long enough */
1942 prepend_elem(op->op_type, scalar(repl), op);
1945 Newz(1101, rcop, 1, LOGOP);
1946 rcop->op_type = OP_SUBSTCONT;
1947 rcop->op_ppaddr = ppaddr[OP_SUBSTCONT];
1948 rcop->op_first = scalar(repl);
1949 rcop->op_flags |= OPf_KIDS;
1950 rcop->op_private = 1;
1951 rcop->op_other = op;
1953 /* establish postfix order */
1954 rcop->op_next = LINKLIST(repl);
1955 repl->op_next = (OP*)rcop;
1957 pm->op_pmreplroot = scalar((OP*)rcop);
1958 pm->op_pmreplstart = LINKLIST(rcop);
1967 newSVOP(type, flags, sv)
1973 Newz(1101, svop, 1, SVOP);
1974 svop->op_type = type;
1975 svop->op_ppaddr = ppaddr[type];
1977 svop->op_next = (OP*)svop;
1978 svop->op_flags = flags;
1979 if (opargs[type] & OA_RETSCALAR)
1981 if (opargs[type] & OA_TARGET)
1982 svop->op_targ = pad_alloc(type, SVs_PADTMP);
1983 return CHECKOP(type, svop);
1987 newGVOP(type, flags, gv)
1993 Newz(1101, gvop, 1, GVOP);
1994 gvop->op_type = type;
1995 gvop->op_ppaddr = ppaddr[type];
1996 gvop->op_gv = (GV*)SvREFCNT_inc(gv);
1997 gvop->op_next = (OP*)gvop;
1998 gvop->op_flags = flags;
1999 if (opargs[type] & OA_RETSCALAR)
2001 if (opargs[type] & OA_TARGET)
2002 gvop->op_targ = pad_alloc(type, SVs_PADTMP);
2003 return CHECKOP(type, gvop);
2007 newPVOP(type, flags, pv)
2013 Newz(1101, pvop, 1, PVOP);
2014 pvop->op_type = type;
2015 pvop->op_ppaddr = ppaddr[type];
2017 pvop->op_next = (OP*)pvop;
2018 pvop->op_flags = flags;
2019 if (opargs[type] & OA_RETSCALAR)
2021 if (opargs[type] & OA_TARGET)
2022 pvop->op_targ = pad_alloc(type, SVs_PADTMP);
2023 return CHECKOP(type, pvop);
2032 save_hptr(&curstash);
2033 save_item(curstname);
2038 name = SvPV(sv, len);
2039 curstash = gv_stashpvn(name,len,TRUE);
2040 sv_setpvn(curstname, name, len);
2044 sv_setpv(curstname,"<none>");
2052 utilize(aver, floor, version, id, arg)
2065 if (id->op_type != OP_CONST)
2066 croak("Module name must be constant");
2070 if(version != Nullop) {
2071 SV *vesv = ((SVOP*)version)->op_sv;
2073 if (arg == Nullop && !SvNIOK(vesv)) {
2080 if (version->op_type != OP_CONST || !SvNIOK(vesv))
2081 croak("Version number must be constant number");
2083 /* Make copy of id so we don't free it twice */
2084 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2086 /* Fake up a method call to VERSION */
2087 meth = newSVOP(OP_CONST, 0, newSVpv("VERSION", 7));
2088 veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2089 append_elem(OP_LIST,
2090 prepend_elem(OP_LIST, pack, list(version)),
2091 newUNOP(OP_METHOD, 0, meth)));
2095 /* Fake up an import/unimport */
2096 if (arg && arg->op_type == OP_STUB)
2097 imop = arg; /* no import on explicit () */
2098 else if(SvNIOK(((SVOP*)id)->op_sv)) {
2099 imop = Nullop; /* use 5.0; */
2102 /* Make copy of id so we don't free it twice */
2103 pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
2104 meth = newSVOP(OP_CONST, 0,
2106 ? newSVpv("import", 6)
2107 : newSVpv("unimport", 8)
2109 imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
2110 append_elem(OP_LIST,
2111 prepend_elem(OP_LIST, pack, list(arg)),
2112 newUNOP(OP_METHOD, 0, meth)));
2115 /* Fake up a require */
2116 rqop = newUNOP(OP_REQUIRE, 0, id);
2118 /* Fake up the BEGIN {}, which does its thing immediately. */
2120 newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
2122 append_elem(OP_LINESEQ,
2123 append_elem(OP_LINESEQ,
2124 newSTATEOP(0, Nullch, rqop),
2125 newSTATEOP(0, Nullch, veop)),
2126 newSTATEOP(0, Nullch, imop) ));
2133 newSLICEOP(flags, subscript, listval)
2138 return newBINOP(OP_LSLICE, flags,
2139 list(force_list(subscript)),
2140 list(force_list(listval)) );
2150 if (op->op_type == OP_NULL && op->op_flags & OPf_KIDS)
2151 op = cUNOP->op_first;
2153 if (op->op_type == OP_COND_EXPR) {
2154 I32 t = list_assignment(cCONDOP->op_first->op_sibling);
2155 I32 f = list_assignment(cCONDOP->op_first->op_sibling->op_sibling);
2160 yyerror("Assignment to both a list and a scalar");
2164 if (op->op_type == OP_LIST || op->op_flags & OPf_PARENS ||
2165 op->op_type == OP_RV2AV || op->op_type == OP_RV2HV ||
2166 op->op_type == OP_ASLICE || op->op_type == OP_HSLICE)
2169 if (op->op_type == OP_PADAV || op->op_type == OP_PADHV)
2172 if (op->op_type == OP_RV2SV)
2179 newASSIGNOP(flags, left, optype, right)
2188 if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN) {
2189 return newLOGOP(optype, 0,
2190 mod(scalar(left), optype),
2191 newUNOP(OP_SASSIGN, 0, scalar(right)));
2194 return newBINOP(optype, OPf_STACKED,
2195 mod(scalar(left), optype), scalar(right));
2199 if (list_assignment(left)) {
2201 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2202 left = mod(left, OP_AASSIGN);
2210 op = newBINOP(OP_AASSIGN, flags,
2211 list(force_list(right)),
2212 list(force_list(left)) );
2213 op->op_private = 0 | (flags >> 8);
2214 if (!(left->op_private & OPpLVAL_INTRO)) {
2215 static int generation = 100;
2219 for (curop = LINKLIST(op); curop != op; curop = LINKLIST(curop)) {
2220 if (opargs[curop->op_type] & OA_DANGEROUS) {
2221 if (curop->op_type == OP_GV) {
2222 GV *gv = ((GVOP*)curop)->op_gv;
2223 if (gv == defgv || SvCUR(gv) == generation)
2225 SvCUR(gv) = generation;
2227 else if (curop->op_type == OP_PADSV ||
2228 curop->op_type == OP_PADAV ||
2229 curop->op_type == OP_PADHV ||
2230 curop->op_type == OP_PADANY) {
2231 SV **svp = AvARRAY(comppad_name);
2232 SV *sv = svp[curop->op_targ];
2233 if (SvCUR(sv) == generation)
2235 SvCUR(sv) = generation; /* (SvCUR not used any more) */
2237 else if (curop->op_type == OP_RV2CV)
2239 else if (curop->op_type == OP_RV2SV ||
2240 curop->op_type == OP_RV2AV ||
2241 curop->op_type == OP_RV2HV ||
2242 curop->op_type == OP_RV2GV) {
2243 if (lastop->op_type != OP_GV) /* funny deref? */
2252 op->op_private = OPpASSIGN_COMMON;
2254 if (right && right->op_type == OP_SPLIT) {
2256 if ((tmpop = ((LISTOP*)right)->op_first) &&
2257 tmpop->op_type == OP_PUSHRE)
2259 PMOP *pm = (PMOP*)tmpop;
2260 if (left->op_type == OP_RV2AV &&
2261 !(left->op_private & OPpLVAL_INTRO) &&
2262 !(op->op_private & OPpASSIGN_COMMON) )
2264 tmpop = ((UNOP*)left)->op_first;
2265 if (tmpop->op_type == OP_GV && !pm->op_pmreplroot) {
2266 pm->op_pmreplroot = (OP*)((GVOP*)tmpop)->op_gv;
2267 pm->op_pmflags |= PMf_ONCE;
2268 tmpop = ((UNOP*)op)->op_first; /* to list (nulled) */
2269 tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
2270 tmpop->op_sibling = Nullop; /* don't free split */
2271 right->op_next = tmpop->op_next; /* fix starting loc */
2272 op_free(op); /* blow off assign */
2273 right->op_flags &= ~(OPf_KNOW|OPf_LIST);
2274 /* "I don't know and I don't care." */
2279 if (modcount < 10000 &&
2280 ((LISTOP*)right)->op_last->op_type == OP_CONST)
2282 SV *sv = ((SVOP*)((LISTOP*)right)->op_last)->op_sv;
2284 sv_setiv(sv, modcount+1);
2292 right = newOP(OP_UNDEF, 0);
2293 if (right->op_type == OP_READLINE) {
2294 right->op_flags |= OPf_STACKED;
2295 return newBINOP(OP_NULL, flags, mod(scalar(left), OP_SASSIGN), scalar(right));
2298 eval_start = right; /* Grandfathering $[ assignment here. Bletch.*/
2299 op = newBINOP(OP_SASSIGN, flags,
2300 scalar(right), mod(scalar(left), OP_SASSIGN) );
2312 newSTATEOP(flags, label, op)
2317 U32 seq = intro_my();
2320 Newz(1101, cop, 1, COP);
2321 if (perldb && curcop->cop_line && curstash != debstash) {
2322 cop->op_type = OP_DBSTATE;
2323 cop->op_ppaddr = ppaddr[ OP_DBSTATE ];
2326 cop->op_type = OP_NEXTSTATE;
2327 cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
2329 cop->op_flags = flags;
2330 cop->op_private = 0 | (flags >> 8);
2331 cop->op_next = (OP*)cop;
2334 cop->cop_label = label;
2335 hints |= HINT_BLOCK_SCOPE;
2338 cop->cop_arybase = curcop->cop_arybase;
2340 if (copline == NOLINE)
2341 cop->cop_line = curcop->cop_line;
2343 cop->cop_line = copline;
2346 cop->cop_filegv = GvREFCNT_inc(curcop->cop_filegv);
2347 cop->cop_stash = curstash;
2349 if (perldb && curstash != debstash) {
2350 SV **svp = av_fetch(GvAV(curcop->cop_filegv),(I32)cop->cop_line, FALSE);
2351 if (svp && *svp != &sv_undef && !SvIOK(*svp)) {
2352 (void)SvIOK_on(*svp);
2354 SvSTASH(*svp) = (HV*)cop;
2358 return prepend_elem(OP_LINESEQ, (OP*)cop, op);
2361 /* "Introduce" my variables to visible status. */
2369 if (! min_intro_pending)
2372 svp = AvARRAY(comppad_name);
2373 for (i = min_intro_pending; i <= max_intro_pending; i++) {
2374 if ((sv = svp[i]) && sv != &sv_undef && !SvIVX(sv)) {
2375 SvIVX(sv) = 999999999; /* Don't know scope end yet. */
2376 SvNVX(sv) = (double)cop_seqmax;
2379 min_intro_pending = 0;
2380 comppad_name_fill = max_intro_pending; /* Needn't search higher */
2381 return cop_seqmax++;
2385 newLOGOP(type, flags, first, other)
2394 if (type == OP_XOR) /* Not short circuit, but here by precedence. */
2395 return newBINOP(type, flags, scalar(first), scalar(other));
2397 scalarboolean(first);
2398 /* optimize "!a && b" to "a || b", and "!a || b" to "a && b" */
2399 if (first->op_type == OP_NOT && (first->op_flags & OPf_SPECIAL)) {
2400 if (type == OP_AND || type == OP_OR) {
2406 first = cUNOP->op_first;
2408 first->op_next = op->op_next;
2409 cUNOP->op_first = Nullop;
2413 if (first->op_type == OP_CONST) {
2414 if (dowarn && (first->op_private & OPpCONST_BARE))
2415 warn("Probable precedence problem on %s", op_desc[type]);
2416 if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
2425 else if (first->op_type == OP_WANTARRAY) {
2435 if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
2436 other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
2438 Newz(1101, logop, 1, LOGOP);
2440 logop->op_type = type;
2441 logop->op_ppaddr = ppaddr[type];
2442 logop->op_first = first;
2443 logop->op_flags = flags | OPf_KIDS;
2444 logop->op_other = LINKLIST(other);
2445 logop->op_private = 1 | (flags >> 8);
2447 /* establish postfix order */
2448 logop->op_next = LINKLIST(first);
2449 first->op_next = (OP*)logop;
2450 first->op_sibling = other;
2452 op = newUNOP(OP_NULL, 0, (OP*)logop);
2453 other->op_next = op;
2459 newCONDOP(flags, first, trueop, falseop)
2469 return newLOGOP(OP_AND, 0, first, trueop);
2471 return newLOGOP(OP_OR, 0, first, falseop);
2473 scalarboolean(first);
2474 if (first->op_type == OP_CONST) {
2475 if (SvTRUE(((SVOP*)first)->op_sv)) {
2486 else if (first->op_type == OP_WANTARRAY) {
2490 Newz(1101, condop, 1, CONDOP);
2492 condop->op_type = OP_COND_EXPR;
2493 condop->op_ppaddr = ppaddr[OP_COND_EXPR];
2494 condop->op_first = first;
2495 condop->op_flags = flags | OPf_KIDS;
2496 condop->op_true = LINKLIST(trueop);
2497 condop->op_false = LINKLIST(falseop);
2498 condop->op_private = 1 | (flags >> 8);
2500 /* establish postfix order */
2501 condop->op_next = LINKLIST(first);
2502 first->op_next = (OP*)condop;
2504 first->op_sibling = trueop;
2505 trueop->op_sibling = falseop;
2506 op = newUNOP(OP_NULL, 0, (OP*)condop);
2508 trueop->op_next = op;
2509 falseop->op_next = op;
2515 newRANGE(flags, left, right)
2525 Newz(1101, condop, 1, CONDOP);
2527 condop->op_type = OP_RANGE;
2528 condop->op_ppaddr = ppaddr[OP_RANGE];
2529 condop->op_first = left;
2530 condop->op_flags = OPf_KIDS;
2531 condop->op_true = LINKLIST(left);
2532 condop->op_false = LINKLIST(right);
2533 condop->op_private = 1 | (flags >> 8);
2535 left->op_sibling = right;
2537 condop->op_next = (OP*)condop;
2538 flip = newUNOP(OP_FLIP, flags, (OP*)condop);
2539 flop = newUNOP(OP_FLOP, 0, flip);
2540 op = newUNOP(OP_NULL, 0, flop);
2543 left->op_next = flip;
2544 right->op_next = flop;
2546 condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2547 sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV);
2548 flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY);
2549 sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV);
2551 flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2552 flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0;
2555 if (!flip->op_private || !flop->op_private)
2556 linklist(op); /* blow off optimizer unless constant */
2562 newLOOPOP(flags, debuggable, expr, block)
2570 int once = block && block->op_flags & OPf_SPECIAL &&
2571 (block->op_type == OP_ENTERSUB || block->op_type == OP_NULL);
2574 if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv))
2575 return block; /* do {} while 0 does once */
2576 else if (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)
2577 expr = newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr);
2580 listop = append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0));
2581 op = newLOGOP(OP_AND, 0, expr, listop);
2583 ((LISTOP*)listop)->op_last->op_next = LINKLIST(op);
2585 if (once && op != listop)
2586 op->op_next = ((LOGOP*)cUNOP->op_first)->op_other;
2589 op = newUNOP(OP_NULL, 0, op); /* or do {} while 1 loses outer block */
2591 op->op_flags |= flags;
2593 op->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/
2598 newWHILEOP(flags, debuggable, loop, expr, block, cont)
2612 if (expr && (expr->op_type == OP_READLINE || expr->op_type == OP_GLOB)) {
2613 expr = newUNOP(OP_DEFINED, 0,
2614 newASSIGNOP(0, newSVREF(newGVOP(OP_GV, 0, defgv)), 0, expr) );
2618 block = newOP(OP_NULL, 0);
2621 next = LINKLIST(cont);
2623 cont = append_elem(OP_LINESEQ, cont, newOP(OP_UNSTACK, 0));
2625 listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
2626 redo = LINKLIST(listop);
2629 op = newLOGOP(OP_AND, 0, expr, scalar(listop));
2630 if (op == expr && op->op_type == OP_CONST && !SvTRUE(cSVOP->op_sv)) {
2631 op_free(expr); /* oops, it's a while (0) */
2633 return Nullop; /* (listop already freed by newLOGOP) */
2635 ((LISTOP*)listop)->op_last->op_next = condop =
2636 (op == listop ? redo : LINKLIST(op));
2644 Newz(1101,loop,1,LOOP);
2645 loop->op_type = OP_ENTERLOOP;
2646 loop->op_ppaddr = ppaddr[OP_ENTERLOOP];
2647 loop->op_private = 0;
2648 loop->op_next = (OP*)loop;
2651 op = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, op);
2653 loop->op_redoop = redo;
2654 loop->op_lastop = op;
2657 loop->op_nextop = next;
2659 loop->op_nextop = op;
2661 op->op_flags |= flags;
2662 op->op_private |= (flags >> 8);
2667 #ifndef CAN_PROTOTYPE
2668 newFOROP(flags,label,forline,sv,expr,block,cont)
2677 newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
2678 #endif /* CAN_PROTOTYPE */
2686 if (sv->op_type == OP_RV2SV) { /* symbol table variable */
2687 sv->op_type = OP_RV2GV;
2688 sv->op_ppaddr = ppaddr[OP_RV2GV];
2690 else if (sv->op_type == OP_PADSV) { /* private variable */
2691 padoff = sv->op_targ;
2696 croak("Can't use %s for loop variable", op_desc[sv->op_type]);
2699 sv = newGVOP(OP_GV, 0, defgv);
2701 if (expr->op_type == OP_RV2AV) {
2702 expr = scalar(ref(expr, OP_ITER));
2703 iterflags |= OPf_STACKED;
2705 loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
2706 append_elem(OP_LIST, mod(force_list(expr), OP_GREPSTART),
2708 assert(!loop->op_next);
2709 Renew(loop, 1, LOOP);
2710 loop->op_targ = padoff;
2711 return newSTATEOP(0, label, newWHILEOP(flags, 1, loop,
2712 newOP(OP_ITER, 0), block, cont));
2716 newLOOPEX(type, label)
2721 if (type != OP_GOTO || label->op_type == OP_CONST) {
2722 op = newPVOP(type, 0, savepv(
2723 label->op_type == OP_CONST
2724 ? SvPVx(((SVOP*)label)->op_sv, na)
2729 if (label->op_type == OP_ENTERSUB)
2730 label = newUNOP(OP_REFGEN, 0, mod(label, OP_REFGEN));
2731 op = newUNOP(type, OPf_STACKED, label);
2733 hints |= HINT_BLOCK_SCOPE;
2741 if (!CvXSUB(cv) && CvROOT(cv)) {
2743 croak("Can't undef active subroutine");
2750 op_free(CvROOT(cv));
2751 CvROOT(cv) = Nullop;
2754 SvREFCNT_dec(CvGV(cv));
2756 SvREFCNT_dec(CvOUTSIDE(cv));
2757 CvOUTSIDE(cv) = Nullcv;
2758 if (CvPADLIST(cv)) {
2759 I32 i = AvFILL(CvPADLIST(cv));
2761 SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
2765 SvREFCNT_dec((SV*)CvPADLIST(cv));
2766 CvPADLIST(cv) = Nullav;
2776 AV* protopadlist = CvPADLIST(proto);
2777 AV* protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
2778 AV* protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
2779 SV** svp = AvARRAY(protopad);
2788 cv = compcv = (CV*)NEWSV(1104,0);
2789 sv_upgrade((SV *)cv, SVt_PVCV);
2792 CvFILEGV(cv) = CvFILEGV(proto);
2793 CvGV(cv) = GvREFCNT_inc(CvGV(proto));
2794 CvSTASH(cv) = CvSTASH(proto);
2795 CvROOT(cv) = CvROOT(proto);
2796 CvSTART(cv) = CvSTART(proto);
2797 if (CvOUTSIDE(proto))
2798 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc((SV*)CvOUTSIDE(proto));
2802 comppadlist = newAV();
2803 AvREAL_off(comppadlist);
2804 av_store(comppadlist, 0, SvREFCNT_inc((SV*)protopad_name));
2805 av_store(comppadlist, 1, (SV*)comppad);
2806 CvPADLIST(cv) = comppadlist;
2807 av_extend(comppad, AvFILL(protopad));
2808 curpad = AvARRAY(comppad);
2810 av = newAV(); /* will be @_ */
2812 av_store(comppad, 0, (SV*)av);
2813 AvFLAGS(av) = AVf_REIFY;
2815 svp = AvARRAY(protopad_name);
2816 for ( ix = AvFILL(protopad); ix > 0; ix--) {
2818 if (svp[ix] != &sv_undef) {
2819 char *name = SvPVX(svp[ix]); /* XXX */
2820 if (SvFLAGS(svp[ix]) & SVf_FAKE) { /* lexical from outside? */
2821 I32 off = pad_findlex(name,ix,curcop->cop_seq, CvOUTSIDE(proto),
2824 croak("panic: cv_clone: %s", name);
2826 else { /* our own lexical */
2828 av_store(comppad, ix, sv = (SV*)newAV());
2829 else if (*name == '%')
2830 av_store(comppad, ix, sv = (SV*)newHV());
2832 av_store(comppad, ix, sv = NEWSV(0,0));
2837 av_store(comppad, ix, sv = NEWSV(0,0));
2853 if(cv && SvPOK(cv) && !SvCUR(cv)) {
2854 for (o = CvSTART(cv); o; o = o->op_next) {
2855 OPCODE type = o->op_type;
2857 if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK)
2859 if (type == OP_LEAVESUB || type == OP_RETURN)
2861 if (type != OP_CONST || sv)
2864 sv = ((SVOP*)o)->op_sv;
2871 newSUB(floor,op,proto,block)
2878 char *name = op ? SvPVx(cSVOP->op_sv, na) : "__ANON__";
2879 GV* gv = gv_fetchpv(name, GV_ADDMULTI, SVt_PVCV);
2886 if (cv = GvCV(gv)) {
2888 cv = 0; /* just a cached method */
2889 else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
2890 SV* const_sv = cv_const_sv(cv);
2892 char *p = proto ? SvPVx(((SVOP*)proto)->op_sv, na) : Nullch;
2894 if((!proto != !SvPOK(cv)) || (p && strNE(SvPV((SV*)cv,na), p))) {
2895 warn("Prototype mismatch: (%s) vs (%s)",
2896 SvPOK(cv) ? SvPV((SV*)cv,na) : "none",
2900 if ((const_sv || dowarn) && strNE(name, "BEGIN")) {/* already defined (or promised)? */
2901 line_t oldline = curcop->cop_line;
2903 curcop->cop_line = copline;
2904 warn(const_sv ? "Constant subroutine %s redefined"
2905 : "Subroutine %s redefined",name);
2906 curcop->cop_line = oldline;
2912 if (cv) { /* must reuse cv if autoloaded */
2914 CvOUTSIDE(cv) = CvOUTSIDE(compcv);
2915 CvOUTSIDE(compcv) = 0;
2916 CvPADLIST(cv) = CvPADLIST(compcv);
2917 CvPADLIST(compcv) = 0;
2918 if (SvREFCNT(compcv) > 1) /* XXX Make closures transit through stub. */
2919 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc((SV*)cv);
2920 SvREFCNT_dec(compcv);
2927 CvFILEGV(cv) = curcop->cop_filegv;
2928 CvGV(cv) = GvREFCNT_inc(gv);
2929 CvSTASH(cv) = curstash;
2932 char *p = SvPVx(((SVOP*)proto)->op_sv, na);
2933 sv_setpv((SV*)cv, p);
2949 av = newAV(); /* Will be @_ */
2951 av_store(comppad, 0, (SV*)av);
2952 AvFLAGS(av) = AVf_REIFY;
2954 for (ix = AvFILL(comppad); ix > 0; ix--) {
2955 if (!SvPADMY(curpad[ix]))
2956 SvPADTMP_on(curpad[ix]);
2959 if (AvFILL(comppad_name) < AvFILL(comppad))
2960 av_store(comppad_name, AvFILL(comppad), Nullsv);
2962 CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block));
2963 CvSTART(cv) = LINKLIST(CvROOT(cv));
2964 CvROOT(cv)->op_next = 0;
2966 if (s = strrchr(name,':'))
2970 if (strEQ(s, "BEGIN") && !error_count) {
2971 line_t oldline = compiling.cop_line;
2975 SAVESPTR(compiling.cop_filegv);
2979 av_push(beginav, (SV *)cv);
2980 DEBUG_x( dump_sub(gv) );
2981 rs = SvREFCNT_inc(nrs);
2984 if (GvCV(gv) == cv) { /* Detach it. */
2986 GvCV(gv) = 0; /* Was above calllist, why? IZ */
2990 curcop = &compiling;
2991 curcop->cop_line = oldline; /* might have recursed to yylex */
2994 else if (strEQ(s, "END") && !error_count) {
2997 av_unshift(endav, 1);
2998 av_store(endav, 0, SvREFCNT_inc(cv));
3000 if (perldb && curstash != debstash) {
3002 SV *tmpstr = sv_newmortal();
3003 static GV *db_postponed;
3007 sprintf(buf,"%s:%ld",SvPVX(GvSV(curcop->cop_filegv)), (long)subline);
3008 sv = newSVpv(buf,0);
3010 sprintf(buf,"%ld",(long)curcop->cop_line);
3012 gv_efullname3(tmpstr, gv, Nullch);
3013 hv_store(GvHV(DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0);
3014 if (!db_postponed) {
3015 db_postponed = gv_fetchpv("DB::postponed", TRUE, SVt_PVHV);
3017 hv = GvHVn(db_postponed);
3018 if (HvFILL(hv) >= 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr))
3019 && (cv = GvCV(db_postponed))) {
3024 perl_call_sv((SV*)cv, G_DISCARD);
3031 GvCV(gv) = 0; /* Will remember in SVOP instead. */
3039 newXSUB(name, ix, subaddr, filename)
3045 CV* cv = newXS(name, (void(*)())subaddr, filename);
3047 CvXSUBANY(cv).any_i32 = ix;
3053 newXS(name, subaddr, filename)
3055 void (*subaddr) _((CV*));
3059 GV *gv = gv_fetchpv((name ? name : "__ANON__"), GV_ADDMULTI, SVt_PVCV);
3064 if (cv = GvCV(gv)) {
3066 cv = 0; /* just a cached method */
3067 else if (CvROOT(cv) || CvXSUB(cv)) { /* already defined? */
3069 line_t oldline = curcop->cop_line;
3071 curcop->cop_line = copline;
3072 warn("Subroutine %s redefined",name);
3073 curcop->cop_line = oldline;
3079 if (cv) { /* must reuse cv if autoloaded */
3080 assert(SvREFCNT(CvGV(cv)) > 1);
3081 SvREFCNT_dec(CvGV(cv));
3084 cv = (CV*)NEWSV(1105,0);
3085 sv_upgrade((SV *)cv, SVt_PVCV);
3088 CvGV(cv) = GvREFCNT_inc(gv);
3090 CvFILEGV(cv) = gv_fetchfile(filename);
3091 CvXSUB(cv) = subaddr;
3094 else if (s = strrchr(name,':'))
3098 if (strEQ(s, "BEGIN")) {
3101 av_push(beginav, SvREFCNT_inc(gv));
3103 else if (strEQ(s, "END")) {
3106 av_unshift(endav, 1);
3107 av_store(endav, 0, SvREFCNT_inc(gv));
3110 GvCV(gv) = 0; /* Will remember elsewhere instead. */
3117 newFORM(floor,op,block)
3128 name = SvPVx(cSVOP->op_sv, na);
3131 gv = gv_fetchpv(name,TRUE, SVt_PVFM);
3133 if (cv = GvFORM(gv)) {
3135 line_t oldline = curcop->cop_line;
3137 curcop->cop_line = copline;
3138 warn("Format %s redefined",name);
3139 curcop->cop_line = oldline;
3145 CvGV(cv) = GvREFCNT_inc(gv);
3146 CvFILEGV(cv) = curcop->cop_filegv;
3148 for (ix = AvFILL(comppad); ix > 0; ix--) {
3149 if (!SvPADMY(curpad[ix]))
3150 SvPADTMP_on(curpad[ix]);
3153 CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block));
3154 CvSTART(cv) = LINKLIST(CvROOT(cv));
3155 CvROOT(cv)->op_next = 0;
3167 return newUNOP(OP_REFGEN, 0,
3168 mod(list(convert(OP_ANONLIST, 0, op)), OP_REFGEN));
3175 return newUNOP(OP_REFGEN, 0,
3176 mod(list(convert(OP_ANONHASH, 0, op)), OP_REFGEN));
3180 newANONSUB(floor, proto, block)
3185 return newUNOP(OP_REFGEN, 0,
3186 newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block)));
3193 switch (o->op_type) {
3195 o->op_type = OP_PADAV;
3196 o->op_ppaddr = ppaddr[OP_PADAV];
3197 return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
3200 o->op_type = OP_RV2AV;
3201 o->op_ppaddr = ppaddr[OP_RV2AV];
3206 warn("oops: oopsAV");
3216 switch (o->op_type) {
3219 o->op_type = OP_PADHV;
3220 o->op_ppaddr = ppaddr[OP_PADHV];
3221 return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
3225 o->op_type = OP_RV2HV;
3226 o->op_ppaddr = ppaddr[OP_RV2HV];
3231 warn("oops: oopsHV");
3241 if (o->op_type == OP_PADANY) {
3242 o->op_type = OP_PADAV;
3243 o->op_ppaddr = ppaddr[OP_PADAV];
3246 return newUNOP(OP_RV2AV, 0, scalar(o));
3254 if (type == OP_MAPSTART)
3255 return newUNOP(OP_NULL, 0, o);
3256 return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
3263 if (o->op_type == OP_PADANY) {
3264 o->op_type = OP_PADHV;
3265 o->op_ppaddr = ppaddr[OP_PADHV];
3268 return newUNOP(OP_RV2HV, 0, scalar(o));
3275 croak("NOT IMPL LINE %d",__LINE__);
3285 return newUNOP(OP_RV2CV, flags, scalar(o));
3292 if (o->op_type == OP_PADANY) {
3293 o->op_type = OP_PADSV;
3294 o->op_ppaddr = ppaddr[OP_PADSV];
3297 return newUNOP(OP_RV2SV, 0, scalar(o));
3300 /* Check routines. */
3306 op->op_private = hints;
3314 if (cUNOP->op_first->op_type == OP_CONCAT)
3315 op->op_flags |= OPf_STACKED;
3323 if (op->op_flags & OPf_KIDS) {
3326 op = modkids(ck_fun(op), op->op_type);
3327 kid = cUNOP->op_first;
3328 newop = kUNOP->op_first->op_sibling;
3330 (newop->op_sibling ||
3331 !(opargs[newop->op_type] & OA_RETSCALAR) ||
3332 newop->op_type == OP_PADAV || newop->op_type == OP_PADHV ||
3333 newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) {
3337 op_free(kUNOP->op_first);
3338 kUNOP->op_first = newop;
3340 op->op_ppaddr = ppaddr[++op->op_type];
3349 if (op->op_flags & OPf_KIDS) {
3350 OP *kid = cUNOP->op_first;
3351 if (kid->op_type != OP_HELEM)
3352 croak("%s argument is not a HASH element", op_desc[op->op_type]);
3362 I32 type = op->op_type;
3364 if (op->op_flags & OPf_KIDS) {
3365 if (cLISTOP->op_first->op_type == OP_STUB) {
3367 op = newUNOP(type, OPf_SPECIAL,
3368 newGVOP(OP_GV, 0, gv_fetchpv("main'ARGV", TRUE, SVt_PVAV)));
3379 hints |= HINT_BLOCK_SCOPE;
3380 if (op->op_flags & OPf_KIDS) {
3381 SVOP *kid = (SVOP*)cUNOP->op_first;
3384 op->op_flags &= ~OPf_KIDS;
3387 else if (kid->op_type == OP_LINESEQ) {
3390 kid->op_next = op->op_next;
3391 cUNOP->op_first = 0;
3394 Newz(1101, enter, 1, LOGOP);
3395 enter->op_type = OP_ENTERTRY;
3396 enter->op_ppaddr = ppaddr[OP_ENTERTRY];
3397 enter->op_private = 0;
3399 /* establish postfix order */
3400 enter->op_next = (OP*)enter;
3402 op = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid);
3403 op->op_type = OP_LEAVETRY;
3404 op->op_ppaddr = ppaddr[OP_LEAVETRY];
3405 enter->op_other = op;
3411 op = newUNOP(OP_ENTEREVAL, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3413 op->op_targ = (PADOFFSET)hints;
3422 if (op->op_flags & OPf_STACKED) {
3424 kid = cUNOP->op_first->op_sibling;
3425 if (kid->op_type == OP_RV2GV)
3437 o = fold_constants(o);
3438 if (o->op_type == OP_CONST)
3447 SVOP *kid = (SVOP*)cUNOP->op_first;
3449 op->op_private |= (hints & HINT_STRICT_REFS);
3450 if (kid->op_type == OP_CONST) {
3451 int iscv = (op->op_type==OP_RV2CV)*2;
3453 kid->op_type = OP_GV;
3454 for (gv = 0; !gv; iscv++) {
3456 * This is a little tricky. We only want to add the symbol if we
3457 * didn't add it in the lexer. Otherwise we get duplicate strict
3458 * warnings. But if we didn't add it in the lexer, we must at
3459 * least pretend like we wanted to add it even if it existed before,
3460 * or we get possible typo warnings. OPpCONST_ENTERED says
3461 * whether the lexer already added THIS instance of this symbol.
3463 gv = gv_fetchpv(SvPVx(kid->op_sv, na),
3464 iscv | !(kid->op_private & OPpCONST_ENTERED),
3467 : op->op_type == OP_RV2SV
3469 : op->op_type == OP_RV2AV
3471 : op->op_type == OP_RV2HV
3475 SvREFCNT_dec(kid->op_sv);
3476 kid->op_sv = SvREFCNT_inc(gv);
3485 I32 type = op->op_type;
3487 if (op->op_flags & OPf_REF)
3490 if (op->op_flags & OPf_KIDS) {
3491 SVOP *kid = (SVOP*)cUNOP->op_first;
3493 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3494 OP *newop = newGVOP(type, OPf_REF,
3495 gv_fetchpv(SvPVx(kid->op_sv, na), TRUE, SVt_PVIO));
3502 if (type == OP_FTTTY)
3503 return newGVOP(type, OPf_REF, gv_fetchpv("main'STDIN", TRUE,
3506 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3519 int type = op->op_type;
3520 register I32 oa = opargs[type] >> OASHIFT;
3522 if (op->op_flags & OPf_STACKED) {
3523 if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL))
3526 return no_fh_allowed(op);
3529 if (op->op_flags & OPf_KIDS) {
3530 tokid = &cLISTOP->op_first;
3531 kid = cLISTOP->op_first;
3532 if (kid->op_type == OP_PUSHMARK ||
3533 kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)
3535 tokid = &kid->op_sibling;
3536 kid = kid->op_sibling;
3538 if (!kid && opargs[type] & OA_DEFGV)
3539 *tokid = kid = newSVREF(newGVOP(OP_GV, 0, defgv));
3543 sibl = kid->op_sibling;
3557 if (kid->op_type == OP_CONST &&
3558 (kid->op_private & OPpCONST_BARE)) {
3559 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3560 OP *newop = newAVREF(newGVOP(OP_GV, 0,
3561 gv_fetchpv(name, TRUE, SVt_PVAV) ));
3563 warn("Array @%s missing the @ in argument %d of %s()",
3564 name, numargs, op_desc[type]);
3567 kid->op_sibling = sibl;
3570 else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
3571 bad_type(numargs, "array", op_desc[op->op_type], kid);
3575 if (kid->op_type == OP_CONST &&
3576 (kid->op_private & OPpCONST_BARE)) {
3577 char *name = SvPVx(((SVOP*)kid)->op_sv, na);
3578 OP *newop = newHVREF(newGVOP(OP_GV, 0,
3579 gv_fetchpv(name, TRUE, SVt_PVHV) ));
3581 warn("Hash %%%s missing the %% in argument %d of %s()",
3582 name, numargs, op_desc[type]);
3585 kid->op_sibling = sibl;
3588 else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
3589 bad_type(numargs, "hash", op_desc[op->op_type], kid);
3594 OP *newop = newUNOP(OP_NULL, 0, kid);
3595 kid->op_sibling = 0;
3597 newop->op_next = newop;
3599 kid->op_sibling = sibl;
3604 if (kid->op_type != OP_GV) {
3605 if (kid->op_type == OP_CONST &&
3606 (kid->op_private & OPpCONST_BARE)) {
3607 OP *newop = newGVOP(OP_GV, 0,
3608 gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, na), TRUE,
3614 kid->op_sibling = 0;
3615 kid = newUNOP(OP_RV2GV, 0, scalar(kid));
3617 kid->op_sibling = sibl;
3623 mod(scalar(kid), type);
3627 tokid = &kid->op_sibling;
3628 kid = kid->op_sibling;
3630 op->op_private |= numargs;
3632 return too_many_arguments(op,op_desc[op->op_type]);
3635 else if (opargs[type] & OA_DEFGV) {
3637 return newUNOP(type, 0, newSVREF(newGVOP(OP_GV, 0, defgv)));
3641 while (oa & OA_OPTIONAL)
3643 if (oa && oa != OA_LIST)
3644 return too_few_arguments(op,op_desc[op->op_type]);
3653 GV *gv = gv_fetchpv("glob", FALSE, SVt_PVCV);
3655 if (gv && GvIMPORTED_CV(gv)) {
3656 op->op_type = OP_LIST;
3657 op->op_ppaddr = ppaddr[OP_LIST];
3658 op = newUNOP(OP_ENTERSUB, OPf_STACKED,
3659 append_elem(OP_LIST, op,
3660 scalar(newUNOP(OP_RV2CV, 0,
3661 newGVOP(OP_GV, 0, gv)))));
3664 gv = newGVgen("main");
3666 append_elem(OP_GLOB, op, newGVOP(OP_GV, 0, gv));
3677 OPCODE type = op->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
3679 op->op_ppaddr = ppaddr[OP_GREPSTART];
3680 Newz(1101, gwop, 1, LOGOP);
3682 if (op->op_flags & OPf_STACKED) {
3685 kid = cLISTOP->op_first->op_sibling;
3686 for (k = cLISTOP->op_first->op_sibling->op_next; k; k = k->op_next) {
3689 kid->op_next = (OP*)gwop;
3690 op->op_flags &= ~OPf_STACKED;
3692 kid = cLISTOP->op_first->op_sibling;
3693 if (type == OP_MAPWHILE)
3700 kid = cLISTOP->op_first->op_sibling;
3701 if (kid->op_type != OP_NULL)
3702 croak("panic: ck_grep");
3703 kid = kUNOP->op_first;
3705 gwop->op_type = type;
3706 gwop->op_ppaddr = ppaddr[type];
3707 gwop->op_first = listkids(op);
3708 gwop->op_flags |= OPf_KIDS;
3709 gwop->op_private = 1;
3710 gwop->op_other = LINKLIST(kid);
3711 gwop->op_targ = pad_alloc(type, SVs_PADTMP);
3712 kid->op_next = (OP*)gwop;
3714 kid = cLISTOP->op_first->op_sibling;
3715 if (!kid || !kid->op_sibling)
3716 return too_few_arguments(op,op_desc[op->op_type]);
3717 for (kid = kid->op_sibling; kid; kid = kid->op_sibling)
3718 mod(kid, OP_GREPSTART);
3727 if (op->op_flags & OPf_KIDS) {
3728 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3729 if (kid && kid->op_type == OP_CONST)
3730 fbm_compile(((SVOP*)kid)->op_sv);
3739 /* XXX length optimization goes here */
3747 return modkids(ck_fun(op), op->op_type);
3754 return refkids(ck_fun(op), op->op_type);
3763 kid = cLISTOP->op_first;
3765 op = force_list(op);
3766 kid = cLISTOP->op_first;
3768 if (kid->op_type == OP_PUSHMARK)
3769 kid = kid->op_sibling;
3770 if (kid && op->op_flags & OPf_STACKED)
3771 kid = kid->op_sibling;
3772 else if (kid && !kid->op_sibling) { /* print HANDLE; */
3773 if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE) {
3774 op->op_flags |= OPf_STACKED; /* make it a filehandle */
3775 kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid));
3776 cLISTOP->op_first->op_sibling = kid;
3777 cLISTOP->op_last = kid;
3778 kid = kid->op_sibling;
3783 append_elem(op->op_type, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
3789 if (hints & HINT_LOCALE)
3790 op->op_private |= OPpLOCALE;
3804 if (hints & HINT_LOCALE)
3805 op->op_private |= OPpLOCALE;
3817 if (hints & HINT_LOCALE)
3818 op->op_private |= OPpLOCALE;
3828 cPMOP->op_pmflags |= PMf_RUNTIME;
3829 cPMOP->op_pmpermflags |= PMf_RUNTIME;
3844 if (cBINOP->op_first->op_flags & OPf_PARENS) {
3845 op->op_private |= OPpREPEAT_DOLIST;
3846 cBINOP->op_first = force_list(cBINOP->op_first);
3857 if (op->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */
3858 SVOP *kid = (SVOP*)cUNOP->op_first;
3860 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
3862 for (s = SvPVX(kid->op_sv); *s; s++) {
3863 if (*s == ':' && s[1] == ':') {
3865 Move(s+2, s+1, strlen(s+2)+1, char);
3866 --SvCUR(kid->op_sv);
3869 sv_catpvn(kid->op_sv, ".pm", 3);
3879 croak("NOT IMPL LINE %d",__LINE__);
3889 if (op->op_flags & OPf_KIDS) {
3890 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3891 if (kid && kid->op_sibling) {
3892 op->op_type = OP_SSELECT;
3893 op->op_ppaddr = ppaddr[OP_SSELECT];
3895 return fold_constants(op);
3899 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3900 if (kid && kid->op_type == OP_RV2GV)
3901 kid->op_private &= ~HINT_STRICT_REFS;
3909 I32 type = op->op_type;
3911 if (!(op->op_flags & OPf_KIDS)) {
3913 return newUNOP(type, 0,
3914 scalar(newUNOP(OP_RV2AV, 0,
3915 scalar(newGVOP(OP_GV, 0, subline
3917 : gv_fetchpv("ARGV", TRUE, SVt_PVAV) )))));
3919 return scalar(modkids(ck_fun(op), type));
3928 if (hints & HINT_LOCALE)
3929 op->op_private |= OPpLOCALE;
3932 if (op->op_flags & OPf_STACKED) {
3933 OP *kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3935 kid = kUNOP->op_first; /* get past rv2gv */
3937 if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
3939 if (kid->op_type == OP_SCOPE) {
3943 else if (kid->op_type == OP_LEAVE) {
3944 if (op->op_type == OP_SORT) {
3945 null(kid); /* wipe out leave */
3948 for (k = kLISTOP->op_first->op_next; k; k = k->op_next) {
3949 if (k->op_next == kid)
3954 kid->op_next = 0; /* just disconnect the leave */
3955 k = kLISTOP->op_first;
3959 kid = cLISTOP->op_first->op_sibling; /* get past pushmark */
3960 null(kid); /* wipe out rv2gv */
3961 if (op->op_type == OP_SORT)
3965 op->op_flags |= OPf_SPECIAL;
3979 if (op->op_flags & OPf_STACKED)
3980 return no_fh_allowed(op);
3982 kid = cLISTOP->op_first;
3983 if (kid->op_type != OP_NULL)
3984 croak("panic: ck_split");
3985 kid = kid->op_sibling;
3986 op_free(cLISTOP->op_first);
3987 cLISTOP->op_first = kid;
3989 cLISTOP->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
3990 cLISTOP->op_last = kid; /* There was only one element previously */
3993 if (kid->op_type != OP_MATCH) {
3994 OP *sibl = kid->op_sibling;
3995 kid->op_sibling = 0;
3996 kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, Nullop);
3997 if (cLISTOP->op_first == cLISTOP->op_last)
3998 cLISTOP->op_last = kid;
3999 cLISTOP->op_first = kid;
4000 kid->op_sibling = sibl;
4003 if (pm->op_pmshort && !(pm->op_pmflags & PMf_ALL)) {
4004 SvREFCNT_dec(pm->op_pmshort); /* can't use substring to optimize */
4008 kid->op_type = OP_PUSHRE;
4009 kid->op_ppaddr = ppaddr[OP_PUSHRE];
4012 if (!kid->op_sibling)
4013 append_elem(OP_SPLIT, op, newSVREF(newGVOP(OP_GV, 0, defgv)) );
4015 kid = kid->op_sibling;
4018 if (!kid->op_sibling)
4019 append_elem(OP_SPLIT, op, newSVOP(OP_CONST, 0, newSViv(0)));
4021 kid = kid->op_sibling;
4024 if (kid->op_sibling)
4025 return too_many_arguments(op,op_desc[op->op_type]);
4034 OP *prev = ((cUNOP->op_first->op_sibling)
4035 ? cUNOP : ((UNOP*)cUNOP->op_first))->op_first;
4036 OP *o = prev->op_sibling;
4043 for (cvop = o; cvop->op_sibling; cvop = cvop->op_sibling) ;
4044 if (cvop->op_type == OP_RV2CV) {
4046 op->op_private |= (cvop->op_private & OPpENTERSUB_AMPER);
4047 null(cvop); /* disable rv2cv */
4048 tmpop = (SVOP*)((UNOP*)cvop)->op_first;
4049 if (tmpop->op_type == OP_GV) {
4050 cv = GvCV(tmpop->op_sv);
4051 if (cv && SvPOK(cv) && !(op->op_private & OPpENTERSUB_AMPER))
4052 proto = SvPV((SV*)cv,na);
4055 op->op_private |= (hints & HINT_STRICT_REFS);
4056 if (perldb && curstash != debstash)
4057 op->op_private |= OPpENTERSUB_DB;
4062 return too_many_arguments(op, CvNAME(cv));
4080 if (o->op_type != OP_REFGEN && o->op_type != OP_UNDEF)
4081 bad_type(arg, "block", CvNAME(cv), o);
4086 if (o->op_type == OP_RV2GV)
4090 o = newUNOP(OP_RV2GV, 0, kid);
4091 o->op_sibling = kid->op_sibling;
4092 kid->op_sibling = 0;
4093 prev->op_sibling = o;
4101 if (o->op_type != OP_RV2GV)
4102 bad_type(arg, "symbol", CvNAME(cv), o);
4105 if (o->op_type != OP_RV2CV)
4106 bad_type(arg, "sub", CvNAME(cv), o);
4109 if (o->op_type != OP_RV2SV && o->op_type != OP_PADSV)
4110 bad_type(arg, "scalar", CvNAME(cv), o);
4113 if (o->op_type != OP_RV2AV && o->op_type != OP_PADAV)
4114 bad_type(arg, "array", CvNAME(cv), o);
4117 if (o->op_type != OP_RV2HV && o->op_type != OP_PADHV)
4118 bad_type(arg, "hash", CvNAME(cv), o);
4122 o = newUNOP(OP_REFGEN, 0, kid);
4123 o->op_sibling = kid->op_sibling;
4124 kid->op_sibling = 0;
4125 prev->op_sibling = o;
4136 croak("Malformed prototype for %s: %s",
4137 CvNAME(cv),SvPV((SV*)cv,na));
4142 mod(o, OP_ENTERSUB);
4146 if (proto && !optional && *proto == '$')
4147 return too_few_arguments(op, CvNAME(cv));
4155 SvREADONLY_on(cSVOP->op_sv);
4163 if (op->op_flags & OPf_KIDS) {
4164 SVOP *kid = (SVOP*)cUNOP->op_first;
4166 if (kid->op_type == OP_NULL)
4167 kid = (SVOP*)kid->op_sibling;
4169 kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE))
4170 op->op_flags |= OPf_SPECIAL;
4175 /* A peephole optimizer. We visit the ops in the order they're to execute. */
4181 register OP* oldop = 0;
4182 if (!o || o->op_seq)
4187 for (; o; o = o->op_next) {
4193 switch (o->op_type) {
4196 curcop = ((COP*)o); /* for warnings */
4197 o->op_seq = op_seqmax++;
4208 if (o->op_next->op_type == OP_STRINGIFY)
4210 o->op_seq = op_seqmax++;
4213 if ((o->op_flags & (OPf_KNOW|OPf_LIST)) != (OPf_KNOW|OPf_LIST)) {
4214 o->op_seq = op_seqmax++;
4215 break; /* Scalar stub must produce undef. List stub is noop */
4219 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
4220 curcop = ((COP*)op);
4226 if (oldop && o->op_next) {
4227 oldop->op_next = o->op_next;
4230 o->op_seq = op_seqmax++;
4234 if (o->op_next->op_type == OP_RV2SV) {
4235 if (!(o->op_next->op_private & (OPpDEREF_HV|OPpDEREF_AV))) {
4237 o->op_private |= o->op_next->op_private & OPpLVAL_INTRO;
4238 o->op_next = o->op_next->op_next;
4239 o->op_type = OP_GVSV;
4240 o->op_ppaddr = ppaddr[OP_GVSV];
4243 else if (o->op_next->op_type == OP_RV2AV) {
4244 OP* pop = o->op_next->op_next;
4246 if (pop->op_type == OP_CONST &&
4247 (op = pop->op_next) &&
4248 pop->op_next->op_type == OP_AELEM &&
4249 !(pop->op_next->op_private &
4250 (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)) &&
4251 (i = SvIV(((SVOP*)pop)->op_sv) - compiling.cop_arybase)
4255 SvREFCNT_dec(((SVOP*)pop)->op_sv);
4259 o->op_flags |= pop->op_next->op_flags & OPf_MOD;
4260 o->op_next = pop->op_next->op_next;
4261 o->op_type = OP_AELEMFAST;
4262 o->op_ppaddr = ppaddr[OP_AELEMFAST];
4263 o->op_private = (U8)i;
4264 GvAVn((GV*)(((SVOP*)o)->op_sv));
4267 o->op_seq = op_seqmax++;
4274 o->op_seq = op_seqmax++;
4275 peep(cLOGOP->op_other);
4279 o->op_seq = op_seqmax++;
4280 peep(cCONDOP->op_true);
4281 peep(cCONDOP->op_false);
4285 o->op_seq = op_seqmax++;
4286 peep(cLOOP->op_redoop);
4287 peep(cLOOP->op_nextop);
4288 peep(cLOOP->op_lastop);
4293 o->op_seq = op_seqmax++;
4294 peep(cPMOP->op_pmreplstart);
4298 o->op_seq = op_seqmax++;
4299 if (dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
4300 if (o->op_next->op_sibling &&
4301 o->op_next->op_sibling->op_type != OP_DIE) {
4302 line_t oldline = curcop->cop_line;
4304 curcop->cop_line = ((COP*)o->op_next)->cop_line;
4305 warn("Statement unlikely to be reached");
4306 warn("(Maybe you meant system() when you said exec()?)\n");
4307 curcop->cop_line = oldline;
4312 o->op_seq = op_seqmax++;