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