示例#1
0
 def record_const(self, value, type_ = None, retval='name'):
     if type_ is None:
         type_ = typeOf(value)
     if self.is_primitive(type_):
         return None
     const = AbstractConst.make(self, value)
     if not const:
         return None
     try:
         if retval == 'name':
             return self.consts[const]
         else:
             self.consts[const]
             return self.reverse_consts[self.consts[const]]
     except KeyError:
         if self.genoo.config.translation.verbose:
             log("New const:%r"%value)
             if isinstance(value, ootype._string):
                 log(value._str)
         else:
             log.dot()
         name = const.get_name()
         if name in self.const_names:
             name += '__%d' % len(self.consts)
         self.consts[const] = name
         self.reverse_consts[name] = const
         self.const_names.add(name)
         self.pending_consts.append((const,name))
     if retval == 'name':
         return name
     else:
         return const
示例#2
0
文件: database.py 项目: chyyuu/pygirl
 def record_const(self, value, type_=None, retval='name'):
     if type_ is None:
         type_ = typeOf(value)
     if self.is_primitive(type_):
         return None
     const = AbstractConst.make(self, value)
     if not const:
         return None
     try:
         if retval == 'name':
             return self.consts[const]
         else:
             self.consts[const]
             return self.reverse_consts[self.consts[const]]
     except KeyError:
         if self.genoo.config.translation.verbose:
             log("New const:%r" % value)
             if isinstance(value, ootype._string):
                 log(value._str)
         else:
             log.dot()
         name = const.get_name()
         if name in self.const_names:
             name += '__%d' % len(self.consts)
         self.consts[const] = name
         self.reverse_consts[name] = const
         self.const_names.add(name)
         self.pending_consts.append((const, name))
     if retval == 'name':
         return name
     else:
         return const
示例#3
0
文件: database.py 项目: chyyuu/pygirl
    def gen_constants(self, ilasm, pending):
        try:
            while True:
                const, name = self.pending_consts.pop()
                const.record_fields()
        except IndexError:
            pass

        if pending:
            return

        if not self.rendered:
            ilasm.begin_consts(self.const_var.name)

        def generate_constants(consts):
            all_c = [const for const, name in consts.iteritems()]
            dep_ok = set()
            while len(all_c) > 0:
                const = all_c.pop()
                if const not in self.rendered:
                    to_render = True
                    if hasattr(const, 'depends_on') and const.depends_on:
                        for i in const.depends_on:
                            if i not in self.rendered and i not in dep_ok:
                                assert i.depends is None or const in i.depends
                                to_render = False
                                continue

                    if to_render and (not hasattr(const, 'depends')) or (
                            not const.depends) or const in dep_ok:
                        yield const, consts[const]
                        self.rendered.add(const)
                    else:
                        all_c.append(const)
                        for i in const.depends:
                            all_c.append(i)
                        dep_ok.add(const)

        # We need to keep track of fields to make sure
        # our items appear earlier than us
        to_init = []
        for const, name in generate_constants(self.consts):
            if self.genoo.config.translation.verbose:
                log("Recording %r %r" % (const, name))
            else:
                log.dot()
            ilasm.load_local(self.const_var)
            const.init(ilasm)
            ilasm.set_field(None, name)
            ilasm.store_void()
            to_init.append((const, name))
            #ilasm.field(name, const.get_type(), static=True)
        for const, name in to_init:
            const.init_fields(ilasm, self.const_var, name)
示例#4
0
    def gen_constants(self, ilasm, pending):
        try:
            while True:
                const,name = self.pending_consts.pop()
                const.record_fields()
        except IndexError:
            pass

        if pending:
            return

        if not self.rendered:
            ilasm.begin_consts(self.const_var.name)
        
        def generate_constants(consts):
            all_c = [const for const,name in consts.iteritems()]
            dep_ok = set()
            while len(all_c) > 0:
                const = all_c.pop()
                if const not in self.rendered:
                    to_render = True
                    if hasattr(const, 'depends_on') and const.depends_on:
                        for i in const.depends_on:
                            if i not in self.rendered and i not in dep_ok:
                                assert i.depends is None or const in i.depends
                                to_render = False
                                continue
                    
                    if to_render and (not hasattr(const, 'depends')) or (not const.depends) or const in dep_ok:
                        yield const,consts[const]
                        self.rendered.add(const)
                    else:
                        all_c.append(const)
                        for i in const.depends:
                            all_c.append(i)
                        dep_ok.add(const)

        # We need to keep track of fields to make sure
        # our items appear earlier than us
        to_init = []
        for const, name in generate_constants(self.consts):
            if self.genoo.config.translation.verbose:
                log("Recording %r %r"%(const,name))
            else:
                log.dot()
            ilasm.load_local(self.const_var)
            const.init(ilasm)
            ilasm.set_field(None, name)
            ilasm.store_void()
            to_init.append((const, name))
            #ilasm.field(name, const.get_type(), static=True)
        for const, name in to_init:
            const.init_fields(ilasm, self.const_var, name)