Skip to content

Commit cb42466

Browse files
authored
Merge pull request #342 from h7x4/master
Make project build with latest dependencies
2 parents b17889a + 90eb88e commit cb42466

27 files changed

+172
-146
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
*.o
55
*.a
66

7+
# For ease of use as cmake build directory
8+
/build

bootcompiler/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ project(MOZARTBOOTCOMPILER NONE)
44
find_package(Java COMPONENTS Runtime REQUIRED)
55

66
set(SBT_JAVA_OPTS
7-
-Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M
7+
-Xms512M -Xmx1024M -Xss1M
88
CACHE STRING "Options passed to the Java executable when running sbt")
99

1010
set(SBT "${Java_JAVA_EXECUTABLE}" ${SBT_JAVA_OPTS} -Dfile.encoding=UTF-8
1111
-jar "${CMAKE_CURRENT_SOURCE_DIR}/sbt-launch.jar")
1212

1313
file(GLOB_RECURSE bootcompiler_sources src/*)
1414
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/bootcompiler.jar"
15-
COMMAND ${SBT} oneJar
15+
COMMAND ${SBT} assembly
1616
COMMAND ${CMAKE_COMMAND} -E copy
17-
"${CMAKE_CURRENT_SOURCE_DIR}/target/scala-2.11/bootcompiler_2.11-2.0-SNAPSHOT-one-jar.jar"
17+
"${CMAKE_CURRENT_SOURCE_DIR}/target/scala-2.13/bootcompiler-assembly-2.0-SNAPSHOT.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

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ name := "bootcompiler"
22

33
version := "2.0-SNAPSHOT"
44

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

7-
scalacOptions ++= Seq("-deprecation", "-optimize")
7+
scalacOptions ++= Seq("-language:postfixOps", "-deprecation", "-optimize")
88

9-
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2"
10-
11-
libraryDependencies += "com.github.scopt" %% "scopt" % "3.2.0"
12-
13-
seq(com.github.retronym.SbtOneJar.oneJarSettings: _*)
9+
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "2.1.1"
10+
libraryDependencies += "com.github.scopt" %% "scopt" % "4.1.0"
11+
libraryDependencies += "io.spray" %% "spray-json" % "1.3.6"
1412

1513
// Work around a bug that prevents generating documentation
1614
unmanagedClasspath in Compile +=
1715
Attributed.blank(new java.io.File("doesnotexist"))
16+
17+
// Added during migration to the java 9 module system
18+
Compile / packageBin / packageOptions +=
19+
Package.ManifestAttributes("Add-Exports" -> "java.base/jdk.internal.math")

bootcompiler/project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.6
1+
sbt.version=1.6.2

bootcompiler/project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
addSbtPlugin("com.github.retronym" % "sbt-onejar" % "0.8")
1+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")

bootcompiler/sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env sh
22

3-
java ${DEBUG_PARAM} -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled \
4-
-XX:MaxPermSize=384M ${JAVA_OPTS} -Dfile.encoding=UTF-8 \
3+
java ${DEBUG_PARAM} -Xms512M -Xmx1536M -Xss1M \
4+
${JAVA_OPTS} -Dfile.encoding=UTF-8 \
55
-jar `dirname $0`/sbt-launch.jar "$@"

bootcompiler/sbt.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
@echo off
22

33
set SCRIPT_DIR=%~dp0
4-
java -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M %JAVA_OPTS% -Dfile.encoding=UTF-8 -jar "%SCRIPT_DIR%sbt-launch.jar" %*
4+
java -Xms512M -Xmx1024M -Xss1M %JAVA_OPTS% -Dfile.encoding=UTF-8 -jar "%SCRIPT_DIR%sbt-launch.jar" %*

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

+92-82
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package org.mozartoz.bootcompiler
33
import java.io.{ Console => _, _ }
44

55
import scala.collection.mutable.ListBuffer
6-
import scala.collection.immutable.PagedSeq
6+
import scala.util.parsing.input.PagedSeqReader
77
import scala.util.parsing.combinator._
88
import scala.util.parsing.input._
9-
import scala.util.parsing.json._
9+
10+
import scopt.{ OParser, OParserSetup, DefaultOParserSetup }
11+
import spray.json._
1012

1113
import oz._
1214
import parser._
@@ -38,34 +40,39 @@ case class Config(
3840
/** Entry point for the Mozart2 bootstrap compiler */
3941
object Main {
4042
/** Executes the Mozart2 bootstrap compiler */
41-
def main(args: Array[String]) {
43+
def main(args: Array[String]): Unit = {
4244
// Define command-line options
4345
val optParser = new scopt.OptionParser[Config]("bootcompiler") {
4446
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")
47+
48+
opt[Unit]("baseenv")
49+
.action((_, c) => c.copy(mode = Config.Mode.BaseEnv))
50+
.text("switch to base environment mode")
51+
52+
opt[String]('o', "output")
53+
.action((v, c) =>
54+
c.copy(outputStream = () => new BufferedOutputStream(new FileOutputStream(v))))
55+
.text("output file")
56+
57+
opt[String]('m', "module")
58+
.action((v, c) => c.copy(moduleDefs = v :: c.moduleDefs))
59+
.text("module definition file or directory")
60+
61+
opt[String]('b', "base")
62+
.action((v, c) => c.copy(baseDeclsFileName = v))
63+
.text("path to the base declarations file")
64+
65+
opt[String]('D', "define")
66+
.action((v, c) => c.copy(defines = c.defines + v))
67+
.text("add a symbol to the conditional defines")
68+
69+
arg[String]("<file>")
70+
.action((v, c) => c.copy(fileName = v))
71+
.text("input file")
6472
}
6573

6674
// Parse the options
67-
optParser.parse(args, Config()) map { config =>
68-
// OK, we're good to go
75+
optParser.parse(args, Config()).foreach({ config =>
6976
try {
7077
config.mode match {
7178
case Config.Mode.Module =>
@@ -80,15 +87,11 @@ object Main {
8087
th.printStackTrace()
8188
sys.exit(2)
8289
}
83-
} getOrElse {
84-
// Bad command-line arguments
85-
optParser.showUsage
86-
sys.exit(1)
87-
}
90+
})
8891
}
8992

9093
/** Performs the Module mode */
91-
private def mainModule(config: Config) {
94+
private def mainModule(config: Config): Unit = {
9295
import config._
9396

9497
val (program, _) = createProgram(moduleDefs, Some(baseDeclsFileName))
@@ -103,7 +106,7 @@ object Main {
103106
}
104107

105108
/** Performs the BaseEnv mode */
106-
private def mainBaseEnv(config: Config) {
109+
private def mainBaseEnv(config: Config): Unit = {
107110
import config._
108111

109112
val (program, bootModules) = createProgram(moduleDefs, None, true)
@@ -120,8 +123,10 @@ object Main {
120123
}
121124

122125
/** Creates a new Program */
123-
private def createProgram(moduleDefs: List[String],
124-
baseDeclsFileName: Option[String], isBaseEnvironment: Boolean = false) = {
126+
private def createProgram(
127+
moduleDefs: List[String],
128+
baseDeclsFileName: Option[String],
129+
isBaseEnvironment: Boolean = false): (Program, Map[String, Expression]) = {
125130
val program = new Program(isBaseEnvironment)
126131
val bootModules = loadModuleDefs(program, moduleDefs)
127132

@@ -140,8 +145,10 @@ object Main {
140145
* @param reader input reader
141146
* @return The statement AST
142147
*/
143-
private def parseStatement(reader: PagedSeqReader, file: File,
144-
defines: Set[String]) =
148+
private def parseStatement(
149+
reader: PagedSeqReader,
150+
file: File,
151+
defines: Set[String]): Statement =
145152
new ParserWrapper().parseStatement(reader, file, defines)
146153

147154
/** Parses an Oz expression from a reader
@@ -153,7 +160,7 @@ object Main {
153160
* @return The expression AST
154161
*/
155162
private def parseExpression(reader: PagedSeqReader, file: File,
156-
defines: Set[String]) =
163+
defines: Set[String]): Expression =
157164
new ParserWrapper().parseExpression(reader, file, defines)
158165

159166
/** Utility wrapper for an [[org.mozartoz.bootcompiler.parser.OzParser]]
@@ -165,11 +172,11 @@ object Main {
165172
private val parser = new OzParser()
166173

167174
def parseStatement(reader: PagedSeqReader, file: File,
168-
defines: Set[String]) =
175+
defines: Set[String]): Statement =
169176
processResult(parser.parseStatement(reader, file, defines))
170177

171178
def parseExpression(reader: PagedSeqReader, file: File,
172-
defines: Set[String]) =
179+
defines: Set[String]): Expression =
173180
processResult(parser.parseExpression(reader, file, defines))
174181

175182
/** Processes a parse result
@@ -200,7 +207,7 @@ object Main {
200207
*
201208
* @param fileName name of the file to be read
202209
*/
203-
private def readerForFile(fileName: String) = {
210+
private def readerForFile(fileName: String): PagedSeqReader = {
204211
new PagedSeqReader(PagedSeq.fromReader(
205212
new BufferedReader(new FileReader(fileName))))
206213
}
@@ -211,8 +218,6 @@ object Main {
211218
* @param moduleDefs list of files that define builtin modules
212219
*/
213220
private def loadModuleDefs(prog: Program, moduleDefs: List[String]) = {
214-
JSON.globalNumberParser = (_.toInt)
215-
216221
val result = new scala.collection.mutable.HashMap[String, Expression]
217222

218223
for (moduleDef <- moduleDefs) {
@@ -235,53 +240,58 @@ object Main {
235240
}
236241

237242
/** Loads one builtin module definition */
238-
private def loadModuleDef(prog: Program, moduleDef: File) = {
239-
class CC[T] {
240-
def unapply(a: Any): Option[T] = Some(a.asInstanceOf[T])
243+
private def loadModuleDef(prog: Program, moduleDef: File): List[(String, Record)] = {
244+
case class JsParameter(val kind: String)
245+
246+
case class JsBuiltin(
247+
val name: String,
248+
val inlineable: Boolean,
249+
val inlineOpCode: Option[Int],
250+
val params: List[JsParameter]
251+
)
252+
253+
case class JsModule(
254+
val name: String,
255+
val builtins: List[JsBuiltin]
256+
)
257+
258+
object ModuleJsonProtocol extends DefaultJsonProtocol {
259+
implicit val parameterJsonFormat: RootJsonFormat[JsParameter] = jsonFormat1(JsParameter)
260+
implicit val builtinJsonFormat: RootJsonFormat[JsBuiltin] = jsonFormat4(JsBuiltin)
261+
implicit val moduleJsonFormat: RootJsonFormat[JsModule] = jsonFormat2(JsModule)
241262
}
242263

243-
object M extends CC[Map[String, Any]]
244-
object L extends CC[List[Any]]
245-
object S extends CC[String]
246-
object D extends CC[Double]
247-
object B extends CC[Boolean]
264+
import ModuleJsonProtocol._
265+
266+
val jsModule: JsModule =
267+
readFileToString(moduleDef)
268+
.parseJson
269+
.convertTo[JsModule]
248270

249-
val modules = JSON.parseFull(readFileToString(moduleDef)).toList
271+
val exportFields = new ListBuffer[RecordField]
250272

251273
for {
252-
M(module) <- modules
253-
S(modName) = module("name")
254-
L(builtins) = module("builtins")
274+
jsBuiltin <- jsModule.builtins
255275
} yield {
256-
val exportFields = new ListBuffer[RecordField]
257-
258-
for {
259-
M(bi) <- builtins
260-
S(biName) = bi("name")
261-
B(inlineable) = bi("inlineable")
262-
L(params) = bi("params")
263-
} {
264-
val inlineAs =
265-
if (inlineable) Some(bi("inlineOpCode").asInstanceOf[Int])
266-
else None
267-
268-
val paramKinds = for {
269-
M(param) <- params
270-
S(paramKind) = param("kind")
271-
} yield {
272-
Builtin.ParamKind.withName(paramKind)
273-
}
276+
val inlineAs: Option[Int] =
277+
if (jsBuiltin.inlineable) jsBuiltin.inlineOpCode
278+
else None
279+
280+
val paramKinds = for {
281+
jsParam <- jsBuiltin.params
282+
} yield {
283+
Builtin.ParamKind.withName(jsParam.kind)
284+
}
274285

275-
val builtin = new Builtin(
276-
modName, biName, paramKinds, inlineAs)
286+
val builtin = new Builtin(
287+
jsModule.name, jsBuiltin.name, paramKinds, inlineAs)
277288

278-
prog.builtins.register(builtin)
289+
prog.builtins.register(builtin)
279290

280-
exportFields += RecordField(
281-
Constant(OzAtom(biName)), Constant(OzBuiltin(builtin)))
282-
}
291+
exportFields += RecordField(
292+
Constant(OzAtom(builtin.name)), Constant(OzBuiltin(builtin)))
283293

284-
val moduleURL = "x-oz://boot/" + modName
294+
val moduleURL = "x-oz://boot/" + jsModule.name
285295
val moduleExport = Record(Constant(OzAtom("export")), exportFields.toList)
286296

287297
moduleURL -> moduleExport
@@ -293,7 +303,7 @@ object Main {
293303
* @param prog program to compile
294304
* @param fileName top-level file that is being processed
295305
*/
296-
private def compile(prog: Program, fileName: String) {
306+
private def compile(prog: Program, fileName: String): Unit = {
297307
applyTransforms(prog)
298308

299309
if (prog.hasErrors) {
@@ -311,7 +321,7 @@ object Main {
311321
}
312322

313323
/** Applies the successive transformation phases to a program */
314-
private def applyTransforms(prog: Program) {
324+
private def applyTransforms(prog: Program): Unit = {
315325
Namer(prog)
316326
DesugarFunctor(prog)
317327
DesugarClass(prog)
@@ -328,7 +338,7 @@ object Main {
328338
* @param file file to read
329339
* @return the contents of the file
330340
*/
331-
private def readFileToString(file: File) = {
341+
private def readFileToString(file: File): String = {
332342
val source = io.Source.fromFile(file)
333343
try source.mkString
334344
finally source.close()
@@ -339,7 +349,7 @@ object Main {
339349
* @param file file to read
340350
* @return the lines in the file
341351
*/
342-
private def readFileLines(file: File) = {
352+
private def readFileLines(file: File): List[String] = {
343353
val source = io.Source.fromFile(file)
344354
try source.getLines().toList
345355
finally source.close()

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object ProgramBuilder extends TreeDSL with TransformUtils {
1919
* end
2020
* }}}
2121
*/
22-
def buildModuleProgram(prog: Program, functor: Expression) {
22+
def buildModuleProgram(prog: Program, functor: Expression): Unit = {
2323
prog.rawCode = {
2424
prog.topLevelResultSymbol === functor
2525
}
@@ -65,7 +65,7 @@ object ProgramBuilder extends TreeDSL with TransformUtils {
6565
*/
6666
def buildBaseEnvProgram(prog: Program,
6767
bootModulesMap: Map[String, Expression],
68-
baseFunctor0: Expression) {
68+
baseFunctor0: Expression): Unit = {
6969

7070
val baseFunctor = baseFunctor0.asInstanceOf[FunctorExpression]
7171

0 commit comments

Comments
 (0)