Skip to content

Commit

Permalink
Replace EDuplicated with __DUPLICATED__ aux function (#239)
Browse files Browse the repository at this point in the history
Co-authored-by: Jihyeok Park <jihyeok_park@korea.ac.kr>
  • Loading branch information
taxor03 and jhnaldo authored Jul 23, 2024
1 parent 086348d commit b3520d0
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 40 deletions.
15 changes: 15 additions & 0 deletions src/main/resources/manuals/funcs/__HAS_DUPLICATE__.ir
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def <AUX>:__HAS_DUPLICATE__(
list: List
): Boolean = {
let i = 1
let len = list.length
while (< i len) {
let j = 0
while (< j i) {
if (= list[i] list[j]) return true
j = (+ j 1)
}
i = (+ i 1)
}
return false
}
3 changes: 2 additions & 1 deletion src/main/resources/result/complete-funcs
Original file line number Diff line number Diff line change
Expand Up @@ -2516,5 +2516,6 @@ YieldExpression[0,0].Evaluation
YieldExpression[1,0].Evaluation
YieldExpression[2,0].Evaluation
__CLAMP__
__HAS_DUPLICATE__
__IS_ARRAY_INDEX__
__REMOVE_ELEM__
__REMOVE_ELEM__
5 changes: 0 additions & 5 deletions src/main/scala/esmeta/analyzer/AbsTransfer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,6 @@ trait AbsTransferDecl { self: Analyzer =>
v <- transfer(map)
lv <- id(_.keys(asite, v, intSorted))
} yield lv
case EDuplicated(expr) =>
for {
v <- transfer(expr)
st <- get
} yield v.duplicated(st)
case EMath(n) => AbsValue(Math(n))
case EInfinity(pos) => AbsValue(Infinity(pos))
case ENumber(n) if n.isNaN => AbsValue(Double.NaN)
Expand Down
12 changes: 0 additions & 12 deletions src/main/scala/esmeta/analyzer/domain/obj/ObjBasicDomain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,6 @@ trait ObjBasicDomainDecl { self: Self =>
modifyList(elem, _ ++ values, _ ⊔ list.mergedValue, weak)
case _ => Top

/** duplicated element check */
def duplicated: AbsBool = elem match
case _: MergedList => AB
case KeyWiseList(vs) if vs.forall(_.isSingle) =>
val values = vs.map(_.getSingle).flatMap {
case One(v) => Some(v)
case _ => None
}
AbsBool(Bool(values.toSet.size != values.size))
case _: KeyWiseList => AB
case _ => AbsBool.Bot

/** appends */
def append(value: AbsValue, weak: Boolean): Elem =
modifyList(elem, _ :+ value, _ ⊔ value, weak)
Expand Down
3 changes: 0 additions & 3 deletions src/main/scala/esmeta/analyzer/domain/obj/ObjDomain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ trait ObjDomainDecl { self: Self =>
/** concat */
def concat(list: AbsObj, weak: Boolean): Elem

/** duplicated element check */
def duplicated: AbsBool

/** append */
def append(value: AbsValue, weak: Boolean): Elem

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,6 @@ trait ValueBasicDomainDecl { self: Self =>
} newV ⊔= apply(cfg.esParser(name, parseArgs).from(str))
// result
newV
def duplicated(st: AbsState): Elem =
apply(bool = elem.part.foldLeft(AbsBool.Bot: AbsBool) {
case (avb, part) => avb ⊔ st.get(part).duplicated
})
def substring(from: Elem): Elem =
(elem.getSingle, from.getSingle) match
case (Zero, _) | (_, Zero) => Bot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ trait ValueDomainDecl { self: Self =>
def convertTo(cop: COp, radix: Elem): Elem
def sourceText: Elem
def parse(rule: Elem): Elem
def duplicated(st: AbsState): Elem
def substring(from: Elem): Elem
def substring(from: Elem, to: Elem): Elem
def trim(isStarting: Boolean): Elem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ trait ValueTypeDomainDecl { self: Self =>
nt <- set
name = nt.name
} yield name).toSet)))
def duplicated(st: AbsState): Elem = boolTop
def substring(from: Elem): Elem = strTop
def substring(from: Elem, to: Elem): Elem = strTop
def trim(isStarting: Boolean): Elem = strTop
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/esmeta/compiler/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,9 @@ class Compiler(
or(is(x, ENumber(Double.NaN)), or(is(x, posInf), is(x, negInf))),
)
case Duplicated =>
EDuplicated(x)
val (b, bExpr) = fb.newTIdWithExpr
fb.addInst(ICall(b, AUX_HAS_DUPLICATE, List(x)))
bExpr
case Present =>
not(isAbsent(x))
case Empty =>
Expand Down
3 changes: 0 additions & 3 deletions src/main/scala/esmeta/interpreter/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,6 @@ class Interpreter(
eval(map) match
case addr: Addr => st.keys(addr, intSorted)
case v => throw NoAddr(map, v)
case EDuplicated(expr) =>
val vs = eval(expr).getList(expr, st).values
Bool(vs.toSet.size != vs.length)
case EMath(n) => Math(n)
case EInfinity(pos) => Infinity(pos)
case ENumber(n) if n.isNaN => Number(Double.NaN)
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/esmeta/ir/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ case class EMathOp(mop: MOp, args: List[Expr]) extends Expr
case class EConvert(cop: COp, expr: Expr) extends Expr
case class ETypeOf(base: Expr) extends Expr
case class ETypeCheck(base: Expr, tyExpr: Expr) extends Expr
case class EDuplicated(list: Expr) extends Expr
case class EClo(fname: String, captured: List[Name]) extends Expr
case class ECont(fname: String) extends Expr

Expand Down
1 change: 1 addition & 0 deletions src/main/scala/esmeta/ir/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,6 @@ def PARAM_NEW_TARGET = Param(NAME_NEW_TARGET)
/** predefined auxiliary functions */
inline def getAux(name: String): EClo = EClo("__" + name + "__", Nil)
def AUX_CLAMP = getAux("CLAMP")
def AUX_HAS_DUPLICATE = getAux("HAS_DUPLICATE")
def AUX_IS_ARRAY_INDEX = getAux("IS_ARRAY_INDEX")
def AUX_REMOVE_ELEM = getAux("REMOVE_ELEM")
2 changes: 0 additions & 2 deletions src/main/scala/esmeta/ir/util/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ trait Parsers extends TyParsers {
case e => ETypeOf(e)
} | "(" ~ "?" ~> expr ~ (":" ~> expr) <~ ")" ^^ {
case e ~ t => ETypeCheck(e, t)
} | "(" ~ "duplicated" ~> expr <~ ")" ^^ {
case e => EDuplicated(e)
} | "clo<" ~> fname ~ opt("," ~ "[" ~> repsep(name, ",") <~ "]") <~ ">" ^^ {
case s ~ cs => EClo(s, cs.getOrElse(Nil))
} | ("cont<" ~> fname <~ ">") ^^ {
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/esmeta/ir/util/Stringifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ class Stringifier(detail: Boolean, location: Boolean) {
app >> "(typeof " >> base >> ")"
case ETypeCheck(expr, ty) =>
app >> "(? " >> expr >> ": " >> ty >> ")"
case EDuplicated(expr) =>
app >> "(duplicated " >> expr >> ")"
case EClo(fname, captured) =>
given Rule[Iterable[Name]] = iterableRule("[", ", ", "]")
app >> "clo<" >> fname
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/esmeta/ir/util/UnitWalker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ trait UnitWalker extends BasicUnitWalker {
walk(fname); walkList(captured, walk)
case ECont(fname) =>
walk(fname)
case EDuplicated(expr) =>
walk(expr)
case EDebug(expr) =>
walk(expr)
case expr: ERandom => walk(expr)
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/esmeta/ir/util/Walker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ trait Walker extends BasicWalker {
EClo(walk(fname), walkList(captured, walk))
case ECont(fname) =>
ECont(walk(fname))
case EDuplicated(expr) =>
EDuplicated(walk(expr))
case EDebug(expr) =>
EDebug(walk(expr))
case expr: ERandom => walk(expr)
Expand Down

0 comments on commit b3520d0

Please sign in to comment.