[pypy-svn] r45478 - in pypy/dist/pypy/lang/scheme: . test
jlg at codespeak.net
jlg at codespeak.net
Fri Aug 3 16:52:29 CEST 2007
Author: jlg
Date: Fri Aug 3 16:52:29 2007
New Revision: 45478
Modified:
pypy/dist/pypy/lang/scheme/object.py
pypy/dist/pypy/lang/scheme/test/test_macro.py
Log:
dirty code to handle with (obj ... ...) like ellipses
Modified: pypy/dist/pypy/lang/scheme/object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/object.py (original)
+++ pypy/dist/pypy/lang/scheme/object.py Fri Aug 3 16:52:29 2007
@@ -1030,7 +1030,21 @@
return {}
- def substituter(self, ctx, sexpr, match_dict):
+ def plst_append(self, plst):
+ first_cons = plst[0]
+
+ last_cons = None
+ for lst in plst:
+ if last_cons is not None:
+ last_cons.cdr = lst
+
+ while isinstance(lst, W_Pair):
+ last_cons = lst
+ lst = lst.cdr
+
+ return first_cons
+
+ def substituter(self, ctx, sexpr, match_dict, flatten=False):
if isinstance(sexpr, W_Pair):
w_car = self.substituter(ctx, sexpr.car, match_dict)
try:
@@ -1040,7 +1054,9 @@
try:
w_cdr = self.substituter(ctx, sexpr.cdr.cdr, match_dict)
except EllipsisTemplate:
- raise NotImplementedError
+ w_inner = W_Pair(sexpr.car, W_Pair(sexpr.cdr.car, w_nil))
+ w_outer = W_Pair(w_inner, sexpr.cdr.cdr)
+ return self.substituter(ctx, w_outer, match_dict, True)
plst = []
mdict_elli = self.find_elli(sexpr.car, match_dict)
@@ -1051,20 +1067,21 @@
for i in range(elli_len):
new_mdict = match_dict.copy()
for (key, val) in mdict_elli.items():
- yyy = val.mdict_lst[i][key]
- new_mdict[key] = yyy
+ new_mdict[key] = val.mdict_lst[i][key]
+
+ sub = self.substituter(ctx, sexpr.car, new_mdict)
+ plst.append(sub)
+
+ if flatten:
+ w_lst = self.plst_append(plst)
- print new_mdict
- zzz = self.substituter(ctx, sexpr.car, new_mdict)
- plst.append(zzz)
+ else:
+ w_lst = plst2lst(plst, w_cdr)
- w_lst = plst2lst(plst, w_cdr)
return w_lst
w_pair = W_Pair(w_car, w_cdr)
if isinstance(w_car, W_Symbol):
- #XXX what if we have here SymbolClosure?
- # can happen when recursive macro
try:
w_macro = ctx.get(w_car.name)
# recursive macro expansion
Modified: pypy/dist/pypy/lang/scheme/test/test_macro.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/test/test_macro.py (original)
+++ pypy/dist/pypy/lang/scheme/test/test_macro.py Fri Aug 3 16:52:29 2007
@@ -400,7 +400,7 @@
"((x y) (1 2 3 4) (+) end)"
def test_nested_ellipsis2():
- py.test.skip("in progress")
+ #py.test.skip("in progress")
ctx = ExecutionContext()
eval_(ctx, """(define-syntax quote-append
(syntax-rules ()
More information about the pypy-svn
mailing list