Example #1
0
def test_instructions(core_type_lib):
    for spec in SPECS:
        in_state = PushState.from_dict(spec["in"], core_type_lib)
        ex_state = PushState.from_dict(spec["ex"], core_type_lib)
        DEFAULT_INTERPRETER.state = in_state
        print(spec["instr"], in_state, ex_state)
        DEFAULT_INTERPRETER.evaluate_atom(spec["instr"])
        ac_state = DEFAULT_INTERPRETER.state
        # ac_state.pretty_print()
        # print("---")
        # ex_state.pretty_print()
        # print()
        # print()
        assert ex_state == ac_state
Example #2
0
def test_instructions():
    for spec in SPECS:
        in_state = PushState.from_dict(spec["in"])
        ex_state = PushState.from_dict(spec["ex"])
        DEFAULT_INTERPRETER.state = in_state
        print(spec["instr"], in_state, ex_state)
        DEFAULT_INTERPRETER.evaluate_atom(spec["instr"])
        ac_state = DEFAULT_INTERPRETER.state
        # ac_state.pretty_print()
        # print("---")
        # ex_state.pretty_print()
        # print()
        # print()
        assert ex_state == ac_state
Example #3
0
def test_input_instructions():
    in_state = PushState.from_dict({"inputs": [7, "x"], "exec": []})
    ex_state = PushState.from_dict({"inputs": [7, "x"], "exec": [Literal(7)]})
    DEFAULT_INTERPRETER.state = in_state
    DEFAULT_INTERPRETER.evaluate_atom(make_input_instruction(0))
    ac_state = DEFAULT_INTERPRETER.state
    assert ex_state == ac_state
    assert len(in_state.inputs) == 2

    in_state = PushState.from_dict({"inputs": [7, "x"], "exec": []})
    ex_state = PushState.from_dict({"inputs": [7, "x"], "exec": [Literal("x")]})
    DEFAULT_INTERPRETER.state = in_state
    DEFAULT_INTERPRETER.evaluate_atom(make_input_instruction(1))
    ac_state = DEFAULT_INTERPRETER.state
    assert ex_state == ac_state
    assert len(in_state.inputs) == 2
Example #4
0
def test_input_instructions(core_type_lib):
    in_state = PushState.from_dict({"inputs": [7, "x"], "int": []}, core_type_lib)
    ex_state = PushState.from_dict({"inputs": [7, "x"], "int": [7]}, core_type_lib)
    DEFAULT_INTERPRETER.state = in_state
    DEFAULT_INTERPRETER.evaluate_atom(make_input_instruction(0))
    ac_state = DEFAULT_INTERPRETER.state
    assert ex_state == ac_state
    assert len(in_state.inputs) == 2

    in_state = PushState.from_dict({"inputs": [7, "x"], "str": []}, core_type_lib)
    ex_state = PushState.from_dict({"inputs": [7, "x"], "str": ["x"]}, core_type_lib)
    DEFAULT_INTERPRETER.state = in_state
    DEFAULT_INTERPRETER.evaluate_atom(make_input_instruction(1))
    ac_state = DEFAULT_INTERPRETER.state
    assert ex_state == ac_state
    assert len(in_state.inputs) == 2
Example #5
0
def test_instructions(core_type_lib, push_config):
    iset = DEFAULT_INTERPRETER.instruction_set
    for spec in SPECS:
        in_state = PushState.from_dict(spec["in"], core_type_lib, push_config)
        ex_state = PushState.from_dict(spec["ex"], core_type_lib, push_config)
        DEFAULT_INTERPRETER.state = in_state
        instruction_name = spec["instr"]
        print(instruction_name, in_state, ex_state)
        DEFAULT_INTERPRETER.evaluate_atom(iset[instruction_name].meta(), push_config)
        ac_state = DEFAULT_INTERPRETER.state
        # ac_state.pretty_print()
        # print("---")
        # ex_state.pretty_print()
        # print()
        # print()
        assert ex_state == ac_state
Example #6
0
def test_inputs(core_type_lib, push_config):
    in_state = PushState.from_dict({"inputs": [7, "x"], "int": []}, core_type_lib, push_config)
    ex_state = PushState.from_dict({"inputs": [7, "x"], "int": [7]}, core_type_lib, push_config)
    DEFAULT_INTERPRETER.state = in_state
    DEFAULT_INTERPRETER.evaluate_atom(Input(input_index=0), push_config)
    ac_state = DEFAULT_INTERPRETER.state
    assert ex_state == ac_state
    assert len(in_state.inputs) == 2

    in_state = PushState.from_dict({"inputs": [7, "x"], "str": []}, core_type_lib, push_config)
    ex_state = PushState.from_dict({"inputs": [7, "x"], "str": ["x"]}, core_type_lib, push_config)
    DEFAULT_INTERPRETER.state = in_state
    DEFAULT_INTERPRETER.evaluate_atom(Input(input_index=1), push_config)
    ac_state = DEFAULT_INTERPRETER.state
    assert ex_state == ac_state
    assert len(in_state.inputs) == 2
Example #7
0
 def test_from_dict(self, atoms, core_type_lib):
     d = {
         "int": [0, 1],
         "stdout": "Hello Push!",
         "exec": [atoms["add"]]
     }
     state = PushState.from_dict(d, core_type_lib)
     assert state.size() == 3
     assert state["int"].top() == 1
Example #8
0
def test_inputs(core_type_lib, push_config):
    interp = PushInterpreter()

    in_state = PushState.from_dict({"inputs": [7, "x"], "int": []}, core_type_lib, push_config)
    ex_state = PushState.from_dict({"inputs": [7, "x"], "int": [7]}, core_type_lib, push_config)
    interp.state = in_state
    interp.evaluate_atom(Input(input_index=0), push_config)
    ac_state = interp.state
    assert ex_state == ac_state
    assert len(in_state.inputs) == 2

    in_state = PushState.from_dict({"inputs": [7, "x"], "str": []}, core_type_lib, push_config)
    ex_state = PushState.from_dict({"inputs": [7, "x"], "str": ["x"]}, core_type_lib, push_config)
    interp.state = in_state
    interp.evaluate_atom(Input(input_index=1), push_config)
    ac_state = interp.state
    assert ex_state == ac_state
    assert len(in_state.inputs) == 2
Example #9
0
def test_instructions(core_type_lib, push_config):
    debug = False
    interp = PushInterpreter()
    iset = interp.instruction_set
    for spec in SPECS:
        in_state = PushState.from_dict(spec["in"], core_type_lib, push_config)
        ex_state = PushState.from_dict(spec["ex"], core_type_lib, push_config)
        interp.state = in_state
        instruction_name = spec["instr"]
        if debug:
            print(instruction_name,)
            in_state.pretty_print()
            print("---")
            ex_state.pretty_print()
            print("---")
        interp.evaluate_atom(iset[instruction_name].meta(), push_config)
        ac_state = interp.state
        if debug:
            ac_state.pretty_print()
            print()
        assert ex_state == ac_state
Example #10
0
 def test_from_dict(self, atoms):
     d = {"int": [0, 1], "stdout": "Hello Push!", "exec": [atoms["add"]]}
     state = PushState.from_dict(d)
     assert state.size() == 3
     assert state["int"].top() == 1
Example #11
0
 def test_from_dict(self, atoms, core_type_lib, push_config):
     d = {"int": [0, 1], "stdout": "Hello Push!", "exec": [atoms["add"]]}
     state = PushState.from_dict(d, core_type_lib, push_config)
     assert state.size() == 3
     assert state["int"].top() == 1