Пример #1
0
def test_ass2(compile_stmt):
    frame = compile_stmt('a = b')

    assert frame.code == [
        ops.LoadName(0),
        ops.StoreName(1),
    ]
    assert frame.vars == [
        obj.LVar('b'),
        obj.LVar('a'),
    ]
Пример #2
0
def test_arith2(compile_expr):
    frame = compile_expr('a - b')

    assert frame.code == [
        ops.LoadName(0),
        ops.LoadName(1),
        ops.BinarySubtract(),
    ]
    assert frame.vars == [
        obj.LVar('a'),
        obj.LVar('b'),
    ]
Пример #3
0
def test_call1(compile_expr):
    frame = compile_expr('print(1)')

    assert frame.code == [ops.LoadConst(0), ops.LoadName(0), ops.Call()]
    assert frame.consts == [
        obj.LNumber(1.0),
    ]
    assert frame.vars == [obj.LVar('print')]
Пример #4
0
def test_ass1(compile_stmt):
    frame = compile_stmt('a = 1')

    assert frame.code == [
        ops.LoadConst(0),
        ops.LoadConst(1),
        ops.StoreName(),
    ]
    assert frame.consts == [
        obj.LVar('a'),
        obj.LNumber(1.0),
    ]
Пример #5
0
def test_call1(compile_stmt):
    frame = compile_stmt('print(1)')

    assert frame.code == [
        ops.LoadConst(0),
        ops.LoadConst(1),
        ops.Call(),
    ]
    assert frame.consts == [
        obj.LVar('print'),
        obj.LNumber(1.0),
    ]
Пример #6
0
def test_ass3(compile_stmt):
    frame = compile_stmt('a = 1 - 2')

    assert frame.code == [
        ops.LoadConst(0),
        ops.LoadConst(1),
        ops.BinarySubtract(),
        ops.StoreName(0),
    ]
    assert frame.consts == [
        obj.LNumber(1.0),
        obj.LNumber(2.0),
    ]
    assert frame.vars == [
        obj.LVar('a'),
    ]
Пример #7
0
def test_call2(compile_expr):
    frame = compile_expr('print(b)')

    assert frame.code == [ops.LoadName(0), ops.LoadName(1), ops.Call()]
    assert frame.vars == [obj.LVar('b'), obj.LVar('print')]
Пример #8
0
 def visit_identifier(self, node, vc):
     return obj.LVar(node.value)
Пример #9
0
def test_ass1(interp_stmt):
    frame = interp_stmt('a = 1')
    assert frame.env == {
        obj.LVar('a'): obj.LNumber(1.0),
    }