Author: Alex Gaynor <alex.gay...@gmail.com> Branch: dynamic-specialized-tuple Changeset: r53680:52c4765a9552 Date: 2012-03-15 09:58 -0700 http://bitbucket.org/pypy/pypy/changeset/52c4765a9552/
Log: metaprogram diff --git a/pypy/rlib/rerased_raw.py b/pypy/rlib/rerased_raw.py --- a/pypy/rlib/rerased_raw.py +++ b/pypy/rlib/rerased_raw.py @@ -92,29 +92,20 @@ def method_getshape(self): return annmodel.SomeString(can_be_None=False) - def method_getint(self, s_idx): - self._check_idx(s_idx) - return annmodel.SomeInteger() + def _typed_annotate_getset(s_type): + def method_get(self, s_idx): + self._check_idx(s_idx) + return s_type + def method_set(self, s_idx, s_v): + self._check_idx(s_idx) + assert s_type.contains(s_v) + return method_get, method_set - def method_setint(self, s_idx, s_v): - self._check_idx(s_idx) - assert annmodel.SomeInteger().contains(s_v) - - def method_getbool(self, s_idx): - self._check_idx(s_idx) - return annmodel.SomeBool() - - def method_setbool(self, s_idx, s_v): - self._check_idx(s_idx) - assert annmodel.SomeBool().contains(s_v) - - def method_getfloat(self, s_idx): - self._check_idx(s_idx) - return annmodel.SomeFloat() - - def method_setfloat(self, s_idx, s_f): - self._check_idx(s_idx) - assert annmodel.SomeFloat().contains(s_f) + method_getint, method_setint = _typed_annotate_getset(annmodel.SomeInteger()) + method_getbool, method_setbool = _typed_annotate_getset(annmodel.SomeBool()) + method_getfloat, method_setfloat = _typed_annotate_getset(annmodel.SomeFloat()) + method_getstr, method_setstr = _typed_annotate_getset(annmodel.SomeString()) + method_getunicode, method_setunicode = _typed_annotate_getset(annmodel.SomeUnicodeString()) def method_getinstance(self, s_idx, s_cls): self._check_idx(s_idx) @@ -127,29 +118,12 @@ self._check_idx(s_idx) assert isinstance(s_obj, annmodel.SomeInstance) - def method_getstr(self, s_idx): - self._check_idx(s_idx) - return annmodel.SomeString() - - def method_setstr(self, s_idx, s_s): - self._check_idx(s_idx) - assert annmodel.SomeString().contains(s_s) - - def method_getunicode(self, s_idx): - self._check_idx(s_idx) - return annmodel.SomeUnicodeString() - - def method_setunicode(self, s_idx, s_u): - self._check_idx(s_idx) - assert annmodel.SomeUnicodeString().contains(s_u) - class __extend__(pairtype(SomeUntypedStorage, SomeUntypedStorage)): def union((self, other)): return SomeUntypedStorage() - UNTYPEDSTORAGE = lltype.GcStruct("untypedstorage", ("shape", lltype.Ptr(STR)), ("data", lltype.Array(llmemory.Address)), _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit