Skip to content

Commit bdeaf6c

Browse files
committed
Merge pull request #222 from sjrd/upgrade-scala-stuff
Upgrade the Scala ecosystem of the bootcompiler.
2 parents dbb8a33 + 208e9d8 commit bdeaf6c

File tree

9 files changed

+56
-45
lines changed

9 files changed

+56
-45
lines changed

bootcompiler/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ lib_managed/
44
src_managed/
55
project/boot/
66
.cache
7+
8+
# Eclipse
9+
/.classpath
10+
/.project
11+
/.settings/

bootcompiler/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ set(SBT "${Java_JAVA_EXECUTABLE}" ${SBT_JAVA_OPTS} -Dfile.encoding=UTF-8
1212

1313
file(GLOB_RECURSE bootcompiler_sources src/*)
1414
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/bootcompiler.jar"
15-
COMMAND ${SBT} one-jar
15+
COMMAND ${SBT} oneJar
1616
COMMAND ${CMAKE_COMMAND} -E copy
17-
"${CMAKE_CURRENT_SOURCE_DIR}/target/scala-2.9.1/bootcompiler_2.9.1-2.0-SNAPSHOT-one-jar.jar"
17+
"${CMAKE_CURRENT_SOURCE_DIR}/target/scala-2.11/bootcompiler_2.11-2.0-SNAPSHOT-one-jar.jar"
1818
"${CMAKE_CURRENT_BINARY_DIR}/bootcompiler.jar"
1919
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
2020
DEPENDS "sbt-launch.jar" "build.sbt" "project/plugins.sbt" ${bootcompiler_sources}

bootcompiler/build.sbt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ name := "bootcompiler"
22

33
version := "2.0-SNAPSHOT"
44

5-
scalaVersion := "2.9.1"
5+
scalaVersion := "2.11.2"
66

77
scalacOptions ++= Seq("-deprecation", "-optimize")
88

9-
libraryDependencies += "com.github.scopt" %% "scopt" % "2.1.0"
9+
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2"
10+
11+
libraryDependencies += "com.github.scopt" %% "scopt" % "3.2.0"
1012

1113
seq(com.github.retronym.SbtOneJar.oneJarSettings: _*)
1214

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=0.13.6

bootcompiler/sbt-launch.jar

110 KB
Binary file not shown.

bootcompiler/src/main/scala/org/mozartoz/bootcompiler/Main.scala

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,27 @@ object Main {
4040
/** Executes the Mozart2 bootstrap compiler */
4141
def main(args: Array[String]) {
4242
// Define command-line options
43-
val optParser = new scopt.immutable.OptionParser[Config]("scopt", "2.x") {
44-
def options = Seq(
45-
flag("baseenv", "switch to base environment mode") {
46-
c => c.copy(mode = Config.Mode.BaseEnv)
47-
},
48-
opt("o", "output", "output file") {
49-
(v, c) => c.copy(outputStream =
50-
() => new BufferedOutputStream(new FileOutputStream(v)))
51-
},
52-
opt("m", "module", "module definition file or directory") {
53-
(v, c) => c.copy(moduleDefs = v :: c.moduleDefs)
54-
},
55-
opt("b", "base", "path to the base declarations file") {
56-
(v, c) => c.copy(baseDeclsFileName = v)
57-
},
58-
opt("D", "define", "add a symbol to the conditional defines") {
59-
(v, c) => c.copy(defines = c.defines + v)
60-
},
61-
arg("<file>", "input file") {
62-
(v, c) => c.copy(fileName = v)
63-
}
64-
)
43+
val optParser = new scopt.OptionParser[Config]("bootcompiler") {
44+
head("bootcompiler", "2.0.x")
45+
opt[Unit]("baseenv") action {
46+
(_, c) => c.copy(mode = Config.Mode.BaseEnv)
47+
} text("switch to base environment mode")
48+
opt[String]('o', "output") action {
49+
(v, c) => c.copy(outputStream =
50+
() => new BufferedOutputStream(new FileOutputStream(v)))
51+
} text("output file")
52+
opt[String]('m', "module") action {
53+
(v, c) => c.copy(moduleDefs = v :: c.moduleDefs)
54+
} text("module definition file or directory")
55+
opt[String]('b', "base") action {
56+
(v, c) => c.copy(baseDeclsFileName = v)
57+
} text("path to the base declarations file")
58+
opt[String]('D', "define") action {
59+
(v, c) => c.copy(defines = c.defines + v)
60+
} text("add a symbol to the conditional defines")
61+
arg[String]("<file>") action {
62+
(v, c) => c.copy(fileName = v)
63+
} text("input file")
6564
}
6665

6766
// Parse the options

bootcompiler/src/main/scala/org/mozartoz/bootcompiler/ast/TreeDSL.scala

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.mozartoz.bootcompiler
22
package ast
33

4+
import scala.reflect.ClassTag
5+
46
import oz._
57
import symtab._
68
import transform._
@@ -236,25 +238,27 @@ trait TreeDSL {
236238
LOCAL (temp) IN expression(temp)
237239
}
238240

239-
def statementWithValIn[A >: Variable <: Expression](value: Expression)(
240-
statement: A => Statement)(implicit m: Manifest[A]) = {
241-
if (m.erasure.isInstance(value)) {
242-
statement(value.asInstanceOf[A])
243-
} else {
244-
statementWithTemp { temp =>
245-
(temp === value) ~ statement(temp)
246-
}
241+
def statementWithValIn[A >: Variable <: Expression : ClassTag](value: Expression)(
242+
statement: A => Statement) = {
243+
value match {
244+
case value: A =>
245+
statement(value)
246+
case _ =>
247+
statementWithTemp { temp =>
248+
(temp === value) ~ statement(temp)
249+
}
247250
}
248251
}
249252

250-
def expressionWithValIn[A >: Variable <: Expression](value: Expression)(
251-
expression: A => Expression)(implicit m: Manifest[A]) = {
252-
if (m.erasure.isInstance(value)) {
253-
expression(value.asInstanceOf[A])
254-
} else {
255-
expressionWithTemp { temp =>
256-
(temp === value) ~> expression(temp)
257-
}
253+
def expressionWithValIn[A >: Variable <: Expression : ClassTag](value: Expression)(
254+
expression: A => Expression) = {
255+
value match {
256+
case value: A =>
257+
expression(value)
258+
case _ =>
259+
expressionWithTemp { temp =>
260+
(temp === value) ~> expression(temp)
261+
}
258262
}
259263
}
260264
}

bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/DesugarFunctor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ object DesugarFunctor extends Transformer with TreeDSL {
104104

105105
val importedDecls = extractAllImportedDecls(imports)
106106

107-
val (definedDecls, defineStat) = define match {
107+
val (definedDecls, defineStat) = (define: @unchecked) match {
108108
case Some(LocalStatement(decls, stat)) => (decls, stat)
109109
case None => (Nil, SkipStatement())
110110
}

bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Transformer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ abstract class Transformer extends (Program => Unit) {
6262
}
6363

6464
/** Transforms a Statement */
65-
def transformStat(statement: Statement): Statement = statement match {
65+
def transformStat(statement: Statement): Statement = (statement: @unchecked) match {
6666
case CompoundStatement(stats) =>
6767
treeCopy.CompoundStatement(statement, stats map transformStat)
6868

@@ -130,7 +130,7 @@ abstract class Transformer extends (Program => Unit) {
130130
}
131131

132132
/** Transforms an expression */
133-
def transformExpr(expression: Expression): Expression = expression match {
133+
def transformExpr(expression: Expression): Expression = (expression: @unchecked) match {
134134
case StatAndExpression(statement, expr) =>
135135
treeCopy.StatAndExpression(expression, transformStat(statement),
136136
transformExpr(expr))

0 commit comments

Comments
 (0)