Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CrescentonC committed Nov 30, 2024
1 parent e302925 commit d6a43aa
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions hkmc2/shared/src/main/scala/hkmc2/codegen/js/JSBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,8 @@ class JSBuilder(using Elaborator.State, Elaborator.Ctx) extends CodeBuilder:
doc" # const $proxy = this; # ${res.stripBreaks}${returningTerm(rst)}"
case _ => doc"$res${returningTerm(rst)}"
doc" # ${resJS}"
case Return(res, true) =>
// val resSym = semantics.TempSymbol(N, "res")
// val resStr = scope.allocateName(resSym)
// doc" # const $resStr = ${result(res)}; # Predef.TraceLogger.indent = prevIndent; # Predef.TraceLogger.log(${JSBuilder.makeStringLiteral("return ")} + $resStr); # ${resStr}"
doc" # ${result(res)}"
case Return(res, false) =>
// val resSym = semantics.TempSymbol(N, "res")
// val resStr = scope.allocateName(resSym)
// // doc" # const $resStr = ${result(res)}; # return ${resStr}"
// doc" # const $resStr = ${result(res)}; # Predef.TraceLogger.indent = prevIndent; # Predef.TraceLogger.log(${JSBuilder.makeStringLiteral("return ")} + $resStr); # return ${resStr}"
// // doc" # return ${result(res)};"
setupReturn(res)
case Return(res, true) => doc" # ${result(res)}"
case Return(res, false) => doc" # return ${result(res)};"

// TODO factor out common logic
case Match(scrut, Case.Lit(syntax.Tree.BoolLit(true)) -> trm :: Nil, els, rest) =>
Expand Down Expand Up @@ -329,14 +319,10 @@ class JSBuilder(using Elaborator.State, Elaborator.Ctx) extends CodeBuilder:
val v = doc"this.${getVar(i._1)}"
doc"""$v = await import("${i._2.toString
}"); # if ($v.default !== undefined) $v = $v.default;"""
// val traceLoggerSymbol = semantics.TempSymbol(N, "traceLogger")
// val traceLoggerStr = Scope.scope.allocateName(traceLoggerSymbol)
imps.mkDocument(doc" # ") ::
(if !compilingFile && false then doc"let = new Predef.TraceLogger(); # " else "") :/:
block(p.main) :: (
exprt match
case S(e) => doc"\nexport default ${e};\n"
case N => doc""
imps.mkDocument(doc" # ") :/: block(p.main) :: (
exprt match
case S(e) => doc"\nexport default ${e};\n"
case N => doc""
)

def block(t: Block)(using Raise, Scope): Document =
Expand All @@ -362,8 +348,6 @@ class JSBuilder(using Elaborator.State, Elaborator.Ctx) extends CodeBuilder:
doc" # return ${result(res)};"


def setupCall(bases: Document, args: Document)(using Raise, Scope): Document =
doc"${bases}(${args})"

object JSBuilder:
import scala.util.matching.Regex
Expand Down

0 comments on commit d6a43aa

Please sign in to comment.