[pypy-commit] cffi HERE-in-paths: Allow specifying $HERE in the paths given to verify()

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: HERE-in-paths
Changeset: r1582:46d4f4c6b3c4
Date: 2014-11-28 10:53 +0100
http://bitbucket.org/cffi/cffi/changeset/46d4f4c6b3c4/

Log:Allow specifying $HERE in the paths given to verify()

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -336,6 +336,7 @@
 """
 from .verifier import Verifier
 self.verifier = Verifier(self, source, tmpdir, **kwargs)
+self.verifier.expand_here_in_kwds(frame=sys._getframe(1))
 lib = self.verifier.load_library()
 self._libraries.append(lib)
 return lib
diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -11,6 +11,11 @@
 def _extension_suffixes():
 return [suffix for suffix, _, type in imp.get_suffixes()
 if type == imp.C_EXTENSION]
+try:
+basestring
+except NameError:
+# Python 3.x
+basestring = str
 
 
 class Verifier(object):
@@ -104,6 +109,24 @@
 modname = self.get_module_name()
 return ffiplatform.get_extension(sourcename, modname, **self.kwds)
 
+def expand_here_in_kwds(self, here=None, frame=None):
+if frame is not None:
+try:
+here = os.path.dirname(frame.f_globals['__file__'])
+except (AttributeError, KeyError):
+pass
+for key, value in self.kwds.items():
+if not isinstance(value, list):
+continue
+for i in range(len(value)):
+x = value[i]
+if isinstance(x, basestring) and (
+x.startswith('$HERE/') or x.startswith('$HERE\\')):
+if here is None:
+raise ValueError("prefix '$HERE' cannot be replaced")
+x = os.path.join(here, x[6:])
+value[i] = x
+
 def generates_python_module(self):
 return self._vengine._gen_python_module
 
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -2037,3 +2037,16 @@
 n = (1 << 29) + i
 lib.SetLastError(n)
 assert ffi.getwinerror()[0] == n
+
+def test_verify_include_dir():
+curdir = os.getcwd()
+try:
+os.chdir('..')
+ffi = FFI()
+ffi.cdef("int v_include_dir(void);")
+lib = ffi.verify('#include "verify_include_dir.h"',
+ include_dirs=['$HERE/snippets/'],
+ sources=['$HERE/snippets/verify_include_dir.c'])
+assert lib.v_include_dir() == 42
+finally:
+os.chdir(curdir)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] creflect default: Support for "typedef ... sometype; "

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r99:4c7a226a0be6
Date: 2014-11-28 12:58 +0100
http://bitbucket.org/cffi/creflect/changeset/4c7a226a0be6/

Log:Support for "typedef ... sometype;"

diff --git a/creflect/cparser.py b/creflect/cparser.py
--- a/creflect/cparser.py
+++ b/creflect/cparser.py
@@ -28,7 +28,8 @@
 r_comment1 = re.compile(r"//.*")
 r_comment2 = re.compile(r"/[*]")
 r_comment3 = re.compile(r"[*]/")
-r_empty_braces = re.compile(r"{\s*}") # after comments have been removed
+r_empty_braces = re.compile(r"{(\s*)}") # after comments have been removed
+r_typedef_dotdodot = re.compile(r"\btypedef(\s*)[.][.][.]")
 
 def remove_comments(csource):
 csource = r_comment1.sub('', csource) # remove the '//' comments
@@ -50,7 +51,10 @@
 return ''.join(parts)
 
 def expand_empty_braces(csource):
-return r_empty_braces.sub('{ char __crx_empty__; }', csource)
+return r_empty_braces.sub(r'{ char __crx_empty__;\1}', csource)
+
+def expand_typedef_dotdotdot(csource):
+return r_typedef_dotdodot.sub(r'typedef\1 __crx_unknown_t ', csource)
 
 
 class CSource(object):
@@ -60,10 +64,15 @@
 self.first_lineno = first_lineno
 self._struct_union_enum_decl = {}
 
-def to_ast(self):
-cparser = pycparser.CParser()
+def prepare_source(self):
 csource = remove_comments(self.cdefblock)
 csource = expand_empty_braces(csource)
+csource = expand_typedef_dotdotdot(csource)
+return 'typedef int __crx_unknown_t; ' + csource
+
+def to_ast(self):
+csource = self.prepare_source()
+cparser = pycparser.CParser()
 try:
 ast = cparser.parse(csource)
 except pycparser.c_parser.ParseError as e:
@@ -85,7 +94,8 @@
 self.declarations = []
 self.typedefs = {}
 ast = self.to_ast()
-for decl in ast.ext:
+assert ast.ext[0].name == '__crx_unknown_t'
+for decl in ast.ext[1:]:
 if isinstance(decl, pycparser.c_ast.Decl):
 self._parse_decl(decl)
 elif isinstance(decl, pycparser.c_ast.Typedef):
@@ -148,9 +158,13 @@
 # first, dereference typedefs, if we have it already parsed, we're good
 if (isinstance(typenode, pycparser.c_ast.TypeDecl) and
 isinstance(typenode.type, pycparser.c_ast.IdentifierType) and
-len(typenode.type.names) == 1 and
-typenode.type.names[0] in self.typedefs):
-return self.typedefs[typenode.type.names[0]]
+len(typenode.type.names) == 1):
+typename = typenode.type.names[0]
+if typename in self.typedefs:
+return self.typedefs[typenode.type.names[0]]
+if typename == '__crx_unknown_t':
+assert approx_name, "XXX"
+return model.UnknownType(approx_name)
 #
 if isinstance(typenode, pycparser.c_ast.ArrayDecl):
 # array type
diff --git a/creflect/model.py b/creflect/model.py
--- a/creflect/model.py
+++ b/creflect/model.py
@@ -476,6 +476,20 @@
 self.name,))
 
 
+class UnknownType(BaseType):
+_attrs_ = ('approx_name',)
+const = False
+
+def __init__(self, approx_name):
+self.approx_name = approx_name
+self.c_name_with_marker = '... &'
+
+def inspect_nonconst_type(self, block, inspect):
+inspect.flush()
+return block.write_crx_type_var('cb->get_unknown_type(cb, "%s")' % (
+self.approx_name,))
+
+
 # 
 
 
diff --git a/creflect/src/creflect.h b/creflect/src/creflect.h
--- a/creflect/src/creflect.h
+++ b/creflect/src/creflect.h
@@ -52,6 +52,7 @@
 crx_type_t *(*get_union_type)(CRX_SELF, const char *);
 crx_type_t *(*get_enum_type)(CRX_SELF, const char *);
 crx_type_t *(*get_user_type)(CRX_SELF, const char *);
+crx_type_t *(*get_unknown_type)(CRX_SELF, const char *);
 void (*complete)(CRX_SELF, crx_type_t *,
  size_t, size_t, crx_field_t[], int);
 void (*complete_enum)(CRX_SELF, crx_type_t *, crx_type_t *);
diff --git a/creflect/src/creflect_print.h b/creflect/src/creflect_print.h
--- a/creflect/src/creflect_print.h
+++ b/creflect/src/creflect_print.h
@@ -167,6 +167,11 @@
 return newtype(name);
 }
 
+static crx_type_t *tst_get_unknown_type(crx_builder_t *cb, const char *name)
+{
+return newtype2("UNKNOWN ", name);
+}
+
 static void tst_complete(crx_builder_t *cb, crx_type_t *t,
  size_t sz, size_t align,
  crx_field_t fields[], int nfields)
@@ -258,6 +263,7 @@
 tst_get_union_type,
 tst_get_enum_type,
 tst_get_user_type,
+tst_get_unknown_type,
 tst_complete,
 tst_complete_enum,
 tst_define_type,
diff --git a/test/codegen/007.c b/test/codegen/007.c
new file mode 100644
--- /dev/null
+++ b/test/codegen/007.c
@@ -0,0 +1,13 @@
+typedef ... num_t;
+
+# __

[pypy-commit] creflect default: Support '#define FOO '

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r100:1d714ead0a23
Date: 2014-11-28 13:10 +0100
http://bitbucket.org/cffi/creflect/changeset/1d714ead0a23/

Log:Support '#define FOO '

diff --git a/creflect/cparser.py b/creflect/cparser.py
--- a/creflect/cparser.py
+++ b/creflect/cparser.py
@@ -30,6 +30,9 @@
 r_comment3 = re.compile(r"[*]/")
 r_empty_braces = re.compile(r"{(\s*)}") # after comments have been removed
 r_typedef_dotdodot = re.compile(r"\btypedef(\s*)[.][.][.]")
+r_define_var = re.compile(
+r"^[ \t]*#[ \t]*define[ \t]+([A-Za-z_][A-Za-z0-9_]+)[ \t][^\n]+",
+re.MULTILINE)
 
 def remove_comments(csource):
 csource = r_comment1.sub('', csource) # remove the '//' comments
@@ -56,6 +59,9 @@
 def expand_typedef_dotdotdot(csource):
 return r_typedef_dotdodot.sub(r'typedef\1 __crx_unknown_t ', csource)
 
+def expand_define_var(csource):
+return r_define_var.sub(r'const int \1;', csource)
+
 
 class CSource(object):
 
@@ -68,6 +74,7 @@
 csource = remove_comments(self.cdefblock)
 csource = expand_empty_braces(csource)
 csource = expand_typedef_dotdotdot(csource)
+csource = expand_define_var(csource)
 return 'typedef int __crx_unknown_t; ' + csource
 
 def to_ast(self):
diff --git a/test/codegen/macro-001.c b/test/codegen/macro-001.c
new file mode 100644
--- /dev/null
+++ b/test/codegen/macro-001.c
@@ -0,0 +1,23 @@
+#define FOO  42
+#define BAR  (40U + 2)
+
+# 
+
+void testmacro_001(crx_builder_t *cb)
+{
+crx_type_t *t1, *t2;
+{
+crx_num_const_t v;
+(void)((FOO) << 1);  /* check that 'FOO' is an integer */
+t1 = CRX_INT_CONST(cb, FOO, &v, 1);
+cb->define_num_const(cb, "FOO", t1, &v);
+#expect NUMCONST FOO = int 42
+}
+{
+crx_num_const_t v;
+(void)((BAR) << 1);  /* check that 'BAR' is an integer */
+t2 = CRX_INT_CONST(cb, BAR, &v, 1);
+cb->define_num_const(cb, "BAR", t2, &v);
+#expect NUMCONST BAR = unsigned int 42
+}
+}
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: Thank-you-psf-2

2014-11-28 Thread fijal
Author: Maciej Fijalkowski 
Branch: extradoc
Changeset: r5467:31bd5aaffc61
Date: 2014-11-28 14:13 +0200
http://bitbucket.org/pypy/extradoc/changeset/31bd5aaffc61/

Log:Thank-you-psf-2

diff --git a/blog/draft/io-improvements.rst b/blog/draft/io-improvements.rst
--- a/blog/draft/io-improvements.rst
+++ b/blog/draft/io-improvements.rst
@@ -32,7 +32,7 @@
 deviation comes mostly from the warmup at the beginning, true figures
 are smaller):
 
-++- 
+-++
+++--+-++
 | benchmark  | CPython  | PyPy 2.4| PyPy non-zero  
|
 
++--+-++
 | fibonacci  | 4.8+-0.15 (1.0x) | 0.59+-0.07 (8.1x)   | 0.45+-0.07 
(10.6x) |
diff --git a/blog/draft/thank-you-psf-2.rst b/blog/draft/thank-you-psf-2.rst
new file mode 100644
--- /dev/null
+++ b/blog/draft/thank-you-psf-2.rst
@@ -0,0 +1,34 @@
+September donations and thank you to the Python Software Foundation!
+
+
+Hello everyone!
+
+We would like to show you a short update on the PyPy funding.
+We gathered a total of $15,986 in the month of September and as per
+`earlier agreement`_, the Python Software Foundation donated $10,000
+to PyPy. We would like to thank everyone participating and the PSF in
+particular for supporting the PyPy project and making our work possible!
+
+We've been working hard on the goals outlined in the funding proposals.
+
+* `PyPy Python 3`_ support has been in beta for a while and it's already
+  being used by many people, as seen per the number of reported bugs.
+  We're currently supporting 3.2, planning on moving towards 3.4 in the
+  future.
+
+* Software Transactional Memory has been a successful research project,
+  with `first real world`_ results shown during the Warsaw sprint.
+
+* More detailed update on numpy will be published soon. A little spoiler is
+  that we're planning on addressing matplotlib, scipy and the larger ecosystem
+  to some extent. Stay tuned!
+
+Again, thanks to everyone who donated and happy Thanksgiving to everyone
+on that side of the world!
+
+Cheers,
+fijal
+
+.. _`earlier agreement`: 
http://morepypy.blogspot.com/2014/09/python-software-foundation-matching.html
+.. _`first real world`: 
http://morepypy.blogspot.com/2014/11/tornado-without-gil-on-pypy-stm.html
+.. _`PyPy Python 3`:  
http://morepypy.blogspot.com/2014/10/pypy3-240-released.html
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: add an image with tornado stm benchmark results

2014-11-28 Thread kostialopuhin
Author: Konstantin Lopuhin 
Branch: extradoc
Changeset: r5469:2a47233c651b
Date: 2014-11-17 16:29 +0300
http://bitbucket.org/pypy/extradoc/changeset/2a47233c651b/

Log:add an image with tornado stm benchmark results

diff --git a/blog/draft/tornado-stm-results.png 
b/blog/draft/tornado-stm-results.png
new file mode 100644
index 
..1913e33f3ded79d5597a5787088581927e2a294f
GIT binary patch

[cut]

diff --git a/blog/draft/tornado-stm.rst b/blog/draft/tornado-stm.rst
--- a/blog/draft/tornado-stm.rst
+++ b/blog/draft/tornado-stm.rst
@@ -124,7 +124,7 @@
 PyPy STM 4  24.2
   =
 
-.. image:: results-1.png
+.. image:: tornado-stm-results.png
 
 As we can see, in this benchmark PyPy STM using just two cores
 can beat regular PyPy!
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: merge heads

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5472:255fb1879b2b
Date: 2014-11-28 13:40 +0100
http://bitbucket.org/pypy/extradoc/changeset/255fb1879b2b/

Log:merge heads

diff --git a/blog/draft/io-improvements.rst b/blog/draft/io-improvements.rst
--- a/blog/draft/io-improvements.rst
+++ b/blog/draft/io-improvements.rst
@@ -32,7 +32,7 @@
 deviation comes mostly from the warmup at the beginning, true figures
 are smaller):
 
-++- 
+-++
+++--+-++
 | benchmark  | CPython  | PyPy 2.4| PyPy non-zero  
|
 
++--+-++
 | fibonacci  | 4.8+-0.15 (1.0x) | 0.59+-0.07 (8.1x)   | 0.45+-0.07 
(10.6x) |
diff --git a/blog/draft/thank-you-psf-2.rst b/blog/draft/thank-you-psf-2.rst
new file mode 100644
--- /dev/null
+++ b/blog/draft/thank-you-psf-2.rst
@@ -0,0 +1,34 @@
+September donations and thank you to the Python Software Foundation!
+
+
+Hello everyone!
+
+We would like to show you a short update on the PyPy funding.
+We gathered a total of $15,986 in the month of September and as per
+`earlier agreement`_, the Python Software Foundation donated $10,000
+to PyPy. We would like to thank everyone participating and the PSF in
+particular for supporting the PyPy project and making our work possible!
+
+We've been working hard on the goals outlined in the funding proposals.
+
+* `PyPy Python 3`_ support has been in beta for a while and it's already
+  being used by many people, as seen per the number of reported bugs.
+  We're currently supporting 3.2, planning on moving towards 3.4 in the
+  future.
+
+* Software Transactional Memory has been a successful research project,
+  with `first real world`_ results shown during the Warsaw sprint.
+
+* More detailed update on numpy will be published soon. A little spoiler is
+  that we're planning on addressing matplotlib, scipy and the larger ecosystem
+  to some extent. Stay tuned!
+
+Again, thanks to everyone who donated and happy Thanksgiving to everyone
+on that side of the world!
+
+Cheers,
+fijal
+
+.. _`earlier agreement`: 
http://morepypy.blogspot.com/2014/09/python-software-foundation-matching.html
+.. _`first real world`: 
http://morepypy.blogspot.com/2014/11/tornado-without-gil-on-pypy-stm.html
+.. _`PyPy Python 3`:  
http://morepypy.blogspot.com/2014/10/pypy3-240-released.html
diff --git a/talk/dls2012/benchmarks/benchmark.sh 
b/talk/dls2012/benchmarks/benchmark.sh
--- a/talk/dls2012/benchmarks/benchmark.sh
+++ b/talk/dls2012/benchmarks/benchmark.sh
@@ -59,13 +59,21 @@
 #$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3 1
 #$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv5 1
 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3 100
+$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3_numpy 100
 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv5 100
+$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv5_numpy 100
 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3 1000
+$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3_numpy 1000
 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv5 1000
+$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv5_numpy 1000
 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3x3 100 3
+$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3x3_numpy 
100 3
 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3x3 1000 1000
+$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3x3_numpy 1000 
1000
 $* ./runner.py $EXTRA_OPTS convolution/convolution.py dilate3x3 1000 1000
+$* ./runner.py $EXTRA_OPTS convolution/convolution.py dilate3x3_numpy 1000 
1000
 $* ./runner.py $EXTRA_OPTS convolution/convolution.py sobel_magnitude 1000 
1000
+$* ./runner.py $EXTRA_OPTS convolution/convolution.py 
sobel_magnitude_numpy 1000 1000
 #$* ./runner.py $EXTRA_OPTS image/noborder.py main NoBorderImagePadded
 #$* ./runner.py $EXTRA_OPTS image/noborder.py main NoBorderImagePadded iter
 #$* ./runner.py $EXTRA_OPTS image/noborder.py main NoBorderImagePadded 
range
diff --git a/talk/dls2012/benchmarks/convolution/convolution.py 
b/talk/dls2012/benchmarks/convolution/convolution.py
--- a/talk/dls2012/benchmarks/convolution/convolution.py
+++ b/talk/dls2012/benchmarks/convolution/convolution.py
@@ -1,5 +1,13 @@
 from array import array
 from math import log10, sqrt
+try:
+import numpy as np
+except ImportError:
+try:
+import numpypy as np
+except ImportError:
+print "Cant find nympy"
+
 
 def _conv3(a, k, n=1):
 assert len(k)==3
@@ -14,7 +22,22 @@
 n = int(args[0])
 _conv3(array('d', [1]) * (1/n)

[pypy-commit] extradoc extradoc: Add my own comments in three places

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5468:d9be15557668
Date: 2014-11-17 14:10 +0100
http://bitbucket.org/pypy/extradoc/changeset/d9be15557668/

Log:Add my own comments in three places

diff --git a/blog/draft/tornado-stm.rst b/blog/draft/tornado-stm.rst
--- a/blog/draft/tornado-stm.rst
+++ b/blog/draft/tornado-stm.rst
@@ -170,7 +170,7 @@
 File "/home/arigo/hg/pypy/stmgc-c7/lib-python/2.7/_weakrefset.py", line 
70, in __contains__
 File "/home/arigo/hg/pypy/stmgc-c7/lib-python/2.7/_weakrefset.py", line 
70, in __contains__
 
-**FIXME** why does it happen?
+[Armin: It is unclear why this happens so far.  We'll investigate...]
 
 The second conflict (without etag tweaks) originates
 in the transaction module, from this piece of code::
@@ -180,7 +180,9 @@
 got_exception)
 counter[0] += 1
 
-**FIXME** why does it happen?
+[Armin: This is a conflict in the transaction module itself; ideally,
+it shouldn't have any, but in order to do that we might need a little bit
+of support from RPython or C code.  So this is pending improvement.]
 
 Tornado modification used in this blog post is based on 3.2.dev2.
 As of now, the latest version is 4.0.2, and if we
@@ -188,6 +190,14 @@
 the same changes to this version, then we no longer get any scaling on this 
benchmark,
 and there are no conflicts that take any substantial time.
 
+[Armin: There are two possible reactions to a conflict.  We can either
+abort one of the two threads, or (depending on the circumstances) just
+pause the current thread until the other one commits, after which the
+thread will likely be able to continue.  The tool ``print_stm_log.py``
+did not report conflicts that cause pauses.  It has been fixed very
+recently.  Chances are that on this test it would report long pauses and
+point to locations that cause them.]
+
 
 Part 2: a more interesting benchmark: A-star
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: merge heads

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5471:dde71b6447a4
Date: 2014-11-17 14:40 +0100
http://bitbucket.org/pypy/extradoc/changeset/dde71b6447a4/

Log:merge heads

diff --git a/blog/draft/tornado-stm-results.png 
b/blog/draft/tornado-stm-results.png
new file mode 100644
index 
..1913e33f3ded79d5597a5787088581927e2a294f
GIT binary patch

[cut]

diff --git a/blog/draft/tornado-stm.rst b/blog/draft/tornado-stm.rst
--- a/blog/draft/tornado-stm.rst
+++ b/blog/draft/tornado-stm.rst
@@ -127,7 +127,7 @@
 PyPy STM 4  24.2
   =
 
-.. image:: results-1.png
+.. image:: tornado-stm-results.png
 
 As we can see, in this benchmark PyPy STM using just two cores
 can beat regular PyPy!
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: Updates

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5470:f326c47b119c
Date: 2014-11-17 14:40 +0100
http://bitbucket.org/pypy/extradoc/changeset/f326c47b119c/

Log:Updates

diff --git a/blog/draft/tornado-stm.rst b/blog/draft/tornado-stm.rst
--- a/blog/draft/tornado-stm.rst
+++ b/blog/draft/tornado-stm.rst
@@ -1,6 +1,9 @@
 Tornado without a GIL on PyPy STM
 =
 
+*This post is by Konstantin Lopuhin, who tried PyPy STM during the
+Warsaw sprint.*
+
 Python has a GIL, right? Not quite - PyPy STM is a python implementation
 without a GIL, so it can scale CPU-bound work to several cores.
 PyPy STM is developed by Armin Rigo and Remi Meier,
@@ -170,7 +173,7 @@
 File "/home/arigo/hg/pypy/stmgc-c7/lib-python/2.7/_weakrefset.py", line 
70, in __contains__
 File "/home/arigo/hg/pypy/stmgc-c7/lib-python/2.7/_weakrefset.py", line 
70, in __contains__
 
-[Armin: It is unclear why this happens so far.  We'll investigate...]
+*Comment by Armin: It is unclear why this happens so far.  We'll 
investigate...*
 
 The second conflict (without etag tweaks) originates
 in the transaction module, from this piece of code::
@@ -180,9 +183,9 @@
 got_exception)
 counter[0] += 1
 
-[Armin: This is a conflict in the transaction module itself; ideally,
+*Comment by Armin: This is a conflict in the transaction module itself; 
ideally,
 it shouldn't have any, but in order to do that we might need a little bit
-of support from RPython or C code.  So this is pending improvement.]
+of support from RPython or C code.  So this is pending improvement.*
 
 Tornado modification used in this blog post is based on 3.2.dev2.
 As of now, the latest version is 4.0.2, and if we
@@ -190,13 +193,13 @@
 the same changes to this version, then we no longer get any scaling on this 
benchmark,
 and there are no conflicts that take any substantial time.
 
-[Armin: There are two possible reactions to a conflict.  We can either
+*Comment by Armin: There are two possible reactions to a conflict.  We can 
either
 abort one of the two threads, or (depending on the circumstances) just
 pause the current thread until the other one commits, after which the
 thread will likely be able to continue.  The tool ``print_stm_log.py``
 did not report conflicts that cause pauses.  It has been fixed very
 recently.  Chances are that on this test it would report long pauses and
-point to locations that cause them.]
+point to locations that cause them.*
 
 
 Part 2: a more interesting benchmark: A-star
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix test

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r74751:4a150158f334
Date: 2014-11-28 14:19 +0100
http://bitbucket.org/pypy/pypy/changeset/4a150158f334/

Log:fix test

diff --git a/rpython/jit/codewriter/test/test_flatten.py 
b/rpython/jit/codewriter/test/test_flatten.py
--- a/rpython/jit/codewriter/test/test_flatten.py
+++ b/rpython/jit/codewriter/test/test_flatten.py
@@ -297,21 +297,27 @@
 int_return $-1
 ---
 L1:
+-live-
 int_return $61
 ---
 L2:
+-live-
 int_return $511
 ---
 L3:
+-live-
 int_return $-22
 ---
 L4:
+-live-
 int_return $81
 ---
 L5:
+-live-
 int_return $17
 ---
 L6:
+-live-
 int_return $54
 """)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix test

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r74752:32796dba665f
Date: 2014-11-28 14:24 +0100
http://bitbucket.org/pypy/pypy/changeset/32796dba665f/

Log:fix test

diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py 
b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -1,4 +1,4 @@
-import py
+import py, sys
 from rpython.rlib.objectmodel import instantiate
 from rpython.jit.metainterp import compile, resume
 from rpython.jit.metainterp.history import AbstractDescr, ConstInt, BoxInt, 
TreeLoop
@@ -190,6 +190,11 @@
 args = []
 for _ in range(oparity[opnum]):
 args.append(random.randrange(1, 20))
+if opnum == rop.INT_SIGNEXT:
+# 2nd arg is number of bytes to extend from ---
+# must not be too random
+args[-1] = random.choice([1, 2] if sys.maxint < 2**32 else
+ [1, 2, 4])
 ops = """
 []
 i1 = %s(%s)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix test

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r74754:ec0b383167ab
Date: 2014-11-28 14:56 +0100
http://bitbucket.org/pypy/pypy/changeset/ec0b383167ab/

Log:fix test

diff --git a/pypy/module/micronumpy/test/test_zjit.py 
b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -127,12 +127,13 @@
 assert result == 3 ** 2
 self.check_trace_count(1)
 self.check_simple_loop({
-'call': 3,
+'call': 1,
 'float_add': 1,
 'float_eq': 3,
 'float_mul': 2,
 'float_ne': 1,
 'getarrayitem_gc': 1,
+'getarrayitem_raw': 1, # read the errno
 'guard_false': 4,
 'guard_not_invalidated': 1,
 'guard_true': 3,
@@ -144,6 +145,7 @@
 'raw_load': 2,
 'raw_store': 1,
 'setarrayitem_gc': 1,
+'setarrayitem_raw': 1, # write the errno
 })
 
 def define_pow_int():
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Support threadlocalref_{addr, get} when running on the llinterp too.

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r74753:0331b21a1685
Date: 2014-11-28 14:51 +0100
http://bitbucket.org/pypy/pypy/changeset/0331b21a1685/

Log:Support threadlocalref_{addr,get} when running on the llinterp too.

diff --git a/rpython/jit/metainterp/test/test_threadlocal.py 
b/rpython/jit/metainterp/test/test_threadlocal.py
--- a/rpython/jit/metainterp/test/test_threadlocal.py
+++ b/rpython/jit/metainterp/test/test_threadlocal.py
@@ -11,10 +11,11 @@
 tlfield = rthread.ThreadLocalField(lltype.Signed, 'foobar_test_')
 
 def f():
+tlfield.setraw(0x544c)
 return tlfield.getraw()
 
 res = self.interp_operations(f, [])
-assert res == 0x544c# magic value returned by llinterp
+assert res == 0x544c
 
 
 class TestLLtype(ThreadLocalTest, LLJitMixin):
diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py
--- a/rpython/rlib/rthread.py
+++ b/rpython/rlib/rthread.py
@@ -286,11 +286,13 @@
 _threadlocalref_seeme(self)
 return llop.threadlocalref_get(FIELDTYPE, offset)
 
+@jit.dont_look_inside
 def get_or_make_raw():
 _threadlocalref_seeme(self)
 addr = llop.threadlocalref_addr(llmemory.Address)
 return llop.raw_load(FIELDTYPE, addr, offset)
 
+@jit.dont_look_inside
 def setraw(value):
 _threadlocalref_seeme(self)
 addr = llop.threadlocalref_addr(llmemory.Address)
diff --git a/rpython/rlib/test/test_rthread.py 
b/rpython/rlib/test/test_rthread.py
--- a/rpython/rlib/test/test_rthread.py
+++ b/rpython/rlib/test/test_rthread.py
@@ -52,6 +52,18 @@
 assert get_ident() == thread.get_ident()
 
 
+def test_threadlocalref_on_llinterp():
+from rpython.rtyper.test.test_llinterp import interpret
+tlfield = ThreadLocalField(lltype.Signed, "rthread_test_")
+#
+def f():
+x = tlfield.setraw(42)
+return tlfield.getraw()
+#
+res = interpret(f, [])
+assert res == 42
+
+
 class AbstractThreadTests(AbstractGCTestClass):
 use_threads = True
 
diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py
--- a/rpython/rtyper/llinterp.py
+++ b/rpython/rtyper/llinterp.py
@@ -133,6 +133,19 @@
 for line in lines:
 log.traceback(line)
 
+def get_tlobj(self):
+try:
+return self._tlobj
+except AttributeError:
+from rpython.rtyper.lltypesystem import rffi
+PERRNO = rffi.CArrayPtr(rffi.INT)
+fake_p_errno = lltype.malloc(PERRNO.TO, 1, flavor='raw', zero=True,
+ track_allocation=False)
+self._tlobj = {'RPY_TLOFS_p_errno': fake_p_errno,
+   #'thread_ident': ...,
+   }
+return self._tlobj
+
 def find_roots(self):
 """Return a list of the addresses of the roots."""
 #log.findroots("starting")
@@ -920,13 +933,11 @@
 return 0
 
 def op_threadlocalref_addr(self):
-raise NotImplementedError("threadlocalref_addr")
+return _address_of_thread_local()
 
-def op_threadlocalref_get(self, offset):
-if (type(offset) is CDefinedIntSymbolic and
-offset.expr == 'RPY_TLOFS_foobar_test_'):   # used in tests
-return 0x544c
-raise NotImplementedError("threadlocalref_get")
+def op_threadlocalref_get(self, RESTYPE, offset):
+return self.op_raw_load(RESTYPE, _address_of_thread_local(), offset)
+op_threadlocalref_get.need_result_type = True
 
 # __
 # operations on addresses
@@ -973,9 +984,9 @@
 ll_p = rffi.cast(rffi.CArrayPtr(RESTYPE),
  rffi.ptradd(ll_p, offset))
 value = ll_p[0]
-## elif getattr(addr, 'is_fake_thread_local_addr', False):
-## assert type(offset) is CDefinedIntSymbolic
-## value = self.llinterpreter.tlobj[offset.expr]
+elif getattr(addr, 'is_fake_thread_local_addr', False):
+assert type(offset) is CDefinedIntSymbolic
+value = self.llinterpreter.get_tlobj()[offset.expr]
 else:
 assert offset.TYPE == RESTYPE
 value = getattr(addr, str(RESTYPE).lower())[offset.repeat]
@@ -996,9 +1007,9 @@
 ll_p = rffi.cast(rffi.CArrayPtr(ARGTYPE),
  rffi.ptradd(ll_p, offset))
 ll_p[0] = value
-## elif getattr(addr, 'is_fake_thread_local_addr', False):
-## assert type(offset) is CDefinedIntSymbolic
-## self.llinterpreter.tlobj[offset.expr] = value
+elif getattr(addr, 'is_fake_thread_local_addr', False):
+assert type(offset) is CDefinedIntSymbolic
+self.llinterpreter.get_tlobj()[offset.expr] = value
 else:
 assert offset.TYPE == ARGTYPE
 getattr(addr, str(ARGTYPE).lower()

[pypy-commit] pypy default: Remove 'int_signext' on an argument that is already known to be

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r74755:f6c90881b77f
Date: 2014-11-28 15:14 +0100
http://bitbucket.org/pypy/pypy/changeset/f6c90881b77f/

Log:Remove 'int_signext' on an argument that is already known to be
within bounds. This would be a no-op. Shows up in:

 getarrayitem_raw(non-full-word)

 int_signext

 setarrayitem_raw(non-full-word)

diff --git a/rpython/jit/metainterp/optimizeopt/intbounds.py 
b/rpython/jit/metainterp/optimizeopt/intbounds.py
--- a/rpython/jit/metainterp/optimizeopt/intbounds.py
+++ b/rpython/jit/metainterp/optimizeopt/intbounds.py
@@ -343,11 +343,17 @@
 self.emit_operation(op)
 
 def optimize_INT_SIGNEXT(self, op):
-self.emit_operation(op)
-v1 = self.getvalue(op.result)
+value = self.getvalue(op.getarg(0))
 numbits = op.getarg(1).getint() * 8
-v1.intbound.make_ge(IntLowerBound(-(1 << (numbits - 1
-v1.intbound.make_lt(IntUpperBound(1 << (numbits - 1)))
+start = -(1 << (numbits - 1))
+stop = 1 << (numbits - 1)
+bounds = IntBound(start, stop - 1)
+if bounds.contains_bound(value.intbound):
+self.make_equal_to(op.result, value)
+else:
+self.emit_operation(op)
+vres = self.getvalue(op.result)
+vres.intbound.intersect(bounds)
 
 def optimize_ARRAYLEN_GC(self, op):
 self.emit_operation(op)
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py 
b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -5494,6 +5494,41 @@
 """
 self.optimize_loop(ops, expected)
 
+def test_int_signext_already_in_bounds(self):
+ops = """
+[i0]
+i1 = int_signext(i0, 1)
+i2 = int_signext(i1, 2)
+jump(i2)
+"""
+expected = """
+[i0]
+i1 = int_signext(i0, 1)
+jump(i1)
+"""
+self.optimize_loop(ops, expected)
+#
+ops = """
+[i0]
+i1 = int_signext(i0, 1)
+i2 = int_signext(i1, 1)
+jump(i2)
+"""
+expected = """
+[i0]
+i1 = int_signext(i0, 1)
+jump(i1)
+"""
+self.optimize_loop(ops, expected)
+#
+ops = """
+[i0]
+i1 = int_signext(i0, 2)
+i2 = int_signext(i1, 1)
+jump(i2)
+"""
+self.optimize_loop(ops, ops)
+
 
 class TestLLtype(BaseTestOptimizeBasic, LLtypeMixin):
 pass
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix test

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r74756:7840fc043a0b
Date: 2014-11-28 15:17 +0100
http://bitbucket.org/pypy/pypy/changeset/7840fc043a0b/

Log:fix test

diff --git a/pypy/module/pypyjit/test_pypy_c/test_ffi.py 
b/pypy/module/pypyjit/test_pypy_c/test_ffi.py
--- a/pypy/module/pypyjit/test_pypy_c/test_ffi.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_ffi.py
@@ -342,9 +342,9 @@
 guard_false(i114, descr=...)
 --TICK--
 i119 = call(ConstClass(_ll_1_raw_malloc_varsize__Signed), 6, 
descr=)
-raw_store(i119, 0, i116, descr=)
-raw_store(i119, 2, i116, descr=)
-raw_store(i119, 4, i116, descr=)
+raw_store(i119, 0, i112, descr=)
+raw_store(i119, 2, i112, descr=)
+raw_store(i119, 4, i112, descr=)
 setfield_gc(p167, i119, descr=)
 i123 = arraylen_gc(p67, descr=)
 jump(..., descr=...)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] creflect default: Transform function argument types as C does

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r101:23d40e0eea11
Date: 2014-11-28 17:25 +0100
http://bitbucket.org/cffi/creflect/changeset/23d40e0eea11/

Log:Transform function argument types as C does

diff --git a/creflect/cparser.py b/creflect/cparser.py
--- a/creflect/cparser.py
+++ b/creflect/cparser.py
@@ -249,8 +249,10 @@
 return model.FunctionType(tuple(args), result, ellipsis)
 
 def _as_func_arg(self, type):
-if isinstance(type, (model.ArrayType, model.FunctionType)):
-return model.PointerType(type.item)
+if isinstance(type, model.ArrayType):
+return model.PointerType(type.item, const=False)
+elif isinstance(type, model.FunctionType):
+return model.PointerType(type, const=False)
 else:
 return type
 
diff --git a/test/codegen/func-005.c b/test/codegen/func-005.c
new file mode 100644
--- /dev/null
+++ b/test/codegen/func-005.c
@@ -0,0 +1,41 @@
+void f(int[], long(char, short));
+
+# 
+
+void f(int a[], long g(char, short)) { }
+
+# 
+
+static void testfunc_005__c_f(void *args[], void *result) {
+f(*(int **)args[0], *(long (**)(char, short))args[1]);
+}
+
+static void testfunc_005__d_f(int *a0, long (*a1)(char, short)) {
+f(a0, a1);
+}
+
+static void testfunc_005__f4(void *func, void *args[], void *result) {
+long (*f)(char, short) = func;
+*(long *)result = f(*(char *)args[0], *(short *)args[1]);
+}
+
+void testfunc_005(crx_builder_t *cb)
+{
+crx_type_t *t1, *t2, *t3, *t4, *t5, *t6, *a7[2], *t8, *t9, *a10[2];
+{
+t1 = cb->get_void_type(cb);
+t2 = cb->get_signed_type(cb, sizeof(int), "int");
+t3 = cb->get_pointer_type(cb, t2);
+t4 = cb->get_signed_type(cb, sizeof(long), "long");
+t5 = cb->get_char_type(cb);
+t6 = cb->get_signed_type(cb, sizeof(short), "short");
+a7[0] = t5;
+a7[1] = t6;
+t8 = cb->get_function_type(cb, t4, a7, 2, &testfunc_005__f4);
+t9 = cb->get_pointer_type(cb, t8);
+a10[0] = t3;
+a10[1] = t9;
+cb->define_func(cb, "f", t1, a10, 2, &testfunc_005__c_f, 
&testfunc_005__d_f);
+#expect FUNC f: PTR int -> PTR FUNC( char -> short -> long ) -> void
+}
+}
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] creflect default: A tool in C to dump the reflection information stored in a library

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r102:538bc1da9a17
Date: 2014-11-28 17:48 +0100
http://bitbucket.org/cffi/creflect/changeset/538bc1da9a17/

Log:A tool in C to dump the reflection information stored in a library
compiled from the output of "creflect".

diff --git a/creflect/src/creflect_check.c b/creflect/src/creflect_check.c
new file mode 100644
--- /dev/null
+++ b/creflect/src/creflect_check.c
@@ -0,0 +1,54 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "creflect.h"
+#include "creflect_print.h"
+
+
+void creflect_dump_information(const char *filename)
+{
+char filename_ex[PATH_MAX];
+
+if (strchr(filename, '/') == NULL)
+strcpy(filename_ex, "./");
+else
+strcpy(filename_ex, "");
+strncat(filename_ex, filename, sizeof(filename_ex) - 3);
+
+void *lib = dlopen(filename_ex, RTLD_LAZY);
+if (lib == NULL)
+goto err;
+
+void (*crxmain)(crx_builder_t *);
+crxmain = (void(*)(crx_builder_t *))dlsym(lib, "_creflect_main");
+if (crxmain == NULL)
+goto err;
+
+crxmain(&maincb);
+
+if (dlclose(lib) != 0) {
+lib = NULL;
+goto err;
+}
+return;
+
+ err:
+fprintf(stderr, "error: %s\n", dlerror());
+if (lib)
+dlclose(lib);
+}
+
+int main(int argc, char *argv[])
+{
+if (argc != 2) {
+fprintf(stderr, "One argument needed: the name of the library file"
+" out of which the creflect information is dumped.\n");
+return 2;
+}
+creflect_dump_information(argv[1]);
+return 0;
+}
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] creflect default: The next part is a bit annoying and requires delaying the calls to

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r105:aeb1f133cab1
Date: 2014-11-29 01:35 +0100
http://bitbucket.org/cffi/creflect/changeset/aeb1f133cab1/

Log:The next part is a bit annoying and requires delaying the calls to
cb->get_xxx_type()

diff --git a/creflect/src/c_decl_parser.c b/creflect/src/c_decl_parser.c
--- a/creflect/src/c_decl_parser.c
+++ b/creflect/src/c_decl_parser.c
@@ -1,4 +1,5 @@
 #include 
+#include 
 #include 
 #include "creflect.h"
 
@@ -35,11 +36,15 @@
 TOK_VOID,
 };
 
+#define NUM_DELAY_SLOTS   5000
+
 typedef struct {
 enum crxp_token_e kind;
 const char *p;
 size_t size;
 crx_builder_t *cb;
+intptr_t *delay_slots;
+intptr_t all_delay_slots[NUM_DELAY_SLOTS];
 } crxp_token_t;
 
 static int is_space(char x)
@@ -134,48 +139,95 @@
 }
 }
 
-static crx_type_t *parse_sequel_right(crxp_token_t *tok, crx_type_t *t1)
+static intptr_t *alloc_ds(crxp_token_t *tok, size_t num)
 {
+intptr_t *result = tok->delay_slots;
+if (num > (tok->all_delay_slots + NUM_DELAY_SLOTS - tok->delay_slots))
+abort();  // XXX out of memory
+tok->delay_slots += num;
+return result;
+}
+
+static void parse_sequel(crxp_token_t *tok, intptr_t ds_end)
+{
+while (tok->kind == TOK_STAR || tok->kind == TOK_CONST) {
+alloc_ds(tok, 1)[0] = tok->kind;
+next_token(tok);
+}
+
+intptr_t *ds, *jump_slot = alloc_ds(tok, 1);
+*jump_slot = ds_end;
+
+ next_right_part:
 switch (tok->kind) {
 
 case TOK_OPEN_PAREN:
-abort();
+/* just parentheses for grouping */
+next_token(tok);
+
+ds = tok->delay_slots;
+parse_sequel(tok, *jump_slot);
+*jump_slot = -(ds - tok->all_delay_slots);
+
+assert(tok->kind == TOK_CLOSE_PAREN);  // XXX
+next_token(tok);
+goto next_right_part;
 
 case TOK_OPEN_BRACKET:
 next_token(tok);
 assert(tok->kind == TOK_INTEGER);  // XXX
-unsigned long long length = strtoull(tok->p, NULL, 10);
+
+uintptr_t length;
+if (sizeof(uintptr_t) > sizeof(unsigned long))
+length = strtoull(tok->p, NULL, 10);
+else
+length = strtoul(tok->p, NULL, 10);
 next_token(tok);
+
 assert(tok->kind == TOK_CLOSE_BRACKET);  // XXX
 next_token(tok);
-t1 = parse_sequel_right(tok, t1);
-t1 = tok->cb->get_array_type(tok->cb, t1, (size_t)length);
-break;
+
+ds = alloc_ds(tok, 3);
+ds[0] = TOK_OPEN_BRACKET;
+ds[1] = (intptr_t)length;
+ds[2] = *jump_slot;
+*jump_slot = -(ds - tok->all_delay_slots);
+goto next_right_part;
 
 default:
 break;
 }
-return t1;
 }
 
-static crx_type_t *parse_sequel(crxp_token_t *tok, crx_type_t *t1)
+static crx_type_t *fetch_delay_slots(crxp_token_t *tok, crx_type_t *t1,
+ intptr_t *delay_slot)
 {
+tok->delay_slots = delay_slot;
 while (1) {
-switch (tok->kind) {
-
-case TOK_STAR:
-t1 = tok->cb->get_pointer_type(tok->cb, t1);
-break;
-
-case TOK_CONST:
-t1 = tok->cb->get_const_type(tok->cb, t1);
-break;
-
-default:
-return parse_sequel_right(tok, t1);
+intptr_t tok_kind = *delay_slot++;
+if (tok_kind > 0) {
+switch (tok_kind) {
+case TOK_END:
+return t1;
+case TOK_STAR:
+t1 = tok->cb->get_pointer_type(tok->cb, t1);
+break;
+case TOK_CONST:
+t1 = tok->cb->get_const_type(tok->cb, t1);
+break;
+case TOK_OPEN_BRACKET:   /* array */
+{
+uintptr_t length = (uintptr_t)*delay_slot++;
+t1 = tok->cb->get_array_type(tok->cb, t1, length);
+break;
+}
+default:
+abort();
+}
 }
-
-next_token(tok);
+else {
+delay_slot = tok->all_delay_slots + (-tok_kind);
+}
 }
 }
 
@@ -192,29 +244,32 @@
 break;
 default:
 tok->kind = TOK_ERROR;
-return NULL;
+return;
 }
 next_token(tok);
 
 if (is_const) {
 t1 = tok->cb->get_const_type(tok->cb, t1);
 }
-return parse_sequel(tok, t1);
+
+intptr_t *orig = tok->delay_slots;
+parse_sequel(tok, TOK_END);
+return fetch_delay_slots(tok, t1, orig);
 }
 
-crx_type_t *creflect_decl_parser(crx_builder_t *cb, const char **input)
+const char *creflect_decl_parser(crx_builder_t *cb, const char *input,
+ crx_type_t **result)
 {
 crxp_token_t token;
-crx_type_t *t1;
 token.kind = TOK_START;
 token.cb = cb;
-token.p = *input;
+token.p = input;
 token.size = 0;
+token.delay_slots = token.all_delay_slots;
 next_token(&token);
-t1 = parse_complete(&token);
+*result = pars

[pypy-commit] creflect default: Parsing simple C declarations, starting

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r103:1ad5d2bb1fa5
Date: 2014-11-28 23:11 +0100
http://bitbucket.org/cffi/creflect/changeset/1ad5d2bb1fa5/

Log:Parsing simple C declarations, starting

diff --git a/creflect/src/c_decl_parser.c b/creflect/src/c_decl_parser.c
new file mode 100644
--- /dev/null
+++ b/creflect/src/c_decl_parser.c
@@ -0,0 +1,197 @@
+#include 
+#include "creflect.h"
+
+
+enum crxp_token_e {
+TOK_STAR='*',
+TOK_OPEN_PAREN='(',
+TOK_CLOSE_PAREN=')',
+TOK_OPEN_BRACKET='[',
+TOK_CLOSE_BRACKET=']',
+TOK_COMMA=',',
+
+TOK_START=256,
+TOK_END,
+TOK_ERROR,
+TOK_IDENTIFIER,
+TOK_INTEGER,
+
+/* keywords */
+TOK__BOOL,
+TOK_CHAR,
+//TOK__COMPLEX,
+TOK_CONST,
+TOK_DOUBLE,
+TOK_FLOAT,
+//TOK__IMAGINARY,
+TOK_INT,
+TOK_LONG,
+TOK_SHORT,
+TOK_SIGNED,
+TOK_STRUCT,
+TOK_UNION,
+TOK_UNSIGNED,
+TOK_VOID,
+};
+
+typedef struct {
+enum crxp_token_e kind;
+const char *p;
+size_t size;
+crx_builder_t *cb;
+} crxp_token_t;
+
+static int is_space(char x)
+{
+return (x == ' ' || x == '\f' || x == '\n' || x == '\r' ||
+x == '\t' || x == '\v');
+}
+
+static int is_ident_first(char x)
+{
+return ('A' <= x && x <= 'Z' || 'a' <= x && x <= 'z' || x == '_');
+}
+
+static int is_ident_next(char x)
+{
+return (is_ident_first(x) || '0' <= x && x <= '9');
+}
+
+static void next_token(crxp_token_t *tok)
+{
+const char *p = tok->p + tok->size;
+if (tok->kind == TOK_ERROR)
+return;
+while (!is_ident_first(*p)) {
+if (is_space(*p)) {
+p++;
+}
+else if (*p) {
+tok->kind = *p;
+tok->p = p;
+tok->size = 1;
+return;
+}
+else {
+tok->kind = TOK_END;
+tok->p = p;
+tok->size = 0;
+return;
+}
+}
+tok->p = p;
+tok->size = 1;
+while (is_ident_next(p[tok->size]))
+tok->size++;
+tok->kind = TOK_IDENTIFIER;
+
+switch (*p) {
+case '_':
+if (tok->size == 5 && !memcmp(p, "_Bool", 5))  tok->kind = TOK__BOOL;
+break;
+case 'c':
+if (tok->size == 4 && !memcmp(p, "char", 4))   tok->kind = TOK_CHAR;
+if (tok->size == 5 && !memcmp(p, "const", 5))  tok->kind = TOK_CONST;
+break;
+case 'd':
+if (tok->size == 6 && !memcmp(p, "double", 6)) tok->kind = TOK_DOUBLE;
+break;
+case 'f':
+if (tok->size == 5 && !memcmp(p, "float", 5))  tok->kind = TOK_FLOAT;
+break;
+case 'i':
+if (tok->size == 3 && !memcmp(p, "int", 3))tok->kind = TOK_INT;
+break;
+case 'l':
+if (tok->size == 4 && !memcmp(p, "long", 4))   tok->kind = TOK_LONG;
+break;
+case 's':
+if (tok->size == 5 && !memcmp(p, "short", 5))  tok->kind = TOK_SHORT;
+if (tok->size == 6 && !memcmp(p, "signed", 6)) tok->kind = TOK_SIGNED;
+if (tok->size == 6 && !memcmp(p, "struct", 6)) tok->kind = TOK_STRUCT;
+break;
+case 'u':
+if (tok->size == 5 && !memcmp(p, "union", 5))  tok->kind = TOK_UNION;
+if (tok->size == 8 && !memcmp(p,"unsigned",8)) tok->kind = 
TOK_UNSIGNED;
+break;
+case 'v':
+if (tok->size == 4 && !memcmp(p, "void", 4))   tok->kind = TOK_VOID;
+break;
+}
+}
+
+static crx_type_t *parse_sequel_right(crxp_token_t *tok, crx_type_t *t1)
+{
+switch (tok->kind) {
+
+case TOK_OPEN_PAREN:
+abort();
+
+case TOK_OPEN_BRACKET:
+abort();
+
+default:
+return t1;
+}
+}
+
+static crx_type_t *parse_sequel(crxp_token_t *tok, crx_type_t *t1)
+{
+while (1) {
+switch (tok->kind) {
+
+case TOK_STAR:
+t1 = tok->cb->get_pointer_type(tok->cb, t1);
+break;
+
+case TOK_CONST:
+t1 = tok->cb->get_const_type(tok->cb, t1);
+break;
+
+default:
+return parse_sequel_right(tok, t1);
+}
+
+next_token(tok);
+}
+}
+
+static crx_type_t *parse_complete(crxp_token_t *tok)
+{
+crx_type_t *t1;
+int is_const = (tok->kind == TOK_CONST);
+if (is_const) {
+next_token(tok);
+}
+switch (tok->kind) {
+case TOK_INT:
+t1 = tok->cb->get_signed_type(tok->cb, sizeof(int), "int");
+break;
+default:
+tok->kind = TOK_ERROR;
+return NULL;
+}
+next_token(tok);
+
+if (is_const) {
+t1 = tok->cb->get_const_type(tok->cb, t1);
+}
+return parse_sequel(tok, t1);
+}
+
+crx_type_t *creflect_decl_parser(crx_builder_t *cb, const char **input)
+{
+crxp_token_t token;
+crx_type_t *t1;
+token.kind = TOK_START;
+token.cb = cb;
+token.p = *input;
+token.size = 0;
+next_token(&token);
+t1 = parse_complete(&token);
+
+if (token.kind == TOK_END)
+return t1;
+*input = token.p;
+return NULL;
+}
diff --git a

[pypy-commit] creflect default: simple arrays

2014-11-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r104:388bb851de61
Date: 2014-11-28 23:18 +0100
http://bitbucket.org/cffi/creflect/changeset/388bb851de61/

Log:simple arrays

diff --git a/creflect/src/c_decl_parser.c b/creflect/src/c_decl_parser.c
--- a/creflect/src/c_decl_parser.c
+++ b/creflect/src/c_decl_parser.c
@@ -1,4 +1,5 @@
 #include 
+#include 
 #include "creflect.h"
 
 
@@ -52,9 +53,14 @@
 return ('A' <= x && x <= 'Z' || 'a' <= x && x <= 'z' || x == '_');
 }
 
+static int is_digit(char x)
+{
+return ('0' <= x && x <= '9');
+}
+
 static int is_ident_next(char x)
 {
-return (is_ident_first(x) || '0' <= x && x <= '9');
+return (is_ident_first(x) || is_digit(x));
 }
 
 static void next_token(crxp_token_t *tok)
@@ -66,6 +72,14 @@
 if (is_space(*p)) {
 p++;
 }
+else if (is_digit(*p)) {
+tok->kind = TOK_INTEGER;
+tok->p = p;
+tok->size = 1;
+while (is_digit(p[tok->size]))
+tok->size++;
+return;
+}
 else if (*p) {
 tok->kind = *p;
 tok->p = p;
@@ -79,11 +93,11 @@
 return;
 }
 }
+tok->kind = TOK_IDENTIFIER;
 tok->p = p;
 tok->size = 1;
 while (is_ident_next(p[tok->size]))
 tok->size++;
-tok->kind = TOK_IDENTIFIER;
 
 switch (*p) {
 case '_':
@@ -128,11 +142,20 @@
 abort();
 
 case TOK_OPEN_BRACKET:
-abort();
+next_token(tok);
+assert(tok->kind == TOK_INTEGER);  // XXX
+unsigned long long length = strtoull(tok->p, NULL, 10);
+next_token(tok);
+assert(tok->kind == TOK_CLOSE_BRACKET);  // XXX
+next_token(tok);
+t1 = parse_sequel_right(tok, t1);
+t1 = tok->cb->get_array_type(tok->cb, t1, (size_t)length);
+break;
 
 default:
-return t1;
+break;
 }
+return t1;
 }
 
 static crx_type_t *parse_sequel(crxp_token_t *tok, crx_type_t *t1)
diff --git a/test/test_c_decl_parser.py b/test/test_c_decl_parser.py
--- a/test/test_c_decl_parser.py
+++ b/test/test_c_decl_parser.py
@@ -50,9 +50,9 @@
 parse("int const **", "PTR PTR CONST int")
 parse("int *const *", "PTR CONST PTR int")
 parse("int ** const", "CONST PTR PTR int")
+parse("int[2]", "ARRAY[2] int")
+parse("int*[2][3]", "ARRAY[2] ARRAY[3] PTR int")
 import py; py.test.skip("in-progress")
-parse("int[2]")
-parse("int*[2][3]")
 parse("int(*)[2][3]")
 parse("int(*[2])[3]")
 parse("int()")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Make python2.6 compatible, which I think we still care about?

2014-11-28 Thread alex_gaynor
Author: Alex Gaynor 
Branch: 
Changeset: r74757:bd8d6cf8f8be
Date: 2014-11-28 19:50 -0600
http://bitbucket.org/pypy/pypy/changeset/bd8d6cf8f8be/

Log:Make python2.6 compatible, which I think we still care about?

diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -617,7 +617,7 @@
 if simplify_phis(block):
 progress = True
 
-renaming = {key: uf[key].rep for key in uf}
+renaming = dict((key, uf[key].rep) for key in uf)
 for block, links in entrymap.items():
 if inputs[block]:
 new_inputs, new_args = zip(*inputs[block])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit