Beispiel #1
0
def test_BasicLoop():
    # Run the VMtranslator
    VMtranslator('test/BasicLoop.vm').run()

    # Load the resulting asm file into the HackExecutor
    asmp = AsmParser('test/BasicLoop.asm')
    hack = HackExecutor(asmp.run())

    # Manual setup for this test
    hack.ram[int(asmp.symbol_table['LCL'])] = 300
    hack.ram[int(asmp.symbol_table['ARG'])] = 400
    hack.ram[400] = 10

    # Simulate program to the end
    while True:
        if hack.step().type == CT.END:
            break

    assert hack.ram[256] == 55
Beispiel #2
0
def test_SimpleNeg():
    # Run the VMtranslator
    VMtranslator('test/SimpleNeg.vm').run()
    # Load the resulting asm file into the HackExecutor
    hack = HackExecutor(AsmParser('test/SimpleNeg.asm').run())
    # Simulate program to the end
    while True:
        if hack.step().type == CT.END:
            break

    assert hack.ram[256] == -8
Beispiel #3
0
def test_FibonacciElement():
    # Run the VMtranslator
    VMtranslator('test/FibonacciElement').run()
    # Load the resulting asm file into the HackExecutor
    hack = HackExecutor(AsmParser('test/FibonacciElement.asm').run())
    # Simulate program to the end
    while True:
        if hack.step().type == CT.END:
            break
    assert hack.ram[0] == 257
    assert hack.ram[256] == 21
Beispiel #4
0
def test_SimpleAdd():
    # Run the VMtranslator
    VMtranslator('test/SimpleAdd.vm').run()
    # Load the resulting asm file into the HackExecutor
    hack = HackExecutor(AsmParser('test/SimpleAdd.asm').run())
    # Simulate program to the end
    while True:
        if hack.step().type == CT.END:
            break

    # Should wind up with 15 on the top of the stack
    assert hack.ram[256] == 15
Beispiel #5
0
def test_StaticsTest():
    # Run the VMtranslator
    VMtranslator('test/StaticsTest').run()
    # Load the resulting asm file into the HackExecutor
    hack = HackExecutor(AsmParser('test/StaticsTest.asm').run())
    # Simulate program to the end
    while True:
        if hack.step().type == CT.END:
            break

    assert hack.ram[0] == 258
    assert hack.ram[256] == -2
    assert hack.ram[257] == 8
def test_PointerTest():
    # Run the VMtranslator
    VMtranslator('test/PointerTest.vm').run()
    # Load the resulting asm file into the HackExecutor
    hack = HackExecutor(AsmParser('test/PointerTest.asm').run())
    # Simulate program to the end
    while True:
        if hack.step().type == CT.END:
            break

    assert hack.ram[256] == 6084
    assert hack.ram[3] == 3030
    assert hack.ram[4] == 3040
    assert hack.ram[3032] == 32
    assert hack.ram[3046] == 46
Beispiel #7
0
def test_NestedCall():
    # Run the VMtranslator
    VMtranslator('test/NestedCall').run()
    # Load the resulting asm file into the HackExecutor
    hack = HackExecutor(AsmParser('test/NestedCall.asm').run())
    # Simulate program to the end
    while True:
        if hack.step().type == CT.END:
            break

    assert hack.ram[0] == 256
    assert hack.ram[3] == 4000
    assert hack.ram[4] == 5000
    assert hack.ram[5] == 135
    assert hack.ram[6] == 246
Beispiel #8
0
def test_FibonacciSeries():
    # Run the VMtranslator
    VMtranslator('test/FibonacciSeries.vm').run()

    # Load the resulting asm file into the HackExecutor
    asmp = AsmParser('test/FibonacciSeries.asm')
    hack = HackExecutor(asmp.run())

    # Manual setup for this test
    hack.ram[int(asmp.symbol_table['ARG'])] = 400
    hack.ram[400] = 6  # 6 elements of the fibonacci series
    hack.ram[401] = 3000  # Starting at address 3000

    # Simulate program to the end
    while True:
        if hack.step().type == CT.END:
            break

    assert hack.ram[3000] == 0
    assert hack.ram[3001] == 1
    assert hack.ram[3002] == 1
    assert hack.ram[3003] == 2
    assert hack.ram[3004] == 3
    assert hack.ram[3005] == 5
Beispiel #9
0
def test_SimpleLt():
    # Run the VMtranslator
    VMtranslator('test/SimpleLt.vm').run()
    # Load the resulting asm file into the HackExecutor
    hack = HackExecutor(AsmParser('test/SimpleLt.asm').run())
    # Force set the top of the stack to != -1/0, so that we to confirm memory is being set by arithmetic command
    for i in [256, 257, 258]:
        hack.ram[i] = 1
    # Simulate program to the end
    while True:
        if hack.step().type == CT.END:
            break

    assert hack.ram[256] == -1
    assert hack.ram[257] == 0
    assert hack.ram[258] == 0
def test_BasicTest():
    # Run the VMtranslator
    VMtranslator('test/BasicTest.vm').run()
    # Load the resulting asm file into the HackExecutor
    hack = HackExecutor(AsmParser('test/BasicTest.asm').run())
    # Initialize LCL, ARG, THIS, and THAT to testing values
    hack.ram[1] = 300
    hack.ram[2] = 400
    hack.ram[3] = 3000
    hack.ram[4] = 3010
    # Simulate program to the end
    while True:
        if hack.step().type == CT.END:
            break
    assert hack.ram[11] == 510
    assert hack.ram[3015] == 45
    assert hack.ram[3012] == 42
    assert hack.ram[3006] == 36
    assert hack.ram[402] == 22
    assert hack.ram[401] == 21
    assert hack.ram[300] == 10
    assert hack.ram[256] == 472
    assert hack.ram[3000] == 8
    assert hack.ram[3010] == 7