Skip to content

Commit

Permalink
Resolve span info bug related to #153
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnaldo committed Oct 30, 2024
1 parent 3a8ab6b commit fc85c0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/scala/esmeta/compiler/BackEdgeWalker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ import esmeta.ir.util.UnitWalker

/** walker for adjusting backward edge from ir to lang */
class BackEdgeWalker(fb: FuncBuilder) extends UnitWalker {
def apply[T <: IRElem](elem: T): T = { walk(elem); elem }
override def walk(inst: Inst): Unit = if (inst.langOpt.isEmpty)
private var overriden = false
def apply[T <: IRElem](elem: T): T = apply(elem, false)
def apply[T <: IRElem](elem: T, overriden: Boolean): T =
this.overriden = overriden
walk(elem)
this.overriden = false
elem
override def walk(inst: Inst): Unit = if (overriden || inst.langOpt.isEmpty)
inst.setLangOpt(fb.langs.headOption)
super.walk(inst)

override def walk(expr: Expr): Unit = if (expr.langOpt.isEmpty)
override def walk(expr: Expr): Unit = if (overriden || expr.langOpt.isEmpty)
expr.setLangOpt(fb.langs.headOption)
super.walk(expr)

override def walk(ref: Ref): Unit = if (ref.langOpt.isEmpty)
override def walk(ref: Ref): Unit = if (overriden || ref.langOpt.isEmpty)
ref.setLangOpt(fb.langs.headOption)
super.walk(ref)
}
1 change: 1 addition & 0 deletions src/main/scala/esmeta/compiler/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ class Compiler(
case None => x
}
val renamed = renameWalker.walk(compileWithScope(fb, algo.body))
fb.backEdgeWalker(renamed, overriden = true)
fb.addInst(renamed)
EUndef() // NOTE: unused expression

Expand Down

0 comments on commit fc85c0c

Please sign in to comment.