[Gambas-user] News about the new just-in-time compiler

Tony Morehen tmorehen at ajm-software.com
Wed Jul 4 00:28:22 CEST 2018


In one of my programs, I have two functions that use the Fast prefix.

When the first function is called, the "wanted String[], got float" is
raised.  Everything works fine when Fast is removed.  Here are the two
functions:

Fast Public Function WordWrap(text As String, $WordWrap As Boolean,
$LineWidth As Float) As String[]

   Dim result As New String[]
   Dim txt As String

   Dim tmp As String[] = Split(text, "\n")

   If Not $WordWrap Then Return tmp
   For Each txt In tmp
     result.Insert(SplitLine(txt, $LineWidth))
   Next
   Return result

End

Fast Private Function SplitLine(txt As String, $LineWidth As Float) As
String[]

   Dim Lines As New String[]
   Dim CurrWord As String
   Dim i As Integer

   If txt = "" Then txt = " "
   Do Until Paint.TextSize(txt).Width / Paint.ResolutionX < $LineWidth
     i = String.Len(txt) + 1
     Do
       Dec i
       CurrWord = String.Left(txt, i)
     Loop Until Paint.TextSize(CurrWord).Width / Paint.ResolutionX <
$LineWidth
     For i = String.Len(CurrWord) To 1 Step -1
       Select Case String.Mid(CurrWord, i, 1)
         Case " ", ";", ",", "\t", ":"
           Break
       End Select
     Next
     If i > 1 Then
       CurrWord = String.Left(CurrWord, i)
     Endif
     Lines.Add(CurrWord)
     txt = String.Mid(txt, String.Len(CurrWord) + 1)
   Loop
   If String.Len(txt) > 0 Then Lines.Add(txt)
   Return Lines

End Function

Fast doesn't make much of a difference on small to medium-sized files,
but seems to make a difference on large files, though I haven't run any
tests.


On 2018-06-28 06:41 PM, Benoît Minisini wrote:
> Hi,
>
> Here is a few news about the new just-in-compiler...
>
> 1) Almost everything is supported, and seem to work. Bigger test are 
> needed now.
>
> 2) The following are not implemented, and may never be implemented for 
> different reasons:
>
> - Functions with a variable number of arguments.
>
> - Arguments passed by reference with ByRef.
>
> - Functions used as extern callbacks.
>
> 3) Extern functions calls are optimized: they are directly called from 
> the JIT code. But this has not been tested yet!
>
> 4) Not all mathematical functions are correctly implemented yet.
>
> 5) clang may be supported instead of gcc. This is something to test 
> before finding a way to dynamically detect which compiler to use.
>
> 6) I introduced a new keyword, UNSAFE. You use it with the FAST keyword.
>
> When a function is declared "FAST UNSAFE", then it is just-in-time 
> compiled, but all the safety checks are removed (null object, division 
> by zero, out of array bounds...).
>
> It allows you to speed up the code a little bit, when you are sure it 
> won't do illegal things.
>
> And if it does anyway, you will have memory corruption and/or 
> segmentation fault.
>
> Of course, the keyword can be used at the class level.
>
> Enjoy!
>




More information about the User mailing list