GST-Ligthning
A Smalltalk binding of GNU lightning. GNU lightning exposes a portable interface for generating machine language at run-time. GNU lightning is fast and tries to be as little intrusive as possible, so that the generated code can also be optimized easily. So far, it has been ported to the x86, SPARC and PowerPC architecture.
With gst-lightining you can create and execute your own machine code inside gst. It create a function that can be called from gst.
Installation
From Source
The git source is available at: http://github.com/MrGwen/gst-lightning
git clone git://github.com/MrGwen/gst-lightning.git
Now you need to generate configuration files:
autoreconf -vi
And proceed to the classic build:
./configure make [sudo] make install
Example
To understand how it work let's start by an example.
We are going to reproduce the incr example from the lightning documentation.
Eval [
PackageLoader fileInPackage: 'Lightning'.
jitState := Lightning.CJitState new.
(jitState
leaf: 1;
getargInt: Lightning.R0 from: jitState argInt;
addI: Lightning.RET to: Lightning.R0 int: 1;
ret;
assemble;
value: 5) printNl.
]
-
PackageLoader fileInPackage: 'Lightning'.
First we need to load the package that contain the gst source for the binding.
-
jitState := Lightning.CJitState new.
Here we create the object that is going to contain all the machine code.
-
jitState leaf: 1
This line added the prolog to the function. It also tell that the function will have one argument
-
jitState getargInt: Lightning.R0 from: jitState argInt
We fetch the argument and store it in the genreal purpose register R0.
The offset of the argument is given by the jitState argInt statement.
-
jitState addI: Lightning.RET to: Lightning.R0 int: 1
This step add 1 to the register R0 and store it into the return value designate by Lightning.RET
-
jitState ret
We ended the function and return to the caller.
-
jitState assemble
This statement is very important. It flushes the generated code and set it executable.
-
(jitState value: 5) printNl
We call and print the output value of the function
You can found more example inside the examples directory from the source package.
