newCONSTSUB added (XSUB equivalent for inlinable sub () { 123 }).
authorJan Dubois <jand@activestate.com>
Sun, 15 Mar 1998 19:09:05 +0000 (20:09 +0100)
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>
Mon, 16 Mar 1998 16:18:35 +0000 (16:18 +0000)
Subject: Bundling builtin.pm and newCONSTSUB with the core?

p4raw-id: //depot/perl@821

embed.h
global.sym
op.c
pod/perlguts.pod
proto.h

diff --git a/embed.h b/embed.h
index caea84b..64e464d 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define newAVREF               Perl_newAVREF
 #define newBINOP               Perl_newBINOP
 #define newCONDOP              Perl_newCONDOP
+#define newCONSTSUB            Perl_newCONSTSUB
 #define newCVREF               Perl_newCVREF
 #define newFORM                        Perl_newFORM
 #define newFOROP               Perl_newFOROP
index a2edeef..26c2528 100644 (file)
@@ -459,6 +459,7 @@ newAV
 newAVREF
 newBINOP
 newCONDOP
+newCONSTSUB
 newCVREF
 newFORM
 newFOROP
diff --git a/op.c b/op.c
index 11c17d7..0ee2e5e 100644 (file)
--- a/op.c
+++ b/op.c
@@ -3516,6 +3516,33 @@ newSUB(I32 floor, OP *o, OP *proto, OP *block)
     return cv;
 }
 
+void
+newCONSTSUB(HV *stash, char *name, SV *sv)
+{
+    dTHR;
+    U32 oldhints = hints;
+    HV *old_cop_stash = curcop->cop_stash;
+    HV *old_curstash = curstash;
+    line_t oldline = curcop->cop_line;
+    curcop->cop_line = copline;
+
+    hints &= ~HINT_BLOCK_SCOPE;
+    if(stash)
+       curstash = curcop->cop_stash = stash;
+
+    newSUB(
+       MY_start_subparse(FALSE, 0),
+       newSVOP(OP_CONST, 0, newSVpv(name,0)),
+       newSVOP(OP_CONST, 0, &sv_no),   /* SvPV(&sv_no) == "" -- GMB */
+       newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
+    );
+
+    hints = oldhints;
+    curcop->cop_stash = old_cop_stash;
+    curstash = old_curstash;
+    curcop->cop_line = oldline;
+}
+
 CV *
 newXS(char *name, void (*subaddr) (CV *), char *filename)
 {
index 0fa7445..e84e7e5 100644 (file)
@@ -2121,6 +2121,13 @@ The XSUB-writer's interface to the C C<malloc> function, with cast.
 
        void*   Newc( x, void *ptr, int size, type, cast )
 
+=item newCONSTSUB
+
+Creates a constant sub equivalent to Perl C<sub FOO () { 123 }>
+which is eligible for inlining at compile-time.
+
+       void    newCONSTSUB(HV* stash, char* name, SV* sv)
+
 =item newHV
 
 Creates a new HV.  The reference count is set to 1.
diff --git a/proto.h b/proto.h
index 8f2fb14..5754f5b 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -302,6 +302,7 @@ OP* newANONHASH _((OP* o));
 OP*    newANONSUB _((I32 floor, OP* proto, OP* block));
 OP*    newASSIGNOP _((I32 flags, OP* left, I32 optype, OP* right));
 OP*    newCONDOP _((I32 flags, OP* expr, OP* trueop, OP* falseop));
+void   newCONSTSUB _((HV* stash, char* name, SV* sv));
 void   newFORM _((I32 floor, OP* o, OP* block));
 OP*    newFOROP _((I32 flags, char* label, line_t forline, OP* scalar, OP* expr, OP*block, OP*cont));
 OP*    newLOGOP _((I32 optype, I32 flags, OP* left, OP* right));