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 evalArguments(app: AppC, param: String, nv: PointerEnvironment, st1: Store): (Store, PointerEnvironment)= {
- val (value, st2): (Value, Store) = interp(app.arg, nv, st1)
- val newLocation: Int = newLoc(st2)
- val st3: Store = extendStore(Cell(newLocation, value), st2)
- val nv3: PointerEnvironment = Pointer(param, newLocation) :: nv
- (st3, nv3)
- }
- def interpApp(app: AppC, nv: PointerEnvironment, st1: Store): (Value, Store) = app.f match{
- case FdC(param, body) => {
- val (st2, nv2): (Store, PointerEnvironment) = evalArguments(app, param, nv, st1) // Expand store
- interp(body, nv2, st2)
- }
- case _ => throw new RuntimeException("f is not a function")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement