Skip to content

Instantly share code, notes, and snippets.

@julianpeeters
julianpeeters / toolbox-example
Last active December 19, 2015 19:19
Trying to generate classes at runtime with a toolbox. Can get classes and objects, but having trouble getting a type to use as a type parameter, or to get the class' scalaSig.
//Adapted from a Gist courtesy Eugene Burmako: https://gist.github.com/5845539.html
import scala.reflect.runtime.{universe => ru}
import scala.tools.reflect.ToolBox
import scala.language.reflectiveCalls
import scala.tools.scalap.scalax.rules.scalasig._
object Test extends App {
def define(tb: ToolBox[ru.type], tree: ru.ImplDef): ru.Symbol = {
@julianpeeters
julianpeeters / ScalaSig2
Created July 16, 2013 18:44
Example of a parsed(not pickled) Scala signature.
Some(ScalaSig version 5.0
0: ClassSymbol(MyRecord, owner=models, flags=40, info=5 ,None)
1: MyRecord
2: models
3: models
4: NoSymbol
5: ClassInfoType(ClassSymbol(MyRecord, owner=models, flags=40, info=5 ,None),List(TypeRefType(ThisType(java.lang),java.lang.Object,List()), TypeRefType(ThisType(scala),scala.ScalaObject,List()), TypeRefType(ThisType(scala),scala.Product,List()), TypeRefType(ThisType(scala),scala.Serializable,List())))
6: TypeRefType(ThisType(java.lang),java.lang.Object,List())
7: ThisType(java.lang)
8: java.lang
@julianpeeters
julianpeeters / ScalaSig1
Last active December 19, 2015 20:09
An example of a pickled Scala signature, found in an ASMified case class dump file (main class, not the module class).
ClassWriter cw = new ClassWriter(0);
FieldVisitor fv;
MethodVisitor mv;
AnnotationVisitor av0;
cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "models/rec", null, "java/lang/Object", new String[] { "scala/ScalaObject", "scala/Product", "scala/Serializable" });
{
av0 = cw.visitAnnotation("Lscala/reflect/ScalaSignature;", true);
@julianpeeters
julianpeeters / scalaSig
Last active December 19, 2015 20:49
scala signature of {case class MyRecord()}, ,a base for signature for investigating how to signatures differ depending on the members of a class. best not o look at the numbers, as the gist has been cut and pasted to show the basic structure of a scala sig only.
ScalaSig version 5.0
0: ClassSymbol(MyRecordA, owner=<empty>, flags=40, info=5 ,None)
1: MyRecordA
2: <empty>
3: <empty>
4: NoSymbol
5: ClassInfoType(ClassSymbol(MyRecordA, owner=<empty>, flags=40, info=5 ,None),List(TypeRefType(ThisType(scala),scala.AnyRef,List()), TypeRefType(ThisType(scala),scala.Product,List()), TypeRefType(ThisType(scala),scala.Serializable,List())))
6: TypeRefType(ThisType(scala),scala.AnyRef,List())
7: ThisType(scala)
8: scala
@julianpeeters
julianpeeters / scalaSignature
Created September 14, 2013 08:17
This is the real pickled signature, presumably encoded from an array that contained a value of 127. I can make a signature, but if mine contains a value of 127, then parsing it fails.
val sig = "\u0006\u0001\u0005\rc\u0001B\u0001\u0003\u0001\u0016\u0011\u0001\"T=SK\u000e|'\u000f\u001a\u0006\u0002\u0007\u00051Qn\u001c3fYN\u001c\u0001a\u0005\u0003\u0001\r1y\u0001CA\u0004\u000b\u001b\u0005A!\"A\u0005\u0002\u000bM\u001c\u0017\r\\1\n\u0005-A!AB!osJ+g\r\u0005\u0002\u0008\u001b%\u0011a\u0002\u0003\u0002\u0008!J|G-^2u!\u00099\u0001#\u0003\u0002\u0012\u0011\u0009a1+\u001a:jC2L'0\u00192mK\"A1\u0003\u0001BK\u0002\u0013\u0005A#A\u0001y+\u0005)\u0002C\u0001\u000c\u001a\u001d\u00099q#\u0003\u0002\u0019\u0011\u00051\u0001K]3eK\u001aL!AG\u000e\u0003\rM#(/\u001b8h\u0015\u0009A\u0002\u0002\u0003\u0005\u001e\u0001\u0009E\u0009\u0015!\u0003\u0016\u0003\u0009A\u0008\u0005\u0003\u0005 \u0001\u0009U\r\u0011\"\u0001!\u0003\u0005IX#A\u0011\u0011\u0005\u001d\u0011\u0013BA\u0012\u0009\u0005\rIe\u000e\u001e\u0005\u0009K\u0001\u0011\u0009\u0012)A\u0005C\u0005\u0011\u0011\u0010\u0009\u0005\u0009O\u0001\u0011)\u001a!C\u0001Q\u0005\u0009!0F\u0001*!\u00099!&\u0003\u0002,\u0011\u00099!i\\8mK\u0006t\u0007\u0002C\u0017\u0001
@julianpeeters
julianpeeters / Macro Annotation typer error
Created January 11, 2014 07:03
macro annotation case class provider typer error
sbt run
Loading /usr/share/sbt/bin/sbt-launch-lib.bash
[warn] The global sbt directory is now versioned and is located at /home/julianpeeters/.sbt/0.13.
[warn] You are seeing this warning because there is global configuration in /home/julianpeeters/.sbt but not in /home/julianpeeters/.sbt/0.13.
[warn] The global sbt directory may be changed via the sbt.global.base system property.
[info] Loading project definition from /home/julianpeeters/Dropbox/macro-annotation-example/project
[info] Updating {file:/home/julianpeeters/Dropbox/macro-annotation-example/project/}macro-annotation-example-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /home/julianpeeters/Dropbox/macro-annotation-example/project/target/scala-2.10/sbt-0.13/classes...
@julianpeeters
julianpeeters / defaultValDef
Created January 13, 2014 18:01
Preprocess a val def in order to splice it and have it retain a DEFAULTPARAM mod
package models
import scala.reflect.macros.Context
import scala.language.experimental.macros
import scala.annotation.StaticAnnotation
import scala.io._
object helloMacro {
@julianpeeters
julianpeeters / macroNested
Created January 13, 2014 18:09
Still need daultparam mod if the type is a nested class?
package models
import scala.reflect.macros.Context
import scala.language.experimental.macros
import scala.annotation.StaticAnnotation
import scala.io._
object nestedInnerMacro {
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
@julianpeeters
julianpeeters / cascadingClusterIssue
Created February 10, 2014 03:55
vagrant-cascading-hadoop-cluster issue on OSX
accipiter:vagrant-cascading-hadoop-cluster julianpeeters$ git pull
Already up-to-date.
accipiter:vagrant-cascading-hadoop-cluster julianpeeters$ git checkout 2.2
Already on '2.2'
accipiter:vagrant-cascading-hadoop-cluster julianpeeters$ vagrant destroy -f
[master] Destroying VM and associated drives...
[master] Running cleanup tasks for 'puppet' provisioner...
[master] Running cleanup tasks for 'puppet' provisioner...
[master] Running cleanup tasks for 'puppet' provisioner...
[master] Running cleanup tasks for 'puppet' provisioner...
run
[info] Compiling 1 Scala source to /home/julianpeeters/Dropbox/macro-annotation-example/macros/target/scala-2.10/classes...
[info] Compiling 2 Scala sources to /home/julianpeeters/Dropbox/macro-annotation-example/core/target/scala-2.10/classes...
while compiling: /home/julianpeeters/Dropbox/macro-annotation-example/core/src/main/scala/models/MyRecord.scala
during phase: uncurry
library version: version 2.10.3
compiler version: version 2.10.3
reconstructed args: -bootclasspath /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/netx.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/plugin.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rhino.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/li