Coder Social home page Coder Social logo

firmforth's Introduction

firmforth

firmforth is a just-in-time-compiling forth-like system using 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.

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 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.

benchmarkfirmforth 95ab9b7gforth-fast 0.7.2
40 fibonacci0.82 (+0.05 compilation)3.2
16 queens25.1 (+0.28 compilation)43.9

References

Authors

Andreas Seltenreich <[email protected]>

firmforth's People

Contributors

anse1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.