Lift Definitions To Top Level

Stratego -- Strategies for Program Transformation
Local strategy definitions can be lifted to the top-level if they do not contain free variables. For example,
  foo(s) = 
    Bar(s, id)
    ; let f = !"foobar"
       in foobar(f)
      end
can be transformed to
  f = !"foobar"
  foo(s) = 
    Bar(s, id)
    ; foobar(f)
This transformation reduces the number of nested functions in the generated C code. The optimization is part of the Stratego optimizer included in StrategoRelease093.

Extension

The transformation can be extended by applying 'lambda lifting', i.e., also lift definitions with free variables. For example,

  foo(s) = 
    Bar(s, ?x)
    ; let f = ?"foobar"; !x
       in foobar(f)
      end
can be tranformed to
  f(|x) = ?"foobar"; !x
  foo(s) = 
    Bar(s, ?x)
    ; foobar(f(|x))
in which x is passed 'by value' to f, which has been extended with an extra argument.

This abstraction does not work for 'by reference' variables as in the following example:

  foo(s) = 
    ?Bar(x, y)
    ; let f = ?FooBar(x, z)
       in <oncetd(f)> y
      end
    ; z

-- EelcoVisser - 18 Aug 2003