Skip to content

Compiler plugin goodies for Scala (continuation of non-OpenCL part of ScalaCL)

License

Notifications You must be signed in to change notification settings

hayssams/Scalaxy

 
 

Repository files navigation

Collection of Scala Macro goodies (BSD-licensed)

  • Loops provide a macro that optimizes simple foreach loops by rewriting them to an equivalent while loop:

    import scalaxy.loops._
    
    for (i <- 0 until 100000000 optimized) { ... }
  • Reified (ScalaDoc) provides a powerful reified values mechanism that deals well with composition and captures of runtime values, allowing for complex ASTs to be generated during runtime for re-compilation or transformation purposes. It preserves the original value that was reified, allowing for flexible mixed usage of runtime value and compile-time AST.

    import scalaxy.reified._
    
    def comp(capture1: Int): ReifiedFunction1[Int, Int] = {
      val capture2 = Seq(10, 20, 30)
      val f = reify((x: Int) => capture1 + capture2(x))
      val g = reify((x: Int) => x * x)
      
      g.compose(f)
    }
    
    println("AST: " + comp(10).expr().tree)
  • Debug (ScalaDoc) provides assert, require and assume macros that automatically add a useful message to the regular Predef calls.

  • MacroExtensions provides an extremely simple (and experimental) syntax to define extensions methods as macros:

    @scalaxy.extension[Any] 
    def quoted(quote: String): String = 
      quote + self + quote
      
    @scalaxy.extension[Int] 
    def copiesOf[T : ClassTag](generator: => T): Array[T] = 
      Array.fill[T](self)(generator)
    
    ...
    println(10.quoted("'"))
    // macro-expanded to `"'" + 10 + "'"`
    
    println(10 copiesOf new Entity)
    // macro-expanded to `Array.fill(3)(new Entity)`
  • Compilets provide an easy way to express AST rewrites, backed by a compiler plugin and an sbt plugin.

  • Beans (ScalaDoc) are a nifty combination of Dynamics and macros that provide a type-safe eye-candy syntax to set fields of regular Java Beans in a Scala way (without any runtime dependency at all!):

    import scalaxy.beans._
    
    new MyBean().set(foo = 10, bar = 12)
  • Fx (ScalaDoc) contains an experimental JavaFX DSL (with virtually no runtime dependency) that makes it easy to build objects and define event handlers:

    new Button().set(
      text = bind {
        s"Hello, ${textField.getText}"
      },
      onAction = {
        println("Hello World!")
      }
    )

Discuss

If you have suggestions / questions:

You can also file bugs and enhancement requests here.

Any help (testing, patches, bug reports) will be greatly appreciated!

Hacking

  • Pushing the site with each sub-project's Scaladoc at http://ochafik.github.io/Scalaxy/:

    sbt clean
    sbt "project scalaxy-doc" ghpages-push-site
    

    (you can preview the site with sbt "project scalaxy-doc" preview-site)

  • Publishing projects on Sonatype OSS Repository + advertise on ls.implicit.ly (assuming correct credentials in ~/.sbt/0.12.4/sonatype.sbt):

    sbt "+ assembly" "+ publish"
    sbt "project scalaxy" ls-write-version lsync
    

About

Compiler plugin goodies for Scala (continuation of non-OpenCL part of ScalaCL)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published