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