From fecb6dc501ce3eeadb6d3f5a39de6a1ac808190d Mon Sep 17 00:00:00 2001 From: dos-reis Date: Sat, 12 Jun 2010 08:39:06 +0000 Subject: * interp/g-opt.boot (replaceableTemporary?): New. (optSEQ) [getRidOfTemps]: Use it to decide when to safely inline a temporary variable definition. --- src/ChangeLog | 6 ++++++ src/interp/g-opt.boot | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index b1d41d6d..56d3b90b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2010-06-12 Gabriel Dos Reis + + * interp/g-opt.boot (replaceableTemporary?): New. + (optSEQ) [getRidOfTemps]: Use it to decide when to safely inline a + temporary variable definition. + 2010-06-12 Gabriel Dos Reis * interp/compiler.boot (compIterate): Rewrite. diff --git a/src/interp/g-opt.boot b/src/interp/g-opt.boot index be39629b..119da259 100644 --- a/src/interp/g-opt.boot +++ b/src/interp/g-opt.boot @@ -330,7 +330,18 @@ optCONDtail l == optPredicateIfTrue p => [[$true,c]] null rest l => [frst,[$true,["CondError"]]] [frst,:optCONDtail l'] - + +++ Determine whether the symbol `g' is the name of a temporary that +++ can be replaced in the form `x', if it is of linear usage and not +++ the name of a program point. The latter occurs when THROW forms +++ are changed to %LET form followed by a GO form -- see optCatch. +replaceableTemporary?(g,x) == + GENSYMP g and numOfOccurencesOf(g,x) < 2 and not jumpTarget?(g,x) where + jumpTarget?(g,x) == + isAtomicForm x => false + x is ['GO,=g] => true + or/[jumpTarget?(g,x') for x' in x] + optSEQ ["SEQ",:l] == tryToRemoveSEQ SEQToCOND getRidOfTemps splicePROGN l where splicePROGN l == @@ -339,7 +350,7 @@ optSEQ ["SEQ",:l] == l.rest := splicePROGN rest l getRidOfTemps l == null l => nil - l is [["%LET",g,x,:.],:r] and GENSYMP g and 2>numOfOccurencesOf(g,r) => + l is [["%LET",g,x],:r] and replaceableTemporary?(g,r) => getRidOfTemps substitute(x,g,r) first l="/throwAway" => getRidOfTemps rest l --this gets rid of unwanted labels generated by declarations in SEQs -- cgit v1.2.3