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