1. Pypy
  2. Untitled project
  3. pypy

Commits

Antonio Cuni  committed 09092bd

fix array_{get,set}item

  • Participants
  • Parent commits 40ab3ea
  • Branches default

Comments (0)

Files changed (2)

File pypy/translator/cli/ilgenerator.py

View file
             self.ilasm.opcode('newarr', clitype.itemtype.typename())
     
     def _array_suffix(self, ARRAY, erase_unsigned=False):
-        from pypy.translator.cli.metavm import OOTYPE_TO_MNEMONIC
-        suffix = OOTYPE_TO_MNEMONIC.get(ARRAY.ITEM, 'ref')
+        from pypy.translator.cli.metavm import ootype_to_mnemonic
+        suffix = ootype_to_mnemonic(ARRAY.ITEM, ARRAY.ITEM, 'ref')
         if erase_unsigned:
             suffix = suffix.replace('u', 'i')
         return suffix

File pypy/translator/cli/metavm.py

View file
 UNSIGNED_TYPES = [ootype.Char, ootype.UniChar, rffi.USHORT,
                   ootype.Unsigned, ootype.UnsignedLongLong]
 
+def ootype_to_mnemonic(FROM, TO, default=None):
+    if TO == ootype.Float:
+        return 'r8'
+    #
+    try:
+        size = str(INT_SIZE[TO])
+    except KeyError:
+        return default
+    if FROM in UNSIGNED_TYPES:
+        return 'u' + size
+    else:
+        return 'i' + size
+
 class _CastPrimitive(MicroInstruction):
     def render(self, generator, op):
         FROM = op.args[0].concretetype
         TO = op.result.concretetype
-        if TO == ootype.Float:
-            mnemonic = 'r8'
-        else:
-            if FROM in UNSIGNED_TYPES:
-                mnemonic = 'u'
-            else:
-                mnemonic = 'i'
-            mnemonic += str(INT_SIZE[TO])
+        mnemonic = ootype_to_mnemonic(FROM, TO)
         generator.ilasm.opcode('conv.%s' % mnemonic)
 
 Call = _Call()