示例#1
0
def _code_extract(code: Atom, ndx: int) -> Union[Token, Tuple[Atom]]:
    if isinstance(code, CodeBlock) and code.size() == 0:
        return Token.revert
    if not isinstance(code, CodeBlock):
        return code,
    ndx = abs(ndx % code.size())
    return code.code_at_point(ndx),
示例#2
0
文件: code.py 项目: erp12/Pysh
def _code_extract(code: Atom, ndx: int) -> Union[Token, Tuple[Atom]]:
    if isinstance(code, CodeBlock) and code.size() == 0:
        return Token.revert
    if not isinstance(code, CodeBlock):
        return code,
    ndx = abs(ndx % code.size())
    return code.code_at_point(ndx),
示例#3
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]),
示例#4
0
文件: code.py 项目: erp12/Pysh
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),
示例#5
0
文件: code.py 项目: bmetevier/pyshgp
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),
示例#6
0
def _code_size(code: Atom) -> Tuple[int]:
    if not isinstance(code, CodeBlock):
        return 1,
    return code.size(),
示例#7
0
文件: code.py 项目: erp12/Pysh
def _code_size(code: Atom) -> Tuple[int]:
    if not isinstance(code, CodeBlock):
        return 1,
    return code.size(),