/* * $Id$ */ Przemyslaw Czerpak (druzus/at/priv.onet.pl) Harbour compile time optimizations. 1. Function call optimization. Just like Clipper Harbour compiler can optimize few function calls if parameters are well known constant values. Here is the list of functions optimized at compile time: - Clipper compatible: AT( , ) // Clipper wrongly calculates // "" $ as .T. CHR( ) UPPER( ) // cannot contain characters different then [0-9A-Za-z] - Harbour extension: INT( ) ASC( [ , ... ] ) MIN( , ) // is N, D or L value MAX( , ) // is N, D or L value EMPTY( | | | | | | | NIL ) LEN( | | ) CTOD( [ , ... } ) DTOS( ] ) STOD( [ ] ) HB_STOD( [ ] ) HB_BITNOT( [, ... ] ) HB_BITAND( , [, ] ) HB_BITOR( , [, ] ) HB_BITXOR( , [, ] ) HB_BITTEST( , [, ... ] ) HB_BITSET( , [, ... ] ) HB_BITRESET( , [, ... ] ) HB_BITSHIFT( , [, ... ] ) - Harbour special functions: HB_I18N_GETTEXT_NOOP( [ , ] ) HB_I18N_NGETTEXT_NOOP( | [ , ] ) HB_MUTEXCREATE() 2. Expresion optimization: Just like Clipper Harbour compiler can optimize some expresions if arguments are well known and can be callculated at compile time: - Clipper compatible: + => + => + => + => // In Clipper neither nor // can contain '&' character. Harbour checks // if concatenation can change existing valid // macro expression - => - => - => - => // In Clipper neither nor // can contain '&' character. Harbour checks // if concatenation can change existing valid // macro expression * => / => // Clipper optimize only integers % => $ => // Clipper wrongly calculates // "" $ as .T. == => == => == => == => NIL == => == NIL => = => = => = => NIL = => = NIL => "" = "" => .T. != => != => != => NIL != => != NIL => "" != "" => .F. >= => >= => >= => <= => <= => <= => > => > => > => < => < => < => .NOT. .T. => .F. .NOT. .F. => .T. .AND. => .OR. => IIF( .T., , ) => IIF( .F., , ) => - optimizations disabled by -z compiler switch .T. .AND. => .AND. .T. => .F. .OR. => .OR. .F. => .F. .AND. => .F. .AND. .F. => .F. .T. .OR. => .T. .OR. .T. => .T. - Harbour extension: ^ => [ ] => ( ) => // it allows to optimize // expresions like: 1+(2) - Harbour extension which may disable RT errors in wrong expressions: .NOT. .NOT. => - - => + 0 => 0 + => + "" => "" + => In cases when result is miningless Harbour compiler can skip code for operation, i.e. for such line of .prg code: ( ) where result of operation is ignored Harbour reduces the code to: ( , ) In Clipper in some places optiomization is not enabled, f.e. Clipper does not optimize in expressions like: : msg( ... ) Unlike Clipper Harbour tries to optimize all expressions. If some code needs strict Clipper behavior then it can be forced by using -kc Harbour compiler switch. It disabled Harbour extensions and enables replicating some Clipper bugs like optimizing "" $ to .T. at compile time when at runtime it's always .F. Expressions fully optimized to constant values at compile time can be used to intialize static variables, f.e.: static s_var := ( 1 + 2 / 3 ) Harbour has additional optimization phase which operates on generated PCODE. It can also reduce expressions, joins jumps, removes death or meaningless code which can appear after all other optimizations and were not optimized by expression optimizer.