Skip to content

Commit

Permalink
updates Scala examples, added detach plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
michelou committed Nov 17, 2010
1 parent 363a145 commit c09f617
Show file tree
Hide file tree
Showing 43 changed files with 3,580 additions and 14 deletions.
186 changes: 186 additions & 0 deletions build.detach.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?xml version="1.0" encoding="UTF-8"?>

<project name="sabbus" default="build">

<description>
SuperSabbus for Scala detach plugin.
</description>

<echo level="info" message="Running SABBUS for ${ant.project.name}..."/>

<!-- ===========================================================================
END-USER TARGETS
============================================================================ -->

<target name="build" depends="pack.done"
description="Builds the Scala detach plugin."/>

<target name="clean" depends="quick.clean">
</target>

<target name="all.clean" depends="quick.clean, pack.clean">
</target>

<!-- ===========================================================================
PROPERTIES
============================================================================ -->

<property environment="env"/>
<!-- Prevents system classpath from being used -->
<property name="build.sysclasspath" value="ignore"/>

<!-- Defines the repository layout -->
<property name="lib.dir" value="${basedir}/lib"/>
<property name="src.dir" value="${basedir}/src"/>
<property name="partest.dir" value="${basedir}/test"/>

<!-- Loads custom properties definitions -->
<property file="${basedir}/build.properties"/>

<!-- Sets location of build folders -->
<property name="build.dir" value="${basedir}/build"/>
<property name="build-quick.dir" value="${build.dir}/quick"/>
<property name="build-pack.dir" value="${build.dir}/pack"/>

<!-- if ANT_OPTS is already set by the environment, it will be unaltered,
but if it is unset it will take this default value. -->
<property name="env.ANT_OPTS" value="-Xms1024M -Xmx1024M -Xss1M -XX:MaxPermSize=128M -XX:+UseParallelGC" />

<property
name="scalacfork.jvmargs"
value="${env.ANT_OPTS}"/>

<property name="scalac.args.quick" value="-deprecation"/>
<property name="scalac.args.optimise" value=""/>

<!-- Setting-up Ant contrib tasks -->
<taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${lib.dir}/ant/ant-contrib.jar"/>

<!-- ===========================================================================
QUICK BUILD (QUICK)
============================================================================ -->

<target name="quick.clean">
<delete includeemptydirs="yes" quiet="yes" failonerror="no">
<fileset dir="${build-quick.dir}/classes/detach-library"/>
<fileset dir="${build-quick.dir}/classes/detach-plugin"/>
</delete>
</target>

<target name="quick.done">
<stopwatch name="quick.done.timer"/>
<path id="quick.classpath">
<pathelement location="${build-quick.dir}/classes/library"/>
<pathelement location="${build-quick.dir}/classes/compiler"/>
<pathelement location="${lib.dir}/fjbg.jar"/>
<pathelement location="${lib.dir}/msil.jar"/>
<pathelement location="${lib.dir}/forkjoin.jar"/>
<pathelement location="${ant.home}/lib/ant.jar"/>
</path>
<taskdef
resource="scala/tools/ant/sabbus/antlib.xml"
classpathref="quick.classpath"
/>
<mkdir dir="${build-quick.dir}/classes/detach-plugin"/>
<scalacfork
destdir="${build-quick.dir}/classes/detach-plugin"
compilerpathref="quick.classpath"
params="${scalac.args.quick}"
srcdir="${src.dir}/detach/plugin"
jvmargs="${scalacfork.jvmargs}">
<include name="**/*.scala"/>
<compilationpath>
<pathelement location="${build-quick.dir}/classes/library"/>
<pathelement location="${build-quick.dir}/classes/compiler"/>
<pathelement location="${build-quick.dir}/classes/detach-plugin"/>
<pathelement location="${lib.dir}/forkjoin.jar"/>
</compilationpath>
</scalacfork>
<copy
file="${src.dir}/detach/plugin/scalac-plugin.xml"
todir="${build-quick.dir}/classes/detach-plugin"
/>
<mkdir dir="${build-quick.dir}/classes/detach-library"/>
<scalacfork
destdir="${build-quick.dir}/classes/detach-library"
compilerpathref="quick.classpath"
params="${scalac.args.quick}"
srcdir="${src.dir}/detach/library"
jvmargs="${scalacfork.jvmargs}">
<include name="**/*.scala"/>
<compilationpath>
<pathelement location="${build-quick.dir}/classes/library"/>
<pathelement location="${lib.dir}/forkjoin.jar"/>
</compilationpath>
</scalacfork>
<touch file="${build-quick.dir}/plugins.complete" verbose="no"/>
<stopwatch name="quick.done.timer" action="total"/>
</target>

<!-- ===========================================================================
PACKED QUICK BUILD (PACK)
============================================================================ -->

<target name="pack.start" depends="quick.done"/>

<target name="pack.pre-lib" depends="pack.start">
<uptodate
property="pack.lib.available"
targetfile="${build-pack.dir}/lib/scala-detach.jar"
srcfile="${build-quick.dir}/plugins.complete"/>
</target>

<target name="pack.lib" depends="pack.pre-lib" unless="pack.lib.available">
<mkdir dir="${build-pack.dir}/misc/scala-devel/plugins"/>
<jar destfile="${build-pack.dir}/misc/scala-devel/plugins/detach.jar">
<fileset dir="${build-quick.dir}/classes/detach-plugin"/>
</jar>
<mkdir dir="${build-pack.dir}/lib"/>
<jar destfile="${build-pack.dir}/lib/scala-detach.jar">
<fileset dir="${build-quick.dir}/classes/detach-library">
<include name="scala/**"/>
</fileset>
</jar>
</target>

<target name="pack.done" depends="pack.lib">
<path id="pack.classpath">
<pathelement location="${build-pack.dir}/lib/scala-library.jar"/>
<pathelement location="${build-pack.dir}/lib/scala-compiler.jar"/>
<pathelement location="${build-pack.dir}/lib/scala-detach.jar"/>
<pathelement location="${build-pack.dir}/lib/scala-partest.jar"/>
<pathelement location="${build-pack.dir}/lib/scalap.jar"/>
<pathelement location="${ant.home}/lib/ant.jar"/>
<pathelement location="${lib.dir}/jline.jar"/>
</path>
<taskdef resource="scala/tools/ant/antlib.xml" classpathref="pack.classpath"/>
<taskdef resource="scala/tools/partest/antlib.xml" classpathref="pack.classpath"/>
</target>

<target name="pack.clean">
<delete includeemptydirs="yes" quiet="yes" failonerror="no">
<fileset dir="${build-pack.dir}/lib" includes="scala-detach.jar"/>
<fileset dir="${build-pack.dir}/misc/scala-devel/plugins" includes="detach.jar"/>
</delete>
</target>

<!-- ===========================================================================
TEST SUITE
============================================================================ -->

<target name="test.suite" depends="pack.done">
<property name="partest.srcdir" value="files" />
<partest showlog="yes" erroronfailed="yes" javacmd="${java.home}/bin/java"
timeout="2400000"
srcdir="${partest.srcdir}"
scalacopts="${scalac.args.optimise} -Xpluginsdir ${build-pack.dir}/misc/scala-devel/plugins -Xplugin-require:detach -P:detach:enable">
<compilationpath>
<path refid="pack.classpath"/>
<fileset dir="${partest.dir}/files/lib" includes="*.jar" />
</compilationpath>
<negtests dir="${partest.dir}/${partest.srcdir}/detach-neg" includes="*.scala"/>
<runtests dir="${partest.dir}/${partest.srcdir}/detach-run" includes="*.scala"/>
</partest>
</target>

</project>
16 changes: 14 additions & 2 deletions build.examples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ PROPERTIES
<property name="scala.comp.jar" value="${lib.dir}/scala-compiler.jar"/>
<property name="fjbg.name" value="fjbg.jar"/>
<property name="fjbg.jar" value="${lib.dir}/${fjbg.name}"/>
<property name="msil.name" value="msil.jar"/>
<property name="msil.jar" value="${lib.dir}/${msil.name}"/>
<property name="ant.jar" value="${ant.home}/lib/ant.jar"/>
<property name="ant-contrib.jar" value="${lib.dir}/ant/ant-contrib.jar"/>
<!-- -->
Expand Down Expand Up @@ -61,7 +63,7 @@ INITIALISATION
classpath="${scala.lib.jar}"
/>
<available
classname="scala.List"
classname="scala.collection.immutable.List"
classpath="${scala.lib.jar}"
/>
<available
Expand All @@ -88,6 +90,15 @@ INITIALISATION
/>
</not></condition>
</fail>
<echo level="verbose" message="msil.jar=${msil.jar}"/>
<fail message="MSIL library in '${lib.dir}/' is not available">
<condition><not>
<available
classname="ch.epfl.lamp.compiler.msil.MemberInfo"
classpath="${msil.jar}"
/>
</not></condition>
</fail>
<echo level="verbose" message="ant.jar=${ant.jar}"/>
<echo level="verbose" message="ant-contrib.jar=${ant-contrib.jar}"/>
<fail message="Additional Ant tasks in '${lib.dir}/' is not available">
Expand All @@ -101,6 +112,7 @@ INITIALISATION
<!-- Creating class-pathes -->
<path id="common.classpath">
<pathelement location="${fjbg.jar}"/>
<pathelement location="${msil.jar}"/>
</path>
<path id="scala.classpath">
<pathelement location="${scala.lib.jar}"/>
Expand Down Expand Up @@ -202,7 +214,7 @@ BUILD
<for list="${list}" param="file">
<sequential>
<scalac srcdir="${src.dir}"
destdir="${build.dir}">
destdir="${build.dir}" deprecation="true">
<classpath>
<pathelement location="${scala.lib.jar}"/>
<pathelement location="${build.dir}"/>
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/boundedbuffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ object boundedbuffer {

import concurrent.ops._

class BoundedBuffer[a](N: Int) {
class BoundedBuffer[A](N: Int)(implicit m: ClassManifest[A]) {
var in, out, n = 0
val elems = new Array[a](N)
val elems = new Array[A](N)

def await(cond: => Boolean) = while (!cond) { wait() }

def put(x: a) = synchronized {
def put(x: A) = synchronized {
await (n < N)
elems(in) = x; in = (in + 1) % N; n += 1
if (n == 1) notifyAll()
}

def get: a = synchronized {
def get: A = synchronized {
await (n != 0)
val x = elems(out); out = (out + 1) % N ; n -= 1
if (n == N - 1) notifyAll()
Expand Down
10 changes: 5 additions & 5 deletions docs/examples/gadts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package examples
object gadts extends Application {

abstract class Term[T]
case class Lit(x: int) extends Term[int]
case class Succ(t: Term[int]) extends Term[int]
case class IsZero(t: Term[int]) extends Term[boolean]
case class If[T](c: Term[boolean],
case class Lit(x: Int) extends Term[Int]
case class Succ(t: Term[Int]) extends Term[Int]
case class IsZero(t: Term[Int]) extends Term[Boolean]
case class If[T](c: Term[Boolean],
t1: Term[T],
t2: Term[T]) extends Term[T]

Expand All @@ -16,7 +16,7 @@ object gadts extends Application {
case IsZero(u) => eval(u) == 0
case If(c, u1, u2) => eval(if (eval(c)) u1 else u2)
}
Console.println(
println(
eval(If(IsZero(Lit(1)), Lit(41), Succ(Lit(41)))))
}

4 changes: 2 additions & 2 deletions docs/examples/iterators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ object iterators {
}

def printArray(xs: Array[Double]) =
Iterator.fromArray(xs) foreach { x => println(x) }
xs.iterator foreach { x => println(x) }

def findGreater(xs: Array[Double], limit: Double) =
Iterator.fromArray(xs)
xs.iterator
.zip(Iterator.from(0))
.filter{case Pair(x, i) => x > limit }
.map{case Pair(x, i) => i}
Expand Down
1 change: 0 additions & 1 deletion src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ trait ScalaSettings extends AbsScalaSettings with StandardScalaSettings {
val noCompletion = BooleanSetting ("-Yno-completion", "Disable tab-completion in the REPL")
val Xdce = BooleanSetting ("-Ydead-code", "Perform dead code elimination")
val debug = BooleanSetting ("-Ydebug", "Output debugging messages")
val Xdetach = BooleanSetting ("-Ydetach", "Perform detaching of remote closures")
// val doc = BooleanSetting ("-Ydoc", "Generate documentation")
val inline = BooleanSetting ("-Yinline", "Perform inlining when possible")
val Xlinearizer = ChoiceSetting ("-Ylinearizer", "Linearizer to use", List("normal", "dfs", "rpo", "dump"), "rpo") .
Expand Down
Loading

0 comments on commit c09f617

Please sign in to comment.