Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a pinch of compiler plugin, a dose of compilets, a laundried- a…
…nd trimmed-down-scala library and an sbt build project
- Loading branch information
Showing
103 changed files
with
5,210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<plugin> | ||
<name>Scalaxy</name> | ||
<classname>scalaxy.plugin.ScalaxyPlugin</classname> | ||
</plugin> |
53 changes: 53 additions & 0 deletions
53
CompilerPlugin/src/main/scala/scalight/plugin/ScalightPlugin.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* ScalaCL - putting Scala on the GPU with JavaCL / OpenCL | ||
* http://scalacl.googlecode.com/ | ||
* | ||
* Copyright (c) 2009-2010, Olivier Chafik (http://ochafik.free.fr/) | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of Olivier Chafik nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY OLIVIER CHAFIK AND CONTRIBUTORS ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY | ||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package scalight.plugin | ||
|
||
import scalaxy.pluginBase._ | ||
import scalaxy.plugin._ | ||
|
||
import scala.tools.nsc.Global | ||
|
||
object ScalightPluginDef extends ScalaxyPluginDefLike { | ||
override def envVarPrefix = "SCALIGHT_" | ||
|
||
override def matchActionHolders = Seq( | ||
scalight.compilets.Collection | ||
) | ||
} | ||
|
||
class ScalightPlugin(override val global: Global) | ||
extends PluginBase(global, ScalightPluginDef) | ||
|
||
object Compile extends CompilerMain { | ||
override def pluginDef = ScalightPluginDef | ||
override def commandName = "scalight" | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
Compilets/src/main/scala/scalight/compilets/Collection.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package scalight; package compilets | ||
|
||
import scalaxy.macros._ | ||
//import scalaxy.matchers._ | ||
|
||
object Collection extends scalaxy.Compilet | ||
{ | ||
import scalight.collection._ | ||
import scalight.collection.{ List => SList } | ||
|
||
|
||
def listForeach[T : TypeTag, U : TypeTag](l: SList[T], body: U) = replace( | ||
l.foreach(v => body), | ||
{ | ||
val it = l.iterator() | ||
while (it.hasNext()) { | ||
val v = it.next | ||
body | ||
} | ||
} | ||
) | ||
// TODO... | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
SCALA LICENSE | ||
|
||
Copyright (c) 2002-2011 EPFL, Lausanne, unless otherwise specified. | ||
All rights reserved. | ||
|
||
This software was developed by the Programming Methods Laboratory of the | ||
Swiss Federal Institute of Technology (EPFL), Lausanne, Switzerland. | ||
|
||
Permission to use, copy, modify, and distribute this software in source | ||
or binary form for any purpose with or without fee is hereby granted, | ||
provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the EPFL nor the names of its contributors | ||
may be used to endorse or promote products derived from this | ||
software without specific prior written permission. | ||
|
||
|
||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
This is a trimmed-down version of the Scala library (see LICENSE for copyright information). | ||
|
||
As a first step, it's probably better not to get rid of Product, Tuples & Functions. | ||
|
||
Source taken from Scala 2.10.0-SNAPSHOT roughly as of the 1st May 2012, with the following changes : | ||
* Commented @specialized annotations | ||
* Renamed scala package to scalaLight (see TODO below) | ||
* Changed scala.Product.productIterator to return Array[Any] | ||
|
||
TODO | ||
==== | ||
|
||
Using a tool such as maven-shade-plugin, relocate / rename the following : | ||
* scalaLight package to scala | ||
* Product.productIterator2 to Product.productIterator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* __ *\ | ||
** ________ ___ / / ___ Scala API ** | ||
** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** | ||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** | ||
** /____/\___/_/ |_/____/_/ | | ** | ||
** |/ ** | ||
\* */ | ||
|
||
|
||
|
||
package scalaLight | ||
|
||
/** A module defining utility methods for higher-order functional programming. | ||
* | ||
* @author Martin Odersky | ||
* @version 1.0, 29/11/2006 | ||
*/ | ||
object Function { | ||
/** Given a sequence of functions `f,,1,,`, ..., `f,,n,,`, return the | ||
* function `f,,1,, andThen ... andThen f,,n,,`. | ||
* | ||
* @param fs The given sequence of functions | ||
* @return ... | ||
*/ | ||
def chain[a](fs: Seq[a => a]): a => a = { x => (x /: fs) ((x, f) => f(x)) } | ||
|
||
/** The constant function */ | ||
def const[T, U](x: T)(y: U): T = x | ||
|
||
/** Turns a function `A => Option[B]` into a `PartialFunction[A, B]`. | ||
* | ||
* TODO: check if the paragraph below is still correct | ||
* '''Important note''': this transformation implies the original function | ||
* will be called 2 or more times on each logical invocation, because the | ||
* only way to supply an implementation of `isDefinedAt` is to call the | ||
* function and examine the return value. | ||
* | ||
* @param f a function `T => Option[R]` | ||
* @return a partial function defined for those inputs where | ||
* f returns `Some(_)` and undefined where `f` returns `None`. | ||
* @see [[scala.PartialFunction#lift]] | ||
*/ | ||
//def unlift[T, R](f: T => Option[R]): PartialFunction[T, R] = PartialFunction.unlifted(f) | ||
|
||
/** Uncurrying for functions of arity 2. This transforms a unary function | ||
* returning another unary function into a function of arity 2. | ||
*/ | ||
def uncurried[a1, a2, b](f: a1 => a2 => b): (a1, a2) => b = { | ||
(x1, x2) => f(x1)(x2) | ||
} | ||
|
||
/** Uncurrying for functions of arity 3. | ||
*/ | ||
def uncurried[a1, a2, a3, b](f: a1 => a2 => a3 => b): (a1, a2, a3) => b = { | ||
(x1, x2, x3) => f(x1)(x2)(x3) | ||
} | ||
|
||
/** Uncurrying for functions of arity 4. | ||
*/ | ||
def uncurried[a1, a2, a3, a4, b](f: a1 => a2 => a3 => a4 => b): (a1, a2, a3, a4) => b = { | ||
(x1, x2, x3, x4) => f(x1)(x2)(x3)(x4) | ||
} | ||
|
||
/** Uncurrying for functions of arity 5. | ||
*/ | ||
def uncurried[a1, a2, a3, a4, a5, b](f: a1 => a2 => a3 => a4 => a5 => b): (a1, a2, a3, a4, a5) => b = { | ||
(x1, x2, x3, x4, x5) => f(x1)(x2)(x3)(x4)(x5) | ||
} | ||
|
||
/** Tupling for functions of arity 2. This transforms a function | ||
* of arity 2 into a unary function that takes a pair of arguments. | ||
* | ||
* @note These functions are slotted for deprecation, but it is on | ||
* hold pending superior type inference for tupling anonymous functions. | ||
* | ||
* @param f ... | ||
* @return ... | ||
*/ | ||
// @deprecated("Use `f.tupled` instead") | ||
def tupled[a1, a2, b](f: (a1, a2) => b): Tuple2[a1, a2] => b = { | ||
case Tuple2(x1, x2) => f(x1, x2) | ||
} | ||
|
||
/** Tupling for functions of arity 3. This transforms a function | ||
* of arity 3 into a unary function that takes a triple of arguments. | ||
*/ | ||
// @deprecated("Use `f.tupled` instead") | ||
def tupled[a1, a2, a3, b](f: (a1, a2, a3) => b): Tuple3[a1, a2, a3] => b = { | ||
case Tuple3(x1, x2, x3) => f(x1, x2, x3) | ||
} | ||
|
||
/** Tupling for functions of arity 4. This transforms a function | ||
* of arity 4 into a unary function that takes a 4-tuple of arguments. | ||
*/ | ||
// @deprecated("Use `f.tupled` instead") | ||
def tupled[a1, a2, a3, a4, b](f: (a1, a2, a3, a4) => b): Tuple4[a1, a2, a3, a4] => b = { | ||
case Tuple4(x1, x2, x3, x4) => f(x1, x2, x3, x4) | ||
} | ||
|
||
/** Tupling for functions of arity 5. This transforms a function | ||
* of arity 5 into a unary function that takes a 5-tuple of arguments. | ||
*/ | ||
// @deprecated("Use `f.tupled` instead") | ||
def tupled[a1, a2, a3, a4, a5, b](f: (a1, a2, a3, a4, a5) => b): Tuple5[a1, a2, a3, a4, a5] => b = { | ||
case Tuple5(x1, x2, x3, x4, x5) => f(x1, x2, x3, x4, x5) | ||
} | ||
|
||
/** Un-tupling for functions of arity 2. This transforms a function taking | ||
* a pair of arguments into a binary function which takes each argument separately. | ||
*/ | ||
def untupled[a1, a2, b](f: Tuple2[a1, a2] => b): (a1, a2) => b = { | ||
(x1, x2) => f(Tuple2(x1, x2)) | ||
} | ||
|
||
/** Un-tupling for functions of arity 3. This transforms a function taking | ||
* a triple of arguments into a ternary function which takes each argument separately. | ||
*/ | ||
def untupled[a1, a2, a3, b](f: Tuple3[a1, a2, a3] => b): (a1, a2, a3) => b = { | ||
(x1, x2, x3) => f(Tuple3(x1, x2, x3)) | ||
} | ||
|
||
/** Un-tupling for functions of arity 4. This transforms a function taking | ||
* a 4-tuple of arguments into a function of arity 4 which takes each argument separately. | ||
*/ | ||
def untupled[a1, a2, a3, a4, b](f: Tuple4[a1, a2, a3, a4] => b): (a1, a2, a3, a4) => b = { | ||
(x1, x2, x3, x4) => f(Tuple4(x1, x2, x3, x4)) | ||
} | ||
|
||
/** Un-tupling for functions of arity 5. This transforms a function taking | ||
* a 5-tuple of arguments into a function of arity 5 which takes each argument separately. | ||
*/ | ||
def untupled[a1, a2, a3, a4, a5, b](f: Tuple5[a1, a2, a3, a4, a5] => b): (a1, a2, a3, a4, a5) => b = { | ||
(x1, x2, x3, x4, x5) => f(Tuple5(x1, x2, x3, x4, x5)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* __ *\ | ||
** ________ ___ / / ___ Scala API ** | ||
** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** | ||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** | ||
** /____/\___/_/ |_/____/_/ | | ** | ||
** |/ ** | ||
\* */ | ||
// GENERATED CODE: DO NOT EDIT. | ||
// genprod generated these sources at: Mon Apr 30 07:46:11 PDT 2012 | ||
|
||
package scalaLight | ||
|
||
|
||
/** A function of 0 parameters. | ||
* | ||
* In the following example, the definition of javaVersion is a | ||
* shorthand for the anonymous class definition anonfun0: | ||
* | ||
* {{{ | ||
* object Main extends App { | ||
* val javaVersion = () => sys.props("java.version") | ||
* | ||
* val anonfun0 = new Function0[String] { | ||
* def apply(): String = sys.props("java.version") | ||
* } | ||
* assert(javaVersion() == anonfun0()) | ||
* } | ||
* }}} | ||
* | ||
* Note that `Function1` does not define a total function, as might | ||
* be suggested by the existence of [[scala.PartialFunction]]. The only | ||
* distinction between `Function1` and `PartialFunction` is that the | ||
* latter can specify inputs which it will not handle. | ||
*/ | ||
trait Function0[/*@specialized*/ +R] extends AnyRef { self => | ||
/** Apply the body of this function to the arguments. | ||
* @return the result of function application. | ||
*/ | ||
def apply(): R | ||
|
||
override def toString() = "<function0>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* __ *\ | ||
** ________ ___ / / ___ Scala API ** | ||
** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** | ||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** | ||
** /____/\___/_/ |_/____/_/ | | ** | ||
** |/ ** | ||
\* */ | ||
// GENERATED CODE: DO NOT EDIT. See scala.Function0 for timestamp. | ||
|
||
package scalaLight | ||
|
||
|
||
/** A function of 1 parameter. | ||
* | ||
* In the following example, the definition of succ is a | ||
* shorthand for the anonymous class definition anonfun1: | ||
* | ||
* {{{ | ||
* object Main extends App { | ||
* val succ = (x: Int) => x + 1 | ||
* val anonfun1 = new Function1[Int, Int] { | ||
* def apply(x: Int): Int = x + 1 | ||
* } | ||
* assert(succ(0) == anonfun1(0)) | ||
* } | ||
* }}} | ||
* | ||
* Note that `Function1` does not define a total function, as might | ||
* be suggested by the existence of [[scala.PartialFunction]]. The only | ||
* distinction between `Function1` and `PartialFunction` is that the | ||
* latter can specify inputs which it will not handle. | ||
*/ | ||
@annotation.implicitNotFound(msg = "No implicit view available from ${T1} => ${R}.") | ||
trait Function1[/*@specialized(scala.Int, scala.Long, scala.Float, scala.Double, scala.AnyRef)*/ -T1, /*@specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double, scala.AnyRef)*/ +R] extends AnyRef { self => | ||
/** Apply the body of this function to the argument. | ||
* @return the result of function application. | ||
*/ | ||
def apply(v1: T1): R | ||
|
||
/** Composes two instances of Function1 in a new Function1, with this function applied last. | ||
* | ||
* @tparam A the type to which function `g` can be applied | ||
* @param g a function A => T1 | ||
* @return a new function `f` such that `f(x) == apply(g(x))` | ||
*/ | ||
def compose[A](g: scalaLight.Function1[A, T1]) = new scalaLight.Function1[A, R] { | ||
override def apply(x: A) = Function1.this.apply(g(x)) | ||
} | ||
|
||
/** Composes two instances of Function1 in a new Function1, with this function applied first. | ||
* | ||
* @tparam A the result type of function `g` | ||
* @param g a function R => A | ||
* @return a new function `f` such that `f(x) == g(apply(x))` | ||
*/ | ||
def andThen[A](g: R => A): T1 => A = { x => g(apply(x)) } | ||
|
||
override def toString() = "<function1>" | ||
} |
Oops, something went wrong.