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