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