Example #1
0
    def runstring(self, s):
        ast = parse(s)

        bc = compile_ast("<input>", s, ast)
        if self.debug:  # pragma: no cover
            print bc.dump()

        return self.run(bc)
Example #2
0
 def test_basic(self):
     assert parse("12+1") == BinaryOp("+", ConstInt(12), ConstInt(1))
Example #3
0
 def test_statements(self):
     assert parse("a=3;a") == SemicolonExpr(
         Assignment("a", ConstInt(3)), Variable("a"))
Example #4
0
 def test_variable_assignment(self):
     assert parse("a=3") == Assignment("a", ConstInt(3))
Example #5
0
 def test_parse_floats(self):
     assert parse("1.2+1") == BinaryOp("+", ConstFloat(1.2), ConstInt(1))
Example #6
0
 def check_compile(self, source, expected=None):
     ast = parse(source)
     bc = compile_ast('<input>', source, ast)
     if expected is not None:
         self.compare(bc, expected)
     return bc
Example #7
0
 def interpret(self, source):
     bc = compile_ast("<input>", source, parse(source))
     frame = run_bytecode(bc)
     return frame.pop()