示例#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)
示例#2
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)
示例#3
0
 def test_letrec(self):
     f, k, function = il.Var('f'), il.Var('k'), il.Var('function')
     result = cps(letrec([(f, lamda((), f()))], f()))
     expect = il.Clamda(v, il.Assign(f, v), v)(il.Lamda(
         (k, ),
         il.Clamda(function, function(k))(f)))
     eq_(result, expect)
示例#4
0
 def test_chars(self):
     x, cs, chars = LogicVar('x'), Var('cs'), MacroVar('chars')
     x1 = Var('x')
     eq_(
         eval(
             let([(chars, lamda(
                 (x1, cs), begin(char(x1), contain(cs, x1))))],
                 parse_text(chars(x, 'a'), 'a'), getvalue(x))), 'a')
示例#5
0
 def test_letrec(self):
   f, k, function = il.Var('f'), il.Var('k'), il.Var('function')
   result = cps(letrec([(f, lamda((), f()))], f()))
   expect = il.Clamda(v, 
                      il.Assign(f, v), 
                      v)(
                        il.Lamda((k,), il.Clamda(function, function(k))(f)))
   eq_(result, expect)
示例#6
0
 def testblock(self):
     f = Var('f')
     foo = Var('foo')
     eq_(
         eval(
             block(
                 foo,
                 let([(f, lamda((), exit_block(foo, 1)))],
                     mul(2, block(foo, f()))))), 1)
示例#7
0
 def testletdouble(self):
     x, f = Const('x'), Const('f')
     eq_(eval(let([(f, lamda([x], add(x, x)))], f(1))), 2)
示例#8
0
 def test_letrec3(self):
     x, f = Var('x'), Var('f')
     eq_(
         eval(
             letrec([(f, lamda((x, ), if_(eq(x, 1), 1, f(sub(x, 1)))))],
                    f(2))), 1)
示例#9
0
 def test_letrec_assign2(self):
     x, f = Const('x'), Const('f')
     assert_raises(MultiAssignToConstError, eval,
                   letrec([(f, lamda((x, ), f(1), assign(f, 1)))], f(2)))
示例#10
0
 def test_lamda2(self):
     x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k')
     eq_(alpha(lamda((x, y), lamda((x, ), x, y), x)),
         lamda((x, y), lamda((x1, ), x1, y), x))
示例#11
0
文件: testeval.py 项目: chaosim/dao
 def test_letrec_assign2(self):
   x, f = Const('x'), Const('f')
   assert_raises(MultiAssignToConstError, eval,
                 letrec([(f, lamda((x,), f(1), assign(f, 1)))], f(2)))
示例#12
0
文件: testparser.py 项目: chaosim/dao
 def test_chars(self):
   x, cs, chars = LogicVar('x'), Var('cs'), MacroVar('chars')
   x1 = Var('x')
   eq_(eval(let([(chars, lamda((x1, cs), begin(char(x1), contain(cs, x1))))],
                           parse_text(chars(x, 'a'), 'a'), getvalue(x))), 'a')
示例#13
0
文件: testeval.py 项目: chaosim/dao
 def test_callcc(self):
   k = Var('k')
   eq_(eval(add(callcc(lamda((k,), k(1))),2)), 3)
示例#14
0
文件: testeval.py 项目: chaosim/dao
 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)
示例#15
0
文件: testeval.py 项目: chaosim/dao
 def testblock(self):
   f = Var('f')
   foo = Var('foo')
   eq_(eval(block(foo, let([(f, lamda((), exit_block(foo,1)))], 
                           mul(2, block(foo, f()))))), 
       1)
示例#16
0
文件: testeval.py 项目: chaosim/dao
 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)
示例#17
0
文件: testeval.py 项目: chaosim/dao
 def testletdouble(self):
   x, f = Const('x'), Const('f')
   eq_(eval(let([(f, lamda([x], add(x, x)))], f(1))), 2)
示例#18
0
文件: testeval.py 项目: chaosim/dao
 def test_letrec3(self):
   x, f = Var('x'), Var('f')
   eq_(eval(letrec([(f, lamda((x,), if_(eq(x,1), 1, f(sub(x,1)))))], f(2))), 1)
示例#19
0
文件: testeval.py 项目: chaosim/dao
 def test_lamda(self):
   x = Const('x')
   eq_(eval(lamda((x,), 1)(1)), 1)
   eq_(eval(lamda((x,), 1)(2)), 1)
   eq_(eval(lamda((x,), x)(2)), 2)
示例#20
0
 def test_lambda(self):
   x, y, k = Var('x'), Var('y'), il.Var('k')
   result = cps(lamda((x,y), 1))
   expect = done()(lamda((x, y, k), k(1)))
   eq_(result, expect)
示例#21
0
 def test_lamda3(self):
     x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k')
     assert_raises(VariableNotBound, alpha, lamda((x, ), x, y))
示例#22
0
文件: testeval.py 项目: chaosim/dao
 def test_lamda2(self):
   x, y = Const('x'), Const('y')
   eq_(eval(lamda((x, y), add(x, y))(1, 3)), 4)
示例#23
0
 def test_callcc(self):
     k = Var('k')
     eq_(eval(add(callcc(lamda((k, ), k(1))), 2)), 3)
示例#24
0
 def test_lamda2(self):
   x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k')
   eq_(alpha(lamda((x,y), lamda((x,), x, y), x)), lamda((x,y), lamda((x1,), x1, y), x))
示例#25
0
 def test_lamda(self):
     x = Const('x')
     eq_(eval(lamda((x, ), 1)(1)), 1)
     eq_(eval(lamda((x, ), 1)(2)), 1)
     eq_(eval(lamda((x, ), x)(2)), 2)
示例#26
0
文件: testeval.py 项目: chaosim/dao
 def xtest_letrec2(self):
   x, f = Var('x'), Var('f')
   eq_(eval(letrec([(f, lamda((x,), f(1)))], f(2))), 1)
示例#27
0
 def test_lambda(self):
     x, y, k = Var('x'), Var('y'), il.Var('k')
     result = cps(lamda((x, y), 1))
     expect = done()(lamda((x, y, k), k(1)))
     eq_(result, expect)
示例#28
0
 def test_lamda2(self):
     x, y = Const('x'), Const('y')
     eq_(eval(lamda((x, y), add(x, y))(1, 3)), 4)
示例#29
0
 def test_lamda(self):
   x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k')
   eq_(alpha(lamda((x,y), 1)), lamda((x, y), il.Integer(1)))
示例#30
0
 def xtest_letrec2(self):
     x, f = Var('x'), Var('f')
     eq_(eval(letrec([(f, lamda((x, ), f(1)))], f(2))), 1)
示例#31
0
 def test_lamda3(self):
   x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k')
   assert_raises(VariableNotBound, alpha, lamda((x,), x, y))
示例#32
0
 def test_lamda(self):
     x, x1, y, y1, k = Var('x'), Var('x1'), Var('y'), Var('y1'), Var('k')
     eq_(alpha(lamda((x, y), 1)), lamda((x, y), il.Integer(1)))