Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Library._
- // case class InterpException(s: String) extends RuntimeException
- case class NotImplementedException(s: String) extends RuntimeException
- object Solution {
- type Store = List[Cell]
- type PointerEnvironment = List[Pointer]
- def interpApp(app: AppC, nv: PointerEnvironment, st1: Store): (Value, Store) = interp(app.f, nv, st1) match {
- // first see if first argument of function is indeed a lambda
- case (PointerClosV(paramater, body, nv), st) => {
- // verify if number of parameters matches the number of arguments
- // (not needed since they both have only a parameter_
- // evaluate argument and update store
- // interpret argument
- val argument = interp(app.arg, nv, st)._1
- val newPosition = newLoc(st)
- val extendedEnvironment = Pointer(paramater, newPosition) :: nv
- val extendedStore = extendStore(Cell(newPosition, argument), st)
- interp(body, extendedEnvironment, extendedStore)
- }
- case _ => throw new InterpException("Something went wrong!")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement