Skip to content

Commit

Permalink
Read source text in js-eval (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
h2oche committed Feb 22, 2022
1 parent ae8bd3e commit 0e888f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/scala/esmeta/interp/Interp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import esmeta.error.*
import esmeta.interp.util.*
import esmeta.ir.{Func => IRFunc, *}
import esmeta.js.*
import esmeta.js.util.{Parser => JSParser}
import esmeta.js.builtin.TypeModel
import esmeta.util.BaseUtils.*
import esmeta.util.SystemUtils.*
Expand All @@ -18,6 +19,7 @@ class Interp(
val st: State,
val timeLimit: Option[Long] = Some(TIMEOUT),
val typeModel: Option[TypeModel] = None, // TODO refactoring
val parser: Option[JSParser] = None, // TODO refactoring
) {
import Interp.*

Expand Down
10 changes: 7 additions & 3 deletions src/main/scala/esmeta/phase/JSEval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package esmeta.phase
import esmeta.*
import esmeta.spec.Spec
import esmeta.interp.*
import esmeta.util.SystemUtils.*
import esmeta.js.*
import esmeta.js.util.*
import esmeta.js.util.Parser
import esmeta.js.builtin.*

/** `js-eval` phase */
Expand All @@ -16,8 +17,11 @@ case object JSEval extends Phase[Spec, State] {
globalConfig: GlobalConfig,
config: Config,
): State = {
val (st, typeModel) = Initialize(spec, "") // XXX get source text
println(st)
// get source text
val filename = getSecondFilename(globalConfig, "js-eval")
// TODO refactoring to mechanized spec
val (st, typeModel) = Initialize(spec, readFile(filename))
val parser = Parser(spec.grammar)
new Interp(st, typeModel = Some(typeModel)).fixpoint
st
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/esmeta/util/SystemUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ object SystemUtils {
def getFirstFilename(globalConfig: GlobalConfig, msg: String): String =
globalConfig.args.headOption.getOrElse(throw NoFileError(msg))

/** get second filename */
def getSecondFilename(globalConfig: GlobalConfig, msg: String): String =
globalConfig.args.tail.headOption.getOrElse(throw NoFileError(msg))

/** read file */
def readFile(filename: String): String =
val source = Source.fromFile(filename, ENC)
Expand Down

0 comments on commit 0e888f5

Please sign in to comment.