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

jlg at codespeak.net jlg at codespeak.net
Tue Jul 17 17:19:40 CEST 2007


Author: jlg
Date: Tue Jul 17 17:19:39 2007
New Revision: 45161

Added:
   pypy/dist/pypy/lang/scheme/execution.py   (contents, props changed)
Modified:
   pypy/dist/pypy/lang/scheme/interactive.py
   pypy/dist/pypy/lang/scheme/object.py
   pypy/dist/pypy/lang/scheme/test/test_eval.py
   pypy/dist/pypy/lang/scheme/test/test_object.py
Log:
ExecutionContext and Location moved to execution.py

Added: pypy/dist/pypy/lang/scheme/execution.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/scheme/execution.py	Tue Jul 17 17:19:39 2007
@@ -0,0 +1,151 @@
+from pypy.lang.scheme.object import *
+
+class Location(object):
+    def __init__(self, w_obj=None):
+        self.obj = w_obj
+
+##
+# dict mapping operations to W_Xxx objects
+# callables must have 2 arguments
+# - ctx = execution context
+# - lst = list of arguments
+##
+OMAP = \
+    {
+            #arithmetic operations
+        '+': Add,
+        '-': Sub,
+        '*': Mul,
+        '/': Div,
+            #list operations
+        'cons': Cons,
+        'car': Car,
+        'cdr': Cdr,
+        'list': List,
+        'quit': Quit,
+            #comparisons
+        '=': Equal,
+            #predicates
+        'integer?': IntegerP,
+        'rational?': RealP,
+        'real?': RealP,
+        'complex?': NumberP,
+        'number?': NumberP,
+        'exact?': ExactP,
+        'inexact?': InexactP,
+        'zero?': ZeroP,
+        'odd?': OddP,
+        'even?': EvenP,
+            #delayed evaluation
+        'force': Force,
+        'delay': Delay, #macro
+            #macros
+        'define': Define,
+        'set!': Sete,
+        'if': MacroIf,
+        'lambda': Lambda,
+        'let': Let,
+        'let*': LetStar,
+        'letrec': Letrec,
+        'quote': Quote,
+    }
+
+OPERATION_MAP = {}
+for name, cls in OMAP.items():
+    OPERATION_MAP[name] = Location(cls(name))
+
+class ExecutionContext(object):
+    """Execution context implemented as a dict.
+
+    { "IDENTIFIER": Location(W_Root()) }
+    """
+    def __init__(self, globalscope=None, scope=None, closure=False):
+        if globalscope is None:
+            self.globalscope = OPERATION_MAP.copy()
+        else:
+            self.globalscope = globalscope
+
+        if scope is None:
+            self.scope = {}
+        else:
+            self.scope = scope
+
+        self.closure = closure
+
+    def copy(self):
+        return ExecutionContext(self.globalscope, self.scope.copy(), True)
+
+    def get(self, name):
+        loc = self.scope.get(name, None)
+        if loc is not None:
+            if loc.obj is None:
+                raise UnboundVariable(name)
+            return loc.obj
+
+        loc = self.globalscope.get(name, None)
+        if loc is not None:
+            if loc.obj is None:
+                raise UnboundVariable(name)
+            return loc.obj
+
+        raise UnboundVariable(name)
+
+    def sete(self, name, obj):
+        """update existing location or raise
+        directly used by (set! <var> <expr>) macro
+        """
+        assert isinstance(obj, W_Root)
+        loc = self.scope.get(name, None)
+        if loc is not None:
+            loc.obj = obj
+            return obj
+
+        loc = self.globalscope.get(name, None)
+        if loc is not None:
+            loc.obj = obj
+            return obj
+
+        raise UnboundVariable(name)
+
+    def set(self, name, obj):
+        """update existing location or create new location"""
+        assert isinstance(obj, W_Root)
+        if self.closure:
+            loc = self.scope.get(name, None)
+        else:
+            loc = self.globalscope.get(name, None)
+
+        if loc is not None:
+            loc.obj = obj
+        else:
+            self.put(name, obj)
+
+    def put(self, name, obj):
+        """create new location"""
+        assert isinstance(obj, W_Root)
+        if self.closure:
+            self.scope[name] = Location(obj)
+        else:
+            self.globalscope[name] = Location(obj)
+
+    def bound(self, name):
+        """create new location"""
+        if self.closure:
+            self.scope[name] = Location(None)
+        else:
+            self.globalscope[name] = Location(None)
+
+    def get_location(self, name):
+        """internal/test use only
+        returns location bound to variable
+        """
+        loc = self.scope.get(name, None)
+        if loc is not None:
+            return loc
+
+        loc = self.globalscope.get(name, None)
+        if loc is not None:
+            return loc
+
+        return None
+

Modified: pypy/dist/pypy/lang/scheme/interactive.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/interactive.py	(original)
+++ pypy/dist/pypy/lang/scheme/interactive.py	Tue Jul 17 17:19:39 2007
@@ -3,8 +3,8 @@
 scheme interpreter
 """
 import autopath
-from pypy.lang.scheme.object import ExecutionContext, SchemeException, \
-        SchemeQuit
+from pypy.lang.scheme.object import SchemeException, SchemeQuit
+from pypy.lang.scheme.execution import ExecutionContext
 from pypy.lang.scheme.ssparser import parse
 from pypy.rlib.parsing.makepackrat import BacktrackException
 import os, sys

Modified: pypy/dist/pypy/lang/scheme/object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/object.py	(original)
+++ pypy/dist/pypy/lang/scheme/object.py	Tue Jul 17 17:19:39 2007
@@ -669,155 +669,3 @@
 
         return W_Promise(lst.car, ctx)
 
-##
-# Location()
-##
-class Location(object):
-    def __init__(self, w_obj=None):
-        self.obj = w_obj
-
-##
-# dict mapping operations to W_Xxx objects
-# callables must have 2 arguments
-# - ctx = execution context
-# - lst = list of arguments
-##
-OMAP = \
-    {
-            #arithmetic operations
-        '+': Add,
-        '-': Sub,
-        '*': Mul,
-        '/': Div,
-            #list operations
-        'cons': Cons,
-        'car': Car,
-        'cdr': Cdr,
-        'list': List,
-        'quit': Quit,
-            #comparisons
-        '=': Equal,
-            #predicates
-        'integer?': IntegerP,
-        'rational?': RealP,
-        'real?': RealP,
-        'complex?': NumberP,
-        'number?': NumberP,
-        'exact?': ExactP,
-        'inexact?': InexactP,
-        'zero?': ZeroP,
-        'odd?': OddP,
-        'even?': EvenP,
-            #delayed evaluation
-        'force': Force,
-        'delay': Delay, #macro
-            #macros
-        'define': Define,
-        'set!': Sete,
-        'if': MacroIf,
-        'lambda': Lambda,
-        'let': Let,
-        'let*': LetStar,
-        'letrec': Letrec,
-        'quote': Quote,
-    }
-
-OPERATION_MAP = {}
-for name, cls in OMAP.items():
-    OPERATION_MAP[name] = Location(cls(name))
-
-class ExecutionContext(object):
-    """Execution context implemented as a dict.
-
-    { "IDENTIFIER": Location(W_Root()) }
-    """
-    def __init__(self, globalscope=None, scope=None, closure=False):
-        if globalscope is None:
-            self.globalscope = OPERATION_MAP.copy()
-        else:
-            self.globalscope = globalscope
-
-        if scope is None:
-            self.scope = {}
-        else:
-            self.scope = scope
-
-        self.closure = closure
-
-    def copy(self):
-        return ExecutionContext(self.globalscope, self.scope.copy(), True)
-
-    def get(self, name):
-        loc = self.scope.get(name, None)
-        if loc is not None:
-            if loc.obj is None:
-                raise UnboundVariable(name)
-            return loc.obj
-
-        loc = self.globalscope.get(name, None)
-        if loc is not None:
-            if loc.obj is None:
-                raise UnboundVariable(name)
-            return loc.obj
-
-        raise UnboundVariable(name)
-
-    def sete(self, name, obj):
-        """update existing location or raise
-        directly used by (set! <var> <expr>) macro
-        """
-        assert isinstance(obj, W_Root)
-        loc = self.scope.get(name, None)
-        if loc is not None:
-            loc.obj = obj
-            return obj
-
-        loc = self.globalscope.get(name, None)
-        if loc is not None:
-            loc.obj = obj
-            return obj
-
-        raise UnboundVariable(name)
-
-    def set(self, name, obj):
-        """update existing location or create new location"""
-        assert isinstance(obj, W_Root)
-        if self.closure:
-            loc = self.scope.get(name, None)
-        else:
-            loc = self.globalscope.get(name, None)
-
-        if loc is not None:
-            loc.obj = obj
-        else:
-            self.put(name, obj)
-
-    def put(self, name, obj):
-        """create new location"""
-        assert isinstance(obj, W_Root)
-        if self.closure:
-            self.scope[name] = Location(obj)
-        else:
-            self.globalscope[name] = Location(obj)
-
-    def bound(self, name):
-        """create new location"""
-        if self.closure:
-            self.scope[name] = Location(None)
-        else:
-            self.globalscope[name] = Location(None)
-
-    def get_location(self, name):
-        """internal/test use only
-        returns location bound to variable
-        """
-        loc = self.scope.get(name, None)
-        if loc is not None:
-            return loc
-
-        loc = self.globalscope.get(name, None)
-        if loc is not None:
-            return loc
-
-        return None
-

Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/test/test_eval.py	(original)
+++ pypy/dist/pypy/lang/scheme/test/test_eval.py	Tue Jul 17 17:19:39 2007
@@ -1,5 +1,6 @@
 import py
 from pypy.lang.scheme.ssparser import parse
+from pypy.lang.scheme.execution import ExecutionContext
 from pypy.lang.scheme.object import *
 
 def test_eval_obj():

Modified: pypy/dist/pypy/lang/scheme/test/test_object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/test/test_object.py	(original)
+++ pypy/dist/pypy/lang/scheme/test/test_object.py	Tue Jul 17 17:19:39 2007
@@ -1,5 +1,6 @@
 import py
 from pypy.lang.scheme.object import *
+from pypy.lang.scheme.execution import ExecutionContext, Location
 
 def test_false():
     w_false = W_Boolean(False)
@@ -58,7 +59,7 @@
     w_fnum = W_Integer(12)
     w_symb = W_Symbol("symb")
 
-    ctx = ExecutionContext({})
+    ctx = ExecutionContext()
     ctx.put("v1", w_fnum)
     ctx.put("symb", w_symb)
 
@@ -77,7 +78,7 @@
     w_fnum2 = W_Integer(43)
     w_fnum3 = W_Integer(44)
 
-    ctx = ExecutionContext({})
+    ctx = ExecutionContext()
     ctx.put("v1", w_fnum)
 
     ctx2 = ctx.copy()



More information about the Pypy-commit mailing list