This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/op/64bitint.t
[perl5.git] / ext / B / B.xs
CommitLineData
a8a597b2
MB
1/* B.xs
2 *
3 * Copyright (c) 1996 Malcolm Beattie
4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
7 *
8 */
9
c5be433b 10#define PERL_NO_GET_CONTEXT
a8a597b2
MB
11#include "EXTERN.h"
12#include "perl.h"
13#include "XSUB.h"
a8a597b2 14
51aa15f3 15#ifdef PERL_OBJECT
22c35a8c
GS
16#undef PL_op_name
17#undef PL_opargs
18#undef PL_op_desc
0cb96387
GS
19#define PL_op_name (get_op_names())
20#define PL_opargs (get_opargs())
21#define PL_op_desc (get_op_descs())
51aa15f3
GS
22#endif
23
24#ifdef PerlIO
25typedef PerlIO * InputStream;
26#else
27typedef FILE * InputStream;
28#endif
29
30
a8a597b2
MB
31static char *svclassnames[] = {
32 "B::NULL",
33 "B::IV",
34 "B::NV",
35 "B::RV",
36 "B::PV",
37 "B::PVIV",
38 "B::PVNV",
39 "B::PVMG",
40 "B::BM",
41 "B::PVLV",
42 "B::AV",
43 "B::HV",
44 "B::CV",
45 "B::GV",
46 "B::FM",
47 "B::IO",
48};
49
50typedef enum {
51 OPc_NULL, /* 0 */
52 OPc_BASEOP, /* 1 */
53 OPc_UNOP, /* 2 */
54 OPc_BINOP, /* 3 */
55 OPc_LOGOP, /* 4 */
1a67a97c
SM
56 OPc_LISTOP, /* 5 */
57 OPc_PMOP, /* 6 */
58 OPc_SVOP, /* 7 */
7934575e 59 OPc_PADOP, /* 8 */
1a67a97c
SM
60 OPc_PVOP, /* 9 */
61 OPc_CVOP, /* 10 */
62 OPc_LOOP, /* 11 */
63 OPc_COP /* 12 */
a8a597b2
MB
64} opclass;
65
66static char *opclassnames[] = {
67 "B::NULL",
68 "B::OP",
69 "B::UNOP",
70 "B::BINOP",
71 "B::LOGOP",
a8a597b2
MB
72 "B::LISTOP",
73 "B::PMOP",
74 "B::SVOP",
7934575e 75 "B::PADOP",
a8a597b2
MB
76 "B::PVOP",
77 "B::CVOP",
78 "B::LOOP",
79 "B::COP"
80};
81
82static int walkoptree_debug = 0; /* Flag for walkoptree debug hook */
83
059a8bb7 84static SV *specialsv_list[6];
e8edd1e6 85
a8a597b2 86static opclass
cea2e8a9 87cc_opclass(pTHX_ OP *o)
a8a597b2
MB
88{
89 if (!o)
90 return OPc_NULL;
91
92 if (o->op_type == 0)
93 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
94
95 if (o->op_type == OP_SASSIGN)
96 return ((o->op_private & OPpASSIGN_BACKWARDS) ? OPc_UNOP : OPc_BINOP);
97
18228111
GS
98#ifdef USE_ITHREADS
99 if (o->op_type == OP_GV || o->op_type == OP_GVSV || o->op_type == OP_AELEMFAST)
100 return OPc_PADOP;
101#endif
102
22c35a8c 103 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
a8a597b2
MB
104 case OA_BASEOP:
105 return OPc_BASEOP;
106
107 case OA_UNOP:
108 return OPc_UNOP;
109
110 case OA_BINOP:
111 return OPc_BINOP;
112
113 case OA_LOGOP:
114 return OPc_LOGOP;
115
a8a597b2
MB
116 case OA_LISTOP:
117 return OPc_LISTOP;
118
119 case OA_PMOP:
120 return OPc_PMOP;
121
122 case OA_SVOP:
123 return OPc_SVOP;
124
7934575e
GS
125 case OA_PADOP:
126 return OPc_PADOP;
a8a597b2 127
293d3ffa
SM
128 case OA_PVOP_OR_SVOP:
129 /*
130 * Character translations (tr///) are usually a PVOP, keeping a
131 * pointer to a table of shorts used to look up translations.
132 * Under utf8, however, a simple table isn't practical; instead,
133 * the OP is an SVOP, and the SV is a reference to a swash
134 * (i.e., an RV pointing to an HV).
135 */
136 return (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF))
137 ? OPc_SVOP : OPc_PVOP;
a8a597b2
MB
138
139 case OA_LOOP:
140 return OPc_LOOP;
141
142 case OA_COP:
143 return OPc_COP;
144
145 case OA_BASEOP_OR_UNOP:
146 /*
147 * UNI(OP_foo) in toke.c returns token UNI or FUNC1 depending on
45f6cd40
SM
148 * whether parens were seen. perly.y uses OPf_SPECIAL to
149 * signal whether a BASEOP had empty parens or none.
150 * Some other UNOPs are created later, though, so the best
151 * test is OPf_KIDS, which is set in newUNOP.
a8a597b2 152 */
45f6cd40 153 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
a8a597b2
MB
154
155 case OA_FILESTATOP:
156 /*
157 * The file stat OPs are created via UNI(OP_foo) in toke.c but use
158 * the OPf_REF flag to distinguish between OP types instead of the
159 * usual OPf_SPECIAL flag. As usual, if OPf_KIDS is set, then we
160 * return OPc_UNOP so that walkoptree can find our children. If
161 * OPf_KIDS is not set then we check OPf_REF. Without OPf_REF set
162 * (no argument to the operator) it's an OP; with OPf_REF set it's
7934575e 163 * an SVOP (and op_sv is the GV for the filehandle argument).
a8a597b2
MB
164 */
165 return ((o->op_flags & OPf_KIDS) ? OPc_UNOP :
93865851
GS
166#ifdef USE_ITHREADS
167 (o->op_flags & OPf_REF) ? OPc_PADOP : OPc_BASEOP);
168#else
7934575e 169 (o->op_flags & OPf_REF) ? OPc_SVOP : OPc_BASEOP);
93865851 170#endif
a8a597b2
MB
171 case OA_LOOPEXOP:
172 /*
173 * next, last, redo, dump and goto use OPf_SPECIAL to indicate that a
174 * label was omitted (in which case it's a BASEOP) or else a term was
175 * seen. In this last case, all except goto are definitely PVOP but
176 * goto is either a PVOP (with an ordinary constant label), an UNOP
177 * with OPf_STACKED (with a non-constant non-sub) or an UNOP for
178 * OP_REFGEN (with goto &sub) in which case OPf_STACKED also seems to
179 * get set.
180 */
181 if (o->op_flags & OPf_STACKED)
182 return OPc_UNOP;
183 else if (o->op_flags & OPf_SPECIAL)
184 return OPc_BASEOP;
185 else
186 return OPc_PVOP;
187 }
188 warn("can't determine class of operator %s, assuming BASEOP\n",
22c35a8c 189 PL_op_name[o->op_type]);
a8a597b2
MB
190 return OPc_BASEOP;
191}
192
193static char *
cea2e8a9 194cc_opclassname(pTHX_ OP *o)
a8a597b2 195{
cea2e8a9 196 return opclassnames[cc_opclass(aTHX_ o)];
a8a597b2
MB
197}
198
199static SV *
cea2e8a9 200make_sv_object(pTHX_ SV *arg, SV *sv)
a8a597b2
MB
201{
202 char *type = 0;
203 IV iv;
204
e8edd1e6
TH
205 for (iv = 0; iv < sizeof(specialsv_list)/sizeof(SV*); iv++) {
206 if (sv == specialsv_list[iv]) {
a8a597b2
MB
207 type = "B::SPECIAL";
208 break;
209 }
210 }
211 if (!type) {
212 type = svclassnames[SvTYPE(sv)];
56431972 213 iv = PTR2IV(sv);
a8a597b2
MB
214 }
215 sv_setiv(newSVrv(arg, type), iv);
216 return arg;
217}
218
219static SV *
cea2e8a9 220make_mg_object(pTHX_ SV *arg, MAGIC *mg)
a8a597b2 221{
56431972 222 sv_setiv(newSVrv(arg, "B::MAGIC"), PTR2IV(mg));
a8a597b2
MB
223 return arg;
224}
225
226static SV *
cea2e8a9 227cstring(pTHX_ SV *sv)
a8a597b2 228{
79cb57f6 229 SV *sstr = newSVpvn("", 0);
a8a597b2
MB
230 STRLEN len;
231 char *s;
232
233 if (!SvOK(sv))
234 sv_setpvn(sstr, "0", 1);
235 else
236 {
237 /* XXX Optimise? */
238 s = SvPV(sv, len);
239 sv_catpv(sstr, "\"");
240 for (; len; len--, s++)
241 {
242 /* At least try a little for readability */
243 if (*s == '"')
244 sv_catpv(sstr, "\\\"");
245 else if (*s == '\\')
246 sv_catpv(sstr, "\\\\");
247 else if (*s >= ' ' && *s < 127) /* XXX not portable */
248 sv_catpvn(sstr, s, 1);
249 else if (*s == '\n')
250 sv_catpv(sstr, "\\n");
251 else if (*s == '\r')
252 sv_catpv(sstr, "\\r");
253 else if (*s == '\t')
254 sv_catpv(sstr, "\\t");
255 else if (*s == '\a')
256 sv_catpv(sstr, "\\a");
257 else if (*s == '\b')
258 sv_catpv(sstr, "\\b");
259 else if (*s == '\f')
260 sv_catpv(sstr, "\\f");
261 else if (*s == '\v')
262 sv_catpv(sstr, "\\v");
263 else
264 {
265 /* no trigraph support */
266 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
267 /* Don't want promotion of a signed -1 char in sprintf args */
268 unsigned char c = (unsigned char) *s;
269 sprintf(escbuff, "\\%03o", c);
270 sv_catpv(sstr, escbuff);
271 }
272 /* XXX Add line breaks if string is long */
273 }
274 sv_catpv(sstr, "\"");
275 }
276 return sstr;
277}
278
279static SV *
cea2e8a9 280cchar(pTHX_ SV *sv)
a8a597b2 281{
79cb57f6 282 SV *sstr = newSVpvn("'", 1);
2d8e6c8d
GS
283 STRLEN n_a;
284 char *s = SvPV(sv, n_a);
a8a597b2
MB
285
286 if (*s == '\'')
287 sv_catpv(sstr, "\\'");
288 else if (*s == '\\')
289 sv_catpv(sstr, "\\\\");
290 else if (*s >= ' ' && *s < 127) /* XXX not portable */
291 sv_catpvn(sstr, s, 1);
292 else if (*s == '\n')
293 sv_catpv(sstr, "\\n");
294 else if (*s == '\r')
295 sv_catpv(sstr, "\\r");
296 else if (*s == '\t')
297 sv_catpv(sstr, "\\t");
298 else if (*s == '\a')
299 sv_catpv(sstr, "\\a");
300 else if (*s == '\b')
301 sv_catpv(sstr, "\\b");
302 else if (*s == '\f')
303 sv_catpv(sstr, "\\f");
304 else if (*s == '\v')
305 sv_catpv(sstr, "\\v");
306 else
307 {
308 /* no trigraph support */
309 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
310 /* Don't want promotion of a signed -1 char in sprintf args */
311 unsigned char c = (unsigned char) *s;
312 sprintf(escbuff, "\\%03o", c);
313 sv_catpv(sstr, escbuff);
314 }
315 sv_catpv(sstr, "'");
316 return sstr;
317}
318
a8a597b2 319void
cea2e8a9 320walkoptree(pTHX_ SV *opsv, char *method)
a8a597b2
MB
321{
322 dSP;
323 OP *o;
324
325 if (!SvROK(opsv))
326 croak("opsv is not a reference");
327 opsv = sv_mortalcopy(opsv);
56431972 328 o = INT2PTR(OP*,SvIV((SV*)SvRV(opsv)));
a8a597b2
MB
329 if (walkoptree_debug) {
330 PUSHMARK(sp);
331 XPUSHs(opsv);
332 PUTBACK;
333 perl_call_method("walkoptree_debug", G_DISCARD);
334 }
335 PUSHMARK(sp);
336 XPUSHs(opsv);
337 PUTBACK;
338 perl_call_method(method, G_DISCARD);
339 if (o && (o->op_flags & OPf_KIDS)) {
340 OP *kid;
341 for (kid = ((UNOP*)o)->op_first; kid; kid = kid->op_sibling) {
342 /* Use the same opsv. Rely on methods not to mess it up. */
56431972 343 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
cea2e8a9 344 walkoptree(aTHX_ opsv, method);
a8a597b2
MB
345 }
346 }
347}
348
349typedef OP *B__OP;
350typedef UNOP *B__UNOP;
351typedef BINOP *B__BINOP;
352typedef LOGOP *B__LOGOP;
a8a597b2
MB
353typedef LISTOP *B__LISTOP;
354typedef PMOP *B__PMOP;
355typedef SVOP *B__SVOP;
7934575e 356typedef PADOP *B__PADOP;
a8a597b2
MB
357typedef PVOP *B__PVOP;
358typedef LOOP *B__LOOP;
359typedef COP *B__COP;
360
361typedef SV *B__SV;
362typedef SV *B__IV;
363typedef SV *B__PV;
364typedef SV *B__NV;
365typedef SV *B__PVMG;
366typedef SV *B__PVLV;
367typedef SV *B__BM;
368typedef SV *B__RV;
369typedef AV *B__AV;
370typedef HV *B__HV;
371typedef CV *B__CV;
372typedef GV *B__GV;
373typedef IO *B__IO;
374
375typedef MAGIC *B__MAGIC;
376
377MODULE = B PACKAGE = B PREFIX = B_
378
379PROTOTYPES: DISABLE
380
381BOOT:
4c1f658f
NIS
382{
383 HV *stash = gv_stashpvn("B", 1, TRUE);
384 AV *export_ok = perl_get_av("B::EXPORT_OK",TRUE);
e8edd1e6
TH
385 specialsv_list[0] = Nullsv;
386 specialsv_list[1] = &PL_sv_undef;
387 specialsv_list[2] = &PL_sv_yes;
388 specialsv_list[3] = &PL_sv_no;
059a8bb7
JH
389 specialsv_list[4] = pWARN_ALL;
390 specialsv_list[5] = pWARN_NONE;
4c1f658f
NIS
391#include "defsubs.h"
392}
a8a597b2 393
3280af22 394#define B_main_cv() PL_main_cv
31d7d75a 395#define B_init_av() PL_initav
059a8bb7
JH
396#define B_begin_av() PL_beginav_save
397#define B_end_av() PL_endav
3280af22
NIS
398#define B_main_root() PL_main_root
399#define B_main_start() PL_main_start
56eca212 400#define B_amagic_generation() PL_amagic_generation
3280af22
NIS
401#define B_comppadlist() (PL_main_cv ? CvPADLIST(PL_main_cv) : CvPADLIST(PL_compcv))
402#define B_sv_undef() &PL_sv_undef
403#define B_sv_yes() &PL_sv_yes
404#define B_sv_no() &PL_sv_no
a8a597b2 405
31d7d75a
NIS
406B::AV
407B_init_av()
408
059a8bb7
JH
409B::AV
410B_begin_av()
411
412B::AV
413B_end_av()
414
a8a597b2
MB
415B::CV
416B_main_cv()
417
418B::OP
419B_main_root()
420
421B::OP
422B_main_start()
423
56eca212
GS
424long
425B_amagic_generation()
426
a8a597b2
MB
427B::AV
428B_comppadlist()
429
430B::SV
431B_sv_undef()
432
433B::SV
434B_sv_yes()
435
436B::SV
437B_sv_no()
438
439MODULE = B PACKAGE = B
440
441
442void
443walkoptree(opsv, method)
444 SV * opsv
445 char * method
cea2e8a9
GS
446 CODE:
447 walkoptree(aTHX_ opsv, method);
a8a597b2
MB
448
449int
450walkoptree_debug(...)
451 CODE:
452 RETVAL = walkoptree_debug;
453 if (items > 0 && SvTRUE(ST(1)))
454 walkoptree_debug = 1;
455 OUTPUT:
456 RETVAL
457
56431972 458#define address(sv) PTR2IV(sv)
a8a597b2
MB
459
460IV
461address(sv)
462 SV * sv
463
464B::SV
465svref_2object(sv)
466 SV * sv
467 CODE:
468 if (!SvROK(sv))
469 croak("argument is not a reference");
470 RETVAL = (SV*)SvRV(sv);
471 OUTPUT:
0cc1d052
NIS
472 RETVAL
473
474void
475opnumber(name)
476char * name
477CODE:
478{
479 int i;
480 IV result = -1;
481 ST(0) = sv_newmortal();
482 if (strncmp(name,"pp_",3) == 0)
483 name += 3;
484 for (i = 0; i < PL_maxo; i++)
485 {
486 if (strcmp(name, PL_op_name[i]) == 0)
487 {
488 result = i;
489 break;
490 }
491 }
492 sv_setiv(ST(0),result);
493}
a8a597b2
MB
494
495void
496ppname(opnum)
497 int opnum
498 CODE:
499 ST(0) = sv_newmortal();
3280af22 500 if (opnum >= 0 && opnum < PL_maxo) {
a8a597b2 501 sv_setpvn(ST(0), "pp_", 3);
22c35a8c 502 sv_catpv(ST(0), PL_op_name[opnum]);
a8a597b2
MB
503 }
504
505void
506hash(sv)
507 SV * sv
508 CODE:
509 char *s;
510 STRLEN len;
511 U32 hash = 0;
faccc32b 512 char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */
a8a597b2 513 s = SvPV(sv, len);
cf86991c 514 PERL_HASH(hash, s, len);
faccc32b 515 sprintf(hexhash, "0x%"UVxf, (UV)hash);
a8a597b2
MB
516 ST(0) = sv_2mortal(newSVpv(hexhash, 0));
517
518#define cast_I32(foo) (I32)foo
519IV
520cast_I32(i)
521 IV i
522
523void
524minus_c()
525 CODE:
3280af22 526 PL_minus_c = TRUE;
a8a597b2 527
059a8bb7
JH
528void
529save_BEGINs()
530 CODE:
531 PL_minus_c |= 0x10;
532
a8a597b2
MB
533SV *
534cstring(sv)
535 SV * sv
cea2e8a9
GS
536 CODE:
537 RETVAL = cstring(aTHX_ sv);
538 OUTPUT:
539 RETVAL
a8a597b2
MB
540
541SV *
542cchar(sv)
543 SV * sv
cea2e8a9
GS
544 CODE:
545 RETVAL = cchar(aTHX_ sv);
546 OUTPUT:
547 RETVAL
a8a597b2
MB
548
549void
550threadsv_names()
551 PPCODE:
552#ifdef USE_THREADS
553 int i;
533c011a 554 STRLEN len = strlen(PL_threadsv_names);
a8a597b2
MB
555
556 EXTEND(sp, len);
557 for (i = 0; i < len; i++)
79cb57f6 558 PUSHs(sv_2mortal(newSVpvn(&PL_threadsv_names[i], 1)));
a8a597b2
MB
559#endif
560
561
562#define OP_next(o) o->op_next
563#define OP_sibling(o) o->op_sibling
22c35a8c 564#define OP_desc(o) PL_op_desc[o->op_type]
a8a597b2
MB
565#define OP_targ(o) o->op_targ
566#define OP_type(o) o->op_type
567#define OP_seq(o) o->op_seq
568#define OP_flags(o) o->op_flags
569#define OP_private(o) o->op_private
570
571MODULE = B PACKAGE = B::OP PREFIX = OP_
572
573B::OP
574OP_next(o)
575 B::OP o
576
577B::OP
578OP_sibling(o)
579 B::OP o
580
581char *
3f872cb9
GS
582OP_name(o)
583 B::OP o
584 CODE:
8063af02
DM
585 RETVAL = PL_op_name[o->op_type];
586 OUTPUT:
587 RETVAL
3f872cb9
GS
588
589
8063af02 590void
a8a597b2
MB
591OP_ppaddr(o)
592 B::OP o
dc333d64
GS
593 PREINIT:
594 int i;
595 SV *sv = sv_newmortal();
a8a597b2 596 CODE:
dc333d64
GS
597 sv_setpvn(sv, "PL_ppaddr[OP_", 13);
598 sv_catpv(sv, PL_op_name[o->op_type]);
599 for (i=13; i<SvCUR(sv); ++i)
600 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
601 sv_catpv(sv, "]");
602 ST(0) = sv;
a8a597b2
MB
603
604char *
605OP_desc(o)
606 B::OP o
607
7934575e 608PADOFFSET
a8a597b2
MB
609OP_targ(o)
610 B::OP o
611
612U16
613OP_type(o)
614 B::OP o
615
616U16
617OP_seq(o)
618 B::OP o
619
620U8
621OP_flags(o)
622 B::OP o
623
624U8
625OP_private(o)
626 B::OP o
627
628#define UNOP_first(o) o->op_first
629
630MODULE = B PACKAGE = B::UNOP PREFIX = UNOP_
631
632B::OP
633UNOP_first(o)
634 B::UNOP o
635
636#define BINOP_last(o) o->op_last
637
638MODULE = B PACKAGE = B::BINOP PREFIX = BINOP_
639
640B::OP
641BINOP_last(o)
642 B::BINOP o
643
644#define LOGOP_other(o) o->op_other
645
646MODULE = B PACKAGE = B::LOGOP PREFIX = LOGOP_
647
648B::OP
649LOGOP_other(o)
650 B::LOGOP o
651
a8a597b2
MB
652MODULE = B PACKAGE = B::LISTOP PREFIX = LISTOP_
653
c03c2844
SM
654U32
655LISTOP_children(o)
656 B::LISTOP o
657 OP * kid = NO_INIT
658 int i = NO_INIT
659 CODE:
c03c2844
SM
660 i = 0;
661 for (kid = o->op_first; kid; kid = kid->op_sibling)
662 i++;
8063af02
DM
663 RETVAL = i;
664 OUTPUT:
665 RETVAL
c03c2844 666
a8a597b2
MB
667#define PMOP_pmreplroot(o) o->op_pmreplroot
668#define PMOP_pmreplstart(o) o->op_pmreplstart
669#define PMOP_pmnext(o) o->op_pmnext
670#define PMOP_pmregexp(o) o->op_pmregexp
671#define PMOP_pmflags(o) o->op_pmflags
672#define PMOP_pmpermflags(o) o->op_pmpermflags
673
674MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_
675
676void
677PMOP_pmreplroot(o)
678 B::PMOP o
679 OP * root = NO_INIT
680 CODE:
681 ST(0) = sv_newmortal();
682 root = o->op_pmreplroot;
683 /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */
684 if (o->op_type == OP_PUSHRE) {
685 sv_setiv(newSVrv(ST(0), root ?
686 svclassnames[SvTYPE((SV*)root)] : "B::SV"),
56431972 687 PTR2IV(root));
a8a597b2
MB
688 }
689 else {
56431972 690 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root));
a8a597b2
MB
691 }
692
693B::OP
694PMOP_pmreplstart(o)
695 B::PMOP o
696
697B::PMOP
698PMOP_pmnext(o)
699 B::PMOP o
700
701U16
702PMOP_pmflags(o)
703 B::PMOP o
704
705U16
706PMOP_pmpermflags(o)
707 B::PMOP o
708
709void
710PMOP_precomp(o)
711 B::PMOP o
712 REGEXP * rx = NO_INIT
713 CODE:
714 ST(0) = sv_newmortal();
715 rx = o->op_pmregexp;
716 if (rx)
717 sv_setpvn(ST(0), rx->precomp, rx->prelen);
718
ac33dcd1
JH
719#define SVOP_sv(o) cSVOPo->op_sv
720#define SVOP_gv(o) ((GV*)cSVOPo->op_sv)
a8a597b2
MB
721
722MODULE = B PACKAGE = B::SVOP PREFIX = SVOP_
723
a8a597b2
MB
724B::SV
725SVOP_sv(o)
726 B::SVOP o
727
f22444f5 728B::GV
065a1863
GS
729SVOP_gv(o)
730 B::SVOP o
731
7934575e
GS
732#define PADOP_padix(o) o->op_padix
733#define PADOP_sv(o) (o->op_padix ? PL_curpad[o->op_padix] : Nullsv)
734#define PADOP_gv(o) ((o->op_padix \
735 && SvTYPE(PL_curpad[o->op_padix]) == SVt_PVGV) \
736 ? (GV*)PL_curpad[o->op_padix] : Nullgv)
a8a597b2 737
7934575e
GS
738MODULE = B PACKAGE = B::PADOP PREFIX = PADOP_
739
740PADOFFSET
741PADOP_padix(o)
742 B::PADOP o
743
744B::SV
745PADOP_sv(o)
746 B::PADOP o
a8a597b2
MB
747
748B::GV
7934575e
GS
749PADOP_gv(o)
750 B::PADOP o
a8a597b2
MB
751
752MODULE = B PACKAGE = B::PVOP PREFIX = PVOP_
753
754void
755PVOP_pv(o)
756 B::PVOP o
757 CODE:
758 /*
2a9e2f8a 759 * OP_TRANS uses op_pv to point to a table of 256 or 258 shorts
a8a597b2
MB
760 * whereas other PVOPs point to a null terminated string.
761 */
762 ST(0) = sv_2mortal(newSVpv(o->op_pv, (o->op_type == OP_TRANS) ?
2a9e2f8a
RH
763 ((o->op_private & OPpTRANS_COMPLEMENT) &&
764 !(o->op_private & OPpTRANS_DELETE) ? 258 : 256)
765 * sizeof(short) : 0));
a8a597b2
MB
766
767#define LOOP_redoop(o) o->op_redoop
768#define LOOP_nextop(o) o->op_nextop
769#define LOOP_lastop(o) o->op_lastop
770
771MODULE = B PACKAGE = B::LOOP PREFIX = LOOP_
772
773
774B::OP
775LOOP_redoop(o)
776 B::LOOP o
777
778B::OP
779LOOP_nextop(o)
780 B::LOOP o
781
782B::OP
783LOOP_lastop(o)
784 B::LOOP o
785
786#define COP_label(o) o->cop_label
11faa288
GS
787#define COP_stashpv(o) CopSTASHPV(o)
788#define COP_stash(o) CopSTASH(o)
57843af0 789#define COP_file(o) CopFILE(o)
a8a597b2
MB
790#define COP_cop_seq(o) o->cop_seq
791#define COP_arybase(o) o->cop_arybase
57843af0 792#define COP_line(o) CopLINE(o)
b295d113 793#define COP_warnings(o) o->cop_warnings
a8a597b2
MB
794
795MODULE = B PACKAGE = B::COP PREFIX = COP_
796
797char *
798COP_label(o)
799 B::COP o
800
11faa288
GS
801char *
802COP_stashpv(o)
803 B::COP o
804
a8a597b2
MB
805B::HV
806COP_stash(o)
807 B::COP o
808
57843af0
GS
809char *
810COP_file(o)
a8a597b2
MB
811 B::COP o
812
813U32
814COP_cop_seq(o)
815 B::COP o
816
817I32
818COP_arybase(o)
819 B::COP o
820
821U16
822COP_line(o)
823 B::COP o
824
b295d113
TH
825B::SV
826COP_warnings(o)
827 B::COP o
828
a8a597b2
MB
829MODULE = B PACKAGE = B::SV PREFIX = Sv
830
831U32
832SvREFCNT(sv)
833 B::SV sv
834
835U32
836SvFLAGS(sv)
837 B::SV sv
838
839MODULE = B PACKAGE = B::IV PREFIX = Sv
840
841IV
842SvIV(sv)
843 B::IV sv
844
845IV
846SvIVX(sv)
847 B::IV sv
848
0ca04487
VB
849UV
850SvUVX(sv)
851 B::IV sv
852
853
a8a597b2
MB
854MODULE = B PACKAGE = B::IV
855
856#define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv))
857
858int
859needs64bits(sv)
860 B::IV sv
861
862void
863packiv(sv)
864 B::IV sv
865 CODE:
866 if (sizeof(IV) == 8) {
867 U32 wp[2];
868 IV iv = SvIVX(sv);
869 /*
870 * The following way of spelling 32 is to stop compilers on
871 * 32-bit architectures from moaning about the shift count
872 * being >= the width of the type. Such architectures don't
873 * reach this code anyway (unless sizeof(IV) > 8 but then
874 * everything else breaks too so I'm not fussed at the moment).
875 */
42718184
RB
876#ifdef UV_IS_QUAD
877 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
878#else
879 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
880#endif
a8a597b2 881 wp[1] = htonl(iv & 0xffffffff);
79cb57f6 882 ST(0) = sv_2mortal(newSVpvn((char *)wp, 8));
a8a597b2
MB
883 } else {
884 U32 w = htonl((U32)SvIVX(sv));
79cb57f6 885 ST(0) = sv_2mortal(newSVpvn((char *)&w, 4));
a8a597b2
MB
886 }
887
888MODULE = B PACKAGE = B::NV PREFIX = Sv
889
76ef7183 890NV
a8a597b2
MB
891SvNV(sv)
892 B::NV sv
893
76ef7183 894NV
a8a597b2
MB
895SvNVX(sv)
896 B::NV sv
897
898MODULE = B PACKAGE = B::RV PREFIX = Sv
899
900B::SV
901SvRV(sv)
902 B::RV sv
903
904MODULE = B PACKAGE = B::PV PREFIX = Sv
905
0b40bd6d
RH
906char*
907SvPVX(sv)
908 B::PV sv
909
a8a597b2
MB
910void
911SvPV(sv)
912 B::PV sv
913 CODE:
914 ST(0) = sv_newmortal();
915 sv_setpvn(ST(0), SvPVX(sv), SvCUR(sv));
746698c5 916 SvFLAGS(ST(0)) |= SvUTF8(sv);
a8a597b2 917
445a12f6
DM
918STRLEN
919SvLEN(sv)
920 B::PV sv
921
922STRLEN
923SvCUR(sv)
924 B::PV sv
925
a8a597b2
MB
926MODULE = B PACKAGE = B::PVMG PREFIX = Sv
927
928void
929SvMAGIC(sv)
930 B::PVMG sv
931 MAGIC * mg = NO_INIT
932 PPCODE:
933 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
cea2e8a9 934 XPUSHs(make_mg_object(aTHX_ sv_newmortal(), mg));
a8a597b2
MB
935
936MODULE = B PACKAGE = B::PVMG
937
938B::HV
939SvSTASH(sv)
940 B::PVMG sv
941
942#define MgMOREMAGIC(mg) mg->mg_moremagic
943#define MgPRIVATE(mg) mg->mg_private
944#define MgTYPE(mg) mg->mg_type
945#define MgFLAGS(mg) mg->mg_flags
946#define MgOBJ(mg) mg->mg_obj
88b39979 947#define MgLENGTH(mg) mg->mg_len
a8a597b2
MB
948
949MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
950
951B::MAGIC
952MgMOREMAGIC(mg)
953 B::MAGIC mg
954
955U16
956MgPRIVATE(mg)
957 B::MAGIC mg
958
959char
960MgTYPE(mg)
961 B::MAGIC mg
962
963U8
964MgFLAGS(mg)
965 B::MAGIC mg
966
967B::SV
968MgOBJ(mg)
969 B::MAGIC mg
970
88b39979
VB
971I32
972MgLENGTH(mg)
973 B::MAGIC mg
974
a8a597b2
MB
975void
976MgPTR(mg)
977 B::MAGIC mg
978 CODE:
979 ST(0) = sv_newmortal();
88b39979
VB
980 if (mg->mg_ptr){
981 if (mg->mg_len >= 0){
982 sv_setpvn(ST(0), mg->mg_ptr, mg->mg_len);
983 } else {
984 if (mg->mg_len == HEf_SVKEY)
985 sv_setsv(ST(0),newRV((SV*)mg->mg_ptr));
986 }
987 }
a8a597b2
MB
988
989MODULE = B PACKAGE = B::PVLV PREFIX = Lv
990
991U32
992LvTARGOFF(sv)
993 B::PVLV sv
994
995U32
996LvTARGLEN(sv)
997 B::PVLV sv
998
999char
1000LvTYPE(sv)
1001 B::PVLV sv
1002
1003B::SV
1004LvTARG(sv)
1005 B::PVLV sv
1006
1007MODULE = B PACKAGE = B::BM PREFIX = Bm
1008
1009I32
1010BmUSEFUL(sv)
1011 B::BM sv
1012
1013U16
1014BmPREVIOUS(sv)
1015 B::BM sv
1016
1017U8
1018BmRARE(sv)
1019 B::BM sv
1020
1021void
1022BmTABLE(sv)
1023 B::BM sv
1024 STRLEN len = NO_INIT
1025 char * str = NO_INIT
1026 CODE:
1027 str = SvPV(sv, len);
1028 /* Boyer-Moore table is just after string and its safety-margin \0 */
79cb57f6 1029 ST(0) = sv_2mortal(newSVpvn(str + len + 1, 256));
a8a597b2
MB
1030
1031MODULE = B PACKAGE = B::GV PREFIX = Gv
1032
1033void
1034GvNAME(gv)
1035 B::GV gv
1036 CODE:
79cb57f6 1037 ST(0) = sv_2mortal(newSVpvn(GvNAME(gv), GvNAMELEN(gv)));
a8a597b2 1038
87d7fd28
GS
1039bool
1040is_empty(gv)
1041 B::GV gv
1042 CODE:
1043 RETVAL = GvGP(gv) == Null(GP*);
1044 OUTPUT:
1045 RETVAL
1046
a8a597b2
MB
1047B::HV
1048GvSTASH(gv)
1049 B::GV gv
1050
1051B::SV
1052GvSV(gv)
1053 B::GV gv
1054
1055B::IO
1056GvIO(gv)
1057 B::GV gv
1058
1059B::CV
1060GvFORM(gv)
1061 B::GV gv
1062
1063B::AV
1064GvAV(gv)
1065 B::GV gv
1066
1067B::HV
1068GvHV(gv)
1069 B::GV gv
1070
1071B::GV
1072GvEGV(gv)
1073 B::GV gv
1074
1075B::CV
1076GvCV(gv)
1077 B::GV gv
1078
1079U32
1080GvCVGEN(gv)
1081 B::GV gv
1082
1083U16
1084GvLINE(gv)
1085 B::GV gv
1086
b195d487
GS
1087char *
1088GvFILE(gv)
1089 B::GV gv
1090
a8a597b2
MB
1091B::GV
1092GvFILEGV(gv)
1093 B::GV gv
1094
1095MODULE = B PACKAGE = B::GV
1096
1097U32
1098GvREFCNT(gv)
1099 B::GV gv
1100
1101U8
1102GvFLAGS(gv)
1103 B::GV gv
1104
1105MODULE = B PACKAGE = B::IO PREFIX = Io
1106
1107long
1108IoLINES(io)
1109 B::IO io
1110
1111long
1112IoPAGE(io)
1113 B::IO io
1114
1115long
1116IoPAGE_LEN(io)
1117 B::IO io
1118
1119long
1120IoLINES_LEFT(io)
1121 B::IO io
1122
1123char *
1124IoTOP_NAME(io)
1125 B::IO io
1126
1127B::GV
1128IoTOP_GV(io)
1129 B::IO io
1130
1131char *
1132IoFMT_NAME(io)
1133 B::IO io
1134
1135B::GV
1136IoFMT_GV(io)
1137 B::IO io
1138
1139char *
1140IoBOTTOM_NAME(io)
1141 B::IO io
1142
1143B::GV
1144IoBOTTOM_GV(io)
1145 B::IO io
1146
1147short
1148IoSUBPROCESS(io)
1149 B::IO io
1150
1151MODULE = B PACKAGE = B::IO
1152
1153char
1154IoTYPE(io)
1155 B::IO io
1156
1157U8
1158IoFLAGS(io)
1159 B::IO io
1160
1161MODULE = B PACKAGE = B::AV PREFIX = Av
1162
1163SSize_t
1164AvFILL(av)
1165 B::AV av
1166
1167SSize_t
1168AvMAX(av)
1169 B::AV av
1170
1171#define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off
1172
1173IV
1174AvOFF(av)
1175 B::AV av
1176
1177void
1178AvARRAY(av)
1179 B::AV av
1180 PPCODE:
1181 if (AvFILL(av) >= 0) {
1182 SV **svp = AvARRAY(av);
1183 I32 i;
1184 for (i = 0; i <= AvFILL(av); i++)
cea2e8a9 1185 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), svp[i]));
a8a597b2
MB
1186 }
1187
1188MODULE = B PACKAGE = B::AV
1189
1190U8
1191AvFLAGS(av)
1192 B::AV av
1193
1194MODULE = B PACKAGE = B::CV PREFIX = Cv
1195
1196B::HV
1197CvSTASH(cv)
1198 B::CV cv
1199
1200B::OP
1201CvSTART(cv)
1202 B::CV cv
1203
1204B::OP
1205CvROOT(cv)
1206 B::CV cv
1207
1208B::GV
1209CvGV(cv)
1210 B::CV cv
1211
57843af0
GS
1212char *
1213CvFILE(cv)
1214 B::CV cv
1215
a8a597b2
MB
1216long
1217CvDEPTH(cv)
1218 B::CV cv
1219
1220B::AV
1221CvPADLIST(cv)
1222 B::CV cv
1223
1224B::CV
1225CvOUTSIDE(cv)
1226 B::CV cv
1227
1228void
1229CvXSUB(cv)
1230 B::CV cv
1231 CODE:
56431972 1232 ST(0) = sv_2mortal(newSViv(PTR2IV(CvXSUB(cv))));
a8a597b2
MB
1233
1234
1235void
1236CvXSUBANY(cv)
1237 B::CV cv
1238 CODE:
1239 ST(0) = sv_2mortal(newSViv(CvXSUBANY(cv).any_iv));
1240
5cfd8ad4
VB
1241MODULE = B PACKAGE = B::CV
1242
6aaf4108 1243U16
5cfd8ad4
VB
1244CvFLAGS(cv)
1245 B::CV cv
1246
de3f1649
JT
1247MODULE = B PACKAGE = B::CV PREFIX = cv_
1248
1249B::SV
1250cv_const_sv(cv)
1251 B::CV cv
1252
5cfd8ad4 1253
a8a597b2
MB
1254MODULE = B PACKAGE = B::HV PREFIX = Hv
1255
1256STRLEN
1257HvFILL(hv)
1258 B::HV hv
1259
1260STRLEN
1261HvMAX(hv)
1262 B::HV hv
1263
1264I32
1265HvKEYS(hv)
1266 B::HV hv
1267
1268I32
1269HvRITER(hv)
1270 B::HV hv
1271
1272char *
1273HvNAME(hv)
1274 B::HV hv
1275
1276B::PMOP
1277HvPMROOT(hv)
1278 B::HV hv
1279
1280void
1281HvARRAY(hv)
1282 B::HV hv
1283 PPCODE:
1284 if (HvKEYS(hv) > 0) {
1285 SV *sv;
1286 char *key;
1287 I32 len;
1288 (void)hv_iterinit(hv);
1289 EXTEND(sp, HvKEYS(hv) * 2);
8063af02 1290 while ((sv = hv_iternextsv(hv, &key, &len))) {
79cb57f6 1291 PUSHs(newSVpvn(key, len));
cea2e8a9 1292 PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv));
a8a597b2
MB
1293 }
1294 }