These are chat archives for unisonweb/unison

16th
Aug 2017
Arya Irani
@aryairani
Aug 16 2017 22:34

@pchiusano in a fit of impatience, I made a couple new codegeneration helpers:

def switch(s: String)(body: String) = s"($s: @annotation.switch) match " + body.b
def `case`(expr: String)(body: String): String = s"case $expr =>" <> body.indent <> ""
def `case`(i: Int)(body: String): String = s"case $i =>" <> body.indent <> ""
def b(s: String)(body: String) = s + " " + body.b

e.g.

"val stackSize = args.map(_.stackSize).max" <>
switch("stackSize") {
  (0 to maxInlineStack).each { stackSize =>
    `case`(stackSize) {
      switch("args.length") {
        (1 to maxInlineArgs).each { argCount =>
          `case`(argCount) {
            (0 until argCount).each { i => s"val arg$i = args($i)" } <>
            b(s"class ${classPrefix}S${stackSize}A${argCount} extends Computation${stackSize}(decompile)") {
              b(s"${applySignature(stackSize)} =") {
                // ...

and it ends up being much less confusing

removes the opportunity to screw up choosing <> { vs + {, or }.b vs }.indent; the former go away, and the latter you specify up front, instead of at the matching }
and switch(x){..} adds the annotation too :+1::+1::+1:
Arya Irani
@aryairani
Aug 16 2017 22:41
you only have to remember to add <> between lines :P