equal
deleted
inserted
replaced
5 // |
5 // |
6 // amm bfi.sc <<bf_program.bf>> |
6 // amm bfi.sc <<bf_program.bf>> |
7 // |
7 // |
8 |
8 |
9 |
9 |
10 import scala.util._ |
10 // BF memory is represented as a Map |
11 |
|
12 // BF memory as a map |
|
13 type Mem = Map[Int, Int] |
11 type Mem = Map[Int, Int] |
14 |
12 |
15 // reading and writing BF memory |
13 // safe reading and writing of BF memory |
16 def sread(mem: Mem, mp: Int) : Int = |
14 def sread(mem: Mem, mp: Int) : Int = |
17 mem.getOrElse(mp, 0) |
15 mem.getOrElse(mp, 0) |
18 |
16 |
19 def write(mem: Mem, mp: Int, v: Int) : Mem = |
17 def write(mem: Mem, mp: Int, v: Int) : Mem = |
20 mem.updated(mp, v) |
18 mem.updated(mp, v) |