Simon Danisch / Aug 27 2018

Hacking the Compiler

1.
We have a JIT - we have macros - we have Cassette!

Pkg.pkg"add Cassette"
using Cassette
Cassette.@context Ctx
test(a, b) = a + b
Cassette.overdub(Ctx(), test, 1, 2)
# Shenanigans:
Cassette.execute(::Ctx, ::typeof(+), a, b) = a - b
Cassette.overdub(Ctx(), test, 1, 2)

1.1.
Tracing

Cassette.@context Trace
global level = 0
function Cassette.execute(ctx::Trace, f, args...)
  global level
  println(" "^level, f, "($(join(args, ", ")))")
  level += 1
  res = Cassette.overdub(ctx, f, args...)
  level -= 1
  res
end
Cassette.overdub(Trace(), +, 1, 1.0)