package cs241e.assignments

import cs241e._

import ProgramRepresentation._

import CodeBuilders._
import Typer._
import scanparse.Grammars._

/** A code generator that converts a Lacs parse tree into the intermediate language developed in Assignment 1 to 6. */
object CodeGenerator {
  def generateProcedures(procedureScopes: Seq[ProcedureScope], typeMap: Map[Tree, Type]): Seq[Procedure] = {

    /** Given a `procedureScope`, generates the `Code` implementing the procedure, and assigns it to
      * `procedureScope.procedure.code`.
    def generateCode(procedureScope: ProcedureScope): Unit = {

      /** Generates the `Code` that implements `tree`.
        * This method will be called from the outside only on `tree`s rooted at nodes of kind "expras".
        * However, if it calls itself recursively on other kinds of nodes, it needs to be able to handle
        * those node kinds as well.
      def recur(tree: Tree): Code = ???

      /* Main body of generateCode. */
      procedureScope.procedure.code = recur(procedureScope.expras)

    /* Main body of generateProcedures. */