[pypy-svn] r45346 - in pypy/dist/pypy/lang/scheme: . test

jlg at codespeak.net jlg at codespeak.net
Thu Jul 26 15:30:26 CEST 2007


Author: jlg
Date: Thu Jul 26 15:30:26 2007
New Revision: 45346

Modified:
   pypy/dist/pypy/lang/scheme/execution.py
   pypy/dist/pypy/lang/scheme/object.py
   pypy/dist/pypy/lang/scheme/test/test_macro.py
Log:
test_shadow passes;  MacroClosure introduced

Modified: pypy/dist/pypy/lang/scheme/execution.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/execution.py	(original)
+++ pypy/dist/pypy/lang/scheme/execution.py	Thu Jul 26 15:30:26 2007
@@ -64,7 +64,7 @@
 
     { "IDENTIFIER": Location(W_Root()) }
     """
-    def __init__(self, globalscope=None, scope=None, closure=False):
+    def __init__(self, globalscope=None, scope=None, closure=False, macro=False):
         if globalscope is None:
             self.globalscope = {}
             for name, oper in OPERATION_MAP.items():
@@ -83,6 +83,9 @@
     def copy(self):
         return ExecutionContext(self.globalscope, self.scope.copy(), True)
 
+    def macro(self, rctx):
+        return MacroClosure(self.globalscope, self.scope.copy(), rctx)
+
     def get(self, name):
         loc = self.scope.get(name, None)
         if loc is not None:
@@ -157,3 +160,23 @@
 
         return None
 
+class MacroClosure(ExecutionContext):
+    def __init__(self, globalscope=None, scope=None, rctx=None):
+        self.globalscope = globalscope
+
+        if scope is None:
+            self.scope = {}
+        else:
+            self.scope = scope
+
+        self.closure = True
+        self.macro = True
+        self.rctx = rctx
+
+    def copy(self):
+        return MacroClosure(self.globalscope, self.scope, self.rctx)
+
+    def sput(self, name, obj):
+        print name, obj
+        return self.rctx.put(name, obj)
+

Modified: pypy/dist/pypy/lang/scheme/object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/object.py	(original)
+++ pypy/dist/pypy/lang/scheme/object.py	Thu Jul 26 15:30:26 2007
@@ -663,7 +663,10 @@
             name = w_def.car.to_string()
             #evaluate the values in caller ctx
             w_val = w_def.get_cdr_as_pair().car.eval(ctx)
-            local_ctx.put(name, w_val)
+            if isinstance(w_def.car, SyntacticClosure):
+                local_ctx.sput(name, w_val)
+            else:
+                local_ctx.put(name, w_val)
             w_formal = w_formal.cdr
 
         return self.eval_body(local_ctx, lst.cdr)
@@ -967,8 +970,7 @@
         # 1. in which macro was defined - self.closure
         # 2. in which macro is called   - ctx
         # 3. in which macro is expanded, and can introduce new bindings - expand_ctx 
-
-        expand_ctx = self.closure.copy()
         expanded = self.expand(sexpr, ctx)
+        expand_ctx = self.closure.macro(ctx)
         return expanded.eval(expand_ctx)
 

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	Thu Jul 26 15:30:26 2007
@@ -162,7 +162,6 @@
     assert ctx.get("counter").to_number() == 5
 
 def test_shadow():
-    py.test.skip("in progress")
     ctx = ExecutionContext()
 
     w_transformer = eval_(ctx, """(syntax-rules ()



More information about the Pypy-commit mailing list