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

Revision: r1.1 - 18 Aug 2003 - 19:52 - EelcoVisser
Stratego > StrategoCompiler > StrategoOptimizer > LiftDefinitionsToTopLevel
Copyright © 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback