Gestalt
An experiment and tutorial on how to create a solid and portable macros system based on solid methodology and principles.
Design Goals:
- Portable -- better IDE experience, works both in Scala and Dotty
- Solid -- friendly typing error instead of compiler crashes or hacks
- Friendly -- no knowledge about compiler internals, no dependent universes
Examples
import scala.gestalt._
object Test {
def plus(a: Int, b: Int): Int = meta {
q"$a + $b"
}
}
Design
- Only blackbox macros
- Separation of typed and untyped trees
- Only inspection of typed trees
- Only semantic information for typed trees
Philosophy
The design space of a macro system is large. Gestalt aims to be simple, solid and portable for the 80% common use cases.
a ) Assumptions on compiler implementation
- more assumptions
- fewer assumptions (✓) : portability & easy implementation
b ) Assumptions on macro usage
- more assumptions (✓) : focus on 80% common cases, make them easy
- fewer assumptions
c) Features
- more features
- fewer features (✓) : metaprogramming is hard, restrict power, implementation solid
Test
Paper
Gestalt : The Road for Lightweight Portable Macros