[pypy-svn] rev 2337 - pypy/trunk/src/pypy/objspace

rxe at codespeak.net rxe at codespeak.net
Mon Dec 15 17:34:22 CET 2003


Author: rxe
Date: Mon Dec 15 17:34:21 2003
New Revision: 2337

Modified:
   pypy/trunk/src/pypy/objspace/trace.py
Log:
Test


Modified: pypy/trunk/src/pypy/objspace/trace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/trace.py	(original)
+++ pypy/trunk/src/pypy/objspace/trace.py	Mon Dec 15 17:34:21 2003
@@ -7,8 +7,18 @@
 from pypy.interpreter.pycode import PyCode
 debug = 0
 
+class Logger(object):
+    def __init__(self, fn, printme):
+        self.fn = fn
+        self.printme = printme
+        
+    def __call__(self, cls, *args, **kwds):
+        print "%s (%s, %s)" % (self.printme, str(args), str(kwds)) 
+        return self.fn(*args, **kwds)
+
+        
 # ______________________________________________________________________
-class TraceObjSpace(ObjSpace):
+class TraceObjSpace(StdObjSpace):
     full_exceptions = False
     
     def initialize(self):
@@ -19,19 +29,16 @@
                 print "key: %s" % key
                 setattr(self, key, item)
             else:
-                def logger(self, *args, **kwargs):
-                    print "instance method %s, args: %s" % (key, args)
-                    return item(*args, **kwargs)
-                setattr(self, key, new.instancemethod(logger, self, TraceObjSpace))
+                l = Logger(item, "instance method")
+                print l
+                setattr(self, key, new.instancemethod(l, self, TraceObjSpace))
 
         for key in space.__class__.__dict__.keys():
             item = getattr(space, key)
             if callable(item) and not key.startswith('__'):
-                def logger(self, *args, **kwargs):
-                    print "class method %s, args: %s" % (key, args)
-                    return item(*args, **kwargs)
-
-                setattr(self, key, new.instancemethod(logger, self, TraceObjSpace))
+                l = Logger(item, "class method")
+                print l
+                setattr(self, key, new.instancemethod(l, self, TraceObjSpace))
 
     def runx(self, func, *args):
         globals = {}
@@ -57,12 +64,11 @@
 
 
 def runx(space, func, *args):
-    globals = {}
-    w_globals = space.wrap(globals) 
     args_w = [space.wrap(ii) for ii in args]
     ec = space.getexecutioncontext()
     code = func.func_code
     code = PyCode()._from_code(code)
+    w_globals = ec.make_standard_w_globals()  
     frame = code.create_frame(space, w_globals)
     frame.setfastscope(args_w)
     return frame.run()


More information about the Pypy-commit mailing list