Ejemplo n.º 1
0
def _code_combine(a: Atom, b: Atom) -> Tuple[CodeBlock]:
    if isinstance(a, CodeBlock) and isinstance(b, CodeBlock):
        return CodeBlock(b + a),
    elif isinstance(b, CodeBlock):
        return b.append(a),
    elif isinstance(a, CodeBlock):
        return a.append(b),
    else:
        return CodeBlock([a, b]),
Ejemplo n.º 2
0
def _code_map(state: PushState) -> PushState:
    if state["exec"].is_empty() or state["code"].is_empty():
        return Token.revert
    e = state["exec"].pop()
    c = state["code"].pop()
    if not isinstance(c, CodeBlock):
        c = CodeBlock([c])
    l1 = [CodeBlock([InstructionMeta(name="code_from_exec", code_blocks=1), item, e]) for item in c]
    l2 = [InstructionMeta(name="code_combine", code_blocks=0) for _ in c[1:]]
    contents = l1 + [InstructionMeta(name="code_wrap", code_blocks=0)] + l2
    state["exec"].push(CodeBlock(contents))
    return state
Ejemplo n.º 3
0
def _exec_do_times(state: PushState) -> PushState:
    if state["exec"].is_empty() or state["int"].is_empty():
        return Token.revert
    if state["int"].top() < 1:
        return Token.revert
    code = state["exec"].pop()
    times = state["int"].pop()
    state["exec"].push(
        CodeBlock(Literal(0), Literal(times - 1),
                  JitInstructionRef("exec_do_range"),
                  CodeBlock(
                      JitInstructionRef("int_pop"),
                      code,
                  )))
    return state
Ejemplo n.º 4
0
def _code_nth(code: Atom, ndx: int) -> Tuple[Atom]:
    if not isinstance(code, CodeBlock):
        code = CodeBlock([code])
    if len(code) == 0:
        return Token.revert
    ndx = abs(ndx) % len(code)
    return code[ndx],
Ejemplo n.º 5
0
def _code_insert(code1, code2, ndx) -> Union[Token, Tuple[Atom]]:
    if not isinstance(code1, CodeBlock):
        code1 = CodeBlock([code1])
    if code1.size() == 0:
        return code1.append(code2),
    ndx = abs(ndx) % code1.size()
    return code1.with_code_inserted_at_point(code2, ndx),
Ejemplo n.º 6
0
def _code_map(state: PushState) -> PushState:
    if state["exec"].is_empty() or state["code"].is_empty():
        return Token.revert
    e = state["exec"].pop()
    c = state["code"].pop()
    if not isinstance(c, CodeBlock):
        c = CodeBlock(c)
    else:
        c = c.copy()
    l1 = [
        CodeBlock(JitInstructionRef("code_from_exec"), item, e) for item in c
    ]
    l2 = [JitInstructionRef("code_combine") for _ in c[1:]]
    state["exec"].push(
        CodeBlock.from_list(l1 + [JitInstructionRef("code_wrap")] + l2))
    return state
Ejemplo n.º 7
0
def _deserialize_atoms(lst, instr_set: InstructionSet):
    type_lib = instr_set.type_library
    atoms = []
    for atom_spec in lst:
        atom = None
        if isinstance(atom_spec, list):
            atom = CodeBlock(_deserialize_atoms(atom_spec, instr_set))
        else:
            atom_type = atom_spec["a"]
            if atom_type == "close":
                atom = Closer()
            elif atom_type == "lit":
                push_type = type_lib[atom_spec["t"]]
                value = push_type.coerce(atom_spec["v"])
                atom = Literal(value=value, push_type=push_type)
            elif atom_type == "input":
                atom = Input(input_index=atom_spec["i"])
            elif atom_type == "instr":
                instr = instr_set[atom_spec["n"]]
                atom = InstructionMeta(name=instr.name,
                                       code_blocks=instr.code_blocks)
            else:
                raise ValueError("bad atom spec {s}".format(s=atom_spec))
        atoms.append(atom)
    return atoms
Ejemplo n.º 8
0
def _exec_do_times(state: PushState) -> Union[Token, PushState]:
    if state["exec"].is_empty() or state["int"].is_empty():
        return Token.revert
    if state["int"].top() < 1:
        return Token.revert
    code = state["exec"].pop()
    times = state["int"].pop()
    state["exec"].push(CodeBlock([
        Literal(value=0, push_type=PushInt),
        Literal(value=times - 1, push_type=PushInt),
        InstructionMeta(name="exec_do_range", code_blocks=1),
        CodeBlock([
            InstructionMeta(name="int_pop", code_blocks=0),
            code,
        ])
    ]))
    return state
Ejemplo n.º 9
0
def _exec_do_count(state: PushState) -> Union[Token, PushState]:
    if state["exec"].is_empty() or state["int"].is_empty():
        return Token.revert
    if state["int"].top() < 1:
        return Token.revert
    code = state["exec"].pop()
    count = state["int"].pop()
    state["exec"].push(
        CodeBlock(Literal(0), Literal(count - 1),
                  JitInstructionRef("exec_do_range"), code))
    return state
Ejemplo n.º 10
0
def _code_combine(a: Atom, b: Atom) -> Tuple[CodeBlock]:
    if isinstance(a, CodeBlock) and isinstance(b, CodeBlock):
        return CodeBlock.from_list(list(b.copy()) + list(a.copy())),
    elif isinstance(b, CodeBlock):
        result = b.copy()
        result.append(a)
        return result,
    elif isinstance(a, CodeBlock):
        result = a.copy()
        result.append(b)
        return result,
    else:
        return CodeBlock(a, b),
Ejemplo n.º 11
0
def genome_to_code(genome: Genome) -> CodeBlock:
    """Translate into nested CodeBlocks.

    These CodeBlocks can be considered the Push program representation of
    the Genome which can be executed by a PushInterpreter and evaluated
    by an Evaluator.

    """
    plushy_buffer = l()
    for atom in genome[::-1]:
        if isinstance(atom, InstructionMeta) and atom.code_blocks > 0:
            plushy_buffer = plushy_buffer.cons(Opener(count=atom.code_blocks))
        plushy_buffer = plushy_buffer.cons(atom)

    push_buffer = []
    while True:
        # If done with plush but unclosed opens, recur with one more close.
        if len(plushy_buffer) == 0 and _has_opener(push_buffer):
            plushy_buffer = plushy_buffer.cons(Closer())
        # If done with plush and all opens closed, return push.
        elif len(plushy_buffer) == 0:
            return CodeBlock(push_buffer)
        else:
            atom = plushy_buffer.first
            plushy_buffer = plushy_buffer.rest
            # If next instruction is a close, and there is an open.
            if isinstance(atom, Closer) and _has_opener(push_buffer):
                ndx, opener = [(ndx, el) for ndx, el in enumerate(push_buffer)
                               if isinstance(el, Opener)][-1]
                post_open = push_buffer[ndx + 1:]
                pre_open = push_buffer[:ndx]
                push_buffer = pre_open + [CodeBlock(post_open)]
                if opener.count > 1:
                    opener = opener.dec()
                    push_buffer.append(opener)
            # If next instruction is a close, and there is no open, ignore it.
            # If next instruction is not a close.
            elif not isinstance(atom, Closer):
                push_buffer.append(atom)
Ejemplo n.º 12
0
def _code_insert(code1, code2, ndx) -> Union[Token, Tuple[Atom]]:
    if isinstance(code1, CodeBlock):
        code1 = code1.copy(True)
    else:
        code1 = CodeBlock(code1)

    if isinstance(code2, CodeBlock):
        code2 = code2.copy(True)

    if code1.size() == 0:
        code1.append(code2)
        return code1,
    ndx = abs(ndx) % code1.size()
    return code1.insert_code_at_point(code2, ndx),
Ejemplo n.º 13
0
def _code_do_count(state: PushState) -> Union[Token, PushState]:
    if state["code"].is_empty() or state["int"].is_empty():
        return Token.revert
    if state["int"].top() < 1:
        return Token.revert
    code = state["code"].pop()
    count = state["int"].pop()
    state["exec"].push(CodeBlock([
        Literal(value=0, push_type=PushInt),
        Literal(value=count - 1, push_type=PushInt),
        InstructionMeta(name="code_from_exec", code_blocks=1),
        code,
        InstructionMeta(name="code_do_range", code_blocks=0)
    ]))
    return state
Ejemplo n.º 14
0
def _exec_do_range(state: PushState) -> Union[Token, PushState]:
    if state["exec"].is_empty() or len(state["int"]) < 2:
        return Token.revert
    to_do = state["exec"].pop()
    destination_ndx = state["int"].pop()
    current_ndx = state["int"].pop()

    increment = 0
    if current_ndx < destination_ndx:
        increment = 1
    elif current_ndx > destination_ndx:
        increment = -1

    if not increment == 0:
        state["exec"].push(
            CodeBlock(Literal(current_ndx + increment),
                      Literal(destination_ndx),
                      JitInstructionRef("exec_do_range"), to_do))
    state["int"].push(current_ndx)
    state["exec"].push(to_do)
    return state
Ejemplo n.º 15
0
def _exec_do_range(state: PushState) -> Union[Token, PushState]:
    if state["exec"].is_empty() or len(state["int"]) < 2:
        return Token.revert
    to_do = state["exec"].pop()
    destination_ndx = state["int"].pop()
    current_ndx = state["int"].pop()

    increment = 0
    if current_ndx < destination_ndx:
        increment = 1
    elif current_ndx > destination_ndx:
        increment = -1

    if not increment == 0:
        state["exec"].push(CodeBlock([
            Literal(value=current_ndx + increment, push_type=PushInt),
            Literal(value=destination_ndx, push_type=PushInt),
            InstructionMeta(name="exec_do_range", code_blocks=1),
            to_do
        ]))
    state["int"].push(current_ndx)
    state["exec"].push(to_do)
    return state
Ejemplo n.º 16
0
 def test_genome_bad_init(self, atoms):
     with pytest.raises(InvariantException):
         Genome([atoms["5"], CodeBlock([atoms["5"], atoms["add"]])])
Ejemplo n.º 17
0
import math
import sys

from pyshgp.push.atoms import Literal, CodeBlock, InstructionMeta
from pyshgp.push.types import Char, PushInt, PushStr, BoolVector, IntVector, FloatVector, CharVector, StrVector, \
    PushIntVector

# Shorthand
L = lambda v, t: Literal(value=v, push_type=t)
IM = lambda nm, cb: InstructionMeta(name=nm, code_blocks=cb)
CB = lambda *args: CodeBlock(list(args))

SPECS = [
    # COMMON
    {
        "instr": "bool_pop",
        "in": {"bool": [True, False]},
        "ex": {"bool": [True]}
    },
    {
        "instr": "int_dup",
        "in": {"int": [101]},
        "ex": {"int": [101, 101]}
    },
    {
        "instr": "float_dup_times",
        "in": {"int": [3], "float": [1.23]},
        "ex": {"int": [], "float": [1.23, 1.23, 1.23]}
    },
    {
        "instr": "bool_dup_times",
Ejemplo n.º 18
0
 def test_load_program(self, state: PushState, atoms):
     prog = CodeBlock([atoms["5"], atoms["5"], atoms["add"]])
     state.load_code(prog)
     assert state.size() == 1
     assert len(state["exec"].top()) == 3
Ejemplo n.º 19
0
def _wrap_code_block(*args):
    return CodeBlock(args),
Ejemplo n.º 20
0
def _code_but_last(x) -> Tuple[Atom]:
    if isinstance(x, CodeBlock) and len(x) > 1:
        return CodeBlock(x[:-1]),
    return Token.revert
Ejemplo n.º 21
0
def _code_reverse(code):
    if not isinstance(code, CodeBlock):
        return code,
    return CodeBlock(code[::-1]),
Ejemplo n.º 22
0
def instructions():
    """Return all core code SimpleInstructions."""
    i = []

    for push_type in ["bool", "int", "float", "str", "char", "exec"]:
        i.append(
            SimpleInstruction(
                "code_from_{t}".format(t=push_type),
                _make_code,
                input_types=[push_type],
                output_types=["code"],
                code_blocks=(1 if push_type == "exec" else 0),
                docstring="Moves the top {t} to the code stack.".format(
                    t=push_type)))

    i.append(
        SimpleInstruction(
            "noop",
            _revert,
            input_types=[],
            output_types=[],
            code_blocks=0,
            docstring="A noop SimpleInstruction which does nothing."))

    i.append(
        SimpleInstruction(
            "noop_open",
            _revert,
            input_types=[],
            output_types=[],
            code_blocks=1,
            docstring=
            "A noop SimpleInstruction which does nothing. Opens a code block.")
    )

    i.append(
        SimpleInstruction(
            "code_is_code_block",
            _is_code_block,
            input_types=["code"],
            output_types=["bool"],
            code_blocks=0,
            docstring=
            "Push True if top item on code stack is a CodeBlock. False otherwise."
        ))

    i.append(
        SimpleInstruction(
            "code_is_singular",
            _is_singular,
            input_types=["code"],
            output_types=["bool"],
            code_blocks=0,
            docstring=
            "Push True if top item on code stack is a not CodeBlock. False otherwise."
        ))

    i.append(
        SimpleInstruction(
            "code_length",
            _code_length,
            input_types=["code"],
            output_types=["int"],
            code_blocks=0,
            docstring=
            "If the top code item is a CodeBlock, pushes its length, otherwise pushes 1."
        ))

    i.append(
        SimpleInstruction(
            "code_first",
            _code_first,
            input_types=["code"],
            output_types=["code"],
            code_blocks=0,
            docstring=
            "If the top code item is a CodeBlock, pushes its first element."))

    i.append(
        SimpleInstruction(
            "code_last",
            _code_first,
            input_types=["code"],
            output_types=["code"],
            code_blocks=0,
            docstring=
            "If the top code item is a CodeBlock, pushes its last element."))

    i.append(
        SimpleInstruction(
            "code_rest",
            _code_rest,
            input_types=["code"],
            output_types=["code"],
            code_blocks=0,
            docstring=
            "If the top code item is a CodeBlock, pushes it to the code stack without its first element."
        ))

    i.append(
        SimpleInstruction(
            "code_but_last",
            _code_but_last,
            input_types=["code"],
            output_types=["code"],
            code_blocks=0,
            docstring=
            "If the top code item is a CodeBlock, pushes it to the code stack without its last element."
        ))

    i.append(
        SimpleInstruction(
            "code_wrap",
            lambda c: [CodeBlock(c)],
            input_types=["code"],
            output_types=["code"],
            code_blocks=0,
            docstring="Wraps the top item on the code stack in a CodeBlock."))

    i.append(
        SimpleInstruction(
            "code_list",
            lambda a, b: [CodeBlock(a, b)],
            input_types=["code", "code"],
            output_types=["code"],
            code_blocks=0,
            docstring=
            "Wraps the top two items on the code stack in a CodeBlock."))

    i.append(
        SimpleInstruction(
            "code_combine",
            _code_combine,
            input_types=["code", "code"],
            output_types=["code"],
            code_blocks=0,
            docstring=
            """Combines the top two items on the code stack in a CodeBlock.
        If one items is a CodeBlock, the other item is appended to it. If both
        items are CodeBlocks, they are concatenated together."""))

    i.append(
        SimpleInstruction(
            "code_do",
            lambda c: [c],
            input_types=["code"],
            output_types=["exec"],
            code_blocks=0,
            docstring=
            "Moves the top element of the code stack to the exec stack for execution."
        ))

    i.append(
        SimpleInstruction(
            "code_do_dup",
            lambda c: [c, c],
            input_types=["code"],
            output_types=["exec", "code"],
            code_blocks=0,
            docstring=
            "Copies the top element of the code stack to the exec stack for execution."
        ))

    i.append(
        StateToStateInstruction(
            "code_do_then_pop",
            _code_do_then_pop,
            types_used=["exec", "code"],
            code_blocks=0,
            docstring=
            """Pushes a `code_pop` JitInstructionRef and the top item of the
        code stack to the exec stack. Result is the top code item executing before
        it is removed from the code stack."""))

    i.append(
        StateToStateInstruction(
            "code_do_range",
            _code_do_range,
            types_used=["exec", "code", "int"],
            code_blocks=0,
            docstring=
            """Evaluates the top item on the code stack for each step along
        the range `i` to `j`. Both `i` and `j` are taken from the int stack."""
        ))

    i.append(
        StateToStateInstruction(
            "exec_do_range",
            _exec_do_range,
            types_used=["exec", "int"],
            code_blocks=1,
            docstring=
            """Evaluates the top item on the exec stack for each step along
        the range `i` to `j`. Both `i` and `j` are taken from the int stack.
        Differs from code_do_range only in the source of the code and the
        recursive call."""))

    i.append(
        StateToStateInstruction(
            "code_do_count",
            _code_do_count,
            types_used=["exec", "code", "int"],
            code_blocks=0,
            docstring=
            """Evaluates the top item on the code stack `n` times, where
        `n` comes from the `n` comes from the top of the int stack."""))

    i.append(
        StateToStateInstruction(
            "exec_do_count",
            _exec_do_count,
            types_used=["exec", "int"],
            code_blocks=1,
            docstring=
            """Evaluates the top item on the exec stack `n` times, where
        `n` comes from the `n` comes from the top of the int stack. Differs from
        code.do*count only in the source of the code and the recursive call."""
        ))

    i.append(
        StateToStateInstruction(
            "code_do_times",
            _code_do_times,
            types_used=["exec", "code", "int"],
            code_blocks=0,
            docstring=
            """Evaluates the top item on the code stack `n` times, where
        `n` comes from the `n` comes from the top of the int stack."""))

    i.append(
        StateToStateInstruction(
            "exec_do_times",
            _exec_do_times,
            types_used=["exec", "code", "int"],
            code_blocks=1,
            docstring=
            """Evaluates the top item on the code stack `n` times, where
        `n` comes from the `n` comes from the top of the int stack."""))

    i.append(
        StateToStateInstruction(
            "exec_while",
            _exec_while,
            types_used=["exec", "bool"],
            code_blocks=1,
            docstring=
            """Evaluates the top item on the exec stack repeated until the top
        bool is no longer True."""))

    i.append(
        StateToStateInstruction(
            "exec_do_while",
            _exec_do_while,
            types_used=["exec", "bool"],
            code_blocks=1,
            docstring=
            """Evaluates the top item on the exec stack repeated until the top
        bool is no longer True."""))

    i.append(
        StateToStateInstruction(
            "code_map",
            _code_map,
            types_used=["exec", "code"],
            code_blocks=0,
            docstring=
            """Evaluates the top item on the exec stack for each element of the top
        CodeBlock on the code stack. If the top code item is not a CodeBlock, it is wrapped
        into one."""))

    i.append(
        SimpleInstruction(
            "code_if",
            _if,
            input_types=["bool", "code", "code"],
            output_types=["exec"],
            code_blocks=0,
            docstring=
            """If the top boolean is true, execute the top element of the code
        stack and skip the second. Otherwise, skip the top element of the
        code stack and execute the second."""))

    i.append(
        SimpleInstruction(
            "exec_if",
            _if,
            input_types=["bool", "exec", "exec"],
            output_types=["exec"],
            code_blocks=2,
            docstring=
            """If the top boolean is true, execute the top element of the exec
        stack and skip the second. Otherwise, skip the top element of the
        exec stack and execute the second."""))

    i.append(
        StateToStateInstruction(
            "code_when",
            _code_when,
            types_used=["exec", "code"],
            code_blocks=0,
            docstring="""Evalutates the top code item if the top bool is True.
        Otherwise the top code is popped."""))

    i.append(
        StateToStateInstruction(
            "exec_when",
            _exec_when,
            types_used=["exec"],
            code_blocks=1,
            docstring=
            """Pops the next item on the exec stack without evaluating it
        if the top bool is False. Otherwise, has no effect."""))

    i.append(
        SimpleInstruction(
            "code_member",
            _code_member,
            input_types=["code", "code"],
            output_types=["bool"],
            code_blocks=0,
            docstring=
            """Pushes True if the second code item is a found within the top code item.
        If the top code item is not a CodeBlock, it is wrapped."""))

    i.append(
        SimpleInstruction(
            "code_nth",
            _code_nth,
            input_types=["code", "int"],
            output_types=["code"],
            code_blocks=0,
            docstring="""Pushes nth item of the top element on the code stack. If
        the top item is not a CodeBlock it is wrapped in a CodeBlock."""))

    i.append(
        SimpleInstruction(
            "make_empty_code_block",
            _make_empty_code_block,
            input_types=[],
            output_types=["code"],
            code_blocks=0,
            docstring="""Pushes an empty CodeBlock to the code stack."""))

    i.append(
        SimpleInstruction(
            "is_empty_code_block",
            _is_empty_code_block,
            input_types=["code"],
            output_types=["bool"],
            code_blocks=0,
            docstring=
            """Pushes true if top code item is an empty CodeBlock. Pushes
        false otherwise."""))

    i.append(
        SimpleInstruction(
            "code_size",
            _code_size,
            input_types=["code"],
            output_types=["int"],
            code_blocks=0,
            docstring=
            """Pushes the total size of the top item on the code stack. If
        the top item is a CodeBlock, this includes the size of all the CodeBlock's
        elements recusively."""))

    i.append(
        SimpleInstruction(
            "code_extract",
            _code_extract,
            input_types=["code", "int"],
            output_types=["code"],
            code_blocks=0,
            docstring=
            """Traverses the top code item depth first and returns the nth
        item based on the top int."""))

    i.append(
        SimpleInstruction(
            "code_insert",
            _code_insert,
            input_types=["code", "code", "int"],
            output_types=["code"],
            code_blocks=0,
            docstring="""Traverses the top code item depth first and inserts the
        second code item at position `n`. The value of `n` is the top int."""))

    # code_subst
    # code_contains
    # code_container

    i.append(
        SimpleInstruction(
            "code_first_position",
            _code_first_position,
            input_types=["code", "code"],
            output_types=["int"],
            code_blocks=0,
            docstring="""Pushes the first position of the second code item within
        the top code item. If not found, pushes -1. If the top code item is not
        a CodeBlock, this instruction returns 0 if the top two code elements are
        equal and -1 otherwise."""))

    i.append(
        SimpleInstruction(
            "code_reverse",
            _code_reverse,
            input_types=["code"],
            output_types=["code"],
            code_blocks=0,
            docstring="""Pushes the top code item reversed. No effect if top code
        item is not a CodeBlock."""))

    return i
Ejemplo n.º 23
0
def _make_empty_code_block() -> Tuple[Atom]:
    return CodeBlock(),
Ejemplo n.º 24
0
    def test_with_code_inserted_at_point(self):
        code_block = CodeBlock([
            CodeBlock([
                Literal(value="A", push_type=PushStr),
                Literal(value="B", push_type=PushStr)
            ]),
            Literal(value="C", push_type=PushStr)
        ])
        code = Literal(value="Z", push_type=PushStr)

        assert code_block.with_code_inserted_at_point(code, 0) == CodeBlock([
            code,
            CodeBlock([
                Literal(value="A", push_type=PushStr),
                Literal(value="B", push_type=PushStr)
            ]),
            Literal(value="C", push_type=PushStr)
        ])

        assert code_block.with_code_inserted_at_point(code, 1) == CodeBlock([
            CodeBlock([
                code,
                Literal(value="A", push_type=PushStr),
                Literal(value="B", push_type=PushStr)
            ]),
            Literal(value="C", push_type=PushStr)
        ])

        assert code_block.with_code_inserted_at_point(code, 2) == CodeBlock([
            CodeBlock([
                Literal(value="A", push_type=PushStr), code,
                Literal(value="B", push_type=PushStr)
            ]),
            Literal(value="C", push_type=PushStr)
        ])

        assert code_block.with_code_inserted_at_point(code, 3) == CodeBlock([
            CodeBlock([
                Literal(value="A", push_type=PushStr),
                Literal(value="B", push_type=PushStr), code
            ]),
            Literal(value="C", push_type=PushStr)
        ])

        assert code_block.with_code_inserted_at_point(code, 4) == CodeBlock([
            CodeBlock([
                Literal(value="A", push_type=PushStr),
                Literal(value="B", push_type=PushStr)
            ]), code,
            Literal(value="C", push_type=PushStr)
        ])

        assert code_block.with_code_inserted_at_point(code, 5) == CodeBlock([
            CodeBlock([
                Literal(value="A", push_type=PushStr),
                Literal(value="B", push_type=PushStr)
            ]),
            Literal(value="C", push_type=PushStr), code
        ])

        assert code_block.with_code_inserted_at_point(code, 100) == CodeBlock([
            CodeBlock([
                Literal(value="A", push_type=PushStr),
                Literal(value="B", push_type=PushStr)
            ]),
            Literal(value="C", push_type=PushStr), code
        ])
Ejemplo n.º 25
0
def _code_member(code: Atom, item: Atom) -> Tuple[bool]:
    if not isinstance(code, CodeBlock):
        code = CodeBlock([code])
    return item in code,
Ejemplo n.º 26
0
def load_code(name, interpreter) -> CodeBlock:
    with open("tests/resources/programs/" + name + ".json") as f:
        atoms = _deserialize_atoms(json.load(f), interpreter.instruction_set)
        return CodeBlock(atoms)