Commit | Line | Data |
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 |
25 | typedef PerlIO * InputStream; |
26 | #else |
27 | typedef FILE * InputStream; |
28 | #endif |
29 | |
30 | |
a8a597b2 |
31 | static 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 | |
50 | typedef 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 | |
67 | static 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 | |
84 | static int walkoptree_debug = 0; /* Flag for walkoptree debug hook */ |
85 | |
86 | static opclass |
87 | cc_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 | |
180 | static char * |
181 | cc_opclassname(OP *o) |
182 | { |
183 | return opclassnames[cc_opclass(o)]; |
184 | } |
185 | |
186 | static SV * |
187 | make_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 | |
206 | static SV * |
207 | make_mg_object(SV *arg, MAGIC *mg) |
208 | { |
209 | sv_setiv(newSVrv(arg, "B::MAGIC"), (IV)mg); |
210 | return arg; |
211 | } |
212 | |
213 | static SV * |
214 | cstring(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 | |
266 | static SV * |
267 | cchar(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 |
307 | void 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 |
315 | void 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 | |
325 | static int fgetc_fromstring(void *data) |
326 | { |
327 | char **strp = (char **)data; |
328 | return *(*strp)++; |
329 | } |
330 | |
331 | static 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 | |
342 | static 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 | |
353 | void 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 |
363 | void byteload_fh(InputStream fp) |
a8a597b2 |
364 | { |
365 | byterun(fp); |
366 | } |
367 | |
368 | void byteload_string(char *str) |
369 | { |
370 | croak("Must compile with -DINDIRECT_BGET_MACROS for byteload_string"); |
371 | } |
372 | #endif /* INDIRECT_BGET_MACROS */ |
373 | |
374 | void |
375 | walkoptree(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 | |
404 | typedef OP *B__OP; |
405 | typedef UNOP *B__UNOP; |
406 | typedef BINOP *B__BINOP; |
407 | typedef LOGOP *B__LOGOP; |
408 | typedef CONDOP *B__CONDOP; |
409 | typedef LISTOP *B__LISTOP; |
410 | typedef PMOP *B__PMOP; |
411 | typedef SVOP *B__SVOP; |
412 | typedef GVOP *B__GVOP; |
413 | typedef PVOP *B__PVOP; |
414 | typedef LOOP *B__LOOP; |
415 | typedef COP *B__COP; |
416 | |
417 | typedef SV *B__SV; |
418 | typedef SV *B__IV; |
419 | typedef SV *B__PV; |
420 | typedef SV *B__NV; |
421 | typedef SV *B__PVMG; |
422 | typedef SV *B__PVLV; |
423 | typedef SV *B__BM; |
424 | typedef SV *B__RV; |
425 | typedef AV *B__AV; |
426 | typedef HV *B__HV; |
427 | typedef CV *B__CV; |
428 | typedef GV *B__GV; |
429 | typedef IO *B__IO; |
430 | |
431 | typedef MAGIC *B__MAGIC; |
432 | |
433 | MODULE = B PACKAGE = B PREFIX = B_ |
434 | |
435 | PROTOTYPES: DISABLE |
436 | |
437 | BOOT: |
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 |
449 | B::AV |
450 | B_init_av() |
451 | |
a8a597b2 |
452 | B::CV |
453 | B_main_cv() |
454 | |
455 | B::OP |
456 | B_main_root() |
457 | |
458 | B::OP |
459 | B_main_start() |
460 | |
461 | B::AV |
462 | B_comppadlist() |
463 | |
464 | B::SV |
465 | B_sv_undef() |
466 | |
467 | B::SV |
468 | B_sv_yes() |
469 | |
470 | B::SV |
471 | B_sv_no() |
472 | |
473 | MODULE = B PACKAGE = B |
474 | |
475 | |
476 | void |
477 | walkoptree(opsv, method) |
478 | SV * opsv |
479 | char * method |
480 | |
481 | int |
482 | walkoptree_debug(...) |
483 | CODE: |
484 | RETVAL = walkoptree_debug; |
485 | if (items > 0 && SvTRUE(ST(1))) |
486 | walkoptree_debug = 1; |
487 | OUTPUT: |
488 | RETVAL |
489 | |
490 | int |
491 | byteload_fh(fp) |
51aa15f3 |
492 | InputStream fp |
a8a597b2 |
493 | CODE: |
494 | byteload_fh(fp); |
495 | RETVAL = 1; |
496 | OUTPUT: |
497 | RETVAL |
498 | |
499 | void |
500 | byteload_string(str) |
501 | char * str |
502 | |
503 | #define address(sv) (IV)sv |
504 | |
505 | IV |
506 | address(sv) |
507 | SV * sv |
508 | |
509 | B::SV |
510 | svref_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 | |
519 | void |
520 | opnumber(name) |
521 | char * name |
522 | CODE: |
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 | |
540 | void |
541 | ppname(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 | |
550 | void |
551 | hash(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 |
564 | IV |
565 | cast_I32(i) |
566 | IV i |
567 | |
568 | void |
569 | minus_c() |
570 | CODE: |
3280af22 |
571 | PL_minus_c = TRUE; |
a8a597b2 |
572 | |
573 | SV * |
574 | cstring(sv) |
575 | SV * sv |
576 | |
577 | SV * |
578 | cchar(sv) |
579 | SV * sv |
580 | |
581 | void |
582 | threadsv_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 | |
603 | MODULE = B PACKAGE = B::OP PREFIX = OP_ |
604 | |
605 | B::OP |
606 | OP_next(o) |
607 | B::OP o |
608 | |
609 | B::OP |
610 | OP_sibling(o) |
611 | B::OP o |
612 | |
613 | char * |
614 | OP_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 | |
621 | char * |
622 | OP_desc(o) |
623 | B::OP o |
624 | |
625 | U16 |
626 | OP_targ(o) |
627 | B::OP o |
628 | |
629 | U16 |
630 | OP_type(o) |
631 | B::OP o |
632 | |
633 | U16 |
634 | OP_seq(o) |
635 | B::OP o |
636 | |
637 | U8 |
638 | OP_flags(o) |
639 | B::OP o |
640 | |
641 | U8 |
642 | OP_private(o) |
643 | B::OP o |
644 | |
645 | #define UNOP_first(o) o->op_first |
646 | |
647 | MODULE = B PACKAGE = B::UNOP PREFIX = UNOP_ |
648 | |
649 | B::OP |
650 | UNOP_first(o) |
651 | B::UNOP o |
652 | |
653 | #define BINOP_last(o) o->op_last |
654 | |
655 | MODULE = B PACKAGE = B::BINOP PREFIX = BINOP_ |
656 | |
657 | B::OP |
658 | BINOP_last(o) |
659 | B::BINOP o |
660 | |
661 | #define LOGOP_other(o) o->op_other |
662 | |
663 | MODULE = B PACKAGE = B::LOGOP PREFIX = LOGOP_ |
664 | |
665 | B::OP |
666 | LOGOP_other(o) |
667 | B::LOGOP o |
668 | |
669 | #define CONDOP_true(o) o->op_true |
670 | #define CONDOP_false(o) o->op_false |
671 | |
672 | MODULE = B PACKAGE = B::CONDOP PREFIX = CONDOP_ |
673 | |
674 | B::OP |
675 | CONDOP_true(o) |
676 | B::CONDOP o |
677 | |
678 | B::OP |
679 | CONDOP_false(o) |
680 | B::CONDOP o |
681 | |
682 | #define LISTOP_children(o) o->op_children |
683 | |
684 | MODULE = B PACKAGE = B::LISTOP PREFIX = LISTOP_ |
685 | |
686 | U32 |
687 | LISTOP_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 | |
697 | MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_ |
698 | |
699 | void |
700 | PMOP_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 | |
716 | B::OP |
717 | PMOP_pmreplstart(o) |
718 | B::PMOP o |
719 | |
720 | B::PMOP |
721 | PMOP_pmnext(o) |
722 | B::PMOP o |
723 | |
724 | U16 |
725 | PMOP_pmflags(o) |
726 | B::PMOP o |
727 | |
728 | U16 |
729 | PMOP_pmpermflags(o) |
730 | B::PMOP o |
731 | |
732 | void |
733 | PMOP_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 | |
744 | MODULE = B PACKAGE = B::SVOP PREFIX = SVOP_ |
745 | |
746 | |
747 | B::SV |
748 | SVOP_sv(o) |
749 | B::SVOP o |
750 | |
751 | #define GVOP_gv(o) o->op_gv |
752 | |
753 | MODULE = B PACKAGE = B::GVOP PREFIX = GVOP_ |
754 | |
755 | |
756 | B::GV |
757 | GVOP_gv(o) |
758 | B::GVOP o |
759 | |
760 | MODULE = B PACKAGE = B::PVOP PREFIX = PVOP_ |
761 | |
762 | void |
763 | PVOP_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 | |
777 | MODULE = B PACKAGE = B::LOOP PREFIX = LOOP_ |
778 | |
779 | |
780 | B::OP |
781 | LOOP_redoop(o) |
782 | B::LOOP o |
783 | |
784 | B::OP |
785 | LOOP_nextop(o) |
786 | B::LOOP o |
787 | |
788 | B::OP |
789 | LOOP_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 | |
799 | MODULE = B PACKAGE = B::COP PREFIX = COP_ |
800 | |
801 | char * |
802 | COP_label(o) |
803 | B::COP o |
804 | |
805 | B::HV |
806 | COP_stash(o) |
807 | B::COP o |
808 | |
809 | B::GV |
810 | COP_filegv(o) |
811 | B::COP o |
812 | |
813 | U32 |
814 | COP_cop_seq(o) |
815 | B::COP o |
816 | |
817 | I32 |
818 | COP_arybase(o) |
819 | B::COP o |
820 | |
821 | U16 |
822 | COP_line(o) |
823 | B::COP o |
824 | |
825 | MODULE = B PACKAGE = B::SV PREFIX = Sv |
826 | |
827 | U32 |
828 | SvREFCNT(sv) |
829 | B::SV sv |
830 | |
831 | U32 |
832 | SvFLAGS(sv) |
833 | B::SV sv |
834 | |
835 | MODULE = B PACKAGE = B::IV PREFIX = Sv |
836 | |
837 | IV |
838 | SvIV(sv) |
839 | B::IV sv |
840 | |
841 | IV |
842 | SvIVX(sv) |
843 | B::IV sv |
844 | |
845 | MODULE = B PACKAGE = B::IV |
846 | |
847 | #define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv)) |
848 | |
849 | int |
850 | needs64bits(sv) |
851 | B::IV sv |
852 | |
853 | void |
854 | packiv(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 | |
875 | MODULE = B PACKAGE = B::NV PREFIX = Sv |
876 | |
877 | double |
878 | SvNV(sv) |
879 | B::NV sv |
880 | |
881 | double |
882 | SvNVX(sv) |
883 | B::NV sv |
884 | |
885 | MODULE = B PACKAGE = B::RV PREFIX = Sv |
886 | |
887 | B::SV |
888 | SvRV(sv) |
889 | B::RV sv |
890 | |
891 | MODULE = B PACKAGE = B::PV PREFIX = Sv |
892 | |
893 | void |
894 | SvPV(sv) |
895 | B::PV sv |
896 | CODE: |
897 | ST(0) = sv_newmortal(); |
898 | sv_setpvn(ST(0), SvPVX(sv), SvCUR(sv)); |
899 | |
900 | MODULE = B PACKAGE = B::PVMG PREFIX = Sv |
901 | |
902 | void |
903 | SvMAGIC(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 | |
910 | MODULE = B PACKAGE = B::PVMG |
911 | |
912 | B::HV |
913 | SvSTASH(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 | |
922 | MODULE = B PACKAGE = B::MAGIC PREFIX = Mg |
923 | |
924 | B::MAGIC |
925 | MgMOREMAGIC(mg) |
926 | B::MAGIC mg |
927 | |
928 | U16 |
929 | MgPRIVATE(mg) |
930 | B::MAGIC mg |
931 | |
932 | char |
933 | MgTYPE(mg) |
934 | B::MAGIC mg |
935 | |
936 | U8 |
937 | MgFLAGS(mg) |
938 | B::MAGIC mg |
939 | |
940 | B::SV |
941 | MgOBJ(mg) |
942 | B::MAGIC mg |
943 | |
944 | void |
945 | MgPTR(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 | |
952 | MODULE = B PACKAGE = B::PVLV PREFIX = Lv |
953 | |
954 | U32 |
955 | LvTARGOFF(sv) |
956 | B::PVLV sv |
957 | |
958 | U32 |
959 | LvTARGLEN(sv) |
960 | B::PVLV sv |
961 | |
962 | char |
963 | LvTYPE(sv) |
964 | B::PVLV sv |
965 | |
966 | B::SV |
967 | LvTARG(sv) |
968 | B::PVLV sv |
969 | |
970 | MODULE = B PACKAGE = B::BM PREFIX = Bm |
971 | |
972 | I32 |
973 | BmUSEFUL(sv) |
974 | B::BM sv |
975 | |
976 | U16 |
977 | BmPREVIOUS(sv) |
978 | B::BM sv |
979 | |
980 | U8 |
981 | BmRARE(sv) |
982 | B::BM sv |
983 | |
984 | void |
985 | BmTABLE(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 | |
994 | MODULE = B PACKAGE = B::GV PREFIX = Gv |
995 | |
996 | void |
997 | GvNAME(gv) |
998 | B::GV gv |
999 | CODE: |
1000 | ST(0) = sv_2mortal(newSVpv(GvNAME(gv), GvNAMELEN(gv))); |
1001 | |
1002 | B::HV |
1003 | GvSTASH(gv) |
1004 | B::GV gv |
1005 | |
1006 | B::SV |
1007 | GvSV(gv) |
1008 | B::GV gv |
1009 | |
1010 | B::IO |
1011 | GvIO(gv) |
1012 | B::GV gv |
1013 | |
1014 | B::CV |
1015 | GvFORM(gv) |
1016 | B::GV gv |
1017 | |
1018 | B::AV |
1019 | GvAV(gv) |
1020 | B::GV gv |
1021 | |
1022 | B::HV |
1023 | GvHV(gv) |
1024 | B::GV gv |
1025 | |
1026 | B::GV |
1027 | GvEGV(gv) |
1028 | B::GV gv |
1029 | |
1030 | B::CV |
1031 | GvCV(gv) |
1032 | B::GV gv |
1033 | |
1034 | U32 |
1035 | GvCVGEN(gv) |
1036 | B::GV gv |
1037 | |
1038 | U16 |
1039 | GvLINE(gv) |
1040 | B::GV gv |
1041 | |
1042 | B::GV |
1043 | GvFILEGV(gv) |
1044 | B::GV gv |
1045 | |
1046 | MODULE = B PACKAGE = B::GV |
1047 | |
1048 | U32 |
1049 | GvREFCNT(gv) |
1050 | B::GV gv |
1051 | |
1052 | U8 |
1053 | GvFLAGS(gv) |
1054 | B::GV gv |
1055 | |
1056 | MODULE = B PACKAGE = B::IO PREFIX = Io |
1057 | |
1058 | long |
1059 | IoLINES(io) |
1060 | B::IO io |
1061 | |
1062 | long |
1063 | IoPAGE(io) |
1064 | B::IO io |
1065 | |
1066 | long |
1067 | IoPAGE_LEN(io) |
1068 | B::IO io |
1069 | |
1070 | long |
1071 | IoLINES_LEFT(io) |
1072 | B::IO io |
1073 | |
1074 | char * |
1075 | IoTOP_NAME(io) |
1076 | B::IO io |
1077 | |
1078 | B::GV |
1079 | IoTOP_GV(io) |
1080 | B::IO io |
1081 | |
1082 | char * |
1083 | IoFMT_NAME(io) |
1084 | B::IO io |
1085 | |
1086 | B::GV |
1087 | IoFMT_GV(io) |
1088 | B::IO io |
1089 | |
1090 | char * |
1091 | IoBOTTOM_NAME(io) |
1092 | B::IO io |
1093 | |
1094 | B::GV |
1095 | IoBOTTOM_GV(io) |
1096 | B::IO io |
1097 | |
1098 | short |
1099 | IoSUBPROCESS(io) |
1100 | B::IO io |
1101 | |
1102 | MODULE = B PACKAGE = B::IO |
1103 | |
1104 | char |
1105 | IoTYPE(io) |
1106 | B::IO io |
1107 | |
1108 | U8 |
1109 | IoFLAGS(io) |
1110 | B::IO io |
1111 | |
1112 | MODULE = B PACKAGE = B::AV PREFIX = Av |
1113 | |
1114 | SSize_t |
1115 | AvFILL(av) |
1116 | B::AV av |
1117 | |
1118 | SSize_t |
1119 | AvMAX(av) |
1120 | B::AV av |
1121 | |
1122 | #define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off |
1123 | |
1124 | IV |
1125 | AvOFF(av) |
1126 | B::AV av |
1127 | |
1128 | void |
1129 | AvARRAY(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 | |
1139 | MODULE = B PACKAGE = B::AV |
1140 | |
1141 | U8 |
1142 | AvFLAGS(av) |
1143 | B::AV av |
1144 | |
1145 | MODULE = B PACKAGE = B::CV PREFIX = Cv |
1146 | |
1147 | B::HV |
1148 | CvSTASH(cv) |
1149 | B::CV cv |
1150 | |
1151 | B::OP |
1152 | CvSTART(cv) |
1153 | B::CV cv |
1154 | |
1155 | B::OP |
1156 | CvROOT(cv) |
1157 | B::CV cv |
1158 | |
1159 | B::GV |
1160 | CvGV(cv) |
1161 | B::CV cv |
1162 | |
1163 | B::GV |
1164 | CvFILEGV(cv) |
1165 | B::CV cv |
1166 | |
1167 | long |
1168 | CvDEPTH(cv) |
1169 | B::CV cv |
1170 | |
1171 | B::AV |
1172 | CvPADLIST(cv) |
1173 | B::CV cv |
1174 | |
1175 | B::CV |
1176 | CvOUTSIDE(cv) |
1177 | B::CV cv |
1178 | |
1179 | void |
1180 | CvXSUB(cv) |
1181 | B::CV cv |
1182 | CODE: |
1183 | ST(0) = sv_2mortal(newSViv((IV)CvXSUB(cv))); |
1184 | |
1185 | |
1186 | void |
1187 | CvXSUBANY(cv) |
1188 | B::CV cv |
1189 | CODE: |
1190 | ST(0) = sv_2mortal(newSViv(CvXSUBANY(cv).any_iv)); |
1191 | |
5cfd8ad4 |
1192 | MODULE = B PACKAGE = B::CV |
1193 | |
1194 | U8 |
1195 | CvFLAGS(cv) |
1196 | B::CV cv |
1197 | |
1198 | |
a8a597b2 |
1199 | MODULE = B PACKAGE = B::HV PREFIX = Hv |
1200 | |
1201 | STRLEN |
1202 | HvFILL(hv) |
1203 | B::HV hv |
1204 | |
1205 | STRLEN |
1206 | HvMAX(hv) |
1207 | B::HV hv |
1208 | |
1209 | I32 |
1210 | HvKEYS(hv) |
1211 | B::HV hv |
1212 | |
1213 | I32 |
1214 | HvRITER(hv) |
1215 | B::HV hv |
1216 | |
1217 | char * |
1218 | HvNAME(hv) |
1219 | B::HV hv |
1220 | |
1221 | B::PMOP |
1222 | HvPMROOT(hv) |
1223 | B::HV hv |
1224 | |
1225 | void |
1226 | HvARRAY(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 | } |