/* op.c
*
- * Copyright (c) 1991-1997, Larry Wall
+ * Copyright (c) 1991-1999, Larry Wall
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
#define CHECKCALL this->*PL_check
#else
#define CHECKCALL *PL_check
+#endif
+
+/* #define PL_OP_SLAB_ALLOC */
+
+#ifdef PL_OP_SLAB_ALLOC
+#define SLAB_SIZE 8192
+static char *PL_OpPtr = NULL;
+static int PL_OpSpace = 0;
+#define NewOp(m,var,c,type) do { if ((PL_OpSpace -= c*sizeof(type)) >= 0) \
+ var = (type *)(PL_OpPtr -= c*sizeof(type)); \
+ else \
+ var = (type *) Slab_Alloc(m,c*sizeof(type)); \
+ } while (0)
+
+static void *
+Slab_Alloc(int m, size_t sz)
+{
+ Newz(m,PL_OpPtr,SLAB_SIZE,char);
+ PL_OpSpace = SLAB_SIZE - sz;
+ return PL_OpPtr += PL_OpSpace;
+}
+
+#else
+#define NewOp(m, var, c, type) Newz(m, var, c, type)
#endif
-
/*
* In the following definition, the ", Nullop" is just to make the compiler
* think the expression is of the right type: croak actually does a Siglongjmp.
static void bad_type _((I32 n, char *t, char *name, OP *kid));
static OP *modkids _((OP *o, I32 type));
static OP *no_fh_allowed _((OP *o));
+static void no_bareword_allowed _((OP *o));
static OP *scalarboolean _((OP *o));
static OP *too_few_arguments _((OP *o, char* name));
static OP *too_many_arguments _((OP *o, char* name));
static void null _((OP* o));
static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, U32 seq,
- CV* startcv, I32 cx_ix, I32 saweval));
+ CV* startcv, I32 cx_ix, I32 saweval, U32 flags));
static OP *newDEFSVOP _((void));
static OP *new_logop _((I32 type, I32 flags, OP **firstp, OP **otherp));
+static void simplify_sort _((OP *o));
+static bool is_handle_constructor _((OP *o, I32 argnum));
#endif
STATIC char*
gv_ename(GV *gv)
{
+ STRLEN n_a;
SV* tmpsv = sv_newmortal();
gv_efullname3(tmpsv, gv, Nullch);
- return SvPV(tmpsv,PL_na);
+ return SvPV(tmpsv,n_a);
}
STATIC OP *
(int)n, name, t, PL_op_desc[kid->op_type]));
}
+STATIC void
+no_bareword_allowed(OP *o)
+{
+ warn("Bareword \"%s\" not allowed while \"strict subs\" in use",
+ SvPV_nolen(cSVOPo->op_sv));
+ ++PL_error_count;
+}
+
void
assertref(OP *o)
{
SV *msg = sv_2mortal(
newSVpvf("(Did you mean $ or @ instead of %c?)\n",
type == OP_ENTERSUB ? '&' : '%'));
- if (PL_in_eval & 2)
+ if (PL_in_eval & EVAL_WARNONLY)
warn("%_", msg);
else if (PL_in_eval)
sv_catsv(GvSV(PL_errgv), msg);
name[1] == '_' && (int)strlen(name) > 2))
{
if (!isPRINT(name[1])) {
- name[3] = '\0';
+ /* 1999-02-27 mjd@plover.com */
+ char *p;
+ p = strchr(name, '\0');
+ /* The next block assumes the buffer is at least 205 chars
+ long. At present, it's always at least 256 chars. */
+ if (p-name > 200) {
+ strcpy(name+200, "...");
+ p = name+199;
+ }
+ else {
+ p[1] = '\0';
+ }
+ /* Move everything else down one character */
+ for (; p-name > 2; p--)
+ *p = *(p-1);
name[2] = toCTRL(name[1]);
name[1] = '^';
}
- croak("Can't use global %s in \"my\"",name);
+ yyerror(form("Can't use global %s in \"my\"",name));
}
if (ckWARN(WARN_UNSAFE) && AvFILLp(PL_comppad_name) >= 0) {
SV **svp = AvARRAY(PL_comppad_name);
sv_setpv(sv, name);
if (PL_in_my_stash) {
if (*name != '$')
- croak("Can't declare class for non-scalar %s in \"my\"",name);
+ yyerror(form("Can't declare class for non-scalar %s in \"my\"",
+ name));
SvOBJECT_on(sv);
(void)SvUPGRADE(sv, SVt_PVMG);
SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
return off;
}
+#define FINDLEX_NOSEARCH 1 /* don't search outer contexts */
+
STATIC PADOFFSET
-pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix, I32 saweval)
+pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix, I32 saweval,
+ U32 flags)
{
dTHR;
CV *cv;
}
}
+ if (flags & FINDLEX_NOSEARCH)
+ return 0;
+
/* Nothing in current lexical context--try eval's context, if any.
* This is necessary to let the perldb get at lexically scoped variables.
* XXX This will also probably interact badly with eval tree caching.
default:
if (i == 0 && saweval) {
seq = cxstack[saweval].blk_oldcop->cop_seq;
- return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval);
+ return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval, 0);
}
break;
case CXt_EVAL:
continue;
}
seq = cxstack[saweval].blk_oldcop->cop_seq;
- return pad_findlex(name, newoff, seq, cv, i-1, saweval);
+ return pad_findlex(name, newoff, seq, cv, i-1, saweval,FINDLEX_NOSEARCH);
}
}
/* Check if if we're compiling an eval'', and adjust seq to be the
* eval's seq number. This depends on eval'' having a non-null
* CvOUTSIDE() while it is being compiled. The eval'' itself is
- * identified by CvUNIQUE being set and CvGV being null. */
- if (outside && CvUNIQUE(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
+ * identified by CvEVAL being true and CvGV being null. */
+ if (outside && CvEVAL(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
cx = &cxstack[cxstack_ix];
if (CxREALEVAL(cx))
seq = cx->blk_oldcop->cop_seq;
}
/* See if it's in a nested scope */
- off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0);
+ off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0, 0);
if (off) {
/* If there is a pending local definition, this new alias must die */
if (pendoff)
#ifdef USE_THREADS
/* find_threadsv is not reentrant */
PADOFFSET
-find_threadsv(char *name)
+find_threadsv(const char *name)
{
dTHR;
char *p;
if (!p)
return NOT_IN_PAD;
key = p - PL_threadsv_names;
+ MUTEX_LOCK(&thr->mutex);
svp = av_fetch(thr->threadsv, key, FALSE);
- if (!svp) {
+ if (svp)
+ MUTEX_UNLOCK(&thr->mutex);
+ else {
SV *sv = NEWSV(0, 0);
av_store(thr->threadsv, key, sv);
thr->threadsvp = AvARRAY(thr->threadsv);
+ MUTEX_UNLOCK(&thr->mutex);
/*
* Some magic variables used to be automagically initialised
* in gv_fetchpv. Those which are now per-thread magicals get
case '`':
case '\'':
PL_sawampersand = TRUE;
+ /* FALL THROUGH */
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
SvREADONLY_on(sv);
/* FALL THROUGH */
if (o->op_targ > 0)
pad_free(o->op_targ);
+#ifdef PL_OP_SLAB_ALLOC
+ if ((char *) o == PL_OpPtr)
+ {
+ }
+#else
Safefree(o);
+#endif
}
STATIC void
OP *kid;
char* useless = 0;
SV* sv;
+ U8 want;
+
+ if (o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE ||
+ (o->op_type == OP_NULL &&
+ (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)))
+ {
+ dTHR;
+ PL_curcop = (COP*)o; /* for warning below */
+ }
/* assumes no premature commitment */
- if (!o || (o->op_flags & OPf_WANT) == OPf_WANT_LIST || PL_error_count
+ want = o->op_flags & OPf_WANT;
+ if ((want && want != OPf_WANT_SCALAR) || PL_error_count
|| o->op_type == OP_RETURN)
return o;
useless = "a variable";
break;
- case OP_NEXTSTATE:
- case OP_DBSTATE:
- WITH_THR(PL_curcop = ((COP*)o)); /* for warning below */
- break;
-
case OP_CONST:
sv = cSVOPo->op_sv;
- {
+ if (cSVOPo->op_private & OPpCONST_STRICT)
+ no_bareword_allowed(o);
+ else {
dTHR;
if (ckWARN(WARN_VOID)) {
useless = "a constant";
break;
case OP_NULL:
- if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
- WITH_THR(PL_curcop = ((COP*)o)); /* for warning below */
if (o->op_flags & OPf_STACKED)
break;
/* FALL THROUGH */
+ case OP_NEXTSTATE:
+ case OP_DBSTATE:
case OP_ENTERTRY:
case OP_ENTER:
case OP_SCALAR:
dTHR;
OP *kid;
SV *sv;
+ STRLEN n_a;
if (!o || PL_error_count)
return o;
case OP_AV2ARYLEN:
PL_hints |= HINT_BLOCK_SCOPE;
case OP_SASSIGN:
+ case OP_ANDASSIGN:
+ case OP_ORASSIGN:
case OP_AELEMFAST:
PL_modcount++;
break;
PL_modcount++;
if (!type)
croak("Can't localize lexical variable %s",
- SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), PL_na));
+ SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a));
break;
#ifdef USE_THREADS
case OP_READ:
case OP_SYSREAD:
case OP_RECV:
- case OP_ANDASSIGN: /* may work later */
- case OP_ORASSIGN: /* may work later */
+ case OP_ANDASSIGN:
+ case OP_ORASSIGN:
return TRUE;
default:
return FALSE;
}
}
+STATIC bool
+is_handle_constructor(OP *o, I32 argnum)
+{
+ switch (o->op_type) {
+ case OP_PIPE_OP:
+ case OP_SOCKPAIR:
+ if (argnum == 2)
+ return TRUE;
+ /* FALL THROUGH */
+ case OP_SYSOPEN:
+ case OP_OPEN:
+ case OP_SELECT: /* XXX c.f. SelectSaver.pm */
+ case OP_SOCKET:
+ case OP_OPEN_DIR:
+ case OP_ACCEPT:
+ if (argnum == 1)
+ return TRUE;
+ /* FALL THROUGH */
+ default:
+ return FALSE;
+ }
+}
+
OP *
refkids(OP *o, I32 type)
{
ref(kid, type);
break;
case OP_RV2SV:
+ if (type == OP_DEFINED)
+ o->op_flags |= OPf_SPECIAL; /* don't create GV */
ref(cUNOPo->op_first, o->op_type);
/* FALL THROUGH */
case OP_PADSV:
o->op_flags |= OPf_REF;
/* FALL THROUGH */
case OP_RV2GV:
+ if (type == OP_DEFINED)
+ o->op_flags |= OPf_SPECIAL; /* don't create GV */
ref(cUNOPo->op_first, o->op_type);
break;
{
dTHR;
if (PL_in_eval) {
- PL_eval_root = newUNOP(OP_LEAVEEVAL, ((PL_in_eval & 4) ? OPf_SPECIAL : 0), o);
+ if (PL_eval_root)
+ return;
+ PL_eval_root = newUNOP(OP_LEAVEEVAL,
+ ((PL_in_eval & EVAL_KEEPERR)
+ ? OPf_SPECIAL : 0), o);
PL_eval_start = linklist(PL_eval_root);
PL_eval_root->op_next = 0;
peep(PL_eval_start);
char *s;
for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
if (*s == ';' || *s == '=')
- warner(WARN_PARENTHESIS, "Parens missing around \"%s\" list",
+ warner(WARN_PARENTHESIS, "Parentheses missing around \"%s\" list",
lex ? "my" : "local");
}
}
goto nope;
switch (type) {
+ case OP_NEGATE:
+ /* XXX might want a ck_negate() for this */
+ cUNOPo->op_first->op_private &= ~OPpCONST_STRICT;
+ break;
case OP_SPRINTF:
case OP_UCFIRST:
case OP_LCFIRST:
for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) {
if (curop->op_type != OP_CONST &&
- curop->op_type != OP_LIST &&
- curop->op_type != OP_SCALAR &&
- curop->op_type != OP_NULL &&
- curop->op_type != OP_PUSHMARK) {
+ curop->op_type != OP_LIST &&
+ curop->op_type != OP_SCALAR &&
+ curop->op_type != OP_NULL &&
+ curop->op_type != OP_PUSHMARK)
+ {
goto nope;
}
}
first->op_children += last->op_children;
if (first->op_children)
first->op_flags |= OPf_KIDS;
-
- Safefree(last);
+
+#ifdef PL_OP_SLAB_ALLOC
+#else
+ Safefree(last);
+#endif
return (OP*)first;
}
{
LISTOP *listop;
- Newz(1101, listop, 1, LISTOP);
+ NewOp(1101, listop, 1, LISTOP);
listop->op_type = type;
listop->op_ppaddr = PL_ppaddr[type];
newOP(I32 type, I32 flags)
{
OP *o;
- Newz(1101, o, 1, OP);
+ NewOp(1101, o, 1, OP);
o->op_type = type;
o->op_ppaddr = PL_ppaddr[type];
o->op_flags = flags;
if (PL_opargs[type] & OA_MARK)
first = force_list(first);
- Newz(1101, unop, 1, UNOP);
+ NewOp(1101, unop, 1, UNOP);
unop->op_type = type;
unop->op_ppaddr = PL_ppaddr[type];
unop->op_first = first;
newBINOP(I32 type, I32 flags, OP *first, OP *last)
{
BINOP *binop;
- Newz(1101, binop, 1, BINOP);
+ NewOp(1101, binop, 1, BINOP);
if (!first)
first = newOP(OP_NULL, 0);
squash = o->op_private & OPpTRANS_SQUASH;
if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
- SV* listsv = newSVpv("# comment\n",0);
+ SV* listsv = newSVpvn("# comment\n",10);
SV* transv = 0;
U8* tend = t + tlen;
U8* rend = r + rlen;
UV nextmin = 0;
New(1109, cp, tlen, U8*);
i = 0;
- transv = newSVpv("",0);
+ transv = newSVpvn("",0);
while (t < tend) {
cp[i++] = t;
t += UTF8SKIP(t);
dTHR;
PMOP *pmop;
- Newz(1101, pmop, 1, PMOP);
+ NewOp(1101, pmop, 1, PMOP);
pmop->op_type = type;
pmop->op_ppaddr = PL_ppaddr[type];
pmop->op_flags = flags;
? OP_REGCRESET
: OP_REGCMAYBE),0,expr);
- Newz(1101, rcop, 1, LOGOP);
+ NewOp(1101, rcop, 1, LOGOP);
rcop->op_type = OP_REGCOMP;
rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP];
rcop->op_first = scalar(expr);
if (repl) {
OP *curop;
- if (pm->op_pmflags & PMf_EVAL)
+ if (pm->op_pmflags & PMf_EVAL) {
curop = 0;
+ if (PL_curcop->cop_line < PL_multi_end)
+ PL_curcop->cop_line = PL_multi_end;
+ }
#ifdef USE_THREADS
else if (repl->op_type == OP_THREADSV
&& strchr("&`'123456789+",
pm->op_pmflags |= PMf_MAYBE_CONST;
pm->op_pmpermflags |= PMf_MAYBE_CONST;
}
- Newz(1101, rcop, 1, LOGOP);
+ NewOp(1101, rcop, 1, LOGOP);
rcop->op_type = OP_SUBSTCONT;
rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT];
rcop->op_first = scalar(repl);
newSVOP(I32 type, I32 flags, SV *sv)
{
SVOP *svop;
- Newz(1101, svop, 1, SVOP);
+ NewOp(1101, svop, 1, SVOP);
svop->op_type = type;
svop->op_ppaddr = PL_ppaddr[type];
svop->op_sv = sv;
{
dTHR;
GVOP *gvop;
- Newz(1101, gvop, 1, GVOP);
+ NewOp(1101, gvop, 1, GVOP);
gvop->op_type = type;
gvop->op_ppaddr = PL_ppaddr[type];
gvop->op_gv = (GV*)SvREFCNT_inc(gv);
newPVOP(I32 type, I32 flags, char *pv)
{
PVOP *pvop;
- Newz(1101, pvop, 1, PVOP);
+ NewOp(1101, pvop, 1, PVOP);
pvop->op_type = type;
pvop->op_ppaddr = PL_ppaddr[type];
pvop->op_pv = pv;
sv_setpv(PL_curstname,"<none>");
PL_curstash = Nullhv;
}
+ PL_hints |= HINT_BLOCK_SCOPE;
PL_copline = NOLINE;
PL_expect = XSTATE;
}
pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
/* Fake up a method call to VERSION */
- meth = newSVOP(OP_CONST, 0, newSVpv("VERSION", 7));
+ meth = newSVOP(OP_CONST, 0, newSVpvn("VERSION", 7));
veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
append_elem(OP_LIST,
prepend_elem(OP_LIST, pack, list(version)),
pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv));
meth = newSVOP(OP_CONST, 0,
aver
- ? newSVpv("import", 6)
- : newSVpv("unimport", 8)
+ ? newSVpvn("import", 6)
+ : newSVpvn("unimport", 8)
);
imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
append_elem(OP_LIST,
/* Fake up the BEGIN {}, which does its thing immediately. */
newSUB(floor,
- newSVOP(OP_CONST, 0, newSVpv("BEGIN", 5)),
+ newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
Nullop,
append_elem(OP_LINESEQ,
append_elem(OP_LINESEQ,
U32 seq = intro_my();
register COP *cop;
- Newz(1101, cop, 1, COP);
+ NewOp(1101, cop, 1, COP);
if (PERLDB_LINE && PL_curcop->cop_line && PL_curstash != PL_debstash) {
cop->op_type = OP_DBSTATE;
cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ];
if (type == OP_ANDASSIGN || type == OP_ORASSIGN)
other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */
- Newz(1101, logop, 1, LOGOP);
+ NewOp(1101, logop, 1, LOGOP);
logop->op_type = type;
logop->op_ppaddr = PL_ppaddr[type];
list(trueop);
scalar(falseop);
}
- Newz(1101, condop, 1, CONDOP);
+ NewOp(1101, condop, 1, CONDOP);
condop->op_type = OP_COND_EXPR;
condop->op_ppaddr = PL_ppaddr[OP_COND_EXPR];
OP *flop;
OP *o;
- Newz(1101, condop, 1, CONDOP);
+ NewOp(1101, condop, 1, CONDOP);
condop->op_type = OP_RANGE;
condop->op_ppaddr = PL_ppaddr[OP_RANGE];
o = listop;
if (!loop) {
- Newz(1101,loop,1,LOOP);
+ NewOp(1101,loop,1,LOOP);
loop->op_type = OP_ENTERLOOP;
loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP];
loop->op_private = 0;
newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont)
{
LOOP *loop;
+ LOOP *tmp;
OP *wop;
int padoff = 0;
I32 iterflags = 0;
loop = (LOOP*)list(convert(OP_ENTERITER, iterflags,
append_elem(OP_LIST, expr, scalar(sv))));
assert(!loop->op_next);
+#ifdef PL_OP_SLAB_ALLOC
+ NewOp(1234,tmp,1,LOOP);
+ Copy(loop,tmp,1,LOOP);
+ loop = tmp;
+#else
Renew(loop, 1, LOOP);
+#endif
loop->op_targ = padoff;
wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont);
PL_copline = forline;
{
dTHR;
OP *o;
+ STRLEN n_a;
+
if (type != OP_GOTO || label->op_type == OP_CONST) {
/* "last()" means "last" */
if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS))
o = newOP(type, OPf_SPECIAL);
else {
o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
- ? SvPVx(((SVOP*)label)->op_sv, PL_na)
+ ? SvPVx(((SVOP*)label)->op_sv, n_a)
: ""));
}
op_free(label);
char *name = SvPVX(namesv); /* XXX */
if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */
I32 off = pad_findlex(name, ix, SvIVX(namesv),
- CvOUTSIDE(cv), cxstack_ix, 0);
+ CvOUTSIDE(cv), cxstack_ix, 0, 0);
if (!off)
PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
else if (off != ix)
CV *
cv_clone(CV *proto)
{
- return cv_clone2(proto, CvOUTSIDE(proto));
+ CV *cv;
+ MUTEX_LOCK(&PL_cred_mutex); /* XXX create separate mutex */
+ cv = cv_clone2(proto, CvOUTSIDE(proto));
+ MUTEX_UNLOCK(&PL_cred_mutex); /* XXX create separate mutex */
+ return cv;
}
void
newSUB(I32 floor, OP *o, OP *proto, OP *block)
{
dTHR;
- char *name = o ? SvPVx(cSVOPo->op_sv, PL_na) : Nullch;
+ STRLEN n_a;
+ char *name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
GV *gv = gv_fetchpv(name ? name : "__ANON__",
GV_ADDMULTI | (block ? 0 : GV_NOINIT), SVt_PVCV);
- char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, PL_na) : Nullch;
+ char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch;
register CV *cv=0;
I32 ix;
if (strEQ(s, "BEGIN")) {
char *not_safe =
"BEGIN not safe after errors--compilation aborted";
- if (PL_in_eval & 4)
+ if (PL_in_eval & EVAL_KEEPERR)
croak(not_safe);
else {
/* force display of errors found but not reported */
sv_catpv(ERRSV, not_safe);
- croak("%s", SvPVx(ERRSV, PL_na));
+ croak("%s", SvPVx(ERRSV, n_a));
}
}
}
return cv;
}
+/* XXX unsafe for threads if eval_owner isn't held */
void
newCONSTSUB(HV *stash, char *name, SV *sv)
{
char *name;
GV *gv;
I32 ix;
+ STRLEN n_a;
if (o)
- name = SvPVx(cSVOPo->op_sv, PL_na);
+ name = SvPVx(cSVOPo->op_sv, n_a);
else
name = "STDOUT";
gv = gv_fetchpv(name,TRUE, SVt_PVFM);
OP *
newGVREF(I32 type, OP *o)
{
- if (type == OP_MAPSTART)
+ if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
return newUNOP(OP_NULL, 0, o);
return ref(newUNOP(OP_RV2GV, OPf_REF, o), type);
}
cUNOPo->op_first = 0;
op_free(o);
- Newz(1101, enter, 1, LOGOP);
+ NewOp(1101, enter, 1, LOGOP);
enter->op_type = OP_ENTERTRY;
enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY];
enter->op_private = 0;
int iscv;
GV *gv;
SV *kidsv = kid->op_sv;
+ STRLEN n_a;
/* Is it a constant from cv_const_sv()? */
if (SvROK(kidsv) && SvREADONLY(kidsv)) {
croak("Constant is not %s reference", badtype);
return o;
}
- name = SvPV(kidsv, PL_na);
+ name = SvPV(kidsv, n_a);
if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) {
char *badthing = Nullch;
switch (o->op_type) {
SVOP *kid = (SVOP*)cUNOPo->op_first;
if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
+ STRLEN n_a;
OP *newop = newGVOP(type, OPf_REF,
- gv_fetchpv(SvPVx(kid->op_sv, PL_na), TRUE, SVt_PVIO));
+ gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO));
op_free(o);
return newop;
}
}
if (o->op_flags & OPf_KIDS) {
+ STRLEN n_a;
tokid = &cLISTOPo->op_first;
kid = cLISTOPo->op_first;
if (kid->op_type == OP_PUSHMARK ||
sibl = kid->op_sibling;
switch (oa & 7) {
case OA_SCALAR:
+ /* list seen where single (scalar) arg expected? */
+ if (numargs == 1 && !(oa >> 4)
+ && kid->op_type == OP_LIST && type != OP_SCALAR)
+ {
+ return too_many_arguments(o,PL_op_desc[type]);
+ }
scalar(kid);
break;
case OA_LIST:
break;
case OA_AVREF:
if (kid->op_type == OP_CONST &&
- (kid->op_private & OPpCONST_BARE)) {
- char *name = SvPVx(((SVOP*)kid)->op_sv, PL_na);
+ (kid->op_private & OPpCONST_BARE))
+ {
+ char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
OP *newop = newAVREF(newGVOP(OP_GV, 0,
gv_fetchpv(name, TRUE, SVt_PVAV) ));
if (ckWARN(WARN_SYNTAX))
*tokid = kid;
}
else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV)
- bad_type(numargs, "array", PL_op_desc[o->op_type], kid);
+ bad_type(numargs, "array", PL_op_desc[type], kid);
mod(kid, type);
break;
case OA_HVREF:
if (kid->op_type == OP_CONST &&
- (kid->op_private & OPpCONST_BARE)) {
- char *name = SvPVx(((SVOP*)kid)->op_sv, PL_na);
+ (kid->op_private & OPpCONST_BARE))
+ {
+ char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
OP *newop = newHVREF(newGVOP(OP_GV, 0,
gv_fetchpv(name, TRUE, SVt_PVHV) ));
if (ckWARN(WARN_SYNTAX))
*tokid = kid;
}
else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV)
- bad_type(numargs, "hash", PL_op_desc[o->op_type], kid);
+ bad_type(numargs, "hash", PL_op_desc[type], kid);
mod(kid, type);
break;
case OA_CVREF:
case OA_FILEREF:
if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) {
if (kid->op_type == OP_CONST &&
- (kid->op_private & OPpCONST_BARE)) {
+ (kid->op_private & OPpCONST_BARE))
+ {
OP *newop = newGVOP(OP_GV, 0,
- gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, PL_na), TRUE,
+ gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE,
SVt_PVIO) );
op_free(kid);
kid = newop;
bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid);
}
else {
+ I32 flags = OPf_SPECIAL;
+ I32 priv = 0;
+ /* is this op a FH constructor? */
+ if (is_handle_constructor(o,numargs)) {
+ flags = 0;
+ /* Set a flag to tell rv2gv to vivify
+ * need to "prove" flag does not mean something
+ * else already - NI-S 1999/05/07
+ */
+ priv = OPpDEREF;
+#if 0
+ /* Helps with open($array[$n],...)
+ but is too simplistic - need to do selectively
+ */
+ mod(kid,type);
+#endif
+ }
kid->op_sibling = 0;
- kid = newUNOP(OP_RV2GV, 0, scalar(kid));
+ kid = newUNOP(OP_RV2GV, flags, scalar(kid));
+ if (priv) {
+ kid->op_private |= priv;
+ }
}
kid->op_sibling = sibl;
*tokid = kid;
gv = gv_fetchpv("CORE::GLOBAL::glob", FALSE, SVt_PVCV);
if (gv && GvIMPORTED_CV(gv)) {
- static int glob_index;
-
append_elem(OP_GLOB, o,
- newSVOP(OP_CONST, 0, newSViv(glob_index++)));
+ newSVOP(OP_CONST, 0, newSViv(PL_glob_index++)));
o->op_type = OP_LIST;
o->op_ppaddr = PL_ppaddr[OP_LIST];
cLISTOPo->op_first->op_type = OP_PUSHMARK;
OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
- Newz(1101, gwop, 1, LOGOP);
+ NewOp(1101, gwop, 1, LOGOP);
if (o->op_flags & OPf_STACKED) {
OP* k;
}
OP *
+ck_defined(OP *o) /* 19990527 MJD */
+{
+ if (ckWARN(WARN_DEPRECATED)) {
+ switch (cUNOPo->op_first->op_type) {
+ case OP_RV2AV:
+ case OP_PADAV:
+ case OP_AASSIGN: /* Is this a good idea? */
+ warner(WARN_DEPRECATED, "defined(@array) is deprecated (and not really meaningful)");
+ warner(WARN_DEPRECATED, "(Maybe you should just omit the defined()?)\n");
+ break;
+ case OP_RV2HV:
+ case OP_PADHV:
+ warner(WARN_DEPRECATED, "defined(%hash) is deprecated (and not really meaningful)");
+ warner(WARN_DEPRECATED, "(Maybe you should just omit the defined()?)\n");
+ break;
+ default:
+ /* no warning */
+ break;
+ }
+ }
+ return ck_rfun(o);
+}
+
+OP *
ck_rfun(OP *o)
{
OPCODE type = o->op_type;
o->op_private |= OPpLOCALE;
#endif
- if (o->op_flags & OPf_STACKED) {
+ if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED)
+ simplify_sort(o);
+ if (o->op_flags & OPf_STACKED) { /* may have been cleared */
OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
OP *k;
- kid = kUNOP->op_first; /* get past rv2gv */
+ kid = kUNOP->op_first; /* get past null */
if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) {
linklist(kid);
peep(k);
kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
- null(kid); /* wipe out rv2gv */
if (o->op_type == OP_SORT)
kid->op_next = kid;
else
return o;
}
+STATIC void
+simplify_sort(OP *o)
+{
+ dTHR;
+ register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */
+ OP *k;
+ int reversed;
+ if (!(o->op_flags & OPf_STACKED))
+ return;
+ GvMULTI_on(gv_fetchpv("a", TRUE, SVt_PV));
+ GvMULTI_on(gv_fetchpv("b", TRUE, SVt_PV));
+ kid = kUNOP->op_first; /* get past null */
+ if (kid->op_type != OP_SCOPE)
+ return;
+ kid = kLISTOP->op_last; /* get past scope */
+ switch(kid->op_type) {
+ case OP_NCMP:
+ case OP_I_NCMP:
+ case OP_SCMP:
+ break;
+ default:
+ return;
+ }
+ k = kid; /* remember this node*/
+ if (kBINOP->op_first->op_type != OP_RV2SV)
+ return;
+ kid = kBINOP->op_first; /* get past cmp */
+ if (kUNOP->op_first->op_type != OP_GV)
+ return;
+ kid = kUNOP->op_first; /* get past rv2sv */
+ if (GvSTASH(kGVOP->op_gv) != PL_curstash)
+ return;
+ if (strEQ(GvNAME(kGVOP->op_gv), "a"))
+ reversed = 0;
+ else if(strEQ(GvNAME(kGVOP->op_gv), "b"))
+ reversed = 1;
+ else
+ return;
+ kid = k; /* back to cmp */
+ if (kBINOP->op_last->op_type != OP_RV2SV)
+ return;
+ kid = kBINOP->op_last; /* down to 2nd arg */
+ if (kUNOP->op_first->op_type != OP_GV)
+ return;
+ kid = kUNOP->op_first; /* get past rv2sv */
+ if (GvSTASH(kGVOP->op_gv) != PL_curstash
+ || ( reversed
+ ? strNE(GvNAME(kGVOP->op_gv), "a")
+ : strNE(GvNAME(kGVOP->op_gv), "b")))
+ return;
+ o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL);
+ if (reversed)
+ o->op_private |= OPpSORT_REVERSE;
+ if (k->op_type == OP_NCMP)
+ o->op_private |= OPpSORT_NUMERIC;
+ if (k->op_type == OP_I_NCMP)
+ o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER;
+ op_free(cLISTOPo->op_first->op_sibling); /* delete comparison block */
+ cLISTOPo->op_first->op_sibling = cLISTOPo->op_last;
+ cLISTOPo->op_children = 1;
+}
+
OP *
ck_split(OP *o)
{
op_free(cLISTOPo->op_first);
cLISTOPo->op_first = kid;
if (!kid) {
- cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpv(" ", 1));
+ cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvn(" ", 1));
cLISTOPo->op_last = kid; /* There was only one element previously */
}
GV *namegv = 0;
int optional = 0;
I32 arg = 0;
+ STRLEN n_a;
for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ;
if (cvop->op_type == OP_RV2CV) {
cv = GvCVu(tmpop->op_sv);
if (cv && SvPOK(cv) && !(o->op_private & OPpENTERSUB_AMPER)) {
namegv = CvANON(cv) ? (GV*)tmpop->op_sv : CvGV(cv);
- proto = SvPV((SV*)cv, PL_na);
+ proto = SvPV((SV*)cv, n_a);
}
}
}
+ else if (cvop->op_type == OP_METHOD) {
+ if (o2->op_type == OP_CONST)
+ o2->op_private &= ~OPpCONST_STRICT;
+ }
o->op_private |= (PL_hints & HINT_STRICT_REFS);
if (PERLDB_SUB && PL_curstash != PL_debstash)
o->op_private |= OPpENTERSUB_DB;
bad_type(arg, "block", gv_ename(namegv), o2);
break;
case '*':
+ /* '*' allows any scalar type, including bareword */
proto++;
arg++;
if (o2->op_type == OP_RV2GV)
- goto wrapref;
- {
- OP* kid = o2;
- OP* sib = kid->op_sibling;
- kid->op_sibling = 0;
- o2 = newUNOP(OP_RV2GV, 0, kid);
- o2->op_sibling = sib;
- prev->op_sibling = o2;
+ goto wrapref; /* autoconvert GLOB -> GLOBref */
+ else if (o2->op_type == OP_CONST)
+ o2->op_private &= ~OPpCONST_STRICT;
+ else if (o2->op_type == OP_ENTERSUB) {
+ /* accidental subroutine, revert to bareword */
+ OP *gvop = ((UNOP*)o2)->op_first;
+ if (gvop && gvop->op_type == OP_NULL) {
+ gvop = ((UNOP*)gvop)->op_first;
+ if (gvop) {
+ for (; gvop->op_sibling; gvop = gvop->op_sibling)
+ ;
+ if (gvop &&
+ (gvop->op_private & OPpENTERSUB_NOPAREN) &&
+ (gvop = ((UNOP*)gvop)->op_first) &&
+ gvop->op_type == OP_GV)
+ {
+ GV *gv = (GV*)((SVOP*)gvop)->op_sv;
+ OP *sibling = o2->op_sibling;
+ op_free(o2);
+ o2 = newSVOP(OP_CONST, 0,
+ newSVpvn(GvNAME(gv),
+ GvNAMELEN(gv)));
+ prev->op_sibling = o2;
+ o2->op_sibling = sibling;
+ }
+ }
+ }
}
- goto wrapref;
+ scalar(o2);
+ break;
case '\\':
proto++;
arg++;
default:
oops:
croak("Malformed prototype for %s: %s",
- gv_ename(namegv), SvPV((SV*)cv, PL_na));
+ gv_ename(namegv), SvPV((SV*)cv, n_a));
}
}
else
{
dTHR;
register OP* oldop = 0;
+ STRLEN n_a;
+
if (!o || o->op_seq)
return;
ENTER;
o->op_seq = PL_op_seqmax++;
break;
- case OP_CONCAT:
case OP_CONST:
+ if (cSVOPo->op_private & OPpCONST_STRICT)
+ no_bareword_allowed(o);
+ /* FALL THROUGH */
+ case OP_CONCAT:
case OP_JOIN:
case OP_UC:
case OP_UCFIRST:
char *key;
STRLEN keylen;
- if (o->op_private & (OPpDEREF_HV|OPpDEREF_AV|OPpLVAL_INTRO)
+ if ((o->op_private & (OPpLVAL_INTRO))
|| ((BINOP*)o)->op_last->op_type != OP_CONST)
break;
rop = (UNOP*)((BINOP*)o)->op_first;
indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE);
if (!indsvp) {
croak("No such field \"%s\" in variable %s of type %s",
- key, SvPV(lexname, PL_na), HvNAME(SvSTASH(lexname)));
+ key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname)));
}
ind = SvIV(*indsvp);
if (ind < 1)