1N/A/* pp.h
1N/A *
1N/A * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999,
1N/A * 2000, 2001, by Larry Wall and others
1N/A *
1N/A * You may distribute under the terms of either the GNU General Public
1N/A * License or the Artistic License, as specified in the README file.
1N/A *
1N/A */
1N/A
1N/A#ifdef USE_5005THREADS
1N/A#define ARGS thr
1N/A#define dARGS struct perl_thread *thr;
1N/A#else
1N/A#define ARGS
1N/A#define dARGS
1N/A#endif /* USE_5005THREADS */
1N/A
1N/A#define PP(s) OP * Perl_##s(pTHX)
1N/A
1N/A/*
1N/A=head1 Stack Manipulation Macros
1N/A
1N/A=for apidoc AmU||SP
1N/AStack pointer. This is usually handled by C<xsubpp>. See C<dSP> and
1N/AC<SPAGAIN>.
1N/A
1N/A=for apidoc AmU||MARK
1N/AStack marker variable for the XSUB. See C<dMARK>.
1N/A
1N/A=for apidoc Ams||PUSHMARK
1N/AOpening bracket for arguments on a callback. See C<PUTBACK> and
1N/AL<perlcall>.
1N/A
1N/A=for apidoc Ams||dSP
1N/ADeclares a local copy of perl's stack pointer for the XSUB, available via
1N/Athe C<SP> macro. See C<SP>.
1N/A
1N/A=for apidoc ms||djSP
1N/A
1N/ADeclare Just C<SP>. This is actually identical to C<dSP>, and declares
1N/Aa local copy of perl's stack pointer, available via the C<SP> macro.
1N/ASee C<SP>. (Available for backward source code compatibility with the
1N/Aold (Perl 5.005) thread model.)
1N/A
1N/A=for apidoc Ams||dMARK
1N/ADeclare a stack marker variable, C<mark>, for the XSUB. See C<MARK> and
1N/AC<dORIGMARK>.
1N/A
1N/A=for apidoc Ams||dORIGMARK
1N/ASaves the original stack mark for the XSUB. See C<ORIGMARK>.
1N/A
1N/A=for apidoc AmU||ORIGMARK
1N/AThe original stack mark for the XSUB. See C<dORIGMARK>.
1N/A
1N/A=for apidoc Ams||SPAGAIN
1N/ARefetch the stack pointer. Used after a callback. See L<perlcall>.
1N/A
1N/A=cut */
1N/A
1N/A#undef SP /* Solaris 2.7 i386 has this in /usr/include/sys/reg.h */
1N/A#define SP sp
1N/A#define MARK mark
1N/A#define TARG targ
1N/A
1N/A#define PUSHMARK(p) if (++PL_markstack_ptr == PL_markstack_max) \
1N/A markstack_grow(); \
1N/A *PL_markstack_ptr = (p) - PL_stack_base
1N/A
1N/A#define TOPMARK (*PL_markstack_ptr)
1N/A#define POPMARK (*PL_markstack_ptr--)
1N/A
1N/A#define dSP register SV **sp = PL_stack_sp
1N/A#define djSP dSP
1N/A#define dMARK register SV **mark = PL_stack_base + POPMARK
1N/A#define dORIGMARK I32 origmark = mark - PL_stack_base
1N/A#define SETORIGMARK origmark = mark - PL_stack_base
1N/A#define ORIGMARK (PL_stack_base + origmark)
1N/A
1N/A#define SPAGAIN sp = PL_stack_sp
1N/A#define MSPAGAIN sp = PL_stack_sp; mark = ORIGMARK
1N/A
1N/A#define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
1N/A#define dTARGETSTACKED SV * GETTARGETSTACKED
1N/A
1N/A#define GETTARGET targ = PAD_SV(PL_op->op_targ)
1N/A#define dTARGET SV * GETTARGET
1N/A
1N/A#define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
1N/A#define dATARGET SV * GETATARGET
1N/A
1N/A#define dTARG SV *targ
1N/A
1N/A#define NORMAL PL_op->op_next
1N/A#define DIE return Perl_die
1N/A
1N/A/*
1N/A=for apidoc Ams||PUTBACK
1N/AClosing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
1N/ASee C<PUSHMARK> and L<perlcall> for other uses.
1N/A
1N/A=for apidoc Amn|SV*|POPs
1N/APops an SV off the stack.
1N/A
1N/A=for apidoc Amn|char*|POPp
1N/APops a string off the stack. Deprecated. New code should provide
1N/Aa STRLEN n_a and use POPpx.
1N/A
1N/A=for apidoc Amn|char*|POPpx
1N/APops a string off the stack.
1N/ARequires a variable STRLEN n_a in scope.
1N/A
1N/A=for apidoc Amn|char*|POPpbytex
1N/APops a string off the stack which must consist of bytes i.e. characters < 256.
1N/ARequires a variable STRLEN n_a in scope.
1N/A
1N/A=for apidoc Amn|NV|POPn
1N/APops a double off the stack.
1N/A
1N/A=for apidoc Amn|IV|POPi
1N/APops an integer off the stack.
1N/A
1N/A=for apidoc Amn|long|POPl
1N/APops a long off the stack.
1N/A
1N/A=cut
1N/A*/
1N/A
1N/A#define PUTBACK PL_stack_sp = sp
1N/A#define RETURN return PUTBACK, NORMAL
1N/A#define RETURNOP(o) return PUTBACK, o
1N/A#define RETURNX(x) return x, PUTBACK, NORMAL
1N/A
1N/A#define POPs (*sp--)
1N/A#define POPp (SvPVx(POPs, PL_na)) /* deprecated */
1N/A#define POPpx (SvPVx(POPs, n_a))
1N/A#define POPpbytex (SvPVbytex(POPs, n_a))
1N/A#define POPn (SvNVx(POPs))
1N/A#define POPi ((IV)SvIVx(POPs))
1N/A#define POPu ((UV)SvUVx(POPs))
1N/A#define POPl ((long)SvIVx(POPs))
1N/A#define POPul ((unsigned long)SvIVx(POPs))
1N/A#ifdef HAS_QUAD
1N/A#define POPq ((Quad_t)SvIVx(POPs))
1N/A#define POPuq ((Uquad_t)SvUVx(POPs))
1N/A#endif
1N/A
1N/A#define TOPs (*sp)
1N/A#define TOPm1s (*(sp-1))
1N/A#define TOPp1s (*(sp+1))
1N/A#define TOPp (SvPV(TOPs, PL_na)) /* deprecated */
1N/A#define TOPpx (SvPV(TOPs, n_a))
1N/A#define TOPn (SvNV(TOPs))
1N/A#define TOPi ((IV)SvIV(TOPs))
1N/A#define TOPu ((UV)SvUV(TOPs))
1N/A#define TOPl ((long)SvIV(TOPs))
1N/A#define TOPul ((unsigned long)SvUV(TOPs))
1N/A#ifdef HAS_QUAD
1N/A#define TOPq ((Quad_t)SvIV(TOPs))
1N/A#define TOPuq ((Uquad_t)SvUV(TOPs))
1N/A#endif
1N/A
1N/A/* Go to some pains in the rare event that we must extend the stack. */
1N/A
1N/A/*
1N/A=for apidoc Am|void|EXTEND|SP|int nitems
1N/AUsed to extend the argument stack for an XSUB's return values. Once
1N/Aused, guarantees that there is room for at least C<nitems> to be pushed
1N/Aonto the stack.
1N/A
1N/A=for apidoc Am|void|PUSHs|SV* sv
1N/APush an SV onto the stack. The stack must have room for this element.
1N/ADoes not handle 'set' magic. See C<XPUSHs>.
1N/A
1N/A=for apidoc Am|void|PUSHp|char* str|STRLEN len
1N/APush a string onto the stack. The stack must have room for this element.
1N/AThe C<len> indicates the length of the string. Handles 'set' magic. See
1N/AC<XPUSHp>.
1N/A
1N/A=for apidoc Am|void|PUSHn|NV nv
1N/APush a double onto the stack. The stack must have room for this element.
1N/AHandles 'set' magic. See C<XPUSHn>.
1N/A
1N/A=for apidoc Am|void|PUSHi|IV iv
1N/APush an integer onto the stack. The stack must have room for this element.
1N/AHandles 'set' magic. See C<XPUSHi>.
1N/A
1N/A=for apidoc Am|void|PUSHu|UV uv
1N/APush an unsigned integer onto the stack. The stack must have room for this
1N/Aelement. See C<XPUSHu>.
1N/A
1N/A=for apidoc Am|void|XPUSHs|SV* sv
1N/APush an SV onto the stack, extending the stack if necessary. Does not
1N/Ahandle 'set' magic. See C<PUSHs>.
1N/A
1N/A=for apidoc Am|void|XPUSHp|char* str|STRLEN len
1N/APush a string onto the stack, extending the stack if necessary. The C<len>
1N/Aindicates the length of the string. Handles 'set' magic. See
1N/AC<PUSHp>.
1N/A
1N/A=for apidoc Am|void|XPUSHn|NV nv
1N/APush a double onto the stack, extending the stack if necessary. Handles
1N/A'set' magic. See C<PUSHn>.
1N/A
1N/A=for apidoc Am|void|XPUSHi|IV iv
1N/APush an integer onto the stack, extending the stack if necessary. Handles
1N/A'set' magic. See C<PUSHi>.
1N/A
1N/A=for apidoc Am|void|XPUSHu|UV uv
1N/APush an unsigned integer onto the stack, extending the stack if necessary.
1N/ASee C<PUSHu>.
1N/A
1N/A=cut
1N/A*/
1N/A
1N/A#define EXTEND(p,n) STMT_START { if (PL_stack_max - p < (int)(n)) { \
1N/A sp = stack_grow(sp,p, (int) (n)); \
1N/A } } STMT_END
1N/A
1N/A/* Same thing, but update mark register too. */
1N/A#define MEXTEND(p,n) STMT_START {if (PL_stack_max - p < (int)(n)) { \
1N/A int markoff = mark - PL_stack_base; \
1N/A sp = stack_grow(sp,p,(int) (n)); \
1N/A mark = PL_stack_base + markoff; \
1N/A } } STMT_END
1N/A
1N/A#define PUSHs(s) (*++sp = (s))
1N/A#define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
1N/A#define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
1N/A#define PUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
1N/A#define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
1N/A#define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
1N/A
1N/A#define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
1N/A#define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
1N/A#define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
1N/A#define XPUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
1N/A#define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
1N/A#define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
1N/A#define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
1N/A
1N/A#define SETs(s) (*sp = s)
1N/A#define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
1N/A#define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
1N/A#define SETn(n) STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
1N/A#define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
1N/A#define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
1N/A
1N/A#define dTOPss SV *sv = TOPs
1N/A#define dPOPss SV *sv = POPs
1N/A#define dTOPnv NV value = TOPn
1N/A#define dPOPnv NV value = POPn
1N/A#define dTOPiv IV value = TOPi
1N/A#define dPOPiv IV value = POPi
1N/A#define dTOPuv UV value = TOPu
1N/A#define dPOPuv UV value = POPu
1N/A#ifdef HAS_QUAD
1N/A#define dTOPqv Quad_t value = TOPu
1N/A#define dPOPqv Quad_t value = POPu
1N/A#define dTOPuqv Uquad_t value = TOPuq
1N/A#define dPOPuqv Uquad_t value = POPuq
1N/A#endif
1N/A
1N/A#define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
1N/A#define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n)
1N/A#define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
1N/A
1N/A#define USE_LEFT(sv) \
1N/A (SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED))
1N/A#define dPOPXnnrl_ul(X) \
1N/A NV right = POPn; \
1N/A SV *leftsv = CAT2(X,s); \
1N/A NV left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
1N/A#define dPOPXiirl_ul(X) \
1N/A IV right = POPi; \
1N/A SV *leftsv = CAT2(X,s); \
1N/A IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
1N/A
1N/A#define dPOPPOPssrl dPOPXssrl(POP)
1N/A#define dPOPPOPnnrl dPOPXnnrl(POP)
1N/A#define dPOPPOPnnrl_ul dPOPXnnrl_ul(POP)
1N/A#define dPOPPOPiirl dPOPXiirl(POP)
1N/A#define dPOPPOPiirl_ul dPOPXiirl_ul(POP)
1N/A
1N/A#define dPOPTOPssrl dPOPXssrl(TOP)
1N/A#define dPOPTOPnnrl dPOPXnnrl(TOP)
1N/A#define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP)
1N/A#define dPOPTOPiirl dPOPXiirl(TOP)
1N/A#define dPOPTOPiirl_ul dPOPXiirl_ul(TOP)
1N/A
1N/A#define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
1N/A#define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
1N/A#define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
1N/A
1N/A#define RETSETYES RETURNX(SETs(&PL_sv_yes))
1N/A#define RETSETNO RETURNX(SETs(&PL_sv_no))
1N/A#define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
1N/A
1N/A#define ARGTARG PL_op->op_targ
1N/A
1N/A /* See OPpTARGET_MY: */
1N/A#define MAXARG (PL_op->op_private & 15)
1N/A
1N/A#define SWITCHSTACK(f,t) \
1N/A STMT_START { \
1N/A AvFILLp(f) = sp - PL_stack_base; \
1N/A PL_stack_base = AvARRAY(t); \
1N/A PL_stack_max = PL_stack_base + AvMAX(t); \
1N/A sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \
1N/A PL_curstack = t; \
1N/A } STMT_END
1N/A
1N/A#define EXTEND_MORTAL(n) \
1N/A STMT_START { \
1N/A if (PL_tmps_ix + (n) >= PL_tmps_max) \
1N/A tmps_grow(n); \
1N/A } STMT_END
1N/A
1N/A#define AMGf_noright 1
1N/A#define AMGf_noleft 2
1N/A#define AMGf_assign 4
1N/A#define AMGf_unary 8
1N/A
1N/A#define tryAMAGICbinW(meth,assign,set) STMT_START { \
1N/A if (PL_amagic_generation) { \
1N/A SV* tmpsv; \
1N/A SV* right= *(sp); SV* left= *(sp-1);\
1N/A if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
1N/A (tmpsv=amagic_call(left, \
1N/A right, \
1N/A CAT2(meth,_amg), \
1N/A (assign)? AMGf_assign: 0))) {\
1N/A SPAGAIN; \
1N/A (void)POPs; set(tmpsv); RETURN; } \
1N/A } \
1N/A } STMT_END
1N/A
1N/A#define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
1N/A#define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
1N/A
1N/A#define AMG_CALLun(sv,meth) amagic_call(sv,&PL_sv_undef, \
1N/A CAT2(meth,_amg),AMGf_noright | AMGf_unary)
1N/A#define AMG_CALLbinL(left,right,meth) \
1N/A amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
1N/A
1N/A#define tryAMAGICunW(meth,set,shift,ret) STMT_START { \
1N/A if (PL_amagic_generation) { \
1N/A SV* tmpsv; \
1N/A SV* arg= sp[shift]; \
1N/A if(0) goto am_again; /* shut up unused warning */ \
1N/A am_again: \
1N/A if ((SvAMAGIC(arg))&&\
1N/A (tmpsv=AMG_CALLun(arg,meth))) {\
1N/A SPAGAIN; if (shift) sp += shift; \
1N/A set(tmpsv); ret; } \
1N/A } \
1N/A } STMT_END
1N/A
1N/A#define FORCE_SETs(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END
1N/A
1N/A#define tryAMAGICun(meth) tryAMAGICunW(meth,SETsvUN,0,RETURN)
1N/A#define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs,0,RETURN)
1N/A#define tryAMAGICunTARGET(meth, shift) \
1N/A { dSP; sp--; /* get TARGET from below PL_stack_sp */ \
1N/A { dTARGETSTACKED; \
1N/A { dSP; tryAMAGICunW(meth,FORCE_SETs,shift,RETURN);}}}
1N/A
1N/A#define setAGAIN(ref) sv = ref; \
1N/A if (!SvROK(ref)) \
1N/A Perl_croak(aTHX_ "Overloaded dereference did not return a reference"); \
1N/A if (ref != arg && SvRV(ref) != SvRV(arg)) { \
1N/A arg = ref; \
1N/A goto am_again; \
1N/A }
1N/A
1N/A#define tryAMAGICunDEREF(meth) tryAMAGICunW(meth,setAGAIN,0,(void)0)
1N/A
1N/A#define opASSIGN (PL_op->op_flags & OPf_STACKED)
1N/A#define SETsv(sv) STMT_START { \
1N/A if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY)) \
1N/A { sv_setsv(TARG, (sv)); SETTARG; } \
1N/A else SETs(sv); } STMT_END
1N/A
1N/A#define SETsvUN(sv) STMT_START { \
1N/A if (SvFLAGS(TARG) & SVs_PADMY) \
1N/A { sv_setsv(TARG, (sv)); SETTARG; } \
1N/A else SETs(sv); } STMT_END
1N/A
1N/A/* newSVsv does not behave as advertised, so we copy missing
1N/A * information by hand */
1N/A
1N/A/* SV* ref causes confusion with the member variable
1N/A changed SV* ref to SV* tmpRef */
1N/A#define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv); \
1N/A if (SvREFCNT(tmpRef)>1) { \
1N/A SvRV(rv)=AMG_CALLun(rv,copy); \
1N/A SvREFCNT_dec(tmpRef); \
1N/A } } STMT_END
1N/A
1N/A/*
1N/A=for apidoc mU||LVRET
1N/ATrue if this op will be the return value of an lvalue subroutine
1N/A
1N/A=cut */
1N/A#define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())