This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[5.004_71] Patch: Fix perl_exp.SH for Unixware
[perl5.git] / bytecode.h
CommitLineData
a8a597b2
MB
1typedef char *pvcontents;
2typedef char *strconst;
3typedef U32 PV;
4typedef char *op_tr_array;
34e97019 5typedef int comment_t;
a8a597b2
MB
6typedef SV *svindex;
7typedef OP *opindex;
8typedef IV IV64;
9
10EXT int iv_overflows INIT(0);
a8a597b2
MB
11
12EXT SV *sv;
13#ifndef USE_THREADS
14EXT OP *op;
15#endif
16EXT XPV pv;
17
18EXT void **obj_list;
19EXT I32 obj_list_fill INIT(-1);
20
21#ifdef INDIRECT_BGET_MACROS
47358472
MB
22#define BGET_FREAD(argp, len, nelem) \
23 bs.fread((char*)(argp),(len),(nelem),bs.data)
24#define BGET_FGETC() bs.fgetc(bs.data)
a8a597b2 25#else
07ba5892 26#define BGET_FREAD(argp, len, nelem) PerlIO_read(fp, (argp), (len)*(nelem))
9c6fd6cc 27#define BGET_FGETC() PerlIO_getc(fp)
a8a597b2
MB
28#endif /* INDIRECT_BGET_MACROS */
29
47358472 30#define BGET_U32(arg) \
d9f97599 31 BGET_FREAD(&arg, sizeof(U32), 1); arg = PerlSock_ntohl((U32)arg)
47358472 32#define BGET_I32(arg) \
d9f97599 33 BGET_FREAD(&arg, sizeof(I32), 1); arg = (I32)PerlSock_ntohl((U32)arg)
47358472 34#define BGET_U16(arg) \
d9f97599 35 BGET_FREAD(&arg, sizeof(U16), 1); arg = PerlSock_ntohs((U16)arg)
47358472 36#define BGET_U8(arg) arg = BGET_FGETC()
a8a597b2
MB
37
38#if INDIRECT_BGET_MACROS
f7d144c8 39#define BGET_PV(arg) STMT_START { \
a8a597b2
MB
40 BGET_U32(arg); \
41 if (arg) \
42 bs.freadpv(arg, bs.data); \
43 else { \
44 pv.xpv_pv = 0; \
45 pv.xpv_len = 0; \
46 pv.xpv_cur = 0; \
47 } \
f7d144c8 48 } STMT_END
a8a597b2 49#else
f7d144c8 50#define BGET_PV(arg) STMT_START { \
a8a597b2
MB
51 BGET_U32(arg); \
52 if (arg) { \
53 New(666, pv.xpv_pv, arg, char); \
07ba5892 54 PerlIO_read(fp, pv.xpv_pv, arg); \
a8a597b2
MB
55 pv.xpv_len = arg; \
56 pv.xpv_cur = arg - 1; \
57 } else { \
58 pv.xpv_pv = 0; \
59 pv.xpv_len = 0; \
60 pv.xpv_cur = 0; \
61 } \
f7d144c8 62 } STMT_END
a8a597b2
MB
63#endif /* INDIRECT_BGET_MACROS */
64
fe3a57c4 65#define BGET_comment_t(arg) \
47358472 66 do { arg = BGET_FGETC(); } while (arg != '\n' && arg != EOF)
a8a597b2
MB
67
68/*
69 * In the following, sizeof(IV)*4 is just a way of encoding 32 on 64-bit-IV
70 * machines such that 32-bit machine compilers don't whine about the shift
71 * count being too high even though the code is never reached there.
72 */
f7d144c8 73#define BGET_IV64(arg) STMT_START { \
a8a597b2
MB
74 U32 hi, lo; \
75 BGET_U32(hi); \
76 BGET_U32(lo); \
77 if (sizeof(IV) == 8) \
78 arg = (IV) (hi << (sizeof(IV)*4) | lo); \
79 else if (((I32)hi == -1 && (I32)lo < 0) \
80 || ((I32)hi == 0 && (I32)lo >= 0)) { \
81 arg = (I32)lo; \
82 } \
83 else { \
84 iv_overflows++; \
85 arg = 0; \
86 } \
f7d144c8 87 } STMT_END
a8a597b2
MB
88
89#define BGET_op_tr_array(arg) do { \
90 unsigned short *ary; \
91 int i; \
92 New(666, ary, 256, unsigned short); \
319b3e9e 93 BGET_FREAD(ary, 256, 2); \
a8a597b2 94 for (i = 0; i < 256; i++) \
d9f97599 95 ary[i] = PerlSock_ntohs(ary[i]); \
a8a597b2
MB
96 arg = (char *) ary; \
97 } while (0)
98
99#define BGET_pvcontents(arg) arg = pv.xpv_pv
f7d144c8 100#define BGET_strconst(arg) STMT_START { \
47358472 101 for (arg = tokenbuf; (*arg = BGET_FGETC()); arg++) /* nothing */; \
a8a597b2 102 arg = tokenbuf; \
f7d144c8 103 } STMT_END
a8a597b2 104
f7d144c8 105#define BGET_double(arg) STMT_START { \
a8a597b2
MB
106 char *str; \
107 BGET_strconst(str); \
108 arg = atof(str); \
f7d144c8 109 } STMT_END
a8a597b2 110
01f988be
GS
111#define BGET_objindex(arg, type) STMT_START { \
112 U32 ix; \
113 BGET_U32(ix); \
114 arg = (type)obj_list[ix]; \
f7d144c8 115 } STMT_END
01f988be
GS
116#define BGET_svindex(arg) BGET_objindex(arg, svindex)
117#define BGET_opindex(arg) BGET_objindex(arg, opindex)
a8a597b2
MB
118
119#define BSET_ldspecsv(sv, arg) sv = specialsv_list[arg]
120
121#define BSET_sv_refcnt_add(svrefcnt, arg) svrefcnt += arg
122#define BSET_gp_refcnt_add(gprefcnt, arg) gprefcnt += arg
f7d144c8
CB
123#define BSET_gp_share(sv, arg) STMT_START { \
124 gp_free((GV*)sv); \
125 GvGP(sv) = GvGP(arg); \
126 } STMT_END
a8a597b2
MB
127
128#define BSET_gv_fetchpv(sv, arg) sv = (SV*)gv_fetchpv(arg, TRUE, SVt_PV)
129#define BSET_gv_stashpv(sv, arg) sv = (SV*)gv_stashpv(arg, TRUE)
130#define BSET_sv_magic(sv, arg) sv_magic(sv, Nullsv, arg, 0, 0)
131#define BSET_mg_pv(mg, arg) mg->mg_ptr = arg; mg->mg_len = pv.xpv_cur
132#define BSET_sv_upgrade(sv, arg) (void)SvUPGRADE(sv, arg)
133#define BSET_xpv(sv) do { \
134 SvPV_set(sv, pv.xpv_pv); \
135 SvCUR_set(sv, pv.xpv_cur); \
136 SvLEN_set(sv, pv.xpv_len); \
137 } while (0)
138#define BSET_av_extend(sv, arg) av_extend((AV*)sv, arg)
139
140#define BSET_av_push(sv, arg) av_push((AV*)sv, arg)
141#define BSET_hv_store(sv, arg) \
142 hv_store((HV*)sv, pv.xpv_pv, pv.xpv_cur, arg, 0)
143#define BSET_pv_free(pv) Safefree(pv.xpv_pv)
144#define BSET_pregcomp(o, arg) \
145 ((PMOP*)o)->op_pmregexp = arg ? \
15e52e56 146 CALLREGCOMP(arg, arg + pv.xpv_cur, ((PMOP*)o)) : 0
a8a597b2
MB
147#define BSET_newsv(sv, arg) sv = NEWSV(666,0); SvUPGRADE(sv, arg)
148#define BSET_newop(o, arg) o = (OP*)safemalloc(optype_size[arg])
f7d144c8
CB
149#define BSET_newopn(o, arg) STMT_START { \
150 OP *oldop = o; \
151 BSET_newop(o, arg); \
152 oldop->op_next = o; \
153 } STMT_END
a8a597b2
MB
154
155#define BSET_ret(foo) return
156
157/*
158 * Kludge special-case workaround for OP_MAPSTART
159 * which needs the ppaddr for OP_GREPSTART. Blech.
160 */
f7d144c8
CB
161#define BSET_op_type(o, arg) STMT_START { \
162 o->op_type = arg; \
163 if (arg == OP_MAPSTART) \
164 arg = OP_GREPSTART; \
165 o->op_ppaddr = ppaddr[arg]; \
166 } STMT_END
a8a597b2
MB
167#define BSET_op_ppaddr(o, arg) croak("op_ppaddr not yet implemented")
168#define BSET_curpad(pad, arg) pad = AvARRAY(arg)
169
170#define BSET_OBJ_STORE(obj, ix) \
171 (I32)ix > obj_list_fill ? \
172 bset_obj_store(obj, (I32)ix) : (obj_list[ix] = obj)