[pypy-svn] r45348 - pypy/dist/pypy/lang/scheme
jlg at codespeak.net
jlg at codespeak.net
Thu Jul 26 16:24:41 CEST 2007
Author: jlg
Date: Thu Jul 26 16:24:40 2007
New Revision: 45348
Modified:
pypy/dist/pypy/lang/scheme/execution.py
pypy/dist/pypy/lang/scheme/object.py
Log:
MacroClosure is no more; SyntacticClosure already has self.closure
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 16:24:40 2007
@@ -80,12 +80,18 @@
self.closure = closure
+ def _dispatch(self, symb):
+ if isinstance(symb, W_Symbol):
+ return (self, symb.name)
+ elif isinstance(symb, SyntacticClosure) and \
+ isinstance(symb.sexpr, W_Symbol):
+ return (symb.closure, symb.sexpr.name)
+
+ raise SchemeSyntaxError
+
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:
@@ -131,6 +137,10 @@
else:
self.put(name, obj)
+ def sput(self, symb, obj):
+ (ctx, name) = self._dispatch(symb)
+ ctx.put(name, obj)
+
def put(self, name, obj):
"""create new location"""
assert isinstance(obj, W_Root)
@@ -159,24 +169,3 @@
return loc
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 16:24:40 2007
@@ -660,13 +660,9 @@
w_formal = lst.car
while isinstance(w_formal, W_Pair):
w_def = w_formal.get_car_as_pair()
- name = w_def.car.to_string()
#evaluate the values in caller ctx
w_val = w_def.get_cdr_as_pair().car.eval(ctx)
- if isinstance(w_def.car, SyntacticClosure):
- local_ctx.sput(name, w_val)
- else:
- local_ctx.put(name, w_val)
+ local_ctx.sput(w_def.car, w_val)
w_formal = w_formal.cdr
return self.eval_body(local_ctx, lst.cdr)
@@ -680,10 +676,9 @@
w_formal = lst.car
while isinstance(w_formal, W_Pair):
w_def = w_formal.get_car_as_pair()
- name = w_def.car.to_string()
#evaluate the values in local ctx
w_val = w_def.get_cdr_as_pair().car.eval(local_ctx)
- local_ctx.put(name, w_val)
+ local_ctx.sput(w_def.car, w_val)
w_formal = w_formal.cdr
return self.eval_body(local_ctx, lst.cdr)
@@ -971,6 +966,6 @@
# 2. in which macro is called - ctx
# 3. in which macro is expanded, and can introduce new bindings - expand_ctx
expanded = self.expand(sexpr, ctx)
- expand_ctx = self.closure.macro(ctx)
+ expand_ctx = self.closure.copy()
return expanded.eval(expand_ctx)
More information about the Pypy-commit
mailing list