From: Jan Dubois Date: Sun, 15 Mar 1998 19:09:05 +0000 (+0100) Subject: newCONSTSUB added (XSUB equivalent for inlinable sub () { 123 }). X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5476c4332a5540db7fc38bfabed95022b6c04b1b;p=p5sagit%2Fp5-mst-13.2.git newCONSTSUB added (XSUB equivalent for inlinable sub () { 123 }). Subject: Bundling builtin.pm and newCONSTSUB with the core? p4raw-id: //depot/perl@821 --- diff --git a/embed.h b/embed.h index caea84b..64e464d 100644 --- a/embed.h +++ b/embed.h @@ -367,6 +367,7 @@ #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 diff --git a/global.sym b/global.sym index a2edeef..26c2528 100644 --- a/global.sym +++ b/global.sym @@ -459,6 +459,7 @@ newAV newAVREF newBINOP newCONDOP +newCONSTSUB newCVREF newFORM newFOROP diff --git a/op.c b/op.c index 11c17d7..0ee2e5e 100644 --- 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) { diff --git a/pod/perlguts.pod b/pod/perlguts.pod index 0fa7445..e84e7e5 100644 --- a/pod/perlguts.pod +++ b/pod/perlguts.pod @@ -2121,6 +2121,13 @@ The XSUB-writer's interface to the C C function, with cast. void* Newc( x, void *ptr, int size, type, cast ) +=item newCONSTSUB + +Creates a constant sub equivalent to Perl C +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 --- 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));