[Jifty-commit] r5730 - in B-OP-Util: lib/B/OP

Jifty commits jifty-commit at lists.jifty.org
Sat Aug 16 07:45:03 EDT 2008


Author: clkao
Date: Sat Aug 16 07:45:01 2008
New Revision: 5730

Removed:
   B-OP-Util/typemap
Modified:
   B-OP-Util/Util.xs
   B-OP-Util/lib/B/OP/Util.pm

Log:
B::OP::Util

Modified: B-OP-Util/Util.xs
==============================================================================
--- B-OP-Util/Util.xs	(original)
+++ B-OP-Util/Util.xs	Sat Aug 16 07:45:01 2008
@@ -3,22 +3,6 @@
 #include "XSUB.h"
 #include "BUtils.h"
 
-typedef OP      *B__OP;
-typedef CV      *B__CV;
-
-static char *
-cc_opclassname(pTHX_ const OP *o)
-{
-    return BUtils_cc_opclassname(aTHX_ o);
-}
-
-
-static SV *
-make_sv_object(pTHX_ SV *arg, SV *sv)
-{
-    return BUtils_make_sv_object(aTHX_ arg, sv);
-}
-
 /* Stolen from pp_ctl.c (with modifications) */
 
 I32
@@ -131,6 +115,13 @@
   OUTPUT:
     RETVAL
 
+B::OP
+return_op(I32 uplevel)
+  CODE:
+    RETVAL = find_return_op(aTHX_ uplevel);
+  OUTPUT:
+    RETVAL
+
 #define PERL_CORE
 #include "embed.h"
 

Modified: B-OP-Util/lib/B/OP/Util.pm
==============================================================================
--- B-OP-Util/lib/B/OP/Util.pm	(original)
+++ B-OP-Util/lib/B/OP/Util.pm	Sat Aug 16 07:45:01 2008
@@ -9,11 +9,101 @@
 require DynaLoader;
 our $VERSION = '0.01';
 our @ISA = qw(Exporter DynaLoader);
-our @EXPORT = qw(parent_op);
+our @EXPORT = qw(parent_op return_op);
+use B::Utils '0.06';
+
 bootstrap B::OP::Util $VERSION;
 
 *B::CV::NEW_with_start = *CvNEW_with_start;
 
 sub dl_load_flags {0x01}
 
+=head1 NAME
+
+B::OP::Util - op related utility functions for perl
+
+=head1 SYNOPSIS
+
+  use B::OP::Util qw(parent_op return_op);
+  sub foo {
+    my $pop = parent_op(0);
+    my $rop = return_op(0);
+  }
+
+=head1 DESCRIPTION
+
+  sub foo {
+    dothis(1);
+    find_things();
+    return;
+  }
+
+has the following optree:
+
+ d  <1> leavesub[1 ref] K/REFC,1 ->(end)
+ -     <@> lineseq KP ->d
+ 1        <;> nextstate(main -371 bah.pl:8) v/2 ->2
+ 5        <1> entersub[t2] vKS/TARG,3 ->6
+ -           <1> ex-list K ->5
+ 2              <0> pushmark s ->3
+ 3              <$> const[IV 1] sM ->4
+ -              <1> ex-rv2cv sK/3 ->-
+ 4                 <#> gv[*dothis] s ->5
+ 6        <;> nextstate(main -371 bah.pl:9) v/2 ->7
+
+ 9        <1> entersub[t4] vKS/TARG,3 ->a
+ -           <1> ex-list K ->9
+ 7              <0> pushmark s ->8
+ -              <1> ex-rv2cv sK/3 ->-
+ 8                 <#> gv[*find_things] s/EARLYCV ->9
+
+ a        <;> nextstate(main -371 bah.pl:10) v/2 ->b
+ c        <@> return K ->d
+ b           <0> pushmark s ->c
+
+The C<find_things> in C<foo> is called in the C<entersub> in #9.  If
+you call C<parent_op> function with level 0, you get the C<nextstate>
+op that is before the entersub, which is #6.  And C<return_op> gives
+you the next op that the caller is returning to, in this case, the
+C<nextstate> in #a.
+
+=head2 EXPORTED PERL FUNCTIONS
+
+=over
+
+=item parent_op($lv)
+
+In runtime, returns the L<B::OP> object whose next is the C<entersub> of the current context up level C<$lv>
+
+=item return_op($lv)
+
+In runtime, returns the L<B::OP> object that the current context is returning to at level C<$lv>
+
+=back
+
+=head2 B::CV METHODS
+
+=over
+
+=item $cv->NEW_with_start($root, $start)
+
+Clone the C<$cv> but with different C<$root> and C<$start>
+
+=back
+
+=head1 AUTHORS
+
+Chia-liang Kao E<lt>clkao at clkao.orgE<gt>
+
+=head1 COPYRIGHT
+
+Copyright 2008 by Chia-liang Kao
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+See L<http://www.perl.com/perl/misc/Artistic.html>
+
+=cut
+
 1;


More information about the Jifty-commit mailing list