This repo contains an implementation of fold-based fusion using partial evaluation. The code uses LMS, or Lightweight Modular Staging. You may wish to read the Scala '15 publication of this work here. You can also take a look at slides here.
The main files for this project are
- FoldLeft.scala:
This file contains the implementation of the staged
FoldLeft
API. - FoldLeftSuite.scala:
This file contains test cases for
FoldLeft
. These tests generate code, and also compile the generated code and run them on dynamic output. The tests programs are defined in theFoldLeftProg
trait. Their generation and execution is done in theFoldLeftSuite
class. - foldleft.check, partition.check, reverse-index.check. They contain the generated code for the test cases, along with printed output which is the result of running a specific input.
To run the code, please follow these steps:
- Clone this here repo in a separate folder:
git clone [email protected]:manojo/staged-fold-fusion.git
. - Profit:
$ cd staged-fold-fusion
$ sbt
> test-only barbedwire.FoldLeftSuite
Hope you have fun!
Add the following lines to your sbt
build to start using:
libraryDependencies += "com.github.manojo" % "staged-fold-fusion
_2.11" % "0.1-SNAPSHOT"
resolvers += Resolver.sonatypeRepo("snapshots")
Here are some basic LMS conventions I use when writing LMS code:
- Each new
Ops
gets its own file - An
Exp
trait only mixes other Exp traits that are notOpt
trait Opt
traits are mixed in at a later stage. If you are often going to use one, create anOpt
trait for yourOps
which mixes the relevantOpt
traits.Fat
optimizations should not be mixed in with the classicalOpt
traits, but used independently.- If I use a certain feature (ex Option) in my current trait, I mix it in explicitly, even if some other trait I'm using has it already. Serves for documentation purposes. Of course, for really trivial stuff it's not necessary to do so.
Update (27 april 2015): The Scala version has just been bumped. If you have downloaded this project before this date, and are updating, make sure you do the same for the LMS dependency as well (i.e. publish-local the latest version).
Update (7 september 2015): You no longer need to publish-local!
Update (11 september 2015): You can now re-use this code in a sane manner