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)
def test_basic(self): assert parse("12+1") == BinaryOp("+", ConstInt(12), ConstInt(1))
def test_statements(self): assert parse("a=3;a") == SemicolonExpr( Assignment("a", ConstInt(3)), Variable("a"))
def test_variable_assignment(self): assert parse("a=3") == Assignment("a", ConstInt(3))
def test_parse_floats(self): assert parse("1.2+1") == BinaryOp("+", ConstFloat(1.2), ConstInt(1))
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
def interpret(self, source): bc = compile_ast("<input>", source, parse(source)) frame = run_bytecode(bc) return frame.pop()