Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions wasm/src/main/scala/ir2wasm/TypeTransformer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ object TypeTransformer {
t: IRTypes.Type
)(implicit ctx: ReadOnlyWasmContext): List[Types.WasmType] =
t match {
case IRTypes.NoType => Nil
case IRTypes.ClassType(className) if className == IRNames.BoxedUnitClass => Nil
case _ => List(transformType(t))
case IRTypes.NoType => Nil
case _ => List(transformType(t))
}
def transformType(t: IRTypes.Type)(implicit ctx: ReadOnlyWasmContext): Types.WasmType =
t match {
Expand All @@ -64,6 +63,10 @@ object TypeTransformer {
Types.WasmRefNullType(
Types.WasmHeapType.Type(Names.WasmTypeName.WasmStructTypeName.string)
)
case IRNames.BoxedUnitClass =>
Types.WasmRefNullType(
Types.WasmHeapType.Type(Names.WasmTypeName.WasmStructTypeName.undef)
)
case _ =>
if (ctx.getClassInfo(clazz.className).isInterface)
Types.WasmRefNullType(Types.WasmHeapType.ObjectType)
Expand Down
19 changes: 3 additions & 16 deletions wasm/src/main/scala/ir2wasm/WasmBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class WasmBuilder {

def transformTopLevelExport(export: LinkedTopLevelExport)(implicit ctx: WasmContext): Unit = {
implicit val fctx = WasmFunctionContext()
val expressionBuilder = new WasmExpressionBuilder(ctx, fctx)
export.tree match {
case d: IRTrees.TopLevelFieldExportDef => ???
case d: IRTrees.TopLevelJSClassExportDef => ???
Expand Down Expand Up @@ -295,7 +294,6 @@ class WasmBuilder {
private def transformToplevelMethodExportDef(
exportDef: IRTrees.TopLevelMethodExportDef
)(implicit ctx: WasmContext, fctx: WasmFunctionContext) = {
val builder = new WasmExpressionBuilder(ctx, fctx)
val method = exportDef.methodDef
val methodName = method.name match {
case lit: IRTrees.StringLiteral => lit
Expand Down Expand Up @@ -363,15 +361,12 @@ class WasmBuilder {
}
params.foreach(fctx.locals.define)

val instrs = newBody match {
case t: IRTrees.Block => t.stats.flatMap(builder.transformTree)
case _ => builder.transformTree(newBody)
}
val expr = WasmExpressionBuilder.transformBody(newBody, resultType)
val func = WasmFunction(
Names.WasmFunctionName(methodName),
functionType,
fctx.locals.all,
WasmExpr(instrs)
expr
)
ctx.addFunction(func)

Expand Down Expand Up @@ -417,18 +412,10 @@ class WasmBuilder {
}).foreach(fctx.locals.define)

// build function body
val builder = new WasmExpressionBuilder(ctx, fctx)
val body = method.body.getOrElse(throw new Exception("abstract method cannot be transformed"))
// val prefix =
// if (method.flags.namespace.isConstructor) builder.objectCreationPrefix(clazz, method) else Nil
val instrs = body match {
case t: IRTrees.Block => t.stats.flatMap(builder.transformTree)
case _ => builder.transformTree(body)
}
val expr = method.resultType match {
case IRTypes.NoType => WasmExpr(instrs)
case _ => WasmExpr(instrs :+ RETURN)
}
val expr = WasmExpressionBuilder.transformBody(body, method.resultType)

val func = WasmFunction(
Names.WasmFunctionName(clazz.name.name, method.name.name),
Expand Down
Loading