This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.0 alpha 2
[perl5.git] / pp.h
CommitLineData
79072805
LW
1/***********************************************************
2 *
3 * $Header: /usr/src/local/lwall/perl5/RCS/pp.h,v 4.1 92/08/07 18:26:20 lwall Exp Locker: lwall $
4 *
5 * Description:
6 * Push/Pop code defs.
7 *
8 * Standards:
9 *
10 * Created:
11 * Mon Jun 15 16:47:20 1992
12 *
13 * Author:
14 * Larry Wall <lwall@netlabs.com>
15 *
16 * $Log: pp.h,v $
17 * Revision 4.1 92/08/07 18:26:20 lwall
18 *
19 *
20 **********************************************************/
21
22#define ARGS
23#define ARGSproto
24#define dARGS
25#define PP(s) OP* s(ARGS) dARGS
26
27#define SP sp
28#define MARK mark
29#define TARG targ
30
31#define POPMARK (*markstack_ptr--)
32#define dSP register SV **sp = stack_sp
33#define dMARK register SV **mark = stack_base + POPMARK
34#define dORIGMARK I32 origmark = mark - stack_base
35#define SETORIGMARK origmark = mark - stack_base
36#define ORIGMARK stack_base + origmark
37
38#define SPAGAIN sp = stack_sp
39#define MSPAGAIN sp = stack_sp; mark = ORIGMARK
40
41#define GETTARGETSTACKED targ = (op->op_flags & OPf_STACKED ? POPs : PAD_SV(op->op_targ))
42#define dTARGETSTACKED SV * GETTARGETSTACKED
43
44#define GETTARGET targ = PAD_SV(op->op_targ)
45#define dTARGET SV * GETTARGET
46
47#define GETATARGET targ = (op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(op->op_targ))
48#define dATARGET SV * GETATARGET
49
50#define dTARG SV *targ
51
52#define GETavn(a,g,st) \
53 a = sv_2av(cGVOP->op_gv ? (SV*)cGVOP->op_gv : POPs, &st, &g, 1)
54#define GEThvn(h,g,st) \
55 h = sv_2hv(cGVOP->op_gv ? (SV*)cGVOP->op_gv : POPs, &st, &g, 1)
56#define GETav(a,g,st) \
57 a = sv_2av(cGVOP->op_gv ? (SV*)cGVOP->op_gv : POPs, &st, &g, 0)
58#define GEThv(h,g,st) \
59 h = sv_2hv(cGVOP->op_gv ? (SV*)cGVOP->op_gv : POPs, &st, &g, 0)
60#define GETcv(r,g,st) \
61 r = sv_2cv(POPs, &st, &g, 0)
62
63#define NORMAL op->op_next
64#define DIE return die
65#define PROP if (dying) return die("%s", dying);
66
67#define PUTBACK stack_sp = sp
68#define RETURN return PUTBACK, NORMAL
69#define RETURNOP(o) return PUTBACK, o
70#define RETURNX(x) return x, PUTBACK, NORMAL
71
72#define POPs (*sp--)
73#define POPp (SvPVnx(POPs))
74#define POPn (SvNVnx(POPs))
75#define POPi ((int)SvIVnx(POPs))
76#define POPl ((long)SvIVnx(POPs))
77
78#define TOPs (*sp)
79#define TOPp (SvPVn(TOPs))
80#define TOPn (SvNVn(TOPs))
81#define TOPi ((int)SvIVn(TOPs))
82#define TOPl ((long)SvNVn(TOPs))
83
84/* Go to some pains in the rare event that we must extend the stack. */
85#define EXTEND(p,n) do { if (stack_max - p < (n)) { \
86 av_fill(stack, (p - stack_base) + (n)); \
87 sp = AvARRAY(stack) + (sp - stack_base); \
88 stack_base = AvARRAY(stack); \
89 stack_max = stack_base + AvMAX(stack); \
90 } } while (0)
91/* Same thing, but update mark register too. */
92#define MEXTEND(p,n) do {if (stack_max - p < (n)) { \
93 av_fill(stack, (p - stack_base) + (n)); \
94 sp = AvARRAY(stack) + (sp - stack_base); \
95 mark = AvARRAY(stack) + (mark - stack_base); \
96 stack_base = AvARRAY(stack); \
97 stack_max = stack_base + AvMAX(stack); \
98 } } while (0)
99
100#define PUSHs(s) (*++sp = (s))
101#define PUSHTARG do { SvSETMAGIC(TARG); PUSHs(TARG); } while (0)
102#define PUSHp(p,l) do { sv_setpvn(TARG, (p), (l)); PUSHTARG; } while (0)
103#define PUSHn(n) do { sv_setnv(TARG, (n)); PUSHTARG; } while (0)
104#define PUSHi(i) do { sv_setiv(TARG, (i)); PUSHTARG; } while (0)
105
106#define XPUSHs(s) do { EXTEND(sp,1); (*++sp = (s)); } while (0)
107#define XPUSHTARG do { SvSETMAGIC(TARG); XPUSHs(TARG); } while (0)
108#define XPUSHp(p,l) do { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } while (0)
109#define XPUSHn(n) do { sv_setnv(TARG, (n)); XPUSHTARG; } while (0)
110#define XPUSHi(i) do { sv_setiv(TARG, (i)); XPUSHTARG; } while (0)
111
112#define MXPUSHs(s) do { MEXTEND(sp,1); (*++sp = (s)); } while (0)
113#define MXPUSHTARG do { SvSETMAGIC(TARG); XPUSHs(TARG); } while (0)
114#define MXPUSHp(p,l) do { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } while (0)
115#define MXPUSHn(n) do { sv_setnv(TARG, (n)); XPUSHTARG; } while (0)
116#define MXPUSHi(i) do { sv_setiv(TARG, (i)); XPUSHTARG; } while (0)
117
118#define SETs(s) (*sp = s)
119#define SETTARG do { SvSETMAGIC(TARG); SETs(TARG); } while (0)
120#define SETp(p,l) do { sv_setpvn(TARG, (p), (l)); SETTARG; } while (0)
121#define SETn(n) do { sv_setnv(TARG, (n)); SETTARG; } while (0)
122#define SETi(i) do { sv_setiv(TARG, (i)); SETTARG; } while (0)
123
124#define dTOPss SV *sv = TOPs
125#define dPOPss SV *sv = POPs
126#define dTOPnv double value = TOPn
127#define dPOPnv double value = POPn
128#define dTOPiv I32 value = TOPi
129#define dPOPiv I32 value = POPi
130
131#define dPOPPOPssrl SV *rstr = POPs; SV *lstr = POPs
132#define dPOPPOPnnrl double right = POPn; double left = POPn
133#define dPOPPOPiirl I32 right = POPi; I32 left = POPi
134
135#define dPOPTOPssrl SV *rstr = POPs; SV *lstr = TOPs
136#define dPOPTOPnnrl double right = POPn; double left = TOPn
137#define dPOPTOPiirl I32 right = POPi; I32 left = TOPi
138
139#define RETPUSHYES RETURNX(PUSHs(&sv_yes))
140#define RETPUSHNO RETURNX(PUSHs(&sv_no))
141#define RETPUSHUNDEF RETURNX(PUSHs(&sv_undef))
142
143#define RETSETYES RETURNX(SETs(&sv_yes))
144#define RETSETNO RETURNX(SETs(&sv_no))
145#define RETSETUNDEF RETURNX(SETs(&sv_undef))
146
147#define ARGTARG op->op_targ
148#define MAXARG op->op_private
149
150#define SWITCHSTACK(f,t) AvFILL(f) = sp - stack_base; \
151 stack_base = AvARRAY(t); \
152 stack_max = stack_base + AvMAX(t); \
153 sp = stack_base + AvFILL(t); \
154 stack = t;
155
156/* XXX need to diffentiate on marked operators? */
157#define FETCH_GV(s) PUTBACK, s = fetch_gv(op,1), SPAGAIN
158#define FETCH_GV1(s) PUTBACK, s = fetch_gv(op,1), SPAGAIN
159#define FETCH_GV2(s) PUTBACK, s = fetch_gv(op,2), SPAGAIN
160#define FETCH_IO(s) PUTBACK, s = fetch_io(op,1), SPAGAIN
161#define FETCH_IO1(s) PUTBACK, s = fetch_io(op,1), SPAGAIN
162#define FETCH_IO2(s) PUTBACK, s = fetch_io(op,2), SPAGAIN
163
164#define ENTER push_scope()
165#define LEAVE pop_scope()
166
167#define SAVEINT(i) save_int((int*)(&i));
168#define SAVEI32(i) save_int((I32*)(&i));
169#define SAVELONG(l) save_int((long*)(&l));
170#define SAVESPTR(s) save_sptr((SV**)(&s))
171#define SAVETMPS save_int(&tmps_floor), tmps_floor = tmps_ix