Skip to content

Commit

Permalink
Project Setup (enso-org#4)
Browse files Browse the repository at this point in the history
* Set up the interpreter project.
* Reformat build.sbt
* Fix style guide
  • Loading branch information
iamrecursion authored Jun 14, 2019
1 parent c23209b commit 6864549
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 80 deletions.
90 changes: 68 additions & 22 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,46 +1,92 @@
version := "1.0"
// Global Configuration
organization := "org.enso"
scalaVersion := "2.12.8"

// Compiler Options
scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-unchecked",
"-Xlint"
)

// Benchmark Configuration
lazy val Benchmark = config("bench") extend Test
lazy val bench = taskKey[Unit]("Run Benchmarks")
lazy val bench = taskKey[Unit]("Run Benchmarks")

// Global Project
lazy val enso = (project in file("."))
.aggregate(syntax, pkg)
.settings(version := "0.1")
.aggregate(
syntax,
pkg,
interpreter
)

// Sub-Projects
lazy val syntax = (project in file("syntax"))
.configs(Benchmark)
.settings(
inConfig(Benchmark)(Defaults.testSettings),
name := "syntax",
organization := "org.enso",
scalaVersion := "2.12.8",
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-Xlint"),
publishArtifact := false,
mainClass in (Compile, run) := Some("org.enso.syntax.Main"),
version := "0.1"
)
.settings(
libraryDependencies ++= Seq(
"com.storm-enroute" %% "scalameter" % "0.17" % "bench",
"org.typelevel" %% "cats-core" % "1.6.0",
"org.scalatest" %% "scalatest" % "3.0.5" % Test,
"com.lihaoyi" %% "pprint" % "0.5.3"
"org.typelevel" %% "cats-core" % "1.6.0",
"org.scalatest" %% "scalatest" % "3.0.5" % Test,
"com.lihaoyi" %% "pprint" % "0.5.3"
),
resolvers ++= Seq(
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
"Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases"
),
"Sonatype OSS Snapshots" at
"https://oss.sonatype.org/content/repositories/snapshots",
"Sonatype OSS Releases" at
"https://oss.sonatype.org/content/repositories/releases"
)
)
.settings(SbtJFlexPlugin.jflexSettings)
.configs(Test)
.settings(
testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework"),
parallelExecution in Benchmark := false,
logBuffered := false
)
.settings(SbtJFlexPlugin.jflexSettings)
.settings(mainClass in (Compile, run) := Some("org.enso.syntax.Main"))
.settings(bench := {
(test in Benchmark).value
})
.configs(Benchmark)
.settings(
inConfig(Benchmark)(Defaults.testSettings),
bench := (test in Benchmark).value,
parallelExecution in Benchmark := false
)

lazy val pkg = (project in file("pkg"))
.settings(
mainClass in (Compile, run) := Some("org.enso.pkg.Main"),
version := "0.1"
)
.settings(
libraryDependencies ++= Seq("circe-core", "circe-generic", "circe-yaml")
.map("io.circe" %% _ % "0.10.0"),
libraryDependencies += "commons-io" % "commons-io" % "2.6"
)

lazy val interpreter = (project in file("interpreter"))
.settings(
mainClass in (Compile, run) := Some("org.enso.interpreter.Main"),
version := "0.1"
)
.settings(
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.3.3",
"com.storm-enroute" %% "scalameter" % "0.17" % "bench",
"org.graalvm.sdk" % "graal-sdk" % "19.0.0",
"org.scalacheck" %% "scalacheck" % "1.14.0" % Test,
"org.scalatest" %% "scalatest" % "3.2.0-SNAP10" % Test,
"org.typelevel" %% "cats-core" % "2.0.0-M4"
)
)
.dependsOn(syntax)
.configs(Test)
.configs(Benchmark)
.settings(
inConfig(Benchmark)(Defaults.testSettings),
bench := (test in Benchmark).value,
parallelExecution in Benchmark := false
)
61 changes: 3 additions & 58 deletions doc/scala-style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ programmer burden; there is usually only _one way_ to lay out code correctly.

- [Code Formatting](#code-formatting)
- [Naming](#naming)
- [Imports](#imports)
- [Visibility](#visibility)
- [Section Headers](#section-headers)
- [Build Tooling](#build-tooling)
- [Commenting](#commenting)
- [Documentation Comments](#documentation-comments)
Expand All @@ -40,8 +37,9 @@ should be used for all new Scala projects.
All files must be formatted using `scalafmt` before commit, and this should be
set up as either a precommit hook, or using the integration in IntelliJ. If you
use the IntelliJ integration, please note that you need only have the official
[Scala Plugin](https://www.jetbrains.com/help/idea/discover-intellij-idea-for-scala.html) installed, and be using IntelliJ 2019.1
or later. You should _not_ use the independent Scalafmt plugin.
[Scala Plugin](https://www.jetbrains.com/help/idea/discover-intellij-idea-for-scala.html)
installed, and be using IntelliJ 2019.1 or later. You should _not_ use the
independent Scalafmt plugin.

### Naming
Luna has some fairly simple general naming conventions, though the sections
Expand All @@ -56,59 +54,6 @@ below may provide more rules for use in specific cases.
temporary data in a function.
- Names should be descriptive, even if this makes them longer.

### Imports
Organisation of imports is simple, and should be ordered alphabetically within
each of the following sections. Each section should be separated from the one
above using a blank line.

1. **Standard Library:** Any imports from the standard library.
2. **Java Standard Library:** Any imports from the Java standard library.
3. **Additional Dependencies:** Imports from project dependencies.

In general, we prefer not to import unqualified into the package scope, as this
just leads to additional clutter.

### Visibility
There is nothing more frustrating than needing to use a function that hasn't
been exported from a package. To this end, we strongly discourage making things
private or protected in our codebase.

If, however, you want to indicate that something is for internal use, you use
one of the following two methods.

1. **Nested Types:** Declaration of inner types called `Internal`.
2. **Internal Packages:** For a package named `com.luna-lang.package` that
contains `MyType`, we can define internal functions and data-types in a
package named `com.luna-lang.package.mytype`. This means that these functions
can be imported by clients of the API if they need to, but that we provide no
guarantees about API stability when using those functions.

### Section Headers
In order to visually break up the code for easier 'visual grepping', we organise
it using section headers. These allow us to easily find the section that we are
looking for, even in a large file.

For each Scala type, within the body of the type, we organise functions as
follows:

```hs
-- === Definition === --
{- The definition of the type goes here -}


-- === API === --
{- The API of the type goes here -}


-- === Instances === --
{- Any instances for the type go here -}

```

The section header must be preceded by three blank lines, while the subsection
headers (except the first) should be preceded by two blank lines. Any of these
subsections may be omitted if they don't exist.

## Build Tooling
All Scala projects in the Luna organisation should manage their dependencies and
build setup using [SBT](hhttps://www.scala-sbt.org/1.x/docs/index.html).
Expand Down
5 changes: 5 additions & 0 deletions interpreter/src/bench/scala/org/enso/interpreter/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.enso.interpreter

import org.scalameter.Bench

object MainBenchmark extends Bench.OfflineReport {}
8 changes: 8 additions & 0 deletions interpreter/src/main/scala/org/enso/interpreter/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.enso.interpreter

object Main {

def main(args: Array[String]): Unit = {
println(x = "Hello, Enso!")
}
}
6 changes: 6 additions & 0 deletions interpreter/src/test/scala/org/enso/interpreter/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.enso.interpreter

import org.scalatest.FlatSpec
import org.scalatest.Matchers

class MainSpec extends FlatSpec with Matchers {}

0 comments on commit 6864549

Please sign in to comment.