codemach/machine.py
def build_class(self, callable_, args):
        """
        Implement ``builtins.__build_class__``.
        We must wrap all class member functions using :py:func:`function_wrapper`.
        This requires using a :py:class:`Machine` to execute the class source code
        and then recreating the class source code using an :py:class:`Assembler`.

        .. note: We might be able to bypass the call to ``builtins.__build_class__``
           entirely and manually construct a class object.

           https://github.com/python/cpython/blob/master/Python/bltinmodule.c
        """
        self._print('build_class')
        self._print(callable_)
        self._print('args=',args)
        
        if isinstance(args[0], FunctionType):
            c = args[0].get_code()
        else:
            c = args[0].__closure__[0].cell_contents.__code__
        
        # execute the original class source code
        print('execute original class source code')
        machine = MachineClassSource(c, self.verbose)
        l = dict()
        machine.execute(self.globals_, l)

        # construct new code for class source
        a = Assembler()
        for name, value in l.items():
            a.load_const(value)
            a.store_name(name)
        a.load_const(None)
        a.return_value()
       
        print('new code for class source')
        dis.dis(a.code())

        #machine = Machine(self.verbose)

        f = types.FunctionType(a.code(), self.globals_, args[1])

        args = (f, *args[1:])

        self.call_callbacks('CALL_FUNCTION', callable_, *args)
                 
        return callable_(*args)
def build_class(self, callable_, args):
        """
        Implement ``builtins.__build_class__``.
        We must wrap all class member functions using :py:func:`function_wrapper`.
        This requires using a :py:class:`Machine` to execute the class source code
        and then recreating the class source code using an :py:class:`Assembler`.

        .. note: We might be able to bypass the call to ``builtins.__build_class__``
           entirely and manually construct a class object.

           https://github.com/python/cpython/blob/master/Python/bltinmodule.c
        """
        self._print('build_class')
        self._print(callable_)
        self._print('args=',args)
        
        if isinstance(args[0], FunctionType):
            c = args[0].get_code()
        else:
            c = args[0].__closure__[0].cell_contents.__code__
        
        # execute the original class source code
        print('execute original class source code')
        machine = MachineClassSource(c, self.verbose)
        l = dict()
        machine.execute(self.globals_, l)

        # construct new code for class source
        a = Assembler()
        for name, value in l.items():
            a.load_const(value)
            a.store_name(name)
        a.load_const(None)
        a.return_value()
       
        print('new code for class source')
        dis.dis(a.code())

        #machine = Machine(self.verbose)

        f = types.FunctionType(a.code(), self.globals_, args[1])

        args = (f, *args[1:])

        self.call_callbacks('CALL_FUNCTION', callable_, *args)
                 
        return callable_(*args)
def build_class ( self , callable_ , args ) : self . _print ( 'build_class' ) self . _print ( callable_ ) self . _print ( 'args=' , args ) if isinstance ( args [ 0 ] , FunctionType ) : c = args [ 0 ] . get_code ( ) else : c = args [ 0 ] . __closure__ [ 0 ] . cell_contents . __code__ # execute the original class source code print ( 'execute original class source code' ) machine = MachineClassSource ( c , self . verbose ) l = dict ( ) machine . execute ( self . globals_ , l ) # construct new code for class source a = Assembler ( ) for name , value in l . items ( ) : a . load_const ( value ) a . store_name ( name ) a . load_const ( None ) a . return_value ( ) print ( 'new code for class source' ) dis . dis ( a . code ( ) ) #machine = Machine(self.verbose) f = types . FunctionType ( a . code ( ) , self . globals_ , args [ 1 ] ) args = ( f , * args [ 1 : ] ) self . call_callbacks ( 'CALL_FUNCTION' , callable_ , * args ) return callable_ ( * args )
Implement ``builtins.__build_class__``.
        We must wrap all class member functions using :py:func:`function_wrapper`.
        This requires using a :py:class:`Machine` to execute the class source code
        and then recreating the class source code using an :py:class:`Assembler`.

        .. note: We might be able to bypass the call to ``builtins.__build_class__``
           entirely and manually construct a class object.

           https://github.com/python/cpython/blob/master/Python/bltinmodule.c
Implement builtins . __build_class__ . We must wrap all class member functions using : py : func : function_wrapper . This requires using a : py : class : Machine to execute the class source code and then recreating the class source code using an : py : class : Assembler .