diff --git a/bootcompiler/CMakeLists.txt b/bootcompiler/CMakeLists.txt index c5700daa3..582187fc2 100644 --- a/bootcompiler/CMakeLists.txt +++ b/bootcompiler/CMakeLists.txt @@ -4,7 +4,7 @@ project(MOZARTBOOTCOMPILER NONE) find_package(Java COMPONENTS Runtime REQUIRED) set(SBT_JAVA_OPTS - -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M + -Xms512M -Xmx1024M -Xss1M CACHE STRING "Options passed to the Java executable when running sbt") set(SBT "${Java_JAVA_EXECUTABLE}" ${SBT_JAVA_OPTS} -Dfile.encoding=UTF-8 @@ -12,9 +12,9 @@ set(SBT "${Java_JAVA_EXECUTABLE}" ${SBT_JAVA_OPTS} -Dfile.encoding=UTF-8 file(GLOB_RECURSE bootcompiler_sources src/*) add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/bootcompiler.jar" - COMMAND ${SBT} oneJar + COMMAND ${SBT} assembly COMMAND ${CMAKE_COMMAND} -E copy - "${CMAKE_CURRENT_SOURCE_DIR}/target/scala-2.11/bootcompiler_2.11-2.0-SNAPSHOT-one-jar.jar" + "${CMAKE_CURRENT_SOURCE_DIR}/target/scala-2.13/bootcompiler-assembly-2.0-SNAPSHOT.jar" "${CMAKE_CURRENT_BINARY_DIR}/bootcompiler.jar" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS "sbt-launch.jar" "build.sbt" "project/plugins.sbt" ${bootcompiler_sources} diff --git a/bootcompiler/build.sbt b/bootcompiler/build.sbt index f0fb42cba..a3faff98f 100644 --- a/bootcompiler/build.sbt +++ b/bootcompiler/build.sbt @@ -2,16 +2,18 @@ name := "bootcompiler" version := "2.0-SNAPSHOT" -scalaVersion := "2.11.2" +scalaVersion := "2.13.8" -scalacOptions ++= Seq("-deprecation", "-optimize") +scalacOptions ++= Seq("-language:postfixOps", "-deprecation", "-optimize") -libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2" - -libraryDependencies += "com.github.scopt" %% "scopt" % "3.2.0" - -seq(com.github.retronym.SbtOneJar.oneJarSettings: _*) +libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "2.1.1" +libraryDependencies += "com.github.scopt" %% "scopt" % "4.1.0" +libraryDependencies += "io.spray" %% "spray-json" % "1.3.6" // Work around a bug that prevents generating documentation unmanagedClasspath in Compile += Attributed.blank(new java.io.File("doesnotexist")) + +// Added during migration to the java 9 module system +Compile / packageBin / packageOptions += + Package.ManifestAttributes("Add-Exports" -> "java.base/jdk.internal.math") diff --git a/bootcompiler/project/build.properties b/bootcompiler/project/build.properties index 64abd373f..c8fcab543 100644 --- a/bootcompiler/project/build.properties +++ b/bootcompiler/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.6 +sbt.version=1.6.2 diff --git a/bootcompiler/project/plugins.sbt b/bootcompiler/project/plugins.sbt index 2e131e947..652a3b93b 100644 --- a/bootcompiler/project/plugins.sbt +++ b/bootcompiler/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("com.github.retronym" % "sbt-onejar" % "0.8") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6") diff --git a/bootcompiler/sbt b/bootcompiler/sbt index 27ecaebca..3010d7c43 100755 --- a/bootcompiler/sbt +++ b/bootcompiler/sbt @@ -1,5 +1,5 @@ #!/usr/bin/env sh -java ${DEBUG_PARAM} -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled \ - -XX:MaxPermSize=384M ${JAVA_OPTS} -Dfile.encoding=UTF-8 \ +java ${DEBUG_PARAM} -Xms512M -Xmx1536M -Xss1M \ + ${JAVA_OPTS} -Dfile.encoding=UTF-8 \ -jar `dirname $0`/sbt-launch.jar "$@" diff --git a/bootcompiler/sbt.bat b/bootcompiler/sbt.bat index 00d1b2729..cdb2ee59b 100644 --- a/bootcompiler/sbt.bat +++ b/bootcompiler/sbt.bat @@ -1,4 +1,4 @@ @echo off set SCRIPT_DIR=%~dp0 -java -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M %JAVA_OPTS% -Dfile.encoding=UTF-8 -jar "%SCRIPT_DIR%sbt-launch.jar" %* +java -Xms512M -Xmx1024M -Xss1M %JAVA_OPTS% -Dfile.encoding=UTF-8 -jar "%SCRIPT_DIR%sbt-launch.jar" %* diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/Main.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/Main.scala index 064e4cbdb..3d7db1094 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/Main.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/Main.scala @@ -3,10 +3,12 @@ package org.mozartoz.bootcompiler import java.io.{ Console => _, _ } import scala.collection.mutable.ListBuffer -import scala.collection.immutable.PagedSeq +import scala.util.parsing.input.PagedSeqReader import scala.util.parsing.combinator._ import scala.util.parsing.input._ -import scala.util.parsing.json._ + +import scopt.{ OParser, OParserSetup, DefaultOParserSetup } +import spray.json._ import oz._ import parser._ @@ -38,31 +40,38 @@ case class Config( /** Entry point for the Mozart2 bootstrap compiler */ object Main { /** Executes the Mozart2 bootstrap compiler */ - def main(args: Array[String]) { + def main(args: Array[String]): Unit = { // Define command-line options val optParser = new scopt.OptionParser[Config]("bootcompiler") { head("bootcompiler", "2.0.x") - opt[Unit]("baseenv") action { - (_, c) => c.copy(mode = Config.Mode.BaseEnv) - } text("switch to base environment mode") - opt[String]('o', "output") action { - (v, c) => c.copy(outputStream = - () => new BufferedOutputStream(new FileOutputStream(v))) - } text("output file") - opt[String]('m', "module") action { - (v, c) => c.copy(moduleDefs = v :: c.moduleDefs) - } text("module definition file or directory") - opt[String]('b', "base") action { - (v, c) => c.copy(baseDeclsFileName = v) - } text("path to the base declarations file") - opt[String]('D', "define") action { - (v, c) => c.copy(defines = c.defines + v) - } text("add a symbol to the conditional defines") - arg[String]("") action { - (v, c) => c.copy(fileName = v) - } text("input file") + + opt[Unit]("baseenv") + .action((_, c) => c.copy(mode = Config.Mode.BaseEnv)) + .text("switch to base environment mode") + + opt[String]('o', "output") + .action((v, c) => + c.copy(outputStream = () => new BufferedOutputStream(new FileOutputStream(v)))) + .text("output file") + + opt[String]('m', "module") + .action((v, c) => c.copy(moduleDefs = v :: c.moduleDefs)) + .text("module definition file or directory") + + opt[String]('b', "base") + .action((v, c) => c.copy(baseDeclsFileName = v)) + .text("path to the base declarations file") + + opt[String]('D', "define") + .action((v, c) => c.copy(defines = c.defines + v)) + .text("add a symbol to the conditional defines") + + arg[String]("") + .action((v, c) => c.copy(fileName = v)) + .text("input file") } + // Parse the options optParser.parse(args, Config()) map { config => // OK, we're good to go @@ -80,15 +89,11 @@ object Main { th.printStackTrace() sys.exit(2) } - } getOrElse { - // Bad command-line arguments - optParser.showUsage - sys.exit(1) } } /** Performs the Module mode */ - private def mainModule(config: Config) { + private def mainModule(config: Config): Unit = { import config._ val (program, _) = createProgram(moduleDefs, Some(baseDeclsFileName)) @@ -103,7 +108,7 @@ object Main { } /** Performs the BaseEnv mode */ - private def mainBaseEnv(config: Config) { + private def mainBaseEnv(config: Config): Unit = { import config._ val (program, bootModules) = createProgram(moduleDefs, None, true) @@ -120,8 +125,10 @@ object Main { } /** Creates a new Program */ - private def createProgram(moduleDefs: List[String], - baseDeclsFileName: Option[String], isBaseEnvironment: Boolean = false) = { + private def createProgram( + moduleDefs: List[String], + baseDeclsFileName: Option[String], + isBaseEnvironment: Boolean = false): (Program, Map[String, Expression]) = { val program = new Program(isBaseEnvironment) val bootModules = loadModuleDefs(program, moduleDefs) @@ -140,8 +147,10 @@ object Main { * @param reader input reader * @return The statement AST */ - private def parseStatement(reader: PagedSeqReader, file: File, - defines: Set[String]) = + private def parseStatement( + reader: PagedSeqReader, + file: File, + defines: Set[String]): Statement = new ParserWrapper().parseStatement(reader, file, defines) /** Parses an Oz expression from a reader @@ -153,7 +162,7 @@ object Main { * @return The expression AST */ private def parseExpression(reader: PagedSeqReader, file: File, - defines: Set[String]) = + defines: Set[String]): Expression = new ParserWrapper().parseExpression(reader, file, defines) /** Utility wrapper for an [[org.mozartoz.bootcompiler.parser.OzParser]] @@ -165,11 +174,11 @@ object Main { private val parser = new OzParser() def parseStatement(reader: PagedSeqReader, file: File, - defines: Set[String]) = + defines: Set[String]): Statement = processResult(parser.parseStatement(reader, file, defines)) def parseExpression(reader: PagedSeqReader, file: File, - defines: Set[String]) = + defines: Set[String]): Expression = processResult(parser.parseExpression(reader, file, defines)) /** Processes a parse result @@ -200,7 +209,7 @@ object Main { * * @param fileName name of the file to be read */ - private def readerForFile(fileName: String) = { + private def readerForFile(fileName: String): PagedSeqReader = { new PagedSeqReader(PagedSeq.fromReader( new BufferedReader(new FileReader(fileName)))) } @@ -211,7 +220,7 @@ object Main { * @param moduleDefs list of files that define builtin modules */ private def loadModuleDefs(prog: Program, moduleDefs: List[String]) = { - JSON.globalNumberParser = (_.toInt) + // JSON.globalNumberParser = (_.toInt) val result = new scala.collection.mutable.HashMap[String, Expression] @@ -235,53 +244,60 @@ object Main { } /** Loads one builtin module definition */ - private def loadModuleDef(prog: Program, moduleDef: File) = { - class CC[T] { - def unapply(a: Any): Option[T] = Some(a.asInstanceOf[T]) + private def loadModuleDef(prog: Program, moduleDef: File): List[(String, Record)] = { + case class JsParameter(val kind: String) + + case class JsBuiltin( + val name: String, + val inlineable: Boolean, + val inlineOpCode: Option[Int], + val params: List[JsParameter] + ) + + case class JsModule( + val name: String, + val builtins: List[JsBuiltin] + ) + + object ModuleJsonProtocol extends DefaultJsonProtocol { + implicit val parameterJsonFormat = jsonFormat1(JsParameter) + implicit val builtinJsonFormat = jsonFormat4(JsBuiltin) + implicit val moduleJsonFormat = jsonFormat2(JsModule) } - object M extends CC[Map[String, Any]] - object L extends CC[List[Any]] - object S extends CC[String] - object D extends CC[Double] - object B extends CC[Boolean] + import ModuleJsonProtocol._ + + val jsModule: JsModule = + readFileToString(moduleDef) + .parseJson + .convertTo[JsModule] - val modules = JSON.parseFull(readFileToString(moduleDef)).toList + val exportFields = new ListBuffer[RecordField] for { - M(module) <- modules - S(modName) = module("name") - L(builtins) = module("builtins") + jsBuiltin <- jsModule.builtins } yield { - val exportFields = new ListBuffer[RecordField] - - for { - M(bi) <- builtins - S(biName) = bi("name") - B(inlineable) = bi("inlineable") - L(params) = bi("params") - } { - val inlineAs = - if (inlineable) Some(bi("inlineOpCode").asInstanceOf[Int]) - else None - - val paramKinds = for { - M(param) <- params - S(paramKind) = param("kind") - } yield { - Builtin.ParamKind.withName(paramKind) - } + val inlineAs: Option[Int] = + if (jsBuiltin.inlineable) jsBuiltin.inlineOpCode + else None + // if (inlineable) Some(bi("inlineOpCode").asInstanceOf[Int]) + // else None + + val paramKinds = for { + jsParam <- jsBuiltin.params + } yield { + Builtin.ParamKind.withName(jsParam.kind) + } - val builtin = new Builtin( - modName, biName, paramKinds, inlineAs) + val builtin = new Builtin( + jsModule.name, jsBuiltin.name, paramKinds, inlineAs) - prog.builtins.register(builtin) + prog.builtins.register(builtin) - exportFields += RecordField( - Constant(OzAtom(biName)), Constant(OzBuiltin(builtin))) - } + exportFields += RecordField( + Constant(OzAtom(builtin.name)), Constant(OzBuiltin(builtin))) - val moduleURL = "x-oz://boot/" + modName + val moduleURL = "x-oz://boot/" + jsModule.name val moduleExport = Record(Constant(OzAtom("export")), exportFields.toList) moduleURL -> moduleExport @@ -293,7 +309,7 @@ object Main { * @param prog program to compile * @param fileName top-level file that is being processed */ - private def compile(prog: Program, fileName: String) { + private def compile(prog: Program, fileName: String): Unit = { applyTransforms(prog) if (prog.hasErrors) { @@ -311,7 +327,7 @@ object Main { } /** Applies the successive transformation phases to a program */ - private def applyTransforms(prog: Program) { + private def applyTransforms(prog: Program): Unit = { Namer(prog) DesugarFunctor(prog) DesugarClass(prog) @@ -328,7 +344,7 @@ object Main { * @param file file to read * @return the contents of the file */ - private def readFileToString(file: File) = { + private def readFileToString(file: File): String = { val source = io.Source.fromFile(file) try source.mkString finally source.close() @@ -339,7 +355,7 @@ object Main { * @param file file to read * @return the lines in the file */ - private def readFileLines(file: File) = { + private def readFileLines(file: File): List[String] = { val source = io.Source.fromFile(file) try source.getLines().toList finally source.close() diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/ProgramBuilder.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/ProgramBuilder.scala index e822a19cc..f6f963a75 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/ProgramBuilder.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/ProgramBuilder.scala @@ -19,7 +19,7 @@ object ProgramBuilder extends TreeDSL with TransformUtils { * end * }}} */ - def buildModuleProgram(prog: Program, functor: Expression) { + def buildModuleProgram(prog: Program, functor: Expression): Unit = { prog.rawCode = { prog.topLevelResultSymbol === functor } @@ -65,7 +65,7 @@ object ProgramBuilder extends TreeDSL with TransformUtils { */ def buildBaseEnvProgram(prog: Program, bootModulesMap: Map[String, Expression], - baseFunctor0: Expression) { + baseFunctor0: Expression): Unit = { val baseFunctor = baseFunctor0.asInstanceOf[FunctorExpression] diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/Serializer.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/Serializer.scala index 5a495b959..d8a0b4673 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/Serializer.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/Serializer.scala @@ -12,7 +12,7 @@ class Serializer(program: Program, output: BufferedOutputStream) { // Top-level - def serialize() { + def serialize(): Unit = { val topLevelCodeArea = OzCodeArea(program.topLevelAbstraction.codeArea) val topLevelValue = OzAbstraction(topLevelCodeArea, Nil) giveIndex(topLevelValue) @@ -28,14 +28,14 @@ class Serializer(program: Program, output: BufferedOutputStream) { // Give indices to nodes - private def giveIndex(value: OzValue) { + private def giveIndex(value: OzValue): Unit = { nodeToIndex.getOrElseUpdate(value, { giveIndicesInside(value) indexCounter.next() }) } - private def giveIndicesInside(value: OzValue) { + private def giveIndicesInside(value: OzValue): Unit = { value match { case OzCons(head, tail) => giveIndex(head) @@ -74,7 +74,7 @@ class Serializer(program: Program, output: BufferedOutputStream) { // Writing of nodes - private def writeValue(index: Int, value: OzValue) { + private def writeValue(index: Int, value: OzValue): Unit = { writeSize(index) value match { @@ -153,7 +153,7 @@ class Serializer(program: Program, output: BufferedOutputStream) { } } - private def writeCodeArea(codeArea: CodeArea) { + private def writeCodeArea(codeArea: CodeArea): Unit = { val codeBlock = for { opCode <- codeArea.opCodes.toList byteCodeElem <- opCode.encoding @@ -178,38 +178,38 @@ class Serializer(program: Program, output: BufferedOutputStream) { // Low-level write procs - private def writeSize(size: Int) { + private def writeSize(size: Int): Unit = { output.write(size >> 24 & 0xff) output.write(size >> 16 & 0xff) output.write(size >> 8 & 0xff) output.write(size & 0xff) } - private def writeByte(b: Int) { + private def writeByte(b: Int): Unit = { output.write(b) } - private def writeString(str: String) { + private def writeString(str: String): Unit = { val bytes = str.getBytes(Serializer.charset) writeSize(bytes.length) output.write(bytes) } - private def writeAtom(atom: String) { + private def writeAtom(atom: String): Unit = { writeString(atom) } - private def writeRef(value: OzValue) { + private def writeRef(value: OzValue): Unit = { writeSize(nodeToIndex(value)) } - private def writeRefs(values: Seq[OzValue]) { + private def writeRefs(values: Seq[OzValue]): Unit = { writeSize(values.size) values foreach writeRef } - private def writeRandomUUID() { - def writeLong(value: Long) { + private def writeRandomUUID(): Unit = { + def writeLong(value: Long): Unit = { for (i <- (0 until 64 by 8).reverse) output.write(((value >> i) & 0xff).asInstanceOf[Int]) } @@ -223,7 +223,7 @@ class Serializer(program: Program, output: BufferedOutputStream) { object Serializer { val charset = java.nio.charset.Charset.forName("UTF-8") - def serialize(program: Program, output: BufferedOutputStream) { + def serialize(program: Program, output: BufferedOutputStream): Unit = { new Serializer(program, output).serialize() } } diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/ast/Node.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/ast/Node.scala index 0b6bd078f..8ee64c0a8 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/ast/Node.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/ast/Node.scala @@ -32,9 +32,9 @@ abstract class Node extends Product with Positional { * * @param handler handler callback */ - def walkBreak(handler: Node => Boolean) { + def walkBreak(handler: Node => Boolean): Unit = { if (handler(this)) { - def inner(element: Any) { + def inner(element: Any): Unit = { element match { case node:Node => node.walk(handler) case seq:Seq[_] => seq foreach inner @@ -52,7 +52,7 @@ abstract class Node extends Product with Positional { * * @param handler handler callback */ - def walk[U](handler: Node => U) { + def walk[U](handler: Node => U): Unit = { walkBreak { node => handler(node) true diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/bytecode/CodeArea.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/bytecode/CodeArea.scala index 1ee39103d..b48a17169 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/bytecode/CodeArea.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/bytecode/CodeArea.scala @@ -24,7 +24,7 @@ class CodeArea(val abstraction: Abstraction) { override def toString() = "" format (abstraction.fullName) - def dump(includeByteCode: Boolean = true) { + def dump(includeByteCode: Boolean = true): Unit = { println("constants:") for ((constant, index) <- constants.zipWithIndex) println(" K(%d) = %s" format (index, constant)) @@ -62,7 +62,7 @@ class CodeArea(val abstraction: Abstraction) { opCodes += opCode class Hole(index: Int) { - def fillWith(opCode: OpCode) { + def fillWith(opCode: OpCode): Unit = { opCodes(index) = opCode } } diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/parser/OzPreprocessor.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/parser/OzPreprocessor.scala index 1c5d63a1e..bf5320a47 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/parser/OzPreprocessor.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/parser/OzPreprocessor.scala @@ -3,8 +3,6 @@ package parser import java.io.{ File, FileReader, BufferedReader } -import scala.collection.immutable.PagedSeq - import scala.util.parsing.input._ import scala.util.parsing.combinator.token._ diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Abstraction.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Abstraction.scala index 0ceb331e4..1d0f931c0 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Abstraction.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Abstraction.scala @@ -42,7 +42,7 @@ class Abstraction(val owner: Abstraction, val name: String, val pos: Position) { def arity = formals.size /** Acquires a symbol as being declared in this abstraction */ - def acquire(symbol: Symbol) { + def acquire(symbol: Symbol): Unit = { symbol.setOwner(this) if (symbol.isFormal) formals += symbol else if (symbol.isGlobal) globals += symbol @@ -75,7 +75,7 @@ class Abstraction(val owner: Abstraction, val name: String, val pos: Position) { * * @param includeByteCode include the bytecode in the dump */ - def dump(includeByteCode: Boolean = true) { + def dump(includeByteCode: Boolean = true): Unit = { println(fullName + ": P/" + arity.toString()) println(" formals: " + (formals mkString " ")) println(" locals: " + (locals mkString " ")) diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Builtins.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Builtins.scala index e07c41453..72f5067dd 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Builtins.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Builtins.scala @@ -15,7 +15,7 @@ class Builtins { private val builtins = new HashMap[(String, String), Builtin] /** Registers a builtin */ - def register(builtin: Builtin) { + def register(builtin: Builtin): Unit = { builtins += (builtin.moduleName, builtin.name) -> builtin } diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Program.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Program.scala index 69836c253..70ed4fdf0 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Program.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Program.scala @@ -56,7 +56,7 @@ class Program(val isBaseEnvironment: Boolean = false) { * @param message error message * @param pos position of the error */ - def reportError(message: String, pos: Position = NoPosition) { + def reportError(message: String, pos: Position = NoPosition): Unit = { errors += ((message, pos)) } @@ -64,12 +64,12 @@ class Program(val isBaseEnvironment: Boolean = false) { * @param message error message * @param positional positional that holds the position of the error */ - def reportError(message: String, positional: Positional) { + def reportError(message: String, positional: Positional): Unit = { reportError(message, positional.pos) } /** Dumps the program on standard error */ - def dump() { + def dump(): Unit = { if (isRawCode) println(rawCode) else { diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Symbol.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Symbol.scala index 434cf2ff7..7363a1fdb 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Symbol.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/symtab/Symbol.scala @@ -31,7 +31,7 @@ sealed class Symbol(_name: String, formal: Boolean = false, def owner = _owner /** Sets the owning abstraction */ - def setOwner(owner: Abstraction) { + def setOwner(owner: Abstraction): Unit = { _owner = owner } diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/CodeGen.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/CodeGen.scala index 7df1b3a84..cc5bc24bc 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/CodeGen.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/CodeGen.scala @@ -16,11 +16,11 @@ object CodeGen extends Transformer with TreeDSL { code.registerFor(expr) private implicit def reg2ops[A <: Register](self: A) = new { - def := (source: Register)(implicit ev: A <:< XOrYReg) { + def := (source: Register)(implicit ev: A <:< XOrYReg): Unit = { code += OpMove(source, self) } - def === (rhs: Register) { + def === (rhs: Register): Unit = { code += OpUnify(self, rhs) } } @@ -33,7 +33,7 @@ object CodeGen extends Transformer with TreeDSL { def toReg = code.registerFor(self) } - def initArrayWith(values: List[Expression]) { + def initArrayWith(values: List[Expression]): Unit = { for (value <- values) { varorconst2reg(value.asInstanceOf[VarOrConst]) match { case v:XReg => code += SubOpArrayFillX(v) @@ -44,7 +44,7 @@ object CodeGen extends Transformer with TreeDSL { } } - override def applyToAbstraction() { + override def applyToAbstraction(): Unit = { // Allocate local variables val localCount = abstraction.formals.size + abstraction.locals.size if (localCount != 0) @@ -65,7 +65,7 @@ object CodeGen extends Transformer with TreeDSL { code += OpReturn() } - def generate(statement: Statement) { + def generate(statement: Statement): Unit = { statement match { case SkipStatement() => // skip diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/ConstantFolding.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/ConstantFolding.scala index 7421a817d..9bd3517f0 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/ConstantFolding.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/ConstantFolding.scala @@ -8,7 +8,7 @@ import symtab._ object ConstantFolding extends Transformer with TreeDSL { import Utils._ - override protected def apply() { + override protected def apply(): Unit = { program.rawCode = transformRoot(program.rawCode) } diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/DesugarClass.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/DesugarClass.scala index 79a1ac1a0..a16ca94b3 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/DesugarClass.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/DesugarClass.scala @@ -300,7 +300,7 @@ object DesugarClass extends Transformer with TreeDSL { atPos(method) { PROC (name, List(selfParam, msgParam)) { - LOCAL (paramVars:_*) IN { + LOCAL (paramVars.toSeq:_*) IN { withSelf(selfParam) { transformStat { CompoundStatement(fetchParamStats.toList) ~ { diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Flattener.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Flattener.scala index cce311ce1..ed9fb2dbf 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Flattener.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Flattener.scala @@ -10,7 +10,7 @@ import symtab._ object Flattener extends Transformer with TreeDSL { private var globalToFreeVar: Map[Symbol, Symbol] = _ - override def apply() { + override def apply(): Unit = { val rawCode = program.rawCode program.rawCode = null diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Namer.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Namer.scala index 23109318b..eb16fa049 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Namer.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Namer.scala @@ -399,7 +399,7 @@ object Namer extends Transformer with TransformUtils with TreeDSL { val initNames = CompoundStatement(for { decl <- namedDecls } yield { - decl === (builtins.newName callExpr ()) + decl === (builtins.newName.callExpr()) }) treeCopy.LocalExpression(clazz, namedDecls, diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/PatternMatcher.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/PatternMatcher.scala index 337a95919..4791ac78b 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/PatternMatcher.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/PatternMatcher.scala @@ -22,7 +22,7 @@ object PatternMatcher extends Transformer with TreeDSL { } transformStat { - LOCAL (newCaptures:_*) IN { + LOCAL (newCaptures.toSeq:_*) IN { treeCopy.MatchStatement(matchStat, value, newClauses, elseStat) } } @@ -53,7 +53,7 @@ object PatternMatcher extends Transformer with TreeDSL { } transformExpr { - LOCAL (newCaptures:_*) IN { + LOCAL (newCaptures.toSeq:_*) IN { treeCopy.MatchExpression(matchStat, value, newClauses, elseExpr) } } diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Transformer.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Transformer.scala index 4c0bed99c..067aafa4a 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Transformer.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Transformer.scala @@ -31,7 +31,7 @@ abstract class Transformer extends (Program => Unit) { val treeCopy = new TreeCopier /** Applies the transformation phase to a program */ - def apply(program: Program) { + def apply(program: Program): Unit = { this.program = program try { apply() @@ -41,7 +41,7 @@ abstract class Transformer extends (Program => Unit) { } /** Applies the transformation phase to the current `program` */ - protected def apply() { + protected def apply(): Unit = { if (program.isRawCode) program.rawCode = transformStat(program.rawCode) else { @@ -57,7 +57,7 @@ abstract class Transformer extends (Program => Unit) { } /** Applies the transformation phase to the current `abstraction` */ - protected def applyToAbstraction() { + protected def applyToAbstraction(): Unit = { abstraction.body = transformStat(abstraction.body) } diff --git a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Unnester.scala b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Unnester.scala index f071ab385..80f1439ee 100644 --- a/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Unnester.scala +++ b/bootcompiler/src/main/scala/org/mozartoz/bootcompiler/transform/Unnester.scala @@ -92,7 +92,7 @@ object Unnester extends Transformer with TreeDSL { case failStat @ FailStatement() => transformStat { atPos(failStat) { - builtins.fail call () + builtins.fail.call() } } diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..9e39c7375 --- /dev/null +++ b/flake.nix @@ -0,0 +1,12 @@ +{ + inputs.nixpkgs.url = "nixpkgs-22.05"; + + outputs = { self, nixpkgs }: let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + devShells.${system}.default = pkgs.mkShell { + targetPackages = with pkgs; [ cmake scala sbt ]; + } + } +}