<commit_before>package com.joescii.lisp
package metal
package jvm

import ir._
import java.io.{PrintStream, FileOutputStream, File}
import me.qmx.jitescript.{CodeBlock, JiteClass}
import org.objectweb.asm.Opcodes._
import com.joescii.lisp.ir.Program
import me.qmx.jitescript.util.CodegenUtils._
import com.joescii.lisp.ir.Program

/**
 * Created by jbarnes on 11/10/2014.
 */
object JvmMetal extends Metal {
  override def forge(program:Program, target:File):Seq[File] = {
    val jite = LispJite(program)

    target.mkdirs()
    val helloClassFile = new File(target, "HelloJite.class")

    val outStream = new FileOutputStream(helloClassFile)
    outStream.write(jite.toBytes)
    outStream.flush()
    outStream.close()

    Seq(helloClassFile)
  }

}

object LispJite {
  implicit class LispCodeBlock(c:CodeBlock) {
    def print(v:Value) = {
      v match {
        case StringVal(s) =>
          c.getstatic(p(classOf[System]), "out", ci(classOf[PrintStream]))
            .ldc(s)
            .invokevirtual(p(classOf[PrintStream]), "println", sig(classOf[Unit], classOf[String]))

        //        case IntVal(i) => i.toString
        case SymbolicName(name) =>
          c.getstatic(p(classOf[System]), "out", ci(classOf[PrintStream]))
            .aload(1)
            .invokevirtual(p(classOf[PrintStream]), "println", sig(classOf[Unit], classOf[String]))

      }
    }
    def declareValue(name:String, v:Value) = {
      v match {
        case StringVal(s) =>
          c.ldc(s)
            .astore(1)
      }
    }
  }

  def apply(program:Program) = new JiteClass("HelloJite") {
    val code = program.vs.foldLeft(new CodeBlock()) {
      case (c, Print(v)) => c.print(v)
      case (c, Let(SymbolicName(name), v)) => c.declareValue(name, v)
    }

    defineMethod("main", ACC_PUBLIC | ACC_STATIC, sig(classOf[Unit], classOf[Array[String]]), code.voidreturn())
  }


}<commit_msg>Refactored the JVM print<commit_after>package com.joescii.lisp
package metal
package jvm

import ir._
import java.io.{PrintStream, FileOutputStream, File}
import me.qmx.jitescript.{CodeBlock, JiteClass}
import org.objectweb.asm.Opcodes._
import com.joescii.lisp.ir.Program
import me.qmx.jitescript.util.CodegenUtils._
import com.joescii.lisp.ir.Program

/**
 * Created by jbarnes on 11/10/2014.
 */
object JvmMetal extends Metal {
  override def forge(program:Program, target:File):Seq[File] = {
    val jite = LispJite(program)

    target.mkdirs()
    val helloClassFile = new File(target, "HelloJite.class")

    val outStream = new FileOutputStream(helloClassFile)
    outStream.write(jite.toBytes)
    outStream.flush()
    outStream.close()

    Seq(helloClassFile)
  }

}

object LispJite {
  implicit class LispCodeBlock(c:CodeBlock) {
    private def loadValue(v:Value) = v match {
      case StringVal(s) => c.ldc(s)
      //        case IntVal(i) => i.toString
      case SymbolicName(name) => c.aload(1)
    }

    def print(v:Value) = {
      c.getstatic(p(classOf[System]), "out", ci(classOf[PrintStream]))
      loadValue(v)
        .invokevirtual(p(classOf[PrintStream]), "println", sig(classOf[Unit], classOf[String]))
    }
    def declareValue(name:String, v:Value) = {
      v match {
        case StringVal(s) =>
          c.ldc(s)
            .astore(1)
      }
    }
  }

  def apply(program:Program) = new JiteClass("HelloJite") {
    val code = program.vs.foldLeft(new CodeBlock()) {
      case (c, Print(v)) => c.print(v)
      case (c, Let(SymbolicName(name), v)) => c.declareValue(name, v)
    }

    defineMethod("main", ACC_PUBLIC | ACC_STATIC, sig(classOf[Unit], classOf[Array[String]]), code.voidreturn())
  }


}
{'fraction_non_alphanumeric': 0.140818007136975, 'fraction_numerical': 0.005489980785067252, 'mean_word_length': 3.232288037166086, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3228040', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1268, 'n_words': 236}