Wednesday, March 2, 2011

Harbour/xharbour Diff (3/57) - EXTENDED CODEBLOCKS by Przemyslaw Czerpak

Both compilers support compile time extended codeblocks which allow to use statements but with a little bit different syntax. Harbour uses standard Clipper codeblock delimiters {}, f.e.:

      ? eval( { | p1, p2, p3 |
                ? p1, p2, p3
                return p1 + p2 + p3
              }, 1, 2, 3 )

and xHarbour <>, f.e.:
      ? eval( < | p1, p2, p3 |
                ? p1, p2, p3
                return p1 + p2 + p3
              >, 1, 2, 3 )

In Harbour extended codeblocks works like nested functions and support all functions attributes, f.e. they can have own static variables or other declarations which are local to extended codeblocks only and do not effect upper function body.

In xHarbour the compiler was not fully updated for such functionality and extended codeblocks were added to existing compiler structures what causes that not all language constructs work in extended codeblocks and creates a set of very serious compiler bugs, f.e., like in this code with syntax errors but which is compiled by xHarbour without even single warning giving unexpected results at runtime:

      #ifndef __XHARBOUR__
         #xtranslate \<|[]| => {||
         #xcommand > [<*x*>]       => } 
      #endif
      proc main()
         local cb, i
         for i:=1 to 5
            cb := <| p |
                     ? p
                     exit
                     return p * 10
                  >
            ?? eval( cb, i )
         next
      return

It's possible to create many other similar examples which are mostly caused by missing in the compiler infrastructure for nested functions support.

This can be fixed if someone invest some time to clean xHarbour compiler.

No comments:

Post a Comment