<commit_before>package org.unisonweb.codegeneration
package v2

object LetRecGenerator extends OneFileGenerator("CompileLetRec.scala") {
  def source =
    "package org.unisonweb.compilation" <>
    "package v2" <>
    "" <>
    "trait CompileLetRec " + {
      "def compileLetRec(e: TermC, bindings: Array[Computation], body: Computation): Computation = " + {
        "(stackSize(e): @annotation.switch) match " + {
           (0 to N).each { i =>
             s"case $i => (bindings.length: @annotation.switch) match " + {
               (1 to N).each { j =>
                 s"case $j => " <> {
                   s"class LetRecS${i}A${j} extends Computation$i(e, ()) " + {
                     (1 to j).each { k => s"val b$k = bindings(${k-1})" } <>
                     applySignature(i) + " = " + {
                       val bArgs =
                        if (i + j <= N)
                          (j to 1 by -1).commas(l => s"0.0, b${l}r") + commaIf(i) +
                          (0 until i).commas(l => s"x$l, x${l}b")
                        else
                          "Array(" +
                            (j to 1 by -1).commas(l => s"Slot(0.0, b${l}r)") + commaIf(i) +
                            (0 until i).commas(l => s"Slot(x$l, x${l}b)") +
                          ")"
                       (1 to j).each { k => s"val b${k}r = Ref()" } <>
                       (1 to j).each { k => s"b${k}r.value = Value(b$k(rec, $bArgs, r), r.boxed)" } <>
                       s"body(rec, $bArgs, r)"
                     }.b
                   }.b <>
                   s"new LetRecS${i}A${j}"
                 }.indent
               } <>
               "case n => " <> {
                 s"class LetRecS${i}AN extends Computation$i(e, ()) " + {
                   applySignature(i) + " = " + {
                     "val refs = bindings.map(_ => Ref())" <>
                     "val xs = Array[Slot](" + (0 until i).commas(k => s"Slot(x$k,x${k}b)") + ")" <>
                     "val slots = refs.view.map(r => Slot(0.0, r)).reverse.toArray ++ xs" <>
                     "var i = 0" <>
                     "while (i < bindings.length)" + {
                       "refs(i).value = Value(bindings(i)(rec, slots, r), r.boxed)" <>
                       "i += 1"
                     }.b <>
                     "body(rec, slots, r)"
                   }.b
                 }.b <>
                 s"new LetRecS${i}AN"
               }.indent
             }.b
           } <>
           "case n => " <> {
             s"class LetRecSNAN extends ComputationN(n, e, ()) " + {
               applyNSignature + " = " + {
                 "val refs = bindings.map(_ => Ref())" <>
                 "val slots = refs.view.map(r => Slot(0.0, r)).reverse.toArray ++ xs" <>
                 "var i = 0" <>
                 "while (i < bindings.length)" + {
                   "refs(i).value = Value(bindings(i)(rec, slots, r), r.boxed)" <>
                   "i += 1"
                 }.b <>
                 "body(rec, slots, r)"
               }.b
             }.b <>
             "new LetRecSNAN"
           }.indent
        }.b
      }.b
    }.b
}<commit_msg>bit of cleanup of generated code<commit_after>package org.unisonweb.codegeneration
package v2

object LetRecGenerator extends OneFileGenerator("CompileLetRec.scala") {
  def source =
    "package org.unisonweb.compilation" <>
    "package v2" <>
    "" <>
    "trait CompileLetRec " + {
      "def compileLetRec(e: TermC, bindings: Array[Computation], body: Computation): Computation = " + {
        "(stackSize(e): @annotation.switch) match " + {
           (0 to N).each { i =>
             s"case $i => (bindings.length: @annotation.switch) match " + {
               (1 to N).each { j =>
                 s"case $j => " <> {
                   s"class LetRecS${i}A${j} extends Computation$i(e, ()) " + {
                     (1 to j).each { k => s"val b$k = bindings(${k-1})" } <>
                     applySignature(i) + " = " + {
                       val bArgs =
                        if (i + j <= N)
                          (j to 1 by -1).commas(l => s"0.0, b${l}r") + commaIf(i) +
                          (0 until i).commas(l => s"x$l, x${l}b")
                        else
                          "Array(" +
                            (j to 1 by -1).commas(l => s"Slot(0.0, b${l}r)") + commaIf(i) +
                            (0 until i).commas(l => s"Slot(x$l, x${l}b)") +
                          ")"
                       "val " + (1 to j).commas { k => s"b${k}r" } + " = Ref()" <>
                       (1 to j).each { k => s"b${k}r.value = Value(b$k(rec, $bArgs, r), r.boxed)" } <>
                       s"body(rec, $bArgs, r)"
                     }.b
                   }.b <>
                   s"new LetRecS${i}A${j}"
                 }.indent
               } <>
               "case n => " <> {
                 s"class LetRecS${i}AN extends Computation$i(e, ()) " + {
                   applySignature(i) + " = " + {
                     "val refs = Array.fill(bindings.length)(Ref())" <>
                     "val xs = Array[Slot](" + (0 until i).commas(k => s"Slot(x$k,x${k}b)") + ")" <>
                     "val slots = refs.view.map(r => Slot(0.0, r)).reverse.toArray ++ xs" <>
                     "var i = 0" <>
                     "while (i < bindings.length)" + {
                       "refs(i).value = Value(bindings(i)(rec, slots, r), r.boxed)" <>
                       "i += 1"
                     }.b <>
                     "body(rec, slots, r)"
                   }.b
                 }.b <>
                 s"new LetRecS${i}AN"
               }.indent
             }.b
           } <>
           "case n => " <> {
             s"class LetRecSNAN extends ComputationN(n, e, ()) " + {
               applyNSignature + " = " + {
                 "val refs = Array.fill(bindings.length)(Ref())" <>
                 "val slots = refs.view.map(r => Slot(0.0, r)).reverse.toArray ++ xs" <>
                 "var i = 0" <>
                 "while (i < bindings.length)" + {
                   "refs(i).value = Value(bindings(i)(rec, slots, r), r.boxed)" <>
                   "i += 1"
                 }.b <>
                 "body(rec, slots, r)"
               }.b
             }.b <>
             "new LetRecSNAN"
           }.indent
        }.b
      }.b
    }.b
}
{'fraction_non_alphanumeric': 0.17415818324197338, 'fraction_numerical': 0.00845732184808144, 'mean_word_length': 1.0869281045751633, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1085526', 'n_tokens_mistral': 2131, 'n_tokens_neox': 1961, 'n_words': 407}