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