Advertisement
VladNitu

Vlad Env Store chaining

Mar 18th, 2023
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 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. def evalArguments(app: AppC, param: String, nv: PointerEnvironment, st1: Store): (Store, PointerEnvironment)= {
  11.  
  12. val (value, st2): (Value, Store) = interp(app.arg, nv, st1)
  13.  
  14. val newLocation: Int = newLoc(st2)
  15. val st3: Store = extendStore(Cell(newLocation, value), st2)
  16. val nv3: PointerEnvironment = Pointer(param, newLocation) :: nv
  17. (st3, nv3)
  18.  
  19. }
  20.  
  21. def interpApp(app: AppC, nv: PointerEnvironment, st1: Store): (Value, Store) = app.f match{
  22.  
  23. case FdC(param, body) => {
  24.  
  25. val (st2, nv2): (Store, PointerEnvironment) = evalArguments(app, param, nv, st1) // Expand store
  26. interp(body, nv2, st2)
  27.  
  28. }
  29. case _ => throw new RuntimeException("f is not a function")
  30.  
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement