コード例 #1
0
    def render(self, gen):
        self.rendered = True
        gen.begin_class(self, self.super_class)

        for inter in self.interfaces:
            gen.implements(inter)

        for field, fielddef in self.fields.values():
            gen.add_field(field)

        # Emit the constructor:
        gen.begin_constructor()
        # set default values for fields
        for field, f_default in self.fields.values():
            if field.jtype is not jVoid:
                gen.load_jvm_var(self, 0) # load this ptr
                # load default value of field
                push_constant(gen.db, field.OOTYPE, f_default, gen)
                field.store(gen)           # store value into field
        gen.end_constructor()

        for method in self.methods.values():
            method.render(gen)

        for method in self.abstract_methods.values():
            gen.begin_j_function(self, method)
            gen.new_with_jtype(jPyPyAbstractMethodException)
            gen.throw()
            gen.end_function()
        
        gen.end_class()
コード例 #2
0
 def create_pointer(self, gen):
     if not self.value:
         TYPE = ootype.ROOT
         gen.push_null(TYPE)
     else:
         TYPE = self.value._TYPE
         push_constant(self.db, self.value._TYPE, self.value, gen)
     gen.create_weakref(TYPE)
コード例 #3
0
ファイル: constant.py プロジェクト: chyyuu/pygirl
 def create_pointer(self, gen):
     if not self.value:
         TYPE = ootype.ROOT
         gen.push_null(TYPE)
     else:
         TYPE = self.value._TYPE
         push_constant(self.db, self.value._TYPE, self.value, gen)
     gen.create_weakref(TYPE)
コード例 #4
0
ファイル: class_.py プロジェクト: griels/pypy-sc
    def render(self, ilasm):
        if self.is_root(self.INSTANCE):
            return

        self.ilasm = ilasm
        self.gen = CLIBaseGenerator(self.db, ilasm)

        if self.namespace:
            ilasm.begin_namespace(self.namespace)

        ilasm.begin_class(self.name,
                          self.get_base_class(),
                          abstract=self.is_abstract())
        for f_name, (f_type, f_default) in self.INSTANCE._fields.iteritems():
            cts_type = self.cts.lltype_to_cts(f_type)
            f_name = self.cts.escape_name(f_name)
            if cts_type != CTS.types.void:
                ilasm.field(f_name, cts_type)

        self._ctor()
        self._toString()

        for m_name, m_meth in self.INSTANCE._methods.iteritems():
            if hasattr(m_meth, 'graph'):
                # if the first argument's type is not a supertype of
                # this class it means that this method this method is
                # not really used by the class: don't render it, else
                # there would be a type mismatch.
                args = m_meth.graph.getargs()
                SELF = args[0].concretetype
                if not ootype.isSubclass(self.INSTANCE, SELF):
                    continue
                f = self.db.genoo.Function(self.db,
                                           m_meth.graph,
                                           m_name,
                                           is_method=True)
                f.render(ilasm)
            else:
                # abstract method
                METH = m_meth._TYPE
                arglist = [(self.cts.lltype_to_cts(ARG), 'v%d' % i)
                           for i, ARG in enumerate(METH.ARGS)
                           if ARG is not ootype.Void]
                returntype = self.cts.lltype_to_cts(METH.RESULT)
                ilasm.begin_function(m_name, arglist, returntype, False,
                                     'virtual')  #, 'abstract')
                ilasm.add_comment('abstract method')
                if isinstance(METH.RESULT, ootype.OOType):
                    ilasm.opcode('ldnull')
                else:
                    push_constant(self.db, METH.RESULT, 0, self.gen)
                ilasm.opcode('ret')
                ilasm.end_function()

        ilasm.end_class()

        if self.namespace:
            ilasm.end_namespace()
コード例 #5
0
ファイル: constant.py プロジェクト: TheDunn/flex-pypy
 def create_pointer(self, gen):
     gen.prepare_cast_ptr_to_weak_address()
     if not self.value:
         TYPE = ootype.ROOT
         gen.push_null(TYPE)
     else:
         TYPE = self.value._TYPE
         push_constant(self.db, self.value._TYPE, self.value, gen)
     gen.finalize_cast_ptr_to_weak_address(TYPE)
コード例 #6
0
ファイル: class_.py プロジェクト: Debug-Orz/Sypy
    def render(self, ilasm):        
        if self.is_root(self.INSTANCE):
            return

        self.ilasm = ilasm
        self.gen = CLIBaseGenerator(self.db, ilasm)

        if self.namespace:
            ilasm.begin_namespace(self.namespace)

        ilasm.begin_class(self.name, self.get_base_class(), abstract=self.is_abstract())
        for f_name, (f_type, f_default) in self.INSTANCE._fields.iteritems():
            cts_type = self.cts.lltype_to_cts(f_type)
            f_name = self.cts.escape_name(f_name)
            if cts_type != CTS.types.void:
                ilasm.field(f_name, cts_type)

        self._ctor()
        self._toString()

        for m_name, m_meth in self.INSTANCE._methods.iteritems():
            if hasattr(m_meth, 'graph'):
                # if the first argument's type is not a supertype of
                # this class it means that this method this method is
                # not really used by the class: don't render it, else
                # there would be a type mismatch.
                args =  m_meth.graph.getargs()
                SELF = args[0].concretetype
##                if not ootype.isSubclass(self.INSTANCE, SELF):
##                    continue
                f = self.db.genoo.Function(self.db, m_meth.graph, m_name, is_method = True)
                f.render(ilasm)
            else:
                # abstract method
                METH = m_meth._TYPE
                arglist = [(self.cts.lltype_to_cts(ARG), 'v%d' % i)
                           for i, ARG in enumerate(METH.ARGS)
                           if ARG is not ootype.Void]
                returntype = self.cts.lltype_to_cts(METH.RESULT)
                ilasm.begin_function(m_name, arglist, returntype, False, 'virtual') #, 'abstract')
                ilasm.add_comment('abstract method')
                if isinstance(METH.RESULT, ootype.OOType):
                    ilasm.opcode('ldnull')
                else:
                    push_constant(self.db, METH.RESULT, METH.RESULT._defl(), self.gen)
                ilasm.opcode('ret')
                ilasm.end_function()

        ilasm.end_class()

        if self.namespace:
            ilasm.end_namespace()
コード例 #7
0
ファイル: constant.py プロジェクト: chyyuu/pygirl
 def _check_for_void_dict(self, gen):
     KEYTYPE = self.value._TYPE._KEYTYPE
     keytype = self.cts.lltype_to_cts(KEYTYPE)
     keytype_T = self.cts.lltype_to_cts(self.value._TYPE.KEYTYPE_T)
     VALUETYPE = self.value._TYPE._VALUETYPE
     valuetype = self.cts.lltype_to_cts(VALUETYPE)
     valuetype_T = self.cts.lltype_to_cts(self.value._TYPE.VALUETYPE_T)
     if VALUETYPE is ootype.Void:
         gen.add_comment('  CLI Dictionary w/ void value')
         class_name = PYPY_DICT_OF_VOID % keytype
         for key in self.value._dict:
             gen.ilasm.opcode('dup')
             push_constant(self.db, KEYTYPE, key, gen)
             meth = 'void class %s::ll_set(%s)' % (class_name, keytype_T)
             gen.ilasm.call_method(meth, False)
         return True
     return False
コード例 #8
0
 def _check_for_void_dict(self, gen):
     KEYTYPE = self.value._TYPE._KEYTYPE
     keytype = self.cts.lltype_to_cts(KEYTYPE)
     keytype_T = self.cts.lltype_to_cts(self.value._TYPE.KEYTYPE_T)
     VALUETYPE = self.value._TYPE._VALUETYPE
     valuetype = self.cts.lltype_to_cts(VALUETYPE)
     valuetype_T = self.cts.lltype_to_cts(self.value._TYPE.VALUETYPE_T)
     if VALUETYPE is ootype.Void:
         gen.add_comment('  CLI Dictionary w/ void value')
         class_name = PYPY_DICT_OF_VOID % keytype
         for key in self.value._dict:
             gen.ilasm.opcode('dup')
             push_constant(self.db, KEYTYPE, key, gen)
             meth = 'void class %s::ll_set(%s)' % (class_name, keytype_T)
             gen.ilasm.call_method(meth, False)
         return True
     return False
コード例 #9
0
ファイル: class_.py プロジェクト: TheDunn/flex-pypy
    def _ctor(self):
        self.ilasm.begin_function('.ctor', [], 'void', False, 'specialname', 'rtspecialname', 'instance')
        self.ilasm.opcode('ldarg.0')
        self.ilasm.call('instance void %s::.ctor()' % self.get_base_class())
        # set default values for fields
        default_values = self.INSTANCE._fields.copy()
        default_values.update(self.INSTANCE._overridden_defaults)
        for f_name, (F_TYPE, f_default) in default_values.iteritems():
            INSTANCE_DEF, _ = self.INSTANCE._lookup_field(f_name)
            cts_type = self.cts.lltype_to_cts(F_TYPE)
            f_name = self.cts.escape_name(f_name)
            if cts_type != 'void':
                self.ilasm.opcode('ldarg.0')
                push_constant(self.db, F_TYPE, f_default, self.gen)
                class_name = self.db.class_name(INSTANCE_DEF)
                self.ilasm.set_field((cts_type, class_name, f_name))

        self.ilasm.opcode('ret')
        self.ilasm.end_function()
コード例 #10
0
ファイル: class_.py プロジェクト: xx312022850/pypy
    def _ctor(self):
        self.ilasm.begin_function('.ctor', [], 'void', False, 'specialname', 'rtspecialname', 'instance')
        self.ilasm.opcode('ldarg.0')
        self.ilasm.call('instance void %s::.ctor()' % self.get_base_class())
        # set default values for fields
        default_values = self.INSTANCE._fields.copy()
        default_values.update(self.INSTANCE._overridden_defaults)
        for f_name, (F_TYPE, f_default) in default_values.iteritems():
            if getattr(F_TYPE, '_is_value_type', False):
                continue # we can't set it to null
            INSTANCE_DEF, _ = self.INSTANCE._lookup_field(f_name)
            cts_type = self.cts.lltype_to_cts(F_TYPE)
            f_name = self.cts.escape_name(f_name)
            if cts_type != CTS.types.void:
                self.ilasm.opcode('ldarg.0')
                push_constant(self.db, F_TYPE, f_default, self.gen)
                class_name = self.db.class_name(INSTANCE_DEF)
                self.ilasm.set_field((cts_type, class_name, f_name))

        self.ilasm.opcode('ret')
        self.ilasm.end_function()
コード例 #11
0
ファイル: generator.py プロジェクト: njues/Sypy
    def load(self, value):
        if isinstance(value, flowmodel.Variable):
            jty, idx = self._var_data(value)
            return self.load_jvm_var(jty, idx)

        if isinstance(value, SubOperation):
            return render_sub_op(value, self.db, self)

        if isinstance(value, flowmodel.Constant):
            return push_constant(self.db, value.concretetype, value.value, self)
            
        raise Exception('Unexpected type for v in load(): '+
                        repr(value.concretetype) + " v=" + repr(value))
コード例 #12
0
ファイル: constant.py プロジェクト: chyyuu/pygirl
 def initialize_data(self, constgen, gen):
     if self.value is not None:
         push_constant(self.db, self.value._TYPE, self.value, gen)
         gen.ilasm.call_method('void %s::ll_set(object)' % self.get_type(),
                               True)
         return True
コード例 #13
0
 def initialize_data(self, constgen, gen):
     if self.value is not None:
         push_constant(self.db, self.value._TYPE, self.value, gen)
         gen.ilasm.call_method('void %s::ll_set(object)' % self.get_type(), True)
         return True
コード例 #14
0
ファイル: ilgenerator.py プロジェクト: njues/Sypy
 def load(self, v):
     if isinstance(v, flowmodel.Constant):
         push_constant(self.db, v.concretetype, v.value, self)
     else:
         assert False
コード例 #15
0
ファイル: ilgenerator.py プロジェクト: alkorzt/pypy
 def load(self, v):
     if isinstance(v, flowmodel.Constant):
         push_constant(self.db, v.concretetype, v.value, self)
     else:
         assert False