[pypy-svn] r26833 - in pypy/dist/pypy/translator/cl: . test
dialtone at codespeak.net
dialtone at codespeak.net
Fri May 5 21:44:57 CEST 2006
Author: dialtone
Date: Fri May 5 21:44:56 2006
New Revision: 26833
Modified:
pypy/dist/pypy/translator/cl/gencl.py
pypy/dist/pypy/translator/cl/opformatter.py
pypy/dist/pypy/translator/cl/test/test_dict.py
Log:
support dict.values()
Modified: pypy/dist/pypy/translator/cl/gencl.py
==============================================================================
--- pypy/dist/pypy/translator/cl/gencl.py (original)
+++ pypy/dist/pypy/translator/cl/gencl.py Fri May 5 21:44:56 2006
@@ -75,15 +75,17 @@
(defun %s (hash)
(let ((current-index -1)
(keys (loop for keys being the hash-keys in hash collect keys)))
- (cons (lambda ()
- (let ((more (<= (incf current-index) (1- (length keys)))))
- (if more
- (let* ((key (nth current-index keys))
- (val (gethash key hash)))
- (values more key val))
- (values nil nil nil))))
- (lambda ()
- (nth current-index keys)))))""" % (name)
+ (list (lambda ()
+ (let ((more (<= (incf current-index) (1- (length keys)))))
+ (if more
+ (let* ((key (nth current-index keys))
+ (val (gethash key hash)))
+ (values more key val))
+ (values nil nil nil))))
+ (lambda ()
+ (nth current-index keys))
+ (lambda ()
+ (gethash (nth current-index keys) hash)))))""" % (name)
self.declarations[name] = (name, definition)
return name
Modified: pypy/dist/pypy/translator/cl/opformatter.py
==============================================================================
--- pypy/dist/pypy/translator/cl/opformatter.py (original)
+++ pypy/dist/pypy/translator/cl/opformatter.py Fri May 5 21:44:56 2006
@@ -214,8 +214,12 @@
def ll_go_next(self):
return """\
(multiple-value-bind (more key value)
- (funcall (car %s))
+ (funcall (first %s))
more)""" % (self.obj,)
def ll_current_key(self):
- return "(funcall (cdr %s))" % (self.obj,)
+ return "(funcall (second %s))" % (self.obj,)
+
+ def ll_current_value(self):
+ return "(funcall (third %s))" % (self.obj,)
+
Modified: pypy/dist/pypy/translator/cl/test/test_dict.py
==============================================================================
--- pypy/dist/pypy/translator/cl/test/test_dict.py (original)
+++ pypy/dist/pypy/translator/cl/test/test_dict.py Fri May 5 21:44:56 2006
@@ -22,5 +22,16 @@
for key in dic:
i = i + dic[key]
return i
- cl_dict_iter = make_cl_func(dict_iter, [])
+ cl_dict_iter = make_cl_func(dict_iter)
assert cl_dict_iter() == 12
+
+def test_dict_values():
+ def dict_values():
+ dic = {1:2, 3:4, 5:6}
+ i = 0
+ for value in dic.values():
+ i = i + value
+ return i
+ cl_dict_value = make_cl_func(dict_values)
+ assert cl_dict_value() == 12
+
More information about the Pypy-commit
mailing list