scala/ex.scala
changeset 209 b16dfc467b67
parent 208 3267acc1f97f
child 210 5e2e576fac7c
equal deleted inserted replaced
208:3267acc1f97f 209:b16dfc467b67
    98 println("Add(69, 30)   " + test_comp2(Add, 69, 30))
    98 println("Add(69, 30)   " + test_comp2(Add, 69, 30))
    99 println("Mult(13, 9)   " + test_comp2(recs.Mult, 13, 9))
    99 println("Mult(13, 9)   " + test_comp2(recs.Mult, 13, 9))
   100 println("Power(3, 4)   " + test_comp2(Power, 3, 4))
   100 println("Power(3, 4)   " + test_comp2(Power, 3, 4))
   101 println("Minus(30, 4)  " + test_comp2(Minus, 30, 4))
   101 println("Minus(30, 4)  " + test_comp2(Minus, 30, 4))
   102 println("Fact(5)       " + test_comp2(Fact, 5))
   102 println("Fact(5)       " + test_comp2(Fact, 5))
   103 println("Prime(5)      " + test_comp2(Prime, 5))
   103 //println("Prime(5)      " + test_comp2(Prime, 5))
   104 println("Prime(6)      " + test_comp2(Prime, 6))
   104 //println("Prime(4)      " + test_comp2(Prime, 4))
   105 println("Strt(1)(2)    " + test_comp2(Strt(1), 2))
   105 println("Strt(1)(2)    " + test_comp2(Strt(1), 2))
   106 
   106 
       
   107 def test_comp1a(f: Rec, ns: Int*) = {
       
   108   val (abc_f, arity, _) = compile_rec(f)
       
   109   val tm1 = toTM(abc_f.p) 
       
   110   val res = tm1.run(Tape(ns.toList))
       
   111   ("Result: " + res + "  length: " + tm1.p.length + " tape: " + arity)
       
   112 }
   107 
   113 
       
   114 println("")
       
   115 println("S(3)          " + test_comp1a(S, 3))
       
   116 println("Const(10)     " + test_comp1a(Const(10), 0))
       
   117 println("Add(6, 3)     " + test_comp1a(Add, 6, 3))
   108 
   118 
       
   119 /*
       
   120 def test_comp1(f: Rec, ns: Int*) = {
       
   121   val (abc_f, arity, _) = compile_rec(f)
       
   122   val tm = toTM(abc_f.p) :+ TMMopup(arity)
       
   123   val res = tm.run(Tape(ns.toList))
       
   124   ("Result: " + res + "  length: " + tm.p.length + " tape: " + arity)
       
   125 }
   109 
   126 
       
   127 println("")
       
   128 println("S(3)          " + test_comp1(S, 3))
       
   129 println("Const(10)     " + test_comp1(Const(10), 0))
       
   130 println("Add(6, 3)     " + test_comp1(Add, 6, 3))
   110 
   131 
       
   132 */ 
   111 //println(toTM(compile_rec(Add)._1.p).run(Tape(3, 4, 0)))
   133 //println(toTM(compile_rec(Add)._1.p).run(Tape(3, 4, 0)))
   112 //println(compile_rec(Add)._1.run(Map(0 -> 3, 1 -> 8, 2 -> 0)))
   134 //println(compile_rec(Add)._1.run(Map(0 -> 3, 1 -> 8, 2 -> 0)))
   113 //compile_rec(Add)._1.run(Map(0 -> 3, 1 -> 4, 2 -> 0))
   135 //compile_rec(Add)._1.run(Map(0 -> 3, 1 -> 4, 2 -> 0))