Name: ildl-example
Owner: Scala Miniboxing
Description: Example of using the data-centric metaprogramming plugin.
Created: 2015-08-06 01:55:59.0
Updated: 2015-08-09 17:39:49.0
Pushed: 2015-08-06 02:24:44.0
Homepage: null
Size: 123
Language: Scala
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This is an example of using data-centric metaprogramming in your sbt project.
To install:
t clone https://github.com/miniboxing/ildl-example.git
ildl-example
In the plugin we have an example transformation:
t src/main/scala/Test.scala
rt ildl._
ct Test {
*
Stores Long objects as Ints, losing precision. It's a
rather dumb transformation, but it shows what's happening.
/
ject RangeReduction extends TransformationDescription {
def toRepr(v: Long): Int @high = v.toInt
def toHigh(v: Int @high): Long = v.toLong
// this method hijacks the + operation on transformed values:
def extension_+(o1: Int @high, o2: Int @high): Int @high = 42
// comment it out to get the right result :)
original method:
f plus1(v1: Long, v2: Long) = v1 + v2
transformed method:
rt(RangeReduction) {
def plus2(v1: Long, v2: Long) = v1 + v2
f main(args: Array[String]): Unit = {
val v1 = 4
val v2 = 5
println(s"$v1 + $v2 = ${plus1(v1,v2)}")
println(s"$v1 + $v2 = ${plus2(v1,v2)}")
To run this code:
t
o] Loading project definition from /mnt/data1/Work/Workspace/dev/ildl-example/project
o] Set current project to ildl-example (in build file:/mnt/data1/Work/Workspace/dev/ildl-example/)
n
o] Running Test
5 = 9
5 = 42
The result will be unexpected. To read more about data-centric metaprogramming check out the scala-ildl.org
website or the project wiki.