Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
h2oche committed Feb 22, 2022
1 parent e87824f commit ae8bd3e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/esmeta/interp/Interp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Interp(
val func = cfg.funcOf(node)
println(s"[${func.ir.kind}${func.ir.name}] $node")
case ExitCursor(func) =>
println(s"[${func.ir.kind}${func.ir.name} Exited")
println(s"[${func.ir.kind}${func.ir.name}] Exited")
interp(st.context.cursor)
} catch case ReturnValue(value) => { setReturn(value); true }

Expand Down
27 changes: 0 additions & 27 deletions src/main/scala/esmeta/js/builtin/Key.scala

This file was deleted.

22 changes: 3 additions & 19 deletions src/main/scala/esmeta/js/builtin/Property.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,20 @@ import esmeta.interp.*
import scala.collection.mutable.{Map => MMap}

// properties
sealed trait Property:
def toObject: MapObj

// TODO
given Option[TypeModel] = None
sealed trait Property

// data properties
case class DataProperty(
value: PureValue,
writable: Boolean,
enumerable: Boolean,
configurable: Boolean,
) extends Property:
def toObject: MapObj = MapObj("PropertyDescriptor")(
Str("Value") -> value,
Str("Writable") -> Bool(writable),
Str("Enumerable") -> Bool(enumerable),
Str("Configurable") -> Bool(configurable),
)
) extends Property

// accessor properties
case class AccessorProperty(
get: NamedAddr,
set: NamedAddr,
enumerable: Boolean,
configurable: Boolean,
) extends Property:
def toObject: MapObj = MapObj("PropertyDescriptor")(
Str("Get") -> get,
Str("Set") -> set,
Str("Enumerable") -> Bool(enumerable),
Str("Configurable") -> Bool(configurable),
)
) extends Property
24 changes: 23 additions & 1 deletion src/main/scala/esmeta/js/builtin/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def descAddr(name: String, key: String): NamedAddr = NamedAddr(
def getSubmapObjects(
name: String,
nmap: List[(String, Property)],
): Map[Addr, Obj] = {
)(using Option[TypeModel]): Map[Addr, Obj] = {
var map = Map[Addr, Obj]()
map += submapAddr(name) -> MapObj(SUBMAP)(nmap.map {
case (k, _) => // handle symbol
Expand All @@ -72,3 +72,25 @@ def getSubmapObjects(
map ++= nmap.map { case (k, prop) => descAddr(name, k) -> prop.toObject }
map
}

/** extensions for Property */
extension (prop: Property) {

/** convert to ir map object */
def toObject(using Option[TypeModel]): MapObj = prop match
case DataProperty(v, w, e, c) =>
MapObj("PropertyDescriptor")(
Str("Value") -> v,
Str("Writable") -> Bool(w),
Str("Enumerable") -> Bool(e),
Str("Configurable") -> Bool(c),
)
case AccessorProperty(g, s, e, c) =>
MapObj("PropertyDescriptor")(
Str("Get") -> g,
Str("Set") -> s,
Str("Enumerable") -> Bool(e),
Str("Configurable") -> Bool(c),
)

}

0 comments on commit ae8bd3e

Please sign in to comment.