"Releasing features into paradise" sounds pretty humane. What aren't you telling us, Eugene?
But where do the features go!
Agreed. Great work Eugene!
I hope in the future we can mimic this process for SIP work before it hits master.
I rather meant that not a lot of people would expect ecosystem to be rebuilt for every nightly. On the other hand, milestones encourage bigger expectations => more testing and more hassle.Though I agree that we need to bring method to the madness. Josh, Greg, Adriaan, what would you advise?
Regarding SNAPSHOT versions, is there any update on how SBT treats SNAPSHOT compiler versions?
My problem with using a non-standard compiler shifted to this one: https://github.com/harrah/xsbt/issues/626
Hmm - given that that ticket is closed, is the implication that this is fixed with SBT 0.13? It wasn't quite clear to me from the comments in the ticket...
With the new API you can emit top-level classes and objects, but if you need inner ones (e.g. to close over something in lexical scope), then the answer is probably no.
java.lang.Enum.valueOf(classOf[Stuff], name)This is (approximately) how one should write an enumerated type:enum Direction {North,East,South,West}
Anything longer than that is a challenge to keep working.
Object and class can be inferred from the presence of arguments.
Maybe a syntax like
case class Direction match {
North
East
South
West
}
BR
John
c.compilerSettings only consists of explicit compiler settings, nothing about the managed and unmanaged sourcefiles etc. and other default settings of the compiler is using to compile. The reading nevertheless works, but I like to query more info about what the compiler is doing. I there also something more elegant for the dummy return type, because I don't have to return anything, but the macro wants something like c.Expr[_] .A Unit would be fine.
def checkSourcesAndCompilerSettingsInCompiletime() = macro checkSourcesAndCompilerSettingsInCompiletimeImpl
def checkSourcesAndCompilerSettingsInCompiletimeImpl(c: Context)(): c.Expr[Unit] = {
import c.universe._
println("Compiler plugin ready")
println("Compiler has found " + c.enclosingRun.units.size + " source file(s):")
c.enclosingRun.units.foreach(cu => {
val fn = cu.source.file.canonicalPath
var contents = new StringBuffer
io.Source.fromFile(new File(fn)).getLines.
foreach(
contents.append(_).append("\n")
)
println(fn)
println("With content:")
println(contents.toString)
})
println("Compiler has found these setting(s):")
c.compilerSettings.foreach(println(_))
reify(()) // dummy return type
}
}
1) I just checked c.enclosingRun.units and it works:
21:11 ~/Projects/Kepler_macrosnippet06/sandbox (topic/macrosnippet06)$ scalac Macros.scala
21:11 ~/Projects/Kepler_macrosnippet06/sandbox (topic/macrosnippet06)$ scalac Qwe.scala Test.scala
List(Qwe.scala, Test.scala)
2) Speaking of c.compilerSettings, what kind of information would you like to query?
3) Could you please submit the Unit idea as an enhancement request?
Okay
why not object Direction extends scala.Enum('North, 'East, 'South, 'West) ?
ThisOp zondag 23 december 2012 20:28:18 UTC+1 schreef Eugene Burmako het volgende:
checkSourcesAndCompilerSettingsInCompiletimeLog(raw"C:\Users\Dave\workspacedev2.10\output.txt")
and this
val s = "Dave"
checkSourcesAndCompilerSettingsInCompiletimeLog(s"C:\\Users\\$s\\workspacedev2.10\\output.txt")
don't work
while this (a plain String)
checkSourcesAndCompilerSettingsInCompiletimeLog("C:\\Users\\Dave\\workspacedev2.10\\output.txt")
works. The first two are not passed on the same way as the last.
The macro starts like this:
def checkSourcesAndCompilerSettingsInCompiletimeLog(filename: String) = macro checkSourcesAndCompilerSettingsInCompiletimeLogImpl
def checkSourcesAndCompilerSettingsInCompiletimeLogImpl(c: Context)(filename: c.Expr[String]): c.Expr[Unit] = {
import c.universe._
val Literal(Constant(s_filename: String)) = filename.tree
val out = new PrintWriter(new File(s_filename))
val s_filename = filename.tree match {
case _@Apply(/* raw string */
Select(
Apply(
Select(
Select(
Ident("scala"), newTermName("StringContext")
),
newTermName("apply")
),
List(
Literal(
Constant(fname: String)
)
)
),
newTermName("raw")
),
List()
) => fname
case _@Apply(/* spliced string */
Select(
Apply(
Select(
Select(
Ident("scala"), newTermName("StringContext")
),
newTermName("apply")
),
List(
Literal(
Constant(beforesplice: String)
),
Literal(
Constant(aftersplice: String)
)
)
),
newTermName("s")
),
List(
splice@Ident(newTermName("s")
)
) => beforesplice + splice + aftersplice
case _@Literal( /* plain string */
Constant(fname: String)
) => fname
}
case ss if ss == Apply(/* spliced string */
overloaded method value Apply with alternatives: (sym: c.universe.Symbol,args: c.universe.Tree*)c.universe.Tree <and> => c.universe.ApplyExtractor
cannot be applied to (c.universe.Select, List[String])
case rs if rs == Apply(/* raw string */
List(
splice@Ident(s2)
)
) if sc == newTermName("StringContext") &&
a == newTermName("apply") &&
s1 == newTermName("s") &&
s2 == newTermName("s")
=> beforesplice + splice + aftersplice
On Wed, Dec 19, 2012 at 7:02 AM, Paul Butcher <pa...@paulbutcher.com> wrote:Regarding SNAPSHOT versions, is there any update on how SBT treats SNAPSHOT compiler versions?If you run "sbt update" explicitly now, it will update your snapshots. I haven't had a problem with this part in a while. My problem with using a non-standard compiler shifted to this one: https://github.com/harrah/xsbt/issues/626
Welcome to Scala version 2.11.0-20121225-185448-74d60036f5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_09).
How do I get sbt to update the scala-compiler as well as the libraries that it uses? I'm using sbt 0.13.0-20121202-052047.
Last login: Fri Dec 28 23:31:17 on ttys001pauls-macbook:~ paul$ cd personal/ScalaMock.typemacros/pauls-macbook:ScalaMock.typemacros paul$ sbtDetected sbt version 0.13.0-20121202-052047Starting sbt: invoke with -help for other optionsUsing /Users/paul/.sbt/0.13.0-20121202-052047 as sbt dir, -sbt-dir to override.[info] Loading project definition from /Users/paul/personal/ScalaMock.typemacros/project[info] Set current project to ScalaMock (in build file:/Users/paul/personal/ScalaMock.typemacros/)[info] Defining */*:log-level[info] The new value will be used by no settings or tasks.[info] Reapplying settings...[info] Set current project to ScalaMock (in build file:/Users/paul/personal/ScalaMock.typemacros/)[info] Defining */*:console-project::trace-level, */*:console::trace-level and 2 others.[info] The new values will be used by no settings or tasks.[info] Run `last` for details.[info] Reapplying settings...[info] Set current project to ScalaMock (in build file:/Users/paul/personal/ScalaMock.typemacros/)ScalaMock:typemacros:3.0> update[info] Updating {file:/Users/paul/personal/ScalaMock.typemacros/}core...[info] Updating {file:/Users/paul/personal/ScalaMock.typemacros/}ScalaMock...[info] Resolving org.scalatest#scalatest_2.10.0;2.0.M5 ...[info] Done updating.[info] Resolving org.scala-lang.macro-paradise#scala-library;2.11.0-SNAPSHOT ...[info] downloading https://oss.sonatype.org/content/repositories/snapshots/org/scala-lang/macro-paradise/scala-reflect/2.11.0-SNAPSHOT/scala-reflect-2.11.0-20121229.042200-5.jar ...[info] [SUCCESSFUL ] org.scala-lang.macro-paradise#scala-reflect;2.11.0-SNAPSHOT!scala-reflect.jar (11020ms)[info] downloading https://oss.sonatype.org/content/repositories/snapshots/org/scala-lang/macro-paradise/scala-library/2.11.0-SNAPSHOT/scala-library-2.11.0-20121229.042200-5.jar ...[info] [SUCCESSFUL ] org.scala-lang.macro-paradise#scala-library;2.11.0-SNAPSHOT!scala-library.jar (18922ms)[info] Done updating.[info] Updating {file:/Users/paul/personal/ScalaMock.typemacros/}scalatest...[info] Resolving org.scalatest#scalatest_2.10.0;2.0.M5 ...[info] Done updating.[info] Updating {file:/Users/paul/personal/ScalaMock.typemacros/}examples...[info] Updating {file:/Users/paul/personal/ScalaMock.typemacros/}core_tests...[info] Resolving org.scalatest#scalatest_2.10.0;2.0.M5 ...[info] Done updating.[info] Resolving org.scalatest#scalatest_2.10.0;2.0.M5 ...[info] Done updating.[success] Total time: 53 s, completed 29-Dec-2012 16:12:11
As you can see there are exactly two occasions where it downloads something - once for scala-library and once for scala-reflect. There's no mention of scala-compiler at all :-(
Do you have to have a dependency on scala-compiler to use repl?
Note that I don't want to link against the compiler - I just want sbt to use the most recent snapshot of the compiler when building my code. Is there really no way to achieve this without linking against the compiler?
[info] Resolving org.scala-lang.macro-paradise#scala-library;2.11.0-SNAPSHOT ...[info] downloading https://oss.sonatype.org/content/repositories/snapshots/org/scala-lang/macro-paradise/scala-reflect/2.11.0-SNAPSHOT/scala-reflect-2.11.0-20121229.042200-5.jar ...[info] [SUCCESSFUL ] org.scala-lang.macro-paradise#scala-reflect;2.11.0-SNAPSHOT!scala-reflect.jar (11020ms)[info] downloading https://oss.sonatype.org/content/repositories/snapshots/org/scala-lang/macro-paradise/scala-library/2.11.0-SNAPSHOT/scala-library-2.11.0-20121229.042200-5.jar ...[info] [SUCCESSFUL ] org.scala-lang.macro-paradise#scala-library;2.11.0-SNAPSHOT!scala-library.jar (18922ms)[info] Done updating.
pauls-macbook:ScalaMock.typemacros paul$ sbtDetected sbt version 0.13.0-20121202-052047Starting sbt: invoke with -help for other optionsUsing /Users/paul/.sbt/0.13.0-20121202-052047 as sbt dir, -sbt-dir to override.[info] Loading project definition from /Users/paul/personal/ScalaMock.typemacros/project
[info] Compiling 1 Scala source to /Users/paul/personal/ScalaMock.typemacros/project/target/scala-2.9.2/sbt-0.13/classes...
[info] Set current project to ScalaMock (in build file:/Users/paul/personal/ScalaMock.typemacros/)[info] Defining */*:log-level[info] The new value will be used by no settings or tasks.[info] Reapplying settings...[info] Set current project to ScalaMock (in build file:/Users/paul/personal/ScalaMock.typemacros/)[info] Defining */*:console-project::trace-level, */*:console::trace-level and 2 others.[info] The new values will be used by no settings or tasks.[info] Run `last` for details.[info] Reapplying settings...[info] Set current project to ScalaMock (in build file:/Users/paul/personal/ScalaMock.typemacros/)ScalaMock:typemacros:3.0> update
[info] Updating {file:/Users/paul/personal/ScalaMock.typemacros/}ScalaMock...
[info] Updating {file:/Users/paul/personal/ScalaMock.typemacros/}core...
[info] Resolving org.scala-lang.macro-paradise#scala-compiler;2.11.0-SNAPSHOT ...[info] downloading https://oss.sonatype.org/content/repositories/snapshots/org/scala-lang/macro-paradise/scala-compiler/2.11.0-SNAPSHOT/scala-compiler-2.11.0-20121229.042200-5.jar ...[info] [SUCCESSFUL ] org.scala-lang.macro-paradise#scala-compiler;2.11.0-SNAPSHOT!scala-compiler.jar (34529ms)[info] Done updating.[info] Resolving org.scala-lang#scala-library;2.11.0-SNAPSHOT ...
[info] Updating {file:/Users/paul/personal/ScalaMock.typemacros/}scalatest...[info] Resolving org.scalatest#scalatest_2.10.0;2.0.M5 ...[info] Done updating.[info] Resolving org.scalatest#scalatest_2.10.0;2.0.M5 ...[info] Done updating.[info] Updating {file:/Users/paul/personal/ScalaMock.typemacros/}examples...[info] Updating {file:/Users/paul/personal/ScalaMock.typemacros/}core_tests...[info] Resolving org.scalatest#scalatest_2.10.0;2.0.M5 ...[info] Done updating.[info] Resolving org.scalatest#scalatest_2.10.0;2.0.M5 ...[info] Done updating.
[success] Total time: 57 s, completed 29-Dec-2012 17:29:10ScalaMock:typemacros:3.0> core/console[info] Starting scala interpreter...[info]
Welcome to Scala version 2.11.0-20121225-185448-74d60036f5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_09).
Type in expressions to have them evaluated.Type :help for more information.scala>[success] Total time: 4 s, completed 29-Dec-2012 17:29:31
So how do I force it to do that again?
Note that the REPL is still 2.11.0-20121225-185448-74d60036f5
ScalaMock:typemacros:3.0> reboot fullGetting net.java.dev.jna jna 3.2.3 ...:: retrieving :: org.scala-sbt#boot-jnaconfs: [default]1 artifacts copied, 0 already retrieved (838kB/13ms)Getting org.scala-sbt sbt 0.13.0-20121202-052047 ...:: retrieving :: org.scala-sbt#boot-appconfs: [default]41 artifacts copied, 0 already retrieved (8514kB/121ms)Getting Scala 2.9.2 (for sbt)...:: retrieving :: org.scala-sbt#boot-scalaconfs: [default]4 artifacts copied, 0 already retrieved (20090kB/105ms)
[info] Loading project definition from /Users/paul/personal/ScalaMock.typemacros/project
[info] Set current project to ScalaMock (in build file:/Users/paul/personal/ScalaMock.typemacros/)
ScalaMock:typemacros:3.0> consoleGetting org.scala-lang.macro-paradise Scala 2.11.0-SNAPSHOT ...downloading https://oss.sonatype.org/content/repositories/snapshots/org/scala-lang/macro-paradise/jline/2.11.0-SNAPSHOT/jline-2.11.0-20121229.042200-5.jar ...[SUCCESSFUL ] org.scala-lang.macro-paradise#jline;2.11.0-SNAPSHOT!jline.jar (2854ms):: retrieving :: org.scala-sbt#boot-scalaconfs: [default]5 artifacts copied, 0 already retrieved (23168kB/32ms)
[info] Starting scala interpreter...[info]Welcome to Scala version 2.11.0-20121225-185448-74d60036f5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_09).Type in expressions to have them evaluated.Type :help for more information.scala>
That doesn't do the trick either I'm afraid :-(
Have you tried a more recent version of sbt 0.13.0-SNAPSHOT?
Simultaneously with the release of Scala 2.10.0-final, tentatively
scheduled for 26 December 2012, we're going to announce the
availability of paradise/macros, a dedicated branch in our official
Scala repository which will host the latest macro developments.
When things like macro types, macro annotations or type inference-
friendly macros - you name it - get ripe for beta testing, they are
going to end up in paradise/macros. Much like the vanilla Scala, macro
paradise is going to be built nightly and have its own Maven artifact,
so it'll be very easy to use it in your projects.
In this talk I present a couple of new features that will be released
into paradise this Christmas, along with a glimpse of the things to
come. I also discuss the roadmap of macro development for the near
future, so if you want to have something in Scala macros, be sure to
take a look and speak up.
Screencast: http://vimeo.com/user8565009/macro-paradise-talk
Slides: http://scalamacros.org/talks/2012-12-18-MacroParadise.pdf
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Yes, but how do I do this? I thought topLevelDef would allow me to do this, but it seems it doesn't.
You received this message because you are subscribed to a topic in the Google Groups "scala-language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scala-language/IcDNzjhxV3E/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to scala-languag...@googlegroups.com.
c.mirror.staticModule("Location") // Location is not explicit known.
2) Is there some kind of "dynamic" reference, or ideally, a type-tree
that contains all type information for the given context which I can traverse?
A simple
apparently does not provide me the desired collection of all type information
so is there something else I should know?
3) Considering the intention of range constrains on numeric types,
I'm not exactly sure how exactly to specify a custom type range without interfering
with existing Scala syntax. Following the idea of the Lifter macro[1], is there a way to
mix-in a trait into an existing type to "append" a range definition that my macro can use?
[1]
https://github.com/xeno-by/typemacros-lifter