This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val compilerCache = new CompilerCache(10) | |
def compileScala(scalaVersion: String, | |
sources: Path, | |
compileClasspath: Seq[Path], | |
outputPath: Path): PathRef = { | |
val binaryScalaVersion = scalaVersion.split('.').dropRight(1).mkString(".") | |
def grepJar(s: String) = { | |
compileClasspath | |
.find(_.toString.endsWith(s)) | |
.getOrElse(throw new Exception("Cannot find " + s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ case class Cross[T](items: T*){ | |
def flatMap[V](f: T => Cross[V]): Cross[(T, V)] = { | |
val flattened = for{ | |
i <- items | |
k <- f(i).items | |
} yield (i, k) | |
Cross(flattened:_*) | |
} | |
def map[V](f: T => V): Cross[(T, V)] = { | |
Cross(items.map(i => i -> f(i)):_*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fasterparser | |
import scala.collection.mutable | |
object Parse { | |
def main(args: Array[String]): Unit = { | |
def hello[_:Ctx] = P( "hello" ) | |
def world[_:Ctx] = P( "world" ) | |
def helloWorld[_:Ctx] = P( hello.! ~ (" " | ",").rep ~ world.! ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.reflect.macros.blackbox.Context | |
import language.experimental.macros | |
object Applicative { | |
def apply[T](t: T): Option[T] = macro Applicative.impl[T] | |
def impl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Option[T]] = { | |
import c.universe._ | |
def rec(t: Tree): Iterator[c.Tree] = Iterator(t) ++ t.children.flatMap(rec(_)) | |
val bound = collection.mutable.Buffer.empty[(c.Tree, ValDef)] | |
val defsWithinMacro = rec(t.tree).filter(_.isDef).map(_.symbol).toSet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.lang.IllegalArgumentException: Could not find proxy for i: Int in List(value i, method apply$mcVI$sp, <$anon: Function1>, method doPhi, class Thread, package rt, package metascala, package <root>) (currentOwner= value x1 ) | |
at scala.tools.nsc.transform.LambdaLift$LambdaLifter.scala$tools$nsc$transform$LambdaLift$LambdaLifter$$searchIn$1(LambdaLift.scala:326) | |
at scala.tools.nsc.transform.LambdaLift$LambdaLifter.scala$tools$nsc$transform$LambdaLift$LambdaLifter$$searchIn$1(LambdaLift.scala:331) | |
at scala.tools.nsc.transform.LambdaLift$LambdaLifter.scala$tools$nsc$transform$LambdaLift$LambdaLifter$$searchIn$1(LambdaLift.scala:331) | |
at scala.tools.nsc.transform.LambdaLift$LambdaLifter.scala$tools$nsc$transform$LambdaLift$LambdaLifter$$searchIn$1(LambdaLift.scala:331) | |
at scala.tools.nsc.transform.LambdaLift$LambdaLifter.scala$tools$nsc$transform$LambdaLift$LambdaLifter$$searchIn$1(LambdaLift.scala:331) | |
at scala.tools.nsc.transform.LambdaLift$LambdaLifter.scala$tools$nsc$transform$LambdaLift$LambdaLifter$$s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lihaoyi test$ tree | |
. | |
└── Foo.scala | |
0 directories, 1 file | |
lihaoyi test$ cat Foo.scala | |
object Main{ | |
def main(args: Array[String]): Unit = { | |
println(getClass.getClassLoader.getResourceAsStream("java/lang/String.class")) | |
println(getClass.getClassLoader.getClass) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lihaoyi test$ cat Test.scala | |
object Test{ | |
def main(args: Array[String]): Unit = { | |
println(List(1, 2, 3).map(_ + 1)) | |
println(List(1, 2, 3).map(_ + 1)) | |
println(List(1, 2, 3).map(_ + 1)) | |
println(List(1, 2, 3).map(_ + 1)) | |
println(List(1, 2, 3).map(_ + 1)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello | |
import java.io.ByteArrayOutputStream | |
import chisel3._ | |
import chisel3.iotesters.{Driver, PeekPokeTester} | |
sealed trait Op | |
object Op{ | |
case class GotoIfZero(dest: Byte, valueAddr: Byte) extends Op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Single-file play framework application! Make sure everything | |
* works, as this is the test case that un-earthed #371 | |
*/ | |
load.ivy("com.typesafe.play" %% "play" % "2.5.0") | |
load.ivy("com.typesafe.play" %% "play-netty-server" % "2.5.0") | |
load.ivy("org.scalaj" %% "scalaj-http" % "2.2.1") | |
@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo | |
import scala.tools.nsc.io.AbstractFile | |
import scala.tools.nsc.{Global, Phase} | |
import scala.tools.nsc.plugins.{Plugin, PluginComponent} | |
class DemoPlugin(val global: Global) extends Plugin { | |
import global._ | |
override def init(options: List[String], error: String => Unit): Boolean = true |