54 def compile_Dec(s: Int, n: Int, e: Int) = |
54 def compile_Dec(s: Int, n: Int, e: Int) = |
55 TMFindnth(n).shift(s - 1) ++ TMDec.shift(2 * n).shift(s - 1).adjust(e) |
55 TMFindnth(n).shift(s - 1) ++ TMDec.shift(2 * n).shift(s - 1).adjust(e) |
56 |
56 |
57 def compile_Goto(s: Int) = TMGoto.shift(s - 1) |
57 def compile_Goto(s: Int) = TMGoto.shift(s - 1) |
58 |
58 |
59 def compile(p: AProg, s: Int, i: AInst) = i match { |
59 def compile_abc(p: AProg, s: Int, i: AInst) = i match { |
60 case Inc(n) => compile_Inc(s, n) |
60 case Inc(n) => compile_Inc(s, n) |
61 case Dec(n, e) => compile_Dec(s, n, address(p, e)) |
61 case Dec(n, e) => compile_Dec(s, n, address(p, e)) |
62 case Goto(e) => compile_Goto(address(p, e)) |
62 case Goto(e) => compile_Goto(address(p, e)) |
63 } |
63 } |
64 |
64 |
65 // component TMs for each instruction |
65 // component TMs for each instruction |
66 def TMs(p: AProg) = |
66 def TMs(p: AProg) = |
67 p.zipWithIndex.map{case (i, n) => compile(p, address(p, n), i)} |
67 p.zipWithIndex.map{case (i, n) => compile_abc(p, address(p, n), i)} |
68 |
68 |
69 def toTM(p: AProg) = TMs(p).reduceLeft(_ ++ _) |
69 def toTM(p: AProg) = TMs(p).reduceLeft(_ ++ _) |
70 |
70 |
71 } |
71 } |
72 |
72 |