Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anse1/firmforth
A just-in-time-compiling forth system using libfirm.
https://github.com/anse1/firmforth
forth jit-compiler libfirm
Last synced: 4 months ago
JSON representation
A just-in-time-compiling forth system using libfirm.
- Host: GitHub
- URL: https://github.com/anse1/firmforth
- Owner: anse1
- License: gpl-3.0
- Created: 2016-01-27T08:25:30.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-01T09:38:38.000Z (almost 8 years ago)
- Last Synced: 2024-02-17T15:35:07.615Z (12 months ago)
- Topics: forth, jit-compiler, libfirm
- Language: C
- Homepage:
- Size: 101 KB
- Stars: 56
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: COPYING
Awesome Lists containing this project
- AwesomeCompiler - firmforth
README
* firmforth
firmforth is a just-in-time-compiling forth-like system using [[http://libfirm.org][libfirm]].
It is small and comprehensible and was written to evaluate
JIT-compilation using libfirm.** Design
Firmforth is built around a dictionary of functions that can be
invoked for an effect on a stack of values or a side effect. It also
sports a typical forth outer interpreter. In interpreter mode, it
executes the words that are input. In compilation mode, its action
depends on whether an entered word is flagged immediate. Immediate
words - e.g. "if" - are still executed right-away and implement the
compiler itself. Normal words end up as Call nodes in the
intermediate language.When the definition of a new word is complete, libfirm-provided
optimizations are invoked, possibly inlining Calls of functions for
which the intermediate representation is available. An assembly file
is then generated by libfirm and assembled into a shared object. This
is in turn loaded into the program using dlopen() and the word is
added to the dictionary. The IR is also kept around for future
inlining of the word.[[file:firmforth.png]]
** Usage
A couple of standard forth words are written in forth itself in the
file =core.fifo=. To get an interactive session with these words
defined, you could invoke firmforth like this:: make && cat core.fifo - | ./firmforth
Some of the forth words are currently implemented in C. In order to
be able to inline them into new words for a major speedup, the
intermediate representation for them can be made available by invoking
[[https://github.com/MatzeB/cparser][cparser]] like this:: cparser --export-ir firmforth.c
** Goals
- [X] Interactively compile forth words using graphs of Call nodes
- [X] Add control flow primitives
- [X] Keep IR of newly defined words around and inline them
- [X] Keep IR of statically defined words around and inline them
- [ ] Use libfirm's binary emitter instead of dlopen()** Benchmark
The table below lists times[s] required for compiling and executing
the word =fibonacci= and =queens= in =examples.fifo= on my machine for
various forth systems.| benchmark | firmforth 95ab9b7 | gforth-fast 0.7.2 |
|--------------+--------------------------+-------------------|
| 40 fibonacci | 0.82 (+0.05 compilation) | 3.2 |
| 16 queens | 25.1 (+0.28 compilation) | 43.9 |** References
- https://korte.credativ.com/~ase/firm-postgres-jit-forth.pdf
** AuthorsAndreas Seltenreich