Exemplo n.º 1
0
def lazy_function(f):
    return thunk.fromvalue(
        FunctionType(
            LazyTransformer().visit(f.__code__),
            f.__globals__,
            f.__name__,
            tuple(map(thunk.fromvalue, f.__defaults__ or ())),
            f.__closure__,
        ), )
Exemplo n.º 2
0
def lazy_function(f):
    return thunk.fromvalue(
        FunctionType(
            LazyTransformer().visit(f.__code__),
            f.__globals__,
            f.__name__,
            tuple(map(thunk.fromvalue, f.__defaults__ or ())),
            f.__closure__,
        ),
    )
Exemplo n.º 3
0
 def __call__(self, f):
     return thunk.fromvalue(
         FunctionType(
             self.transform(Code.from_pycode(f.__code__)).to_pycode(),
             f.__globals__,
             f.__name__,
             tuple(map(thunk.fromvalue, f.__defaults__ or ())),
             f.__closure__,
         ),
     )
Exemplo n.º 4
0
 def __call__(self, f):
     return thunk.fromvalue(
         FunctionType(
             self.visit(f.__code__),
             f.__globals__,
             f.__name__,
             tuple(map(thunk.fromvalue, f.__defaults__ or ())),
             f.__closure__,
         ),
     )
Exemplo n.º 5
0
    def _build_set(self, instr):
        # TOS  v_0
        # ...
        # TOSn v_n

        yield instructions.BUILD_TUPLE(instr.arg).steal(instr)
        # TOS  (v_0, ..., v_n)

        yield instructions.LOAD_CONST(thunk.fromvalue(set))
        # TOS  thunk.fromvalue(set)
        # TOS1 (v_0, ..., v_n)

        yield instructions.ROT_TWO()
        # TOS  (v_0, ..., v_n)
        # TOS1 thunk.fromvalue(set)

        yield instructions.CALL_FUNCTION(1)
Exemplo n.º 6
0
 def visit_const(self, const):
     const = super().visit_const(const)
     if not isinstance(const, CodeType):
         const = thunk.fromvalue(const)
     return const
Exemplo n.º 7
0
 def visit_const(self, const):
     const = super().visit_const(const)
     if not isinstance(const, CodeType):
         const = thunk.fromvalue(const)
     return const
Exemplo n.º 8
0
 def transform_consts(self, consts):
     return tuple(
         const if isinstance(const, CodeType) else thunk.fromvalue(const)
         for const in super().transform_consts(consts)
     )
Exemplo n.º 9
0
 def visit_consts(self, consts):
     return tuple(
         const if isinstance(const, CodeType) else thunk.fromvalue(const)
         for const in super().visit_consts(consts)
     )