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