コード例 #1
0
ファイル: gencl.py プロジェクト: TheDunn/flex-pypy
 def declare_constant_instance(self, const):
     # const.concretetype is Instance
     if const in self.declarations:
         return self.declarations[const][0]
     name = "+const" + str(self.constcount) + "+"
     INST = dynamicType(const.value)
     self.declare_class(INST)
     inst = oodowncast(INST, const.value)
     cls = clrepr(INST)
     const_declaration = []
     const_declaration.append("(defvar %s nil)" % clrepr(name, True))
     const_declaration.append("(setf %s (make-instance %s))" % (clrepr(name, True),
                                                                clrepr(cls, True)))
     fields = INST._allfields()
     for fieldname in fields:
         fieldvalue = getattr(inst, fieldname)
         if isinstance(fieldvalue, _class):
             self.declare_any(fieldvalue._INSTANCE)
         fieldvaluerepr = clrepr(getattr(inst, fieldname))
         ### XXX
         const_declaration.append("(setf (slot-value %s '%s) %s)" % (clrepr(name, True),
                                                                     clrepr(fieldname, True),
                                                                     clrepr(fieldvaluerepr, True)))
     const_declaration = "\n".join(const_declaration)
     self.declarations[const] = (name, const_declaration)
     self.constcount += 1
     return name
コード例 #2
0
ファイル: node.py プロジェクト: TheDunn/flex-pypy
    def render(self):
        codef = CodeFormatter(self.gen)
        # XXX use CodeFormatter throughout here
        yield self.render_fileout_header(
                "%s class" % self._class_name, "internals")
        message = Message("setupConstants")
        yield codef.format(message.with_args([]))
        yield "    Constants := Dictionary new."
        for const, const_id in self.constants.iteritems():
            INST = dynamicType(const.value)
            inst = oodowncast(INST, const.value)
            field_names = INST._allfields().keys()
            field_values = [getattr(inst, f) for f in field_names]
            new = Message("new").send_to(INST, [])
            init_message = Message("fieldInit").send_to(new, field_values)
            yield "    Constants at: '%s' put: %s." \
                    % (const_id, codef.format(init_message))
        yield "! !"
        yield ""

        yield self.render_fileout_header(
                "%s class" % self._class_name, "internals")
        arg = CustomVariable("constId")
        get_message = Message("getConstant")
        yield codef.format(get_message.with_args([arg]))
        yield "    ^ Constants at: constId"
        yield "! !"
コード例 #3
0
ファイル: tool.py プロジェクト: antoine1fr/pygirl
 def read_attr(self, value, attr):
     value = ootype.oodowncast(ootype.dynamicType(value), value)
     return getattr(value, "o" + attr)
コード例 #4
0
ファイル: ooopimpl.py プロジェクト: TheDunn/flex-pypy
def op_oodowncast(INST, inst):
    return ootype.oodowncast(INST, inst)
コード例 #5
0
 def read_attr(self, value, attr):
     value = ootype.oodowncast(ootype.dynamicType(value), value)
     return getattr(value, "o" + attr)
コード例 #6
0
ファイル: ooopimpl.py プロジェクト: njues/Sypy
def op_oodowncast(INST, inst):
    return ootype.oodowncast(INST, inst)