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 q"java.this.lang.Math.pow($a, $b)" => Power(getComponent(a), getComponent(b)) |
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 Power(first: Component, second: Component) extends Component { | |
override def toTree(implicit c: blackbox.Context): c.Tree = { | |
import c.universe._ | |
q"Math.pow(${first.toTree}, ${second.toTree})" | |
} | |
override def derive: Component = this match { | |
case Power(Variable(_), DoubleConstant(b)) => | |
Multiply(second, Power(first, DoubleConstant(b - 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
case q"$a * $b" => Multiply(getComponent(a), getComponent(b)) |
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 Multiply(first: Component, second: Component) extends Component { | |
override def toTree(implicit c: blackbox.Context): c.Tree = { | |
import c.universe._ | |
q"${first.toTree} * ${second.toTree}" | |
} | |
override def derive: Component = | |
Add( | |
Multiply(first, second.derive), | |
Multiply(first.derive, second) |
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 q"$a - $b" => Add(getComponent(a), Negate(getComponent(b))) |
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 q"$a + $b" => Add(getComponent(a), getComponent(b)) |
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 Add(first: Component, second: Component) extends Component { | |
override def toTree(implicit c: blackbox.Context): c.Tree = { | |
import c.universe._ | |
q"${first.toTree} + ${second.toTree}" | |
} | |
override def derive: Component = Add(first.derive, second.derive) | |
} |
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
scala> q"(x: Double) => -x" | |
res0: reflect.runtime.universe.Function = ((x: Double) => x.unary_$minus) | |
scala> show(res0) | |
res1: String = ((x: Double) => x.unary_$minus) | |
scala> showRaw(res1) | |
res2: String = Function(...), Select(Ident(TermName("x")), TermName("unary_$minus"))) |
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 q"$nextTree - $arg" => | |
Negate(getComponent(arg)) :: extractComponents(nextTree) |
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 q"+$x" => getComponent(x) |