Esempio n. 1
0
 def test_letrec_odd_even(self):
     from util import n, odd, even
     eq_(
         eval(
             letrec([(odd, lamda([n], if_(eq(n, 0), 0, even(sub(n, 1))))),
                     (even, lamda([n], if_(eq(n, 0), 1, odd(sub(n, 1)))))],
                    odd(3))), 1)
Esempio n. 2
0
 def test_letrec_odd_even(self):
     from util import n
     odd, even = MacroVar('odd'), MacroVar('even')
     eq_(
         eval(
             letrec([(odd, macro([n], if_(eq(n, 0), 0, even(sub(n, 1))))),
                     (even, macro([n], if_(eq(n, 0), 1, odd(sub(n, 1)))))],
                    odd(3))), 1)
Esempio n. 3
0
 def test_letrec_fac(self):
     from util import m, n, fac
     eq_(
         eval(
             letrec([
                 (fac, lamda([n], if_(eq(n, 1), 1, mul(n, fac(sub(n, 1))))))
             ], fac(3))), 6)
Esempio n. 4
0
 def testblock3(self):
     a = Var('a')
     eq_(
         eval(
             block(a, 1,
                   if_(0, continue_block(a), begin(exit_block(a, 2), 3)))),
         2)
Esempio n. 5
0
 def test_unwind_protect_loop(self):
   from util import a, i
   eq_(eval(let([(i,3)], 
                block(a, assign(i, sub(i, 1)), 
                         if_(eq(i, 0), 
                           exit_block(a, 1),
                           unwind_protect(continue_block(a), prin(i)))), i)), 0)
Esempio n. 6
0
 def testloop(self):
     from util import a, i
     eq_(
         eval(
             let([(i, 3)],
                 block(a, assign(i, sub(i, 1)),
                       if_(eq(i, 0), exit_block(a, 1), continue_block(a))),
                 i)), 0)
Esempio n. 7
0
 def testloop(self):
   from util import a, i
   eq_(eval(let([(i,3)], 
                block(a, assign(i, sub(i, 1)), 
                         if_(eq(i, 0), 
                             exit_block(a, 1), 
                             continue_block(a))), 
                i)), 0)
Esempio n. 8
0
 def test_letrec_fac(self):
     from util import m, n
     fac = MacroVar('fac')
     eq_(
         eval(
             letrec([
                 (fac, macro([n], if_(eq(n, 1), 1, mul(n, fac(sub(n, 1))))))
             ], fac(3))), 6)
Esempio n. 9
0
 def test_macro6(self):
     n, act, ntimes = Var('n'), Var('act'), MacroVar('ntimes')
     eq_(
         eval(
             letrec([(ntimes,
                      macro((n, act),
                            if_(eq(n, 0), 1,
                                begin(act, ntimes(sub(n, 1), act)))))],
                    ntimes(3, println(1)))), 1)
Esempio n. 10
0
 def test_unwind_protect_loop(self):
     from util import a, i
     eq_(
         eval(
             let([(i, 3)],
                 block(
                     a, assign(i, sub(i, 1)),
                     if_(eq(i, 0), exit_block(a, 1),
                         unwind_protect(continue_block(a), prin(i)))), i)),
         0)
Esempio n. 11
0
 def test_if(self):
   result = compile_optimize(if_(0, 1, 2))
   expect = il.Integer(2)
   eq_(result, expect)
Esempio n. 12
0
 def test_if(self):
     result = compile_optimize(if_(0, 1, 2))
     expect = il.Integer(2)
     eq_(result, expect)
Esempio n. 13
0
 def test_letrec3(self):
     x, f = Var('x'), MacroVar('f')
     eq_(
         eval(
             letrec([(f, macro((x, ), if_(eq(x, 1), 1, f(sub(x, 1)))))],
                    f(2))), 1)
Esempio n. 14
0
 def test_letrec_fac(self):
   from util import m, n, fac
   eq_(eval(letrec([(fac, lamda([n], if_(eq(n,1), 1, mul(n, fac(sub(n, 1))))))],
                 fac(3))), 6)
Esempio n. 15
0
 def test_letrec_odd_even(self):
   from util import n, odd, even  
   eq_(eval(letrec([(odd, lamda([n], if_(eq(n,0), 0, even(sub(n,1))))),
                   (even, lamda([n], if_(eq(n,0), 1, odd(sub(n, 1)))))],
                 odd(3))), 1)
Esempio n. 16
0
 def test_if(self):
   result = compile(if_(0, 1, 2))
   expect = '2'
   eq_(result, expect)
Esempio n. 17
0
 def test_if(self):
   result = cps(if_(0, 1, 2))
   expect = il.Clamda(v, il.If(v, done()(1), done()(2)))(0)
   eq_(result, expect)
Esempio n. 18
0
 def testblock3(self):
   a = Var('a')
   eq_(eval(block(a, 1, if_(0, continue_block(a), 
                            begin(exit_block(a, 2), 3)))), 2)
Esempio n. 19
0
 def test_letrec_odd_even(self):
   from util import n
   odd, even  = MacroVar('odd'), MacroVar('even')  
   eq_(eval(letrec([(odd, macro([n], if_(eq(n,0), 0, even(sub(n,1))))),
                   (even, macro([n], if_(eq(n,0), 1, odd(sub(n, 1)))))],
                 odd(3))), 1)
Esempio n. 20
0
 def test_letrec_fac(self):
   from util import m, n
   fac = MacroVar('fac')
   eq_(eval(letrec([(fac, macro([n], if_(eq(n,1), 1, mul(n, fac(sub(n, 1))))))],
                 fac(3))), 6)
Esempio n. 21
0
 def test_letrec3(self):
   x, f = Var('x'), MacroVar('f')
   eq_(eval(letrec([(f, macro((x,), if_(eq(x,1), 1, f(sub(x,1)))))], f(2))), 1)
Esempio n. 22
0
 def test_macro6(self):
   n, act, ntimes = Var('n'), Var('act'), MacroVar('ntimes')
   eq_(eval(letrec([(ntimes, macro((n, act), 
                   if_(eq(n, 0), 1, 
                       begin(act, ntimes(sub(n, 1), act)))))], 
                   ntimes(3, println(1)))), 1)
Esempio n. 23
0
 def testif_(self):
     eq_(eval(if_(0, 1, 2)), 2)
Esempio n. 24
0
 def testif_(self):
   eq_(eval(if_(0, 1, 2)), 2)
Esempio n. 25
0
 def test_if(self):
     result = cps(if_(0, 1, 2))
     expect = il.Clamda(v, il.If(v, done()(1), done()(2)))(0)
     eq_(result, expect)
Esempio n. 26
0
 def test_if(self):
     result = compile(if_(0, 1, 2))
     expect = '2'
     eq_(result, expect)