Exemple #1
0
def test_skip_operation():
    start_ast = [
        parser.AssignOp("inbox", "emp"),
        parser.JumpOp("label"),
        parser.OutboxOp(),
        parser.LabelStmt("label"),
        parser.AddOp("tmp")
    ]
    expected_ast = [
        parser.AssignOp("inbox", "emp"),
        parser.JumpOp("label"),
        parser.LabelStmt("label"),
        parser.AddOp("tmp")
    ]

    ast = remove_unreachable_code(start_ast)
    assert ast == expected_ast
Exemple #2
0
def test_jcond_no_jump_in_false():
    start_ast = [
        parser.AssignOp("inbox", "emp"),
        parser.JumpCondOp(condition="ez", label_name="truebranch"),
        parser.OutboxOp(),
        parser.LabelStmt("truebranch"),
        parser.AddOp("tmp")
    ]

    ast = remove_unreachable_code(start_ast)
    assert ast == start_ast
def test_add_addressed_tilealias():
    code = [
        parser.AliasStmt(tile_no="3", symbolic_name="myTile"),
        parser.AssignOp("inbox", "emp"),
        parser.AssignOp("emp", "myTile"),
        parser.AddOp(parser.AddressOf("myTile"))
    ]
    assert get_assembly(code) == [
        {"operation": "inbox"},
        {"operation": "copyto", "operand": {"Cell": 3}},
        {"operation": "add", "operand": {"Address": 3}}
    ]
def test_add_undefined_addressOfAlias():
    code = [parser.AddOp(parser.AddressOf("myTile"))]
    with pytest.raises(ValueError):
        get_assembly(code)
def test_add_addressed_tilenumber():
    code = [parser.AddOp(parser.AddressOf("3"))]
    assert get_assembly(code) == [{"operation": "add", "operand": {"Address": 3}}]
def test_add_tilenumber():
    code = [parser.AddOp("3")]
    assert get_assembly(code) == [{"operation": "add", "operand": {"Cell": 3}}]