[pypy-svn] rev 550 - in pypy/trunk/src/pypy: interpreter module module/test objspace/std
arigo at codespeak.net
arigo at codespeak.net
Tue May 27 15:02:06 CEST 2003
Author: arigo
Date: Tue May 27 15:02:06 2003
New Revision: 550
Modified:
pypy/trunk/src/pypy/interpreter/baseobjspace.py
pypy/trunk/src/pypy/interpreter/extmodule.py
pypy/trunk/src/pypy/interpreter/main.py
pypy/trunk/src/pypy/interpreter/pycode.py
pypy/trunk/src/pypy/interpreter/pycode_app.py
pypy/trunk/src/pypy/module/builtin.py
pypy/trunk/src/pypy/module/builtin_app.py
pypy/trunk/src/pypy/module/test/test_range.py (props changed)
pypy/trunk/src/pypy/objspace/std/dictobject.py
pypy/trunk/src/pypy/objspace/std/moduleobject.py
pypy/trunk/src/pypy/objspace/std/objspace.py
Log:
bunch of changes, getting closer to having hello_world again
Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/baseobjspace.py (original)
+++ pypy/trunk/src/pypy/interpreter/baseobjspace.py Tue May 27 15:02:06 2003
@@ -17,15 +17,15 @@
def __init__(self):
"Basic initialization of objects."
- self.w_builtins = self.newdict([]) #temporary! changed by make_builtins()
self.w_modules = self.newdict([])
self.appfile_helpers = {}
self.initialize()
def make_builtins(self):
self.builtin = pypy.module.builtin.Builtin(self)
- self.w_builtin = self.builtin.wrap_me()
+ self.w_builtin = self.builtin.wrap_base()
self.w_builtins = self.getattr(self.w_builtin, self.wrap("__dict__"))
+ self.builtin.wrap_appfile(self.w_builtin)
def make_sys(self):
import pypy.module.sysmodule
Modified: pypy/trunk/src/pypy/interpreter/extmodule.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/extmodule.py (original)
+++ pypy/trunk/src/pypy/interpreter/extmodule.py Tue May 27 15:02:06 2003
@@ -49,13 +49,17 @@
__appfile__ = None
__helper_appfile__ = None
+ _helper = None
+
def __init__(self, space):
self.space = space
- if self.__helper_appfile__ is not None:
- self._helper = appfile.AppHelper(self.space,
- self.__helper_appfile__)
def wrap_me(self):
+ w_module = self.wrap_base()
+ self.wrap_appfile(w_module)
+ return w_module
+
+ def wrap_base(self):
space = self.space
modulename = self.__pythonname__
w_module = space.newmodule(space.wrap(modulename))
@@ -67,12 +71,17 @@
elif isinstance(value, appdata):
w_data = space.wrap(value.data)
space.setattr(w_module, space.wrap(key), w_data)
+ return w_module
+
+ def wrap_appfile(self, w_module):
sappfile = self.__appfile__
if sappfile:
+ space = self.space
w_dict = space.getattr(w_module, space.wrap("__dict__"))
appfile.AppHelper(space, sappfile, w_dict)
- return w_module
def callhelp(functioname,argslist):
+ if self._helper is None:
+ self._helper = appfile.AppHelper(self.space,
+ self.__helper_appfile__)
self._helper.call(functioname,argslist)
-
Modified: pypy/trunk/src/pypy/interpreter/main.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/main.py (original)
+++ pypy/trunk/src/pypy/interpreter/main.py Tue May 27 15:02:06 2003
@@ -22,6 +22,7 @@
frame = pyframe.PyFrame(space, space.unwrap(w_code),
w_globals, w_globals)
except baseobjspace.OperationError, operationerr:
+ operationerr.record_interpreter_traceback()
raise baseobjspace.PyPyError(space, operationerr)
else:
ec.eval_frame(frame)
@@ -37,8 +38,6 @@
try:
run_file(argv[1])
except baseobjspace.PyPyError, pypyerr:
- if pypyerr.space is None:
- raise pypyerr.operationerr # does anyone have a better idea?
pypyerr.operationerr.print_detailed_traceback(pypyerr.space)
if __name__ == '__main__':
Modified: pypy/trunk/src/pypy/interpreter/pycode.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/pycode.py (original)
+++ pypy/trunk/src/pypy/interpreter/pycode.py Tue May 27 15:02:06 2003
@@ -41,7 +41,6 @@
# application-level at all.
co = self
if (co.co_flags & (CO_VARARGS|CO_VARKEYWORDS) == 0 and
- (w_defaults is None or not space.is_true(w_defaults)) and
(w_kwargs is None or not space.is_true(w_kwargs)) and
(w_closure is None or not space.is_true(w_closure))):
# looks like a simple case, see if we got exactly the correct
Modified: pypy/trunk/src/pypy/interpreter/pycode_app.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/pycode_app.py (original)
+++ pypy/trunk/src/pypy/interpreter/pycode_app.py Tue May 27 15:02:06 2003
@@ -1,82 +1,85 @@
-# replacement for decode_frame_arguments
-
-def decode_code_arguments(args, kws, defs, closure, codeobject):
- """
- Assumptions:
- args = sequence of the normal actual parameters
- kws = dictionary of keyword actual parameters
- defs = sequence of defaults
- """
- CO_VARARGS = 0x4
- CO_VARKEYWORDS = 0x8
- varargs = (codeobject.co_flags & CO_VARARGS) and 1
- varkeywords = (codeobject.co_flags & CO_VARKEYWORDS) and 1
- varargs_tuple = ()
-
- argdict = {}
- parameter_names = codeobject.co_varnames[:codeobject.co_argcount]
-
- # Normal arguments
- for i in range(len(args)):
- try:
- argdict[parameter_names[i]] = args[i]
- except IndexError:
- # If varargs, put in tuple, else throw error
- if varargs:
- varargs_tuple = args[i:]
- else:
- raise TypeError, 'Too many parameters to callable object'
-
- # Put all suitable keywords into arglist
- if kws:
- if varkeywords:
- # Allow all keywords
- newkw = {}
- for key in kws.keys():
- for name in parameter_names:
- if name == key:
- if argdict.has_key(key):
- raise TypeError, 'Setting parameter %s twice.' % name
- else:
- argdict[key] = kws[key]
- break # name found in parameter names
- else:
- newkw[key] = kws[key]
-
- else:
- # Only allow formal parameter keywords
- count = len(kws)
- for name in parameter_names:
- if kws.has_key(name):
- count -= 1
- if argdict.has_key(name):
- raise TypeError, 'Setting parameter %s twice.' % name
- else:
- argdict[name] = kws[name]
- if count:
- # XXX This should be improved to show the parameters that
- # shouldn't be here.
- raise TypeError, 'Setting keyword parameter that does not exist in formal parameter list.'
-
- # Fill in with defaults, starting at argcount - defcount
- if defs:
- argcount = codeobject.co_argcount
- defcount = len(defs)
- for i in range(argcount - defcount, argcount):
- if argdict.has_key(parameter_names[i]):
- continue
- argdict[parameter_names[i]] = defs[i - (argcount - defcount)]
-
- if len(argdict) < codeobject.co_argcount:
- raise TypeError, 'Too few paramteres to callable object'
-
- namepos = codeobject.co_argcount
- if varargs:
- name = codeobject.co_varnames[namepos]
- argdict[name] = varargs_tuple
- namepos += 1
- if varkeywords:
- name = codeobject.co_varnames[namepos]
- argdict[name] = newkw
-
- return argdict
+# replacement for decode_frame_arguments
+# Attention ! All calls here must be "easy", i.e. not involve
+# default or keyword arguments !! For example, all range() calls
+# need three arguments.
+
+def decode_code_arguments(args, kws, defs, closure, codeobject):
+ """
+ Assumptions:
+ args = sequence of the normal actual parameters
+ kws = dictionary of keyword actual parameters
+ defs = sequence of defaults
+ """
+ CO_VARARGS = 0x4
+ CO_VARKEYWORDS = 0x8
+ varargs = (codeobject.co_flags & CO_VARARGS) and 1
+ varkeywords = (codeobject.co_flags & CO_VARKEYWORDS) and 1
+ varargs_tuple = ()
+
+ argdict = {}
+ parameter_names = codeobject.co_varnames[:codeobject.co_argcount]
+
+ # Normal arguments
+ for i in range(0, len(args), 1):
+ try:
+ argdict[parameter_names[i]] = args[i]
+ except IndexError:
+ # If varargs, put in tuple, else throw error
+ if varargs:
+ varargs_tuple = args[i:]
+ else:
+ raise TypeError, 'Too many parameters to callable object'
+
+ # Put all suitable keywords into arglist
+ if kws:
+ if varkeywords:
+ # Allow all keywords
+ newkw = {}
+ for key in kws.keys():
+ for name in parameter_names:
+ if name == key:
+ if key in argdict:
+ raise TypeError, 'Setting parameter %s twice.' % name
+ else:
+ argdict[key] = kws[key]
+ break # name found in parameter names
+ else:
+ newkw[key] = kws[key]
+
+ else:
+ # Only allow formal parameter keywords
+ count = len(kws)
+ for name in parameter_names:
+ if name in kws:
+ count -= 1
+ if name in argdict:
+ raise TypeError, 'Setting parameter %s twice.' % name
+ else:
+ argdict[name] = kws[name]
+ if count:
+ # XXX This should be improved to show the parameters that
+ # shouldn't be here.
+ raise TypeError, 'Setting keyword parameter that does not exist in formal parameter list.'
+
+ # Fill in with defaults, starting at argcount - defcount
+ if defs:
+ argcount = codeobject.co_argcount
+ defcount = len(defs)
+ for i in range(argcount - defcount, argcount, 1):
+ if parameter_names[i] in argdict:
+ continue
+ argdict[parameter_names[i]] = defs[i - (argcount - defcount)]
+
+ if len(argdict) < codeobject.co_argcount:
+ raise TypeError, 'Too few parameters to callable object'
+
+ namepos = codeobject.co_argcount
+ if varargs:
+ name = codeobject.co_varnames[namepos]
+ argdict[name] = varargs_tuple
+ namepos += 1
+ if varkeywords:
+ name = codeobject.co_varnames[namepos]
+ argdict[name] = newkw
+
+ return argdict
Modified: pypy/trunk/src/pypy/module/builtin.py
==============================================================================
--- pypy/trunk/src/pypy/module/builtin.py (original)
+++ pypy/trunk/src/pypy/module/builtin.py Tue May 27 15:02:06 2003
@@ -15,13 +15,15 @@
# we have None!
None = appdata(_b.None)
+ dict = appdata(_b.dict) # XXX temporary
+ tuple = appdata(_b.tuple) # XXX temporary
# temporary hack, until we have a real tuple type for calling
- def tuple(self, w_obj):
- lis = self.space.unpackiterable(w_obj)
- w_res = self.space.newtuple(lis)
- return w_res
- tuple = appmethod(tuple)
+ #def tuple(self, w_obj):
+ # lis = self.space.unpackiterable(w_obj)
+ # w_res = self.space.newtuple(lis)
+ # return w_res
+ #tuple = appmethod(tuple)
def __import__(self, w_modulename, w_locals, w_globals, w_fromlist):
space = self.space
@@ -105,8 +107,8 @@
#It works only for new-style classes.
#So we have to fix it, when we add support for
#the old-style classes
- def issubclass(self, w_val):
- return self.space.issubtype(w_val)
+ def issubclass(self, w_cls1, w_cls2):
+ return self.space.issubtype(w_cls1, w_cls2)
issubclass = appmethod(issubclass)
#XXX the is also the second form of iter, we don't have implemented
Modified: pypy/trunk/src/pypy/module/builtin_app.py
==============================================================================
--- pypy/trunk/src/pypy/module/builtin_app.py (original)
+++ pypy/trunk/src/pypy/module/builtin_app.py Tue May 27 15:02:06 2003
@@ -1,9 +1,5 @@
-# XXX kwds yet to come
-# Problem: need to decide how to implement iterators,
-# which are needed for star args.
-
-def apply(function, args, kwds):
+def apply(function, args, kwds={}):
return function(*args, **kwds)
def map(function, *collections):
Modified: pypy/trunk/src/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/dictobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/dictobject.py Tue May 27 15:02:06 2003
@@ -84,3 +84,17 @@
raise OperationError(space.w_KeyError, w_lookup)
StdObjSpace.delitem.register(delitem_dict_any, W_DictObject, W_ANY)
+
+def len_dict(space, w_dict):
+ return space.wrap(len(w_dict.non_empties()))
+
+StdObjSpace.len.register(len_dict, W_DictObject)
+
+def contains_dict_any(space, w_dict, w_lookup):
+ data = w_dict.non_empties()
+ for w_key,cell in data:
+ if space.is_true(space.eq(w_lookup, w_key)):
+ return space.w_True
+ return space.w_False
+
+StdObjSpace.contains.register(contains_dict_any, W_DictObject, W_ANY)
Modified: pypy/trunk/src/pypy/objspace/std/moduleobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/moduleobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/moduleobject.py Tue May 27 15:02:06 2003
@@ -13,7 +13,7 @@
self.w_dict = W_DictObject(items)
-def getattr_dict_any(space, w_module, w_attr):
+def getattr_module_any(space, w_module, w_attr):
if space.is_true(space.eq(w_attr, space.wrap('__dict__'))):
return w_module.w_dict
else:
@@ -25,14 +25,14 @@
else:
raise
-def setattr_dict_any_any(space, w_module, w_attr, w_value):
+def setattr_module_any_any(space, w_module, w_attr, w_value):
if space.is_true(space.eq(w_attr, space.wrap('__dict__'))):
raise OperationError(space.w_TypeError,
space.wrap("readonly attribute"))
else:
space.setitem(w_module.w_dict, w_attr, w_value)
-def delattr_dict_any(space, w_module, w_attr):
+def delattr_module_any(space, w_module, w_attr):
if space.is_true(space.eq(w_attr, space.wrap('__dict__'))):
raise OperationError(space.w_TypeError,
space.wrap("readonly attribute"))
@@ -45,6 +45,6 @@
else:
raise
-StdObjSpace.getattr.register(getattr_dict_any, W_ModuleObject, W_ANY)
-StdObjSpace.setattr.register(setattr_dict_any_any, W_ModuleObject, W_ANY, W_ANY)
-StdObjSpace.delattr.register(delattr_dict_any, W_ModuleObject, W_ANY)
+StdObjSpace.getattr.register(getattr_module_any, W_ModuleObject, W_ANY)
+StdObjSpace.setattr.register(setattr_module_any_any, W_ModuleObject, W_ANY,W_ANY)
+StdObjSpace.delattr.register(delattr_module_any, W_ModuleObject, W_ANY)
Modified: pypy/trunk/src/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/std/objspace.py Tue May 27 15:02:06 2003
@@ -175,12 +175,12 @@
def default_setattr(space, w_obj, w_attr, w_value):
raise OperationError(space.w_AttributeError, w_attr)
-StdObjSpace.setattr.register(default_getattr, W_ANY, W_ANY, W_ANY)
+StdObjSpace.setattr.register(default_setattr, W_ANY, W_ANY, W_ANY)
def default_delattr(space, w_obj, w_attr, w_value):
raise OperationError(space.w_AttributeError, w_attr)
-StdObjSpace.delattr.register(default_getattr, W_ANY, W_ANY)
+StdObjSpace.delattr.register(default_delattr, W_ANY, W_ANY)
# add default implementations for in-place operators
for _name, _symbol, _arity in ObjSpace.MethodTable:
More information about the Pypy-commit
mailing list