Advertisement
VladNitu

diana env store

Mar 18th, 2023
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import Library._
  2.  
  3. // case class InterpException(s: String) extends RuntimeException
  4. case class NotImplementedException(s: String) extends RuntimeException
  5.  
  6. object Solution {
  7. type Store = List[Cell]
  8. type PointerEnvironment = List[Pointer]
  9.  
  10.  
  11. def interpApp(app: AppC, nv: PointerEnvironment, st1: Store): (Value, Store) = interp(app.f, nv, st1) match {
  12. // first see if first argument of function is indeed a lambda
  13. case (PointerClosV(paramater, body, nv), st) => {
  14. // verify if number of parameters matches the number of arguments
  15. // (not needed since they both have only a parameter_
  16.  
  17. // evaluate argument and update store
  18. // interpret argument
  19. val argument = interp(app.arg, nv, st)._1
  20.  
  21.  
  22. val newPosition = newLoc(st)
  23. val extendedEnvironment = Pointer(paramater, newPosition) :: nv
  24. val extendedStore = extendStore(Cell(newPosition, argument), st)
  25.  
  26. interp(body, extendedEnvironment, extendedStore)
  27.  
  28.  
  29.  
  30.  
  31. }
  32. case _ => throw new InterpException("Something went wrong!")
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement