Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- CA-Clipper 5.2 . Release Notes - <b>1 compiler optimizations</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 1   Compiler Optimizations
--------------------------------------------------------------------------------

     The Clipper compiler in contrast to previous versions of Clipper
     performs three types of optimization to your code.

     .  Shortcutting
     .  Constant folding
     .  Dead code removal

     Optimizations have impact on what code is generated by the compiler
     and therefore what code is actually executed at runtime.  This is
     important since it may affect how your programs operate.

   Shortcutting

     Beginning with Clipper version 5.0, the compiler automatically
     performs optimizations (called shortcutting) on logical
     expressions containing .AND. and .OR. operators.  When an
     expression evaluation is shortcut, it ends when the result becomes
     evident.

     With .AND. this means that <lCondition1> and <lCondition2> are both
     evaluated only when <lCondition1> evaluates to true (.T.).  If
     <lCondition1> evaluates to false (.F.), the .AND. operation is
     false (.F.) and <lCondition2> is therefore not evaluated.  For
     example:

     ? .F. .AND. .T.        // Result: .F.  (shortcut)
     ? .F. .AND. .F.        // Result: .F.  (shortcut)
     ? .T. .AND. .T.        // Result: .T.
     ? .T. .AND. .F.        // Result: .F.

     With .OR. this means that <lCondition1> and <lCondition2> are both
     evaluated only when <lCondition1> evaluates to false (.F.).  If
     <lCondition1> evaluates to true (.T.), the .OR. operation is true
     (.T.) and <lCondition2> is therefore not evaluated.  For
     example:

     ? .T. .OR. .T.         // Result: .T.  (shortcut)
     ? .T. .OR. .F.         // Result: .T.  (shortcut)
     ? .F. .OR. .T.         // Result: .T.
     ? .F. .OR. .F.         // Result: .F.

     If the program (.prg) file is compiled with the /Z option, all
     operands of .AND. and .OR. operators are guaranteed to be evaluated
     at runtime.  Note that the scope of the optimization is the scope
     of the compile.  For example, the following compiler command-line
     suppresses shortcutting for Test.prg:

     C>CLIPPER Test /N /W /Z

   Constant Folding

     In Clipper 5.0, the compiler will perform simple evaluation where
     both operands of a binary operator are constant values.  As an
     example,

     nVar := 1 + 2 + 3

     is generated as nVar := 6.  Likewise,

     cVar := "Hello " + "There"

     is generated as cVar := "Hello There."

   Dead Code Removal

     The Clipper compiler automatically removes statements that never
     execute.  This is referred to as dead code removal.  For
     example, the compiler never generates code for the following
     constructs:

     IF .F.
       <statements>
     ENDIF

     DO WHILE .F.
       <statements>
     ENDDO

     Example:  In the STD.CH, the definition for the extended
     expression version of the SET CURSOR command takes advantage of
     dead code removal to allow a logical command argument to be
     transformed into numeric efficiently:

     #command SET CURSOR (<x>) ;
           => SETCURSOR( IF(<x>, 1, 0) )

     In this example, depending on whether you specify true (.T.) or
     false (.F.) as the SET CURSOR argument, the compiler generates
     either SETCURSOR(1) or SETCURSOR(0).  The IF() evaluation and the
     non-executed case are removed.

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson