[pypy-svn] r21125 - in pypy/dist/pypy: interpreter module/__builtin__ module/_sre module/recparser objspace/std
arigo at codespeak.net
arigo at codespeak.net
Tue Dec 13 12:12:38 CET 2005
Author: arigo
Date: Tue Dec 13 12:12:35 2005
New Revision: 21125
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/interpreter/function.py
pypy/dist/pypy/interpreter/gateway.py
pypy/dist/pypy/interpreter/main.py
pypy/dist/pypy/interpreter/nestedscope.py
pypy/dist/pypy/interpreter/pyopcode.py
pypy/dist/pypy/interpreter/typedef.py
pypy/dist/pypy/module/__builtin__/importing.py
pypy/dist/pypy/module/_sre/interp_sre.py
pypy/dist/pypy/module/recparser/pyparser.py
pypy/dist/pypy/objspace/std/marshal_impl.py
Log:
Use the new space.interp_w() instead of space.interpclass_w() where it makes
sense to do so.
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Tue Dec 13 12:12:35 2005
@@ -406,7 +406,7 @@
return None
obj = self.interpclass_w(w_obj)
if not isinstance(obj, RequiredClass): # or obj is None
- msg = "expected a %s, got %s instead" % (
+ msg = "'%s' object expected, got '%s' instead" % (
RequiredClass.typedef.name,
w_obj.getclass(self).getname(self, '?'))
raise OperationError(self.w_TypeError, self.wrap(msg))
Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py (original)
+++ pypy/dist/pypy/interpreter/function.py Tue Dec 13 12:12:35 2005
@@ -50,9 +50,7 @@
def descr_method__new__(space, w_subtype, w_code, w_globals,
w_name=None, w_argdefs=None, w_closure=None):
- code = space.interpclass_w(w_code)
- if code is None or not isinstance(code, Code):
- raise OperationError(space.w_TypeError, space.wrap("expected code"))
+ code = space.interp_w(Code, w_code)
if not space.is_true(space.isinstance(w_globals, space.w_dict)):
raise OperationError(space.w_TypeError, space.wrap("expected dict"))
if not space.is_w(w_name, space.w_None):
@@ -79,12 +77,7 @@
raise OperationError(space.w_ValueError, space.wrap("no closure needed"))
elif nfreevars != n:
raise OperationError(space.w_ValueError, space.wrap("closure is wrong size"))
- closure = []
- for w_cell in closure_w:
- cell = space.interpclass_w(w_cell)
- if not isinstance(cell, Cell):
- raise OperationError(space.w_TypeError, space.wrap("non-cell in closure"))
- closure.append(cell)
+ closure = [space.interp_w(Cell, w_cell) for w_cell in closure_w]
func = space.allocate_instance(Function, w_subtype)
Function.__init__(func, space, code, w_globals, defs_w, closure, name)
return space.wrap(func)
@@ -153,9 +146,7 @@
def fset_func_code(space, self, w_code):
from pypy.interpreter.pycode import PyCode
- code = space.interpclass_w(w_code)
- if not isinstance(code, Code):
- raise OperationError(space.w_TypeError, space.wrap("func_code must be set to a code object") )
+ code = space.interp_w(Code, w_code)
closure_len = 0
if self.closure:
closure_len = len(self.closure)
@@ -320,10 +311,7 @@
self.w_module = func.w_module
def descr_method__new__(space, w_subtype, w_func):
- func = space.interpclass_w(w_func)
- if func is None or not isinstance(func, Function):
- raise OperationError(space.w_TypeError,
- space.wrap("expected a function object"))
+ func = space.interp_w(Function, w_func)
bltin = space.allocate_instance(BuiltinFunction, w_subtype)
BuiltinFunction.__init__(bltin, func)
return space.wrap(bltin)
Modified: pypy/dist/pypy/interpreter/gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/gateway.py (original)
+++ pypy/dist/pypy/interpreter/gateway.py Tue Dec 13 12:12:35 2005
@@ -165,13 +165,8 @@
name = el.__name__
cur = emit_sig.through_scope_w
emit_sig.setfastscope.append(
- "obj = self.space.interpclass_w(scope_w[%d])" % cur)
- emit_sig.setfastscope.append(
- "if obj is None or not isinstance(obj, %s):" % name)
- emit_sig.setfastscope.append(
- " raise OperationError(self.space.w_TypeError,self.space.wrap('expected %%s' %% %s.typedef.name ))" % name) # xxx
+ "obj = self.space.interp_w(%s, scope_w[%d])" % (name, cur))
emit_sig.miniglobals[name] = el
- emit_sig.miniglobals['OperationError'] = OperationError
emit_sig.setfastscope.append(
"self.%s_arg%d = obj" % (name,cur))
emit_sig.through_scope_w += 1
@@ -374,7 +369,7 @@
# It is a list of types or singleton objects:
# baseobjspace.ObjSpace is used to specify the space argument
# baseobjspace.W_Root is for wrapped arguments to keep wrapped
- # baseobjspace.Wrappable subclasses imply interpclass_w and a typecheck
+ # baseobjspace.Wrappable subclasses imply interp_w and a typecheck
# argument.Arguments is for a final rest arguments Arguments object
# 'args_w' for unpacktuple applied to rest arguments
# 'w_args' for rest arguments passed as wrapped tuple
Modified: pypy/dist/pypy/interpreter/main.py
==============================================================================
--- pypy/dist/pypy/interpreter/main.py (original)
+++ pypy/dist/pypy/interpreter/main.py Tue Dec 13 12:12:35 2005
@@ -20,8 +20,7 @@
w = space.wrap
w_code = space.builtin.call('compile',
w(source), w(filename), w(cmd), w(0), w(0))
- pycode = space.interpclass_w(w_code)
- assert isinstance(pycode, eval.Code)
+ pycode = space.interp_w(eval.Code, w_code)
return pycode
Modified: pypy/dist/pypy/interpreter/nestedscope.py
==============================================================================
--- pypy/dist/pypy/interpreter/nestedscope.py (original)
+++ pypy/dist/pypy/interpreter/nestedscope.py Tue Dec 13 12:12:35 2005
@@ -166,24 +166,15 @@
def MAKE_CLOSURE(f, numdefaults):
w_codeobj = f.valuestack.pop()
- codeobj = f.space.interpclass_w(w_codeobj)
- assert isinstance(codeobj, pycode.PyCode)
+ codeobj = f.space.interp_w(pycode.PyCode, w_codeobj)
if codeobj.magic >= 0xa0df281: # CPython 2.5 AST branch merge
w_freevarstuple = f.valuestack.pop()
- freevars = []
- for cell in f.space.unpacktuple(w_freevarstuple):
- cell = f.space.interpclass_w(cell)
- if not isinstance(cell, Cell):
- raise pyframe.BytecodeCorruption
- freevars.append(cell)
+ freevars = [f.space.interp_w(Cell, cell)
+ for cell in f.space.unpacktuple(w_freevarstuple)]
else:
nfreevars = len(codeobj.co_freevars)
- freevars = []
- for i in range(nfreevars):
- cell = f.space.interpclass_w(f.valuestack.pop())
- if not isinstance(cell, Cell):
- raise pyframe.BytecodeCorruption
- freevars.append(cell)
+ freevars = [f.space.interp_w(Cell, f.valuestack.pop())
+ for i in range(nfreevars)]
freevars.reverse()
defaultarguments = [f.valuestack.pop() for i in range(numdefaults)]
defaultarguments.reverse()
Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py (original)
+++ pypy/dist/pypy/interpreter/pyopcode.py Tue Dec 13 12:12:35 2005
@@ -6,7 +6,7 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter.baseobjspace import UnpackValueError
-from pypy.interpreter import gateway, function
+from pypy.interpreter import gateway, function, eval
from pypy.interpreter import pyframe, pytraceback
from pypy.interpreter.miscutils import InitializedClass
from pypy.interpreter.argument import Arguments
@@ -360,9 +360,8 @@
plain = f.w_locals is not None and f.space.is_w(w_locals, f.w_locals)
if plain:
w_locals = f.getdictscope()
- pycode = f.space.interpclass_w(w_prog)
- assert isinstance(pycode, PyCode)
- pycode.exec_code(f.space, w_globals, w_locals)
+ co = f.space.interp_w(eval.Code, w_prog)
+ co.exec_code(f.space, w_globals, w_locals)
if plain:
f.setdictscope(w_locals)
@@ -692,8 +691,7 @@
def MAKE_FUNCTION(f, numdefaults):
w_codeobj = f.valuestack.pop()
- codeobj = f.space.interpclass_w(w_codeobj)
- assert isinstance(codeobj, PyCode)
+ codeobj = f.space.interp_w(PyCode, w_codeobj)
defaultarguments = [f.valuestack.pop() for i in range(numdefaults)]
defaultarguments.reverse()
fn = function.Function(f.space, codeobj, f.w_globals, defaultarguments)
Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py (original)
+++ pypy/dist/pypy/interpreter/typedef.py Tue Dec 13 12:12:35 2005
@@ -2,6 +2,7 @@
"""
+import py
from pypy.interpreter.gateway import interp2app
from pypy.interpreter.argument import Arguments
from pypy.interpreter.baseobjspace import Wrappable, W_Root, ObjSpace
@@ -184,34 +185,30 @@
if isinstance(cls, str):
#print "<CHECK", func.__module__ or '?', func.__name__
assert cls.startswith('<'),"pythontype typecheck should begin with <"
- unwrap = "w_obj"
+ source = """
+ def descr_typecheck_%(name)s(space, w_obj, %(extra)s):
+ if not space.is_true(space.isinstance(w_obj, space.w_%(cls_name)s)):
+ # xxx improve msg
+ msg = "descriptor is for '%(expected)s'"
+ raise OperationError(space.w_TypeError, space.wrap(msg))
+ return %(name)s(space, w_obj, %(extra)s)
+ """
cls_name = cls[1:]
expected = repr(cls_name)
- check = "space.is_true(space.isinstance(obj, space.w_%s))" % cls_name
else:
cls_name = cls.__name__
- if issubclass(cls, Wrappable):
- unwrap = "space.interpclass_w(w_obj)"
- else:
- unwrap = "w_obj"
- miniglobals[cls_name] = cls
- check = "isinstance(obj, %s)" % cls_name
- expected = "%s.typedef.name" % cls_name
-
- source = """if 1:
+ assert issubclass(cls, Wrappable)
+ source = """
def descr_typecheck_%(name)s(space, w_obj, %(extra)s):
- obj = %(unwrap)s
- if obj is None or not %(check)s:
- # xxx improve msg
- msg = "descriptor is for '%%s'" %% %(expected)s
- raise OperationError(space.w_TypeError, space.wrap(msg))
+ obj = space.interp_w(%(cls_name)s, w_obj)
return %(name)s(space, obj, %(extra)s)
- \n""" % {'name': func.__name__,
- 'check': check,
- 'expected': expected,
- 'unwrap': unwrap,
- 'extra': ', '.join(extraargs)}
- exec compile2(source) in miniglobals
+ """
+ miniglobals[cls_name] = cls
+
+ name = func.__name__
+ extra = ', '.join(extraargs)
+ source = py.code.Source(source % locals())
+ exec source.compile() in miniglobals
return miniglobals['descr_typecheck_%s' % func.__name__]
def unknown_objclass_getter(space):
Modified: pypy/dist/pypy/module/__builtin__/importing.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/importing.py (original)
+++ pypy/dist/pypy/module/__builtin__/importing.py Tue Dec 13 12:12:35 2005
@@ -358,8 +358,7 @@
w_mode = w("exec")
w_pathname = w(pathname)
w_code = space.builtin.call('compile', w_source, w_pathname, w_mode)
- pycode = space.interpclass_w(w_code)
- assert isinstance(pycode, Code) # hint to the annotator
+ pycode = space.interp_w(Code, w_code)
return pycode
def load_source_module(space, w_modulename, w_mod, pathname, osfile):
Modified: pypy/dist/pypy/module/_sre/interp_sre.py
==============================================================================
--- pypy/dist/pypy/module/_sre/interp_sre.py (original)
+++ pypy/dist/pypy/module/_sre/interp_sre.py Tue Dec 13 12:12:35 2005
@@ -251,10 +251,7 @@
#### Main opcode dispatch loop
def w_search(space, w_state, w_pattern_codes):
- state = space.interpclass_w(w_state)
- if not isinstance(state, W_State):
- raise OperationError(space.w_TypeError,
- space.wrap("State object expected"))
+ state = space.interp_w(W_State, w_state)
pattern_codes = [intmask(space.uint_w(code)) for code
in space.unpackiterable(w_pattern_codes)]
return space.newbool(search(space, state, pattern_codes))
@@ -327,10 +324,7 @@
return False
def w_match(space, w_state, w_pattern_codes):
- state = space.interpclass_w(w_state)
- if not isinstance(state, W_State):
- raise OperationError(space.w_TypeError,
- space.wrap("State object expected"))
+ state = space.interp_w(W_State, w_state)
pattern_codes = [intmask(space.uint_w(code)) for code
in space.unpackiterable(w_pattern_codes)]
return space.newbool(match(space, state, pattern_codes))
Modified: pypy/dist/pypy/module/recparser/pyparser.py
==============================================================================
--- pypy/dist/pypy/module/recparser/pyparser.py (original)
+++ pypy/dist/pypy/module/recparser/pyparser.py Tue Dec 13 12:12:35 2005
@@ -236,9 +236,7 @@
def descr_alternative_append( self, space, w_rule ):
- rule = space.interpclass_w(w_rule)
- if not isinstance( rule, GrammarElement ):
- raise OperationError( space.w_TypeError, space.wrap("Need a GrammarElement instance") )
+ rule = space.interp_w(GrammarElement, w_rule)
self.args.append( rule )
@@ -246,18 +244,14 @@
return space.wrap(self.args[idx])
def descr_alternative___setitem__(self, space, idx, w_rule ):
- rule = space.interpclass_w(w_rule)
- if not isinstance( rule, GrammarElement ):
- raise OperationError( space.w_TypeError, space.wrap("Need a GrammarElement instance") )
+ rule = space.interp_w(GrammarElement, w_rule)
return space.wrap( self.args[idx] )
def descr_alternative___delitem__(self, space, idx ):
del self.args[idx]
def descr_alternative_insert(self, space, idx, w_rule ):
- rule = space.interpclass_w(w_rule)
- if not isinstance( rule, GrammarElement ):
- raise OperationError( space.w_TypeError, space.wrap("Need a GrammarElement instance") )
+ rule = space.interp_w(GrammarElement, w_rule)
if idx<0 or idx>len(self.args):
raise OperationError( space.w_IndexError, space.wrap("Invalid index") )
self.args.insert( idx, rule )
@@ -308,11 +302,9 @@
return space.wrap(self.args[idx])
def descr_kleenestar___setitem__(self, space, idx, w_rule ):
- rule = space.interpclass_w(w_rule)
if idx!=0:
raise OperationError( space.w_ValueError, space.wrap("KleeneStar only support one child"))
- if not isinstance( rule, GrammarElement ):
- raise OperationError( space.w_TypeError, space.wrap("Need a GrammarElement instance") )
+ rule = space.interp_w(GrammarElement, w_rule)
self.args[idx] = rule
KleeneStar.descr_kleenestar___getitem__ = descr_kleenestar___getitem__
Modified: pypy/dist/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/dist/pypy/objspace/std/marshal_impl.py (original)
+++ pypy/dist/pypy/objspace/std/marshal_impl.py Tue Dec 13 12:12:35 2005
@@ -369,8 +369,7 @@
def marshal_w_pycode(space, w_pycode, m):
m.start(TYPE_CODE)
# see pypy.interpreter.pycode for the layout
- x = space.interpclass_w(w_pycode)
- assert isinstance(x, PyCode)
+ x = space.interp_w(PyCode, w_pycode)
m.put_int(x.co_argcount)
m.put_int(x.co_nlocals)
m.put_int(x.co_stacksize)
More information about the Pypy-commit
mailing list