[pypy-svn] r68410 - in pypy/branch/avm/pypy: module/posix module/sys translator/avm2
magcius at codespeak.net
magcius at codespeak.net
Wed Oct 14 01:12:34 CEST 2009
Author: magcius
Date: Wed Oct 14 01:12:33 2009
New Revision: 68410
Modified:
pypy/branch/avm/pypy/module/posix/__init__.py
pypy/branch/avm/pypy/module/sys/version.py
pypy/branch/avm/pypy/translator/avm2/avm2gen.py
pypy/branch/avm/pypy/translator/avm2/constants.py
pypy/branch/avm/pypy/translator/avm2/instructions.py
pypy/branch/avm/pypy/translator/avm2/util.py
Log:
More AVM2 stuff
Modified: pypy/branch/avm/pypy/module/posix/__init__.py
==============================================================================
--- pypy/branch/avm/pypy/module/posix/__init__.py (original)
+++ pypy/branch/avm/pypy/module/posix/__init__.py Wed Oct 14 01:12:33 2009
@@ -124,7 +124,7 @@
backend = space.config.translation.backend
# the Win32 urandom implementation isn't going to translate on JVM or CLI
# so we have to remove it
- if backend == 'cli' or backend == 'jvm':
+ if (backend == 'cli' or backend == 'jvm') and 'urandom' in self.interpleveldefs:
del self.interpleveldefs['urandom']
MixedModule.__init__(self, space, w_name)
Modified: pypy/branch/avm/pypy/module/sys/version.py
==============================================================================
--- pypy/branch/avm/pypy/module/sys/version.py (original)
+++ pypy/branch/avm/pypy/module/sys/version.py Wed Oct 14 01:12:33 2009
@@ -13,7 +13,7 @@
TRIM_URL_UP_TO = 'svn/pypy/'
SVN_URL = """$HeadURL$"""[10:-28]
-REV = """$LastChangedRevision$"""[22:-2]
+REV = """68301"""
import pypy
Modified: pypy/branch/avm/pypy/translator/avm2/avm2gen.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/avm2gen.py (original)
+++ pypy/branch/avm/pypy/translator/avm2/avm2gen.py Wed Oct 14 01:12:33 2009
@@ -4,23 +4,28 @@
from pypy.objspace.flow import model as flowmodel
from pypy.rpython.ootypesystem import ootype
-from pypy.translator.avm2 import constants, instructions
+from pypy.translator.avm2 import constants, instructions, assembler
from pypy.translator.oosupport.treebuilder import SubOperation
from pypy.translator.oosupport.metavm import Generator as OOGenerator
from pypy.translator.oosupport.constant import push_constant
from collections import namedtuple
+from itertools import chain
Scope = namedtuple("Scope", "block parent registers namespaces")
+_vec_qname = constants.QName("Vector", constants.Namespace(constants.PACKAGE_NAMESPACE, "__AS3__.vec"))
+_str_qname = constants.QName("String")
+_arr_qname = constants.QName("Array")
+
class Avm2ilasm(OOGenerator):
""" AVM2 'assembler' generator routines """
- def __init__(self):
- self.scope = Scope(None, None, [], [constants.PRIVATE_NAMESPACE, constants.PACKAGE_NAMESPACE])
+ def __init__(self, asm):
+ self.scope = Scope(asm, None, constants.ValuePool("this"), [constants.PACKAGE_NAMESPACE, constants.PRIVATE_NAMESPACE])
self.constants = constants.AbcConstantPool()
-
+
def I(self, *instructions):
self.scope.block.add(instructions)
-
+
@property
def current_namespaces(self):
context = self.scope
@@ -48,11 +53,14 @@
def dup(self):
self.I(instructions.dup())
+ def swap(self):
+ self.I(instructions.swap())
+
def emit(self, instr, *args):
self.I(instructions.INSTRUCTIONS[instr](*args))
def load(self, v):
- if hasattr(v, "__iter__") and not isinstance(v, basestring):
+ if hasattr(v, "__iter__") and not isinstance(v, basestring):
for i in v:
self.load(i)
elif isinstance(v, flowmodel.Variable):
@@ -65,19 +73,27 @@
else:
self.push_const(v)
+ def store_var(self, v):
+ self.I(instrucitons.setlocal(self.registers.index_for(v)))
+
+ def store_local(self, v):
+ self.store_var(v.name)
+
def call_oostring(self, OOTYPE):
- str_qname = constants.QName("String")
- self.I(instructions.findpropstrict(str_qname))
- self.I(instructions.swap())
- self.I(instructions.callproperty(str_qname, 1))
+ self.I(instructions.findpropstrict(_str_qname))
+ self.swap()
+ self.I(instructions.callproperty(_str_qname, 1))
call_oounicode = call_oostring
def oonewarray(self, TYPE, length=1):
- arr_qname = constants.QName("Array")
- self.I(instructions.findpropstrict(arr_qname))
+ self.I(instructions.findpropstrict(_arr_qname))
self.push_const(length)
- self.I(instructions.callproperty(arr_qname, 1))
+ self.I(instructions.callproperty(_arr_qname, 1))
+
+ def oonewvector(self, TYPE, length=1):
+ self.I(instructions.findpropstrict(_vec_qname))
+ self.push_const(
def push_this(self):
self.I(instructions.getlocal(0))
@@ -89,11 +105,11 @@
def push_var(self, v):
assert v in self.registers
- self.I(instructions.getlocal(self.registers.find(v)))
+ self.I(instructions.getlocal(self.registers.index_for(v)))
def push_const(self, v):
if isinstance(v, int):
- if 0 < v < 256:
+ if 0 <= v < 256:
self.I(instructions.pushbyte(v))
elif v >= 0:
self.I(instructions.pushuint(self.constants.uint_pool.index_for(v)))
@@ -124,3 +140,11 @@
self.push_const(value._str)
else:
self.push_const(value)
+
+ def init_array(self, members=[]):
+ self.load(members)
+ self.I(instructions.newarray(len(members)))
+
+ def init_object(self, members={}):
+ self.load(chain(*members.items()))
+ self.I(instructions.newobject(len(members)))
Modified: pypy/branch/avm/pypy/translator/avm2/constants.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/constants.py (original)
+++ pypy/branch/avm/pypy/translator/avm2/constants.py Wed Oct 14 01:12:33 2009
@@ -1,4 +1,4 @@
-c
+
import struct
from pypy.translator.avm2.util import serialize_u32 as u32
@@ -302,9 +302,6 @@
def __hash__(self):
return hash((self.KIND))
- def serialize(self):
- return chr(self.KIND)
-
class RtqNameLA(RtqNameL):
KIND = TYPE_MULTINAME_RtqNameLA
@@ -318,7 +315,7 @@
def __eq__(self, other):
return self.KIND == other.KIND and self.name == other.name
- def __ne__(self):
+ def __ne__(self, other):
return not self == other
def __hash__(self):
@@ -329,7 +326,7 @@
if self.name == "*":
self._name_index = 0
else:
- self._name_index = pool.utf8_pool.index_for(name)
+ self._name_index = pool.utf8_pool.index_for(self.name)
def serialize(self):
assert self._name_index is not None, "Please call write_to_pool before serializing"
@@ -364,7 +361,7 @@
def serialize(self):
assert self._name_index is not None, "Please call write_to_pool before serializing"
assert self._types_indices is not None, "Please call write_to_pool before serializing"
- return ''.join([chr(self.KIND), u32(self._name_index), u32(self._types_indices)] + [u32(a) for a in self._types_indices])
+ return ''.join([chr(self.KIND), u32(self._name_index), u32(len(self._types_indices))] + [u32(a) for a in self._types_indices])
# ======================================
# Constant Pool
@@ -377,6 +374,9 @@
self.pool = []
self.default = default
+ def __contains__(self, value):
+ return value in self.index_map
+
def __iter__(self):
return iter(self.pool)
Modified: pypy/branch/avm/pypy/translator/avm2/instructions.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/instructions.py (original)
+++ pypy/branch/avm/pypy/translator/avm2/instructions.py Wed Oct 14 01:12:33 2009
@@ -11,8 +11,11 @@
raise ValueError, "Instruction needs to be specialized"
return fn(self, *args, **kwargs)
+class _Avm2SpecializedInstruction(object):
+ pass
+
class _Avm2ShortInstruction(object):
- specialized = False
+ specialized=False
def __init__(self, opcode, name, stack=0, scope=0, flags=0):
self.opcode = opcode
self.name = name
@@ -32,18 +35,21 @@
def _serialize(self):
return chr(self.opcode)
-
- serialize = _serialize
- set_assembler_props = _set_assembler_props
- __repr__ = _repr
def specialize(self, **kwargs):
- return type("Avm2_%s_Instruction" % self.name,
- (self.__class__), dict(kwargs.items(),
- specialized=True,
- serialize=self._serialize,
- set_assembler_props=self._set_assembler_props,
- __repr__=self._repr))
+ return type("_Avm2_Instruction_%s" % self.name,
+ (_Avm2SpecializedInstruction, self.__class__),
+ dict(kwargs.items(),
+ specialized=True,
+ set_assembler_props=self._set_assembler_props,
+ serialize=self._serialize,
+ __repr__=self._repr,
+ opcode=self.opcode, name=self.name, stack=self.stack, scope=self.scope,
+ ))()
+
+
+ def __call__(self):
+ return self.specialize()
class _Avm2DebugInstruction(_Avm2ShortInstruction):
@needs_specialized
@@ -54,6 +60,9 @@
chr(self.reg & 0xFF) + \
u32(self.extra)
+ def __call__(self, debug_type, index, reg, extra):
+ return self.specialize(debug_type=debug_type, index=index, reg=reg, extra=extra)
+
class _Avm2U8Instruction(_Avm2ShortInstruction):
@needs_specialized
def _serialize(self):
Modified: pypy/branch/avm/pypy/translator/avm2/util.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/util.py (original)
+++ pypy/branch/avm/pypy/translator/avm2/util.py Wed Oct 14 01:12:33 2009
@@ -22,6 +22,20 @@
raise ValueError, "value does not fit in a s24"
return m[:3]
+def camel_case_match(string):
+ """
+ Properly matches the camelCase naming style so that a name like
+ writeXMLDocument gets parsed as ["write", "XML", "Document"].
+ """
+ return re.findall('(^[a-z]+|[A-Z][a-z]+|[A-Z]+|[0-9])(?![a-z])', string)
+
+def camel_case_convert(string):
+ """
+ Properly converts the camelCase naming style to underscore style so that
+ writeXMLDocument gets converted to write_xml_document.
+ """
+ return '_'.join(s.lower() for s in camel_case_match(string))
+
Avm2Backpatch = namedtuple("Avm2Backpatch", "location base lbl")
class Avm2Label(object):
More information about the Pypy-commit
mailing list