The libjit library implements Just-In-Time compilation functionality. Unlike other JIT's, this one is designed to be independent of any particular virtual machine bytecode format or language. The hope is that Free Software projects can get a leg-up on proprietry VM vendors by using this library rather than spending large amounts of time writing their own JIT from scratch.
This JIT is also designed to be portable to multiple archictures. If you run libjit on a machine for which a native code generator is not yet available, then libjit will fall back to interpreting the code. This way, you don't need to write your own interpreter for your bytecode format if you don't want to.
Features:
The primary interface is in C, for maximal reusability. Class interfaces are available for programmers who prefer C++.
Designed for portability to all major 32-bit and 64-bit platforms.
Simple three-address API for library users, but opaque enough that other representations can be used inside the library in future without affecting existing users.
Up-front or on-demand compilation of any function.
In-built support to re-compile functions with greater optimization, automatically redirecting previous callers to the new version.
Fallback interpreter for running code on platforms that don't have a native code generator yet. This reduces the need for programmers to write their own interpreters for such platforms.
Arithmetic, bitwise, conversion, and comparison operators for 8-bit, 16-bit, 32-bit, or 64-bit integer types; and 32-bit, 64-bit, or longer floating point types. Includes overflow detecting arithmetic for integer types.
Large set of mathematical and trigonometric operations (sqrt, sin, cos, min, abs, etc) for inlining floating-point library functions.
Simplified type layout and exception handling mechanisms, upon which a variety of different object models can be built.
I've translated the headers and examples, get them here:
oyster wrote:looks interesting.
I think it is far from a FB interpreter. oh, my lovely QB interpreter
Well, I hope someone makes a FB JIT VM out of it.. I'm sure the outcome would be very interesting =)
FB.NET maybe, or maybe a FreeBASIC web server, a la ASP.NET? :P
Dim FBMain As Function(args As String) As Integer
Dim As String file=command(1)
If file="" Then
?"Please specify a file"
End 1
EndIf
Dim As String dllFile=file+".dll"
Dim text As String
Open Pipe "fbc -dll "+chr(34)+file+chr(34)+" -x "+chr(34)+dllFile+chr(34) For Input As #1
Line Input #1, text
If text<>"" Then
?text
Do While Not EOF(1)
Line Input #1, text
Print text
Loop
?"Compiler error"
end
EndIf
Dim As Any ptr dll=DyLibLoad(dllFile)
If dll<>0 Then
FBMain=DyLibSymbol(dll,"FBMain")
If FBMain<>0 Then
Dim As Integer res=FBMain("")'Havent implemented args yet
DyLibFree(dll)
If res<>0 Then
?"Program ended with error: ";res
End res
EndIf
End 0
EndIf
DyLibFree(dll)
Else
?"Error loading the dll"
End 2
EndIf