Exemple #1
0
def test_vm_math():
    code = [
        *create_instr("load", 0, 3, 232),
        *create_instr("load", 1, 1, 244),
        *create_instr("add", 0, 1, 2),
        *create_instr("sub", 2, 1, 3),
        *create_instr("mul", 1, 2, 4),
        *create_instr("truediv", 2, 3, 5),
    ]

    vm = Arkhe(code)
    vm.eval()
    assert (vm.registers[0] == 1000 and vm.registers[1] == 500
            and vm.registers[2] == 1500 and vm.registers[3] == 1000
            and vm.registers[4] == 750_000 and vm.registers[5] == 1.5)
Exemple #2
0
def test_vm_load_multiple():
    code = [*create_instr("load", 0, 3, 232), *create_instr("load", 1, 1, 244)]

    vm = Arkhe(code)
    vm.eval()
    assert vm.registers[0] == 1000 and vm.registers[1] == 500
Exemple #3
0
def test_vm_load():
    code = create_instr("load", 0, 0, 100)
    vm = Arkhe(code)
    vm.eval()
    assert vm.registers[0] == 100