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

[PATCH @8436] Eliminate op_children

Thread Next
From:
Stephen McCamant
Date:
January 14, 2001 03:00
Subject:
[PATCH @8436] Eliminate op_children
Message ID:
14945.32919.44271.685122@soda.csua.berkeley.edu
This a finished version of a change I started working quite a while
ago -- getting rid of the op_children field in LISTOPs. This field
isn't really used anywhere, but I've kept the B interface so that B::
modules don't have to be changed (the replacement version doesn't
give the same answer in some situations, but that won't make a
difference for any of the B:: modules I know about). I did remove
op_children from the bytecode specification, though, since it wasn't
immediately obvious how to tell it to just ignore a certain opcode.

With this change, the BINOP and LISTOP structures look the same, but
there are two reasons I didn't merge them. The first is that I also
think it would be a good idea to get rid of the BINOP (but not LISTOP) 
op_last, so it would then be UNOP and BINOP that merged. Second,
merging OP classes seems like a fair amount of work, and I think it
only makes sense when the end result is that the code is easier to
understand. The current separation into unary, binary, and list OPs
seems to be a useful division for understanding, which might as well
stick around even if it doesn't reflect a difference in storage
layout.

 -- Stephen McC

--- op.h.orig	Sat Jan 13 16:21:13 2001
+++ op.h	Sun Jan 14 01:56:51 2001
@@ -229,14 +229,12 @@ struct listop {
     BASEOP
     OP *	op_first;
     OP *	op_last;
-    U32		op_children;
 };
 
 struct pmop {
     BASEOP
     OP *	op_first;
     OP *	op_last;
-    U32		op_children;
     OP *	op_pmreplroot;
     OP *	op_pmreplstart;
     PMOP *	op_pmnext;		/* list of all scanpats */
@@ -292,7 +290,6 @@ struct loop {
     BASEOP
     OP *	op_first;
     OP *	op_last;
-    U32		op_children;
     OP *	op_redoop;
     OP *	op_nextop;
     OP *	op_lastop;
--- op.c.orig	Sat Jan 13 16:21:13 2001
+++ op.c	Sun Jan 14 02:02:42 2001
@@ -2410,13 +2410,6 @@ Perl_convert(pTHX_ I32 type, I32 flags, 
     if (o->op_type != type)
 	return o;
 
-    if (cLISTOPo->op_children < 7) {
-	/* XXX do we really need to do this if we're done appending?? */
-	for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
-	    last = kid;
-	cLISTOPo->op_last = last;	/* in case check substituted last arg */
-    }
-
     return fold_constants(o);
 }
 
@@ -2444,7 +2437,6 @@ Perl_append_elem(pTHX_ I32 type, OP *fir
 	((LISTOP*)first)->op_first = last;
     }
     ((LISTOP*)first)->op_last = last;
-    ((LISTOP*)first)->op_children++;
     return first;
 }
 
@@ -2465,9 +2457,7 @@ Perl_append_list(pTHX_ I32 type, LISTOP 
 
     first->op_last->op_sibling = last->op_first;
     first->op_last = last->op_last;
-    first->op_children += last->op_children;
-    if (first->op_children)
-	first->op_flags |= OPf_KIDS;
+    first->op_flags |= (last->op_flags & OPf_KIDS);
 
 #ifdef PL_OP_SLAB_ALLOC
 #else
@@ -2500,7 +2490,7 @@ Perl_prepend_elem(pTHX_ I32 type, OP *fi
 	    first->op_sibling = ((LISTOP*)last)->op_first;
 	    ((LISTOP*)last)->op_first = first;
 	}
-	((LISTOP*)last)->op_children++;
+	last->op_flags |= OPf_KIDS;
 	return last;
     }
 
@@ -2533,7 +2523,8 @@ Perl_newLISTOP(pTHX_ I32 type, I32 flags
 
     listop->op_type = type;
     listop->op_ppaddr = PL_ppaddr[type];
-    listop->op_children = (first != 0) + (last != 0);
+    if (first || last)
+	flags |= OPf_KIDS;
     listop->op_flags = flags;
 
     if (!last && first)
@@ -2553,8 +2544,6 @@ Perl_newLISTOP(pTHX_ I32 type, I32 flags
 	if (!last)
 	    listop->op_last = pushop;
     }
-    else if (listop->op_children)
-	listop->op_flags |= OPf_KIDS;
 
     return (OP*)listop;
 }
@@ -6309,7 +6298,6 @@ S_simplify_sort(pTHX_ OP *o)
     kid = cLISTOPo->op_first->op_sibling;
     cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */
     op_free(kid);				      /* then delete it */
-    cLISTOPo->op_children--;
 }
 
 OP *
--- bytecode.pl.orig	Sat Jan 13 16:21:12 2001
+++ bytecode.pl	Sun Jan 14 01:54:10 2001
@@ -379,7 +379,6 @@ op_private	PL_op->op_private			U8
 op_first	cUNOP->op_first				opindex
 op_last		cBINOP->op_last				opindex
 op_other	cLOGOP->op_other			opindex
-op_children	cLISTOP->op_children			U32
 op_pmreplroot	cPMOP->op_pmreplroot			opindex
 op_pmreplrootgv	*(SV**)&cPMOP->op_pmreplroot		svindex
 op_pmreplstart	cPMOP->op_pmreplstart			opindex
--- ext/B/B/Bytecode.pm.orig	Sat Jan 13 16:21:01 2001
+++ ext/B/B/Bytecode.pm	Sun Jan 14 01:53:20 2001
@@ -312,15 +312,6 @@ sub B::BINOP::bytecode {
     }
 }
 
-sub B::LISTOP::bytecode {
-    my $op = shift;
-    my $children = $op->children unless $strip_syntree;
-    $op->B::BINOP::bytecode;
-    if (($op->type || !$compress_nullops) && !$strip_syntree) {
-	asm "op_children $children\n";
-    }
-}
-
 sub B::LOOP::bytecode {
     my $op = shift;
     my $redoopix = $op->redoop->objix;

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