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),
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]),
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),
def _code_size(code: Atom) -> Tuple[int]: if not isinstance(code, CodeBlock): return 1, return code.size(),