示例#1
0
def disassemble(code: str, scope: Scope = None, arg_dict: dict = None):
    """
    Disassembles asynchronous code into dis.dis-style bytecode instructions.
    """

    # Similar to AsyncCodeExecutor.__init__
    arg_names = list(arg_dict.keys()) if arg_dict else []

    scope = scope or Scope()

    wrapped = wrap_code(code, args=', '.join(arg_names))
    exec(compile(wrapped, '<repl>', 'exec'), scope.globals, scope.locals)

    func_def = scope.locals.get(
        '_repl_coroutine') or scope.globals['_repl_coroutine']

    co = func_def.__code__

    for instruction in dis._get_instructions_bytes(
            co.co_code,
            co.co_varnames,
            co.co_names,
            co.co_consts,
            co.co_cellvars + co.co_freevars,
            dict(dis.findlinestarts(co)),
            line_offset=0):
        if instruction.starts_line is not None and instruction.offset > 0:
            yield ''

        yield instruction._disassemble(4, False, 4)
def disassemble(code: str, scope: Scope = None, arg_dict: dict = None):
    """
    Disassembles asynchronous code into dis.dis-style bytecode instructions.
    """

    # Similar to AsyncCodeExecutor.__init__
    arg_names = list(arg_dict.keys()) if arg_dict else []

    scope = scope or Scope()

    wrapped = wrap_code(code, args=", ".join(arg_names))
    exec(
        compile(wrapped, "<repl>", "exec"), scope.globals, scope.locals
    )  # pylint: disable=exec-used

    func_def = scope.locals.get("_repl_coroutine") or scope.globals["_repl_coroutine"]

    # pylint is gonna really hate this part onwards
    # pylint: disable=protected-access, invalid-name
    co = func_def.__code__

    for instruction in dis._get_instructions_bytes(
        co.co_code,
        co.co_varnames,
        co.co_names,
        co.co_consts,
        co.co_cellvars + co.co_freevars,
        dict(dis.findlinestarts(co)),
        line_offset=0,
    ):
        if instruction.starts_line is not None and instruction.offset > 0:
            yield ""

        yield instruction._disassemble(4, False, 4)
示例#3
0
    def __init__(self, code: str, scope: Scope = None, arg_dict: dict = None, loop: asyncio.BaseEventLoop = None):
        self.args = []
        self.arg_names = []

        if arg_dict:
            for key, value in arg_dict.items():
                self.arg_names.append(key)
                self.args.append(value)

        self.code = wrap_code(code, args=', '.join(self.arg_names))
        self.scope = scope or Scope()
        self.loop = loop or asyncio.get_event_loop()
示例#4
0
文件: Dev.py 项目: Daggy1234/Elli0t
 def __init__(self, bot):
     self.bot = bot
     self.last_result = None
     self._scope = Scope()
     self.task_count: int = 0
     self.tasks = collections.deque()