develooper Front page | perl.perl5.porters | Postings from July 2001

[PATCH] Turn off constant folding and optimization

Thread Next
From:
Simon Cozens
Date:
July 23, 2001 20:13
Subject:
[PATCH] Turn off constant folding and optimization
Message ID:
20010723230508.A2677@netthink.co.uk
This makes B::Deparse DTRT with constants:

./perl -Ilib -MO=Deparse -e 'print 3+5'

No, I'm not hacking in the middle of the P5P meeting.

--- sv.c~	Mon Jul 23 22:48:04 2001
+++ sv.c	Mon Jul 23 22:48:11 2001
@@ -9752,6 +9752,7 @@
 
     /* switches */
     PL_minus_c		= proto_perl->Iminus_c;
+    PL_no_optimize	= proto_perl->Ino_optimize;
     PL_patchlevel	= sv_dup_inc(proto_perl->Ipatchlevel, param);
     PL_localpatches	= proto_perl->Ilocalpatches;
     PL_splitstr		= proto_perl->Isplitstr;
--- intrpvar.h~	Mon Jul 23 22:46:06 2001
+++ intrpvar.h	Mon Jul 23 22:46:42 2001
@@ -22,6 +22,7 @@
 
 /* switches */
 PERLVAR(Iminus_c,	bool)
+PERLVAR(Ino_optimize, bool)
 PERLVAR(Ipatchlevel,	SV *)
 PERLVAR(Ilocalpatches,	char **)
 PERLVARI(Isplitstr,	char *,	" ")
--- op.c~	Mon Jul 23 22:49:12 2001
+++ op.c	Mon Jul 23 22:49:57 2001
@@ -2263,7 +2263,7 @@
 	o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)];
     }
 
-    if (!(PL_opargs[type] & OA_FOLDCONST))
+    if (!(PL_opargs[type] & OA_FOLDCONST) || PL_no_optimize)
 	goto nope;
 
     switch (type) {
@@ -6700,7 +6700,7 @@
     register OP* oldop = 0;
     STRLEN n_a;
 
-    if (!o || o->op_seq)
+    if (!o || o->op_seq || PL_no_optimize)
 	return;
     ENTER;
     SAVEOP();
--- ext/B/B.xs~	Mon Jul 23 22:50:11 2001
+++ ext/B/B.xs	Mon Jul 23 22:51:11 2001
@@ -526,6 +526,11 @@
 	PL_minus_c = TRUE;
 
 void
+no_optimize()
+    CODE:
+	PL_no_optimize = TRUE;
+
+void
 save_BEGINs()
     CODE:
 	PL_minus_c |= 0x10;
--- ext/B/B.pm~	Mon Jul 23 22:55:11 2001
+++ ext/B/B.pm	Mon Jul 23 22:56:13 2001
@@ -12,7 +12,7 @@
 
 # walkoptree_slow comes from B.pm (you are there),
 # walkoptree comes from B.xs
-@EXPORT_OK = qw(minus_c ppname save_BEGINs
+@EXPORT_OK = qw(minus_c no_optimize ppname save_BEGINs
 		class peekop cast_I32 cstring cchar hash threadsv_names
 		main_root main_start main_cv svref_2object opnumber
 		amagic_generation
--- ext/B/B/Deparse.pm~	Mon Jul 23 22:56:53 2001
+++ ext/B/B/Deparse.pm	Mon Jul 23 23:01:06 2001
@@ -523,10 +523,11 @@
     delete $self->{'subs_declared'};
 }
 
+B::no_optimize();
+
 sub compile {
     my(@args) = @_;
     return sub { 
 	my $self = B::Deparse->new(@args);
 	my @BEGINs  = B::begin_av->isa("B::AV") ? B::begin_av->ARRAY : ();
 	my @INITs   = B::init_av->isa("B::AV") ? B::init_av->ARRAY : ();

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About