Skip to content

Commit

Permalink
add overloading logic
Browse files Browse the repository at this point in the history
  • Loading branch information
stonechoe committed Oct 8, 2024
1 parent e1cddce commit 3cea729
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/scala/esmeta/interpreter/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,20 @@ class Interpreter(
eval(fexpr) match
case clo @ Clo(func, captured) =>
val vs = args.map(eval)
val newLocals =
getLocals(func.irFunc.params, vs, call, clo) ++ captured
st.callStack ::= CallContext(st.context, lhs)
st.context = Context(func, newLocals)
func.irFunc.overloads.apply(vs) match
case None =>
val newLocals =
getLocals(func.irFunc.params, vs, call, clo) ++ captured
st.callStack ::= CallContext(st.context, lhs)
st.context = Context(func, newLocals)
case Some(newFuncName) =>
val newFunc = cfg.getFunc(newFuncName)
val newLocals =
// TODO : check captured's `Name` is correct
getLocals(newFunc.irFunc.params, vs, call, clo) ++ captured
st.callStack ::= CallContext(st.context, lhs)
st.context = Context(newFunc, newLocals)

case cont @ Cont(func, captured, callStack) => {
val vs = args.map(eval)
val newLocals =
Expand Down

0 comments on commit 3cea729

Please sign in to comment.