def test_begin(self): c = Compiler() c.compile([ sym_begin, [sym_define, Symbol('answer'), 42], ['abs', Symbol('answer')] ]) self.assertEqual(eval(c.dump()), 42)
def test_func(self): src = """ (abs -42) """ r = Reader(src).read() c = Compiler() c.compile(r) self.assertEqual(eval(c.dump()), 42)
def setUp(self): c = Compiler() c.compile(['ord', 'a']) self.co = c.dump()
def test_if(self): c = Compiler() c.compile([sym_if, True, "True!"]) self.assertEqual(eval(c.dump()), "True!") c = Compiler() c.compile([sym_if, True, "True!", "False!"]) self.assertEqual(eval(c.dump()), "True!") c = Compiler() c.compile([sym_if, False, "True!", "False!"]) self.assertEqual(eval(c.dump()), "False!")
def test_define(self): c = Compiler() c.compile([sym_define, Symbol('answer'), -42]) c.compile(['abs', Symbol('answer')]) self.assertEqual(eval(c.dump()), 42)
def test_nest_func_call(self): c = Compiler() c.compile(['abs', ['max', -100, -42]]) self.assertEqual(eval(c.dump()), 42)
def test_func_call(self): c = Compiler() c.compile(['ord', 'a']) self.assertEqual(eval(c.dump()), 97)
def test_begin(self): c = Compiler() c.compile([sym_begin, [sym_define, Symbol('answer'), 42], ['abs', Symbol('answer')]]) self.assertEqual(eval(c.dump()), 42)