From tismer at codespeak.net Mon May 26 12:50:04 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 12:50:04 +0200 (MEST) Subject: [pypy-svn] rev 426 - in pypy/trunk/src/pypy: interpreter objspace/std Message-ID: <20030526105004.1BDFC5B698@thoth.codespeak.net> Author: tismer Date: Mon May 26 12:50:03 2003 New Revision: 426 Modified: pypy/trunk/src/pypy/interpreter/pycode.py pypy/trunk/src/pypy/objspace/std/funcobject.py pypy/trunk/src/pypy/objspace/std/objspace.py Log: generalizing functions. They all redirect to their specific code object Modified: pypy/trunk/src/pypy/interpreter/pycode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pycode.py (original) +++ pypy/trunk/src/pypy/interpreter/pycode.py Mon May 26 12:50:03 2003 @@ -1,64 +1,74 @@ -""" -PyCode class implementation. - -This class is similar to the built-in code objects. -It avoids wrapping existing code object, instead, -it plays its role without exposing real code objects. -SInce in C Python the only way to crate a code object -by somehow call into the builtin compile, we implement -the creation of our code object by defining out own compile, -wich ()at the moment) calls back into the real compile, -hijacks the code object and creates our code object from that. -compile is found in the builtin.py file. -""" - -# XXX todo: -# look at this if it makes sense -# think of a proper base class??? - -import baseobjspace -from appfile import AppFile - -# no appfile neede, yet -#appfile = AppFile(__name__, ["interpreter"]) - -class PyCode: - """Represents a code object, in the way we need it. - - Public fields: - to be done - """ - - def __init__(self): - """ initialize all attributes to just something. """ - self.co_argcount = 0 - self.co_nlocals = 0 - self.co_stacksize = 0 - self.co_flags = 0 - self.co_code = None - self.co_consts = None - self.co_names = None - self.co_varnames = None - self.co_freevars = None - self.co_cellvars = None - # The rest doesn't count for hash/cmp - self.co_filename = "" - self.co_name = "" - self.co_firstlineno = 0 #first source line number - self.co_lnotab = "" # string (encoding addr<->lineno mapping) - - ### codeobject initialization ### - - def _from_code(self, code): - """ Initialize the code object from a real one. - This is just a hack, until we have our own compile. - At the moment, we just fake this. - This method is called by our compile builtin function. - """ - import types - assert(type(code is types.CodeType)) - # simply try to suck in all attributes we know of - for name in self.__dict__.keys(): - value = getattr(code, name) - setattr(self, name, value) - +""" +PyCode class implementation. + +This class is similar to the built-in code objects. +It avoids wrapping existing code object, instead, +it plays its role without exposing real code objects. +SInce in C Python the only way to crate a code object +by somehow call into the builtin compile, we implement +the creation of our code object by defining out own compile, +wich ()at the moment) calls back into the real compile, +hijacks the code object and creates our code object from that. +compile is found in the builtin.py file. +""" + +# XXX todo: +# look at this if it makes sense +# think of a proper base class??? + +import baseobjspace +from appfile import AppFile + +# no appfile neede, yet +#appfile = AppFile(__name__, ["interpreter"]) + +class PyBaseCode: + def __init__(self): + self.co_filename = "" + self.co_name = "" + +class PyByteCode(PyBaseCode): + """Represents a code object for Python functions. + + Public fields: + to be done + """ + + def __init__(self): + """ initialize all attributes to just something. """ + self.co_argcount = 0 + self.co_nlocals = 0 + self.co_stacksize = 0 + self.co_flags = 0 + self.co_code = None + self.co_consts = None + self.co_names = None + self.co_varnames = None + self.co_freevars = None + self.co_cellvars = None + # The rest doesn't count for hash/cmp + self.co_firstlineno = 0 #first source line number + self.co_lnotab = "" # string (encoding addr<->lineno mapping) + + ### codeobject initialization ### + + def _from_code(self, code): + """ Initialize the code object from a real one. + This is just a hack, until we have our own compile. + At the moment, we just fake this. + This method is called by our compile builtin function. + """ + import types + assert(type(code is types.CodeType)) + # simply try to suck in all attributes we know of + for name in self.__dict__.keys(): + value = getattr(code, name) + setattr(self, name, value) + + def eval_code(self, space, w_globals, w_locals): + frame = pypy.interpreter.pyframe.PyFrame(space, self, + w_globals, w_locals) + ec = space.getexecutioncontext() + w_ret = ec.eval_frame(frame) + return w_ret + Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/funcobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/funcobject.py Mon May 26 12:50:03 2003 @@ -26,14 +26,13 @@ def func_call(space, w_function, w_arguments, w_keywords): ec = space.getexecutioncontext() - bytecode = space.unwrap(w_function.w_code) + somecode = space.unwrap(w_function.w_code) w_locals = space.newdict([]) - frame = pypy.interpreter.pyframe.PyFrame(space, bytecode, - w_function.w_globals, w_locals) - frame.setargs(w_arguments, w_keywords, + w_globals = w_function.w_globals + w_locals = buildargs(w_arguments, w_keywords, w_defaults = w_function.w_defaultarguments, w_closure = w_function.w_closure) - w_result = ec.eval_frame(frame) - return w_result + w_ret = somecode.eval_code(space, w_globals, w_locals) + return w_ret StdObjSpace.call.register(func_call, W_FuncObject, W_ANY, 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 Mon May 26 12:50:03 2003 @@ -81,9 +81,9 @@ import sliceobject return sliceobject.W_SliceObject(w_start, w_end, w_step) - def newfunction(self, w_code, w_globals, w_defaultarguments, w_closure=None): + def newfunction(self, code, w_globals, w_defaultarguments, w_closure=None): import funcobject - return funcobject.W_FuncObject(w_code, w_globals, + return funcobject.W_FuncObject(code, w_globals, w_defaultarguments, w_closure) def newmodule(self, w_name): From pedronis at codespeak.net Mon May 26 12:57:47 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Mon, 26 May 2003 12:57:47 +0200 (MEST) Subject: [pypy-svn] rev 428 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030526105747.C36B25B699@thoth.codespeak.net> Author: pedronis Date: Mon May 26 12:57:47 2003 New Revision: 428 Modified: pypy/trunk/src/pypy/objspace/std/dictobject.py Log: added cell retrieving method 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 Mon May 26 12:57:47 2003 @@ -32,9 +32,21 @@ self.data = [ (w_key,Cell(w_value)) for w_key,w_value in list_pairs_w ] def non_empties(self): - return [ (w_key,cell) for w_key,cell in self.data if not cell.is_empty()] - + return [ (w_key,cell) for w_key,cell in self.data if not cell.is_empty()] + def _cell(self,space,w_lookup): + data = self.data + for w_key, cell in data: + if space.is_true(space.eq(w_lookup, w_key)): + break + else: + cell = Cell() + data.append((w_lookup,cell)) + return cell + + def cell(self,space,w_lookup): + return space.wrap(self._cell(space,w_lookup)) + def dict_is_true(space, w_dict): return not not w_dict.non_empties() @@ -58,13 +70,8 @@ StdObjSpace.getitem.register(getitem_dict_any, W_DictObject, W_ANY) def setitem_dict_any_any(space, w_dict, w_newkey, w_newvalue): - data = w_dict.data - for w_key,cell in data: - if space.is_true(space.eq(w_newkey, w_key)): - cell.set(w_newvalue) - return - # add new (key,Cell(value)) pair - data.append((w_newkey, Cell(w_newvalue))) + cell = w_dict._cell(space,w_newkey) + cell.set(w_newvalue) StdObjSpace.setitem.register(setitem_dict_any_any, W_DictObject, W_ANY, W_ANY) From pedronis at codespeak.net Mon May 26 12:58:25 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Mon, 26 May 2003 12:58:25 +0200 (MEST) Subject: [pypy-svn] rev 429 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030526105825.F06955B699@thoth.codespeak.net> Author: pedronis Date: Mon May 26 12:58:25 2003 New Revision: 429 Modified: pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py Log: added test for cell method Modified: pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py Mon May 26 12:58:25 2003 @@ -46,6 +46,17 @@ self.assertEqual_w(space.getitem(d,space.wrap('two')),space.wrap(2)) self.failUnlessRaises(OperationError,space.getitem,d,space.wrap('one')) + def test_cell(self): + space = self.space + wk1 = space.wrap('key') + d = dobj.W_DictObject([]) + w_cell = d.cell(space,wk1) + cell = space.unwrap(w_cell) + self.failUnless(cell.is_empty()) + cell.set(space.wrap(1)) + self.assertEqual_w(space.getitem(d,wk1),space.wrap(1)) + + if __name__ == '__main__': unittest.main() From pedronis at codespeak.net Mon May 26 13:39:42 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Mon, 26 May 2003 13:39:42 +0200 (MEST) Subject: [pypy-svn] rev 431 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030526113942.8760A5B698@thoth.codespeak.net> Author: pedronis Date: Mon May 26 13:39:42 2003 New Revision: 431 Modified: pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py Log: added test for non-empty cell retrieval. Modified: pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py Mon May 26 13:39:42 2003 @@ -55,6 +55,10 @@ self.failUnless(cell.is_empty()) cell.set(space.wrap(1)) self.assertEqual_w(space.getitem(d,wk1),space.wrap(1)) + wk2 = space.wrap('key2') + space.setitem(d,wk2,space.wrap(2)) + cell = space.unwrap(d.cell(space,wk2)) + self.assertEqual_w(cell.get(),space.wrap(2)) From tismer at codespeak.net Mon May 26 13:48:50 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 13:48:50 +0200 (MEST) Subject: [pypy-svn] rev 432 - in pypy/trunk/src/pypy: interpreter objspace/std Message-ID: <20030526114850.35ACE5B699@thoth.codespeak.net> Author: tismer Date: Mon May 26 13:48:49 2003 New Revision: 432 Modified: pypy/trunk/src/pypy/interpreter/pycode.py pypy/trunk/src/pypy/interpreter/pyframe_app.py pypy/trunk/src/pypy/objspace/std/funcobject.py Log: generalizing functions. They all redirect to their specific code object Modified: pypy/trunk/src/pypy/interpreter/pycode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pycode.py (original) +++ pypy/trunk/src/pypy/interpreter/pycode.py Mon May 26 13:48:49 2003 @@ -19,13 +19,49 @@ import baseobjspace from appfile import AppFile -# no appfile neede, yet -#appfile = AppFile(__name__, ["interpreter"]) +appfile = AppFile(__name__, ["interpreter"]) class PyBaseCode: def __init__(self): self.co_filename = "" self.co_name = "" + self.co_flags = 0 + self.co_code = None + self.co_consts = None + self.co_names = None + self.co_varnames = None + self.co_freevars = None + self.co_cellvars = None + + def build_arguments(self, space, w_arguments, w_kwargs, w_defaults, w_closure): + # We cannot systematically go to the application-level (_app.py) + # to do this dirty work, for bootstrapping reasons. So we check + # if we are in the most simple case and if so do not go to the + # 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 + # number of arguments + try: + args = space.unpacktuple(w_arguments, self.co_argcount) + except ValueError: + pass # no + else: + return args # yes! fine! + # non-trivial case. I won't do it myself. + if w_kwargs is None: w_kwargs = space.newdict([]) + if w_defaults is None: w_defaults = space.newtuple([]) + if w_closure is None: w_closure = space.newtuple([]) + w_bytecode = space.wrap(co) + w_arguments = space.gethelper(appfile).call( + "decode_code_arguments", [w_arguments, w_kwargs, w_defaults, + w_closure, w_bytecode]) + # we assume that decode_codee_arguments() gives us a dictionary + # of the correct length. + return w_arguments class PyByteCode(PyBaseCode): """Represents a code object for Python functions. @@ -39,13 +75,6 @@ self.co_argcount = 0 self.co_nlocals = 0 self.co_stacksize = 0 - self.co_flags = 0 - self.co_code = None - self.co_consts = None - self.co_names = None - self.co_varnames = None - self.co_freevars = None - self.co_cellvars = None # The rest doesn't count for hash/cmp self.co_firstlineno = 0 #first source line number self.co_lnotab = "" # string (encoding addr<->lineno mapping) Modified: pypy/trunk/src/pypy/interpreter/pyframe_app.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pyframe_app.py (original) +++ pypy/trunk/src/pypy/interpreter/pyframe_app.py Mon May 26 13:48:49 2003 @@ -1,3 +1,9 @@ +# XXX +# This is deprecated. +# We use the same functionality,. but do it in +# pycode_app.py. +# the function is just fine, we just don't reduce the +# dictionary; it is the result. def decode_frame_arguments(args, kws, defs, closure, codeobject): """ Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/funcobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/funcobject.py Mon May 26 13:48:49 2003 @@ -29,7 +29,7 @@ somecode = space.unwrap(w_function.w_code) w_locals = space.newdict([]) w_globals = w_function.w_globals - w_locals = buildargs(w_arguments, w_keywords, + w_locals = somecode.build_arguments(space, w_arguments, w_keywords, w_defaults = w_function.w_defaultarguments, w_closure = w_function.w_closure) w_ret = somecode.eval_code(space, w_globals, w_locals) From tismer at codespeak.net Mon May 26 14:06:42 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 14:06:42 +0200 (MEST) Subject: [pypy-svn] rev 433 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030526120642.F28765B699@thoth.codespeak.net> Author: tismer Date: Mon May 26 14:06:42 2003 New Revision: 433 Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py Log: generalizing functions. They all redirect to their specific code object Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/funcobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/funcobject.py Mon May 26 14:06:42 2003 @@ -25,9 +25,7 @@ def func_call(space, w_function, w_arguments, w_keywords): - ec = space.getexecutioncontext() somecode = space.unwrap(w_function.w_code) - w_locals = space.newdict([]) w_globals = w_function.w_globals w_locals = somecode.build_arguments(space, w_arguments, w_keywords, w_defaults = w_function.w_defaultarguments, From tismer at codespeak.net Mon May 26 14:10:01 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 14:10:01 +0200 (MEST) Subject: [pypy-svn] rev 434 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526121001.3D4DD5B699@thoth.codespeak.net> Author: tismer Date: Mon May 26 14:10:00 2003 New Revision: 434 Added: pypy/trunk/src/pypy/interpreter/pycode_app.py Log: generalizing functions. They all redirect to their specific code object Added: pypy/trunk/src/pypy/interpreter/pycode_app.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/interpreter/pycode_app.py Mon May 26 14:10:00 2003 @@ -0,0 +1,82 @@ +# 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 From arigo at codespeak.net Mon May 26 14:28:06 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 14:28:06 +0200 (MEST) Subject: [pypy-svn] rev 435 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526122806.88F745B699@thoth.codespeak.net> Author: arigo Date: Mon May 26 14:28:06 2003 New Revision: 435 Modified: pypy/trunk/src/pypy/interpreter/pycode.py Log: moved co_xxx definitions around Modified: pypy/trunk/src/pypy/interpreter/pycode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pycode.py (original) +++ pypy/trunk/src/pypy/interpreter/pycode.py Mon May 26 14:28:06 2003 @@ -23,15 +23,12 @@ class PyBaseCode: def __init__(self): - self.co_filename = "" self.co_name = "" self.co_flags = 0 - self.co_code = None - self.co_consts = None - self.co_names = None - self.co_varnames = None - self.co_freevars = None - self.co_cellvars = None + self.co_varnames = () + self.co_argcount = 0 + self.co_freevars = () + self.co_cellvars = () def build_arguments(self, space, w_arguments, w_kwargs, w_defaults, w_closure): # We cannot systematically go to the application-level (_app.py) @@ -72,7 +69,10 @@ def __init__(self): """ initialize all attributes to just something. """ - self.co_argcount = 0 + self.co_filename = "" + self.co_code = None + self.co_consts = () + self.co_names = () self.co_nlocals = 0 self.co_stacksize = 0 # The rest doesn't count for hash/cmp @@ -88,7 +88,7 @@ This method is called by our compile builtin function. """ import types - assert(type(code is types.CodeType)) + assert type(code) is types.CodeType # simply try to suck in all attributes we know of for name in self.__dict__.keys(): value = getattr(code, name) @@ -100,4 +100,3 @@ ec = space.getexecutioncontext() w_ret = ec.eval_frame(frame) return w_ret - From arigo at codespeak.net Mon May 26 14:32:06 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 14:32:06 +0200 (MEST) Subject: [pypy-svn] rev 436 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526123206.A95085B699@thoth.codespeak.net> Author: arigo Date: Mon May 26 14:32:06 2003 New Revision: 436 Modified: pypy/trunk/src/pypy/interpreter/pycode.py Log: fixed trivial case of argument decoding Modified: pypy/trunk/src/pypy/interpreter/pycode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pycode.py (original) +++ pypy/trunk/src/pypy/interpreter/pycode.py Mon May 26 14:32:06 2003 @@ -47,7 +47,10 @@ except ValueError: pass # no else: - return args # yes! fine! + # yes! fine! + argnames = [space.wrap(name) for name in co.co_varnames] + w_arguments = space.newdict(zip(argnames, args)) + return w_arguments # non-trivial case. I won't do it myself. if w_kwargs is None: w_kwargs = space.newdict([]) if w_defaults is None: w_defaults = space.newtuple([]) From tismer at codespeak.net Mon May 26 14:52:17 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 14:52:17 +0200 (MEST) Subject: [pypy-svn] rev 437 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526125217.B97195B699@thoth.codespeak.net> Author: tismer Date: Mon May 26 14:52:17 2003 New Revision: 437 Modified: pypy/trunk/src/pypy/interpreter/pyframe.py Log: there is a problem with circular imports if one of them is spelling the package Modified: pypy/trunk/src/pypy/interpreter/pyframe.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pyframe.py (original) +++ pypy/trunk/src/pypy/interpreter/pyframe.py Mon May 26 14:52:17 2003 @@ -1,7 +1,10 @@ """ PyFrame class implementation with the interpreter main loop. """ - -from pypy.interpreter import opcode +import opcode +# XXX this is probably a Python bug: +# circular import doesn't work if we spell this +# from pypy.interpreter import opcode +# report this to python-dev from executioncontext import OperationError, Stack import baseobjspace from appfile import AppFile From arigo at codespeak.net Mon May 26 14:53:13 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 14:53:13 +0200 (MEST) Subject: [pypy-svn] rev 438 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526125313.5FF515B699@thoth.codespeak.net> Author: arigo Date: Mon May 26 14:53:13 2003 New Revision: 438 Modified: pypy/trunk/src/pypy/interpreter/interactive.py pypy/trunk/src/pypy/interpreter/main.py pypy/trunk/src/pypy/interpreter/pycode.py Log: made all imports relative Modified: pypy/trunk/src/pypy/interpreter/interactive.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/interactive.py (original) +++ pypy/trunk/src/pypy/interpreter/interactive.py Mon May 26 14:53:13 2003 @@ -1,6 +1,4 @@ -from pypy.interpreter import executioncontext -from pypy.interpreter import pyframe -from pypy.interpreter import baseobjspace +import executioncontext, pyframe, baseobjspace import sys import code import linecache Modified: pypy/trunk/src/pypy/interpreter/main.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/main.py (original) +++ pypy/trunk/src/pypy/interpreter/main.py Mon May 26 14:53:13 2003 @@ -1,7 +1,6 @@ from pypy.objspace.std import StdObjSpace from pypy.objspace.trivial import TrivialObjSpace -from pypy.interpreter import executioncontext, baseobjspace -from pypy.interpreter import pyframe +import executioncontext, baseobjspace, pyframe import sys Modified: pypy/trunk/src/pypy/interpreter/pycode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pycode.py (original) +++ pypy/trunk/src/pypy/interpreter/pycode.py Mon May 26 14:53:13 2003 @@ -16,7 +16,7 @@ # look at this if it makes sense # think of a proper base class??? -import baseobjspace +import baseobjspace, pyframe from appfile import AppFile appfile = AppFile(__name__, ["interpreter"]) @@ -72,6 +72,7 @@ def __init__(self): """ initialize all attributes to just something. """ + PyBaseCode.__init__(self) self.co_filename = "" self.co_code = None self.co_consts = () @@ -98,8 +99,7 @@ setattr(self, name, value) def eval_code(self, space, w_globals, w_locals): - frame = pypy.interpreter.pyframe.PyFrame(space, self, - w_globals, w_locals) + frame = pyframe.PyFrame(space, self, w_globals, w_locals) ec = space.getexecutioncontext() w_ret = ec.eval_frame(frame) return w_ret From tomek at codespeak.net Mon May 26 15:00:28 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Mon, 26 May 2003 15:00:28 +0200 (MEST) Subject: [pypy-svn] rev 439 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526130028.A678B5B699@thoth.codespeak.net> Author: tomek Date: Mon May 26 15:00:28 2003 New Revision: 439 Modified: pypy/trunk/src/pypy/interpreter/appfile.py pypy/trunk/src/pypy/interpreter/main.py Log: the right version of compile in main.py Modified: pypy/trunk/src/pypy/interpreter/appfile.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/appfile.py (original) +++ pypy/trunk/src/pypy/interpreter/appfile.py Mon May 26 15:00:28 2003 @@ -1,5 +1,5 @@ import os - +from pypy.module.builtin import compile class AppFile: """Dynamic loader of a set of Python functions and objects that Modified: pypy/trunk/src/pypy/interpreter/main.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/main.py (original) +++ pypy/trunk/src/pypy/interpreter/main.py Mon May 26 15:00:28 2003 @@ -1,6 +1,7 @@ from pypy.objspace.std import StdObjSpace from pypy.objspace.trivial import TrivialObjSpace import executioncontext, baseobjspace, pyframe +from pypy.module.builtin import compile import sys From tomek at codespeak.net Mon May 26 15:04:49 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Mon, 26 May 2003 15:04:49 +0200 (MEST) Subject: [pypy-svn] rev 440 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526130449.7A5135B699@thoth.codespeak.net> Author: tomek Date: Mon May 26 15:04:49 2003 New Revision: 440 Modified: pypy/trunk/src/pypy/interpreter/appfile.py Log: removed import of builtin.compile Modified: pypy/trunk/src/pypy/interpreter/appfile.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/appfile.py (original) +++ pypy/trunk/src/pypy/interpreter/appfile.py Mon May 26 15:04:49 2003 @@ -1,5 +1,4 @@ import os -from pypy.module.builtin import compile class AppFile: """Dynamic loader of a set of Python functions and objects that @@ -30,6 +29,7 @@ f = open(filename, 'r') src = f.read() f.close() + print filename self.bytecode = compile(src, filename, 'exec') From arigo at codespeak.net Mon May 26 15:06:07 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 15:06:07 +0200 (MEST) Subject: [pypy-svn] rev 441 - in pypy/trunk/src/pypy: interpreter module Message-ID: <20030526130607.0D8C55B699@thoth.codespeak.net> Author: arigo Date: Mon May 26 15:06:06 2003 New Revision: 441 Added: pypy/trunk/src/pypy/interpreter/extmodule.py Modified: pypy/trunk/src/pypy/module/builtin.py Log: extension modules, first draft Added: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Mon May 26 15:06:06 2003 @@ -0,0 +1,54 @@ + + +class appmethod(object): + def __init__(self, func): + self.func = func + def __get__(self, instance, cls=None): + return self.func.__get__(instance, cls) + + +class PyBuiltinCode(PyBaseCode): + """The code object implementing a built-in (interpreter-level) hook.""" + + def __init__(self, bltinmodule, appmethod): + PyBaseCode.__init__(self) + self.bltinmodule = bltinmodule + self.appmethod = appmethod + co = appmethod.func.func_code + self.co_name = appmethod.func.__name__ + self.co_flags = co.co_flags + # extract argument names from 'co', + # removing 'self' and the 'w_' prefixes + assert co.co_varnames[0] == "self" + argnames = [] + for argname in co.co_varnames[1:co.co_argcount]: + assert argname.startswith('w_') + argnames.append(argname[2:]) + self.co_varnames = tuple(argnames) + self.co_argcount = co.co_argcount - 1 + + def eval_code(self, space, w_globals, w_locals): + # this isn't quite complete: varargs and kwargs are missing + args = [] + for argname in self.co_varnames: + w_arg = space.getitem(w_locals, space.wrap(argname)) + args.append(w_arg) + w_ret = self.appmethod.func(self.bltinmodule, *args) + return w_ret + + +class BuiltinModule: + + def __init__(self, space): + self.space = space + + def wrap_me(self): + space = self.space + modulename = self.__pythonname__ + w_module = space.newmodule(space.wrap(modulename)) + for key, value in self.__class__.__dict__.items(): + if isinstance(value, appmethod): + + PyBuiltinCode(self, value) + + ... Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 15:06:06 2003 @@ -1,23 +1,28 @@ -from pypy.interpreter import baseobjspace -from pypy.interpreter.pycode import PyCode +from pypy.interpreter.extmodule import * ####################### #### __builtin__ #### ####################### -# XXX what should methodtables be? -class methodtable: +##import __builtin__ as _b - def chr(space, w_ascii): - w_character = space.newstring([w_ascii]) - return w_character +##def compile(*args, **kwargs): +## c = _b.compile(*args, **kwargs) +## res = PyCode() +## res._from_code(c) +## return res + +##compile.__doc__ = _b.compile.__doc__ -import __builtin__ as _b -def compile(*args, **kwargs): - c = _b.compile(*args, **kwargs) - res = PyCode() - res._from_code(c) - return res +class Builtin(BuiltinModule): + __pythonname__ = '__builtin__' + + def chr(self, w_ascii): + w_character = self.space.newstring([w_ascii]) + return w_character + chr = appmethod(chr) -compile.__doc__ = _b.compile.__doc__ + def len(self, w_obj): + return self.space.len(w_obj) + len = appmethod(len) From tomek at codespeak.net Mon May 26 15:11:07 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Mon, 26 May 2003 15:11:07 +0200 (MEST) Subject: [pypy-svn] rev 442 - pypy/trunk/src/pypy/module Message-ID: <20030526131107.E16585B699@thoth.codespeak.net> Author: tomek Date: Mon May 26 15:11:07 2003 New Revision: 442 Modified: pypy/trunk/src/pypy/module/builtin.py Log: Builtin Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 15:11:07 2003 @@ -1,16 +1,17 @@ from pypy.interpreter.extmodule import * +from pypy.interpreter.pycode import PyByteCode ####################### #### __builtin__ #### ####################### -##import __builtin__ as _b +import __builtin__ as _b -##def compile(*args, **kwargs): -## c = _b.compile(*args, **kwargs) -## res = PyCode() -## res._from_code(c) -## return res +def compile(*args, **kwargs): + c = _b.compile(*args, **kwargs) + res = PyByteCode() + res._from_code(c) + return res ##compile.__doc__ = _b.compile.__doc__ From tismer at codespeak.net Mon May 26 15:22:49 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 15:22:49 +0200 (MEST) Subject: [pypy-svn] rev 443 - pypy/trunk/src/pypy/module Message-ID: <20030526132249.046BD5AD46@thoth.codespeak.net> Author: tismer Date: Mon May 26 15:22:48 2003 New Revision: 443 Modified: pypy/trunk/src/pypy/module/builtin.py Log: added compile to Builtin class Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 15:22:48 2003 @@ -7,12 +7,6 @@ import __builtin__ as _b -def compile(*args, **kwargs): - c = _b.compile(*args, **kwargs) - res = PyByteCode() - res._from_code(c) - return res - ##compile.__doc__ = _b.compile.__doc__ @@ -27,3 +21,23 @@ def len(self, w_obj): return self.space.len(w_obj) len = appmethod(len) + + def compile(self, w_str, w_filename, w_startstr, + w_supplied_flags=None, w_dont_inherit=None): + str = space.unwrap(w_str) + filename = space.unwrap(w_filename) + startstr = space.unwrap(w_startstr) + if w_supplied_flags is None: + supplied_flags = 0 + else: + supplied_flags = space.unwrap(w_supplied_flags) + if w_dont_inherit is None: + dont_inherit = False + else: + dont_inherit = space.unwrap(w_supplied_flags) + + c = _b.compile(str, filename, startstr, supplied_flags, dont_inherit) + res = PyByteCode() + res._from_code(c) + return space.wrap(res) + compile = appmethod(compile) From tismer at codespeak.net Mon May 26 15:37:38 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 15:37:38 +0200 (MEST) Subject: [pypy-svn] rev 444 - pypy/trunk/src/pypy/module Message-ID: <20030526133738.C3B0E5B0F3@thoth.codespeak.net> Author: tismer Date: Mon May 26 15:37:38 2003 New Revision: 444 Modified: pypy/trunk/src/pypy/module/builtin.py Log: small fixes Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 15:37:38 2003 @@ -34,7 +34,7 @@ if w_dont_inherit is None: dont_inherit = False else: - dont_inherit = space.unwrap(w_supplied_flags) + dont_inherit = space.unwrap(w_dont_inherit) c = _b.compile(str, filename, startstr, supplied_flags, dont_inherit) res = PyByteCode() From arigo at codespeak.net Mon May 26 15:39:29 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 15:39:29 +0200 (MEST) Subject: [pypy-svn] rev 445 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526133929.D0EAD5B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 15:39:29 2003 New Revision: 445 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py Log: no default arguments yet Modified: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Mon May 26 15:39:29 2003 @@ -29,6 +29,7 @@ def eval_code(self, space, w_globals, w_locals): # this isn't quite complete: varargs and kwargs are missing + # defaults are not here either args = [] for argname in self.co_varnames: w_arg = space.getitem(w_locals, space.wrap(argname)) @@ -48,7 +49,7 @@ w_module = space.newmodule(space.wrap(modulename)) for key, value in self.__class__.__dict__.items(): if isinstance(value, appmethod): - - PyBuiltinCode(self, value) - - ... + code = PyBuiltinCode(self, value) + w_function = space.newfunction(code, space.w_None, None) + space.setattr(w_module, space.wrap(key), w_function) + return w_module From tismer at codespeak.net Mon May 26 15:39:52 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 15:39:52 +0200 (MEST) Subject: [pypy-svn] rev 446 - pypy/trunk/src/pypy/module Message-ID: <20030526133952.35A995B0F3@thoth.codespeak.net> Author: tismer Date: Mon May 26 15:39:51 2003 New Revision: 446 Modified: pypy/trunk/src/pypy/module/builtin.py Log: no default args for extmodule Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 15:39:51 2003 @@ -23,19 +23,12 @@ len = appmethod(len) def compile(self, w_str, w_filename, w_startstr, - w_supplied_flags=None, w_dont_inherit=None): + w_supplied_flags, w_dont_inherit): str = space.unwrap(w_str) filename = space.unwrap(w_filename) startstr = space.unwrap(w_startstr) - if w_supplied_flags is None: - supplied_flags = 0 - else: - supplied_flags = space.unwrap(w_supplied_flags) - if w_dont_inherit is None: - dont_inherit = False - else: - dont_inherit = space.unwrap(w_dont_inherit) - + supplied_flags = space.unwrap(w_supplied_flags) + dont_inherit = space.unwrap(w_dont_inherit) c = _b.compile(str, filename, startstr, supplied_flags, dont_inherit) res = PyByteCode() res._from_code(c) From alex at codespeak.net Mon May 26 16:01:01 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 16:01:01 +0200 (MEST) Subject: [pypy-svn] rev 447 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030526140101.5F2615B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 16:01:01 2003 New Revision: 447 Modified: pypy/trunk/src/pypy/objspace/std/test/test_intobject.py Log: usenew testsupport Modified: pypy/trunk/src/pypy/objspace/std/test/test_intobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_intobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_intobject.py Mon May 26 16:01:01 2003 @@ -4,7 +4,7 @@ from pypy.objspace.std.objspace import * -class TestW_IntObject(unittest.TestCase): +class TestW_IntObject(testsupport.TestCase_w): def setUp(self): self.space = StdObjSpace() From tismer at codespeak.net Mon May 26 16:05:19 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 16:05:19 +0200 (MEST) Subject: [pypy-svn] rev 448 - pypy/trunk/src/pypy/module Message-ID: <20030526140519.667875B0F3@thoth.codespeak.net> Author: tismer Date: Mon May 26 16:05:19 2003 New Revision: 448 Modified: pypy/trunk/src/pypy/module/builtin.py Log: small cleanups Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 16:05:19 2003 @@ -7,9 +7,6 @@ import __builtin__ as _b -##compile.__doc__ = _b.compile.__doc__ - - class Builtin(BuiltinModule): __pythonname__ = '__builtin__' From arigo at codespeak.net Mon May 26 16:12:48 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 16:12:48 +0200 (MEST) Subject: [pypy-svn] rev 449 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526141248.3F19B5B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 16:12:47 2003 New Revision: 449 Modified: pypy/trunk/src/pypy/interpreter/pycode_app.py (props changed) Log: Unix end-of-lines From tismer at codespeak.net Mon May 26 16:18:57 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 16:18:57 +0200 (MEST) Subject: [pypy-svn] rev 450 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526141857.BB5D65B0F3@thoth.codespeak.net> Author: tismer Date: Mon May 26 16:18:57 2003 New Revision: 450 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py pypy/trunk/src/pypy/interpreter/main.py Log: main uses compile from space.builtin now Modified: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Mon May 26 16:18:57 2003 @@ -1,4 +1,4 @@ - +from pycode import PyBaseCode class appmethod(object): def __init__(self, func): Modified: pypy/trunk/src/pypy/interpreter/main.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/main.py (original) +++ pypy/trunk/src/pypy/interpreter/main.py Mon May 26 16:18:57 2003 @@ -1,14 +1,15 @@ from pypy.objspace.std import StdObjSpace from pypy.objspace.trivial import TrivialObjSpace import executioncontext, baseobjspace, pyframe -from pypy.module.builtin import compile import sys def run_string(source, fname): try: space = StdObjSpace() - code = compile(source, fname, 'exec') + compile = space.builtin.compile + w=space.wrap + code = compile(w(source), w(fname), w('exec')) ec = executioncontext.ExecutionContext(space) w_mainmodule = space.newmodule(space.wrap("__main__")) From alex at codespeak.net Mon May 26 16:31:02 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 16:31:02 +0200 (MEST) Subject: [pypy-svn] rev 451 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526143102.0E3035B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 16:31:01 2003 New Revision: 451 Added: pypy/trunk/src/pypy/interpreter/unittest_w.py Log: moved class w/wrapped-tests methods to better-accessible place Added: pypy/trunk/src/pypy/interpreter/unittest_w.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/interpreter/unittest_w.py Mon May 26 16:31:01 2003 @@ -0,0 +1,34 @@ +import sys, os +import unittest + +sys.path.insert(0, os.path.dirname(rootdir)) + +class TestCase_w(unittest.TestCase): + """ enrich TestCase with wrapped-methods """ + + def failUnless_w(self, w_condition, msg=None): + condition = self.space.is_true(w_condition) + return self.failUnless(condition, msg) + + def failIf_w(self, w_condition, msg=None): + condition = self.space.is_true(w_condition) + return self.failIf(condition, msg) + + def assertEqual_w(self, w_first, w_second, msg=None): + w_condition = self.space.eq(w_first, w_second) + condition = self.space.is_true(w_condition) + return self.failUnless(condition, msg) + + def assertNotEqual_w(self, w_first, w_second, msg=None): + w_condition = self.space.eq(w_first, w_second) + condition = self.space.is_true(w_condition) + return self.failIf(condition, msg) + + def assertRaises_w(self, w_exc_class, callable, *args, **kw): + from pypy.objspace.std.objspace import OperationError + try: + callable(*args, **kw) + except OperationError, e: + self.failUnless(e.match(self.space, w_exc_class)) + else: + self.fail('should have got an exception') From alex at codespeak.net Mon May 26 16:42:06 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 16:42:06 +0200 (MEST) Subject: [pypy-svn] rev 452 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526144206.1FB295B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 16:42:05 2003 New Revision: 452 Added: pypy/trunk/src/pypy/interpreter/testsupport.py - copied unchanged from rev 446, pypy/trunk/src/pypy/objspace/std/test/testsupport.py Modified: pypy/trunk/src/pypy/interpreter/extmodule.py pypy/trunk/src/pypy/interpreter/unittest_w.py Log: refactored unittest_w and testsupport Modified: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Mon May 26 16:42:05 2003 @@ -6,6 +6,12 @@ def __get__(self, instance, cls=None): return self.func.__get__(instance, cls) +class appdata(object): + def __init__(self, data): + self.data = data + def __get__(self, instance, cls=None): + return self.data + class PyBuiltinCode(PyBaseCode): """The code object implementing a built-in (interpreter-level) hook.""" @@ -52,4 +58,7 @@ code = PyBuiltinCode(self, value) w_function = space.newfunction(code, space.w_None, None) space.setattr(w_module, space.wrap(key), w_function) + elif isinstance(value, appdata): + w_data = space.wrap(value.data) + space.setattr(w_module, space.wrap(key), w_data) return w_module Modified: pypy/trunk/src/pypy/interpreter/unittest_w.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/unittest_w.py (original) +++ pypy/trunk/src/pypy/interpreter/unittest_w.py Mon May 26 16:42:05 2003 @@ -1,8 +1,6 @@ import sys, os import unittest -sys.path.insert(0, os.path.dirname(rootdir)) - class TestCase_w(unittest.TestCase): """ enrich TestCase with wrapped-methods """ From alex at codespeak.net Mon May 26 16:43:38 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 16:43:38 +0200 (MEST) Subject: [pypy-svn] rev 453 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030526144338.0D3F45B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 16:43:37 2003 New Revision: 453 Removed: pypy/trunk/src/pypy/objspace/std/test/gorp.py Modified: pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py pypy/trunk/src/pypy/objspace/std/test/test_intobject.py pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py pypy/trunk/src/pypy/objspace/std/test/test_template.py pypy/trunk/src/pypy/objspace/std/test/testsupport.py Log: refactored testsupport and unittest_w Deleted: pypy/trunk/src/pypy/objspace/std/test/gorp.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/gorp.py Mon May 26 16:43:37 2003 +++ (empty file) @@ -1 +0,0 @@ -gorp Modified: pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py Mon May 26 16:43:37 2003 @@ -1,10 +1,11 @@ import unittest, sys import testsupport +from pypy.interpreter import unittest_w from pypy.objspace.std import dictobject as dobj from pypy.objspace.std.objspace import * -class TestW_DictObject(testsupport.TestCase_w): +class TestW_DictObject(unittest_w.TestCase_w): def setUp(self): self.space = StdObjSpace() Modified: pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py Mon May 26 16:43:37 2003 @@ -3,6 +3,9 @@ import sys import os +print "not working, rewrite this test!" +sys.exit(0) + #Start HACK ####################################### @@ -10,7 +13,7 @@ # an "objectspace" ####################################### -import objspace +import pypy.objspace thisdir = os.getcwd() syspath = sys.path sys.path.insert(0,thisdir) Modified: pypy/trunk/src/pypy/objspace/std/test/test_intobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_intobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_intobject.py Mon May 26 16:43:37 2003 @@ -1,10 +1,11 @@ import unittest, sys import testsupport +from pypy.interpreter import unittest_w from pypy.objspace.std import intobject as iobj from pypy.objspace.std.objspace import * -class TestW_IntObject(testsupport.TestCase_w): +class TestW_IntObject(unittest_w.TestCase_w): def setUp(self): self.space = StdObjSpace() Modified: pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py Mon May 26 16:43:37 2003 @@ -1,10 +1,11 @@ import unittest, sys import testsupport +from pypy.interpreter import unittest_w from pypy.objspace.std import moduleobject as mobj from pypy.objspace.std.objspace import * -class TestW_ModuleObject(testsupport.TestCase_w): +class TestW_ModuleObject(unittest_w.TestCase_w): def setUp(self): self.space = StdObjSpace() Modified: pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py Mon May 26 16:43:37 2003 @@ -1,10 +1,11 @@ import unittest, sys import testsupport +from pypy.interpreter import unittest_w from pypy.objspace.std import noneobject as nobj from pypy.objspace.std.objspace import * -class TestW_NoneObject(testsupport.TestCase_w): +class TestW_NoneObject(unittest_w.TestCase_w): def setUp(self): self.space = StdObjSpace() Modified: pypy/trunk/src/pypy/objspace/std/test/test_template.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_template.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_template.py Mon May 26 16:43:37 2003 @@ -1,3 +1,7 @@ +import sys +print "not working, do not run nor use this!" +sys.exit(0) + import objspace thisdir = os.getcwd() syspath = sys.path Modified: pypy/trunk/src/pypy/objspace/std/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/testsupport.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/testsupport.py Mon May 26 16:43:37 2003 @@ -7,32 +7,3 @@ sys.path.insert(0, os.path.dirname(rootdir)) -class TestCase_w(unittest.TestCase): - """ enrich TestCase with wrapped-methods """ - - def failUnless_w(self, w_condition, msg=None): - condition = self.space.is_true(w_condition) - return self.failUnless(condition, msg) - - def failIf_w(self, w_condition, msg=None): - condition = self.space.is_true(w_condition) - return self.failIf(condition, msg) - - def assertEqual_w(self, w_first, w_second, msg=None): - w_condition = self.space.eq(w_first, w_second) - condition = self.space.is_true(w_condition) - return self.failUnless(condition, msg) - - def assertNotEqual_w(self, w_first, w_second, msg=None): - w_condition = self.space.eq(w_first, w_second) - condition = self.space.is_true(w_condition) - return self.failIf(condition, msg) - - def assertRaises_w(self, w_exc_class, callable, *args, **kw): - from pypy.objspace.std.objspace import OperationError - try: - callable(*args, **kw) - except OperationError, e: - self.failUnless(e.match(self.space, w_exc_class)) - else: - self.fail('should have got an exception') From arigo at codespeak.net Mon May 26 16:53:34 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 16:53:34 +0200 (MEST) Subject: [pypy-svn] rev 454 - in pypy/trunk/src/pypy: interpreter module objspace/std objspace/std/test Message-ID: <20030526145334.CD7685B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 16:53:34 2003 New Revision: 454 Modified: pypy/trunk/src/pypy/interpreter/appfile.py pypy/trunk/src/pypy/interpreter/baseobjspace.py pypy/trunk/src/pypy/interpreter/extmodule.py (props changed) pypy/trunk/src/pypy/interpreter/main.py pypy/trunk/src/pypy/interpreter/opcode.py pypy/trunk/src/pypy/interpreter/pycode.py pypy/trunk/src/pypy/interpreter/pyframe.py pypy/trunk/src/pypy/module/builtin.py pypy/trunk/src/pypy/objspace/std/funcobject.py pypy/trunk/src/pypy/objspace/std/moduleobject.py (props changed) pypy/trunk/src/pypy/objspace/std/objspace.py pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py (props changed) pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py (props changed) Log: If strings knew their length, we'd have acheived our goal for today. Now sort out your conflicts (evil cackle). Modified: pypy/trunk/src/pypy/interpreter/appfile.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/appfile.py (original) +++ pypy/trunk/src/pypy/interpreter/appfile.py Mon May 26 16:53:34 2003 @@ -29,7 +29,7 @@ f = open(filename, 'r') src = f.read() f.close() - print filename + #print filename self.bytecode = compile(src, filename, 'exec') @@ -57,8 +57,11 @@ # initialize the module by running the bytecode in a new # dictionary, in a new execution context from pyframe import PyFrame + from pycode import PyByteCode ec = self.space.getexecutioncontext() - frame = PyFrame(self.space, bytecode, + res = PyByteCode() + res._from_code(bytecode) + frame = PyFrame(self.space, res, self.w_namespace, self.w_namespace) ec.eval_frame(frame) Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/baseobjspace.py (original) +++ pypy/trunk/src/pypy/interpreter/baseobjspace.py Mon May 26 16:53:34 2003 @@ -1,5 +1,6 @@ from executioncontext import ExecutionContext, OperationError, NoValue import pyframe +import pypy.module.builtin __all__ = ['ObjSpace', 'OperationError', 'NoValue', 'PyPyError'] @@ -16,12 +17,15 @@ def __init__(self): "Basic initialization of objects." - self.w_builtins = self.newdict([]) - self.w_modules = self.newdict([]) + self.w_modules = self.newdict([]) self.appfile_helpers = {} self.initialize() - #import builtins - #builtins.init(self) + + def make_builtins(self): + self.builtin = pypy.module.builtin.Builtin(self) + w_builtin = self.builtin.wrap_me() + self.w_builtins = self.getattr(w_builtin, self.wrap("__dict__")) + self.setitem(self.w_modules, self.wrap("__builtin__"), w_builtin) def initialize(self): """Abstract method that should put some minimal content into the Modified: pypy/trunk/src/pypy/interpreter/main.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/main.py (original) +++ pypy/trunk/src/pypy/interpreter/main.py Mon May 26 16:53:34 2003 @@ -1,23 +1,25 @@ from pypy.objspace.std import StdObjSpace -from pypy.objspace.trivial import TrivialObjSpace -import executioncontext, baseobjspace, pyframe - +from pypy.module.builtin import Builtin +from pypy.interpreter import executioncontext, baseobjspace, pyframe import sys def run_string(source, fname): try: space = StdObjSpace() + compile = space.builtin.compile w=space.wrap - code = compile(w(source), w(fname), w('exec')) + w_code = compile(w(source), w(fname), w('exec'), + w(0), w(0)) + ec = executioncontext.ExecutionContext(space) w_mainmodule = space.newmodule(space.wrap("__main__")) w_globals = space.getattr(w_mainmodule, space.wrap("__dict__")) - space.setitem(w_globals, space.wrap("__builtins__"), - ec.get_w_builtins()) + space.setitem(w_globals, space.wrap("__builtins__"), space.w_builtins) - frame = pyframe.PyFrame(space, code, w_globals, w_globals) + frame = pyframe.PyFrame(space, space.unwrap(w_code), + w_globals, w_globals) except baseobjspace.OperationError, operationerr: raise baseobjspace.PyPyError(space, operationerr) else: Modified: pypy/trunk/src/pypy/interpreter/opcode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/opcode.py (original) +++ pypy/trunk/src/pypy/interpreter/opcode.py Mon May 26 16:53:34 2003 @@ -626,7 +626,8 @@ defaultarguments = [f.valuestack.pop() for i in range(numdefaults)] defaultarguments.reverse() w_defaultarguments = f.space.newtuple(defaultarguments) - w_func = f.space.newfunction(w_codeobj, f.w_globals, w_defaultarguments) + w_func = f.space.newfunction(f.space.unwrap(w_codeobj), + f.w_globals, w_defaultarguments) f.valuestack.push(w_func) def MAKE_CLOSURE(f, numdefaults): @@ -639,8 +640,8 @@ defaultarguments = [f.valuestack.pop() for i in range(numdefaults)] defaultarguments.reverse() w_defaultarguments = f.space.newtuple(defaultarguments) - w_func = f.space.newfunction(w_codeobj, f.w_globals, w_defaultarguments, - w_freevars) + w_func = f.space.newfunction(f.space.unwrap(w_codeobj), + f.w_globals, w_defaultarguments, w_freevars) f.valuestack.push(w_func) def BUILD_SLICE(f, numargs): Modified: pypy/trunk/src/pypy/interpreter/pycode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pycode.py (original) +++ pypy/trunk/src/pypy/interpreter/pycode.py Mon May 26 16:53:34 2003 @@ -21,6 +21,10 @@ appfile = AppFile(__name__, ["interpreter"]) +CO_VARARGS = 0x0004 +CO_VARKEYWORDS = 0x0008 + + class PyBaseCode: def __init__(self): self.co_name = "" @@ -97,6 +101,15 @@ for name in self.__dict__.keys(): value = getattr(code, name) setattr(self, name, value) + newconsts = () + for const in code.co_consts: + if isinstance(const, types.CodeType): + newc = PyByteCode() + newc._from_code(const) + newconsts = newconsts + (newc,) + else: + newconsts = newconsts + (const,) + self.co_consts = newconsts def eval_code(self, space, w_globals, w_locals): frame = pyframe.PyFrame(space, self, w_globals, w_locals) Modified: pypy/trunk/src/pypy/interpreter/pyframe.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pyframe.py (original) +++ pypy/trunk/src/pypy/interpreter/pyframe.py Mon May 26 16:53:34 2003 @@ -11,9 +11,6 @@ appfile = AppFile(__name__, ["interpreter"]) -CO_VARARGS = 0x0004 -CO_VARKEYWORDS = 0x0008 - class PyFrame: """Represents a frame for a regular Python function Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 16:53:34 2003 @@ -21,6 +21,7 @@ def compile(self, w_str, w_filename, w_startstr, w_supplied_flags, w_dont_inherit): + space = self.space str = space.unwrap(w_str) filename = space.unwrap(w_filename) startstr = space.unwrap(w_startstr) Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/funcobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/funcobject.py Mon May 26 16:53:34 2003 @@ -4,8 +4,8 @@ class W_FuncObject(object): - def __init__(w_self, w_code, w_globals, w_defaultarguments, w_closure): - w_self.w_code = w_code + def __init__(w_self, code, w_globals, w_defaultarguments, w_closure): + w_self.code = code w_self.w_globals = w_globals w_self.w_defaultarguments = w_defaultarguments w_self.w_closure = w_closure @@ -25,7 +25,8 @@ def func_call(space, w_function, w_arguments, w_keywords): - somecode = space.unwrap(w_function.w_code) + somecode = w_function.code + print somecode w_globals = w_function.w_globals w_locals = somecode.build_arguments(space, w_arguments, w_keywords, w_defaults = w_function.w_defaultarguments, 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 Mon May 26 16:53:34 2003 @@ -27,6 +27,7 @@ self.w_None = W_NoneObject() self.w_False = W_BoolObject(False) self.w_True = W_BoolObject(True) + self.make_builtins() # hack in the exception classes import __builtin__, types for n, c in __builtin__.__dict__.iteritems(): From arigo at codespeak.net Mon May 26 16:58:30 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 16:58:30 +0200 (MEST) Subject: [pypy-svn] rev 455 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030526145830.7A97B5B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 16:58:30 2003 New Revision: 455 Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py Log: removed debugging print Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/funcobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/funcobject.py Mon May 26 16:58:30 2003 @@ -26,7 +26,6 @@ def func_call(space, w_function, w_arguments, w_keywords): somecode = w_function.code - print somecode w_globals = w_function.w_globals w_locals = somecode.build_arguments(space, w_arguments, w_keywords, w_defaults = w_function.w_defaultarguments, From arigo at codespeak.net Mon May 26 16:59:45 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 16:59:45 +0200 (MEST) Subject: [pypy-svn] rev 456 - in pypy/trunk/src/pypy: interpreter module objspace/std Message-ID: <20030526145945.664A15B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 16:59:44 2003 New Revision: 456 Modified: pypy/trunk/src/pypy/interpreter/opcode_app.py pypy/trunk/src/pypy/module/builtin.py pypy/trunk/src/pypy/objspace/std/stringobject.py Log: we've done it Modified: pypy/trunk/src/pypy/interpreter/opcode_app.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/opcode_app.py (original) +++ pypy/trunk/src/pypy/interpreter/opcode_app.py Mon May 26 16:59:44 2003 @@ -57,8 +57,7 @@ def print_item_to(x, stream): if file_softspace(stream, False): stream.write(" ") - # XXX str call should go here!!! for now, only print strings -- mwh - stream.write(x) + stream.write(str(x)) # add a softspace unless we just printed a string which ends in a '\t' # or '\n' -- or more generally any whitespace character but ' ' # if isinstance(x, str) and len(x) and x[-1].isspace() and x[-1]!=' ': Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 16:59:44 2003 @@ -19,6 +19,10 @@ return self.space.len(w_obj) len = appmethod(len) + def str(self, w_obj): + return self.space.str(w_obj) + str = appmethod(str) + def compile(self, w_str, w_filename, w_startstr, w_supplied_flags, w_dont_inherit): space = self.space Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Mon May 26 16:59:44 2003 @@ -80,3 +80,8 @@ def mod_str_tuple(space, w_format, w_args): notImplemented + +def len_str(space, w_str): + return space.wrap(len(w_str.value)) + +StdObjSpace.len.register(len_str, W_StringObject) From tomek at codespeak.net Mon May 26 17:08:10 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Mon, 26 May 2003 17:08:10 +0200 (MEST) Subject: [pypy-svn] rev 457 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030526150810.372335B0F3@thoth.codespeak.net> Author: tomek Date: Mon May 26 17:08:09 2003 New Revision: 457 Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py Log: A simple __import__ hook Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/funcobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/funcobject.py Mon May 26 17:08:09 2003 @@ -27,6 +27,10 @@ def func_call(space, w_function, w_arguments, w_keywords): somecode = w_function.code w_globals = w_function.w_globals + print somecode + print w_function.w_code + print dir(somecode) + print somecode.__class__ w_locals = somecode.build_arguments(space, w_arguments, w_keywords, w_defaults = w_function.w_defaultarguments, w_closure = w_function.w_closure) From tomek at codespeak.net Mon May 26 17:08:46 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Mon, 26 May 2003 17:08:46 +0200 (MEST) Subject: [pypy-svn] rev 458 - pypy/trunk/src/pypy/module Message-ID: <20030526150846.2A5E95B0F3@thoth.codespeak.net> Author: tomek Date: Mon May 26 17:08:45 2003 New Revision: 458 Modified: pypy/trunk/src/pypy/module/builtin.py Log: A simple __import__ hook Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 17:08:45 2003 @@ -1,5 +1,6 @@ from pypy.interpreter.extmodule import * from pypy.interpreter.pycode import PyByteCode +from pypy.interpreter.executioncontext import OperationError ####################### #### __builtin__ #### @@ -7,6 +8,9 @@ import __builtin__ as _b +##compile.__doc__ = _b.compile.__doc__ + + class Builtin(BuiltinModule): __pythonname__ = '__builtin__' @@ -19,18 +23,35 @@ return self.space.len(w_obj) len = appmethod(len) - def str(self, w_obj): - return self.space.str(w_obj) - str = appmethod(str) - def compile(self, w_str, w_filename, w_startstr, - w_supplied_flags, w_dont_inherit): + def __import__(self,w_modulename,w_locals,w_globals,w_fromlist): space = self.space + try: + w_mod = space.getitem(space.w_modules,w_modulename) + return w_mod + except OperationError,e: + if not e.match(space,space.w_KeyError): + raise + raise OperationError(space.w_ImportError) + + + + __import__ = appmethod(__import__) + + def compile(self, w_str, w_filename, w_startstr, + w_supplied_flags=None, w_dont_inherit=None): str = space.unwrap(w_str) filename = space.unwrap(w_filename) startstr = space.unwrap(w_startstr) - supplied_flags = space.unwrap(w_supplied_flags) - dont_inherit = space.unwrap(w_dont_inherit) + if w_supplied_flags is None: + supplied_flags = 0 + else: + supplied_flags = space.unwrap(w_supplied_flags) + if w_dont_inherit is None: + dont_inherit = False + else: + dont_inherit = space.unwrap(w_dont_inherit) + c = _b.compile(str, filename, startstr, supplied_flags, dont_inherit) res = PyByteCode() res._from_code(c) From tismer at codespeak.net Mon May 26 17:23:16 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 17:23:16 +0200 (MEST) Subject: [pypy-svn] rev 459 - pypy/trunk/src/pypy/module Message-ID: <20030526152316.038195B0F3@thoth.codespeak.net> Author: tismer Date: Mon May 26 17:23:16 2003 New Revision: 459 Modified: pypy/trunk/src/pypy/module/builtin.py Log: repaired some checkin mismatch Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 17:23:16 2003 @@ -8,9 +8,6 @@ import __builtin__ as _b -##compile.__doc__ = _b.compile.__doc__ - - class Builtin(BuiltinModule): __pythonname__ = '__builtin__' @@ -33,24 +30,16 @@ if not e.match(space,space.w_KeyError): raise raise OperationError(space.w_ImportError) - - - __import__ = appmethod(__import__) def compile(self, w_str, w_filename, w_startstr, w_supplied_flags=None, w_dont_inherit=None): + space = self.space str = space.unwrap(w_str) filename = space.unwrap(w_filename) startstr = space.unwrap(w_startstr) - if w_supplied_flags is None: - supplied_flags = 0 - else: - supplied_flags = space.unwrap(w_supplied_flags) - if w_dont_inherit is None: - dont_inherit = False - else: - dont_inherit = space.unwrap(w_dont_inherit) + supplied_flags = space.unwrap(w_supplied_flags) + dont_inherit = space.unwrap(w_dont_inherit) c = _b.compile(str, filename, startstr, supplied_flags, dont_inherit) res = PyByteCode() From arigo at codespeak.net Mon May 26 17:26:15 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 17:26:15 +0200 (MEST) Subject: [pypy-svn] rev 460 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030526152615.B6DE75B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 17:26:15 2003 New Revision: 460 Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py Log: cancelled accidential commit of an old version Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/funcobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/funcobject.py Mon May 26 17:26:15 2003 @@ -27,10 +27,6 @@ def func_call(space, w_function, w_arguments, w_keywords): somecode = w_function.code w_globals = w_function.w_globals - print somecode - print w_function.w_code - print dir(somecode) - print somecode.__class__ w_locals = somecode.build_arguments(space, w_arguments, w_keywords, w_defaults = w_function.w_defaultarguments, w_closure = w_function.w_closure) From mwh at codespeak.net Mon May 26 17:26:53 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Mon, 26 May 2003 17:26:53 +0200 (MEST) Subject: [pypy-svn] rev 461 - pypy/trunk/src/pypy/module Message-ID: <20030526152653.220795B0F3@thoth.codespeak.net> Author: mwh Date: Mon May 26 17:26:52 2003 New Revision: 461 Added: pypy/trunk/src/pypy/module/sys.py Log: very glimmerings of 'sys' Added: pypy/trunk/src/pypy/module/sys.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/sys.py Mon May 26 17:26:52 2003 @@ -0,0 +1,5 @@ +from pypy.interpreter.extmodule import * + +class Sys(BuiltinModule): + __pythonname__ = 'sys' + From mwh at codespeak.net Mon May 26 17:40:27 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Mon, 26 May 2003 17:40:27 +0200 (MEST) Subject: [pypy-svn] rev 462 - pypy/trunk/src/pypy/module Message-ID: <20030526154027.0B6235B0F3@thoth.codespeak.net> Author: mwh Date: Mon May 26 17:40:26 2003 New Revision: 462 Added: pypy/trunk/src/pypy/module/sysmodule.py - copied unchanged from rev 461, pypy/trunk/src/pypy/module/sys.py Removed: pypy/trunk/src/pypy/module/sys.py Log: eh, having a module called "sys" is pretty dumb... Deleted: pypy/trunk/src/pypy/module/sys.py ============================================================================== --- pypy/trunk/src/pypy/module/sys.py Mon May 26 17:40:26 2003 +++ (empty file) @@ -1,5 +0,0 @@ -from pypy.interpreter.extmodule import * - -class Sys(BuiltinModule): - __pythonname__ = 'sys' - From arigo at codespeak.net Mon May 26 17:43:36 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 17:43:36 +0200 (MEST) Subject: [pypy-svn] rev 463 - in pypy/trunk/src/pypy: interpreter module objspace/std Message-ID: <20030526154336.2E8C25B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 17:43:35 2003 New Revision: 463 Modified: pypy/trunk/src/pypy/interpreter/appfile.py 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/pyframe.py pypy/trunk/src/pypy/module/builtin.py pypy/trunk/src/pypy/objspace/std/objspace.py Log: builtin_app.py is now loaded Modified: pypy/trunk/src/pypy/interpreter/appfile.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/appfile.py (original) +++ pypy/trunk/src/pypy/interpreter/appfile.py Mon May 26 17:43:35 2003 @@ -35,10 +35,12 @@ class Namespace: - def __init__(self, space): + def __init__(self, space, w_namespace=None): self.space = space ec = space.getexecutioncontext() - self.w_namespace = ec.make_standard_w_globals() + if w_namespace is None: + w_namespace = ec.make_standard_w_globals() + self.w_namespace = w_namespace def get(self, objname): "Returns a wrapped copy of an object by name." @@ -68,6 +70,6 @@ class AppHelper(Namespace): - def __init__(self, space, bytecode): - Namespace.__init__(self, space) - self.runbytecode(bytecode) + def __init__(self, space, appfile, w_namespace=None): + Namespace.__init__(self, space, w_namespace) + self.runbytecode(appfile.bytecode) Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/baseobjspace.py (original) +++ pypy/trunk/src/pypy/interpreter/baseobjspace.py Mon May 26 17:43:35 2003 @@ -17,6 +17,7 @@ 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() @@ -48,7 +49,7 @@ helper = self.appfile_helpers[applicationfile] except KeyError: from appfile import AppHelper - helper = AppHelper(self, applicationfile.bytecode) + helper = AppHelper(self, applicationfile) self.appfile_helpers[applicationfile] = helper return helper Modified: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Mon May 26 17:43:35 2003 @@ -1,4 +1,5 @@ from pycode import PyBaseCode +from appfile import AppHelper class appmethod(object): def __init__(self, func): @@ -45,6 +46,7 @@ class BuiltinModule: + __appfile__ = None def __init__(self, space): self.space = space @@ -61,4 +63,8 @@ elif isinstance(value, appdata): w_data = space.wrap(value.data) space.setattr(w_module, space.wrap(key), w_data) + appfile = self.__appfile__ + if appfile: + w_dict = space.getattr(w_module, space.wrap("__dict__")) + AppHelper(space, appfile, w_dict) return w_module Modified: pypy/trunk/src/pypy/interpreter/main.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/main.py (original) +++ pypy/trunk/src/pypy/interpreter/main.py Mon May 26 17:43:35 2003 @@ -4,6 +4,7 @@ import sys def run_string(source, fname): + space = None # in case StdObjSpace.__init__() crashes try: space = StdObjSpace() @@ -40,6 +41,8 @@ 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) except baseobjspace.OperationError, operationerr: operationerr.print_detailed_traceback(operationerr.space) Modified: pypy/trunk/src/pypy/interpreter/pyframe.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pyframe.py (original) +++ pypy/trunk/src/pypy/interpreter/pyframe.py Mon May 26 17:43:35 2003 @@ -145,7 +145,12 @@ # initialize self.w_builtins. This cannot be done in the '.app.py' # file for bootstrapping reasons. w_builtinsname = self.space.wrap("__builtins__") - w_builtins = self.space.getitem(self.w_globals, w_builtinsname) + try: + w_builtins = self.space.getitem(self.w_globals, w_builtinsname) + except OperationError, e: + if not e.match(self.space, self.space.w_KeyError): + raise + w_builtins = self.space.w_builtins # fall-back for bootstrapping # w_builtins can be a module object or a dictionary object. # In frameobject.c we explicitely check if w_builtins is a module # object. Here we will just try to read its __dict__ attribute and Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 17:43:35 2003 @@ -1,5 +1,6 @@ from pypy.interpreter.extmodule import * from pypy.interpreter.pycode import PyByteCode +from pypy.interpreter.appfile import AppFile from pypy.interpreter.executioncontext import OperationError ####################### @@ -10,6 +11,7 @@ class Builtin(BuiltinModule): __pythonname__ = '__builtin__' + __appfile__ = AppFile(__name__, ["module"]) def chr(self, w_ascii): w_character = self.space.newstring([w_ascii]) 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 Mon May 26 17:43:35 2003 @@ -27,17 +27,21 @@ self.w_None = W_NoneObject() self.w_False = W_BoolObject(False) self.w_True = W_BoolObject(True) - self.make_builtins() # hack in the exception classes import __builtin__, types + newstuff = {"False": self.w_False, + "True" : self.w_True, + "None" : self.w_None, + } for n, c in __builtin__.__dict__.iteritems(): if isinstance(c, types.ClassType) and issubclass(c, Exception): w_c = W_CPythonObject(c) setattr(self, 'w_' + c.__name__, w_c) - self.setitem(self.w_builtins, self.wrap(c.__name__), w_c) - self.setitem(self.w_builtins, self.wrap("False"), self.w_False) - self.setitem(self.w_builtins, self.wrap("True"), self.w_True) - self.setitem(self.w_builtins, self.wrap("None"), self.w_None) + newstuff[c.__name__] = w_c + self.make_builtins() + # insert these into the newly-made builtins + for key, w_value in newstuff.items(): + self.setitem(self.w_builtins, self.wrap(key), w_value) # add a dummy __import__ XXX fixme w_import = self.wrap(__import__) self.setitem(self.w_builtins, self.wrap("__import__"), w_import) From arigo at codespeak.net Mon May 26 17:44:13 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 17:44:13 +0200 (MEST) Subject: [pypy-svn] rev 464 - pypy/trunk/src/pypy/module Message-ID: <20030526154413.A0D055B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 17:44:13 2003 New Revision: 464 Modified: pypy/trunk/src/pypy/module/builtin.py Log: str() is back Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 17:44:13 2003 @@ -22,6 +22,9 @@ return self.space.len(w_obj) len = appmethod(len) + def str(self, w_obj): + return self.space.str(w_obj) + str = appmethod(str) def __import__(self,w_modulename,w_locals,w_globals,w_fromlist): space = self.space From tomek at codespeak.net Mon May 26 17:47:36 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Mon, 26 May 2003 17:47:36 +0200 (MEST) Subject: [pypy-svn] rev 465 - pypy/trunk/src/pypy/module Message-ID: <20030526154736.8D6935B0F3@thoth.codespeak.net> Author: tomek Date: Mon May 26 17:47:36 2003 New Revision: 465 Modified: pypy/trunk/src/pypy/module/builtin.py Log: Bugs von __import__ Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 17:47:36 2003 @@ -26,15 +26,15 @@ return self.space.str(w_obj) str = appmethod(str) - def __import__(self,w_modulename,w_locals,w_globals,w_fromlist): + def __import__(self, w_modulename, w_locals, w_globals, w_fromlist): space = self.space try: - w_mod = space.getitem(space.w_modules,w_modulename) + w_mod = space.getitem(space.w_modules, w_modulename) return w_mod except OperationError,e: - if not e.match(space,space.w_KeyError): + if not e.match(space, space.w_KeyError): raise - raise OperationError(space.w_ImportError) + raise OperationError(space.w_ImportError, w_modulename) __import__ = appmethod(__import__) def compile(self, w_str, w_filename, w_startstr, From mwh at codespeak.net Mon May 26 17:52:26 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Mon, 26 May 2003 17:52:26 +0200 (MEST) Subject: [pypy-svn] rev 466 - in pypy/trunk/src/pypy: interpreter module objspace/std Message-ID: <20030526155226.8D9E95B0F3@thoth.codespeak.net> Author: mwh Date: Mon May 26 17:52:26 2003 New Revision: 466 Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py pypy/trunk/src/pypy/module/sysmodule.py pypy/trunk/src/pypy/objspace/std/objspace.py Log: use our __import__ hook Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/baseobjspace.py (original) +++ pypy/trunk/src/pypy/interpreter/baseobjspace.py Mon May 26 17:52:26 2003 @@ -28,6 +28,13 @@ self.w_builtins = self.getattr(w_builtin, self.wrap("__dict__")) self.setitem(self.w_modules, self.wrap("__builtin__"), w_builtin) + def make_sys(self): + import pypy.module.sysmodule + self.sys = pypy.module.sysmodule.Sys(self) + self.w_sys = self.sys.wrap_me() + self.setitem(self.w_modules, self.wrap("sys"), self.w_sys) + self.setattr(self.w_sys, self.wrap("modules"), self.w_modules) + def initialize(self): """Abstract method that should put some minimal content into the w_builtins.""" Modified: pypy/trunk/src/pypy/module/sysmodule.py ============================================================================== --- pypy/trunk/src/pypy/module/sysmodule.py (original) +++ pypy/trunk/src/pypy/module/sysmodule.py Mon May 26 17:52:26 2003 @@ -1,5 +1,6 @@ from pypy.interpreter.extmodule import * +import sys class Sys(BuiltinModule): __pythonname__ = 'sys' - + stdout = appdata(sys.stdout) 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 Mon May 26 17:52:26 2003 @@ -39,12 +39,13 @@ setattr(self, 'w_' + c.__name__, w_c) newstuff[c.__name__] = w_c self.make_builtins() + self.make_sys() # insert these into the newly-made builtins for key, w_value in newstuff.items(): self.setitem(self.w_builtins, self.wrap(key), w_value) # add a dummy __import__ XXX fixme - w_import = self.wrap(__import__) - self.setitem(self.w_builtins, self.wrap("__import__"), w_import) +# w_import = self.wrap(__import__) +# self.setitem(self.w_builtins, self.wrap("__import__"), w_import) def wrap(self, x): "Wraps the Python value 'x' into one of the wrapper classes." From arigo at codespeak.net Mon May 26 18:05:41 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 18:05:41 +0200 (MEST) Subject: [pypy-svn] rev 467 - in pypy/trunk/src/pypy: interpreter/test objspace/std Message-ID: <20030526160541.856705B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 18:05:41 2003 New Revision: 467 Modified: pypy/trunk/src/pypy/interpreter/test/hello_world.py pypy/trunk/src/pypy/objspace/std/cpythonobject.py Log: builtin_app.py usable Modified: pypy/trunk/src/pypy/interpreter/test/hello_world.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/hello_world.py (original) +++ pypy/trunk/src/pypy/interpreter/test/hello_world.py Mon May 26 18:05:41 2003 @@ -1,6 +1,5 @@ -def main(): - aStr = "hello world" +def main(aStr): print len(aStr) -main() +map(main, ["hello world", "good bye"]) Modified: pypy/trunk/src/pypy/objspace/std/cpythonobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/cpythonobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/cpythonobject.py Mon May 26 18:05:41 2003 @@ -227,7 +227,7 @@ def cpython_next(space, w_obj): obj = space.unwrap(w_obj) try: - result = w.next() + result = obj.next() except StopIteration: raise NoValue except: From mwh at codespeak.net Mon May 26 18:17:50 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Mon, 26 May 2003 18:17:50 +0200 (MEST) Subject: [pypy-svn] rev 468 - pypy/trunk/src/pypy/module/test Message-ID: <20030526161750.9BDBD5B0F3@thoth.codespeak.net> Author: mwh Date: Mon May 26 18:17:50 2003 New Revision: 468 Added: pypy/trunk/src/pypy/module/test/test_sysmodule.py pypy/trunk/src/pypy/module/test/testsupport.py Log: add test_sysmodule, testsupport Added: pypy/trunk/src/pypy/module/test/test_sysmodule.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/test_sysmodule.py Mon May 26 18:17:50 2003 @@ -0,0 +1,3 @@ +import unittest + + Added: pypy/trunk/src/pypy/module/test/testsupport.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/testsupport.py Mon May 26 18:17:50 2003 @@ -0,0 +1,9 @@ +import sys, os + +opd = os.path.dirname + +testdir = opd(os.path.abspath(__file__)) +parentdir = opd(testdir) +rootdir = opd(parentdir) + +sys.path.insert(0, opd(rootdir)) From mwh at codespeak.net Mon May 26 18:30:35 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Mon, 26 May 2003 18:30:35 +0200 (MEST) Subject: [pypy-svn] rev 469 - in pypy/trunk/src/pypy/module: . test Message-ID: <20030526163035.71AE65B0F3@thoth.codespeak.net> Author: mwh Date: Mon May 26 18:30:35 2003 New Revision: 469 Modified: pypy/trunk/src/pypy/module/sysmodule.py pypy/trunk/src/pypy/module/test/test_sysmodule.py Log: actually put a test in test_sysmodule.py Modified: pypy/trunk/src/pypy/module/sysmodule.py ============================================================================== --- pypy/trunk/src/pypy/module/sysmodule.py (original) +++ pypy/trunk/src/pypy/module/sysmodule.py Mon May 26 18:30:35 2003 @@ -4,3 +4,4 @@ class Sys(BuiltinModule): __pythonname__ = 'sys' stdout = appdata(sys.stdout) + Modified: pypy/trunk/src/pypy/module/test/test_sysmodule.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_sysmodule.py (original) +++ pypy/trunk/src/pypy/module/test/test_sysmodule.py Mon May 26 18:30:35 2003 @@ -1,3 +1,19 @@ -import unittest +import testsupport, unittest +from pypy.interpreter.unittest_w import TestCase_w +from pypy.objspace.std.objspace import StdObjSpace +class SysTests(TestCase_w): + def setUp(self): + self.space = StdObjSpace() + self.sys_w = self.space.getitem(self.space.w_modules, + self.space.wrap("sys")) + def tearDown(self): + pass + + def test_stdout_exists(self): + s = self.space + self.failUnless_w(s.getattr(self.sys_w, s.wrap("stdout"))) + +if __name__ == '__main__': + unittest.main() From alex at codespeak.net Mon May 26 18:38:47 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 18:38:47 +0200 (MEST) Subject: [pypy-svn] rev 470 - pypy/trunk/src/pypy Message-ID: <20030526163847.5A4745B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 18:38:47 2003 New Revision: 470 Added: pypy/trunk/src/pypy/testsupport.py Log: Master version of testsupport Added: pypy/trunk/src/pypy/testsupport.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/testsupport.py Mon May 26 18:38:47 2003 @@ -0,0 +1,17 @@ +""" +Master version of testsupport.py: copy into any subdirectory of pypy +from which scripts need to be run (typically all of the 'test' subdirs) +so that any test can "import testsupport" to ensure the parent of pypy +is on the sys.path -- so that "import pypy.etc.etc." always works. +""" +import sys, os + +head = this_path = os.path.abspath(__file__) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + sys.path.insert(0, head) + break + From alex at codespeak.net Mon May 26 18:41:52 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 18:41:52 +0200 (MEST) Subject: [pypy-svn] rev 471 - in pypy/trunk/src/pypy: interpreter interpreter/testmodule/test objspace/std/test Message-ID: <20030526164152.771BD5B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 18:41:51 2003 New Revision: 471 Added: pypy/trunk/src/pypy/interpreter/test/testsupport.py Removed: pypy/trunk/src/pypy/interpreter/testsupport.py Modified: pypy/trunk/src/pypy/module/test/testsupport.py pypy/trunk/src/pypy/objspace/std/test/testsupport.py Log: copy master testsupport in all test directories that need it Added: pypy/trunk/src/pypy/interpreter/test/testsupport.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/interpreter/test/testsupport.py Mon May 26 18:41:51 2003 @@ -0,0 +1,17 @@ +""" +Master version of testsupport.py: copy into any subdirectory of pypy +from which scripts need to be run (typically all of the 'test' subdirs) +so that any test can "import testsupport" to ensure the parent of pypy +is on the sys.path -- so that "import pypy.etc.etc." always works. +""" +import sys, os + +head = this_path = os.path.abspath(__file__) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + sys.path.insert(0, head) + break + Deleted: pypy/trunk/src/pypy/interpreter/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/testsupport.py Mon May 26 18:41:51 2003 +++ (empty file) @@ -1,38 +0,0 @@ -import sys, os -import unittest - -testdir = os.path.dirname(os.path.abspath(__file__)) -parentdir = os.path.dirname(testdir) -rootdir = os.path.dirname(os.path.dirname(parentdir)) - -sys.path.insert(0, os.path.dirname(rootdir)) - -class TestCase_w(unittest.TestCase): - """ enrich TestCase with wrapped-methods """ - - def failUnless_w(self, w_condition, msg=None): - condition = self.space.is_true(w_condition) - return self.failUnless(condition, msg) - - def failIf_w(self, w_condition, msg=None): - condition = self.space.is_true(w_condition) - return self.failIf(condition, msg) - - def assertEqual_w(self, w_first, w_second, msg=None): - w_condition = self.space.eq(w_first, w_second) - condition = self.space.is_true(w_condition) - return self.failUnless(condition, msg) - - def assertNotEqual_w(self, w_first, w_second, msg=None): - w_condition = self.space.eq(w_first, w_second) - condition = self.space.is_true(w_condition) - return self.failIf(condition, msg) - - def assertRaises_w(self, w_exc_class, callable, *args, **kw): - from pypy.objspace.std.objspace import OperationError - try: - callable(*args, **kw) - except OperationError, e: - self.failUnless(e.match(self.space, w_exc_class)) - else: - self.fail('should have got an exception') Modified: pypy/trunk/src/pypy/module/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/module/test/testsupport.py (original) +++ pypy/trunk/src/pypy/module/test/testsupport.py Mon May 26 18:41:51 2003 @@ -1,9 +1,17 @@ -import sys, os - -opd = os.path.dirname - -testdir = opd(os.path.abspath(__file__)) -parentdir = opd(testdir) -rootdir = opd(parentdir) - -sys.path.insert(0, opd(rootdir)) +""" +Master version of testsupport.py: copy into any subdirectory of pypy +from which scripts need to be run (typically all of the 'test' subdirs) +so that any test can "import testsupport" to ensure the parent of pypy +is on the sys.path -- so that "import pypy.etc.etc." always works. +""" +import sys, os + +head = this_path = os.path.abspath(__file__) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + sys.path.insert(0, head) + break + Modified: pypy/trunk/src/pypy/objspace/std/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/testsupport.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/testsupport.py Mon May 26 18:41:51 2003 @@ -1,9 +1,17 @@ +""" +Master version of testsupport.py: copy into any subdirectory of pypy +from which scripts need to be run (typically all of the 'test' subdirs) +so that any test can "import testsupport" to ensure the parent of pypy +is on the sys.path -- so that "import pypy.etc.etc." always works. +""" import sys, os -import unittest -testdir = os.path.dirname(os.path.abspath(__file__)) -parentdir = os.path.dirname(testdir) -rootdir = os.path.dirname(os.path.dirname(parentdir)) - -sys.path.insert(0, os.path.dirname(rootdir)) +head = this_path = os.path.abspath(__file__) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + sys.path.insert(0, head) + break From alex at codespeak.net Mon May 26 18:43:25 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 18:43:25 +0200 (MEST) Subject: [pypy-svn] rev 472 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030526164325.695225B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 18:43:25 2003 New Revision: 472 Added: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Log: partial broken version just to save partial emulation of objspace Added: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Mon May 26 18:43:25 2003 @@ -0,0 +1,46 @@ +import unittest, sys +sys.path.append('..') + +import extmodule + +class EmptyBM(extmodule.BuiltinModule): + __pythonname__ = 'empty_bm' + +class wrapper(object): + def __init__(self, wrapped): + self.wrapped = wrapped +def is_wrapped(obj): + return isinstance(obj, wrapper) +import new +class dummyspace(object): + w_None = wrapper(None) + def wrap(self, obj): + return wrapper(obj) + def unwrap(self, obj): + return obj.wrapped + def newmodule(self, name): + return self.wrap(new.module(self.unwrap(name))) + def newfunction(self, code, w_something, somethingelse): + + +class TestBuiltinModule(unittest.TestCase): + + def setUp(self): + self.space = dummyspace() + + def tearDown(self): + pass + + def test_empty(self): + bm = EmptyBM(self.space) + w_bm = bm.wrap_me() + modobj = self.space.unwrap(w_bm) + bmd = modobj.__dict__ + bmd_kys = bmd.keys() + bmd_kys.sort() + self.assertEqual(bmd_kys, ['__doc__','__name__']) + self.assertEqual(bmd['__doc__'], EmptyBM.__doc__) + self.assertEqual(bmd['__name__'], EmptyBM.__pythonname__) + +if __name__ == '__main__': + unittest.main() From alex at codespeak.net Mon May 26 18:53:54 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 18:53:54 +0200 (MEST) Subject: [pypy-svn] rev 473 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526165354.785C05B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 18:53:54 2003 New Revision: 473 Modified: pypy/trunk/src/pypy/interpreter/pycode.py Log: removed a from Modified: pypy/trunk/src/pypy/interpreter/pycode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pycode.py (original) +++ pypy/trunk/src/pypy/interpreter/pycode.py Mon May 26 18:53:54 2003 @@ -17,9 +17,9 @@ # think of a proper base class??? import baseobjspace, pyframe -from appfile import AppFile +import appfile -appfile = AppFile(__name__, ["interpreter"]) +appfile = appfile.AppFile(__name__, ["interpreter"]) CO_VARARGS = 0x0004 CO_VARKEYWORDS = 0x0008 From alex at codespeak.net Mon May 26 18:58:07 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 18:58:07 +0200 (MEST) Subject: [pypy-svn] rev 474 - pypy/trunk/src/pypy/module Message-ID: <20030526165807.A7E855B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 18:58:07 2003 New Revision: 474 Modified: pypy/trunk/src/pypy/module/builtin.py Log: cleaned up some from statements Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 18:58:07 2003 @@ -1,7 +1,5 @@ from pypy.interpreter.extmodule import * -from pypy.interpreter.pycode import PyByteCode -from pypy.interpreter.appfile import AppFile -from pypy.interpreter.executioncontext import OperationError +from pypy.interpreter import pycode, appfile, executioncontext ####################### #### __builtin__ #### @@ -11,7 +9,7 @@ class Builtin(BuiltinModule): __pythonname__ = '__builtin__' - __appfile__ = AppFile(__name__, ["module"]) + __appfile__ = appfile.AppFile(__name__, ["module"]) def chr(self, w_ascii): w_character = self.space.newstring([w_ascii]) @@ -31,10 +29,11 @@ try: w_mod = space.getitem(space.w_modules, w_modulename) return w_mod - except OperationError,e: + except executioncontext.OperationError,e: if not e.match(space, space.w_KeyError): raise - raise OperationError(space.w_ImportError, w_modulename) + raise executioncontext.OperationError( + space.w_ImportError, w_modulename) __import__ = appmethod(__import__) def compile(self, w_str, w_filename, w_startstr, @@ -47,7 +46,7 @@ dont_inherit = space.unwrap(w_dont_inherit) c = _b.compile(str, filename, startstr, supplied_flags, dont_inherit) - res = PyByteCode() + res = pycode.PyByteCode() res._from_code(c) return space.wrap(res) compile = appmethod(compile) From alex at codespeak.net Mon May 26 19:02:23 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 19:02:23 +0200 (MEST) Subject: [pypy-svn] rev 475 - in pypy/trunk/src/pypy/interpreter: . test Message-ID: <20030526170223.3F3415B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 19:02:17 2003 New Revision: 475 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Log: refactored from Modified: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Mon May 26 19:02:17 2003 @@ -1,5 +1,5 @@ -from pycode import PyBaseCode -from appfile import AppHelper +import pycode +import appfile class appmethod(object): def __init__(self, func): @@ -14,11 +14,11 @@ return self.data -class PyBuiltinCode(PyBaseCode): +class PyBuiltinCode(pycode.PyBaseCode): """The code object implementing a built-in (interpreter-level) hook.""" def __init__(self, bltinmodule, appmethod): - PyBaseCode.__init__(self) + pycode.PyBaseCode.__init__(self) self.bltinmodule = bltinmodule self.appmethod = appmethod co = appmethod.func.func_code @@ -63,8 +63,8 @@ elif isinstance(value, appdata): w_data = space.wrap(value.data) space.setattr(w_module, space.wrap(key), w_data) - appfile = self.__appfile__ - if appfile: + sappfile = self.__appfile__ + if sappfile: w_dict = space.getattr(w_module, space.wrap("__dict__")) - AppHelper(space, appfile, w_dict) + appfile.AppHelper(space, sappfile, w_dict) return w_module Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Mon May 26 19:02:17 2003 @@ -1,32 +1,17 @@ import unittest, sys -sys.path.append('..') +import testsupport +from pypy.interpreter import unittest_w -import extmodule +from pypy.interpreter import extmodule +from pypy.objspace import trivial class EmptyBM(extmodule.BuiltinModule): __pythonname__ = 'empty_bm' -class wrapper(object): - def __init__(self, wrapped): - self.wrapped = wrapped -def is_wrapped(obj): - return isinstance(obj, wrapper) -import new -class dummyspace(object): - w_None = wrapper(None) - def wrap(self, obj): - return wrapper(obj) - def unwrap(self, obj): - return obj.wrapped - def newmodule(self, name): - return self.wrap(new.module(self.unwrap(name))) - def newfunction(self, code, w_something, somethingelse): - - -class TestBuiltinModule(unittest.TestCase): +class TestBuiltinModule(unittest_w.TestCase_w): def setUp(self): - self.space = dummyspace() + self.space = trivial.TrivialObjSpace() def tearDown(self): pass From alex at codespeak.net Mon May 26 19:06:47 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 19:06:47 +0200 (MEST) Subject: [pypy-svn] rev 476 - pypy/trunk/src/pypy/interpreter Message-ID: <20030526170647.CB8915B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 19:06:44 2003 New Revision: 476 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py Log: refactored a from Modified: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Mon May 26 19:06:44 2003 @@ -1,4 +1,4 @@ -import pycode +from pypy.interpreter import pycode import appfile class appmethod(object): From alex at codespeak.net Mon May 26 19:10:18 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 19:10:18 +0200 (MEST) Subject: [pypy-svn] rev 477 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030526171018.420595B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 19:10:16 2003 New Revision: 477 Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Log: added a magic import to make others work Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Mon May 26 19:10:16 2003 @@ -2,6 +2,9 @@ import testsupport from pypy.interpreter import unittest_w +# need pypy.module.builtin first to make other imports work (???) +from pypy.module import builtin + from pypy.interpreter import extmodule from pypy.objspace import trivial From arigo at codespeak.net Mon May 26 19:26:28 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 19:26:28 +0200 (MEST) Subject: [pypy-svn] rev 478 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030526172628.E029C5B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 19:26:28 2003 New Revision: 478 Added: pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Modified: pypy/trunk/src/pypy/objspace/std/iterobject.py pypy/trunk/src/pypy/objspace/std/iterobject_app.py pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py pypy/trunk/src/pypy/objspace/std/tupleobject.py Log: sequence iterators Modified: pypy/trunk/src/pypy/objspace/std/iterobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/iterobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/iterobject.py Mon May 26 19:26:28 2003 @@ -1,10 +1,27 @@ -from pypy.objspace.std.objspace import * +from objspace import * -appfile = StdObjSpace.AppFile(__name__) -W_SequenceIterator = pull_class_from_appfile(appfile, 'SequenceIterator') -StdObjSpace.getiter.register(W_SequenceIterator.method('__iter__'), - W_SequenceIterator....) +class W_SeqIterObject: + delegate_once = {} + def __init__(self, w_seq, index=0): + self.w_seq = w_seq + self.index = index -# XXX figure out some nice syntax to grab multimethods from the _app.py file + +def iter_seqiter(space, w_seqiter): + return w_seqiter + +StdObjSpace.iter.register(iter_seqiter, W_SeqIterObject) + +def next_seqiter(space, w_seqiter): + try: + w_item = space.getitem(w_seqiter.w_seq, space.wrap(w_seqiter.index)) + except OperationError, e: + if e.match(space, space.w_IndexError): + raise NoValue + raise + w_seqiter.index += 1 + return w_item + +StdObjSpace.next.register(next_seqiter, W_SeqIterObject) Modified: pypy/trunk/src/pypy/objspace/std/iterobject_app.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/iterobject_app.py (original) +++ pypy/trunk/src/pypy/objspace/std/iterobject_app.py Mon May 26 19:26:28 2003 @@ -13,3 +13,5 @@ self.it_index += 1 return item # Yes, the implementation is complete, I think + +# XXX design a way to have this working and get rid of iterobject.py Added: pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py Mon May 26 19:26:28 2003 @@ -0,0 +1,33 @@ +import unittest, sys +import testsupport +from pypy.interpreter import unittest_w +from pypy.objspace.std import iterobject as iobj +from pypy.objspace.std.objspace import * + + +class TestW_IterObject(unittest_w.TestCase_w): + + def setUp(self): + self.space = StdObjSpace() + + def tearDown(self): + pass + + def test_iter(self): + w = self.space.wrap + w_tuple = self.space.newtuple([w(5), w(3), w(99)]) + w_iter = iobj.W_SeqIterObject(w_tuple) + self.assertEqual_w(self.space.next(w_iter), w(5)) + self.assertEqual_w(self.space.next(w_iter), w(3)) + self.assertEqual_w(self.space.next(w_iter), w(99)) + self.assertRaises(NoValue, self.space.next, w_iter) + self.assertRaises(NoValue, self.space.next, w_iter) + + def test_emptyiter(self): + w_list = self.space.newlist([]) + w_iter = iobj.W_SeqIterObject(w_list) + self.assertRaises(NoValue, self.space.next, w_iter) + self.assertRaises(NoValue, self.space.next, w_iter) + +if __name__ == '__main__': + unittest.main() Modified: pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py Mon May 26 19:26:28 2003 @@ -31,6 +31,7 @@ space.delattr(w_m, space.wrap('x')) self.assertRaises_w(space.w_AttributeError, space.getattr, w_m, space.wrap('x')) + self.assertEqual_w(space.getattr(w_m, space.wrap('yy')), w_yy) if __name__ == '__main__': unittest.main() Added: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Mon May 26 19:26:28 2003 @@ -0,0 +1,50 @@ +import unittest, sys +import testsupport +from pypy.interpreter import unittest_w +from pypy.objspace.std import tupleobject as tobj +from pypy.objspace.std.objspace import * + + +class TestW_TupleObject(unittest_w.TestCase_w): + + def setUp(self): + self.space = StdObjSpace() + + def tearDown(self): + pass + + def test_is_true(self): + w = self.space.wrap + w_tuple = tobj.W_TupleObject([]) + self.assertEqual(self.space.is_true(w_tuple), False) + w_tuple = tobj.W_TupleObject([w(5)]) + self.assertEqual(self.space.is_true(w_tuple), True) + w_tuple = tobj.W_TupleObject([w(5), w(3)]) + self.assertEqual(self.space.is_true(w_tuple), True) + + def test_getitem(self): + w = self.space.wrap + w_tuple = tobj.W_TupleObject([w(5), w(3)]) + self.assertEqual_w(self.space.getitem(w_tuple, w(0)), w(5)) + self.assertEqual_w(self.space.getitem(w_tuple, w(1)), w(3)) + self.assertEqual_w(self.space.getitem(w_tuple, w(-2)), w(5)) + self.assertEqual_w(self.space.getitem(w_tuple, w(-1)), w(3)) + self.assertRaises_w(self.space.w_IndexError, + self.space.getitem, w_tuple, w(2)) + self.assertRaises_w(self.space.w_IndexError, + self.space.getitem, w_tuple, w(42)) + self.assertRaises_w(self.space.w_IndexError, + self.space.getitem, w_tuple, w(-3)) + + def test_iter(self): + w = self.space.wrap + w_tuple = tobj.W_TupleObject([w(5), w(3), w(99)]) + w_iter = self.space.iter(w_tuple) + self.assertEqual_w(self.space.next(w_iter), w(5)) + self.assertEqual_w(self.space.next(w_iter), w(3)) + self.assertEqual_w(self.space.next(w_iter), w(99)) + self.assertRaises(NoValue, self.space.next, w_iter) + self.assertRaises(NoValue, self.space.next, w_iter) + +if __name__ == '__main__': + unittest.main() Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Mon May 26 19:26:28 2003 @@ -32,7 +32,17 @@ def tuple_getitem(space, w_tuple, w_index): items = w_tuple.wrappeditems - w_item = items[w_index.intval] + try: + w_item = items[w_index.intval] + except IndexError: + raise OperationError(space.w_IndexError, + space.wrap("tuple index out of range")) return w_item StdObjSpace.getitem.register(tuple_getitem, W_TupleObject, W_IntObject) + +def tuple_iter(space, w_tuple): + import iterobject + return iterobject.W_SeqIterObject(w_tuple) + +StdObjSpace.iter.register(tuple_iter, W_TupleObject) From arigo at codespeak.net Mon May 26 19:28:04 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 19:28:04 +0200 (MEST) Subject: [pypy-svn] rev 479 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030526172804.D8EDB5B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 19:28:04 2003 New Revision: 479 Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Log: testing len(tuple) Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Mon May 26 19:28:04 2003 @@ -22,6 +22,15 @@ w_tuple = tobj.W_TupleObject([w(5), w(3)]) self.assertEqual(self.space.is_true(w_tuple), True) + def test_len(self): + w = self.space.wrap + w_tuple = tobj.W_TupleObject([]) + self.assertEqual_w(self.space.len(w_tuple), w(0)) + w_tuple = tobj.W_TupleObject([w(5)]) + self.assertEqual_w(self.space.len(w_tuple), w(1)) + w_tuple = tobj.W_TupleObject([w(5), w(3), w(99)]*111) + self.assertEqual_w(self.space.len(w_tuple), w(333)) + def test_getitem(self): w = self.space.wrap w_tuple = tobj.W_TupleObject([w(5), w(3)]) From alex at codespeak.net Mon May 26 19:31:05 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 19:31:05 +0200 (MEST) Subject: [pypy-svn] rev 480 - pypy/trunk/src/pypy/objspace Message-ID: <20030526173105.08DBB5B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 19:31:05 2003 New Revision: 480 Modified: pypy/trunk/src/pypy/objspace/trivial.py Log: fixing newfunction Modified: pypy/trunk/src/pypy/objspace/trivial.py ============================================================================== --- pypy/trunk/src/pypy/objspace/trivial.py (original) +++ pypy/trunk/src/pypy/objspace/trivial.py Mon May 26 19:31:05 2003 @@ -170,9 +170,13 @@ raise NoValue def newfunction(self, code, globals, defaultarguments, closure=None): - if closure is None: # temp hack for Python 2.2 - return new.function(code, globals, None, defaultarguments) - return new.function(code, globals, None, defaultarguments, closure) + def newfun(self, *args, **kwds): + locals = code.build_arguments(self, args, kwds, + w_defaults = defaultarguments, + w_closure = closure) + return code.evalcode(self, globals, locals) + newfun.__name__ = code.co_name + return newfun def newstring(self, asciilist): return ''.join([chr(ascii) for ascii in asciilist]) From mwh at codespeak.net Mon May 26 19:35:38 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Mon, 26 May 2003 19:35:38 +0200 (MEST) Subject: [pypy-svn] rev 481 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030526173538.BD31F5B0F3@thoth.codespeak.net> Author: mwh Date: Mon May 26 19:35:38 2003 New Revision: 481 Added: pypy/trunk/src/pypy/objspace/std/test/test_objspace.py Modified: pypy/trunk/src/pypy/objspace/std/objspace.py Log: add StdObjSpace.newstring and add test_objspace while we're at it 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 Mon May 26 19:35:38 2003 @@ -96,6 +96,11 @@ import moduleobject return moduleobject.W_ModuleObject(self, w_name) + def newstring(self, chars_w): + chars = [chr(self.unwrap(w_c)) for w_c in chars_w] + import stringobject + return stringobject.W_StringObject(''.join(chars)) + # special multimethods unwrap = MultiMethod('unwrap', 1) # returns an unwrapped object is_true = MultiMethod('nonzero', 1) # returns an unwrapped bool Added: pypy/trunk/src/pypy/objspace/std/test/test_objspace.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/test/test_objspace.py Mon May 26 19:35:38 2003 @@ -0,0 +1,23 @@ +import unittest, sys +import testsupport +from pypy.interpreter import unittest_w +from pypy.objspace.std import noneobject as nobj +from pypy.objspace.std.objspace import * + + +class TestStdObjectSpace(unittest_w.TestCase_w): + + def setUp(self): + self.space = StdObjSpace() + + def tearDown(self): + pass + + def test_newstring(self): + w = self.space.wrap + s = 'abc' + chars_w = [w(ord(c)) for c in s] + self.assertEqual_w(w(s), self.space.newstring(chars_w)) + +if __name__ == '__main__': + unittest.main() From alex at codespeak.net Mon May 26 19:36:54 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 19:36:54 +0200 (MEST) Subject: [pypy-svn] rev 482 - pypy/trunk/src/pypy/objspace Message-ID: <20030526173654.910405B0F3@thoth.codespeak.net> Author: alex Date: Mon May 26 19:36:54 2003 New Revision: 482 Modified: pypy/trunk/src/pypy/objspace/trivial.py Log: use class fur newfunction Modified: pypy/trunk/src/pypy/objspace/trivial.py ============================================================================== --- pypy/trunk/src/pypy/objspace/trivial.py (original) +++ pypy/trunk/src/pypy/objspace/trivial.py Mon May 26 19:36:54 2003 @@ -170,13 +170,20 @@ raise NoValue def newfunction(self, code, globals, defaultarguments, closure=None): - def newfun(self, *args, **kwds): - locals = code.build_arguments(self, args, kwds, - w_defaults = defaultarguments, - w_closure = closure) - return code.evalcode(self, globals, locals) - newfun.__name__ = code.co_name - return newfun + class nufun(object): + def __init__(self, space, code, globals, defaultarguments, closure): + self.space = space + self.__name__ = code.co_name + self.code = code + self.globals = globals + self.defaultarguments = defaultarguments + self.closure = closure + def __call__(self, *args, **kwds): + locals = self.code.build_arguments(self.space, args, kwds, + w_defaults = self.defaultarguments, + w_closure = self.closure) + return self.code.evalcode(self.space, self.globals, locals) + return nufun(self, code, globals, defaultarguments, closure) def newstring(self, asciilist): return ''.join([chr(ascii) for ascii in asciilist]) From arigo at codespeak.net Mon May 26 19:37:51 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 19:37:51 +0200 (MEST) Subject: [pypy-svn] rev 483 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030526173751.985A95B0F3@thoth.codespeak.net> Author: arigo Date: Mon May 26 19:37:51 2003 New Revision: 483 Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py Log: tuple+tuple Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Mon May 26 19:37:51 2003 @@ -46,3 +46,10 @@ return iterobject.W_SeqIterObject(w_tuple) StdObjSpace.iter.register(tuple_iter, W_TupleObject) + +def tuple_add(space, w_tuple1, w_tuple2): + items1 = w_tuple1.wrappeditems + items2 = w_tuple2.wrappeditems + return W_TupleObject(items1 + items2) + +StdObjSpace.add.register(tuple_add, W_TupleObject, W_TupleObject) From alex at codespeak.net Mon May 26 19:40:43 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Mon, 26 May 2003 19:40:43 +0200 (MEST) Subject: [pypy-svn] rev 484 - in pypy/trunk/src/pypy: interpreter/test objspace Message-ID: <20030526174043.887F95A186@thoth.codespeak.net> Author: alex Date: Mon May 26 19:40:42 2003 New Revision: 484 Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py pypy/trunk/src/pypy/objspace/trivial.py Log: fixed trivial objspace enough to make test_extmodule work Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Mon May 26 19:40:42 2003 @@ -11,6 +11,11 @@ class EmptyBM(extmodule.BuiltinModule): __pythonname__ = 'empty_bm' +class BM_with_appmethod(extmodule.BuiltinModule): + __pythonname__ = 'bm_with_appmethod' + def amethod(self): return 23 + amethod = extmodule.appmethod(amethod) + class TestBuiltinModule(unittest_w.TestCase_w): def setUp(self): @@ -30,5 +35,20 @@ self.assertEqual(bmd['__doc__'], EmptyBM.__doc__) self.assertEqual(bmd['__name__'], EmptyBM.__pythonname__) + def test_appmethod(self): + bm = BM_with_appmethod(self.space) + w_bm = bm.wrap_me() + modobj = self.space.unwrap(w_bm) + bmd = modobj.__dict__ + bmd_kys = bmd.keys() + bmd_kys.sort() + self.assertEqual(bmd_kys, ['__doc__','__name__','amethod']) + self.assertEqual(bmd['__doc__'], BM_with_appmethod.__doc__) + self.assertEqual(bmd['__name__'], BM_with_appmethod.__pythonname__) + self.assertEqual(bmd['amethod'].__name__, 'amethod') + result = bmd['amethod']() + self.assertEqual(result, 23) + + if __name__ == '__main__': unittest.main() Modified: pypy/trunk/src/pypy/objspace/trivial.py ============================================================================== --- pypy/trunk/src/pypy/objspace/trivial.py (original) +++ pypy/trunk/src/pypy/objspace/trivial.py Mon May 26 19:40:42 2003 @@ -182,7 +182,7 @@ locals = self.code.build_arguments(self.space, args, kwds, w_defaults = self.defaultarguments, w_closure = self.closure) - return self.code.evalcode(self.space, self.globals, locals) + return self.code.eval_code(self.space, self.globals, locals) return nufun(self, code, globals, defaultarguments, closure) def newstring(self, asciilist): From mwh at codespeak.net Mon May 26 19:41:00 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Mon, 26 May 2003 19:41:00 +0200 (MEST) Subject: [pypy-svn] rev 485 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030526174100.C49D25A186@thoth.codespeak.net> Author: mwh Date: Mon May 26 19:41:00 2003 New Revision: 485 Modified: pypy/trunk/src/pypy/objspace/std/objspace.py Log: add comment about issue that bothers me 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 Mon May 26 19:41:00 2003 @@ -97,6 +97,9 @@ return moduleobject.W_ModuleObject(self, w_name) def newstring(self, chars_w): + # nyyyaaaaaaaaagh! what do we do if chars_w is not a list, or + # if it is a list, but contains things other than wrapped + # integers -- mwh chars = [chr(self.unwrap(w_c)) for w_c in chars_w] import stringobject return stringobject.W_StringObject(''.join(chars)) From arigo at codespeak.net Mon May 26 19:41:42 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Mon, 26 May 2003 19:41:42 +0200 (MEST) Subject: [pypy-svn] rev 486 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030526174142.81A7F5A186@thoth.codespeak.net> Author: arigo Date: Mon May 26 19:41:42 2003 New Revision: 486 Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py pypy/trunk/src/pypy/objspace/std/tupleobject.py Log: equality between tuples Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Mon May 26 19:41:42 2003 @@ -55,5 +55,19 @@ self.assertRaises(NoValue, self.space.next, w_iter) self.assertRaises(NoValue, self.space.next, w_iter) + def test_add(self): + w = self.space.wrap + w_tuple0 = tobj.W_TupleObject([]) + w_tuple1 = tobj.W_TupleObject([w(5), w(3), w(99)]) + w_tuple2 = tobj.W_TupleObject([w(-7)] * 111) + self.assertEqual_w(self.space.add(w_tuple1, w_tuple1), + tobj.W_TupleObject([w(5), w(3), w(99), + w(5), w(3), w(99)])) + self.assertEqual_w(self.space.add(w_tuple1, w_tuple2), + tobj.W_TupleObject([w(5), w(3), w(99)] + + [w(-7)] * 111)) + self.assertEqual_w(self.space.add(w_tuple1, w_tuple0), w_tuple1) + self.assertEqual_w(self.space.add(w_tuple0, w_tuple2), w_tuple2) + if __name__ == '__main__': unittest.main() Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Mon May 26 19:41:42 2003 @@ -53,3 +53,15 @@ return W_TupleObject(items1 + items2) StdObjSpace.add.register(tuple_add, W_TupleObject, W_TupleObject) + +def tuple_eq(space, w_tuple1, w_tuple2): + items1 = w_tuple1.wrappeditems + items2 = w_tuple2.wrappeditems + if len(items1) != len(items2): + return space.w_False + for item1, item2 in zip(items1, items2): + if not space.is_true(space.eq(item1, item2)): + return space.w_False + return space.w_True + +StdObjSpace.eq.register(tuple_eq, W_TupleObject, W_TupleObject) From pedronis at codespeak.net Mon May 26 19:41:47 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Mon, 26 May 2003 19:41:47 +0200 (MEST) Subject: [pypy-svn] rev 487 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030526174147.432865A186@thoth.codespeak.net> Author: pedronis Date: Mon May 26 19:41:46 2003 New Revision: 487 Modified: pypy/trunk/src/pypy/interpreter/test/test_main.py Log: working test for print len(aStr) where aStr = 'hello world' Modified: pypy/trunk/src/pypy/interpreter/test/test_main.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_main.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_main.py Mon May 26 19:41:46 2003 @@ -1,5 +1,6 @@ import unittest -import support +import testsupport +from cStringIO import StringIO from pypy.interpreter.baseobjspace import OperationError @@ -11,6 +12,22 @@ main() """ +testresultoutput = '11\n' + +capture = StringIO() + +def checkoutput(expected_output,f,*args): + import sys + oldout = sys.stdout + try: + capture.reset() + sys.stdout = capture + f(*args) + finally: + sys.stdout = oldout + + return capture.getvalue() == expected_output + testfn = 'tmp_hello_world.py' class TestMain(unittest.TestCase): @@ -26,16 +43,12 @@ def test_run_file(self): from pypy.interpreter import main - self.assertRaises(OperationError, - main.run_file, - testfn) + self.assert_(checkoutput(testresultoutput,main.run_file,testfn)) def test_run_string(self): from pypy.interpreter import main - self.assertRaises(OperationError, - main.run_string, - testcode, - testfn) + self.assert_(checkoutput(testresultoutput, + main.run_string,testcode,testfn)) if __name__ == '__main__': unittest.main() From tismer at codespeak.net Mon May 26 19:41:59 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Mon, 26 May 2003 19:41:59 +0200 (MEST) Subject: [pypy-svn] rev 488 - in pypy/trunk/src/pypy: interpreter/test module objspace/std Message-ID: <20030526174159.1F3165A186@thoth.codespeak.net> Author: tismer Date: Mon May 26 19:41:58 2003 New Revision: 488 Modified: pypy/trunk/src/pypy/interpreter/test/hello_world.py pypy/trunk/src/pypy/module/builtin.py pypy/trunk/src/pypy/module/builtin_app.py pypy/trunk/src/pypy/objspace/std/sliceobject.py Log: some half-baked apply working, too Modified: pypy/trunk/src/pypy/interpreter/test/hello_world.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/hello_world.py (original) +++ pypy/trunk/src/pypy/interpreter/test/hello_world.py Mon May 26 19:41:58 2003 @@ -3,3 +3,4 @@ print len(aStr) map(main, ["hello world", "good bye"]) +apply(main, ("apply works, too",)) \ No newline at end of file Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Mon May 26 19:41:58 2003 @@ -24,6 +24,13 @@ return self.space.str(w_obj) str = appmethod(str) + # 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 __import__(self, w_modulename, w_locals, w_globals, w_fromlist): space = self.space try: 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 Mon May 26 19:41:58 2003 @@ -1,6 +1,11 @@ +# XXX kwds yet to come +# Problem: need to decide how to implement iterators, +# which are needed for star args. +def apply(function, args):#, kwds): + return function(*args)#, **kwds) def map(function, list): "docstring" Modified: pypy/trunk/src/pypy/objspace/std/sliceobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/sliceobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/sliceobject.py Mon May 26 19:41:58 2003 @@ -1,8 +1,7 @@ class W_SliceObject(object): - __slots__ = ['start', 'stop', 'step'] - def __init__(self, start, stop, step): + def __init__(self, w_start, w_stop, w_step): self.w_start = w_start self.w_stop = w_stop self.w_step = w_step From tismer at codespeak.net Tue May 27 10:40:54 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Tue, 27 May 2003 10:40:54 +0200 (MEST) Subject: [pypy-svn] rev 489 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527084054.0870F5A186@thoth.codespeak.net> Author: tismer Date: Tue May 27 10:40:52 2003 New Revision: 489 Modified: pypy/trunk/src/pypy/interpreter/main.py Log: made test_main run under windows (file should be closed early) 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 10:40:52 2003 @@ -31,8 +31,8 @@ raise def run_file(fname): - ifile = open(fname) - run_string(ifile.read(), fname) + istring = open(fname).read() + run_string(istring, fname) def main(argv=None): if argv is None: From arigo at codespeak.net Tue May 27 10:51:51 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 10:51:51 +0200 (MEST) Subject: [pypy-svn] rev 490 - in pypy/trunk/src/pypy: interpreter/test objspace/std Message-ID: <20030527085151.CA3EC5A186@thoth.codespeak.net> Author: arigo Date: Tue May 27 10:51:51 2003 New Revision: 490 Modified: pypy/trunk/src/pypy/interpreter/test/hello_world.py pypy/trunk/src/pypy/objspace/std/objspace.py pypy/trunk/src/pypy/objspace/std/stringobject.py Log: got newstring() do some type-checking Modified: pypy/trunk/src/pypy/interpreter/test/hello_world.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/hello_world.py (original) +++ pypy/trunk/src/pypy/interpreter/test/hello_world.py Tue May 27 10:51:51 2003 @@ -3,4 +3,6 @@ print len(aStr) map(main, ["hello world", "good bye"]) -apply(main, ("apply works, too",)) \ No newline at end of file +apply(main, ("apply works, too",)) + +print chr(65) 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 10:51:51 2003 @@ -100,7 +100,14 @@ # nyyyaaaaaaaaagh! what do we do if chars_w is not a list, or # if it is a list, but contains things other than wrapped # integers -- mwh - chars = [chr(self.unwrap(w_c)) for w_c in chars_w] + try: + chars = [chr(self.unwrap(w_c)) for w_c in chars_w] + except TypeError: # chr(not-an-integer) + raise OperationError(self.w_TypeError, + self.wrap("an integer is required")) + except ValueError: # chr(out-of-range) + raise OperationError(self.w_ValueError, + self.wrap("character code not in range(256)")) import stringobject return stringobject.W_StringObject(''.join(chars)) Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Tue May 27 10:51:51 2003 @@ -85,3 +85,8 @@ return space.wrap(len(w_str.value)) StdObjSpace.len.register(len_str, W_StringObject) + +def str_str(space, w_str): + return w_str + +StdObjSpace.str.register(str_str, W_StringObject) From mwh at codespeak.net Tue May 27 10:57:16 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 10:57:16 +0200 (MEST) Subject: [pypy-svn] rev 491 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527085716.511905A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 10:57:15 2003 New Revision: 491 Modified: pypy/trunk/src/pypy/objspace/std/objspace.py Log: remove my anguished comment 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 10:57:15 2003 @@ -97,9 +97,6 @@ return moduleobject.W_ModuleObject(self, w_name) def newstring(self, chars_w): - # nyyyaaaaaaaaagh! what do we do if chars_w is not a list, or - # if it is a list, but contains things other than wrapped - # integers -- mwh try: chars = [chr(self.unwrap(w_c)) for w_c in chars_w] except TypeError: # chr(not-an-integer) From mwh at codespeak.net Tue May 27 11:03:24 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 11:03:24 +0200 (MEST) Subject: [pypy-svn] rev 492 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030527090324.593D45A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 11:03:23 2003 New Revision: 492 Modified: pypy/trunk/src/pypy/objspace/std/test/test_objspace.py Log: add test of newstring behaving itself on incorrect input Modified: pypy/trunk/src/pypy/objspace/std/test/test_objspace.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_objspace.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_objspace.py Tue May 27 11:03:23 2003 @@ -19,5 +19,16 @@ chars_w = [w(ord(c)) for c in s] self.assertEqual_w(w(s), self.space.newstring(chars_w)) + def test_newstring_fail(self): + w = self.space.wrap + s = 'abc' + not_chars_w = [w(c) for c in s] + self.assertRaises_w(self.space.w_TypeError, + self.space.newstring, + not_chars_w) + self.assertRaises_w(self.space.w_ValueError, + self.space.newstring, + [w(-1)]) + if __name__ == '__main__': unittest.main() From pedronis at codespeak.net Tue May 27 11:11:13 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 11:11:13 +0200 (MEST) Subject: [pypy-svn] rev 493 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527091113.1A9425A186@thoth.codespeak.net> Author: pedronis Date: Tue May 27 11:11:12 2003 New Revision: 493 Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py Log: added get_builtin method to retrieve builtin modules. 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 11:11:12 2003 @@ -24,9 +24,9 @@ def make_builtins(self): self.builtin = pypy.module.builtin.Builtin(self) - w_builtin = self.builtin.wrap_me() - self.w_builtins = self.getattr(w_builtin, self.wrap("__dict__")) - self.setitem(self.w_modules, self.wrap("__builtin__"), w_builtin) + self.w_builtin = self.builtin.wrap_me() + self.w_builtins = self.getattr(self.w_builtin, self.wrap("__dict__")) + self.setitem(self.w_modules, self.wrap("__builtin__"), self.w_builtin) def make_sys(self): import pypy.module.sysmodule @@ -35,6 +35,15 @@ self.setitem(self.w_modules, self.wrap("sys"), self.w_sys) self.setattr(self.w_sys, self.wrap("modules"), self.w_modules) + # XXX use a dictionary in the future + def get_builtin(self,w_name): + name = self.unwrap(w_name) + if name == '__builtin__': + return self.w_builtin + elif name == 'sys': + return self.w_sys + return None + def initialize(self): """Abstract method that should put some minimal content into the w_builtins.""" From mwh at codespeak.net Tue May 27 11:15:15 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 11:15:15 +0200 (MEST) Subject: [pypy-svn] rev 494 - pypy/trunk/src/pypy/module/test Message-ID: <20030527091515.8E1EB5A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 11:15:15 2003 New Revision: 494 Added: pypy/trunk/src/pypy/module/test/test_builtin.py - copied unchanged from rev 493, pypy/trunk/src/pypy/module/test/test_builtins.py Removed: pypy/trunk/src/pypy/module/test/test_builtins.py Log: rename test_builtins to test_builtin Deleted: pypy/trunk/src/pypy/module/test/test_builtins.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_builtins.py Tue May 27 11:15:15 2003 +++ (empty file) @@ -1,15 +0,0 @@ -import unittest -from pypy.module.builtin import compile - -class TestCompile(unittest.TestCase): - """It makes basicaly not much sense, but we want to check, - if there break something - """ - - def test_f(self): - codeobject = compile("def main(): return None", '?', 'exec') - self.assertEquals(codeobject.co_names[0], 'main') - -if __name__ == '__main__': - unittest.main() - From tomek at codespeak.net Tue May 27 11:15:21 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 11:15:21 +0200 (MEST) Subject: [pypy-svn] rev 495 - pypy/trunk/src/pypy/module Message-ID: <20030527091521.0E6295A186@thoth.codespeak.net> Author: tomek Date: Tue May 27 11:15:20 2003 New Revision: 495 Modified: pypy/trunk/src/pypy/module/builtin.py Log: Wrapper for the builtins 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 11:15:20 2003 @@ -57,3 +57,91 @@ res._from_code(c) return space.wrap(res) compile = appmethod(compile) + + + ####essentially implemented by the objectspace + def abs(self, w_val): + pass + abs = appmethod(abs) + + + def chr(self, w_val): + pass + chr = appmethod(chr) + + + def delattr(self, w_val): + pass + delattr = appmethod(delattr) + + + def getattr(self, w_val): + pass + getattr = appmethod(getattr) + + + def hash(self, w_val): + pass + hash = appmethod(hash) + + + def hex(self, w_val): + pass + hex = appmethod(hex) + + + def id(self, w_val): + pass + id = appmethod(id) + + + def isinstance(self, w_val): + pass + isinstance = appmethod(isinstance) + + + def issubclass(self, w_val): + pass + issubclass = appmethod(issubclass) + + + def iter(self, w_val): + pass + iter = appmethod(iter) + + + def len(self, w_val): + pass + len = appmethod(len) + + + def eon(self, w_val): + pass + eon = appmethod(eon) + + + def ord(self, w_val): + pass + ord = appmethod(ord) + + + def pow(self, w_val): + pass + pow = appmethod(pow) + + + def repr(self, w_val): + pass + repr = appmethod(repr) + + + def setattr(self, w_val): + pass + setattr = appmethod(setattr) + + + def unichr(self, w_val): + pass + unichr = appmethod(unichr) + + From mwh at codespeak.net Tue May 27 11:18:53 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 11:18:53 +0200 (MEST) Subject: [pypy-svn] rev 496 - pypy/trunk/src/pypy/module/test Message-ID: <20030527091853.6C8EF5A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 11:18:53 2003 New Revision: 496 Modified: pypy/trunk/src/pypy/module/test/test_builtin.py Log: tidy Modified: pypy/trunk/src/pypy/module/test/test_builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_builtin.py (original) +++ pypy/trunk/src/pypy/module/test/test_builtin.py Tue May 27 11:18:53 2003 @@ -1,15 +1,16 @@ -import unittest -from pypy.module.builtin import compile +import testsupport -class TestCompile(unittest.TestCase): - """It makes basicaly not much sense, but we want to check, - if there break something - """ +from pypy.interpreter.unittest_w +from pypy.objspace.std import StdObjSpace - def test_f(self): - codeobject = compile("def main(): return None", '?', 'exec') - self.assertEquals(codeobject.co_names[0], 'main') +class TestCompile(unittest_w.TestCase_w): + def setUp(self): + self.space = StdObjSpace() + + def tearDown(self): + pass + if __name__ == '__main__': unittest.main() From pedronis at codespeak.net Tue May 27 11:21:07 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 11:21:07 +0200 (MEST) Subject: [pypy-svn] rev 497 - pypy/trunk/src/pypy/module Message-ID: <20030527092107.4F07B5A186@thoth.codespeak.net> Author: pedronis Date: Tue May 27 11:21:07 2003 New Revision: 497 Modified: pypy/trunk/src/pypy/module/builtin.py Log: __import__ uses get_builtin 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 11:21:07 2003 @@ -39,6 +39,10 @@ except executioncontext.OperationError,e: if not e.match(space, space.w_KeyError): raise + w_mod = space.get_builtin(w_modulename) + if w_mod is not None: + space.setitem(space.w_modules,w_modulename,w_mod) + return w_mod raise executioncontext.OperationError( space.w_ImportError, w_modulename) __import__ = appmethod(__import__) From arigo at codespeak.net Tue May 27 11:34:41 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 11:34:41 +0200 (MEST) Subject: [pypy-svn] rev 498 - in pypy/trunk/src/pypy/interpreter: . test Message-ID: <20030527093441.AC2C65A186@thoth.codespeak.net> Author: arigo Date: Tue May 27 11:34:41 2003 New Revision: 498 Modified: pypy/trunk/src/pypy/interpreter/executioncontext.py pypy/trunk/src/pypy/interpreter/main.py pypy/trunk/src/pypy/interpreter/test/hello_world.py Log: excepthook displays a detailed OperationError traceback automatically Modified: pypy/trunk/src/pypy/interpreter/executioncontext.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/executioncontext.py (original) +++ pypy/trunk/src/pypy/interpreter/executioncontext.py Tue May 27 11:34:41 2003 @@ -123,7 +123,7 @@ l = l[:-1] print >> file, l - def print_detailed_traceback(self, space, file=None): + def print_detailed_traceback(self, space=None, file=None): """Dump a nice detailed interpreter- and application-level traceback, useful to debug the interpreter.""" if file is None: file = sys.stderr @@ -133,9 +133,14 @@ interpr_file = LinePrefixer(file, '||') print >> interpr_file, "Traceback (interpreter-level):" traceback.print_tb(self.debug_tb, file=interpr_file) - exc_type = space.unwrap(self.w_type) - exc_value = space.unwrap(self.w_value) - print >> file, '(application-level)', exc_type.__name__+':', exc_value + if space is None: + exc_typename = str(self.w_type) + exc_value = self.w_value + else: + exc_typename = space.unwrap(self.w_type).__name__ + exc_value = space.unwrap(self.w_value) + print >> file, '(application-level)', + print >> file, exc_typename+':', exc_value class NoValue(Exception): @@ -205,3 +210,14 @@ def empty(self): return not self.items + + +# installing the excepthook for OperationErrors +def operr_excepthook(exctype, value, traceback): + if issubclass(exctype, OperationError): + value.debug_tb = traceback + value.print_detailed_traceback() + else: + old_excepthook(exctype, value, traceback) +old_excepthook = sys.excepthook +sys.excepthook = operr_excepthook 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 11:34:41 2003 @@ -24,11 +24,7 @@ except baseobjspace.OperationError, operationerr: raise baseobjspace.PyPyError(space, operationerr) else: - try: - ec.eval_frame(frame) - except baseobjspace.OperationError, operationerr: - operationerr.space = space - raise + ec.eval_frame(frame) def run_file(fname): istring = open(fname).read() @@ -44,8 +40,6 @@ if pypyerr.space is None: raise pypyerr.operationerr # does anyone have a better idea? pypyerr.operationerr.print_detailed_traceback(pypyerr.space) - except baseobjspace.OperationError, operationerr: - operationerr.print_detailed_traceback(operationerr.space) if __name__ == '__main__': sys.exit(main(sys.argv)) Modified: pypy/trunk/src/pypy/interpreter/test/hello_world.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/hello_world.py (original) +++ pypy/trunk/src/pypy/interpreter/test/hello_world.py Tue May 27 11:34:41 2003 @@ -6,3 +6,4 @@ apply(main, ("apply works, too",)) print chr(65) +print chr('!') From mwh at codespeak.net Tue May 27 11:37:23 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 11:37:23 +0200 (MEST) Subject: [pypy-svn] rev 499 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527093723.653DC5A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 11:37:23 2003 New Revision: 499 Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py Log: add call_function convenience method 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 11:37:23 2003 @@ -152,6 +152,11 @@ if self.is_true(w_rv): return w_rv return self.w_False + + def call_function(self, w_func, *args_w): + return self.call(w_func, + self.newtuple(list(args_w)), + self.newdict([])) ## Table describing the regular part of the interface of object spaces, ## namely all methods which only take w_ arguments and return a w_ result From tomek at codespeak.net Tue May 27 11:38:22 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 11:38:22 +0200 (MEST) Subject: [pypy-svn] rev 500 - pypy/trunk/src/pypy/module Message-ID: <20030527093822.E5D8E5A186@thoth.codespeak.net> Author: tomek Date: Tue May 27 11:38:22 2003 New Revision: 500 Modified: pypy/trunk/src/pypy/module/builtin.py Log: Changes in builtin 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 11:38:22 2003 @@ -65,87 +65,77 @@ ####essentially implemented by the objectspace def abs(self, w_val): - pass + return self.space.abs(w_val) abs = appmethod(abs) - + #XXX def chr(self, w_val): - pass + return self.space.chr(w_val) chr = appmethod(chr) - def delattr(self, w_val): - pass + def delattr(self, w_object, w_name): + return self.space.delattr(w_object, w_name) delattr = appmethod(delattr) - def getattr(self, w_val): - pass + def getattr(self, w_object, w_name): + return self.space.getattr(w_object, w_name) getattr = appmethod(getattr) - def hash(self, w_val): - pass + def hash(self, w_object): + return self.space.hash(w_object) hash = appmethod(hash) - + #XXX def hex(self, w_val): - pass + return self.space.hex(w_val) hex = appmethod(hex) - def id(self, w_val): - pass + def id(self, w_object): + return self.space.id(w_object) id = appmethod(id) - - def isinstance(self, w_val): - pass + #XXX + def isinstance(self, w_object, w_class-or-type-or-tuple): + return self.space.isinstance(w_object, w_class-or-type-or-tuple) isinstance = appmethod(isinstance) - + #built-in name and object space name do not match def issubclass(self, w_val): - pass + return self.space.issubtype(w_val) issubclass = appmethod(issubclass) - - def iter(self, w_val): - pass + #XXX the is also the second form of iter, we don't have implemented + def iter(self, w_collection): + return self.space.iter(w_collection) iter = appmethod(iter) - - def len(self, w_val): - pass - len = appmethod(len) - - - def eon(self, w_val): - pass - eon = appmethod(eon) - - + #XXX def ord(self, w_val): - pass + return self.space.ord(w_val) ord = appmethod(ord) def pow(self, w_val): - pass + return self.space.pow(w_val) pow = appmethod(pow) - def repr(self, w_val): - pass + def repr(self, w_object): + return self.space.repr(w_object) repr = appmethod(repr) - def setattr(self, w_val): - pass + def setattr(self, w_object, w_name, w_val): + return self.space.setattr(w_object, w_name, w_val) setattr = appmethod(setattr) - + #XXX def unichr(self, w_val): - pass + return self.space.unichr(w_val) unichr = appmethod(unichr) From tomek at codespeak.net Tue May 27 11:41:42 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 11:41:42 +0200 (MEST) Subject: [pypy-svn] rev 501 - pypy/trunk/src/pypy/module Message-ID: <20030527094142.EBD965A186@thoth.codespeak.net> Author: tomek Date: Tue May 27 11:41:42 2003 New Revision: 501 Modified: pypy/trunk/src/pypy/module/builtin.py Log: changes in builtin 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 11:41:42 2003 @@ -11,19 +11,6 @@ __pythonname__ = '__builtin__' __appfile__ = appfile.AppFile(__name__, ["module"]) - def chr(self, w_ascii): - w_character = self.space.newstring([w_ascii]) - return w_character - chr = appmethod(chr) - - def len(self, w_obj): - return self.space.len(w_obj) - len = appmethod(len) - - def str(self, w_obj): - return self.space.str(w_obj) - str = appmethod(str) - # temporary hack, until we have a real tuple type for calling def tuple(self, w_obj): lis = self.space.unpackiterable(w_obj) @@ -68,11 +55,18 @@ return self.space.abs(w_val) abs = appmethod(abs) - #XXX - def chr(self, w_val): - return self.space.chr(w_val) + def chr(self, w_ascii): + w_character = self.space.newstring([w_ascii]) + return w_character chr = appmethod(chr) + def len(self, w_obj): + return self.space.len(w_obj) + len = appmethod(len) + + def str(self, w_obj): + return self.space.str(w_obj) + str = appmethod(str) def delattr(self, w_object, w_name): return self.space.delattr(w_object, w_name) @@ -99,8 +93,8 @@ id = appmethod(id) #XXX - def isinstance(self, w_object, w_class-or-type-or-tuple): - return self.space.isinstance(w_object, w_class-or-type-or-tuple) + def isinstance(self, w_object, w_class): + return self.space.isinstance(w_object, w_class) isinstance = appmethod(isinstance) #built-in name and object space name do not match From arigo at codespeak.net Tue May 27 11:43:19 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 11:43:19 +0200 (MEST) Subject: [pypy-svn] rev 502 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527094319.0FC2C5A186@thoth.codespeak.net> Author: arigo Date: Tue May 27 11:43:18 2003 New Revision: 502 Modified: pypy/trunk/src/pypy/interpreter/executioncontext.py Log: little possible fix Modified: pypy/trunk/src/pypy/interpreter/executioncontext.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/executioncontext.py (original) +++ pypy/trunk/src/pypy/interpreter/executioncontext.py Tue May 27 11:43:18 2003 @@ -215,7 +215,7 @@ # installing the excepthook for OperationErrors def operr_excepthook(exctype, value, traceback): if issubclass(exctype, OperationError): - value.debug_tb = traceback + value.debug_tb = value.debug_tb or traceback value.print_detailed_traceback() else: old_excepthook(exctype, value, traceback) From mwh at codespeak.net Tue May 27 11:44:43 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 11:44:43 +0200 (MEST) Subject: [pypy-svn] rev 503 - pypy/trunk/src/pypy/module/test Message-ID: <20030527094443.C8E9C5A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 11:44:43 2003 New Revision: 503 Modified: pypy/trunk/src/pypy/module/test/test_builtin.py Log: add test for chr Modified: pypy/trunk/src/pypy/module/test/test_builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_builtin.py (original) +++ pypy/trunk/src/pypy/module/test/test_builtin.py Tue May 27 11:44:43 2003 @@ -1,6 +1,8 @@ import testsupport -from pypy.interpreter.unittest_w +import unittest + +from pypy.interpreter import unittest_w from pypy.objspace.std import StdObjSpace class TestCompile(unittest_w.TestCase_w): @@ -10,6 +12,19 @@ def tearDown(self): pass + + def get_builtin(self, name): + s = self.space + w_name = s.wrap(name) + w_bltin = s.getitem(s.w_builtins, w_name) + return w_bltin + + def test_chr(self): + s = self.space + w = s.wrap + w_chr = self.get_builtin('chr') + self.assertEqual_w(w(chr(65)), + s.call_function(w_chr, w(65))) if __name__ == '__main__': unittest.main() From pedronis at codespeak.net Tue May 27 11:47:50 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 11:47:50 +0200 (MEST) Subject: [pypy-svn] rev 504 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527094750.3B0335A186@thoth.codespeak.net> Author: pedronis Date: Tue May 27 11:47:49 2003 New Revision: 504 Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py Log: let's __import__ populate sys.modules (w_modules) and get builtin modules through get_builtin. 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 11:47:49 2003 @@ -26,13 +26,11 @@ self.builtin = pypy.module.builtin.Builtin(self) self.w_builtin = self.builtin.wrap_me() self.w_builtins = self.getattr(self.w_builtin, self.wrap("__dict__")) - self.setitem(self.w_modules, self.wrap("__builtin__"), self.w_builtin) def make_sys(self): import pypy.module.sysmodule self.sys = pypy.module.sysmodule.Sys(self) self.w_sys = self.sys.wrap_me() - self.setitem(self.w_modules, self.wrap("sys"), self.w_sys) self.setattr(self.w_sys, self.wrap("modules"), self.w_modules) # XXX use a dictionary in the future From mwh at codespeak.net Tue May 27 11:50:23 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 11:50:23 +0200 (MEST) Subject: [pypy-svn] rev 505 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527095023.055915A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 11:50:23 2003 New Revision: 505 Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py Log: support keyword args in call_function 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 11:50:23 2003 @@ -151,10 +151,11 @@ return w_rv return self.w_False - def call_function(self, w_func, *args_w): - return self.call(w_func, - self.newtuple(list(args_w)), - self.newdict([])) + def call_function(self, w_func, *args_w, **kw_w): + w_kw = self.newdict([]) + for k, w_v in kw_w.iteritems(): + self.setitem(w_kw, self.wrap(k), w_v) + return self.call(w_func, self.newtuple(list(args_w)), w_kw) ## Table describing the regular part of the interface of object spaces, ## namely all methods which only take w_ arguments and return a w_ result From mwh at codespeak.net Tue May 27 11:55:00 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 11:55:00 +0200 (MEST) Subject: [pypy-svn] rev 506 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527095500.824425A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 11:55:00 2003 New Revision: 506 Modified: pypy/trunk/src/pypy/interpreter/unittest_w.py Log: Add assertWRaises_w to check that a wrapped callable raises the right kind of wrapped exception. I'm not so sold on the name. Modified: pypy/trunk/src/pypy/interpreter/unittest_w.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/unittest_w.py (original) +++ pypy/trunk/src/pypy/interpreter/unittest_w.py Tue May 27 11:55:00 2003 @@ -30,3 +30,12 @@ self.failUnless(e.match(self.space, w_exc_class)) else: self.fail('should have got an exception') + + def assertWRaises_w(self, w_exc_class, w_callable, *args_w, **kw_w): + from pypy.objspace.std.objspace import OperationError + try: + self.space.call_function(w_callable, *args_w, **kw_w) + except OperationError, e: + self.failUnless(e.match(self.space, w_exc_class)) + else: + self.fail('should have got an exception') From alex at codespeak.net Tue May 27 11:55:33 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 11:55:33 +0200 (MEST) Subject: [pypy-svn] rev 507 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030527095533.F19425A186@thoth.codespeak.net> Author: alex Date: Tue May 27 11:55:33 2003 New Revision: 507 Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Log: fixed tests to run on both object-space kinds Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Tue May 27 11:55:33 2003 @@ -1,6 +1,4 @@ -import unittest, sys import testsupport -from pypy.interpreter import unittest_w # need pypy.module.builtin first to make other imports work (???) from pypy.module import builtin @@ -16,39 +14,41 @@ def amethod(self): return 23 amethod = extmodule.appmethod(amethod) -class TestBuiltinModule(unittest_w.TestCase_w): +class TestBuiltinModule(testsupport.TestCase): def setUp(self): - self.space = trivial.TrivialObjSpace() + self.space = testsupport.objspace() def tearDown(self): pass def test_empty(self): - bm = EmptyBM(self.space) + space = self.space + bm = EmptyBM(space) w_bm = bm.wrap_me() - modobj = self.space.unwrap(w_bm) - bmd = modobj.__dict__ - bmd_kys = bmd.keys() - bmd_kys.sort() - self.assertEqual(bmd_kys, ['__doc__','__name__']) - self.assertEqual(bmd['__doc__'], EmptyBM.__doc__) - self.assertEqual(bmd['__name__'], EmptyBM.__pythonname__) + w_bmd = space.getattr(w_bm, space.wrap('__dict__')) + bmd = space.unwrap(w_bmd) + self.assertEqual(bmd, + {'__doc__': EmptyBM.__doc__, + '__name__': EmptyBM.__pythonname__} ) def test_appmethod(self): - bm = BM_with_appmethod(self.space) + space = self.space + bm = BM_with_appmethod(space) w_bm = bm.wrap_me() - modobj = self.space.unwrap(w_bm) - bmd = modobj.__dict__ - bmd_kys = bmd.keys() - bmd_kys.sort() - self.assertEqual(bmd_kys, ['__doc__','__name__','amethod']) - self.assertEqual(bmd['__doc__'], BM_with_appmethod.__doc__) - self.assertEqual(bmd['__name__'], BM_with_appmethod.__pythonname__) - self.assertEqual(bmd['amethod'].__name__, 'amethod') - result = bmd['amethod']() + w_bmd = space.getattr(w_bm, space.wrap('__dict__')) + bmd = space.unwrap(w_bmd) + themethod = bmd.get('amethod') + self.assertNotEqual(themethod, None) + w_method = space.getitem(w_bmd, space.wrap('amethod')) + bmd['amethod'] = BM_with_appmethod.amethod + self.assertEqual(bmd, + {'__doc__': BM_with_appmethod.__doc__, + '__name__': BM_with_appmethod.__pythonname__, + 'amethod': BM_with_appmethod.amethod} ) + result = space.call(w_method, space.wrap(()), None) self.assertEqual(result, 23) if __name__ == '__main__': - unittest.main() + testsupport.main() From alex at codespeak.net Tue May 27 11:56:17 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 11:56:17 +0200 (MEST) Subject: [pypy-svn] rev 508 - in pypy/trunk/src/pypy: . interpreter/test module/test objspace/std/test Message-ID: <20030527095617.98F8D5A186@thoth.codespeak.net> Author: alex Date: Tue May 27 11:56:17 2003 New Revision: 508 Modified: pypy/trunk/src/pypy/interpreter/test/testsupport.py pypy/trunk/src/pypy/module/test/testsupport.py pypy/trunk/src/pypy/objspace/std/test/testsupport.py pypy/trunk/src/pypy/testsupport.py Log: new version of testsupport is richer and in particular eases the use of either trivial or standard object spaces for testing Modified: pypy/trunk/src/pypy/interpreter/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/testsupport.py (original) +++ pypy/trunk/src/pypy/interpreter/test/testsupport.py Tue May 27 11:56:17 2003 @@ -3,6 +3,20 @@ from which scripts need to be run (typically all of the 'test' subdirs) so that any test can "import testsupport" to ensure the parent of pypy is on the sys.path -- so that "import pypy.etc.etc." always works. + +Also, this module exposes a member 'TestCase' that is unittest.TestCase +or a subclass thereof supplying extra methods; and a function 'main' +that is unittest.main or the equivalent. + +Furthermore, this module now exposes a member 'objspace' which is +by default class pypy.objspace.trivial.TrivialObjSpace but can be +set to use another objectspace instead; this allows tests to run +under different objectspaces without needing to edit their sources. + +For this setting, use environment variable OBJSPACE and set it to +a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is +also the default if the environment variable is not found or empty +or without any dot in it). """ import sys, os @@ -15,3 +29,21 @@ sys.path.insert(0, head) break +import pypy.interpreter.unittest_w +TestCase = pypy.interpreter.unittest_w.TestCase_w +import unittest +main = unittest.main + +objspace_path = os.environ.get('OBJSPACE') +if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + objspace = pypy.objspace.trivial.TrivialObjSpace +else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + objspace = getattr(objspace_module, objspace_classname) + Modified: pypy/trunk/src/pypy/module/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/module/test/testsupport.py (original) +++ pypy/trunk/src/pypy/module/test/testsupport.py Tue May 27 11:56:17 2003 @@ -3,6 +3,20 @@ from which scripts need to be run (typically all of the 'test' subdirs) so that any test can "import testsupport" to ensure the parent of pypy is on the sys.path -- so that "import pypy.etc.etc." always works. + +Also, this module exposes a member 'TestCase' that is unittest.TestCase +or a subclass thereof supplying extra methods; and a function 'main' +that is unittest.main or the equivalent. + +Furthermore, this module now exposes a member 'objspace' which is +by default class pypy.objspace.trivial.TrivialObjSpace but can be +set to use another objectspace instead; this allows tests to run +under different objectspaces without needing to edit their sources. + +For this setting, use environment variable OBJSPACE and set it to +a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is +also the default if the environment variable is not found or empty +or without any dot in it). """ import sys, os @@ -15,3 +29,21 @@ sys.path.insert(0, head) break +import pypy.interpreter.unittest_w +TestCase = pypy.interpreter.unittest_w.TestCase_w +import unittest +main = unittest.main + +objspace_path = os.environ.get('OBJSPACE') +if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + objspace = pypy.objspace.trivial.TrivialObjSpace +else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + objspace = getattr(objspace_module, objspace_classname) + Modified: pypy/trunk/src/pypy/objspace/std/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/testsupport.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/testsupport.py Tue May 27 11:56:17 2003 @@ -3,6 +3,20 @@ from which scripts need to be run (typically all of the 'test' subdirs) so that any test can "import testsupport" to ensure the parent of pypy is on the sys.path -- so that "import pypy.etc.etc." always works. + +Also, this module exposes a member 'TestCase' that is unittest.TestCase +or a subclass thereof supplying extra methods; and a function 'main' +that is unittest.main or the equivalent. + +Furthermore, this module now exposes a member 'objspace' which is +by default class pypy.objspace.trivial.TrivialObjSpace but can be +set to use another objectspace instead; this allows tests to run +under different objectspaces without needing to edit their sources. + +For this setting, use environment variable OBJSPACE and set it to +a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is +also the default if the environment variable is not found or empty +or without any dot in it). """ import sys, os @@ -15,3 +29,21 @@ sys.path.insert(0, head) break +import pypy.interpreter.unittest_w +TestCase = pypy.interpreter.unittest_w.TestCase_w +import unittest +main = unittest.main + +objspace_path = os.environ.get('OBJSPACE') +if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + objspace = pypy.objspace.trivial.TrivialObjSpace +else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + objspace = getattr(objspace_module, objspace_classname) + Modified: pypy/trunk/src/pypy/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/testsupport.py (original) +++ pypy/trunk/src/pypy/testsupport.py Tue May 27 11:56:17 2003 @@ -3,6 +3,20 @@ from which scripts need to be run (typically all of the 'test' subdirs) so that any test can "import testsupport" to ensure the parent of pypy is on the sys.path -- so that "import pypy.etc.etc." always works. + +Also, this module exposes a member 'TestCase' that is unittest.TestCase +or a subclass thereof supplying extra methods; and a function 'main' +that is unittest.main or the equivalent. + +Furthermore, this module now exposes a member 'objspace' which is +by default class pypy.objspace.trivial.TrivialObjSpace but can be +set to use another objectspace instead; this allows tests to run +under different objectspaces without needing to edit their sources. + +For this setting, use environment variable OBJSPACE and set it to +a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is +also the default if the environment variable is not found or empty +or without any dot in it). """ import sys, os @@ -15,3 +29,21 @@ sys.path.insert(0, head) break +import pypy.interpreter.unittest_w +TestCase = pypy.interpreter.unittest_w.TestCase_w +import unittest +main = unittest.main + +objspace_path = os.environ.get('OBJSPACE') +if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + objspace = pypy.objspace.trivial.TrivialObjSpace +else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + objspace = getattr(objspace_module, objspace_classname) + From mwh at codespeak.net Tue May 27 11:56:25 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 11:56:25 +0200 (MEST) Subject: [pypy-svn] rev 509 - pypy/trunk/src/pypy/module/test Message-ID: <20030527095625.D2C3A5A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 11:56:25 2003 New Revision: 509 Modified: pypy/trunk/src/pypy/module/test/test_builtin.py Log: Add tests for chr on invalid input. Modified: pypy/trunk/src/pypy/module/test/test_builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_builtin.py (original) +++ pypy/trunk/src/pypy/module/test/test_builtin.py Tue May 27 11:56:25 2003 @@ -25,6 +25,12 @@ w_chr = self.get_builtin('chr') self.assertEqual_w(w(chr(65)), s.call_function(w_chr, w(65))) + self.assertWRaises_w(s.w_ValueError, + w_chr, + w(-1)) + self.assertWRaises_w(s.w_TypeError, + w_chr, + w('a')) if __name__ == '__main__': unittest.main() From alex at codespeak.net Tue May 27 12:03:56 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 12:03:56 +0200 (MEST) Subject: [pypy-svn] rev 510 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030527100356.0C5E95A186@thoth.codespeak.net> Author: alex Date: Tue May 27 12:03:55 2003 New Revision: 510 Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Log: added test for appdata Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Tue May 27 12:03:55 2003 @@ -14,6 +14,12 @@ def amethod(self): return 23 amethod = extmodule.appmethod(amethod) +class BM_with_appdata(extmodule.BuiltinModule): + __pythonname__ = 'bm_with_appdata' + somedata = 'twentythree' + somedata = extmodule.appdata(somedata) + + class TestBuiltinModule(testsupport.TestCase): def setUp(self): @@ -49,6 +55,21 @@ result = space.call(w_method, space.wrap(()), None) self.assertEqual(result, 23) + def test_appdata(self): + space = self.space + bm = BM_with_appdata(space) + w_bm = bm.wrap_me() + w_bmd = space.getattr(w_bm, space.wrap('__dict__')) + bmd = space.unwrap(w_bmd) + thedata = bmd.get('somedata') + self.assertNotEqual(thedata, None) + w_data = space.getitem(w_bmd, space.wrap('somedata')) + bmd['somedata'] = BM_with_appdata.somedata + self.assertEqual(bmd, + {'__doc__': BM_with_appdata.__doc__, + '__name__': BM_with_appdata.__pythonname__, + 'somedata': BM_with_appdata.somedata} ) + self.assertEqual(thedata, 'twentythree') if __name__ == '__main__': testsupport.main() From alex at codespeak.net Tue May 27 12:05:48 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 12:05:48 +0200 (MEST) Subject: [pypy-svn] rev 511 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030527100548.8B7B55A186@thoth.codespeak.net> Author: alex Date: Tue May 27 12:05:48 2003 New Revision: 511 Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Log: removed unneded import Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Tue May 27 12:05:48 2003 @@ -4,7 +4,6 @@ from pypy.module import builtin from pypy.interpreter import extmodule -from pypy.objspace import trivial class EmptyBM(extmodule.BuiltinModule): __pythonname__ = 'empty_bm' From tomek at codespeak.net Tue May 27 12:07:19 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 12:07:19 +0200 (MEST) Subject: [pypy-svn] rev 512 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527100719.6D37C5A186@thoth.codespeak.net> Author: tomek Date: Tue May 27 12:07:19 2003 New Revision: 512 Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py Log: Two new methods in MethodTable, hex and ord. 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 12:07:19 2003 @@ -181,6 +181,8 @@ ('neg', 'neg', 1), ('not_', 'not', 1), ('abs' , 'abs', 1), + ('hex', 'hex', 1), + ('ord', 'ord', 1), ('invert', '~', 1), ('add', '+', 2), ('sub', '-', 2), From mwh at codespeak.net Tue May 27 12:19:04 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 12:19:04 +0200 (MEST) Subject: [pypy-svn] rev 514 - pypy/trunk/src/pypy/module/test Message-ID: <20030527101904.4D07E5A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 12:19:04 2003 New Revision: 514 Modified: pypy/trunk/src/pypy/module/test/test_builtin.py Log: Use testsupport.objspace() to allow testing in multiple object spaces. Modified: pypy/trunk/src/pypy/module/test/test_builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_builtin.py (original) +++ pypy/trunk/src/pypy/module/test/test_builtin.py Tue May 27 12:19:04 2003 @@ -8,7 +8,7 @@ class TestCompile(unittest_w.TestCase_w): def setUp(self): - self.space = StdObjSpace() + self.space = testsupport.objspace() def tearDown(self): pass From tomek at codespeak.net Tue May 27 12:19:19 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 12:19:19 +0200 (MEST) Subject: [pypy-svn] rev 515 - pypy/trunk/src/pypy/module Message-ID: <20030527101919.AD8865A186@thoth.codespeak.net> Author: tomek Date: Tue May 27 12:19:19 2003 New Revision: 515 Modified: pypy/trunk/src/pypy/module/builtin.py Log: builtin changes 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 12:19:19 2003 @@ -82,7 +82,6 @@ return self.space.hash(w_object) hash = appmethod(hash) - #XXX def hex(self, w_val): return self.space.hex(w_val) hex = appmethod(hex) @@ -93,11 +92,9 @@ id = appmethod(id) #XXX - def isinstance(self, w_object, w_class): - return self.space.isinstance(w_object, w_class) - isinstance = appmethod(isinstance) - - #built-in name and object space name do not match + #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) issubclass = appmethod(issubclass) @@ -107,7 +104,6 @@ return self.space.iter(w_collection) iter = appmethod(iter) - #XXX def ord(self, w_val): return self.space.ord(w_val) ord = appmethod(ord) @@ -128,8 +124,9 @@ setattr = appmethod(setattr) #XXX + #We don't have newunicode at the time def unichr(self, w_val): - return self.space.unichr(w_val) + return self.space.newunicode([w_val]) unichr = appmethod(unichr) From mwh at codespeak.net Tue May 27 12:21:44 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 12:21:44 +0200 (MEST) Subject: [pypy-svn] rev 517 - pypy/trunk/src/pypy/module/test Message-ID: <20030527102144.1AC1F5A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 12:21:43 2003 New Revision: 517 Modified: pypy/trunk/src/pypy/module/test/test_builtin.py Log: use testsupport.main Modified: pypy/trunk/src/pypy/module/test/test_builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_builtin.py (original) +++ pypy/trunk/src/pypy/module/test/test_builtin.py Tue May 27 12:21:43 2003 @@ -1,7 +1,5 @@ import testsupport -import unittest - from pypy.interpreter import unittest_w from pypy.objspace.std import StdObjSpace @@ -33,5 +31,5 @@ w('a')) if __name__ == '__main__': - unittest.main() + testsupport.main() From alex at codespeak.net Tue May 27 12:30:35 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 12:30:35 +0200 (MEST) Subject: [pypy-svn] rev 518 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030527103035.7C4615A186@thoth.codespeak.net> Author: alex Date: Tue May 27 12:30:35 2003 New Revision: 518 Modified: pypy/trunk/src/pypy/interpreter/test/test_builtins.py Log: last few mods (incomplete) before deletion Modified: pypy/trunk/src/pypy/interpreter/test/test_builtins.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_builtins.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_builtins.py Tue May 27 12:30:35 2003 @@ -1,23 +1,22 @@ -# XXX fixme: -# This test is out of date and not functioning. +import testsupport -import unittest, sys, os -sys.path.insert(0, '..') +# need pypy.module.builtin first to make other imports work (???) +import pypy.module.builtin -from pyframe import PyFrame -import pypy.objspace.trivial as trivialspace +from pypy.interpreter.pyframe import PyFrame def make_builtins_global(): d = {} exec '''def filter(a, b): return 42''' in d return d -class TestBuiltins(unittest.TestCase): +class TestBuiltins(testsupport.TestCase): def test_filter_None(self): # build frame - space = trivialspace - bytecode = compile("def f(x): return filter(None, [1, '', 2])", '', 'exec').co_consts[0] + space = testsupport.objspace() + bytecode = compile("def f(x): return filter(None, [1, '', 2])", + '', 'exec').co_consts[0] d = make_builtins_global() w_globals = space.wrap(d) w_locals = space.wrap({}) @@ -31,4 +30,4 @@ if __name__ == '__main__': - unittest.main() + testsupport.main() From alex at codespeak.net Tue May 27 12:31:14 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 12:31:14 +0200 (MEST) Subject: [pypy-svn] rev 519 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030527103114.0CABC5A186@thoth.codespeak.net> Author: alex Date: Tue May 27 12:31:13 2003 New Revision: 519 Removed: pypy/trunk/src/pypy/interpreter/test/test_builtins.py Log: removed test_builtins from the interpreter/test (too obsolete to keep) Deleted: pypy/trunk/src/pypy/interpreter/test/test_builtins.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_builtins.py Tue May 27 12:31:13 2003 +++ (empty file) @@ -1,33 +0,0 @@ -import testsupport - -# need pypy.module.builtin first to make other imports work (???) -import pypy.module.builtin - -from pypy.interpreter.pyframe import PyFrame - -def make_builtins_global(): - d = {} - exec '''def filter(a, b): return 42''' in d - return d - -class TestBuiltins(testsupport.TestCase): - - def test_filter_None(self): - # build frame - space = testsupport.objspace() - bytecode = compile("def f(x): return filter(None, [1, '', 2])", - '', 'exec').co_consts[0] - d = make_builtins_global() - w_globals = space.wrap(d) - w_locals = space.wrap({}) - frame = PyFrame(space, bytecode, w_globals, w_locals) - - # perform call - w_input = frame.space.wrap((5,)) - frame.setargs(w_input) - w_output = frame.eval() - self.assertEquals(frame.space.unwrap(w_output), [1,2]) - - -if __name__ == '__main__': - testsupport.main() From tomek at codespeak.net Tue May 27 12:35:11 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 12:35:11 +0200 (MEST) Subject: [pypy-svn] rev 520 - pypy/trunk/src/pypy/module Message-ID: <20030527103511.F0C0F5A186@thoth.codespeak.net> Author: tomek Date: Tue May 27 12:35:11 2003 New Revision: 520 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: add isinstance 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 12:35:11 2003 @@ -1,3 +1,4 @@ +import types # XXX kwds yet to come @@ -10,3 +11,16 @@ def map(function, list): "docstring" return [function(x) for x in list] + +def isinstance(obj, klass_or_tuple): + objcls = obj.__class__ + if type(klass_or_tuple) == types.TupleType: + for klass in klass_or_tuple: + if issubclass(objcls, klass): + return 1 + return 0 + elif type(klass_ot_tuple) == types.ClassType: + return issubclass(objcls, klass) + else: + raise TypeError, "isinstance() arg 2 must be a class or type" + From tismer at codespeak.net Tue May 27 12:39:30 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Tue, 27 May 2003 12:39:30 +0200 (MEST) Subject: [pypy-svn] rev 521 - pypy/trunk/src/pypy/module Message-ID: <20030527103930.B81EF5A186@thoth.codespeak.net> Author: tismer Date: Tue May 27 12:39:30 2003 New Revision: 521 Modified: pypy/trunk/src/pypy/module/sysmodule.py Log: added displayhook Modified: pypy/trunk/src/pypy/module/sysmodule.py ============================================================================== --- pypy/trunk/src/pypy/module/sysmodule.py (original) +++ pypy/trunk/src/pypy/module/sysmodule.py Tue May 27 12:39:30 2003 @@ -4,4 +4,4 @@ class Sys(BuiltinModule): __pythonname__ = 'sys' stdout = appdata(sys.stdout) - + displayhook = appdata(sys.displayhook) From tomek at codespeak.net Tue May 27 12:39:54 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 12:39:54 +0200 (MEST) Subject: [pypy-svn] rev 522 - pypy/trunk/src/pypy/module Message-ID: <20030527103954.6573F5A186@thoth.codespeak.net> Author: tomek Date: Tue May 27 12:39:54 2003 New Revision: 522 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: small changes... 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 12:39:54 2003 @@ -19,8 +19,8 @@ if issubclass(objcls, klass): return 1 return 0 - elif type(klass_ot_tuple) == types.ClassType: - return issubclass(objcls, klass) + elif type(klass_or_tuple) == types.ClassType: + return issubclass(objcls, klass_or_tuple) else: raise TypeError, "isinstance() arg 2 must be a class or type" From tismer at codespeak.net Tue May 27 12:40:20 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Tue, 27 May 2003 12:40:20 +0200 (MEST) Subject: [pypy-svn] rev 523 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527104020.E310B5A186@thoth.codespeak.net> Author: tismer Date: Tue May 27 12:40:20 2003 New Revision: 523 Modified: pypy/trunk/src/pypy/interpreter/interactive.py pypy/trunk/src/pypy/interpreter/opcode.py pypy/trunk/src/pypy/interpreter/pyframe.py Log: modified several imports to make interactive.py work with std Modified: pypy/trunk/src/pypy/interpreter/interactive.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/interactive.py (original) +++ pypy/trunk/src/pypy/interpreter/interactive.py Tue May 27 12:40:20 2003 @@ -1,4 +1,4 @@ -import executioncontext, pyframe, baseobjspace +from pypy.interpreter import executioncontext, pyframe, baseobjspace import sys import code import linecache Modified: pypy/trunk/src/pypy/interpreter/opcode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/opcode.py (original) +++ pypy/trunk/src/pypy/interpreter/opcode.py Tue May 27 12:40:20 2003 @@ -1,6 +1,7 @@ -import dis, pyframe, baseobjspace from appfile import AppFile -from baseobjspace import OperationError, NoValue +from pypy.interpreter.baseobjspace import OperationError, NoValue +import dis +from pypy.interpreter import pyframe, baseobjspace # dynamically loaded application-space utilities Modified: pypy/trunk/src/pypy/interpreter/pyframe.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pyframe.py (original) +++ pypy/trunk/src/pypy/interpreter/pyframe.py Tue May 27 12:40:20 2003 @@ -1,13 +1,8 @@ """ PyFrame class implementation with the interpreter main loop. """ -import opcode -# XXX this is probably a Python bug: -# circular import doesn't work if we spell this -# from pypy.interpreter import opcode -# report this to python-dev -from executioncontext import OperationError, Stack -import baseobjspace -from appfile import AppFile + +from pypy.interpreter.executioncontext import OperationError, Stack +from pypy.interpreter.appfile import AppFile appfile = AppFile(__name__, ["interpreter"]) @@ -37,6 +32,7 @@ def eval(self, executioncontext): "Interpreter main loop!" + from pypy.interpreter import opcode try: while True: try: From pedronis at codespeak.net Tue May 27 12:55:22 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 12:55:22 +0200 (MEST) Subject: [pypy-svn] rev 525 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527105522.828895A186@thoth.codespeak.net> Author: pedronis Date: Tue May 27 12:55:22 2003 New Revision: 525 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py Log: let's have separate support for app level hidden app level helper functions for implementing extmodule. set __apphelperfile__ to an AppFile call function defined in it through self.callhelp 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 12:55:22 2003 @@ -47,10 +47,13 @@ class BuiltinModule: __appfile__ = None + __apphelperfile__ = None def __init__(self, space): self.space = space - + if self.__apphelperfile__ is not None: + self._helper = AppHelper(self.space, self.__apphelperfile__) + def wrap_me(self): space = self.space modulename = self.__pythonname__ @@ -68,3 +71,7 @@ w_dict = space.getattr(w_module, space.wrap("__dict__")) appfile.AppHelper(space, sappfile, w_dict) return w_module + + def callhelp(functioname,argslist): + self._helper.call(functioname,argslist) + From pedronis at codespeak.net Tue May 27 12:58:05 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 12:58:05 +0200 (MEST) Subject: [pypy-svn] rev 526 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527105805.2ACC85A186@thoth.codespeak.net> Author: pedronis Date: Tue May 27 12:58:04 2003 New Revision: 526 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py Log: renamed __apphelperfile__ __helper_appfile__ 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 12:58:04 2003 @@ -47,12 +47,12 @@ class BuiltinModule: __appfile__ = None - __apphelperfile__ = None + __helper_appfile__ = None def __init__(self, space): self.space = space - if self.__apphelperfile__ is not None: - self._helper = AppHelper(self.space, self.__apphelperfile__) + if self.__helper_appfile__ is not None: + self._helper = AppHelper(self.space, self.__helper_appfile__) def wrap_me(self): space = self.space From pedronis at codespeak.net Tue May 27 13:00:48 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 13:00:48 +0200 (MEST) Subject: [pypy-svn] rev 527 - pypy/trunk/src/pypy/module Message-ID: <20030527110048.4D9025A186@thoth.codespeak.net> Author: pedronis Date: Tue May 27 13:00:48 2003 New Revision: 527 Added: pypy/trunk/src/pypy/module/builtin_helper_app.py Log: file for app level impl. functions for builtins that should be hidden from app level. Added: pypy/trunk/src/pypy/module/builtin_helper_app.py ============================================================================== From tomek at codespeak.net Tue May 27 13:01:08 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 13:01:08 +0200 (MEST) Subject: [pypy-svn] rev 528 - pypy/trunk/src/pypy/module Message-ID: <20030527110108.4D54E5A186@thoth.codespeak.net> Author: tomek Date: Tue May 27 13:01:08 2003 New Revision: 528 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: got rid of import type 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 13:01:08 2003 @@ -1,5 +1,3 @@ -import types - # XXX kwds yet to come # Problem: need to decide how to implement iterators, @@ -14,13 +12,14 @@ def isinstance(obj, klass_or_tuple): objcls = obj.__class__ - if type(klass_or_tuple) == types.TupleType: + if type(klass_or_tuple) is tuple: for klass in klass_or_tuple: if issubclass(objcls, klass): return 1 return 0 - elif type(klass_or_tuple) == types.ClassType: - return issubclass(objcls, klass_or_tuple) else: - raise TypeError, "isinstance() arg 2 must be a class or type" + try: + return issubclass(objcls, klass_or_tuple) + except TypeError: + raise TypeError, "isinstance() arg 2 must be a class or type" From pedronis at codespeak.net Tue May 27 13:10:30 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 13:10:30 +0200 (MEST) Subject: [pypy-svn] rev 529 - pypy/trunk/src/pypy/module Message-ID: <20030527111030.775465A186@thoth.codespeak.net> Author: pedronis Date: Tue May 27 13:10:30 2003 New Revision: 529 Modified: pypy/trunk/src/pypy/module/builtin.py Log: hook builtin_helper_app.py 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 13:10:30 2003 @@ -11,6 +11,8 @@ __pythonname__ = '__builtin__' __appfile__ = appfile.AppFile(__name__, ["module"]) + __helper_appfile__ = appfile.AppFile('builtin_helper',["module"]) + # temporary hack, until we have a real tuple type for calling def tuple(self, w_obj): lis = self.space.unpackiterable(w_obj) From pedronis at codespeak.net Tue May 27 13:13:06 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 13:13:06 +0200 (MEST) Subject: [pypy-svn] rev 530 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527111306.0881C5A186@thoth.codespeak.net> Author: pedronis Date: Tue May 27 13:13:05 2003 New Revision: 530 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py Log: prefix with appfile 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 13:13:05 2003 @@ -52,7 +52,8 @@ def __init__(self, space): self.space = space if self.__helper_appfile__ is not None: - self._helper = AppHelper(self.space, self.__helper_appfile__) + self._helper = appfile.AppHelper(self.space, + self.__helper_appfile__) def wrap_me(self): space = self.space From mwh at codespeak.net Tue May 27 13:14:54 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 13:14:54 +0200 (MEST) Subject: [pypy-svn] rev 531 - pypy/trunk/src/pypy/module/test Message-ID: <20030527111454.111DC5A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 13:14:53 2003 New Revision: 531 Modified: pypy/trunk/src/pypy/module/test/test_builtin.py pypy/trunk/src/pypy/module/test/test_sysmodule.py Log: Use Alex's nice testsuite stuff. Next is wokring out why test_sysmodule fails... Modified: pypy/trunk/src/pypy/module/test/test_builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_builtin.py (original) +++ pypy/trunk/src/pypy/module/test/test_builtin.py Tue May 27 13:14:53 2003 @@ -1,9 +1,6 @@ import testsupport -from pypy.interpreter import unittest_w -from pypy.objspace.std import StdObjSpace - -class TestCompile(unittest_w.TestCase_w): +class TestBuiltin(testsupport.TestCase): def setUp(self): self.space = testsupport.objspace() Modified: pypy/trunk/src/pypy/module/test/test_sysmodule.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_sysmodule.py (original) +++ pypy/trunk/src/pypy/module/test/test_sysmodule.py Tue May 27 13:14:53 2003 @@ -1,10 +1,8 @@ -import testsupport, unittest -from pypy.interpreter.unittest_w import TestCase_w -from pypy.objspace.std.objspace import StdObjSpace +import testsupport -class SysTests(TestCase_w): +class SysTests(testsupport.TestCase): def setUp(self): - self.space = StdObjSpace() + self.space = testsupport.objspace() self.sys_w = self.space.getitem(self.space.w_modules, self.space.wrap("sys")) def tearDown(self): @@ -15,5 +13,5 @@ self.failUnless_w(s.getattr(self.sys_w, s.wrap("stdout"))) if __name__ == '__main__': - unittest.main() + testsupport.main() From tomek at codespeak.net Tue May 27 13:20:34 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 13:20:34 +0200 (MEST) Subject: [pypy-svn] rev 532 - pypy/trunk/src/pypy/module Message-ID: <20030527112034.011315A259@thoth.codespeak.net> Author: tomek Date: Tue May 27 13:20:34 2003 New Revision: 532 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: functionals: reduce, zip and filter 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 13:20:34 2003 @@ -10,6 +10,22 @@ "docstring" return [function(x) for x in list] +def filter(function, list): + pass + +def zip(function, list): + pass + +def reduce(function, list, initial = None): + if initial is None: + try: + initial = list.pop(0) + except IndexError: + raise TypeError, "reduce() of empty sequence with no initial value" + for value in list: + initial = function(initial, value) + return initial + def isinstance(obj, klass_or_tuple): objcls = obj.__class__ if type(klass_or_tuple) is tuple: From mwh at codespeak.net Tue May 27 13:22:55 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 13:22:55 +0200 (MEST) Subject: [pypy-svn] rev 533 - in pypy/trunk/src/pypy: interpreter module Message-ID: <20030527112255.EFBF45A259@thoth.codespeak.net> Author: mwh Date: Tue May 27 13:22:55 2003 New Revision: 533 Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py pypy/trunk/src/pypy/module/builtin.py Log: That name's not going to survive for very long! 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 13:22:55 2003 @@ -34,7 +34,7 @@ self.setattr(self.w_sys, self.wrap("modules"), self.w_modules) # XXX use a dictionary in the future - def get_builtin(self,w_name): + def get_builtin_module(self, w_name): name = self.unwrap(w_name) if name == '__builtin__': return self.w_builtin 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 13:22:55 2003 @@ -28,7 +28,7 @@ except executioncontext.OperationError,e: if not e.match(space, space.w_KeyError): raise - w_mod = space.get_builtin(w_modulename) + w_mod = space.get_builtin_module(w_modulename) if w_mod is not None: space.setitem(space.w_modules,w_modulename,w_mod) return w_mod From mwh at codespeak.net Tue May 27 13:25:26 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 13:25:26 +0200 (MEST) Subject: [pypy-svn] rev 534 - pypy/trunk/src/pypy/objspace Message-ID: <20030527112526.6236B5A259@thoth.codespeak.net> Author: mwh Date: Tue May 27 13:25:26 2003 New Revision: 534 Modified: pypy/trunk/src/pypy/objspace/trivial.py Log: Add w_sys to TrivialObjSpace. We really should document the object space interface at some point... Modified: pypy/trunk/src/pypy/objspace/trivial.py ============================================================================== --- pypy/trunk/src/pypy/objspace/trivial.py (original) +++ pypy/trunk/src/pypy/objspace/trivial.py Tue May 27 13:25:26 2003 @@ -20,6 +20,7 @@ self.w_None = None self.w_True = True self.w_False = False + self.w_sys = sys # general stuff def wrap(self, x): From tomek at codespeak.net Tue May 27 13:27:55 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 13:27:55 +0200 (MEST) Subject: [pypy-svn] rev 535 - pypy/trunk/src/pypy/module Message-ID: <20030527112755.6A5A95A259@thoth.codespeak.net> Author: tomek Date: Tue May 27 13:27:55 2003 New Revision: 535 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: small changes.. 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 13:27:55 2003 @@ -11,7 +11,16 @@ return [function(x) for x in list] def filter(function, list): - pass + res = [] + if function is None: + for elem in list: + if elem: + res.append(elem) + else: + for elem in list: + if function(elem): + res.append(elem) + def zip(function, list): pass From lac at codespeak.net Tue May 27 13:31:55 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Tue, 27 May 2003 13:31:55 +0200 (MEST) Subject: [pypy-svn] rev 536 - pypy/trunk/src/pypy/module Message-ID: <20030527113155.ABE125A259@thoth.codespeak.net> Author: lac Date: Tue May 27 13:31:55 2003 New Revision: 536 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: Added the builtin range() 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 13:31:55 2003 @@ -48,3 +48,27 @@ except TypeError: raise TypeError, "isinstance() arg 2 must be a class or type" +def range(x, y=None, step=1): + "docstring" + + if y is None: + start = 0 + stop = x + else: + start = x + stop = y + + arr = [] + i = start + if step == 0: + raise ValueError, 'range() arg 3 must not be zero' + elif step > 0: + while i < stop: + arr.append(i) + i += step + else: + while i > stop: + arr.append(i) + i += step + + return arr From arigo at codespeak.net Tue May 27 13:37:39 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 13:37:39 +0200 (MEST) Subject: [pypy-svn] rev 537 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527113739.9925F5A259@thoth.codespeak.net> Author: arigo Date: Tue May 27 13:37:39 2003 New Revision: 537 Modified: pypy/trunk/src/pypy/objspace/std/objspace.py Log: fake __class__ attribute 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 13:37:39 2003 @@ -163,6 +163,11 @@ #w_type = space.type(w_obj) #w_typename = space.getattr(w_type, space.wrap('__name__')) #... + + # XXX as long as don't have types... + if space.is_true(space.eq(w_attr, space.wrap('__class__'))): + return space.wrap(space.unwrap(w_obj).__class__) + raise OperationError(space.w_AttributeError, w_attr) StdObjSpace.getattr.register(default_getattr, W_ANY, W_ANY) @@ -176,3 +181,11 @@ raise OperationError(space.w_AttributeError, w_attr) StdObjSpace.delattr.register(default_getattr, W_ANY, W_ANY) + +# add default implementations for in-place operators +for _name, _symbol, _arity in ObjSpace.MethodTable: + if _name.startswith('inplace_'): + def default_inplace(space, w_1, w_2, baseop=_name[8:]): + op = getattr(space, baseop) + return op(w_1, w_2) + getattr(StdObjSpace, _name).register(default_inplace, W_ANY, W_ANY) From lac at codespeak.net Tue May 27 13:39:16 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Tue, 27 May 2003 13:39:16 +0200 (MEST) Subject: [pypy-svn] rev 538 - pypy/trunk/src/pypy/module/test Message-ID: <20030527113916.A266C5A259@thoth.codespeak.net> Author: lac Date: Tue May 27 13:39:16 2003 New Revision: 538 Added: pypy/trunk/src/pypy/module/test/test_range.py Log: Unit tests for the builtin range. Added: pypy/trunk/src/pypy/module/test/test_range.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/test_range.py Tue May 27 13:39:16 2003 @@ -0,0 +1,46 @@ +import testsupport +from pypy.module.builtin_app import range + +class TestRange(testsupport.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_range_one(self): + self.assertEqual(range(1), [0]) + + def test_range_none(self): + self.assertEqual(range(0), []) + + def test_range_twoargs(self): + self.assertEqual(range(1, 2), [1]) + + def test_range_decreasingtwoargs(self): + self.assertEqual(range(3, 1), []) + + def test_range_negatives(self): + self.assertEqual(range(-3), []) + + def test_range_decreasing_negativestep(self): + self.assertEqual(range(5, -2, -1), [5, 4, 3, 2, 1, 0 , -1]) + + def test_range_decreasing_negativelargestep(self): + self.assertEqual(range(5, -2, -3), [5, 2, -1]) + + def test_range_decreasing_negativelargestep2(self): + self.assertEqual(range(5, -3, -3), [5, 2, -1]) + + def test_range_zerostep(self): + self.assertRaises(ValueError, range, 1, 5, 0) + + def test_range_float(self): + "How CPython does it - UGLY, ignored for now." + self.assertEqual(range(0.1, 2.0, 1.1), [0, 1]) + +if __name__ == '__main__': + testsupport.main() + + From arigo at codespeak.net Tue May 27 13:43:43 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 13:43:43 +0200 (MEST) Subject: [pypy-svn] rev 539 - in pypy/trunk/src/pypy: module objspace/std objspace/std/test Message-ID: <20030527114343.BB8415A259@thoth.codespeak.net> Author: arigo Date: Tue May 27 13:43:43 2003 New Revision: 539 Modified: pypy/trunk/src/pypy/module/builtin.py pypy/trunk/src/pypy/module/builtin_app.py pypy/trunk/src/pypy/objspace/std/sliceobject.py pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py pypy/trunk/src/pypy/objspace/std/tupleobject.py Log: getting closer to having slices working, but tests still fail 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 13:43:43 2003 @@ -13,6 +13,9 @@ __helper_appfile__ = appfile.AppFile('builtin_helper',["module"]) + # we have None! + None = appdata(_b.None) + # temporary hack, until we have a real tuple type for calling def tuple(self, w_obj): lis = self.space.unpackiterable(w_obj) 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 13:43:43 2003 @@ -3,8 +3,8 @@ # Problem: need to decide how to implement iterators, # which are needed for star args. -def apply(function, args):#, kwds): - return function(*args)#, **kwds) +def apply(function, args, kwds): + return function(*args, **kwds) def map(function, list): "docstring" @@ -37,7 +37,7 @@ def isinstance(obj, klass_or_tuple): objcls = obj.__class__ - if type(klass_or_tuple) is tuple: + if issubclass(klass_or_tuple.__class__, tuple): for klass in klass_or_tuple: if issubclass(objcls, klass): return 1 Modified: pypy/trunk/src/pypy/objspace/std/sliceobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/sliceobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/sliceobject.py Tue May 27 13:43:43 2003 @@ -1,60 +1,37 @@ +from pypy.objspace.std.objspace import * +from pypy.interpreter.appfile import AppFile -class W_SliceObject(object): - def __init__(self, w_start, w_stop, w_step): - self.w_start = w_start - self.w_stop = w_stop - self.w_step = w_step +appfile = AppFile(__name__, ["objspace.std"]) + + +class W_SliceObject: + def __init__(w_self, w_start, w_stop, w_step): + w_self.w_start = w_start + w_self.w_stop = w_stop + w_self.w_step = w_step def indices(w_self, space, w_length): - length = space.int.as_long(w_length) - - if self.w_step == space.w_None: - step = 1 - elif isinstance(self.w_step, W_IntObject): - step = self.w_step.intval - if step == 0: - raise OperationError( - space.w_ValueError, - space.W_StringObject("slice step cannot be zero")) + w_ret = space.gethelper(appfile).call("sliceindices", [w_self, w_length]) + w_start, w_stop, w_step, w_slicelength = space.unpackiterable(w_ret, 4) + return w_start, w_stop, w_step, w_slicelength + + +def getattr_slice_any(space, w_slice, w_attr): + if space.is_true(space.eq(w_attr, space.wrap('start'))): + if w_slice.w_start is None: + return space.w_None else: - raise OperationError(space.w_TypeError) - - if step < 0: - defstart = length - 1 - defstop = -1 + return w_slice.w_start + if space.is_true(space.eq(w_attr, space.wrap('stop'))): + if w_slice.w_stop is None: + return space.w_None else: - defstart = 0 - defstop = length - - if isinstance(self.w_start, space.W_NoneObject): - start = defstart + return w_slice.w_stop + if space.is_true(space.eq(w_attr, space.wrap('step'))): + if w_slice.w_step is None: + return space.w_None else: - start = space.eval_slice_index(self.w_start) - if start < 0: - start = start + length - if start < 0: - if step < 0: - start = -1 - else: - start = 0 - elif start >= length: - if step < 0: - start = length - 1 - else: - start = length + return w_slice.w_step + raise FailedToImplement(space.w_AttributeError) - if isinstance(self.w_stop, space.W_NoneObject): - stop = defstop - else: - stop = space.eval_slice_index(self.w_stop) - if stop < 0: - stop = stop + length - if stop < 0: - stop = -1 - elif stop > length: - stop = length - - return space.newtuple([space.W_IntObject(start), - space.W_IntObject(stop), - space.W_IntObject(step)]) - +StdObjSpace.getattr.register(getattr_slice_any, W_SliceObject, W_ANY) Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Tue May 27 13:43:43 2003 @@ -1,3 +1,4 @@ +from __future__ import nested_scopes import unittest, sys import testsupport from pypy.interpreter import unittest_w @@ -69,5 +70,26 @@ self.assertEqual_w(self.space.add(w_tuple1, w_tuple0), w_tuple1) self.assertEqual_w(self.space.add(w_tuple0, w_tuple2), w_tuple2) + def test_getslice(self): + w = self.space.wrap + + def test1(testtuple, start, stop, step, expected): + w_slice = self.space.newslice(w(start), w(end), w(step)) + w_tuple = tobj.W_TupleObject([w(i) for i in testtuple]) + w_result = self.space.getitem(w_tuple, w_slice) + self.assertEqual(self.space.unwrap(w_result), expected) + + for testtuple in [(), (5,3,99), tuple(range(5,555,10))]: + for start in [-2, -1, 0, 1, 10]: + for end in [-1, 0, 2, 999]: + test1(testtuple, start, end, 1, testtuple[start:end]) + + test1((5,7,1,4), 3, 1, -2, (4,)) + test1((5,7,1,4), 3, 0, -2, (4, 7)) + test1((5,7,1,4), 3, -1, -2, ()) + test1((5,7,1,4), -2, 11, 2, (1,)) + test1((5,7,1,4), -3, 11, 2, (7, 4)) + test1((5,7,1,4), -5, 11, 2, (7, 4)) + if __name__ == '__main__': unittest.main() Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Tue May 27 13:43:43 2003 @@ -1,5 +1,6 @@ from pypy.objspace.std.objspace import * from intobject import W_IntObject +from sliceobject import W_SliceObject class W_TupleObject(object): @@ -30,7 +31,7 @@ StdObjSpace.len.register(tuple_len, W_TupleObject) -def tuple_getitem(space, w_tuple, w_index): +def getitem_tuple_int(space, w_tuple, w_index): items = w_tuple.wrappeditems try: w_item = items[w_index.intval] @@ -39,7 +40,23 @@ space.wrap("tuple index out of range")) return w_item -StdObjSpace.getitem.register(tuple_getitem, W_TupleObject, W_IntObject) +StdObjSpace.getitem.register(getitem_tuple_int, W_TupleObject, W_IntObject) + +def getitem_tuple_slice(space, w_tuple, w_slice): + items = w_tuple.wrappeditems + w_length = space.wrap(len(items)) + w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length) + start = space.unwrap(w_start) + step = space.unwrap(w_step) + slicelength = space.unwrap(w_slicelength) + assert slicelength >= 0 + subitems = [] + for i in range(slicelength): + subitems.append(items[start]) + start += step + return W_TupleObject(subitems) + +StdObjSpace.getitem.register(getitem_tuple_slice, W_TupleObject, W_SliceObject) def tuple_iter(space, w_tuple): import iterobject From mwh at codespeak.net Tue May 27 13:45:38 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 13:45:38 +0200 (MEST) Subject: [pypy-svn] rev 540 - pypy/trunk/src/pypy/module/test Message-ID: <20030527114538.1A3515A259@thoth.codespeak.net> Author: mwh Date: Tue May 27 13:45:37 2003 New Revision: 540 Modified: pypy/trunk/src/pypy/module/test/test_sysmodule.py (contents, props changed) Log: unbreak Modified: pypy/trunk/src/pypy/module/test/test_sysmodule.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_sysmodule.py (original) +++ pypy/trunk/src/pypy/module/test/test_sysmodule.py Tue May 27 13:45:37 2003 @@ -3,8 +3,7 @@ class SysTests(testsupport.TestCase): def setUp(self): self.space = testsupport.objspace() - self.sys_w = self.space.getitem(self.space.w_modules, - self.space.wrap("sys")) + self.sys_w = self.space.get_builtin_module(self.space.wrap("sys")) def tearDown(self): pass From mwh at codespeak.net Tue May 27 13:47:28 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 13:47:28 +0200 (MEST) Subject: [pypy-svn] rev 541 - in pypy/trunk/src/pypy: . interpreter interpreter/test module objspace/std/test Message-ID: <20030527114728.0FE525A259@thoth.codespeak.net> Author: mwh Date: Tue May 27 13:47:27 2003 New Revision: 541 Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (contents, props changed) pypy/trunk/src/pypy/interpreter/test/testsupport.py (props changed) pypy/trunk/src/pypy/interpreter/unittest_w.py (props changed) pypy/trunk/src/pypy/module/builtin_helper_app.py (props changed) pypy/trunk/src/pypy/module/sysmodule.py (props changed) pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py (props changed) pypy/trunk/src/pypy/objspace/std/test/test_objspace.py (props changed) pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py (props changed) pypy/trunk/src/pypy/testsupport.py (props changed) Log: line endings fu Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Tue May 27 13:47:27 2003 @@ -1,74 +1,74 @@ -import testsupport - -# need pypy.module.builtin first to make other imports work (???) -from pypy.module import builtin - -from pypy.interpreter import extmodule - -class EmptyBM(extmodule.BuiltinModule): - __pythonname__ = 'empty_bm' - -class BM_with_appmethod(extmodule.BuiltinModule): - __pythonname__ = 'bm_with_appmethod' - def amethod(self): return 23 - amethod = extmodule.appmethod(amethod) - -class BM_with_appdata(extmodule.BuiltinModule): - __pythonname__ = 'bm_with_appdata' - somedata = 'twentythree' - somedata = extmodule.appdata(somedata) - - -class TestBuiltinModule(testsupport.TestCase): - - def setUp(self): - self.space = testsupport.objspace() - - def tearDown(self): - pass - - def test_empty(self): - space = self.space - bm = EmptyBM(space) - w_bm = bm.wrap_me() - w_bmd = space.getattr(w_bm, space.wrap('__dict__')) - bmd = space.unwrap(w_bmd) - self.assertEqual(bmd, - {'__doc__': EmptyBM.__doc__, - '__name__': EmptyBM.__pythonname__} ) - - def test_appmethod(self): - space = self.space - bm = BM_with_appmethod(space) - w_bm = bm.wrap_me() - w_bmd = space.getattr(w_bm, space.wrap('__dict__')) - bmd = space.unwrap(w_bmd) - themethod = bmd.get('amethod') - self.assertNotEqual(themethod, None) - w_method = space.getitem(w_bmd, space.wrap('amethod')) - bmd['amethod'] = BM_with_appmethod.amethod - self.assertEqual(bmd, - {'__doc__': BM_with_appmethod.__doc__, - '__name__': BM_with_appmethod.__pythonname__, - 'amethod': BM_with_appmethod.amethod} ) - result = space.call(w_method, space.wrap(()), None) - self.assertEqual(result, 23) - - def test_appdata(self): - space = self.space - bm = BM_with_appdata(space) - w_bm = bm.wrap_me() - w_bmd = space.getattr(w_bm, space.wrap('__dict__')) - bmd = space.unwrap(w_bmd) - thedata = bmd.get('somedata') - self.assertNotEqual(thedata, None) - w_data = space.getitem(w_bmd, space.wrap('somedata')) - bmd['somedata'] = BM_with_appdata.somedata - self.assertEqual(bmd, - {'__doc__': BM_with_appdata.__doc__, - '__name__': BM_with_appdata.__pythonname__, - 'somedata': BM_with_appdata.somedata} ) - self.assertEqual(thedata, 'twentythree') - -if __name__ == '__main__': - testsupport.main() +import testsupport + +# need pypy.module.builtin first to make other imports work (???) +from pypy.module import builtin + +from pypy.interpreter import extmodule + +class EmptyBM(extmodule.BuiltinModule): + __pythonname__ = 'empty_bm' + +class BM_with_appmethod(extmodule.BuiltinModule): + __pythonname__ = 'bm_with_appmethod' + def amethod(self): return 23 + amethod = extmodule.appmethod(amethod) + +class BM_with_appdata(extmodule.BuiltinModule): + __pythonname__ = 'bm_with_appdata' + somedata = 'twentythree' + somedata = extmodule.appdata(somedata) + + +class TestBuiltinModule(testsupport.TestCase): + + def setUp(self): + self.space = testsupport.objspace() + + def tearDown(self): + pass + + def test_empty(self): + space = self.space + bm = EmptyBM(space) + w_bm = bm.wrap_me() + w_bmd = space.getattr(w_bm, space.wrap('__dict__')) + bmd = space.unwrap(w_bmd) + self.assertEqual(bmd, + {'__doc__': EmptyBM.__doc__, + '__name__': EmptyBM.__pythonname__} ) + + def test_appmethod(self): + space = self.space + bm = BM_with_appmethod(space) + w_bm = bm.wrap_me() + w_bmd = space.getattr(w_bm, space.wrap('__dict__')) + bmd = space.unwrap(w_bmd) + themethod = bmd.get('amethod') + self.assertNotEqual(themethod, None) + w_method = space.getitem(w_bmd, space.wrap('amethod')) + bmd['amethod'] = BM_with_appmethod.amethod + self.assertEqual(bmd, + {'__doc__': BM_with_appmethod.__doc__, + '__name__': BM_with_appmethod.__pythonname__, + 'amethod': BM_with_appmethod.amethod} ) + result = space.call(w_method, space.wrap(()), None) + self.assertEqual(result, 23) + + def test_appdata(self): + space = self.space + bm = BM_with_appdata(space) + w_bm = bm.wrap_me() + w_bmd = space.getattr(w_bm, space.wrap('__dict__')) + bmd = space.unwrap(w_bmd) + thedata = bmd.get('somedata') + self.assertNotEqual(thedata, None) + w_data = space.getitem(w_bmd, space.wrap('somedata')) + bmd['somedata'] = BM_with_appdata.somedata + self.assertEqual(bmd, + {'__doc__': BM_with_appdata.__doc__, + '__name__': BM_with_appdata.__pythonname__, + 'somedata': BM_with_appdata.somedata} ) + self.assertEqual(thedata, 'twentythree') + +if __name__ == '__main__': + testsupport.main() From tomek at codespeak.net Tue May 27 14:03:38 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 14:03:38 +0200 (MEST) Subject: [pypy-svn] rev 542 - pypy/trunk/src/pypy/module Message-ID: <20030527120338.303CD5A259@thoth.codespeak.net> Author: tomek Date: Tue May 27 14:03:37 2003 New Revision: 542 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: full implementation of higher order functions 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 14:03:37 2003 @@ -10,20 +10,37 @@ "docstring" return [function(x) for x in list] -def filter(function, list): +def filter(function, collection): res = [] if function is None: - for elem in list: + for elem in collection: if elem: res.append(elem) else: - for elem in list: + for elem in collection: if function(elem): res.append(elem) - + if type(collection) == tuple: + return tuple(res) + elif type(collection) == str: + return "".join(res) + else: + return res + +def zip(*collections): + if len(collections) == 0: + raise TypeError, "zip() requires at least one sequence" + res = [] + while 1: + try: + elems = [] + for collection in collections: + elems.append(collection.pop(0)) + res.append(tuple(elems)) + except IndexError: + break + return res -def zip(function, list): - pass def reduce(function, list, initial = None): if initial is None: From tomek at codespeak.net Tue May 27 14:08:24 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 14:08:24 +0200 (MEST) Subject: [pypy-svn] rev 543 - in pypy/trunk/src/pypy: interpreter module Message-ID: <20030527120824.074335A259@thoth.codespeak.net> Author: tomek Date: Tue May 27 14:08:23 2003 New Revision: 543 Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py pypy/trunk/src/pypy/module/builtin.py Log: oct added to baseobjspace's methodtable 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 14:08:23 2003 @@ -182,6 +182,7 @@ ('not_', 'not', 1), ('abs' , 'abs', 1), ('hex', 'hex', 1), + ('oct', 'oct', 1), ('ord', 'ord', 1), ('invert', '~', 1), ('add', '+', 2), 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 14:08:23 2003 @@ -87,6 +87,11 @@ return self.space.hash(w_object) hash = appmethod(hash) + def oct(self, w_val): + return self.space.oct(w_val) + oct = appmethod(oct) + + def hex(self, w_val): return self.space.hex(w_val) hex = appmethod(hex) From arigo at codespeak.net Tue May 27 14:39:23 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 14:39:23 +0200 (MEST) Subject: [pypy-svn] rev 544 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527123923.67C4F5A259@thoth.codespeak.net> Author: arigo Date: Tue May 27 14:39:23 2003 New Revision: 544 Added: pypy/trunk/src/pypy/objspace/std/sliceobject_app.py Log: sorry, forgot this one Added: pypy/trunk/src/pypy/objspace/std/sliceobject_app.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/sliceobject_app.py Tue May 27 14:39:23 2003 @@ -0,0 +1,50 @@ + +def sliceindices(slice, length): + step = slice.step + if step is None: + step = 1 + elif step == 0: + raise ValueError, "slice step cannot be zero" + if step < 0: + defstart = length - 1 + defstop = -1 + else: + defstart = 0 + defstop = length + + start = slice.start + if start is None: + start = defstart + else: + if start < 0: + start += length + if start < 0: + if step < 0: + start = -1 + else: + start = 0 + elif start >= length: + if step < 0: + start = length - 1 + else: + start = length + + stop = slice.stop + if stop is None: + stop = defstop + else: + if stop < 0: + stop += length + if stop < 0: + stop = -1 + elif stop > length: + stop = length + + if (step < 0 and stop >= start) or (step > 0 and start >= stop): + slicelength = 0 + elif step < 0: + slicelength = (stop-start+1)//step + 1 + else: + slicelength = (stop-start-1)//step + 1 + + return start, stop, step, slicelength From lac at codespeak.net Tue May 27 14:44:56 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Tue, 27 May 2003 14:44:56 +0200 (MEST) Subject: [pypy-svn] rev 545 - pypy/trunk/src/pypy/module/test Message-ID: <20030527124456.3B6EB5A186@thoth.codespeak.net> Author: lac Date: Tue May 27 14:44:55 2003 New Revision: 545 Added: pypy/trunk/src/pypy/module/test/test_minmax.py Log: Unit tests for the builtin functions min and max Added: pypy/trunk/src/pypy/module/test/test_minmax.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/test_minmax.py Tue May 27 14:44:55 2003 @@ -0,0 +1,77 @@ +import testsupport +from pypy.module.builtin_app import min, max + +class TestMin(testsupport.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_min_one(self): + self.assertEqual(min(1), 1) + + def test_min_usual(self): + self.assertEqual(min(1, 2, 3), 1) + + def test_min_floats(self): + self.assertEqual(min(0.1, 2.7, 14.7), 0.1) + + # write fixed point if that becomes a type. + + def test_min_chars(self): + self.assertEqual(min('a', 'b', 'c'), 'a') + + # write a unicode test when unicode works. + + def test_min_strings(self): + self.assertEqual(min('aaa', 'bbb', 'c'), 'aaa') + + # write an imaginary test when we have complex numbers + + def test_min_mixed(self): + self.assertEqual(min('1', 2, 3, 'aa'), 2) + + def test_min_noargs(self): + self.assertRaises(TypeError, min) + +class TestMax(testsupport.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_max_one(self): + self.assertEqual(max(1), 1) + + def test_max_usual(self): + self.assertEqual(max(1, 2, 3), 3) + + def test_max_floats(self): + self.assertEqual(max(0.1, 2.7, 14.7), 14.7) + + # write fixed point if that becomes a type. + + def test_max_chars(self): + self.assertEqual(max('a', 'b', 'c'), 'c') + + # write a unicode test when unicode works. + + def test_max_strings(self): + self.assertEqual(max('aaa', 'bbb', 'c'), 'c') + + # write an imaginary test when we have complex numbers + + def test_max_mixed(self): + self.assertEqual(max('1', 2, 3, 'aa'), 'aa') + + def test_max_noargs(self): + self.assertRaises(TypeError, max) + +if __name__ == '__main__': + testsupport.main() + + From tomek at codespeak.net Tue May 27 14:46:55 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 14:46:55 +0200 (MEST) Subject: [pypy-svn] rev 546 - pypy/trunk/src/pypy/module Message-ID: <20030527124655.8CBDD5A186@thoth.codespeak.net> Author: tomek Date: Tue May 27 14:46:55 2003 New Revision: 546 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: changes by map 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 14:46:55 2003 @@ -6,9 +6,29 @@ def apply(function, args, kwds): return function(*args, **kwds) -def map(function, list): - "docstring" - return [function(x) for x in list] +def map(function, *collections): + if len(collections) == 1: + #it's the most common case, so make it faster + return [function(x) for x in collections[0]] + else: + res = [] + idx = 0 + while 1: + cont = 0 #is any collection not empty? + args = [] + for collection in collections: + try: + elem = collection[idx] + cont = cont + 1 + except IndexError: + elem = None + args.append(elem) + if cont: + res.append(function(*args)) + else: + return res + idx = idx + 1 + print idx def filter(function, collection): res = [] @@ -20,9 +40,9 @@ for elem in collection: if function(elem): res.append(elem) - if type(collection) == tuple: + if type(collection) is tuple: return tuple(res) - elif type(collection) == str: + elif type(collection) is str: return "".join(res) else: return res From lac at codespeak.net Tue May 27 14:49:32 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Tue, 27 May 2003 14:49:32 +0200 (MEST) Subject: [pypy-svn] rev 547 - pypy/trunk/src/pypy/module Message-ID: <20030527124932.EE5E75A186@thoth.codespeak.net> Author: lac Date: Tue May 27 14:49:32 2003 New Revision: 547 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: Added the builtins min and max 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 14:49:32 2003 @@ -109,3 +109,27 @@ i += step return arr + +def min(*arr): + "docstring" + + if not len(arr): + raise TypeError, 'min/max() takes exactly 1 argument (0 given)' + + min = arr[0] + for i in arr: + if min > i: + min = i + return min + +def max(*arr): + "docstring" + + if not len(arr): + raise TypeError, 'min/max() takes exactly 1 argument (0 given)' + + max = arr[0] + for i in arr: + if max < i: + max = i + return max From mwh at codespeak.net Tue May 27 14:57:33 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 14:57:33 +0200 (MEST) Subject: [pypy-svn] rev 548 - in pypy/trunk/src/pypy: . appspace/test interpreterinterpreter/test module/test objspace/std/test Message-ID: <20030527125733.CC5ED5A186@thoth.codespeak.net> Author: mwh Date: Tue May 27 14:57:33 2003 New Revision: 548 Added: pypy/trunk/src/pypy/appspace/test/__init__.py pypy/trunk/src/pypy/interpreter/testtools.py pypy/trunk/src/pypy/module/test/__init__.py pypy/trunk/src/pypy/objspace/std/test/__init__.py pypy/trunk/src/pypy/objspace/std/test/broken_test_floatobject.py - copied unchanged from rev 544, pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py pypy/trunk/src/pypy/objspace/std/test/broken_test_template.py - copied unchanged from rev 544, pypy/trunk/src/pypy/objspace/std/test/test_template.py pypy/trunk/src/pypy/testall.py Removed: pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py pypy/trunk/src/pypy/objspace/std/test/test_template.py Modified: pypy/trunk/src/pypy/interpreter/appfile.py pypy/trunk/src/pypy/interpreter/test/testsupport.py pypy/trunk/src/pypy/module/test/testsupport.py (contents, props changed) pypy/trunk/src/pypy/objspace/std/test/testsupport.py pypy/trunk/src/pypy/testsupport.py Log: Reorganize (well, add) testing framework. The new testall.py script in the root of the project scours for test_*.py files and runs tests therein. Also change testsupport.py files to run tests in their directories when run as a script. Move a couple of REALLY broken tests so that the testall.py script doesn't find them. Added: pypy/trunk/src/pypy/appspace/test/__init__.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/appspace/test/__init__.py Tue May 27 14:57:33 2003 @@ -0,0 +1 @@ +# empty Modified: pypy/trunk/src/pypy/interpreter/appfile.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/appfile.py (original) +++ pypy/trunk/src/pypy/interpreter/appfile.py Tue May 27 14:57:33 2003 @@ -25,7 +25,7 @@ break else: raise IOError, "cannot locate helper module '%s' in %s" % ( - modulename, lookuppaths_ext) + modulename, path_ext) f = open(filename, 'r') src = f.read() f.close() Modified: pypy/trunk/src/pypy/interpreter/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/testsupport.py (original) +++ pypy/trunk/src/pypy/interpreter/test/testsupport.py Tue May 27 14:57:33 2003 @@ -1,49 +1,60 @@ -""" -Master version of testsupport.py: copy into any subdirectory of pypy -from which scripts need to be run (typically all of the 'test' subdirs) -so that any test can "import testsupport" to ensure the parent of pypy -is on the sys.path -- so that "import pypy.etc.etc." always works. - -Also, this module exposes a member 'TestCase' that is unittest.TestCase -or a subclass thereof supplying extra methods; and a function 'main' -that is unittest.main or the equivalent. - -Furthermore, this module now exposes a member 'objspace' which is -by default class pypy.objspace.trivial.TrivialObjSpace but can be -set to use another objectspace instead; this allows tests to run -under different objectspaces without needing to edit their sources. - -For this setting, use environment variable OBJSPACE and set it to -a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is -also the default if the environment variable is not found or empty -or without any dot in it). -""" -import sys, os - -head = this_path = os.path.abspath(__file__) -while 1: - head, tail = os.path.split(head) - if not tail: - raise EnvironmentError, "pypy not among parents of %r!" % this_path - elif tail.lower()=='pypy': - sys.path.insert(0, head) - break - -import pypy.interpreter.unittest_w -TestCase = pypy.interpreter.unittest_w.TestCase_w -import unittest -main = unittest.main - -objspace_path = os.environ.get('OBJSPACE') -if not objspace_path or '.' not in objspace_path: - import pypy.objspace.trivial - objspace = pypy.objspace.trivial.TrivialObjSpace -else: - objspace_pieces = objspace_path.split('.') - objspace_path = '.'.join(objspace_pieces[:-1]) - objspace_module = __import__(objspace_path) - for piece in objspace_pieces[1:-1]: - objspace_module = getattr(objspace_module, piece) - objspace_classname = objspace_pieces[-1] - objspace = getattr(objspace_module, objspace_classname) - +""" +Master version of testsupport.py: copy into any subdirectory of pypy +from which scripts need to be run (typically all of the 'test' subdirs) +so that any test can "import testsupport" to ensure the parent of pypy +is on the sys.path -- so that "import pypy.etc.etc." always works. + +Also, this module exposes a member 'TestCase' that is unittest.TestCase +or a subclass thereof supplying extra methods; and a function 'main' +that is unittest.main or the equivalent. + +Furthermore, this module now exposes a member 'objspace' which is +by default class pypy.objspace.trivial.TrivialObjSpace but can be +set to use another objectspace instead; this allows tests to run +under different objectspaces without needing to edit their sources. + +For this setting, use environment variable OBJSPACE and set it to +a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is +also the default if the environment variable is not found or empty +or without any dot in it). + +When run as a script, runs all tests found in files called 'test_*.py' +in the same directory. +""" +import sys, os + +try: + head = this_path = os.path.abspath(__file__) +except NameError: + head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + sys.path.insert(0, head) + break + +import pypy.interpreter.unittest_w +TestCase = pypy.interpreter.unittest_w.TestCase_w +import unittest +main = unittest.main + +from pypy.interpreter import testtools + +objspace_path = os.environ.get('OBJSPACE') +if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + objspace = pypy.objspace.trivial.TrivialObjSpace +else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + objspace = getattr(objspace_module, objspace_classname) + +if __name__ == '__main__': + runner = unittest.TextTestRunner() + runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0]))) Added: pypy/trunk/src/pypy/interpreter/testtools.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/interpreter/testtools.py Tue May 27 14:57:33 2003 @@ -0,0 +1,18 @@ +import os +import unittest + +def get_tests_for_dir(directory): + files = os.listdir(directory) + testfiles = [f[:-3] for f in files if f.startswith('test_') and f.endswith('.py')] + + ts = unittest.TestSuite() + + tl = unittest.TestLoader() + + for testfile in testfiles: + mod = __import__(testfile) + ts.addTest(tl.loadTestsFromModule(mod)) + + return ts + + Added: pypy/trunk/src/pypy/module/test/__init__.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/__init__.py Tue May 27 14:57:33 2003 @@ -0,0 +1 @@ +# empty Modified: pypy/trunk/src/pypy/module/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/module/test/testsupport.py (original) +++ pypy/trunk/src/pypy/module/test/testsupport.py Tue May 27 14:57:33 2003 @@ -1,49 +1,60 @@ -""" -Master version of testsupport.py: copy into any subdirectory of pypy -from which scripts need to be run (typically all of the 'test' subdirs) -so that any test can "import testsupport" to ensure the parent of pypy -is on the sys.path -- so that "import pypy.etc.etc." always works. - -Also, this module exposes a member 'TestCase' that is unittest.TestCase -or a subclass thereof supplying extra methods; and a function 'main' -that is unittest.main or the equivalent. - -Furthermore, this module now exposes a member 'objspace' which is -by default class pypy.objspace.trivial.TrivialObjSpace but can be -set to use another objectspace instead; this allows tests to run -under different objectspaces without needing to edit their sources. - -For this setting, use environment variable OBJSPACE and set it to -a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is -also the default if the environment variable is not found or empty -or without any dot in it). -""" -import sys, os - -head = this_path = os.path.abspath(__file__) -while 1: - head, tail = os.path.split(head) - if not tail: - raise EnvironmentError, "pypy not among parents of %r!" % this_path - elif tail.lower()=='pypy': - sys.path.insert(0, head) - break - -import pypy.interpreter.unittest_w -TestCase = pypy.interpreter.unittest_w.TestCase_w -import unittest -main = unittest.main - -objspace_path = os.environ.get('OBJSPACE') -if not objspace_path or '.' not in objspace_path: - import pypy.objspace.trivial - objspace = pypy.objspace.trivial.TrivialObjSpace -else: - objspace_pieces = objspace_path.split('.') - objspace_path = '.'.join(objspace_pieces[:-1]) - objspace_module = __import__(objspace_path) - for piece in objspace_pieces[1:-1]: - objspace_module = getattr(objspace_module, piece) - objspace_classname = objspace_pieces[-1] - objspace = getattr(objspace_module, objspace_classname) - +""" +Master version of testsupport.py: copy into any subdirectory of pypy +from which scripts need to be run (typically all of the 'test' subdirs) +so that any test can "import testsupport" to ensure the parent of pypy +is on the sys.path -- so that "import pypy.etc.etc." always works. + +Also, this module exposes a member 'TestCase' that is unittest.TestCase +or a subclass thereof supplying extra methods; and a function 'main' +that is unittest.main or the equivalent. + +Furthermore, this module now exposes a member 'objspace' which is +by default class pypy.objspace.trivial.TrivialObjSpace but can be +set to use another objectspace instead; this allows tests to run +under different objectspaces without needing to edit their sources. + +For this setting, use environment variable OBJSPACE and set it to +a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is +also the default if the environment variable is not found or empty +or without any dot in it). + +When run as a script, runs all tests found in files called 'test_*.py' +in the same directory. +""" +import sys, os + +try: + head = this_path = os.path.abspath(__file__) +except NameError: + head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + sys.path.insert(0, head) + break + +import pypy.interpreter.unittest_w +TestCase = pypy.interpreter.unittest_w.TestCase_w +import unittest +main = unittest.main + +from pypy.interpreter import testtools + +objspace_path = os.environ.get('OBJSPACE') +if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + objspace = pypy.objspace.trivial.TrivialObjSpace +else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + objspace = getattr(objspace_module, objspace_classname) + +if __name__ == '__main__': + runner = unittest.TextTestRunner() + runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0]))) Added: pypy/trunk/src/pypy/objspace/std/test/__init__.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/test/__init__.py Tue May 27 14:57:33 2003 @@ -0,0 +1 @@ +# empty Deleted: pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py Tue May 27 14:57:33 2003 +++ (empty file) @@ -1,118 +0,0 @@ -#!/usr/bin/env python -import unittest -import sys -import os - -print "not working, rewrite this test!" -sys.exit(0) - -#Start HACK - -####################################### -# Workaround to give the modules -# an "objectspace" -####################################### - -import pypy.objspace -thisdir = os.getcwd() -syspath = sys.path -sys.path.insert(0,thisdir) -sys.path.append('..') - - -####################################### -# import the module you want to test -# import yourmodule -####################################### - -os.chdir('..') -import floatobject as fl -os.chdir(thisdir) - -# End HACK - -True,False = (1==1),(1==0) - -class TestW_FloatObject(unittest.TestCase): - - def setUp(self): - self.space = objspace.StdObjSpace - - def tearDown(self): - pass - - def test_float(self): - f1 = fl.W_FloatObject(1.0) - result = fl.float_float(self.space,f1) - assert result == f1 - - def test_repr(self): - x = 1.0 - f1 = fl.W_FloatObject(x) - result = fl.float_repr(self.space,f1) - assert self.space.unwrap(result) == repr(x) - - def test_str(self): - x = 1.0 - f1 = fl.W_FloatObject(x) - result = fl.float_str(self.space,f1) - assert self.space.unwrap(result) == str(x) - - def test_hash(self): - x = 1.0 - f1 = fl.W_FloatObject(x) - result = fl.float_hash(self.space,f1) - assert self.space.unwrap(result) == hash(x) - - def test_add(self): - f1 = fl.W_FloatObject(1.0) - f2 = fl.W_FloatObject(2.0) - result = fl.float_float_add(self.space,f1,f2) - assert result.floatval == 3.0 - - def test_sub(self): - f1 = fl.W_FloatObject(1.0) - f2 = fl.W_FloatObject(2.0) - result = fl.float_float_sub(self.space,f1,f2) - assert result.floatval == -1.0 - - def test_mul(self): - f1 = fl.W_FloatObject(1.0) - f2 = fl.W_FloatObject(2.0) - result = fl.float_float_mul(self.space,f1,f2) - assert result.floatval == 2.0 - - def test_div(self): - f1 = fl.W_FloatObject(1.0) - f2 = fl.W_FloatObject(2.0) - result = fl.float_float_div(self.space,f1,f2) - assert result.floatval == 0.5 - - def test_mod(self): - x = 1.0 - y = 2.0 - f1 = fl.W_FloatObject(x) - f2 = fl.W_FloatObject(y) - v = fl.float_float_mod(self.space,f1,f2) - assert v.floatval == x % y - - def test_divmod(self): - x = 1.0 - y = 2.0 - f1 = fl.W_FloatObject(x) - f2 = fl.W_FloatObject(y) - wrappedTuple = fl.float_float_divmod(self.space,f1,f2) - v,w = self.space.unwrap(wrappedTuple) - assert (v.floatval,w.floatval) == divmod(x,y) - - def test_pow(self): - x = 1.0 - y = 2.0 - f1 = fl.W_FloatObject(x) - f2 = fl.W_FloatObject(y) - v = fl.float_float_pow(self.space,f1,f2) - assert v.floatval == x ** y - - -if __name__ == '__main__': - unittest.main() Deleted: pypy/trunk/src/pypy/objspace/std/test/test_template.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_template.py Tue May 27 14:57:33 2003 +++ (empty file) @@ -1,35 +0,0 @@ -import sys -print "not working, do not run nor use this!" -sys.exit(0) - -import objspace -thisdir = os.getcwd() -syspath = sys.path -sys.path.insert(0,thisdir) -sys.path.append('..') - - -####################################### -# import the module you want to test -# import yourmodule -####################################### - -os.chdir('..') -#import your_object_class -os.chdir(thisdir) - -# End HACK -class TestYourObjectClass(unittest.TestCase): - - def setUp(self): - pass - - def tearDown(self): - pass - - def test_test1(self): - pass - - -if __name__ == '__main__': - unittest.main() Modified: pypy/trunk/src/pypy/objspace/std/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/testsupport.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/testsupport.py Tue May 27 14:57:33 2003 @@ -17,10 +17,16 @@ a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is also the default if the environment variable is not found or empty or without any dot in it). + +When run as a script, runs all tests found in files called 'test_*.py' +in the same directory. """ import sys, os -head = this_path = os.path.abspath(__file__) +try: + head = this_path = os.path.abspath(__file__) +except NameError: + head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) while 1: head, tail = os.path.split(head) if not tail: @@ -34,6 +40,8 @@ import unittest main = unittest.main +from pypy.interpreter import testtools + objspace_path = os.environ.get('OBJSPACE') if not objspace_path or '.' not in objspace_path: import pypy.objspace.trivial @@ -47,3 +55,6 @@ objspace_classname = objspace_pieces[-1] objspace = getattr(objspace_module, objspace_classname) +if __name__ == '__main__': + runner = unittest.TextTestRunner() + runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0]))) Added: pypy/trunk/src/pypy/testall.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/testall.py Tue May 27 14:57:33 2003 @@ -0,0 +1,39 @@ +import os +import unittest +import sys + +try: + head = this_path = os.path.abspath(__file__) +except NameError: + head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + PYPYDIR = head + if PYPYDIR not in sys.path: + sys.path.insert(0, PYPYDIR) + break + +def find_tests(root): + testmods = [] + def callback(arg, dirname, names): + if os.path.basename(dirname) == 'test': + package = dirname[len(PYPYDIR)+1:].replace(os.sep, '.') + testfiles = [f[:-3] for f in names + if f.startswith('test_') and f.endswith('.py')] + for file in testfiles: + testmods.append(package + '.' + file) + + os.path.walk(root, callback, None) + + tl = unittest.TestLoader() + + return tl.loadTestsFromNames(testmods) + +if __name__ == '__main__': + runner = unittest.TextTestRunner() + runner.run(find_tests(PYPYDIR)) + + Modified: pypy/trunk/src/pypy/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/testsupport.py (original) +++ pypy/trunk/src/pypy/testsupport.py Tue May 27 14:57:33 2003 @@ -1,49 +1,60 @@ -""" -Master version of testsupport.py: copy into any subdirectory of pypy -from which scripts need to be run (typically all of the 'test' subdirs) -so that any test can "import testsupport" to ensure the parent of pypy -is on the sys.path -- so that "import pypy.etc.etc." always works. - -Also, this module exposes a member 'TestCase' that is unittest.TestCase -or a subclass thereof supplying extra methods; and a function 'main' -that is unittest.main or the equivalent. - -Furthermore, this module now exposes a member 'objspace' which is -by default class pypy.objspace.trivial.TrivialObjSpace but can be -set to use another objectspace instead; this allows tests to run -under different objectspaces without needing to edit their sources. - -For this setting, use environment variable OBJSPACE and set it to -a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is -also the default if the environment variable is not found or empty -or without any dot in it). -""" -import sys, os - -head = this_path = os.path.abspath(__file__) -while 1: - head, tail = os.path.split(head) - if not tail: - raise EnvironmentError, "pypy not among parents of %r!" % this_path - elif tail.lower()=='pypy': - sys.path.insert(0, head) - break - -import pypy.interpreter.unittest_w -TestCase = pypy.interpreter.unittest_w.TestCase_w -import unittest -main = unittest.main - -objspace_path = os.environ.get('OBJSPACE') -if not objspace_path or '.' not in objspace_path: - import pypy.objspace.trivial - objspace = pypy.objspace.trivial.TrivialObjSpace -else: - objspace_pieces = objspace_path.split('.') - objspace_path = '.'.join(objspace_pieces[:-1]) - objspace_module = __import__(objspace_path) - for piece in objspace_pieces[1:-1]: - objspace_module = getattr(objspace_module, piece) - objspace_classname = objspace_pieces[-1] - objspace = getattr(objspace_module, objspace_classname) - +""" +Master version of testsupport.py: copy into any subdirectory of pypy +from which scripts need to be run (typically all of the 'test' subdirs) +so that any test can "import testsupport" to ensure the parent of pypy +is on the sys.path -- so that "import pypy.etc.etc." always works. + +Also, this module exposes a member 'TestCase' that is unittest.TestCase +or a subclass thereof supplying extra methods; and a function 'main' +that is unittest.main or the equivalent. + +Furthermore, this module now exposes a member 'objspace' which is +by default class pypy.objspace.trivial.TrivialObjSpace but can be +set to use another objectspace instead; this allows tests to run +under different objectspaces without needing to edit their sources. + +For this setting, use environment variable OBJSPACE and set it to +a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is +also the default if the environment variable is not found or empty +or without any dot in it). + +When run as a script, runs all tests found in files called 'test_*.py' +in the same directory. +""" +import sys, os + +try: + head = this_path = os.path.abspath(__file__) +except NameError: + head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + sys.path.insert(0, head) + break + +import pypy.interpreter.unittest_w +TestCase = pypy.interpreter.unittest_w.TestCase_w +import unittest +main = unittest.main + +from pypy.interpreter import testtools + +objspace_path = os.environ.get('OBJSPACE') +if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + objspace = pypy.objspace.trivial.TrivialObjSpace +else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + objspace = getattr(objspace_module, objspace_classname) + +if __name__ == '__main__': + runner = unittest.TextTestRunner() + runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0]))) From arigo at codespeak.net Tue May 27 15:01:12 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 15:01:12 +0200 (MEST) Subject: [pypy-svn] rev 549 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030527130112.DF8DD5A186@thoth.codespeak.net> Author: arigo Date: Tue May 27 15:01:12 2003 New Revision: 549 Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Log: typos Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Tue May 27 15:01:12 2003 @@ -74,7 +74,7 @@ w = self.space.wrap def test1(testtuple, start, stop, step, expected): - w_slice = self.space.newslice(w(start), w(end), w(step)) + w_slice = self.space.newslice(w(start), w(stop), w(step)) w_tuple = tobj.W_TupleObject([w(i) for i in testtuple]) w_result = self.space.getitem(w_tuple, w_slice) self.assertEqual(self.space.unwrap(w_result), expected) @@ -89,7 +89,7 @@ test1((5,7,1,4), 3, -1, -2, ()) test1((5,7,1,4), -2, 11, 2, (1,)) test1((5,7,1,4), -3, 11, 2, (7, 4)) - test1((5,7,1,4), -5, 11, 2, (7, 4)) + test1((5,7,1,4), -5, 11, 2, (5, 1)) if __name__ == '__main__': unittest.main() From arigo at codespeak.net Tue May 27 15:02:06 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 15:02:06 +0200 (MEST) Subject: [pypy-svn] rev 550 - in pypy/trunk/src/pypy: interpreter module module/test objspace/std Message-ID: <20030527130206.DC1645A186@thoth.codespeak.net> 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: From tomek at codespeak.net Tue May 27 15:10:50 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 15:10:50 +0200 (MEST) Subject: [pypy-svn] rev 551 - pypy/trunk/src/pypy/module Message-ID: <20030527131050.80D285A186@thoth.codespeak.net> Author: tomek Date: Tue May 27 15:10:50 2003 New Revision: 551 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: small changes on functionals 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:10:50 2003 @@ -47,25 +47,34 @@ if len(collections) == 0: raise TypeError, "zip() requires at least one sequence" res = [] + idx = 0 while 1: try: elems = [] for collection in collections: - elems.append(collection.pop(0)) + elems.append(collection[idx]) res.append(tuple(elems)) except IndexError: break + idx = idx + 1 return res def reduce(function, list, initial = None): if initial is None: try: - initial = list.pop(0) + initial = list[0] except IndexError: raise TypeError, "reduce() of empty sequence with no initial value" - for value in list: - initial = function(initial, value) + idx = 1 + else + idx = 0 + while 1: + try: + initial = function(initial, list[idx]) + idx = idx + 1 + except: + break return initial def isinstance(obj, klass_or_tuple): From tismer at codespeak.net Tue May 27 15:11:03 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Tue, 27 May 2003 15:11:03 +0200 (MEST) Subject: [pypy-svn] rev 552 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527131103.1C08C5A186@thoth.codespeak.net> Author: tismer Date: Tue May 27 15:11:02 2003 New Revision: 552 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: basic list objects are working, but yet not better than tuples Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Tue May 27 15:11:02 2003 @@ -1,3 +1,87 @@ +from pypy.objspace.std.objspace import * +from intobject import W_IntObject +from sliceobject import W_SliceObject -class W_ListObject: - ... + +class W_ListObject(object): + + def __init__(self, wrappeditems): + self.wrappeditems = wrappeditems # a list of wrapped values + + def __repr__(w_self): + """ representation for debugging purposes """ + reprlist = [repr(w_item) for w_item in w_self.wrappeditems] + return "%s(%s)" % (w_self.__class__.__name__, ', '.join(reprlist)) + + +def list_unwrap(space, w_list): + items = [space.unwrap(w_item) for w_item in w_list.wrappeditems] + return list(items) + +StdObjSpace.unwrap.register(list_unwrap, W_ListObject) + +def list_is_true(space, w_list): + return not not w_list.wrappeditems + +StdObjSpace.is_true.register(list_is_true, W_ListObject) + +def list_len(space, w_list): + result = len(w_list.wrappeditems) + return W_IntObject(result) + +StdObjSpace.len.register(list_len, W_ListObject) + +def getitem_list_int(space, w_list, w_index): + items = w_list.wrappeditems + try: + w_item = items[w_index.intval] + except IndexError: + raise OperationError(space.w_IndexError, + space.wrap("list index out of range")) + return w_item + +StdObjSpace.getitem.register(getitem_list_int, W_ListObject, W_IntObject) + +def getitem_list_slice(space, w_list, w_slice): + items = w_list.wrappeditems + w_length = space.wrap(len(items)) + w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length) + start = space.unwrap(w_start) + step = space.unwrap(w_step) + slicelength = space.unwrap(w_slicelength) + assert slicelength >= 0 + subitems = [] + for i in range(slicelength): + subitems.append(items[start]) + start += step + return W_ListObject(subitems) + +StdObjSpace.getitem.register(getitem_list_slice, W_ListObject, W_SliceObject) + +def list_iter(space, w_list): + import iterobject + return iterobject.W_SeqIterObject(w_list) + +StdObjSpace.iter.register(list_iter, W_ListObject) + +def list_add(space, w_list1, w_list2): + items1 = w_list1.wrappeditems + items2 = w_list2.wrappeditems + return W_ListObject(items1 + items2) + +StdObjSpace.add.register(list_add, W_ListObject, W_ListObject) + +def list_eq(space, w_list1, w_list2): + items1 = w_list1.wrappeditems + items2 = w_list2.wrappeditems + if len(items1) != len(items2): + return space.w_False + for item1, item2 in zip(items1, items2): + if not space.is_true(space.eq(item1, item2)): + return space.w_False + return space.w_True + +StdObjSpace.eq.register(list_eq, W_ListObject, W_ListObject) + +# upto here, lists are nearly identical to tuples. +# XXX have to add over-allocation! From tismer at codespeak.net Tue May 27 15:11:30 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Tue, 27 May 2003 15:11:30 +0200 (MEST) Subject: [pypy-svn] rev 553 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030527131130.854A45A186@thoth.codespeak.net> Author: tismer Date: Tue May 27 15:11:30 2003 New Revision: 553 Added: pypy/trunk/src/pypy/objspace/std/test/test_listobject.py Log: basic list objects are working, but yet not better than tuples Added: pypy/trunk/src/pypy/objspace/std/test/test_listobject.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/test/test_listobject.py Tue May 27 15:11:30 2003 @@ -0,0 +1,95 @@ +from __future__ import nested_scopes +import unittest, sys +import testsupport +from pypy.interpreter import unittest_w +from pypy.objspace.std import listobject as tobj +from pypy.objspace.std.objspace import * + + +class TestW_ListObject(unittest_w.TestCase_w): + + def setUp(self): + self.space = StdObjSpace() + + def tearDown(self): + pass + + def test_is_true(self): + w = self.space.wrap + w_list = tobj.W_ListObject([]) + self.assertEqual(self.space.is_true(w_list), False) + w_list = tobj.W_ListObject([w(5)]) + self.assertEqual(self.space.is_true(w_list), True) + w_list = tobj.W_ListObject([w(5), w(3)]) + self.assertEqual(self.space.is_true(w_list), True) + + def test_len(self): + w = self.space.wrap + w_list = tobj.W_ListObject([]) + self.assertEqual_w(self.space.len(w_list), w(0)) + w_list = tobj.W_ListObject([w(5)]) + self.assertEqual_w(self.space.len(w_list), w(1)) + w_list = tobj.W_ListObject([w(5), w(3), w(99)]*111) + self.assertEqual_w(self.space.len(w_list), w(333)) + + def test_getitem(self): + w = self.space.wrap + w_list = tobj.W_ListObject([w(5), w(3)]) + self.assertEqual_w(self.space.getitem(w_list, w(0)), w(5)) + self.assertEqual_w(self.space.getitem(w_list, w(1)), w(3)) + self.assertEqual_w(self.space.getitem(w_list, w(-2)), w(5)) + self.assertEqual_w(self.space.getitem(w_list, w(-1)), w(3)) + self.assertRaises_w(self.space.w_IndexError, + self.space.getitem, w_list, w(2)) + self.assertRaises_w(self.space.w_IndexError, + self.space.getitem, w_list, w(42)) + self.assertRaises_w(self.space.w_IndexError, + self.space.getitem, w_list, w(-3)) + + def test_iter(self): + w = self.space.wrap + w_list = tobj.W_ListObject([w(5), w(3), w(99)]) + w_iter = self.space.iter(w_list) + self.assertEqual_w(self.space.next(w_iter), w(5)) + self.assertEqual_w(self.space.next(w_iter), w(3)) + self.assertEqual_w(self.space.next(w_iter), w(99)) + self.assertRaises(NoValue, self.space.next, w_iter) + self.assertRaises(NoValue, self.space.next, w_iter) + + def test_add(self): + w = self.space.wrap + w_list0 = tobj.W_ListObject([]) + w_list1 = tobj.W_ListObject([w(5), w(3), w(99)]) + w_list2 = tobj.W_ListObject([w(-7)] * 111) + self.assertEqual_w(self.space.add(w_list1, w_list1), + tobj.W_ListObject([w(5), w(3), w(99), + w(5), w(3), w(99)])) + self.assertEqual_w(self.space.add(w_list1, w_list2), + tobj.W_ListObject([w(5), w(3), w(99)] + + [w(-7)] * 111)) + self.assertEqual_w(self.space.add(w_list1, w_list0), w_list1) + self.assertEqual_w(self.space.add(w_list0, w_list2), w_list2) + + def test_getslice(self): + w = self.space.wrap + + def test1(testlist, start, stop, step, expected): + w_slice = self.space.newslice(w(start), w(stop), w(step)) + w_list = tobj.W_ListObject([w(i) for i in testlist]) + w_result = self.space.getitem(w_list, w_slice) + self.assertEqual(self.space.unwrap(w_result), expected) + + for testlist in [[], [5,3,99], list(range(5,555,10))]: + for start in [-2, -1, 0, 1, 10]: + for end in [-1, 0, 2, 999]: + test1(testlist, start, end, 1, testlist[start:end]) + + test1([5,7,1,4], 3, 1, -2, [4,]) + test1([5,7,1,4], 3, 0, -2, [4, 7]) + test1([5,7,1,4], 3, -1, -2, []) + test1([5,7,1,4], -2, 11, 2, [1]) + test1([5,7,1,4], -3, 11, 2, [7, 4]) + test1([5,7,1,4], -5, 11, 2, [5, 1]) + +if __name__ == '__main__': + unittest.main() From tomek at codespeak.net Tue May 27 15:15:10 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 15:15:10 +0200 (MEST) Subject: [pypy-svn] rev 554 - pypy/trunk/src/pypy/module Message-ID: <20030527131510.F04E65A243@thoth.codespeak.net> Author: tomek Date: Tue May 27 15:15:10 2003 New Revision: 554 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: syntax error 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:15:10 2003 @@ -67,7 +67,7 @@ except IndexError: raise TypeError, "reduce() of empty sequence with no initial value" idx = 1 - else + else: idx = 0 while 1: try: From pedronis at codespeak.net Tue May 27 15:17:15 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 15:17:15 +0200 (MEST) Subject: [pypy-svn] rev 555 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527131715.606E15A243@thoth.codespeak.net> Author: pedronis Date: Tue May 27 15:17:15 2003 New Revision: 555 Added: pypy/trunk/src/pypy/objspace/std/instmethobject.py Log: instancemethod object beginning Added: pypy/trunk/src/pypy/objspace/std/instmethobject.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/instmethobject.py Tue May 27 15:17:15 2003 @@ -0,0 +1,30 @@ +from __future__ import nested_scopes +from pypy.objspace.std.objspace import * + + +class W_InstMethObject(object): + def __init__(w_self, w_im_self,w_im_func): + w_self.w_im_self = w_im_self + w_self.w_im_func = w_im_func + + +#def function_unwrap(space, w_function): +# # XXX this is probably a temporary hack +# def proxy_function(*args, **kw): +# w_arguments = space.wrap(args) +# w_keywords = space.wrap(kw) +# w_result = func_call(space, w_function, w_arguments, w_keywords) +# return space.unwrap(w_result) +# # XXX no closure implemented +# return proxy_function +# +#StdObjSpace.unwrap.register(function_unwrap, W_FuncObject) + + +def instmeth_call(space, w_instmeth, w_arguments, w_keywords): + w_ret = space.call(self.w_im_func, + space.wrap((space.add(space.newtuple([self.w_im_self]),space.unwrap(w_arguments)), + w_keywords) + return w_ret + +StdObjSpace.call.register(instmeth_call, W_InstMeth, W_ANY, W_ANY) From lac at codespeak.net Tue May 27 15:17:35 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Tue, 27 May 2003 15:17:35 +0200 (MEST) Subject: [pypy-svn] rev 556 - pypy/trunk/src/pypy/module/test Message-ID: <20030527131735.93A225A243@thoth.codespeak.net> Author: lac Date: Tue May 27 15:17:35 2003 New Revision: 556 Modified: pypy/trunk/src/pypy/module/test/test_minmax.py Log: Check that when min or max is fed a non-sequence, it fails. Modified: pypy/trunk/src/pypy/module/test/test_minmax.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_minmax.py (original) +++ pypy/trunk/src/pypy/module/test/test_minmax.py Tue May 27 15:17:35 2003 @@ -9,8 +9,8 @@ def tearDown(self): pass - def test_min_one(self): - self.assertEqual(min(1), 1) + def test_min_notseq(self): + self.assertRaises(TypeError, min, 1) def test_min_usual(self): self.assertEqual(min(1, 2, 3), 1) @@ -44,8 +44,8 @@ def tearDown(self): pass - def test_max_one(self): - self.assertEqual(max(1), 1) + def test_max_notseq(self): + self.assertRaises(TypeError, max, 1) def test_max_usual(self): self.assertEqual(max(1, 2, 3), 3) From mwh at codespeak.net Tue May 27 15:17:37 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 15:17:37 +0200 (MEST) Subject: [pypy-svn] rev 557 - in pypy/trunk/src/pypy: . appspace/test interpreter/test module/test objspace/std/test Message-ID: <20030527131737.4F82C5A259@thoth.codespeak.net> Author: mwh Date: Tue May 27 15:17:36 2003 New Revision: 557 Added: pypy/trunk/src/pypy/appspace/test/testsupport.py Removed: pypy/trunk/src/pypy/appspace/test/setpath.py Modified: pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py pypy/trunk/src/pypy/appspace/test/test_complexobject.py pypy/trunk/src/pypy/interpreter/test/testsupport.py pypy/trunk/src/pypy/module/test/testsupport.py pypy/trunk/src/pypy/objspace/std/test/testsupport.py pypy/trunk/src/pypy/testsupport.py Log: testsupport tweaks. appspace tests probably bust, please hold the line. Deleted: pypy/trunk/src/pypy/appspace/test/setpath.py ============================================================================== --- pypy/trunk/src/pypy/appspace/test/setpath.py Tue May 27 15:17:36 2003 +++ (empty file) @@ -1,15 +0,0 @@ -import sys, os - -dirname = os.path.dirname - -testdir = dirname(os.path.abspath(__file__)) -parentdir = dirname(testdir) -rootdir = dirname(parentdir) - -del dirname - -sys.path.insert(0, rootdir) - -# rootdir should probably be one level up, since then you -# could really import pypy.appsapce... and not just from -# appspace... Modified: pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py ============================================================================== --- pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py (original) +++ pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py Tue May 27 15:17:36 2003 @@ -14,11 +14,11 @@ import sys import types import unittest +import testsupport try: - import setpath - from appspace import cmathmodule - from appspace.complexobject import complex as pycomplex + from pypy.appspace import cmathmodule + from pypy.appspace.complexobject import complex as pycomplex except ImportError: import cmathmodule from complexobject import complex as pycomplex Modified: pypy/trunk/src/pypy/appspace/test/test_complexobject.py ============================================================================== --- pypy/trunk/src/pypy/appspace/test/test_complexobject.py (original) +++ pypy/trunk/src/pypy/appspace/test/test_complexobject.py Tue May 27 15:17:36 2003 @@ -160,13 +160,13 @@ self.assert_(equal(dc, dp)) if not equal(z1c, complex(0,0)): - try: +# try: qc = z0c/z1c qp = z0p/z1p self.assert_(equal(qc, qp)) - except AssertionError: - print "c: (%s/%s) = (%s)" % (z0c, z1c, qc) - print "py:(%s/%s) = (%s)" % (z0p, z1p, qp) +# except AssertionError: +# print "c: (%s/%s) = (%s)" % (z0c, z1c, qc) +# print "py:(%s/%s) = (%s)" % (z0p, z1p, qp) def test_special(self): @@ -195,16 +195,16 @@ self.assert_(equal(mc, mp)) if not equal(z1c, complex(0,0)): - try: +# try: ddc, mmc = divmod(z0c, z1c) self.assert_(ddc*z1c + mmc == z0c) ddp, mmp = divmod(z0p, z1p) # self.assert_(ddp*z1p + mmp == z0p) self.assert_(equal(ddc, ddp)) self.assert_(equal(mmc, mmp)) - except AssertionError: - print "c: divmod(%s,%s) = (%s,%s)" % (z0c, z1c, ddc,mmc) - print "py:divmod(%s,%s) = (%s,%s)" % (z0p, z1p, ddp,mmp) +# except AssertionError: +# print "c: divmod(%s,%s) = (%s,%s)" % (z0c, z1c, ddc,mmc) +# print "py:divmod(%s,%s) = (%s,%s)" % (z0p, z1p, ddp,mmp) def test_mod(self): @@ -216,13 +216,13 @@ self.assert_(equal(mc, mp)) if not equal(z1c, complex(0,0)): - try: +# try: rc = z0c%z1c rp = z0p%z1p self.assert_(equal(rc, rp)) - except AssertionError: - print "c: %s%%%s = %s" % (z0c, z1c, rc) - print "py:%s%%%s = %s" % (z0p, z1p, rp) +# except AssertionError: +# print "c: %s%%%s = %s" % (z0c, z1c, rc) +# print "py:%s%%%s = %s" % (z0p, z1p, rp) def test_pow(self): Added: pypy/trunk/src/pypy/appspace/test/testsupport.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/appspace/test/testsupport.py Tue May 27 15:17:36 2003 @@ -0,0 +1,63 @@ +""" +Master version of testsupport.py: copy into any subdirectory of pypy +from which scripts need to be run (typically all of the 'test' subdirs) +so that any test can "import testsupport" to ensure the parent of pypy +is on the sys.path -- so that "import pypy.etc.etc." always works. + +Also, this module exposes a member 'TestCase' that is unittest.TestCase +or a subclass thereof supplying extra methods; and a function 'main' +that is unittest.main or the equivalent. + +Furthermore, this module now exposes a member 'objspace' which is +by default class pypy.objspace.trivial.TrivialObjSpace but can be +set to use another objectspace instead; this allows tests to run +under different objectspaces without needing to edit their sources. + +For this setting, use environment variable OBJSPACE and set it to +a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is +also the default if the environment variable is not found or empty +or without any dot in it). + +When run as a script, runs all tests found in files called 'test_*.py' +in the same directory. +""" +import sys, os + +try: + head = this_path = os.path.abspath(__file__) +except NameError: + p = os.path.dirname(sys.argv[0]) + if not p: + p = os.curdir + head = this_path = os.path.abspath(p) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + sys.path.insert(0, head) + break + +import pypy.interpreter.unittest_w +TestCase = pypy.interpreter.unittest_w.TestCase_w +import unittest +main = unittest.main + +from pypy.interpreter import testtools + +objspace_path = os.environ.get('OBJSPACE') +if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + objspace = pypy.objspace.trivial.TrivialObjSpace +else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + objspace = getattr(objspace_module, objspace_classname) + +if __name__ == '__main__': + runner = unittest.TextTestRunner() + runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0]))) Modified: pypy/trunk/src/pypy/interpreter/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/testsupport.py (original) +++ pypy/trunk/src/pypy/interpreter/test/testsupport.py Tue May 27 15:17:36 2003 @@ -26,7 +26,10 @@ try: head = this_path = os.path.abspath(__file__) except NameError: - head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) + p = os.path.dirname(sys.argv[0]) + if not p: + p = os.curdir + head = this_path = os.path.abspath(p) while 1: head, tail = os.path.split(head) if not tail: Modified: pypy/trunk/src/pypy/module/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/module/test/testsupport.py (original) +++ pypy/trunk/src/pypy/module/test/testsupport.py Tue May 27 15:17:36 2003 @@ -26,7 +26,10 @@ try: head = this_path = os.path.abspath(__file__) except NameError: - head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) + p = os.path.dirname(sys.argv[0]) + if not p: + p = os.curdir + head = this_path = os.path.abspath(p) while 1: head, tail = os.path.split(head) if not tail: Modified: pypy/trunk/src/pypy/objspace/std/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/testsupport.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/testsupport.py Tue May 27 15:17:36 2003 @@ -26,7 +26,10 @@ try: head = this_path = os.path.abspath(__file__) except NameError: - head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) + p = os.path.dirname(sys.argv[0]) + if not p: + p = os.curdir + head = this_path = os.path.abspath(p) while 1: head, tail = os.path.split(head) if not tail: Modified: pypy/trunk/src/pypy/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/testsupport.py (original) +++ pypy/trunk/src/pypy/testsupport.py Tue May 27 15:17:36 2003 @@ -26,7 +26,10 @@ try: head = this_path = os.path.abspath(__file__) except NameError: - head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) + p = os.path.dirname(sys.argv[0]) + if not p: + p = os.curdir + head = this_path = os.path.abspath(p) while 1: head, tail = os.path.split(head) if not tail: From mwh at codespeak.net Tue May 27 15:18:49 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 15:18:49 +0200 (MEST) Subject: [pypy-svn] rev 558 - in pypy/trunk/src/pypy: . appspace/test interpretermodule/test objspace/std objspace/std/test Message-ID: <20030527131849.839245A243@thoth.codespeak.net> Author: mwh Date: Tue May 27 15:18:49 2003 New Revision: 558 Modified: pypy/trunk/src/pypy/appspace/test/__init__.py (props changed) pypy/trunk/src/pypy/appspace/test/testsupport.py (props changed) pypy/trunk/src/pypy/interpreter/testtools.py (props changed) pypy/trunk/src/pypy/module/test/__init__.py (props changed) pypy/trunk/src/pypy/module/test/test_minmax.py (props changed) pypy/trunk/src/pypy/objspace/std/sliceobject_app.py (props changed) pypy/trunk/src/pypy/objspace/std/test/__init__.py (props changed) pypy/trunk/src/pypy/objspace/std/test/test_listobject.py (props changed) pypy/trunk/src/pypy/testall.py (props changed) Log: line endings From arigo at codespeak.net Tue May 27 15:23:01 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 15:23:01 +0200 (MEST) Subject: [pypy-svn] rev 559 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527132301.968BB5A243@thoth.codespeak.net> Author: arigo Date: Tue May 27 15:23:01 2003 New Revision: 559 Modified: pypy/trunk/src/pypy/objspace/std/instmethobject.py Log: fix Modified: pypy/trunk/src/pypy/objspace/std/instmethobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/instmethobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/instmethobject.py Tue May 27 15:23:01 2003 @@ -22,9 +22,9 @@ def instmeth_call(space, w_instmeth, w_arguments, w_keywords): - w_ret = space.call(self.w_im_func, - space.wrap((space.add(space.newtuple([self.w_im_self]),space.unwrap(w_arguments)), - w_keywords) + w_args = space.add(space.newtuple([self.w_im_self]), + w_arguments) + w_ret = space.call(self.w_im_func, w_args, w_keywords) return w_ret StdObjSpace.call.register(instmeth_call, W_InstMeth, W_ANY, W_ANY) From alex at codespeak.net Tue May 27 15:38:41 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 15:38:41 +0200 (MEST) Subject: [pypy-svn] rev 560 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030527133841.574295A243@thoth.codespeak.net> Author: alex Date: Tue May 27 15:38:41 2003 New Revision: 560 Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Log: removed errors (8 failures out of 12 remain) Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_interpreter.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Tue May 27 15:38:41 2003 @@ -1,19 +1,30 @@ -import unittest -import support +import testsupport -class TestInterpreter(unittest.TestCase): +class TestInterpreter(testsupport.TestCase): - def codetest(self, code, functionname, args): + def codetest(self, source, functionname, args): """Compile and run the given code string, and then call its function named by 'functionname' with arguments 'args'.""" - from pypy.interpreter import baseobjspace, executioncontext, appfile + from pypy.interpreter import baseobjspace, executioncontext, pyframe + space = self.space - bytecode = executioncontext.inlinecompile(code) - apphelper = appfile.AppHelper(self.space, bytecode) + compile = space.builtin.compile + w = space.wrap + w_code = compile(w(source), w(''), w('exec'), w(0), w(0)) + + ec = executioncontext.ExecutionContext(space) + + w_tempmodule = space.newmodule(w("__temp__")) + w_glob = space.getattr(w_tempmodule, w("__dict__")) + space.setitem(w_glob, w("__builtins__"), space.w_builtins) + + frame = pyframe.PyFrame(space, space.unwrap(w_code), w_glob, w_glob) + ec.eval_frame(frame) - wrappedargs = [self.space.wrap(arg) for arg in args] + wrappedargs = w([w(arg) for arg in args]) + wrappedfunc = space.getitem(w_glob, w(functionname)) try: - w_output = apphelper.call(functionname, wrappedargs) + w_output = space.call(wrappedfunc, wrappedargs, None) except baseobjspace.OperationError, e: e.print_detailed_traceback(self.space) return '<<<%s>>>' % e.errorstr(self.space) @@ -21,8 +32,7 @@ return self.space.unwrap(w_output) def setUp(self): - from pypy.objspace.trivial import TrivialObjSpace - self.space = TrivialObjSpace() + self.space = testsupport.objspace() def test_trivial(self): x = self.codetest(''' @@ -144,4 +154,4 @@ if __name__ == '__main__': - unittest.main() + testsupport.main() From tismer at codespeak.net Tue May 27 15:40:23 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Tue, 27 May 2003 15:40:23 +0200 (MEST) Subject: [pypy-svn] rev 561 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527134023.4B04E5A243@thoth.codespeak.net> Author: tismer Date: Tue May 27 15:40:22 2003 New Revision: 561 Modified: pypy/trunk/src/pypy/objspace/std/restricted_int.py Log: made restrincted ints work with sequence multiply Modified: pypy/trunk/src/pypy/objspace/std/restricted_int.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/restricted_int.py (original) +++ pypy/trunk/src/pypy/objspace/std/restricted_int.py Tue May 27 15:40:22 2003 @@ -38,7 +38,10 @@ def __mul__(self, other): x = int(self) y = int(other) - return r_int(x * y) + res = x * y + if not isinstance(res, int, long)): + res = r_int(res) + return res __rmul__ = __mul__ def __div__(self, other): @@ -175,7 +178,10 @@ def __mul__(self, other): x = long(self) y = long(other) - return r_uint(x * y) + res = x * y + if not isinstance(res, int, long)): + res = r_uint(res) + return res __rmul__ = __mul__ def __div__(self, other): From arigo at codespeak.net Tue May 27 15:40:47 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 15:40:47 +0200 (MEST) Subject: [pypy-svn] rev 562 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527134047.C09465A243@thoth.codespeak.net> Author: arigo Date: Tue May 27 15:40:47 2003 New Revision: 562 Modified: pypy/trunk/src/pypy/objspace/std/objspace.py Log: using Christian's lists 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:40:47 2003 @@ -74,9 +74,8 @@ return tupleobject.W_TupleObject(list_w) def newlist(self, list_w): - #import listobject - #return listobject.W_ListObject(list_w) - return self.wrap([self.unwrap(w_x) for w_x in list_w]) + import listobject + return listobject.W_ListObject(list_w) def newdict(self, list_pairs_w): import dictobject From tismer at codespeak.net Tue May 27 15:42:50 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Tue, 27 May 2003 15:42:50 +0200 (MEST) Subject: [pypy-svn] rev 563 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527134250.ED26C5A243@thoth.codespeak.net> Author: tismer Date: Tue May 27 15:42:50 2003 New Revision: 563 Modified: pypy/trunk/src/pypy/objspace/std/objspace.py Log: corrected newlist in objspeca.py 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:42:50 2003 @@ -66,6 +66,10 @@ wrappeditems = [self.wrap(item) for item in x] import tupleobject return tupleobject.W_TupleObject(wrappeditems) + if isinstance(x, list): + wrappeditems = [self.wrap(item) for item in x] + import listobject + return listobject.W_ListObject(wrappeditems) import cpythonobject return cpythonobject.W_CPythonObject(x) From tismer at codespeak.net Tue May 27 15:44:28 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Tue, 27 May 2003 15:44:28 +0200 (MEST) Subject: [pypy-svn] rev 564 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527134428.161AF5A243@thoth.codespeak.net> Author: tismer Date: Tue May 27 15:44:27 2003 New Revision: 564 Modified: pypy/trunk/src/pypy/objspace/std/restricted_int.py Log: typo in restricted:int Modified: pypy/trunk/src/pypy/objspace/std/restricted_int.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/restricted_int.py (original) +++ pypy/trunk/src/pypy/objspace/std/restricted_int.py Tue May 27 15:44:27 2003 @@ -39,7 +39,7 @@ x = int(self) y = int(other) res = x * y - if not isinstance(res, int, long)): + if not isinstance(res, (int, long)): res = r_int(res) return res __rmul__ = __mul__ @@ -179,7 +179,7 @@ x = long(self) y = long(other) res = x * y - if not isinstance(res, int, long)): + if not isinstance(res, (int, long)): res = r_uint(res) return res __rmul__ = __mul__ From arigo at codespeak.net Tue May 27 15:47:31 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 15:47:31 +0200 (MEST) Subject: [pypy-svn] rev 565 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527134731.8E8A25A243@thoth.codespeak.net> Author: arigo Date: Tue May 27 15:47:31 2003 New Revision: 565 Modified: pypy/trunk/src/pypy/objspace/std/instmethobject.py (props changed) Log: fixeol From tomek at codespeak.net Tue May 27 15:50:30 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 15:50:30 +0200 (MEST) Subject: [pypy-svn] rev 566 - in pypy/trunk/src/pypy/module: . test Message-ID: <20030527135030.6FCE35A259@thoth.codespeak.net> Author: tomek Date: Tue May 27 15:50:30 2003 New Revision: 566 Added: pypy/trunk/src/pypy/module/test/test_funtional.py Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: small changes 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:50:30 2003 @@ -5,7 +5,10 @@ def map(function, *collections): if len(collections) == 1: #it's the most common case, so make it faster - return [function(x) for x in collections[0]] + if function is None: + return collections[0] + else: + return [function(x) for x in collections[0]] else: res = [] idx = 0 @@ -20,7 +23,10 @@ elem = None args.append(elem) if cont: - res.append(function(*args)) + if function is None: + res.append(tuple(args)) + else: + res.append(function(*args)) else: return res idx = idx + 1 @@ -60,15 +66,16 @@ return res -def reduce(function, list, initial = None): - if initial is None: +def reduce(function, list, *initialt): + if initialt: + initial, = initialt + idx = 0 + else: try: initial = list[0] except IndexError: raise TypeError, "reduce() of empty sequence with no initial value" idx = 1 - else: - idx = 0 while 1: try: initial = function(initial, list[idx]) Added: pypy/trunk/src/pypy/module/test/test_funtional.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/test_funtional.py Tue May 27 15:50:30 2003 @@ -0,0 +1,43 @@ +import testsupport +from pypy.module.builtin_app import map, filter, reduce, zip + +class TestMap(testsupport.TestCase): + + def test_map_identity1(self): + a = ['1', 2, 3, 'b', None] + b = a[:] + self.assertEqual(map(lambda x: x, a), a) + self.assertEqual(a, b) + + def test_map_None1(self): + a = ['1', 2, 3, 'b', None] + b = a[:] + self.assertEqual(map(None, a), a) + self.assertEqual(a, b) + + def test_map_badoperation(self): + a = ['1', 2, 3, 'b', None] + self.assertRaises(TypeError, map, lambda x: x+1, a) + + def test_map_multiply_identity(self): + a = ['1', 2, 3, 'b', None] + b = [ 2, 3, 4, 5, 6] + self.assertEqual(map(None, a, b), [('1', 2), (2, 3), (3, 4), ('b', 5), (None, 6)]) + + def test_map_multiply(self): + a = [1, 2, 3, 4] + b = [0, 1, 1, 1] + self.assertEqual(map(lambda x, y: x+y, a, b), [1, 2, 4, 5]) + + def test_map_multiply(self): + a = [1, 2, 3, 4, 5] + b = [] + self.assertEqual(map(lambda x, y: x, a, b), a) + +class TestZip(testsupport.TestCase): + pass + +if __name__ == '__main__': + testsupport.main() + + From alex at codespeak.net Tue May 27 15:59:43 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 15:59:43 +0200 (MEST) Subject: [pypy-svn] rev 567 - pypy/trunk/src/pypy/objspace Message-ID: <20030527135943.BF71E5A243@thoth.codespeak.net> Author: alex Date: Tue May 27 15:59:43 2003 New Revision: 567 Modified: pypy/trunk/src/pypy/objspace/trivial.py Log: minor fixes Modified: pypy/trunk/src/pypy/objspace/trivial.py ============================================================================== --- pypy/trunk/src/pypy/objspace/trivial.py (original) +++ pypy/trunk/src/pypy/objspace/trivial.py Tue May 27 15:59:43 2003 @@ -13,6 +13,7 @@ def initialize(self): import __builtin__, types + self.builtin = __builtin__ self.w_builtins.update(__builtin__.__dict__) for n, c in self.w_builtins.iteritems(): if isinstance(c, types.ClassType) and issubclass(c, Exception): @@ -171,6 +172,9 @@ raise NoValue def newfunction(self, code, globals, defaultarguments, closure=None): + assert hasattr(code.co_name) + assert hasattr(code.build_arguments) + assert hasattr(code.eval_code) class nufun(object): def __init__(self, space, code, globals, defaultarguments, closure): self.space = space @@ -215,6 +219,6 @@ return ec.eval_frame(frame) else: try: - return apply(callable, args, kwds) + return apply(callable, args, kwds or {}) except: raise OperationError(*sys.exc_info()[:2]) From alex at codespeak.net Tue May 27 16:00:52 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 16:00:52 +0200 (MEST) Subject: [pypy-svn] rev 568 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030527140052.712C15A243@thoth.codespeak.net> Author: alex Date: Tue May 27 16:00:52 2003 New Revision: 568 Modified: pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Log: the test now runs. Modified: pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py Tue May 27 16:00:52 2003 @@ -1,16 +1,14 @@ -import unittest -import support +import testsupport from pypy.interpreter.pyframe import PyFrame from pypy.interpreter import baseobjspace, executioncontext -from pypy.objspace.trivial import TrivialObjSpace -class TestExecutionContext(unittest.TestCase): +class TestExecutionContext(testsupport.TestCase): def test_trivial1(self): # build frame - space = TrivialObjSpace() + space = testsupport.objspace() ec = executioncontext.ExecutionContext(space) bytecode = compile('def f(x): return x+1', '', 'exec').co_consts[0] @@ -24,4 +22,4 @@ if __name__ == '__main__': - unittest.main() + testsupport.main() Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_interpreter.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Tue May 27 16:00:52 2003 @@ -39,29 +39,29 @@ def g(): return 42''', 'g', []) self.assertEquals(x, 42) - def test_trivial_call(self): + def aatest_trivial_call(self): x = self.codetest(''' def f(): return 42 def g(): return f()''', 'g', []) self.assertEquals(x, 42) - def test_trivial_call2(self): + def aatest_trivial_call2(self): x = self.codetest(''' def f(): return 1 + 1 def g(): return f()''', 'g', []) self.assertEquals(x, 2) - def test_print(self): + def aatest_print(self): x = self.codetest(''' def g(): print 10''', 'g', []) self.assertEquals(x, None) - def test_identity(self): + def aatest_identity(self): x = self.codetest(''' def g(x): return x''', 'g', [666]) self.assertEquals(x, 666) - def test_exception(self): + def aatest_exception(self): x = self.codetest(''' def f(): try: @@ -71,7 +71,7 @@ ''', 'f', []) self.assertEquals(x, 1) - def test_finally(self): + def aatest_finally(self): code = ''' def f(a): try: @@ -84,14 +84,14 @@ self.assertEquals(self.codetest(code, 'f', [0]), -12) self.assertEquals(self.codetest(code, 'f', [1]), 1) - def test_raise(self): + def aatest_raise(self): x = self.codetest(''' def f(): raise 1 ''', 'f', []) self.assertEquals(x, '<<>>') - def test_except2(self): + def aatest_except2(self): x = self.codetest(''' def f(): try: @@ -106,7 +106,7 @@ ''', 'f', []) self.assertEquals(x, 5) - def test_except3(self): + def aatest_except3(self): code = ''' def f(v): z = 0 @@ -120,7 +120,7 @@ self.assertEquals(self.codetest(code, 'f', [0]), "infinite result") self.assertEquals(self.codetest(code, 'f', ['x']), "<<>>") - def test_break(self): + def aatest_break(self): code = ''' def f(n): total = 0 @@ -135,7 +135,7 @@ self.assertEquals(self.codetest(code, 'f', [4]), 1+2+3) self.assertEquals(self.codetest(code, 'f', [9]), 1+2+3+4) - def test_continue(self): + def aatest_continue(self): code = ''' def f(n): total = 0 From mwh at codespeak.net Tue May 27 16:06:19 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 16:06:19 +0200 (MEST) Subject: [pypy-svn] rev 569 - in pypy/trunk/src/pypy/appspace: . test Message-ID: <20030527140619.EEBD15A243@thoth.codespeak.net> Author: mwh Date: Tue May 27 16:06:19 2003 New Revision: 569 Modified: pypy/trunk/src/pypy/appspace/cmathmodule.py pypy/trunk/src/pypy/appspace/complexobject.py pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py pypy/trunk/src/pypy/appspace/test/test_complexobject.py Log: Bang on appspace tests. Two still fail, but this is not the time and place to work out why (complexobject.complex.__mod__, sheesh). Modified: pypy/trunk/src/pypy/appspace/cmathmodule.py ============================================================================== --- pypy/trunk/src/pypy/appspace/cmathmodule.py (original) +++ pypy/trunk/src/pypy/appspace/cmathmodule.py Tue May 27 16:06:19 2003 @@ -131,7 +131,7 @@ Return the base-10 logarithm of x.""" l = math.hypot(x.real, x.imag) - imag = math.atan2(x.imag, x.real)/log(10.) + imag = math.atan2(x.imag, x.real)/math.log(10.) real = math.log10(l) return complex(real, imag) Modified: pypy/trunk/src/pypy/appspace/complexobject.py ============================================================================== --- pypy/trunk/src/pypy/appspace/complexobject.py (original) +++ pypy/trunk/src/pypy/appspace/complexobject.py Tue May 27 16:06:19 2003 @@ -146,21 +146,6 @@ return complex(real, imag) - def __d_i_v__(self, other): - # the canonical alternative, which is said to have problems - # with floating point precision... - if other.__class__ != complex: - return complex(self.real/other, self.imag/other) - - a, b = self.real, self.imag - c, d = other.real, other.imag - zr = a*c + b*d - zi = b*c - a*d - n = c*c + d*d - - return complex(zr/n, zi/n) - - def __floordiv__(self, other): return self / other @@ -251,7 +236,9 @@ return self, complex(other) elif other.__class__ == complex: return self, other - + elif typ is types.ComplexType: # cough + return self, complex(other.real, other.imag) + raise TypeError, "number coercion failed" @@ -260,6 +247,7 @@ def __ne__(self, other): + self, other = self.__coerce__(other) if self.real != other.real: return 1 if self.imag != other.imag: Modified: pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py ============================================================================== --- pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py (original) +++ pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py Tue May 27 16:06:19 2003 @@ -16,25 +16,29 @@ import unittest import testsupport -try: - from pypy.appspace import cmathmodule - from pypy.appspace.complexobject import complex as pycomplex -except ImportError: - import cmathmodule - from complexobject import complex as pycomplex +#try: +from pypy.appspace import cmathmodule +from pypy.appspace.complexobject import complex as pycomplex +#except ImportError: +# import cmathmodule +# from pypy.complexobject import complex as pycomplex from test_complexobject import equal, enumerate class TestCMathModule(unittest.TestCase): + def assertAEqual(self, a, b): + if not equal(a, b): + raise self.failureException, '%s ~== %s'%(a, b) + def test_funcs(self): "Compare many functions with CPython." for (z0c, z1c, z0p, z1p) in enumerate(): mc = z0c*z1c mp = z0p*z1p - self.assert_(equal(mc, mp)) + self.assertAEqual(mc, mp) for op in "sqrt acos acosh asin asinh atan atanh cos cosh exp".split(): if op == "atan" and equal(z0c, complex(0,-1)) or equal(z0c, complex(0,1)): @@ -43,13 +47,13 @@ continue op0 = cmath.__dict__[op](z0c) op1 = cmathmodule.__dict__[op](z0p) - self.assert_(equal(op0, op1)) + self.assertAEqual(op0, op1) # check divisions if equal(z0c, complex(0,0)) or equal(z1c, complex(0,0)): continue - self.assert_(equal(mc/z0c, mp/z0p)) - self.assert_(equal(mc/z1c, mp/z1p)) + self.assertAEqual(mc/z0c, mp/z0p) + self.assertAEqual(mc/z1c, mp/z1p) def test_log_log10(self): @@ -57,10 +61,10 @@ for (z0c, z1c, z0p, z1p) in enumerate(): for op in "log log10".split(): - op0 = cmath.__dict__[op](z0c) - op1 = cmathmodule.__dict__[op](z0p) - self.assert_(equal(op0, op1)) - + if z0p != 0: + op0 = cmath.__dict__[op](z0c) + op1 = cmathmodule.__dict__[op](z0p) + self.assertAEqual(op0, op1) if __name__ == "__main__": Modified: pypy/trunk/src/pypy/appspace/test/test_complexobject.py ============================================================================== --- pypy/trunk/src/pypy/appspace/test/test_complexobject.py (original) +++ pypy/trunk/src/pypy/appspace/test/test_complexobject.py Tue May 27 16:06:19 2003 @@ -16,14 +16,10 @@ import sys import types import unittest +import testsupport - -try: - import setpath - from appspace.complexobject import complex as pycomplex -except ImportError: - from complexobject import complex as pycomplex - +from pypy.appspace.complexobject import complex as pycomplex + try: unicode @@ -74,6 +70,10 @@ class TestComplex(unittest.TestCase): + def assertAEqual(self, a, b): + if not equal(a, b): + raise self.failureException, '%s ~== %s'%(a, b) + def test_wrongInit1(self): "Compare wrong init. with CPython." @@ -149,41 +149,37 @@ for (z0c, z1c, z0p, z1p) in enumerate(): mc = z0c*z1c mp = z0p*z1p - self.assert_(equal(mc, mp)) + self.assertAEqual(mc, mp) sc = z0c+z1c sp = z0p+z1p - self.assert_(equal(sc, sp)) + self.assertAEqual(sc, sp) dc = z0c-z1c dp = z0p-z1p - self.assert_(equal(dc, dp)) + self.assertAEqual(dc, dp) if not equal(z1c, complex(0,0)): -# try: - qc = z0c/z1c - qp = z0p/z1p - self.assert_(equal(qc, qp)) -# except AssertionError: -# print "c: (%s/%s) = (%s)" % (z0c, z1c, qc) -# print "py:(%s/%s) = (%s)" % (z0p, z1p, qp) + qc = z0c/z1c + qp = z0p/z1p + self.assertAEqual(qc, qp) def test_special(self): "Compare special methods with CPython." - ass = self.assert_ for (x, y) in [(0,0), (0,1), (1,3.)]: zc = complex(x, y) zp = pycomplex(x, y) - ass(equal(zc, zp), "%s != %s" % (zc, zp)) - ass(equal(-zc, -zp), "%s != %s" % (-zc, -zp)) - ass(equal(+zc, +zp), "%s != %s" % (+zc, +zp)) - ass(equal(abs(zc), abs(zp)), "%s != %s" % (abs(zc), abs(zp))) - ass(equal(zc.conjugate(), zp.conjugate()), "%s != %s" % (zc.conjugate(), zp.conjugate())) - ass(str(zc) == str(zp), "str(%s) != str(%s)" % (str(zc), str(zp))) - ass(hash(zc) == hash(zp), "%s == hash(%s) != hash(%s) == %s" % (hash(zc), zc, zp, hash(zp))) + self.assertAEqual(zc, zp) + self.assertAEqual(-zc, -zp) + self.assertAEqual(+zc, +zp) + self.assertAEqual(abs(zc), abs(zp)) + self.assertAEqual(zc, zp) + self.assertEqual(zc.conjugate(), zp.conjugate()) + self.assertEqual(str(zc), str(zp)) + self.assertEqual(hash(zc), hash(zp)) def test_divmod(self): @@ -192,19 +188,15 @@ for (z0c, z1c, z0p, z1p) in enumerate(): mc = z0c*z1c mp = z0p*z1p - self.assert_(equal(mc, mp)) + self.assertAEqual(mc, mp) if not equal(z1c, complex(0,0)): -# try: - ddc, mmc = divmod(z0c, z1c) - self.assert_(ddc*z1c + mmc == z0c) - ddp, mmp = divmod(z0p, z1p) - # self.assert_(ddp*z1p + mmp == z0p) - self.assert_(equal(ddc, ddp)) - self.assert_(equal(mmc, mmp)) -# except AssertionError: -# print "c: divmod(%s,%s) = (%s,%s)" % (z0c, z1c, ddc,mmc) -# print "py:divmod(%s,%s) = (%s,%s)" % (z0p, z1p, ddp,mmp) + ddc, mmc = divmod(z0c, z1c) + self.assertAEqual(ddc*z1c + mmc, z0c) + ddp, mmp = divmod(z0p, z1p) + self.assertAEqual(ddp*z1p + mmp, z0p) + self.assertAEqual(ddc, ddp) + self.assertAEqual(mmc, mmp) def test_mod(self): @@ -213,16 +205,25 @@ for (z0c, z1c, z0p, z1p) in enumerate(): mc = z0c*z1c mp = z0p*z1p - self.assert_(equal(mc, mp)) + self.assertAEqual(mc, mp) if not equal(z1c, complex(0,0)): -# try: - rc = z0c%z1c - rp = z0p%z1p - self.assert_(equal(rc, rp)) -# except AssertionError: -# print "c: %s%%%s = %s" % (z0c, z1c, rc) -# print "py:%s%%%s = %s" % (z0p, z1p, rp) + rc = z0c%z1c + rp = z0p%z1p + self.assertAEqual(rc, rp) + + def test_div(self): + "Compare mod with CPython." + + for (z0c, z1c, z0p, z1p) in enumerate(): + mc = z0c*z1c + mp = z0p*z1p + self.assertAEqual(mc, mp) + + if not equal(z1c, complex(0,0)): + rc = z0c/z1c + rp = z0p/z1p + self.assertAEqual(rc, rp) def test_pow(self): @@ -232,40 +233,10 @@ if not equal(z0c, 0j) and (z1c.imag != 0.0): pc = z0c**z1c pp = z0p**z1p - assert equal(pc, pp) + self.assertAEqual(pc, pp) pc = z0c**z0c.real pp = z0p**z0p.real - self.assert_(equal(pc, pp)) - - - -# used previously for investigating numerical instabilities - -def dm(self, other): - # a divmod like used in complex. - - div = self/other - print div - div = complex(math.floor(div.real), 0.0) - print div - mod = self - div*other - print mod - return div, mod - - -def testNumericalInstability(): - x, y = -3+1j, -1-3j - print x, y, divmod(x, y) - print x/y - print math.floor((x/y).real)+0j - print - - x, y = complex(-3,1), complex(-1,-3) - print x, y - dm(x, y) - - - + self.assertAEqual(pc, pp) if __name__ == "__main__": unittest.main() From alex at codespeak.net Tue May 27 16:08:11 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 16:08:11 +0200 (MEST) Subject: [pypy-svn] rev 570 - pypy/trunk/src/pypy/objspace Message-ID: <20030527140811.108205A243@thoth.codespeak.net> Author: alex Date: Tue May 27 16:08:10 2003 New Revision: 570 Modified: pypy/trunk/src/pypy/objspace/trivial.py Log: some further fixes Modified: pypy/trunk/src/pypy/objspace/trivial.py ============================================================================== --- pypy/trunk/src/pypy/objspace/trivial.py (original) +++ pypy/trunk/src/pypy/objspace/trivial.py Tue May 27 16:08:10 2003 @@ -13,7 +13,6 @@ def initialize(self): import __builtin__, types - self.builtin = __builtin__ self.w_builtins.update(__builtin__.__dict__) for n, c in self.w_builtins.iteritems(): if isinstance(c, types.ClassType) and issubclass(c, Exception): @@ -21,7 +20,8 @@ self.w_None = None self.w_True = True self.w_False = False - self.w_sys = sys + self.make_builtins() + self.make_sys() # general stuff def wrap(self, x): @@ -172,9 +172,9 @@ raise NoValue def newfunction(self, code, globals, defaultarguments, closure=None): - assert hasattr(code.co_name) - assert hasattr(code.build_arguments) - assert hasattr(code.eval_code) + assert hasattr(code, co_name) + assert hasattr(code, build_arguments) + assert hasattr(code, eval_code) class nufun(object): def __init__(self, space, code, globals, defaultarguments, closure): self.space = space From alex at codespeak.net Tue May 27 16:09:01 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 16:09:01 +0200 (MEST) Subject: [pypy-svn] rev 571 - pypy/trunk/src/pypy/objspace Message-ID: <20030527140901.11D755A243@thoth.codespeak.net> Author: alex Date: Tue May 27 16:09:00 2003 New Revision: 571 Modified: pypy/trunk/src/pypy/objspace/trivial.py Log: yet more fixes Modified: pypy/trunk/src/pypy/objspace/trivial.py ============================================================================== --- pypy/trunk/src/pypy/objspace/trivial.py (original) +++ pypy/trunk/src/pypy/objspace/trivial.py Tue May 27 16:09:00 2003 @@ -172,9 +172,9 @@ raise NoValue def newfunction(self, code, globals, defaultarguments, closure=None): - assert hasattr(code, co_name) - assert hasattr(code, build_arguments) - assert hasattr(code, eval_code) + assert hasattr(code, 'co_name') + assert hasattr(code, 'build_arguments') + assert hasattr(code, 'eval_code') class nufun(object): def __init__(self, space, code, globals, defaultarguments, closure): self.space = space From arigo at codespeak.net Tue May 27 16:14:12 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 16:14:12 +0200 (MEST) Subject: [pypy-svn] rev 572 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527141412.987685A259@thoth.codespeak.net> Author: arigo Date: Tue May 27 16:14:12 2003 New Revision: 572 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: broken, i'm just sending this to Samuele Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Tue May 27 16:14:12 2003 @@ -1,6 +1,7 @@ from pypy.objspace.std.objspace import * from intobject import W_IntObject from sliceobject import W_SliceObject +from instmethobject import W_InstMethObject class W_ListObject(object): @@ -13,6 +14,9 @@ reprlist = [repr(w_item) for w_item in w_self.wrappeditems] return "%s(%s)" % (w_self.__class__.__name__, ', '.join(reprlist)) +### def append(w_self): +### .:. + def list_unwrap(space, w_list): items = [space.unwrap(w_item) for w_item in w_list.wrappeditems] @@ -85,3 +89,9 @@ # upto here, lists are nearly identical to tuples. # XXX have to add over-allocation! + +###def getattr_list(space, w_list, w_attr): +### if space.is_true(space.eq(w_attr, space.wrap('append'))): +### ... +### return W_InstMethObject(w_list, w_builtinfn) +### raise FailedToImplement(space.w_AttributeError) From mwh at codespeak.net Tue May 27 16:26:26 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 16:26:26 +0200 (MEST) Subject: [pypy-svn] rev 573 - pypy/trunk/src/goals Message-ID: <20030527142626.46CBE5A259@thoth.codespeak.net> Author: mwh Date: Tue May 27 16:26:26 2003 New Revision: 573 Added: pypy/trunk/src/goals/ pypy/trunk/src/goals/hello_world.py Log: add first, completed, goal Added: pypy/trunk/src/goals/hello_world.py ============================================================================== --- (empty file) +++ pypy/trunk/src/goals/hello_world.py Tue May 27 16:26:26 2003 @@ -0,0 +1,2 @@ +aStr = 'hello world' +print len(aStr) From mwh at codespeak.net Tue May 27 16:31:58 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 16:31:58 +0200 (MEST) Subject: [pypy-svn] rev 574 - pypy/trunk/src/goals Message-ID: <20030527143158.3F0845A259@thoth.codespeak.net> Author: mwh Date: Tue May 27 16:31:58 2003 New Revision: 574 Modified: pypy/trunk/src/goals/ (props changed) Log: set svn:ignore From mwh at codespeak.net Tue May 27 16:40:21 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 16:40:21 +0200 (MEST) Subject: [pypy-svn] rev 575 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527144021.028205B0F3@thoth.codespeak.net> Author: mwh Date: Tue May 27 16:40:21 2003 New Revision: 575 Modified: pypy/trunk/src/pypy/objspace/std/instmethobject.py Log: render importable Modified: pypy/trunk/src/pypy/objspace/std/instmethobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/instmethobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/instmethobject.py Tue May 27 16:40:21 2003 @@ -27,4 +27,4 @@ w_ret = space.call(self.w_im_func, w_args, w_keywords) return w_ret -StdObjSpace.call.register(instmeth_call, W_InstMeth, W_ANY, W_ANY) +StdObjSpace.call.register(instmeth_call, W_InstMethObject, W_ANY, W_ANY) From mwh at codespeak.net Tue May 27 16:48:32 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 16:48:32 +0200 (MEST) Subject: [pypy-svn] rev 576 - pypy/trunk/src/pypy Message-ID: <20030527144832.EAD385A265@thoth.codespeak.net> Author: mwh Date: Tue May 27 16:48:32 2003 New Revision: 576 Modified: pypy/trunk/src/pypy/testall.py Log: add --noappspace option -- appspace isn't changing much at the moment & the tests take ages. Modified: pypy/trunk/src/pypy/testall.py ============================================================================== --- pypy/trunk/src/pypy/testall.py (original) +++ pypy/trunk/src/pypy/testall.py Tue May 27 16:48:32 2003 @@ -16,10 +16,11 @@ sys.path.insert(0, PYPYDIR) break -def find_tests(root): +def find_tests(root, no_appspace=0): testmods = [] def callback(arg, dirname, names): - if os.path.basename(dirname) == 'test': + if ( os.path.basename(dirname) == 'test' + and ((not no_appspace) or dirname.find('appspace') == -1) ): package = dirname[len(PYPYDIR)+1:].replace(os.sep, '.') testfiles = [f[:-3] for f in names if f.startswith('test_') and f.endswith('.py')] @@ -32,8 +33,11 @@ return tl.loadTestsFromNames(testmods) -if __name__ == '__main__': +def main(argv=None): + if argv is None: + argv = sys.argv runner = unittest.TextTestRunner() - runner.run(find_tests(PYPYDIR)) - + runner.run(find_tests(PYPYDIR, '--noappspace' in sys.argv)) +if __name__ == '__main__': + main() From tismer at codespeak.net Tue May 27 16:52:46 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Tue, 27 May 2003 16:52:46 +0200 (MEST) Subject: [pypy-svn] rev 577 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030527145246.0B2A55A265@thoth.codespeak.net> Author: tismer Date: Tue May 27 16:52:45 2003 New Revision: 577 Modified: pypy/trunk/src/pypy/objspace/std/restricted_int.py pypy/trunk/src/pypy/objspace/std/test/test_restricted_int.py Log: corrected r_int to really support sequences, and added tests Modified: pypy/trunk/src/pypy/objspace/std/restricted_int.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/restricted_int.py (original) +++ pypy/trunk/src/pypy/objspace/std/restricted_int.py Tue May 27 16:52:45 2003 @@ -37,11 +37,10 @@ def __mul__(self, other): x = int(self) + if not isinstance(other, (int, long)): + return x * other y = int(other) - res = x * y - if not isinstance(res, (int, long)): - res = r_int(res) - return res + return r_int(x * y) __rmul__ = __mul__ def __div__(self, other): @@ -177,11 +176,10 @@ def __mul__(self, other): x = long(self) + if not isinstance(other, (int, long)): + return x * other y = long(other) - res = x * y - if not isinstance(res, (int, long)): - res = r_uint(res) - return res + return r_uint(x * y) __rmul__ = __mul__ def __div__(self, other): Modified: pypy/trunk/src/pypy/objspace/std/test/test_restricted_int.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_restricted_int.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_restricted_int.py Tue May 27 16:52:45 2003 @@ -16,6 +16,9 @@ self.binary_test(lambda x, y: x - y) def test__mul__(self): self.binary_test(lambda x, y: x * y) + x = 3; y = [2] + self.assertEquals(x*y, r_int(x)*y) + self.assertEquals(y*x, y*r_int(x)) def test__div__(self): self.binary_test(lambda x, y: x // y) def test__mod__(self): @@ -73,6 +76,9 @@ self.binary_test(lambda x, y: x - y) def test__mul__(self): self.binary_test(lambda x, y: x * y) + x = 3; y = [2] + self.assertEquals(x*y, r_uint(x)*y) + self.assertEquals(y*x, y*r_uint(x)) def test__div__(self): self.binary_test(lambda x, y: x // y) def test__mod__(self): From anna at codespeak.net Tue May 27 17:02:51 2003 From: anna at codespeak.net (anna at codespeak.net) Date: Tue, 27 May 2003 17:02:51 +0200 (MEST) Subject: [pypy-svn] rev 578 - pypy/trunk/src/goals Message-ID: <20030527150251.7A59E5A28A@thoth.codespeak.net> Author: anna Date: Tue May 27 17:02:51 2003 New Revision: 578 Added: pypy/trunk/src/goals/stringcomp.py Log: add stringcomp.py Added: pypy/trunk/src/goals/stringcomp.py ============================================================================== --- (empty file) +++ pypy/trunk/src/goals/stringcomp.py Tue May 27 17:02:51 2003 @@ -0,0 +1,17 @@ + +### a trivial program to test strings, lists, functions and methods ### + +def addstr(s1,s2): + return s1 + s2 + +str = "an interesting string" +str2 = 'another::string::xxx::y:aa' +str3 = addstr(str,str2) +arr = [] +for word in str.split(): + if word in str2.split('::'): + arr.append(word) +print ''.join(arr) +print "str + str2 = ", str3 + + From alex at codespeak.net Tue May 27 17:06:27 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 17:06:27 +0200 (MEST) Subject: [pypy-svn] rev 579 - pypy/trunk/src/pypy/module Message-ID: <20030527150627.D461D5A28A@thoth.codespeak.net> Author: alex Date: Tue May 27 17:06:27 2003 New Revision: 579 Modified: pypy/trunk/src/pypy/module/builtin.py Log: added False and True builtin names 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 17:06:27 2003 @@ -15,6 +15,8 @@ # we have None! None = appdata(_b.None) + False = appdata(_b.False) + True = appdata(_b.True) dict = appdata(_b.dict) # XXX temporary tuple = appdata(_b.tuple) # XXX temporary From alex at codespeak.net Tue May 27 17:08:35 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 17:08:35 +0200 (MEST) Subject: [pypy-svn] rev 580 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527150835.D9F935A28A@thoth.codespeak.net> Author: alex Date: Tue May 27 17:08:35 2003 New Revision: 580 Modified: pypy/trunk/src/pypy/interpreter/executioncontext.py Log: tried fixing inline_compile (incomplete and not really working though) Modified: pypy/trunk/src/pypy/interpreter/executioncontext.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/executioncontext.py (original) +++ pypy/trunk/src/pypy/interpreter/executioncontext.py Tue May 27 17:08:35 2003 @@ -150,13 +150,16 @@ # Utilities -def inlinecompile(source, symbol='exec'): +def inlinecompile(source, space, symbol='exec'): """Compile the given 'source' string. This function differs from the built-in compile() because it abuses co_filename to store a copy of the complete source code. This lets OperationError.print_application_traceback() print the actual source line in the traceback.""" - return compile(source, '\n' + source, symbol) + compile = space.builtin.compile + w = space.wrap + return compile(w(source), w('\n%s'%source), w(symbol), w(0), w(0)) + def offset2lineno(c, stopat): tab = c.co_lnotab From alex at codespeak.net Tue May 27 17:08:55 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 17:08:55 +0200 (MEST) Subject: [pypy-svn] rev 581 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030527150855.B96C25A28A@thoth.codespeak.net> Author: alex Date: Tue May 27 17:08:55 2003 New Revision: 581 Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Log: 4 tests out of 4 now passing Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_interpreter.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Tue May 27 17:08:55 2003 @@ -39,19 +39,19 @@ def g(): return 42''', 'g', []) self.assertEquals(x, 42) - def aatest_trivial_call(self): + def test_trivial_call(self): x = self.codetest(''' def f(): return 42 def g(): return f()''', 'g', []) self.assertEquals(x, 42) - def aatest_trivial_call2(self): + def test_trivial_call2(self): x = self.codetest(''' def f(): return 1 + 1 def g(): return f()''', 'g', []) self.assertEquals(x, 2) - def aatest_print(self): + def test_print(self): x = self.codetest(''' def g(): print 10''', 'g', []) self.assertEquals(x, None) From pedronis at codespeak.net Tue May 27 17:11:17 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 17:11:17 +0200 (MEST) Subject: [pypy-svn] rev 582 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527151117.23A925A28A@thoth.codespeak.net> Author: pedronis Date: Tue May 27 17:11:16 2003 New Revision: 582 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py Log: change PyBuiltinCode ctr interface. 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 17:11:16 2003 @@ -17,18 +17,21 @@ class PyBuiltinCode(pycode.PyBaseCode): """The code object implementing a built-in (interpreter-level) hook.""" - def __init__(self, bltinmodule, appmethod): + def __init__(self, func, boundmethod=False): pycode.PyBaseCode.__init__(self) - self.bltinmodule = bltinmodule - self.appmethod = appmethod - co = appmethod.func.func_code - self.co_name = appmethod.func.__name__ + self.func = func + co = func.func_code + self.co_name = func.__name__ self.co_flags = co.co_flags # extract argument names from 'co', # removing 'self' and the 'w_' prefixes - assert co.co_varnames[0] == "self" + if boundmethod: + assert co.co_varnames[0] == "self" + start = 1 + else: + start = 0 argnames = [] - for argname in co.co_varnames[1:co.co_argcount]: + for argname in co.co_varnames[start:co.co_argcount]: assert argname.startswith('w_') argnames.append(argname[2:]) self.co_varnames = tuple(argnames) @@ -41,7 +44,7 @@ for argname in self.co_varnames: w_arg = space.getitem(w_locals, space.wrap(argname)) args.append(w_arg) - w_ret = self.appmethod.func(self.bltinmodule, *args) + w_ret = self.func(*args) return w_ret @@ -65,7 +68,7 @@ w_module = space.newmodule(space.wrap(modulename)) for key, value in self.__class__.__dict__.items(): if isinstance(value, appmethod): - code = PyBuiltinCode(self, value) + code = PyBuiltinCode(value.func.__get__(self),boundmethod=True) w_function = space.newfunction(code, space.w_None, None) space.setattr(w_module, space.wrap(key), w_function) elif isinstance(value, appdata): From arigo at codespeak.net Tue May 27 17:14:18 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 17:14:18 +0200 (MEST) Subject: [pypy-svn] rev 583 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527151418.68E005A28A@thoth.codespeak.net> Author: arigo Date: Tue May 27 17:14:17 2003 New Revision: 583 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py pypy/trunk/src/pypy/objspace/std/tupleobject.py Log: pre-allocating memory for slicing Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Tue May 27 17:14:17 2003 @@ -54,9 +54,9 @@ step = space.unwrap(w_step) slicelength = space.unwrap(w_slicelength) assert slicelength >= 0 - subitems = [] + subitems = [None] * slicelength for i in range(slicelength): - subitems.append(items[start]) + subitems[i] = items[start] start += step return W_ListObject(subitems) Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Tue May 27 17:14:17 2003 @@ -50,9 +50,9 @@ step = space.unwrap(w_step) slicelength = space.unwrap(w_slicelength) assert slicelength >= 0 - subitems = [] + subitems = [None] * slicelength for i in range(slicelength): - subitems.append(items[start]) + subitems[i] = items[start] start += step return W_TupleObject(subitems) From arigo at codespeak.net Tue May 27 17:14:34 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 17:14:34 +0200 (MEST) Subject: [pypy-svn] rev 584 - pypy/trunk/src/pypy/module/test Message-ID: <20030527151434.D852B5A28A@thoth.codespeak.net> Author: arigo Date: Tue May 27 17:14:34 2003 New Revision: 584 Modified: pypy/trunk/src/pypy/module/test/test_funtional.py (props changed) Log: fixeol From pedronis at codespeak.net Tue May 27 17:20:36 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 17:20:36 +0200 (MEST) Subject: [pypy-svn] rev 585 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527152036.6E1C25A07F@thoth.codespeak.net> Author: pedronis Date: Tue May 27 17:20:36 2003 New Revision: 585 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py Log: added make_builtin_func function. 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 17:20:36 2003 @@ -47,7 +47,11 @@ w_ret = self.func(*args) return w_ret - +def make_builtin_func(space,func,boundmethod=False): + code = PyBuiltinCode(func,boundmethod) + w_function = space.newfunction(code, space.w_None, None) + return w_function + class BuiltinModule: __appfile__ = None __helper_appfile__ = None @@ -68,8 +72,7 @@ w_module = space.newmodule(space.wrap(modulename)) for key, value in self.__class__.__dict__.items(): if isinstance(value, appmethod): - code = PyBuiltinCode(value.func.__get__(self),boundmethod=True) - w_function = space.newfunction(code, space.w_None, None) + w_function = make_builtin_func(space,value.func.__get__(self),boundmethod=True) space.setattr(w_module, space.wrap(key), w_function) elif isinstance(value, appdata): w_data = space.wrap(value.data) From alex at codespeak.net Tue May 27 17:21:57 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 17:21:57 +0200 (MEST) Subject: [pypy-svn] rev 586 - in pypy/trunk/src/pypy: interpreter/test objspace Message-ID: <20030527152157.3C9C35A07F@thoth.codespeak.net> Author: alex Date: Tue May 27 17:21:56 2003 New Revision: 586 Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py pypy/trunk/src/pypy/objspace/trivial.py Log: trying to make more tests pass w/trivial objspace Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_interpreter.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Tue May 27 17:21:56 2003 @@ -56,12 +56,12 @@ def g(): print 10''', 'g', []) self.assertEquals(x, None) - def aatest_identity(self): + def test_identity(self): x = self.codetest(''' def g(x): return x''', 'g', [666]) self.assertEquals(x, 666) - def aatest_exception(self): + def test_exception(self): x = self.codetest(''' def f(): try: Modified: pypy/trunk/src/pypy/objspace/trivial.py ============================================================================== --- pypy/trunk/src/pypy/objspace/trivial.py (original) +++ pypy/trunk/src/pypy/objspace/trivial.py Tue May 27 17:21:56 2003 @@ -12,16 +12,24 @@ class TrivialObjSpace(ObjSpace): def initialize(self): - import __builtin__, types - self.w_builtins.update(__builtin__.__dict__) - for n, c in self.w_builtins.iteritems(): - if isinstance(c, types.ClassType) and issubclass(c, Exception): - setattr(self, 'w_' + c.__name__, c) self.w_None = None self.w_True = True self.w_False = False + import __builtin__, types + newstuff = {"False": self.w_False, + "True" : self.w_True, + "None" : self.w_None, + } + for n, c in __builtin__.__dict__.iteritems(): + if isinstance(c, types.ClassType) and issubclass(c, Exception): + w_c = c + setattr(self, 'w_' + c.__name__, w_c) + newstuff[c.__name__] = w_c self.make_builtins() self.make_sys() + # insert these into the newly-made builtins + for key, w_value in newstuff.items(): + self.setitem(self.w_builtins, self.wrap(key), w_value) # general stuff def wrap(self, x): From tomek at codespeak.net Tue May 27 17:26:23 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 17:26:23 +0200 (MEST) Subject: [pypy-svn] rev 587 - in pypy/trunk/src/pypy/module: . test Message-ID: <20030527152623.793345A07F@thoth.codespeak.net> Author: tomek Date: Tue May 27 17:26:23 2003 New Revision: 587 Modified: pypy/trunk/src/pypy/module/builtin_app.py pypy/trunk/src/pypy/module/test/test_funtional.py Log: small changes 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 17:26:23 2003 @@ -80,7 +80,7 @@ try: initial = function(initial, list[idx]) idx = idx + 1 - except: + except IndexError: break return initial Modified: pypy/trunk/src/pypy/module/test/test_funtional.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_funtional.py (original) +++ pypy/trunk/src/pypy/module/test/test_funtional.py Tue May 27 17:26:23 2003 @@ -35,8 +35,37 @@ self.assertEqual(map(lambda x, y: x, a, b), a) class TestZip(testsupport.TestCase): - pass - + def test_one_list(self): + self.assertEqual(zip([1,2,3]), [(1,), (2,), (3,)]) + + def test_three_lists(self): + self.assertEqual(zip([1,2,3], [1,2], [1,2,3]), [(1,1,1), (2,2,2)]) + +class TestReduce(testsupport.TestCase): + def test_None(self): + self.assertRaises(TypeError, reduce, lambda x, y: x+y, [1,2,3], None) + + def test_sum(self): + self.assertEqual(reduce(lambda x, y: x+y, [1,2,3,4], 0), 10) + self.assertEqual(reduce(lambda x, y: x+y, [1,2,3,4]), 10) + + def test_minus(self): + self.assertEqual(reduce(lambda x, y: x-y, [10, 2, 8]), 0) + self.assertEqual(reduce(lambda x, y: x-y, [2, 8], 10), 0) + +class TestFilter(testsupport.TestCase): + def test_None(self): + self.assertEqual(filter(None, ['a', 'b', 1, 0, None]), ['a', 'b', 1]) + + def test_return_type(self): + txt = "This is a test text" + self.assertEqual(filter(None, txt), txt) + tup = ("a", None, 0, [], 1) + self.assertEqual(filter(None, tup), ("a", 1)) + + def test_function(self): + self.assertEqual(filter(lambda x: x != "a", "a small text"), " smll text") + if __name__ == '__main__': testsupport.main() From alex at codespeak.net Tue May 27 17:33:01 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Tue, 27 May 2003 17:33:01 +0200 (MEST) Subject: [pypy-svn] rev 588 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030527153301.032EB5A07F@thoth.codespeak.net> Author: alex Date: Tue May 27 17:33:01 2003 New Revision: 588 Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Log: 6/6 tests now pass w both trivial and std object spaces, 2 are disabled/delayed (renamed to XXXtest_...), others yet untried (named aatest:...), Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_interpreter.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Tue May 27 17:33:01 2003 @@ -21,15 +21,15 @@ frame = pyframe.PyFrame(space, space.unwrap(w_code), w_glob, w_glob) ec.eval_frame(frame) - wrappedargs = w([w(arg) for arg in args]) + wrappedargs = w(args) wrappedfunc = space.getitem(w_glob, w(functionname)) try: w_output = space.call(wrappedfunc, wrappedargs, None) except baseobjspace.OperationError, e: - e.print_detailed_traceback(self.space) - return '<<<%s>>>' % e.errorstr(self.space) + e.print_detailed_traceback(space) + return '<<<%s>>>' % e.errorstr(space) else: - return self.space.unwrap(w_output) + return space.unwrap(w_output) def setUp(self): self.space = testsupport.objspace() @@ -61,7 +61,8 @@ def g(x): return x''', 'g', [666]) self.assertEquals(x, 666) - def test_exception(self): + def XXXtest_exception(self): + """ can't make it run as e has no args; deep bug...? """ x = self.codetest(''' def f(): try: @@ -71,7 +72,7 @@ ''', 'f', []) self.assertEquals(x, 1) - def aatest_finally(self): + def test_finally(self): code = ''' def f(a): try: @@ -84,7 +85,8 @@ self.assertEquals(self.codetest(code, 'f', [0]), -12) self.assertEquals(self.codetest(code, 'f', [1]), 1) - def aatest_raise(self): + def XXXtest_raise(self): + """ depends on being able to import types """ x = self.codetest(''' def f(): raise 1 From tismer at codespeak.net Tue May 27 17:33:03 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Tue, 27 May 2003 17:33:03 +0200 (MEST) Subject: [pypy-svn] rev 589 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030527153303.32FD35A07F@thoth.codespeak.net> Author: tismer Date: Tue May 27 17:33:02 2003 New Revision: 589 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py pypy/trunk/src/pypy/objspace/std/test/test_listobject.py pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py pypy/trunk/src/pypy/objspace/std/tupleobject.py Log: added right multiplication to tuples and lists (with test) Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Tue May 27 17:33:02 2003 @@ -75,6 +75,13 @@ StdObjSpace.add.register(list_add, W_ListObject, W_ListObject) +def list_int_mul(space, w_list, w_int): + items = w_list.wrappeditems + times = w_int.intval + return W_ListObject(items * times) + +StdObjSpace.mul.register(list_int_mul, W_ListObject, W_IntObject) + def list_eq(space, w_list1, w_list2): items1 = w_list1.wrappeditems items2 = w_list2.wrappeditems @@ -90,8 +97,17 @@ # upto here, lists are nearly identical to tuples. # XXX have to add over-allocation! -###def getattr_list(space, w_list, w_attr): -### if space.is_true(space.eq(w_attr, space.wrap('append'))): -### ... -### return W_InstMethObject(w_list, w_builtinfn) -### raise FailedToImplement(space.w_AttributeError) +""" +static PyMethodDef list_methods[] = { + {"append", (PyCFunction)listappend, METH_O, append_doc}, + {"insert", (PyCFunction)listinsert, METH_VARARGS, insert_doc}, + {"extend", (PyCFunction)listextend, METH_O, extend_doc}, + {"pop", (PyCFunction)listpop, METH_VARARGS, pop_doc}, + {"remove", (PyCFunction)listremove, METH_O, remove_doc}, + {"index", (PyCFunction)listindex, METH_O, index_doc}, + {"count", (PyCFunction)listcount, METH_O, count_doc}, + {"reverse", (PyCFunction)listreverse, METH_NOARGS, reverse_doc}, + {"sort", (PyCFunction)listsort, METH_VARARGS, sort_doc}, + {NULL, NULL} /* sentinel */ +}; +""" Modified: pypy/trunk/src/pypy/objspace/std/test/test_listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_listobject.py Tue May 27 17:33:02 2003 @@ -1,95 +1,105 @@ -from __future__ import nested_scopes -import unittest, sys -import testsupport -from pypy.interpreter import unittest_w -from pypy.objspace.std import listobject as tobj -from pypy.objspace.std.objspace import * - - -class TestW_ListObject(unittest_w.TestCase_w): - - def setUp(self): - self.space = StdObjSpace() - - def tearDown(self): - pass - - def test_is_true(self): - w = self.space.wrap - w_list = tobj.W_ListObject([]) - self.assertEqual(self.space.is_true(w_list), False) - w_list = tobj.W_ListObject([w(5)]) - self.assertEqual(self.space.is_true(w_list), True) - w_list = tobj.W_ListObject([w(5), w(3)]) - self.assertEqual(self.space.is_true(w_list), True) - - def test_len(self): - w = self.space.wrap - w_list = tobj.W_ListObject([]) - self.assertEqual_w(self.space.len(w_list), w(0)) - w_list = tobj.W_ListObject([w(5)]) - self.assertEqual_w(self.space.len(w_list), w(1)) - w_list = tobj.W_ListObject([w(5), w(3), w(99)]*111) - self.assertEqual_w(self.space.len(w_list), w(333)) - - def test_getitem(self): - w = self.space.wrap - w_list = tobj.W_ListObject([w(5), w(3)]) - self.assertEqual_w(self.space.getitem(w_list, w(0)), w(5)) - self.assertEqual_w(self.space.getitem(w_list, w(1)), w(3)) - self.assertEqual_w(self.space.getitem(w_list, w(-2)), w(5)) - self.assertEqual_w(self.space.getitem(w_list, w(-1)), w(3)) - self.assertRaises_w(self.space.w_IndexError, - self.space.getitem, w_list, w(2)) - self.assertRaises_w(self.space.w_IndexError, - self.space.getitem, w_list, w(42)) - self.assertRaises_w(self.space.w_IndexError, - self.space.getitem, w_list, w(-3)) - - def test_iter(self): - w = self.space.wrap - w_list = tobj.W_ListObject([w(5), w(3), w(99)]) - w_iter = self.space.iter(w_list) - self.assertEqual_w(self.space.next(w_iter), w(5)) - self.assertEqual_w(self.space.next(w_iter), w(3)) - self.assertEqual_w(self.space.next(w_iter), w(99)) - self.assertRaises(NoValue, self.space.next, w_iter) - self.assertRaises(NoValue, self.space.next, w_iter) - - def test_add(self): - w = self.space.wrap - w_list0 = tobj.W_ListObject([]) - w_list1 = tobj.W_ListObject([w(5), w(3), w(99)]) - w_list2 = tobj.W_ListObject([w(-7)] * 111) - self.assertEqual_w(self.space.add(w_list1, w_list1), - tobj.W_ListObject([w(5), w(3), w(99), - w(5), w(3), w(99)])) - self.assertEqual_w(self.space.add(w_list1, w_list2), - tobj.W_ListObject([w(5), w(3), w(99)] + - [w(-7)] * 111)) - self.assertEqual_w(self.space.add(w_list1, w_list0), w_list1) - self.assertEqual_w(self.space.add(w_list0, w_list2), w_list2) - - def test_getslice(self): - w = self.space.wrap - - def test1(testlist, start, stop, step, expected): - w_slice = self.space.newslice(w(start), w(stop), w(step)) - w_list = tobj.W_ListObject([w(i) for i in testlist]) - w_result = self.space.getitem(w_list, w_slice) - self.assertEqual(self.space.unwrap(w_result), expected) - - for testlist in [[], [5,3,99], list(range(5,555,10))]: - for start in [-2, -1, 0, 1, 10]: - for end in [-1, 0, 2, 999]: - test1(testlist, start, end, 1, testlist[start:end]) - - test1([5,7,1,4], 3, 1, -2, [4,]) - test1([5,7,1,4], 3, 0, -2, [4, 7]) - test1([5,7,1,4], 3, -1, -2, []) - test1([5,7,1,4], -2, 11, 2, [1]) - test1([5,7,1,4], -3, 11, 2, [7, 4]) - test1([5,7,1,4], -5, 11, 2, [5, 1]) - -if __name__ == '__main__': - unittest.main() +from __future__ import nested_scopes +import unittest, sys +import testsupport +from pypy.interpreter import unittest_w +from pypy.objspace.std import listobject as tobj +from pypy.objspace.std.objspace import * + + +class TestW_ListObject(unittest_w.TestCase_w): + + def setUp(self): + self.space = StdObjSpace() + + def tearDown(self): + pass + + def test_is_true(self): + w = self.space.wrap + w_list = tobj.W_ListObject([]) + self.assertEqual(self.space.is_true(w_list), False) + w_list = tobj.W_ListObject([w(5)]) + self.assertEqual(self.space.is_true(w_list), True) + w_list = tobj.W_ListObject([w(5), w(3)]) + self.assertEqual(self.space.is_true(w_list), True) + + def test_len(self): + w = self.space.wrap + w_list = tobj.W_ListObject([]) + self.assertEqual_w(self.space.len(w_list), w(0)) + w_list = tobj.W_ListObject([w(5)]) + self.assertEqual_w(self.space.len(w_list), w(1)) + w_list = tobj.W_ListObject([w(5), w(3), w(99)]*111) + self.assertEqual_w(self.space.len(w_list), w(333)) + + def test_mul(self): + # only testing right mul at the moment + w = self.space.wrap + arg = w(2) + n = 3 + w_lis = tobj.W_ListObject([arg]) + w_lis3 = tobj.W_ListObject([arg]*n) + w_res = self.space.mul(w_lis, w(n)) + self.assertEqual_w(w_lis3, w_res) + + def test_getitem(self): + w = self.space.wrap + w_list = tobj.W_ListObject([w(5), w(3)]) + self.assertEqual_w(self.space.getitem(w_list, w(0)), w(5)) + self.assertEqual_w(self.space.getitem(w_list, w(1)), w(3)) + self.assertEqual_w(self.space.getitem(w_list, w(-2)), w(5)) + self.assertEqual_w(self.space.getitem(w_list, w(-1)), w(3)) + self.assertRaises_w(self.space.w_IndexError, + self.space.getitem, w_list, w(2)) + self.assertRaises_w(self.space.w_IndexError, + self.space.getitem, w_list, w(42)) + self.assertRaises_w(self.space.w_IndexError, + self.space.getitem, w_list, w(-3)) + + def test_iter(self): + w = self.space.wrap + w_list = tobj.W_ListObject([w(5), w(3), w(99)]) + w_iter = self.space.iter(w_list) + self.assertEqual_w(self.space.next(w_iter), w(5)) + self.assertEqual_w(self.space.next(w_iter), w(3)) + self.assertEqual_w(self.space.next(w_iter), w(99)) + self.assertRaises(NoValue, self.space.next, w_iter) + self.assertRaises(NoValue, self.space.next, w_iter) + + def test_add(self): + w = self.space.wrap + w_list0 = tobj.W_ListObject([]) + w_list1 = tobj.W_ListObject([w(5), w(3), w(99)]) + w_list2 = tobj.W_ListObject([w(-7)] * 111) + self.assertEqual_w(self.space.add(w_list1, w_list1), + tobj.W_ListObject([w(5), w(3), w(99), + w(5), w(3), w(99)])) + self.assertEqual_w(self.space.add(w_list1, w_list2), + tobj.W_ListObject([w(5), w(3), w(99)] + + [w(-7)] * 111)) + self.assertEqual_w(self.space.add(w_list1, w_list0), w_list1) + self.assertEqual_w(self.space.add(w_list0, w_list2), w_list2) + + def test_getslice(self): + w = self.space.wrap + + def test1(testlist, start, stop, step, expected): + w_slice = self.space.newslice(w(start), w(stop), w(step)) + w_list = tobj.W_ListObject([w(i) for i in testlist]) + w_result = self.space.getitem(w_list, w_slice) + self.assertEqual(self.space.unwrap(w_result), expected) + + for testlist in [[], [5,3,99], list(range(5,555,10))]: + for start in [-2, -1, 0, 1, 10]: + for end in [-1, 0, 2, 999]: + test1(testlist, start, end, 1, testlist[start:end]) + + test1([5,7,1,4], 3, 1, -2, [4,]) + test1([5,7,1,4], 3, 0, -2, [4, 7]) + test1([5,7,1,4], 3, -1, -2, []) + test1([5,7,1,4], -2, 11, 2, [1]) + test1([5,7,1,4], -3, 11, 2, [7, 4]) + test1([5,7,1,4], -5, 11, 2, [5, 1]) + +if __name__ == '__main__': + unittest.main() Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Tue May 27 17:33:02 2003 @@ -70,6 +70,16 @@ self.assertEqual_w(self.space.add(w_tuple1, w_tuple0), w_tuple1) self.assertEqual_w(self.space.add(w_tuple0, w_tuple2), w_tuple2) + def test_mul(self): + # only testing right mul at the moment + w = self.space.wrap + arg = w(2) + n = 3 + w_tup = tobj.W_TupleObject([arg]) + w_tup3 = tobj.W_TupleObject([arg]*n) + w_res = self.space.mul(w_tup, w(n)) + self.assertEqual_w(w_tup3, w_res) + def test_getslice(self): w = self.space.wrap Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Tue May 27 17:33:02 2003 @@ -71,6 +71,13 @@ StdObjSpace.add.register(tuple_add, W_TupleObject, W_TupleObject) +def tuple_int_mul(space, w_tuple, w_int): + items = w_tuple.wrappeditems + times = w_int.intval + return W_TupleObject(items * times) + +StdObjSpace.mul.register(tuple_int_mul, W_TupleObject, W_IntObject) + def tuple_eq(space, w_tuple1, w_tuple2): items1 = w_tuple1.wrappeditems items2 = w_tuple2.wrappeditems From mwh at codespeak.net Tue May 27 17:35:25 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 17:35:25 +0200 (MEST) Subject: [pypy-svn] rev 590 - pypy/trunk/src/pypy Message-ID: <20030527153525.793685A07F@thoth.codespeak.net> Author: mwh Date: Tue May 27 17:35:25 2003 New Revision: 590 Modified: pypy/trunk/src/pypy/testall.py Log: add some command line processing to include/exclude various tests Modified: pypy/trunk/src/pypy/testall.py ============================================================================== --- pypy/trunk/src/pypy/testall.py (original) +++ pypy/trunk/src/pypy/testall.py Tue May 27 17:35:25 2003 @@ -16,16 +16,17 @@ sys.path.insert(0, PYPYDIR) break -def find_tests(root, no_appspace=0): +def find_tests(root, inc_names=[], exc_names=[]): testmods = [] def callback(arg, dirname, names): - if ( os.path.basename(dirname) == 'test' - and ((not no_appspace) or dirname.find('appspace') == -1) ): - package = dirname[len(PYPYDIR)+1:].replace(os.sep, '.') - testfiles = [f[:-3] for f in names - if f.startswith('test_') and f.endswith('.py')] - for file in testfiles: - testmods.append(package + '.' + file) + if os.path.basename(dirname) == 'test': + parname = os.path.basename(os.path.dirname(dirname)) + if ((not inc_names) or parname in inc_names) and parname not in exc_names: + package = dirname[len(PYPYDIR)+1:].replace(os.sep, '.') + testfiles = [f[:-3] for f in names + if f.startswith('test_') and f.endswith('.py')] + for file in testfiles: + testmods.append(package + '.' + file) os.path.walk(root, callback, None) @@ -36,8 +37,20 @@ def main(argv=None): if argv is None: argv = sys.argv + + inc_names = [] + exc_names = [] + + for arg in argv[1:]: + if arg.startswith('--include='): + inc_names = arg[len('--include='):].split(',') + elif arg.startswith('--exclude='): + exc_names = arg[len('--exclude='):].split(',') + else: + raise Exception, "don't know arg " + arg + runner = unittest.TextTestRunner() - runner.run(find_tests(PYPYDIR, '--noappspace' in sys.argv)) + runner.run(find_tests(PYPYDIR, inc_names, exc_names)) if __name__ == '__main__': main() From mwh at codespeak.net Tue May 27 17:46:30 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 17:46:30 +0200 (MEST) Subject: [pypy-svn] rev 591 - pypy/trunk/src/goals Message-ID: <20030527154630.B7CEF5A07F@thoth.codespeak.net> Author: mwh Date: Tue May 27 17:46:30 2003 New Revision: 591 Added: pypy/trunk/src/goals/dis-goal.py Log: add dis-goal.py Added: pypy/trunk/src/goals/dis-goal.py ============================================================================== --- (empty file) +++ pypy/trunk/src/goals/dis-goal.py Tue May 27 17:46:30 2003 @@ -0,0 +1,2 @@ +import dis +dis.dis(dis.dis) From arigo at codespeak.net Tue May 27 18:05:03 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 18:05:03 +0200 (MEST) Subject: [pypy-svn] rev 595 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527160503.2BC9E5A07F@thoth.codespeak.net> Author: arigo Date: Tue May 27 18:05:02 2003 New Revision: 595 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py Log: fix 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 18:05:02 2003 @@ -35,7 +35,7 @@ assert argname.startswith('w_') argnames.append(argname[2:]) self.co_varnames = tuple(argnames) - self.co_argcount = co.co_argcount - 1 + self.co_argcount = co.co_argcount - start def eval_code(self, space, w_globals, w_locals): # this isn't quite complete: varargs and kwargs are missing From mwh at codespeak.net Tue May 27 18:09:27 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 18:09:27 +0200 (MEST) Subject: [pypy-svn] rev 596 - pypy/trunk/src/pypy/module/test Message-ID: <20030527160927.795A55A07F@thoth.codespeak.net> Author: mwh Date: Tue May 27 18:09:27 2003 New Revision: 596 Modified: pypy/trunk/src/pypy/module/test/test_range.py Log: disable failing test Modified: pypy/trunk/src/pypy/module/test/test_range.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_range.py (original) +++ pypy/trunk/src/pypy/module/test/test_range.py Tue May 27 18:09:27 2003 @@ -36,7 +36,7 @@ def test_range_zerostep(self): self.assertRaises(ValueError, range, 1, 5, 0) - def test_range_float(self): + def XXXtest_range_float(self): "How CPython does it - UGLY, ignored for now." self.assertEqual(range(0.1, 2.0, 1.1), [0, 1]) From mwh at codespeak.net Tue May 27 18:11:17 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 18:11:17 +0200 (MEST) Subject: [pypy-svn] rev 597 - pypy/trunk/src/pypy/module Message-ID: <20030527161117.264565A07F@thoth.codespeak.net> Author: mwh Date: Tue May 27 18:11:16 2003 New Revision: 597 Modified: pypy/trunk/src/pypy/module/builtin.py Log: oops, instantiate exception before raising. 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 18:11:16 2003 @@ -39,8 +39,9 @@ if w_mod is not None: space.setitem(space.w_modules,w_modulename,w_mod) return w_mod + w_exc = space.call_function(space.w_ImportError, w_modulename) raise executioncontext.OperationError( - space.w_ImportError, w_modulename) + space.w_ImportError, w_exc) __import__ = appmethod(__import__) def compile(self, w_str, w_filename, w_startstr, From mwh at codespeak.net Tue May 27 18:12:07 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 18:12:07 +0200 (MEST) Subject: [pypy-svn] rev 598 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030527161207.601865A07F@thoth.codespeak.net> Author: mwh Date: Tue May 27 18:12:06 2003 New Revision: 598 Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Log: update comment about why this fails Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_interpreter.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Tue May 27 18:12:06 2003 @@ -62,7 +62,7 @@ self.assertEquals(x, 666) def XXXtest_exception(self): - """ can't make it run as e has no args; deep bug...? """ + """ exception raising currently broken """ x = self.codetest(''' def f(): try: From mwh at codespeak.net Tue May 27 18:12:51 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 18:12:51 +0200 (MEST) Subject: [pypy-svn] rev 599 - pypy/trunk/src/pypy/interpreter Message-ID: <20030527161251.C2F9B5A07F@thoth.codespeak.net> Author: mwh Date: Tue May 27 18:12:51 2003 New Revision: 599 Modified: pypy/trunk/src/pypy/interpreter/interactive.py Log: I thought tismer had fixed this module up. Anyway, this seems to work, ish. Modified: pypy/trunk/src/pypy/interpreter/interactive.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/interactive.py (original) +++ pypy/trunk/src/pypy/interpreter/interactive.py Tue May 27 18:12:51 2003 @@ -31,7 +31,10 @@ code.InteractiveConsole.interact(self, banner) def runcode(self, code): - frame = pyframe.PyFrame(self.space, code, + from pypy.interpreter import pycode + r = pycode.PyByteCode() + r._from_code(code) + frame = pyframe.PyFrame(self.space, r, self.w_globals, self.w_globals) try: self.ec.eval_frame(frame) From mwh at codespeak.net Tue May 27 18:13:40 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 18:13:40 +0200 (MEST) Subject: [pypy-svn] rev 600 - pypy/trunk/src/pypy/module Message-ID: <20030527161340.EA04F5A07F@thoth.codespeak.net> Author: mwh Date: Tue May 27 18:13:40 2003 New Revision: 600 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: comment out debuggin print? anyway, it was annoying me. revision 600, woohoo! 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 18:13:40 2003 @@ -30,7 +30,7 @@ else: return res idx = idx + 1 - print idx + #print idx def filter(function, collection): res = [] From arigo at codespeak.net Tue May 27 18:15:51 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 18:15:51 +0200 (MEST) Subject: [pypy-svn] rev 601 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527161551.34A905A07F@thoth.codespeak.net> Author: arigo Date: Tue May 27 18:15:50 2003 New Revision: 601 Modified: pypy/trunk/src/pypy/objspace/std/boolobject.py pypy/trunk/src/pypy/objspace/std/cpythonobject.py pypy/trunk/src/pypy/objspace/std/dictobject.py pypy/trunk/src/pypy/objspace/std/floatobject.py pypy/trunk/src/pypy/objspace/std/funcobject.py pypy/trunk/src/pypy/objspace/std/instmethobject.py pypy/trunk/src/pypy/objspace/std/intobject.py pypy/trunk/src/pypy/objspace/std/iterobject.py pypy/trunk/src/pypy/objspace/std/listobject.py pypy/trunk/src/pypy/objspace/std/longobject.py pypy/trunk/src/pypy/objspace/std/moduleobject.py pypy/trunk/src/pypy/objspace/std/noneobject.py pypy/trunk/src/pypy/objspace/std/objspace.py pypy/trunk/src/pypy/objspace/std/sliceobject.py pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/tupleobject.py Log: BROKEN, we are changing a hell lot of things Modified: pypy/trunk/src/pypy/objspace/std/boolobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/boolobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/boolobject.py Tue May 27 18:15:50 2003 @@ -1,10 +1,11 @@ from pypy.objspace.std.objspace import * -class W_BoolObject: +class W_BoolObject(W_Object): delegate_once = {} - def __init__(w_self, boolval): # please pass in a real bool, not an int + def __init__(w_self, space, boolval):# please pass in a real bool, not an int + W_Object.__init__(w_self, space) w_self.boolval = boolval def __eq__(w_self, w_other): Modified: pypy/trunk/src/pypy/objspace/std/cpythonobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/cpythonobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/cpythonobject.py Tue May 27 18:15:50 2003 @@ -2,12 +2,13 @@ from stringobject import W_StringObject import sys, operator, types -class W_CPythonObject: +class W_CPythonObject(W_Object): "This class wraps an arbitrary CPython object." delegate_once = {} - def __init__(w_self, cpyobj): + def __init__(w_self, space, cpyobj): + W_Object.__init__(w_self, space) w_self.cpyobj = cpyobj def __repr__(w_self): 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 18:15:50 2003 @@ -25,11 +25,12 @@ return self.w_value is _NoValueInCell -class W_DictObject: +class W_DictObject(W_Object): delegate_once = {} - def __init__(self, list_pairs_w): - self.data = [ (w_key,Cell(w_value)) for w_key,w_value in list_pairs_w ] + def __init__(w_self, space, list_pairs_w): + W_Object.__init__(w_self, space) + w_self.data = [ (w_key,Cell(w_value)) for w_key,w_value in list_pairs_w ] def non_empties(self): return [ (w_key,cell) for w_key,cell in self.data if not cell.is_empty()] Modified: pypy/trunk/src/pypy/objspace/std/floatobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/floatobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/floatobject.py Tue May 27 18:15:50 2003 @@ -10,12 +10,13 @@ applicationfile = StdObjSpace.AppFile(__name__) -class W_FloatObject: +class W_FloatObject(W_Object): """This is a reimplementation of the CPython "PyFloatObject" it is assumed that the constructor takes a real Python float as an argument""" - def __init__(w_self, floatval): + def __init__(w_self, space, floatval): + W_Object.__init__(w_self, space) w_self.floatval = floatval def float_float(space,w_value): Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/funcobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/funcobject.py Tue May 27 18:15:50 2003 @@ -3,8 +3,9 @@ import pypy.interpreter.pyframe -class W_FuncObject(object): - def __init__(w_self, code, w_globals, w_defaultarguments, w_closure): +class W_FuncObject(W_Object): + def __init__(w_self, space, code, w_globals, w_defaultarguments, w_closure): + W_Object.__init__(w_self, space) w_self.code = code w_self.w_globals = w_globals w_self.w_defaultarguments = w_defaultarguments Modified: pypy/trunk/src/pypy/objspace/std/instmethobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/instmethobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/instmethobject.py Tue May 27 18:15:50 2003 @@ -2,8 +2,9 @@ from pypy.objspace.std.objspace import * -class W_InstMethObject(object): - def __init__(w_self, w_im_self,w_im_func): +class W_InstMethObject(W_Object): + def __init__(w_self, space, w_im_self, w_im_func): + W_Object.__init__(w_self, space) w_self.w_im_self = w_im_self w_self.w_im_func = w_im_func @@ -22,9 +23,9 @@ def instmeth_call(space, w_instmeth, w_arguments, w_keywords): - w_args = space.add(space.newtuple([self.w_im_self]), + w_args = space.add(space.newtuple([w_instmeth.w_im_self]), w_arguments) - w_ret = space.call(self.w_im_func, w_args, w_keywords) + w_ret = space.call(w_instmeth.w_im_func, w_args, w_keywords) return w_ret StdObjSpace.call.register(instmeth_call, W_InstMethObject, W_ANY, W_ANY) Modified: pypy/trunk/src/pypy/objspace/std/intobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/intobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/intobject.py Tue May 27 18:15:50 2003 @@ -20,11 +20,12 @@ RPython, just for test purposes. """ -class W_IntObject: +class W_IntObject(W_Object): delegate_once = {} - def __init__(w_self, intval): + def __init__(w_self, space, intval): + W_Object.__init__(w_self, space) w_self.intval = r_int(intval) def __repr__(w_self): Modified: pypy/trunk/src/pypy/objspace/std/iterobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/iterobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/iterobject.py Tue May 27 18:15:50 2003 @@ -1,12 +1,13 @@ from objspace import * -class W_SeqIterObject: +class W_SeqIterObject(W_Object): delegate_once = {} - def __init__(self, w_seq, index=0): - self.w_seq = w_seq - self.index = index + def __init__(w_self, space, w_seq, index=0): + W_Object.__init__(w_self, space) + w_self.w_seq = w_seq + w_self.index = index def iter_seqiter(space, w_seqiter): Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Tue May 27 18:15:50 2003 @@ -2,20 +2,23 @@ from intobject import W_IntObject from sliceobject import W_SliceObject from instmethobject import W_InstMethObject +from pypy.interpreter.extmodule import make_builtin_func -class W_ListObject(object): +class W_ListObject(W_Object): - def __init__(self, wrappeditems): - self.wrappeditems = wrappeditems # a list of wrapped values + def __init__(w_self, space, wrappeditems): + W_Object.__init__(w_self, space) + w_self.wrappeditems = wrappeditems # a list of wrapped values def __repr__(w_self): """ representation for debugging purposes """ reprlist = [repr(w_item) for w_item in w_self.wrappeditems] return "%s(%s)" % (w_self.__class__.__name__, ', '.join(reprlist)) -### def append(w_self): -### .:. + def append(w_self, w_obj): + w_self.wrappeditems.append(w_obj) + return w_self.space def list_unwrap(space, w_list): @@ -97,6 +100,15 @@ # upto here, lists are nearly identical to tuples. # XXX have to add over-allocation! +def getattr_list(space, w_list, w_attr): + if space.is_true(space.eq(w_attr, space.wrap('append'))): + w_builtinfn = make_builtin_func(space, W_ListObject.append) + return W_InstMethObject(w_list, w_builtinfn) + raise FailedToImplement(space.w_AttributeError) + +StdObjSpace.getattr.register(getattr_list, W_ListObject, W_ANY) + + """ static PyMethodDef list_methods[] = { {"append", (PyCFunction)listappend, METH_O, append_doc}, Modified: pypy/trunk/src/pypy/objspace/std/longobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/longobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/longobject.py Tue May 27 18:15:50 2003 @@ -1,10 +1,11 @@ -from objspace import * +from pypy.objspace.std.objspace import * -class W_LongObject: +class W_LongObject(W_Object): - def __init__(w_self, longval): + def __init__(w_self, space, longval): + W_Object.__init__(w_self, space) w_self.longval = longval def getattr(w_self, space, w_attrname): 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 18:15:50 2003 @@ -1,11 +1,12 @@ -from objspace import * +from pypy.objspace.std.objspace import * from dictobject import W_DictObject -class W_ModuleObject: +class W_ModuleObject(W_Object): delegate_once = {} - def __init__(self, space, w_name): + def __init__(w_self, space, w_name): + W_Object.__init__(w_self, space) w_key_name = space.wrap('__name__') w_key_doc = space.wrap('__doc__') items = [(w_key_name, w_name), Modified: pypy/trunk/src/pypy/objspace/std/noneobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/noneobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/noneobject.py Tue May 27 18:15:50 2003 @@ -1,7 +1,7 @@ from pypy.objspace.std.objspace import * -class W_NoneObject: +class W_NoneObject(W_Object): delegate_once = {} 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 18:15:50 2003 @@ -8,6 +8,12 @@ booltype = bool +class W_Object: + "Parent base class for wrapped objects." + def __init__(w_self, space): + w_self.space = space + + ################################################################## class StdObjSpace(ObjSpace): Modified: pypy/trunk/src/pypy/objspace/std/sliceobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/sliceobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/sliceobject.py Tue May 27 18:15:50 2003 @@ -5,8 +5,9 @@ appfile = AppFile(__name__, ["objspace.std"]) -class W_SliceObject: - def __init__(w_self, w_start, w_stop, w_step): +class W_SliceObject(W_Object): + def __init__(w_self, space, w_start, w_stop, w_step): + W_Object.__init__(w_self, space) w_self.w_start = w_start w_self.w_stop = w_stop w_self.w_step = w_step Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Tue May 27 18:15:50 2003 @@ -1,11 +1,12 @@ -from objspace import * +from pypy.objspace.std.objspace import * from intobject import W_IntObject from sliceobject import W_SliceObject applicationfile = StdObjSpace.AppFile(__name__) -class W_StringObject: - def __init__(w_self, str): +class W_StringObject(W_Object): + def __init__(w_self, space, str): + W_Object.__init__(w_self, space) w_self.value = str def __repr__(w_self): """ representation for debugging purposes """ Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Tue May 27 18:15:50 2003 @@ -3,10 +3,11 @@ from sliceobject import W_SliceObject -class W_TupleObject(object): +class W_TupleObject(W_Object): - def __init__(self, wrappeditems): - self.wrappeditems = wrappeditems # a list of wrapped values + def __init__(w_self, space, wrappeditems): + W_Object.__init__(w_self, space) + w_self.wrappeditems = wrappeditems # a list of wrapped values def __repr__(w_self): """ representation for debugging purposes """ From arigo at codespeak.net Tue May 27 18:26:34 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 18:26:34 +0200 (MEST) Subject: [pypy-svn] rev 602 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030527162634.5C6D15A07F@thoth.codespeak.net> Author: arigo Date: Tue May 27 18:26:33 2003 New Revision: 602 Modified: pypy/trunk/src/pypy/objspace/std/floatobject.py pypy/trunk/src/pypy/objspace/std/intobject.py pypy/trunk/src/pypy/objspace/std/listobject.py pypy/trunk/src/pypy/objspace/std/longobject.py pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Log: merging changes with mwh, hold on... Modified: pypy/trunk/src/pypy/objspace/std/floatobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/floatobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/floatobject.py Tue May 27 18:26:33 2003 @@ -23,7 +23,7 @@ if w_value.__class__ == W_FloatObject: return w_value else: - return W_FloatObject(w_value.floatval) + return W_FloatObject(space, w_value.floatval) StdObjSpace.float.register(float_float, W_FloatObject) @@ -67,7 +67,7 @@ z = x + y except FloatingPointError: raise FailedToImplement(space.w_FloatingPointError, space.wrap("float addition")) - return W_FloatObject(z) + return W_FloatObject(space, z) StdObjSpace.add.register(float_float_add, W_FloatObject, W_FloatObject) @@ -78,7 +78,7 @@ z = x - y except FloatingPointError: raise FailedToImplement(space.w_FloatingPointError, space.wrap("float substraction")) - return W_FloatObject(z) + return W_FloatObject(space, z) StdObjSpace.sub.register(float_float_sub, W_FloatObject, W_FloatObject) @@ -89,7 +89,7 @@ z = x * y except FloatingPointError: raise FailedToImplement(space.w_FloatingPointError, space.wrap("float multiplication")) - return W_FloatObject(z) + return W_FloatObject(space, z) StdObjSpace.mul.register(float_float_mul, W_FloatObject, W_FloatObject) @@ -101,7 +101,7 @@ except FloatingPointError: raise FailedToImplement(space.w_FloatingPointError, space.wrap("float division")) # no overflow - return W_FloatObject(z) + return W_FloatObject(space, z) StdObjSpace.div.register(float_float_div, W_FloatObject, W_FloatObject) @@ -118,7 +118,7 @@ except FloatingPointError: raise FailedToImplement(space.w_FloatingPointError, space.wrap("float division")) - return W_FloatObject(mod) + return W_FloatObject(space, mod) StdObjSpace.mod.register(float_float_mod, W_FloatObject, W_FloatObject) @@ -149,7 +149,8 @@ except FloatingPointError: raise FailedToImplement(space.w_FloatingPointError, space.wrap("float division")) - return space.newtuple([W_FloatObject(floordiv),W_FloatObject(mod)]) + return space.newtuple([W_FloatObject(space, floordiv), + W_FloatObject(space, mod)]) StdObjSpace.divmod.register(float_float_divmod, W_FloatObject, W_FloatObject) @@ -162,12 +163,12 @@ z = x ** y except OverflowError: raise FailedToImplement(space.w_OverflowError, space.wrap("float power")) - return W_FloatObject(z) + return W_FloatObject(space, z) StdObjSpace.pow.register(float_float_pow, W_FloatObject, W_FloatObject) def float_neg(space, w_float1): - return W_FloatObject(w_float1.floatval) + return W_FloatObject(space, w_float1.floatval) StdObjSpace.neg.register(float_neg, W_FloatObject) @@ -175,12 +176,12 @@ if w_float.__class__ == W_FloatObject: return w_float else: - return W_FloatObject(w_float.floatval) + return W_FloatObject(space, w_float.floatval) StdObjSpace.pos.register(float_pos, W_FloatObject) def float_abs(space, w_float): - return W_FloatObject(fabs(w_float.floatval)) + return W_FloatObject(space, fabs(w_float.floatval)) StdObjSpace.abs.register(float_abs, W_FloatObject) @@ -195,7 +196,7 @@ if w_float.__class__ == W_FloatObject: return w_float else: - return W_FloatObject(w_float.floatval) + return W_FloatObject(space, w_float.floatval) StdObjSpace.coerce.register(float_coerce, W_FloatObject) """ Modified: pypy/trunk/src/pypy/objspace/std/intobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/intobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/intobject.py Tue May 27 18:26:33 2003 @@ -34,7 +34,7 @@ def bool_to_int(space, w_bool): - return W_IntObject(int(w_bool.boolval)) + return W_IntObject(space, int(w_bool.boolval)) W_BoolObject.delegate_once[W_IntObject] = bool_to_int @@ -74,7 +74,7 @@ ## ret = 1 ## else: ## ret = 0 -## return W_IntObject(ret) +## return W_IntObject(space, ret) ## ##StdObjSpace.cmp.register(int_int_cmp, W_IntObject, W_IntObject) @@ -122,7 +122,7 @@ x = w_int1.intval if x == -1: x = -2 - return W_IntObject(x) + return W_IntObject(space, x) def int_hash_liberal(space, w_int1): # Armin: unlike CPython we have no need to special-case the value -1 @@ -149,7 +149,7 @@ except OverflowError: raise FailedToImplement(space.w_OverflowError, space.wrap("integer addition")) - return W_IntObject(z) + return W_IntObject(space, z) StdObjSpace.add.register(int_int_add, W_IntObject, W_IntObject) @@ -161,7 +161,7 @@ except OverflowError: raise FailedToImplement(space.w_OverflowError, space.wrap("integer substraction")) - return W_IntObject(z) + return W_IntObject(space, z) StdObjSpace.sub.register(int_int_sub, W_IntObject, W_IntObject) @@ -173,7 +173,7 @@ except OverflowError: raise FailedToImplement(space.w_OverflowError, space.wrap("integer multiplication")) - return W_IntObject(z) + return W_IntObject(space, z) StdObjSpace.mul.register(int_int_mul, W_IntObject, W_IntObject) @@ -188,7 +188,7 @@ except OverflowError: raise FailedToImplement(space.w_OverflowError, space.wrap("integer division")) - return W_IntObject(z) + return W_IntObject(space, z) StdObjSpace.floordiv.register(int_int_floordiv, W_IntObject, W_IntObject) @@ -210,7 +210,7 @@ except OverflowError: raise FailedToImplement(space.w_OverflowError, space.wrap("integer modulo")) - return W_IntObject(z) + return W_IntObject(space, z) StdObjSpace.mod.register(int_int_mod, W_IntObject, W_IntObject) @@ -280,7 +280,7 @@ y = w_int2.intval z = w_int3.intval ret = _impl_int_int_pow(space, x, y, z) - return W_IntObject(ret) + return W_IntObject(space, ret) StdObjSpace.pow.register(int_int_int_pow, W_IntObject, W_IntObject, W_IntObject) @@ -288,7 +288,7 @@ x = w_int1.intval y = w_int2.intval ret = _impl_int_int_pow(space, x, y) - return W_IntObject(ret) + return W_IntObject(space, ret) StdObjSpace.pow.register(int_int_none_pow, W_IntObject, W_IntObject, W_NoneObject) @@ -299,7 +299,7 @@ except OverflowError: raise FailedToImplement(space.w_OverflowError, space.wrap("integer negation")) - return W_IntObject(x) + return W_IntObject(space, x) StdObjSpace.neg.register(int_neg, W_IntObject) @@ -311,7 +311,7 @@ if w_int1.__class__ is W_IntObject: return w_int1 a = w_int1.intval - return W_IntObject(a) + return W_IntObject(space, a) StdObjSpace.pos.register(int_pos, W_IntObject) @@ -331,7 +331,7 @@ def int_invert(space, w_int1): x = w_int1.intval a = ~x - return W_IntObject(a) + return W_IntObject(space, a) StdObjSpace.invert.register(int_invert, W_IntObject) @@ -360,7 +360,7 @@ except OverflowError: raise FailedToImplement(space.w_OverflowError, space.wrap("integer left shift")) - return W_IntObject(c); + return W_IntObject(space, c) StdObjSpace.lshift.register(int_int_lshift, W_IntObject, W_IntObject) @@ -381,7 +381,7 @@ ## please look into pyport.h, how >> should be implemented! ## a = Py_ARITHMETIC_RIGHT_SHIFT(long, a, b); a = a >> b - return W_IntObject(a) + return W_IntObject(space, a) StdObjSpace.rshift.register(int_int_rshift, W_IntObject, W_IntObject) @@ -389,7 +389,7 @@ a = w_int1.intval b = w_int2.intval res = a & b - return W_IntObject(res) + return W_IntObject(space, res) StdObjSpace.and_.register(int_int_and, W_IntObject, W_IntObject) @@ -397,7 +397,7 @@ a = w_int1.intval b = w_int2.intval res = a ^ b - return W_IntObject(res) + return W_IntObject(space, res) StdObjSpace.xor.register(int_int_xor, W_IntObject, W_IntObject) @@ -405,7 +405,7 @@ a = w_int1.intval b = w_int2.intval res = a | b - return W_IntObject(res) + return W_IntObject(space, res) StdObjSpace.or_.register(int_int_or, W_IntObject, W_IntObject) @@ -456,7 +456,7 @@ ret = "0%lo" % x return space.wrap(ret) -#?StdObjSpace.oct.register(int_oct, W_IntObject) +StdObjSpace.oct.register(int_oct, W_IntObject) def int_hex(space, w_int1): x = w_int1.intval @@ -473,4 +473,4 @@ ret = "0x%lx" % x return space.wrap(ret) -#?StdObjSpace.hex.register(int_hex, W_IntObject) +StdObjSpace.hex.register(int_hex, W_IntObject) Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Tue May 27 18:26:33 2003 @@ -34,7 +34,7 @@ def list_len(space, w_list): result = len(w_list.wrappeditems) - return W_IntObject(result) + return W_IntObject(space, result) StdObjSpace.len.register(list_len, W_ListObject) @@ -61,27 +61,27 @@ for i in range(slicelength): subitems[i] = items[start] start += step - return W_ListObject(subitems) + return W_ListObject(space, subitems) StdObjSpace.getitem.register(getitem_list_slice, W_ListObject, W_SliceObject) def list_iter(space, w_list): import iterobject - return iterobject.W_SeqIterObject(w_list) + return iterobject.W_SeqIterObject(space, w_list) StdObjSpace.iter.register(list_iter, W_ListObject) def list_add(space, w_list1, w_list2): items1 = w_list1.wrappeditems items2 = w_list2.wrappeditems - return W_ListObject(items1 + items2) + return W_ListObject(space, items1 + items2) StdObjSpace.add.register(list_add, W_ListObject, W_ListObject) def list_int_mul(space, w_list, w_int): items = w_list.wrappeditems times = w_int.intval - return W_ListObject(items * times) + return W_ListObject(space, items * times) StdObjSpace.mul.register(list_int_mul, W_ListObject, W_IntObject) @@ -103,7 +103,7 @@ def getattr_list(space, w_list, w_attr): if space.is_true(space.eq(w_attr, space.wrap('append'))): w_builtinfn = make_builtin_func(space, W_ListObject.append) - return W_InstMethObject(w_list, w_builtinfn) + return W_InstMethObject(space, w_list, w_builtinfn) raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_list, W_ListObject, W_ANY) Modified: pypy/trunk/src/pypy/objspace/std/longobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/longobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/longobject.py Tue May 27 18:26:33 2003 @@ -22,7 +22,7 @@ z = x + y except OverflowError: raise OperationError(OverflowError, "long addition") - return W_LongObject(z) + return W_LongObject(space, z) def long_long_sub(space, w_long1, w_long2): x = w_long1.longval @@ -31,7 +31,7 @@ z = x - y except Error,e: raise OperationError(Error, e) - return W_LongObject(z) + return W_LongObject(space, z) def long_long_mul(space, w_long1, w_long2): x = w_long1.longval @@ -40,7 +40,7 @@ z = x * y except OverflowError: raise OperationError(OverflowError, "long multiplication") - return W_LongObject(z) + return W_LongObject(space, z) def long_long_floordiv(space, w_long1, w_long2): x = w_long1.longval @@ -50,7 +50,7 @@ except ZeroDivisionError: raise # we have to implement the exception or it will be ignored # no overflow - return W_LongObject(z) + return W_LongObject(space, z) def long_long_truediv(space, w_long1, w_long2): x = w_long1.longval @@ -60,7 +60,7 @@ except ZeroDivisionError: raise # we have to implement the exception or it will be ignored # no overflow - return W_LongObject(z) + return W_LongObject(space, z) if 1L / 2L == 1L // 2L: long_long_div = long_long_floordiv @@ -75,7 +75,7 @@ except ZeroDivisionError: raise # we have to implement the exception or it will be ignored # no overflow - return W_LongObject(z) + return W_LongObject(space, z) def long_long_divmod(space, w_long1, w_long2): x = w_long1.longval @@ -86,7 +86,8 @@ except ZeroDivisionError: raise # we have to implement the exception or it will be ignored # no overflow - return W_TupleObject([z, m]) + return W_TupleObject(space, [W_LongObject(space, z), + W_LongObject(space, m)]) def long_long_pow(space, w_long1,w_long2): x = w_long1.longval @@ -95,7 +96,7 @@ z = x ** y except OverflowError: raise OperationError(OverflowError, "long multiplication") - return W_LongObject(z) + return W_LongObject(space, z) def long_long_long_pow(space, w_long1,w_long2,w_long3): x = w_long1.longval @@ -105,7 +106,7 @@ z = (x ** y) % z except Error,e: raise OperationError(Error(e), "long multiplication") - return W_LongObject(z) + return W_LongObject(space, z) def long_long_lshift(space, w_long1,w_long2): x = w_long1.longval @@ -114,7 +115,7 @@ z = x << y except OverflowError: raise OperationError(OverflowError, "long multiplication") - return W_LongObject(z) + return W_LongObject(space, z) def long_long_rshift(space, w_long1,w_long2): x = w_long1.longval @@ -123,7 +124,7 @@ z = x >> y except OverflowError: raise OperationError(OverflowError, "long multiplication") - return W_LongObject(z) + return W_LongObject(space, z) def long_long_and(space, w_long1,w_long2): x = w_long1.longval @@ -132,7 +133,7 @@ z = x & y except OverflowError: raise OperationError(OverflowError, "long multiplication") - return W_LongObject(z) + return W_LongObject(space, z) def long_long_xor(space, w_long1,w_long2): x = w_long1.longval @@ -141,7 +142,7 @@ z = x ^ y except OverflowError: raise OperationError(OverflowError, "long multiplication") - return W_LongObject(z) + return W_LongObject(space, z) def long_long_or(space, w_long1,w_long2): x = w_long1.longval @@ -150,7 +151,7 @@ z = x | y except OverflowError: raise OperationError(OverflowError, "long multiplication") - return W_LongObject(z) + return W_LongObject(space, z) Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Tue May 27 18:26:33 2003 @@ -16,25 +16,25 @@ def test_is_true(self): w = self.space.wrap - w_tuple = tobj.W_TupleObject([]) + w_tuple = tobj.W_TupleObject(self.space, []) self.assertEqual(self.space.is_true(w_tuple), False) - w_tuple = tobj.W_TupleObject([w(5)]) + w_tuple = tobj.W_TupleObject(self.space, [w(5)]) self.assertEqual(self.space.is_true(w_tuple), True) - w_tuple = tobj.W_TupleObject([w(5), w(3)]) + w_tuple = tobj.W_TupleObject(self.space, [w(5), w(3)]) self.assertEqual(self.space.is_true(w_tuple), True) def test_len(self): w = self.space.wrap - w_tuple = tobj.W_TupleObject([]) + w_tuple = tobj.W_TupleObject(self.space, []) self.assertEqual_w(self.space.len(w_tuple), w(0)) - w_tuple = tobj.W_TupleObject([w(5)]) + w_tuple = tobj.W_TupleObject(self.space, [w(5)]) self.assertEqual_w(self.space.len(w_tuple), w(1)) - w_tuple = tobj.W_TupleObject([w(5), w(3), w(99)]*111) + w_tuple = tobj.W_TupleObject(self.space, [w(5), w(3), w(99)]*111) self.assertEqual_w(self.space.len(w_tuple), w(333)) def test_getitem(self): w = self.space.wrap - w_tuple = tobj.W_TupleObject([w(5), w(3)]) + w_tuple = tobj.W_TupleObject(self.space, [w(5), w(3)]) self.assertEqual_w(self.space.getitem(w_tuple, w(0)), w(5)) self.assertEqual_w(self.space.getitem(w_tuple, w(1)), w(3)) self.assertEqual_w(self.space.getitem(w_tuple, w(-2)), w(5)) @@ -48,7 +48,7 @@ def test_iter(self): w = self.space.wrap - w_tuple = tobj.W_TupleObject([w(5), w(3), w(99)]) + w_tuple = tobj.W_TupleObject(self.space, [w(5), w(3), w(99)]) w_iter = self.space.iter(w_tuple) self.assertEqual_w(self.space.next(w_iter), w(5)) self.assertEqual_w(self.space.next(w_iter), w(3)) @@ -58,15 +58,15 @@ def test_add(self): w = self.space.wrap - w_tuple0 = tobj.W_TupleObject([]) - w_tuple1 = tobj.W_TupleObject([w(5), w(3), w(99)]) - w_tuple2 = tobj.W_TupleObject([w(-7)] * 111) + w_tuple0 = tobj.W_TupleObject(self.space, []) + w_tuple1 = tobj.W_TupleObject(self.space, [w(5), w(3), w(99)]) + w_tuple2 = tobj.W_TupleObject(self.space, [w(-7)] * 111) self.assertEqual_w(self.space.add(w_tuple1, w_tuple1), - tobj.W_TupleObject([w(5), w(3), w(99), - w(5), w(3), w(99)])) + tobj.W_TupleObject(self.space, [w(5), w(3), w(99), + w(5), w(3), w(99)])) self.assertEqual_w(self.space.add(w_tuple1, w_tuple2), - tobj.W_TupleObject([w(5), w(3), w(99)] + - [w(-7)] * 111)) + tobj.W_TupleObject(self.space, [w(5), w(3), w(99)] + + [w(-7)] * 111)) self.assertEqual_w(self.space.add(w_tuple1, w_tuple0), w_tuple1) self.assertEqual_w(self.space.add(w_tuple0, w_tuple2), w_tuple2) @@ -75,8 +75,8 @@ w = self.space.wrap arg = w(2) n = 3 - w_tup = tobj.W_TupleObject([arg]) - w_tup3 = tobj.W_TupleObject([arg]*n) + w_tup = tobj.W_TupleObject(self.space, [arg]) + w_tup3 = tobj.W_TupleObject(self.space, [arg]*n) w_res = self.space.mul(w_tup, w(n)) self.assertEqual_w(w_tup3, w_res) @@ -85,7 +85,7 @@ def test1(testtuple, start, stop, step, expected): w_slice = self.space.newslice(w(start), w(stop), w(step)) - w_tuple = tobj.W_TupleObject([w(i) for i in testtuple]) + w_tuple = tobj.W_TupleObject(self.space, [w(i) for i in testtuple]) w_result = self.space.getitem(w_tuple, w_slice) self.assertEqual(self.space.unwrap(w_result), expected) From mwh at codespeak.net Tue May 27 18:27:10 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 18:27:10 +0200 (MEST) Subject: [pypy-svn] rev 603 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030527162710.1E9F65A07F@thoth.codespeak.net> Author: mwh Date: Tue May 27 18:27:09 2003 New Revision: 603 Modified: pypy/trunk/src/pypy/objspace/std/moduleobject.py pypy/trunk/src/pypy/objspace/std/objspace.py pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py pypy/trunk/src/pypy/objspace/std/test/test_intobject.py pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py pypy/trunk/src/pypy/objspace/std/test/test_listobject.py pypy/trunk/src/pypy/objspace/std/tupleobject.py Log: W_Foo first arg changes 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 18:27:09 2003 @@ -11,7 +11,7 @@ w_key_doc = space.wrap('__doc__') items = [(w_key_name, w_name), (w_key_doc, space.w_None)] - self.w_dict = W_DictObject(items) + self.w_dict = W_DictObject(self.space, items) def getattr_module_any(space, w_module, w_attr): 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 18:27:09 2003 @@ -61,44 +61,44 @@ if isinstance(x, booltype): return self.newbool(x) import intobject - return intobject.W_IntObject(x) + return intobject.W_IntObject(self, x) if isinstance(x, str): import stringobject - return stringobject.W_StringObject(x) + return stringobject.W_StringObject(self, x) #if isinstance(x, float): # import floatobject # return floatobject.W_FloatObject(x) if isinstance(x, tuple): wrappeditems = [self.wrap(item) for item in x] import tupleobject - return tupleobject.W_TupleObject(wrappeditems) + return tupleobject.W_TupleObject(self, wrappeditems) if isinstance(x, list): wrappeditems = [self.wrap(item) for item in x] import listobject - return listobject.W_ListObject(wrappeditems) + return listobject.W_ListObject(self, wrappeditems) import cpythonobject - return cpythonobject.W_CPythonObject(x) + return cpythonobject.W_CPythonObject(self, x) def newtuple(self, list_w): import tupleobject - return tupleobject.W_TupleObject(list_w) + return tupleobject.W_TupleObject(self, list_w) def newlist(self, list_w): import listobject - return listobject.W_ListObject(list_w) + return listobject.W_ListObject(self, list_w) def newdict(self, list_pairs_w): import dictobject - return dictobject.W_DictObject(list_pairs_w) + return dictobject.W_DictObject(self, list_pairs_w) def newslice(self, w_start, w_end, w_step): # w_step may be a real None import sliceobject - return sliceobject.W_SliceObject(w_start, w_end, w_step) + return sliceobject.W_SliceObject(self, w_start, w_end, w_step) def newfunction(self, code, w_globals, w_defaultarguments, w_closure=None): import funcobject - return funcobject.W_FuncObject(code, w_globals, + return funcobject.W_FuncObject(self, code, w_globals, w_defaultarguments, w_closure) def newmodule(self, w_name): @@ -115,7 +115,7 @@ raise OperationError(self.w_ValueError, self.wrap("character code not in range(256)")) import stringobject - return stringobject.W_StringObject(''.join(chars)) + return stringobject.W_StringObject(self, ''.join(chars)) # special multimethods unwrap = MultiMethod('unwrap', 1) # returns an unwrapped object @@ -153,7 +153,7 @@ def default_id(space, w_obj): import intobject - return intobject.W_IntObject(id(w_obj)) + return intobject.W_IntObject(space, id(w_obj)) StdObjSpace.id.register(default_id, W_ANY) Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Tue May 27 18:27:09 2003 @@ -12,9 +12,9 @@ """ representation for debugging purposes """ return "%s(%r)" % (w_self.__class__.__name__, w_self.value) def nonzero(w_self): - return W_IntObject(w_self.value != 0) + return W_IntObject(self.space, w_self.value != 0) def hash(w_self): - return W_IntObject(hash(self.value)) + return W_IntObject(self, hash(self.value)) def str_unwrap(space, w_str): @@ -60,10 +60,10 @@ def getitem_str_int(space, w_str, w_int): - return W_StringObject(w_str.value[w_int.intval]) + return W_StringObject(space, w_str.value[w_int.intval]) StdObjSpace.getitem.register(getitem_str_int, - W_StringObject, W_IntObject) + W_StringObject, W_IntObject) def getitem_str_slice(space, w_str, w_slice): return applicationfile.call(space, "getitem_string_slice", [w_str, w_slice]) @@ -72,7 +72,7 @@ W_StringObject, W_SliceObject) def add_str_str(space, w_left, w_right): - return W_StringObject(w_left.value + w_right.value) + return W_StringObject(space, w_left.value + w_right.value) StdObjSpace.add.register(add_str_str, W_StringObject, W_StringObject) Modified: pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py Tue May 27 18:27:09 2003 @@ -15,14 +15,14 @@ def test_empty(self): space = self.space - d = dobj.W_DictObject([]) + d = dobj.W_DictObject(space, []) self.failIf_w(d) def test_nonempty(self): space = self.space wNone = space.w_None - d = dobj.W_DictObject([(wNone, wNone)]) - self.failUnless(self.space.is_true(d)) + d = dobj.W_DictObject(space, [(wNone, wNone)]) + self.failUnless(space.is_true(d)) i = space.getitem(d, wNone) equal = space.eq(i, wNone) self.failUnless(space.is_true(equal)) @@ -31,7 +31,7 @@ space = self.space wk1 = space.wrap('key') wone = space.wrap(1) - d = dobj.W_DictObject([(space.wrap('zero'),space.wrap(0))]) + d = dobj.W_DictObject(space, [(space.wrap('zero'),space.wrap(0))]) space.setitem(d,wk1,wone) wback = space.getitem(d,wk1) self.assertEqual_w(wback,wone) @@ -39,7 +39,8 @@ def test_delitem(self): space = self.space wk1 = space.wrap('key') - d = dobj.W_DictObject([(space.wrap('zero'),space.wrap(0)), + d = dobj.W_DictObject(space, + [(space.wrap('zero'),space.wrap(0)), (space.wrap('one'),space.wrap(1)), (space.wrap('two'),space.wrap(2))]) space.delitem(d,space.wrap('one')) @@ -50,7 +51,7 @@ def test_cell(self): space = self.space wk1 = space.wrap('key') - d = dobj.W_DictObject([]) + d = dobj.W_DictObject(space, []) w_cell = d.cell(space,wk1) cell = space.unwrap(w_cell) self.failUnless(cell.is_empty()) Modified: pypy/trunk/src/pypy/objspace/std/test/test_intobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_intobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_intobject.py Tue May 27 18:27:09 2003 @@ -42,19 +42,19 @@ def test_repr(self): x = 1 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) result = iobj.int_repr(self.space, f1) self.assertEquals(self.space.unwrap(result), repr(x)) def test_str(self): x = 12345 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) result = iobj.int_str(self.space, f1) self.assertEquals(self.space.unwrap(result), str(x)) def test_hash(self): x = 42 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) result = iobj.int_hash(self.space, f1) self.assertEquals(result.intval, hash(x)) @@ -64,8 +64,8 @@ for x in (-10, -1, 0, 1, 2, 1000, sys.maxint): for y in (-sys.maxint-1, -11, -9, -2, 0, 1, 3, 1111, sys.maxint): for op in optab: - wx = iobj.W_IntObject(x) - wy = iobj.W_IntObject(y) + wx = iobj.W_IntObject(self.space, x) + wy = iobj.W_IntObject(self.space, y) res = getattr(operator, op)(x, y) method = getattr(iobj, 'int_int_%s' % op) myres = method(self.space, wx, wy) @@ -74,28 +74,28 @@ def test_add(self): x = 1 y = 2 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) result = iobj.int_int_add(self.space, f1, f2) self.assertEquals(result.intval, x+y) x = sys.maxint y = 1 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) self.assertEquals(self.space.w_OverflowError, self._unwrap_nonimpl(iobj.int_int_add, self.space, f1, f2)) def test_sub(self): x = 1 y = 2 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) result = iobj.int_int_sub(self.space, f1, f2) self.assertEquals(result.intval, x-y) x = sys.maxint y = -1 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) self.assertEquals(self.space.w_OverflowError, self._unwrap_nonimpl(iobj.int_int_sub, self.space, f1, f2)) @@ -103,14 +103,14 @@ def test_mul(self): x = 2 y = 3 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) result = iobj.int_int_mul(self.space, f1, f2) self.assertEquals(result.intval, x*y) x = -sys.maxint-1 y = -1 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) self.assertEquals(self.space.w_OverflowError, self._unwrap_nonimpl(iobj.int_int_mul, self.space, f1, f2)) @@ -118,22 +118,22 @@ def test_div(self): for i in range(10): res = i//3 - f1 = iobj.W_IntObject(i) - f2 = iobj.W_IntObject(3) + f1 = iobj.W_IntObject(self.space, i) + f2 = iobj.W_IntObject(self.space, 3) result = iobj.int_int_div(self.space, f1, f2) self.assertEquals(result.intval, res) x = -sys.maxint-1 y = -1 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) self.assertEquals(self.space.w_OverflowError, self._unwrap_nonimpl(iobj.int_int_div, self.space, f1, f2)) def test_mod(self): x = 1 y = 2 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) v = iobj.int_int_mod(self.space, f1, f2) self.assertEquals(v.intval, x % y) # not that mod cannot overflow @@ -141,15 +141,15 @@ def test_divmod(self): x = 1 y = 2 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) ret = iobj.int_int_divmod(self.space, f1, f2) v, w = self.space.unwrap(ret) self.assertEquals((v, w), divmod(x, y)) x = -sys.maxint-1 y = -1 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) self.assertEquals(self.space.w_OverflowError, self._unwrap_nonimpl(iobj.int_int_divmod, self.space, f1, f2)) @@ -157,9 +157,9 @@ x = 10 y = 2 z = 13 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) - f3 = iobj.W_IntObject(z) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) + f3 = iobj.W_IntObject(self.space, z) v = iobj.int_int_int_pow(self.space, f1, f2, f3) self.assertEquals(v.intval, pow(x, y, z)) f1, f2, f3 = map(iobj.W_IntObject, (10, -1, 42)) @@ -172,8 +172,8 @@ def test_pow_iin(self): x = 10 y = 2 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) v = iobj.int_int_none_pow(self.space, f1, f2) self.assertEquals(v.intval, x ** y) f1, f2 = map(iobj.W_IntObject, (10, 20)) @@ -185,111 +185,111 @@ def test_neg(self): x = 42 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) v = iobj.int_neg(self.space, f1) self.assertEquals(v.intval, -x) x = -sys.maxint-1 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) self.assertEquals(self.space.w_OverflowError, self._unwrap_nonimpl(iobj.int_neg, self.space, f1)) def test_pos(self): x = 42 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) v = iobj.int_pos(self.space, f1) self.assertEquals(v.intval, +x) def test_abs(self): x = 42 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) v = iobj.int_abs(self.space, f1) self.assertEquals(v.intval, abs(x)) x = -42 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) v = iobj.int_abs(self.space, f1) self.assertEquals(v.intval, abs(x)) x = -sys.maxint-1 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) self.assertEquals(self.space.w_OverflowError, self._unwrap_nonimpl(iobj.int_neg, self.space, f1)) def test_pos(self): x = 42 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) v = iobj.int_invert(self.space, f1) self.assertEquals(v.intval, ~x) def test_lshift(self): x = 12345678 y = 2 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) v = iobj.int_int_lshift(self.space, f1, f2) self.assertEquals(v.intval, x << y) y = self._longshiftresult(x) - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) self.assertEquals(self.space.w_OverflowError, self._unwrap_nonimpl(iobj.int_int_lshift, self.space, f1, f2)) def test_rshift(self): x = 12345678 y = 2 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) v = iobj.int_int_rshift(self.space, f1, f2) self.assertEquals(v.intval, x >> y) def test_and(self): x = 12345678 y = 2 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) v = iobj.int_int_and(self.space, f1, f2) self.assertEquals(v.intval, x & y) def test_xor(self): x = 12345678 y = 2 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) v = iobj.int_int_xor(self.space, f1, f2) self.assertEquals(v.intval, x ^ y) def test_or(self): x = 12345678 y = 2 - f1 = iobj.W_IntObject(x) - f2 = iobj.W_IntObject(y) + f1 = iobj.W_IntObject(self.space, x) + f2 = iobj.W_IntObject(self.space, y) v = iobj.int_int_or(self.space, f1, f2) self.assertEquals(v.intval, x | y) def test_int(self): - f1 = iobj.W_IntObject(1) + f1 = iobj.W_IntObject(self.space, 1) result = iobj.int_int(self.space, f1) self.assertEquals(result, f1) ## def test_long(self): ## x = 1 -## f1 = iobj.W_IntObject(x) +## f1 = iobj.W_IntObject(self.space, x) ## result = iobj.int_long(self.space, f1) ## self.assertEquals(self.space.unwrap(result), long(x)) ## def test_float(self): ## x = 1 -## f1 = iobj.W_IntObject(x) +## f1 = iobj.W_IntObject(self.space, x) ## result = iobj.int_float(self.space, f1) ## self.assertEquals(self.space.unwrap(result), float(x)) def test_oct(self): x = 012345 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) result = iobj.int_oct(self.space, f1) self.assertEquals(self.space.unwrap(result), oct(x)) def test_hex(self): x = 0x12345 - f1 = iobj.W_IntObject(x) + f1 = iobj.W_IntObject(self.space, x) result = iobj.int_hex(self.space, f1) self.assertEquals(self.space.unwrap(result), hex(x)) Modified: pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py Tue May 27 18:27:09 2003 @@ -16,7 +16,7 @@ def test_iter(self): w = self.space.wrap w_tuple = self.space.newtuple([w(5), w(3), w(99)]) - w_iter = iobj.W_SeqIterObject(w_tuple) + w_iter = iobj.W_SeqIterObject(self.space, w_tuple) self.assertEqual_w(self.space.next(w_iter), w(5)) self.assertEqual_w(self.space.next(w_iter), w(3)) self.assertEqual_w(self.space.next(w_iter), w(99)) @@ -25,7 +25,7 @@ def test_emptyiter(self): w_list = self.space.newlist([]) - w_iter = iobj.W_SeqIterObject(w_list) + w_iter = iobj.W_SeqIterObject(self.space, w_list) self.assertRaises(NoValue, self.space.next, w_iter) self.assertRaises(NoValue, self.space.next, w_iter) Modified: pypy/trunk/src/pypy/objspace/std/test/test_listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_listobject.py Tue May 27 18:27:09 2003 @@ -16,20 +16,20 @@ def test_is_true(self): w = self.space.wrap - w_list = tobj.W_ListObject([]) + w_list = tobj.W_ListObject(self.space, []) self.assertEqual(self.space.is_true(w_list), False) - w_list = tobj.W_ListObject([w(5)]) + w_list = tobj.W_ListObject(self.space, [w(5)]) self.assertEqual(self.space.is_true(w_list), True) - w_list = tobj.W_ListObject([w(5), w(3)]) + w_list = tobj.W_ListObject(self.space, [w(5), w(3)]) self.assertEqual(self.space.is_true(w_list), True) def test_len(self): w = self.space.wrap - w_list = tobj.W_ListObject([]) + w_list = tobj.W_ListObject(self.space, []) self.assertEqual_w(self.space.len(w_list), w(0)) - w_list = tobj.W_ListObject([w(5)]) + w_list = tobj.W_ListObject(self.space, [w(5)]) self.assertEqual_w(self.space.len(w_list), w(1)) - w_list = tobj.W_ListObject([w(5), w(3), w(99)]*111) + w_list = tobj.W_ListObject(self.space, [w(5), w(3), w(99)]*111) self.assertEqual_w(self.space.len(w_list), w(333)) def test_mul(self): @@ -37,14 +37,14 @@ w = self.space.wrap arg = w(2) n = 3 - w_lis = tobj.W_ListObject([arg]) - w_lis3 = tobj.W_ListObject([arg]*n) + w_lis = tobj.W_ListObject(self.space, [arg]) + w_lis3 = tobj.W_ListObject(self.space, [arg]*n) w_res = self.space.mul(w_lis, w(n)) self.assertEqual_w(w_lis3, w_res) def test_getitem(self): w = self.space.wrap - w_list = tobj.W_ListObject([w(5), w(3)]) + w_list = tobj.W_ListObject(self.space, [w(5), w(3)]) self.assertEqual_w(self.space.getitem(w_list, w(0)), w(5)) self.assertEqual_w(self.space.getitem(w_list, w(1)), w(3)) self.assertEqual_w(self.space.getitem(w_list, w(-2)), w(5)) @@ -58,7 +58,7 @@ def test_iter(self): w = self.space.wrap - w_list = tobj.W_ListObject([w(5), w(3), w(99)]) + w_list = tobj.W_ListObject(self.space, [w(5), w(3), w(99)]) w_iter = self.space.iter(w_list) self.assertEqual_w(self.space.next(w_iter), w(5)) self.assertEqual_w(self.space.next(w_iter), w(3)) @@ -68,15 +68,15 @@ def test_add(self): w = self.space.wrap - w_list0 = tobj.W_ListObject([]) - w_list1 = tobj.W_ListObject([w(5), w(3), w(99)]) - w_list2 = tobj.W_ListObject([w(-7)] * 111) + w_list0 = tobj.W_ListObject(self.space, []) + w_list1 = tobj.W_ListObject(self.space, [w(5), w(3), w(99)]) + w_list2 = tobj.W_ListObject(self.space, [w(-7)] * 111) self.assertEqual_w(self.space.add(w_list1, w_list1), - tobj.W_ListObject([w(5), w(3), w(99), - w(5), w(3), w(99)])) + tobj.W_ListObject(self.space, [w(5), w(3), w(99), + w(5), w(3), w(99)])) self.assertEqual_w(self.space.add(w_list1, w_list2), - tobj.W_ListObject([w(5), w(3), w(99)] + - [w(-7)] * 111)) + tobj.W_ListObject(self.space, [w(5), w(3), w(99)] + + [w(-7)] * 111)) self.assertEqual_w(self.space.add(w_list1, w_list0), w_list1) self.assertEqual_w(self.space.add(w_list0, w_list2), w_list2) @@ -85,7 +85,7 @@ def test1(testlist, start, stop, step, expected): w_slice = self.space.newslice(w(start), w(stop), w(step)) - w_list = tobj.W_ListObject([w(i) for i in testlist]) + w_list = tobj.W_ListObject(self.space, [w(i) for i in testlist]) w_result = self.space.getitem(w_list, w_slice) self.assertEqual(self.space.unwrap(w_result), expected) Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Tue May 27 18:27:09 2003 @@ -28,7 +28,7 @@ def tuple_len(space, w_tuple): result = len(w_tuple.wrappeditems) - return W_IntObject(result) + return W_IntObject(space, result) StdObjSpace.len.register(tuple_len, W_TupleObject) @@ -55,27 +55,27 @@ for i in range(slicelength): subitems[i] = items[start] start += step - return W_TupleObject(subitems) + return W_TupleObject(space, subitems) StdObjSpace.getitem.register(getitem_tuple_slice, W_TupleObject, W_SliceObject) def tuple_iter(space, w_tuple): import iterobject - return iterobject.W_SeqIterObject(w_tuple) + return iterobject.W_SeqIterObject(space, w_tuple) StdObjSpace.iter.register(tuple_iter, W_TupleObject) def tuple_add(space, w_tuple1, w_tuple2): items1 = w_tuple1.wrappeditems items2 = w_tuple2.wrappeditems - return W_TupleObject(items1 + items2) + return W_TupleObject(space, items1 + items2) StdObjSpace.add.register(tuple_add, W_TupleObject, W_TupleObject) def tuple_int_mul(space, w_tuple, w_int): items = w_tuple.wrappeditems times = w_int.intval - return W_TupleObject(items * times) + return W_TupleObject(space, items * times) StdObjSpace.mul.register(tuple_int_mul, W_TupleObject, W_IntObject) From arigo at codespeak.net Tue May 27 18:28:36 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 18:28:36 +0200 (MEST) Subject: [pypy-svn] rev 604 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527162836.980415A07F@thoth.codespeak.net> Author: arigo Date: Tue May 27 18:28:36 2003 New Revision: 604 Modified: pypy/trunk/src/pypy/objspace/std/objspace.py Log: hmmm... 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 18:28:36 2003 @@ -30,9 +30,9 @@ from noneobject import W_NoneObject from boolobject import W_BoolObject from cpythonobject import W_CPythonObject - self.w_None = W_NoneObject() - self.w_False = W_BoolObject(False) - self.w_True = W_BoolObject(True) + self.w_None = W_NoneObject(self) + self.w_False = W_BoolObject(self, False) + self.w_True = W_BoolObject(self, True) # hack in the exception classes import __builtin__, types newstuff = {"False": self.w_False, @@ -41,7 +41,7 @@ } for n, c in __builtin__.__dict__.iteritems(): if isinstance(c, types.ClassType) and issubclass(c, Exception): - w_c = W_CPythonObject(c) + w_c = W_CPythonObject(self, c) setattr(self, 'w_' + c.__name__, w_c) newstuff[c.__name__] = w_c self.make_builtins() @@ -67,7 +67,7 @@ return stringobject.W_StringObject(self, x) #if isinstance(x, float): # import floatobject - # return floatobject.W_FloatObject(x) + # return floatobject.W_FloatObject(self, x) if isinstance(x, tuple): wrappeditems = [self.wrap(item) for item in x] import tupleobject From arigo at codespeak.net Tue May 27 18:30:52 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 18:30:52 +0200 (MEST) Subject: [pypy-svn] rev 605 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527163052.4C2D15A07F@thoth.codespeak.net> Author: arigo Date: Tue May 27 18:30:51 2003 New Revision: 605 Modified: pypy/trunk/src/pypy/objspace/std/moduleobject.py Log: self -> w_self 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 18:30:51 2003 @@ -11,7 +11,7 @@ w_key_doc = space.wrap('__doc__') items = [(w_key_name, w_name), (w_key_doc, space.w_None)] - self.w_dict = W_DictObject(self.space, items) + w_self.w_dict = W_DictObject(w_self.space, items) def getattr_module_any(space, w_module, w_attr): From arigo at codespeak.net Tue May 27 18:33:58 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 18:33:58 +0200 (MEST) Subject: [pypy-svn] rev 606 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030527163358.7CAB85A07F@thoth.codespeak.net> Author: arigo Date: Tue May 27 18:33:57 2003 New Revision: 606 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py pypy/trunk/src/pypy/objspace/std/test/test_intobject.py Log: things start working again Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Tue May 27 18:33:57 2003 @@ -18,7 +18,7 @@ def append(w_self, w_obj): w_self.wrappeditems.append(w_obj) - return w_self.space + return w_self.space.w_None def list_unwrap(space, w_list): Modified: pypy/trunk/src/pypy/objspace/std/test/test_intobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_intobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_intobject.py Tue May 27 18:33:57 2003 @@ -162,10 +162,10 @@ f3 = iobj.W_IntObject(self.space, z) v = iobj.int_int_int_pow(self.space, f1, f2, f3) self.assertEquals(v.intval, pow(x, y, z)) - f1, f2, f3 = map(iobj.W_IntObject, (10, -1, 42)) + f1, f2, f3 = [iobj.W_IntObject(space, i) for i in (10, -1, 42)] self.assertEquals(self.space.w_TypeError, self._unwrap_except(iobj.int_int_int_pow, self.space, f1, f2, f3)) - f1, f2, f3 = map(iobj.W_IntObject, (10, 5, 0)) + f1, f2, f3 = [iobj.W_IntObject(space, i) for i in (10, 5, 0)] self.assertEquals(self.space.w_ValueError, self._unwrap_except(iobj.int_int_int_pow, self.space, f1, f2, f3)) @@ -176,10 +176,10 @@ f2 = iobj.W_IntObject(self.space, y) v = iobj.int_int_none_pow(self.space, f1, f2) self.assertEquals(v.intval, x ** y) - f1, f2 = map(iobj.W_IntObject, (10, 20)) + f1, f2 = [iobj.W_IntObject(space, i) for i in (10, 20)] self.assertEquals(self.space.w_OverflowError, self._unwrap_nonimpl(iobj.int_int_none_pow, self.space, f1, f2)) - f1, f2 = map(iobj.W_IntObject, (10, -1)) + f1, f2 = [iobj.W_IntObject(space, i) for i in (10, -1)] self.assertEquals(self.space.w_ValueError, self._unwrap_nonimpl(iobj.int_int_none_pow, self.space, f1, f2)) From arigo at codespeak.net Tue May 27 18:34:36 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 18:34:36 +0200 (MEST) Subject: [pypy-svn] rev 607 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030527163436.F15BB5A07F@thoth.codespeak.net> Author: arigo Date: Tue May 27 18:34:36 2003 New Revision: 607 Modified: pypy/trunk/src/pypy/objspace/std/test/test_intobject.py Log: typo Modified: pypy/trunk/src/pypy/objspace/std/test/test_intobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_intobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_intobject.py Tue May 27 18:34:36 2003 @@ -162,10 +162,10 @@ f3 = iobj.W_IntObject(self.space, z) v = iobj.int_int_int_pow(self.space, f1, f2, f3) self.assertEquals(v.intval, pow(x, y, z)) - f1, f2, f3 = [iobj.W_IntObject(space, i) for i in (10, -1, 42)] + f1, f2, f3 = [iobj.W_IntObject(self.space, i) for i in (10, -1, 42)] self.assertEquals(self.space.w_TypeError, self._unwrap_except(iobj.int_int_int_pow, self.space, f1, f2, f3)) - f1, f2, f3 = [iobj.W_IntObject(space, i) for i in (10, 5, 0)] + f1, f2, f3 = [iobj.W_IntObject(self.space, i) for i in (10, 5, 0)] self.assertEquals(self.space.w_ValueError, self._unwrap_except(iobj.int_int_int_pow, self.space, f1, f2, f3)) @@ -176,10 +176,10 @@ f2 = iobj.W_IntObject(self.space, y) v = iobj.int_int_none_pow(self.space, f1, f2) self.assertEquals(v.intval, x ** y) - f1, f2 = [iobj.W_IntObject(space, i) for i in (10, 20)] + f1, f2 = [iobj.W_IntObject(self.space, i) for i in (10, 20)] self.assertEquals(self.space.w_OverflowError, self._unwrap_nonimpl(iobj.int_int_none_pow, self.space, f1, f2)) - f1, f2 = [iobj.W_IntObject(space, i) for i in (10, -1)] + f1, f2 = [iobj.W_IntObject(self.space, i) for i in (10, -1)] self.assertEquals(self.space.w_ValueError, self._unwrap_nonimpl(iobj.int_int_none_pow, self.space, f1, f2)) From tomek at codespeak.net Tue May 27 18:35:18 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 18:35:18 +0200 (MEST) Subject: [pypy-svn] rev 608 - in pypy/trunk/src/pypy/module: . test Message-ID: <20030527163518.F1E565A07F@thoth.codespeak.net> Author: tomek Date: Tue May 27 18:35:18 2003 New Revision: 608 Modified: pypy/trunk/src/pypy/module/builtin.py pypy/trunk/src/pypy/module/builtin_app.py pypy/trunk/src/pypy/module/test/test_builtin.py Log: globals() and locals() built-ins 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 18:35:18 2003 @@ -27,6 +27,19 @@ # return w_res #tuple = appmethod(tuple) + def _actframe(self): + return self.space.getexecutioncontext().framestack.top() + + + def globals(self): + return self._actframe().w_globals + globals = appmethod(globals) + + def locals(self): + return self._actframe().w_locals + locals = appmethod(locals) + + def __import__(self, w_modulename, w_locals, w_globals, w_fromlist): space = self.space try: 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 18:35:18 2003 @@ -145,3 +145,12 @@ if max < i: max = i return max + + +def cmp(x, y): + if x < y: + return -1 + elif x == y: + return 0 + else: + return 1 Modified: pypy/trunk/src/pypy/module/test/test_builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_builtin.py (original) +++ pypy/trunk/src/pypy/module/test/test_builtin.py Tue May 27 18:35:18 2003 @@ -1,4 +1,6 @@ import testsupport +from pypy.module.builtin_app import cmp + class TestBuiltin(testsupport.TestCase): @@ -26,7 +28,14 @@ self.assertWRaises_w(s.w_TypeError, w_chr, w('a')) - + +class TestCmp(testsupport.TestCase): + + def test_cmp(self): + self.failUnless(cmp(9, 9) == 0) + self.failUnless(cmp(0,9) < 0) + self.failUnless(cmp(9,0) > 0) + if __name__ == '__main__': testsupport.main() From arigo at codespeak.net Tue May 27 18:36:15 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 18:36:15 +0200 (MEST) Subject: [pypy-svn] rev 609 - pypy/trunk/src/goals Message-ID: <20030527163615.3B8135A07F@thoth.codespeak.net> Author: arigo Date: Tue May 27 18:36:14 2003 New Revision: 609 Modified: pypy/trunk/src/goals/dis-goal.py (props changed) pypy/trunk/src/goals/hello_world.py (props changed) pypy/trunk/src/goals/stringcomp.py (props changed) Log: fixeol From arigo at codespeak.net Tue May 27 18:52:38 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 18:52:38 +0200 (MEST) Subject: [pypy-svn] rev 610 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030527165238.DBDA45A0BB@thoth.codespeak.net> Author: arigo Date: Tue May 27 18:52:38 2003 New Revision: 610 Added: pypy/trunk/src/pypy/objspace/std/default.py Modified: pypy/trunk/src/pypy/objspace/std/objspace.py pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Log: factored out the default operation implementations added default_contains, iterating over the elements Added: pypy/trunk/src/pypy/objspace/std/default.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/default.py Tue May 27 18:52:38 2003 @@ -0,0 +1,94 @@ +"""Default implementation for some operation.""" + +from pypy.objspace.std.objspace import * + + +# 'eq' and 'ne' fall back to 'is' + +def default_eq(space, w_a, w_b): + return space.is_(w_a, w_b) + +StdObjSpace.eq.register(default_eq, W_ANY, W_ANY) + +def default_ne(space, w_a, w_b): + return space.not_(space.is_(w_a, w_b)) + +StdObjSpace.ne.register(default_ne, W_ANY, W_ANY) + + +# 'id' falls back to the address of the wrapper + +def default_id(space, w_obj): + import intobject + return intobject.W_IntObject(space, id(w_obj)) + +StdObjSpace.id.register(default_id, W_ANY) + + +# this 'not' implementation should be fine for most cases + +def default_not(space, w_obj): + return space.newbool(not space.is_true(w_obj)) + +StdObjSpace.not_.register(default_not, W_ANY) + + +# everything is True unless otherwise specified + +def default_is_true(space, w_obj): + return True + +StdObjSpace.is_true.register(default_is_true, W_ANY) + + +# give objects some default attributes and a default way to complain +# about missing attributes + +def default_getattr(space, w_obj, w_attr): + # XXX build a nicer error message along these lines: + #w_type = space.type(w_obj) + #w_typename = space.getattr(w_type, space.wrap('__name__')) + #... + + # XXX as long as don't have types... + if space.is_true(space.eq(w_attr, space.wrap('__class__'))): + return space.wrap(space.unwrap(w_obj).__class__) + + raise OperationError(space.w_AttributeError, w_attr) + +StdObjSpace.getattr.register(default_getattr, W_ANY, W_ANY) + +def default_setattr(space, w_obj, w_attr, w_value): + raise OperationError(space.w_AttributeError, w_attr) + +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_delattr, W_ANY, W_ANY) + + +# in-place operators fall back to their non-in-place counterpart + +for _name, _symbol, _arity in ObjSpace.MethodTable: + if _name.startswith('inplace_'): + def default_inplace(space, w_1, w_2, baseop=_name[8:]): + op = getattr(space, baseop) + return op(w_1, w_2) + getattr(StdObjSpace, _name).register(default_inplace, W_ANY, W_ANY) + + +# 'contains' falls back to iteration + +def default_contains(space, w_iterable, w_lookfor): + w_iter = space.iter(w_iterable) + while 1: + try: + w_next = space.next(w_iter) + except NoValue: + return space.w_False + if space.is_true(space.eq(w_next, w_lookfor)): + return space.w_True + +StdObjSpace.contains.register(default_contains, W_ANY, 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 18:52:38 2003 @@ -141,60 +141,4 @@ # default implementations of some multimethods for all objects # that don't explicitely override them or that raise FailedToImplement -def default_eq(space, w_a, w_b): - return space.is_(w_a, w_b) - -StdObjSpace.eq.register(default_eq, W_ANY, W_ANY) - -def default_ne(space, w_a, w_b): - return space.not_(space.is_(w_a, w_b)) - -StdObjSpace.ne.register(default_ne, W_ANY, W_ANY) - -def default_id(space, w_obj): - import intobject - return intobject.W_IntObject(space, id(w_obj)) - -StdObjSpace.id.register(default_id, W_ANY) - -def default_not(space, w_obj): - return space.newbool(not space.is_true(w_obj)) - -StdObjSpace.not_.register(default_not, W_ANY) - -def default_is_true(space, w_obj): - return True # everything is True unless otherwise specified - -StdObjSpace.is_true.register(default_is_true, W_ANY) - -def default_getattr(space, w_obj, w_attr): - # XXX build a nicer error message along these lines: - #w_type = space.type(w_obj) - #w_typename = space.getattr(w_type, space.wrap('__name__')) - #... - - # XXX as long as don't have types... - if space.is_true(space.eq(w_attr, space.wrap('__class__'))): - return space.wrap(space.unwrap(w_obj).__class__) - - raise OperationError(space.w_AttributeError, w_attr) - -StdObjSpace.getattr.register(default_getattr, W_ANY, W_ANY) - -def default_setattr(space, w_obj, w_attr, w_value): - raise OperationError(space.w_AttributeError, w_attr) - -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_delattr, W_ANY, W_ANY) - -# add default implementations for in-place operators -for _name, _symbol, _arity in ObjSpace.MethodTable: - if _name.startswith('inplace_'): - def default_inplace(space, w_1, w_2, baseop=_name[8:]): - op = getattr(space, baseop) - return op(w_1, w_2) - getattr(StdObjSpace, _name).register(default_inplace, W_ANY, W_ANY) +import pypy.objspace.std.default Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Tue May 27 18:52:38 2003 @@ -56,6 +56,18 @@ self.assertRaises(NoValue, self.space.next, w_iter) self.assertRaises(NoValue, self.space.next, w_iter) + def test_contains(self): + w = self.space.wrap + w_tuple = tobj.W_TupleObject(self.space, [w(5), w(3), w(99)]) + self.assertEqual_w(self.space.contains(w_tuple, w(5)), + self.space.w_True) + self.assertEqual_w(self.space.contains(w_tuple, w(99)), + self.space.w_True) + self.assertEqual_w(self.space.contains(w_tuple, w(11)), + self.space.w_False) + self.assertEqual_w(self.space.contains(w_tuple, w_tuple), + self.space.w_False) + def test_add(self): w = self.space.wrap w_tuple0 = tobj.W_TupleObject(self.space, []) From tomek at codespeak.net Tue May 27 18:55:49 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Tue, 27 May 2003 18:55:49 +0200 (MEST) Subject: [pypy-svn] rev 611 - pypy/trunk/src/pypy/module Message-ID: <20030527165549.E1B025A0BB@thoth.codespeak.net> Author: tomek Date: Tue May 27 18:55:49 2003 New Revision: 611 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: vars() 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 18:55:49 2003 @@ -154,3 +154,16 @@ return 0 else: return 1 + +def vars(*objectt): + if len(objectt) == 0: + locals() + else: + try: + object, = objectt + except ValueError: + raise TypeError, "vars() takes at most 1 argument (2 given)" + try: + return object.__dict__ + except AttributeError: + raise TypeError, "vars() argument must have __dict__ attribute" From lac at codespeak.net Tue May 27 18:57:35 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Tue, 27 May 2003 18:57:35 +0200 (MEST) Subject: [pypy-svn] rev 612 - pypy/trunk/src/pypy/module Message-ID: <20030527165735.72F765A0BB@thoth.codespeak.net> Author: lac Date: Tue May 27 18:57:35 2003 New Revision: 612 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: New range which doesn't use append. 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 18:57:35 2003 @@ -1,4 +1,3 @@ - def apply(function, args, kwds={}): return function(*args, **kwds) @@ -100,33 +99,46 @@ def range(x, y=None, step=1): "docstring" + if step == 0: + raise ValueError, 'range() arg 3 must not be zero' + if y is None: start = 0 stop = x else: start = x stop = y + + if (stop <= start and step > 0) or (stop >= start and step < 0): + return [] + else: + howmany = abs((stop - start)/step) + if abs(step) != 1: + howmany += 1 + + if howmany == 0: + return [] + else: + arr = [None] * int(howmany) - arr = [] i = start - if step == 0: - raise ValueError, 'range() arg 3 must not be zero' - elif step > 0: - while i < stop: - arr.append(i) - i += step - else: - while i > stop: - arr.append(i) - i += step + n = 0 + while n < howmany: + arr[n] = i + i += step + n += 1 return arr def min(*arr): "docstring" - if not len(arr): - raise TypeError, 'min/max() takes exactly 1 argument (0 given)' + if not arr: + raise TypeError, 'min() takes at least one argument' + + if len(arr) == 1: + arr = arr[0] + min = arr[0] for i in arr: @@ -137,8 +149,11 @@ def max(*arr): "docstring" - if not len(arr): - raise TypeError, 'min/max() takes exactly 1 argument (0 given)' + if not arr: + raise TypeError, 'max() takes at least one argument' + + if len(arr) == 1: + arr = arr[0] max = arr[0] for i in arr: From lac at codespeak.net Tue May 27 19:01:24 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Tue, 27 May 2003 19:01:24 +0200 (MEST) Subject: [pypy-svn] rev 613 - pypy/trunk/src/pypy/module/test Message-ID: <20030527170124.96A9A5A0BB@thoth.codespeak.net> Author: lac Date: Tue May 27 19:01:21 2003 New Revision: 613 Modified: pypy/trunk/src/pypy/module/test/test_range.py Log: New range test for the new range that does not use append Modified: pypy/trunk/src/pypy/module/test/test_range.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_range.py (original) +++ pypy/trunk/src/pypy/module/test/test_range.py Tue May 27 19:01:21 2003 @@ -9,10 +9,16 @@ def tearDown(self): pass + def test_range_toofew(self): + self.assertRaises(TypeError, range) + + def test_range_toomany(self): + self.assertRaises(TypeError, range, 1, 2, 3, 4) + def test_range_one(self): self.assertEqual(range(1), [0]) - def test_range_none(self): + def test_range_zero(self): self.assertEqual(range(0), []) def test_range_twoargs(self): @@ -30,15 +36,17 @@ def test_range_decreasing_negativelargestep(self): self.assertEqual(range(5, -2, -3), [5, 2, -1]) - def test_range_decreasing_negativelargestep2(self): - self.assertEqual(range(5, -3, -3), [5, 2, -1]) + def test_range_increasing_positivelargestep(self): + self.assertEqual(range(-5, 2, 3), [-5, -2, 1]) def test_range_zerostep(self): self.assertRaises(ValueError, range, 1, 5, 0) - def XXXtest_range_float(self): +""" + def test_range_float(self): "How CPython does it - UGLY, ignored for now." self.assertEqual(range(0.1, 2.0, 1.1), [0, 1]) + """ if __name__ == '__main__': testsupport.main() From tismer at codespeak.net Tue May 27 19:03:44 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Tue, 27 May 2003 19:03:44 +0200 (MEST) Subject: [pypy-svn] rev 614 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030527170344.63CE45A0BB@thoth.codespeak.net> Author: tismer Date: Tue May 27 19:03:41 2003 New Revision: 614 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py pypy/trunk/src/pypy/objspace/std/test/test_listobject.py Log: added setitem to listobject with test Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Tue May 27 19:03:41 2003 @@ -100,6 +100,17 @@ # upto here, lists are nearly identical to tuples. # XXX have to add over-allocation! +def setitem_list_int(space, w_list, w_index, w_any): + items = w_list.wrappeditems + try: + items[w_index.intval] = w_any + except IndexError: + raise OperationError(space.w_IndexError, + space.wrap("list index out of range")) + return space.w_None + +StdObjSpace.setitem.register(setitem_list_int, W_ListObject, W_IntObject, W_ANY) + def getattr_list(space, w_list, w_attr): if space.is_true(space.eq(w_attr, space.wrap('append'))): w_builtinfn = make_builtin_func(space, W_ListObject.append) Modified: pypy/trunk/src/pypy/objspace/std/test/test_listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_listobject.py Tue May 27 19:03:41 2003 @@ -2,7 +2,7 @@ import unittest, sys import testsupport from pypy.interpreter import unittest_w -from pypy.objspace.std import listobject as tobj +from pypy.objspace.std import listobject as lobj from pypy.objspace.std.objspace import * @@ -16,20 +16,20 @@ def test_is_true(self): w = self.space.wrap - w_list = tobj.W_ListObject(self.space, []) + w_list = lobj.W_ListObject(self.space, []) self.assertEqual(self.space.is_true(w_list), False) - w_list = tobj.W_ListObject(self.space, [w(5)]) + w_list = lobj.W_ListObject(self.space, [w(5)]) self.assertEqual(self.space.is_true(w_list), True) - w_list = tobj.W_ListObject(self.space, [w(5), w(3)]) + w_list = lobj.W_ListObject(self.space, [w(5), w(3)]) self.assertEqual(self.space.is_true(w_list), True) def test_len(self): w = self.space.wrap - w_list = tobj.W_ListObject(self.space, []) + w_list = lobj.W_ListObject(self.space, []) self.assertEqual_w(self.space.len(w_list), w(0)) - w_list = tobj.W_ListObject(self.space, [w(5)]) + w_list = lobj.W_ListObject(self.space, [w(5)]) self.assertEqual_w(self.space.len(w_list), w(1)) - w_list = tobj.W_ListObject(self.space, [w(5), w(3), w(99)]*111) + w_list = lobj.W_ListObject(self.space, [w(5), w(3), w(99)]*111) self.assertEqual_w(self.space.len(w_list), w(333)) def test_mul(self): @@ -37,14 +37,14 @@ w = self.space.wrap arg = w(2) n = 3 - w_lis = tobj.W_ListObject(self.space, [arg]) - w_lis3 = tobj.W_ListObject(self.space, [arg]*n) + w_lis = lobj.W_ListObject(self.space, [arg]) + w_lis3 = lobj.W_ListObject(self.space, [arg]*n) w_res = self.space.mul(w_lis, w(n)) self.assertEqual_w(w_lis3, w_res) def test_getitem(self): w = self.space.wrap - w_list = tobj.W_ListObject(self.space, [w(5), w(3)]) + w_list = lobj.W_ListObject(self.space, [w(5), w(3)]) self.assertEqual_w(self.space.getitem(w_list, w(0)), w(5)) self.assertEqual_w(self.space.getitem(w_list, w(1)), w(3)) self.assertEqual_w(self.space.getitem(w_list, w(-2)), w(5)) @@ -58,7 +58,7 @@ def test_iter(self): w = self.space.wrap - w_list = tobj.W_ListObject(self.space, [w(5), w(3), w(99)]) + w_list = lobj.W_ListObject(self.space, [w(5), w(3), w(99)]) w_iter = self.space.iter(w_list) self.assertEqual_w(self.space.next(w_iter), w(5)) self.assertEqual_w(self.space.next(w_iter), w(3)) @@ -68,15 +68,15 @@ def test_add(self): w = self.space.wrap - w_list0 = tobj.W_ListObject(self.space, []) - w_list1 = tobj.W_ListObject(self.space, [w(5), w(3), w(99)]) - w_list2 = tobj.W_ListObject(self.space, [w(-7)] * 111) + w_list0 = lobj.W_ListObject(self.space, []) + w_list1 = lobj.W_ListObject(self.space, [w(5), w(3), w(99)]) + w_list2 = lobj.W_ListObject(self.space, [w(-7)] * 111) self.assertEqual_w(self.space.add(w_list1, w_list1), - tobj.W_ListObject(self.space, [w(5), w(3), w(99), - w(5), w(3), w(99)])) + lobj.W_ListObject(self.space, [w(5), w(3), w(99), + w(5), w(3), w(99)])) self.assertEqual_w(self.space.add(w_list1, w_list2), - tobj.W_ListObject(self.space, [w(5), w(3), w(99)] + - [w(-7)] * 111)) + lobj.W_ListObject(self.space, [w(5), w(3), w(99)] + + [w(-7)] * 111)) self.assertEqual_w(self.space.add(w_list1, w_list0), w_list1) self.assertEqual_w(self.space.add(w_list0, w_list2), w_list2) @@ -85,7 +85,7 @@ def test1(testlist, start, stop, step, expected): w_slice = self.space.newslice(w(start), w(stop), w(step)) - w_list = tobj.W_ListObject(self.space, [w(i) for i in testlist]) + w_list = lobj.W_ListObject(self.space, [w(i) for i in testlist]) w_result = self.space.getitem(w_list, w_slice) self.assertEqual(self.space.unwrap(w_result), expected) @@ -101,5 +101,20 @@ test1([5,7,1,4], -3, 11, 2, [7, 4]) test1([5,7,1,4], -5, 11, 2, [5, 1]) + def test_setitem(self): + w = self.space.wrap + w_list = lobj.W_ListObject(self.space, [w(5), w(3)]) + w_exp1 = lobj.W_ListObject(self.space, [w(5), w(7)]) + w_exp2 = lobj.W_ListObject(self.space, [w(8), w(7)]) + self.space.setitem(w_list, w(1), w(7)) + self.assertEqual_w(w_exp1, w_list) + self.space.setitem(w_list, w(-2), w(8)) + self.assertEqual_w(w_exp2, w_list) + self.assertRaises_w(self.space.w_IndexError, + self.space.setitem, w_list, w(2), w(5)) + self.assertRaises_w(self.space.w_IndexError, + self.space.setitem, w_list, w(-3), w(5)) + + if __name__ == '__main__': unittest.main() From arigo at codespeak.net Tue May 27 19:07:27 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 19:07:27 +0200 (MEST) Subject: [pypy-svn] rev 615 - pypy/trunk/src/pypy/module Message-ID: <20030527170727.7423E5A0BB@thoth.codespeak.net> Author: arigo Date: Tue May 27 19:07:26 2003 New Revision: 615 Modified: pypy/trunk/src/pypy/module/builtin.py Log: hacked 'int' temporarily too 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 19:07:26 2003 @@ -19,6 +19,7 @@ True = appdata(_b.True) dict = appdata(_b.dict) # XXX temporary tuple = appdata(_b.tuple) # XXX temporary + int = appdata(_b.int) # XXX temporary # temporary hack, until we have a real tuple type for calling #def tuple(self, w_obj): @@ -63,8 +64,14 @@ str = space.unwrap(w_str) filename = space.unwrap(w_filename) startstr = space.unwrap(w_startstr) - supplied_flags = space.unwrap(w_supplied_flags) - dont_inherit = space.unwrap(w_dont_inherit) + if w_supplied_flags is None: + supplied_flags = 0 + else: + supplied_flags = space.unwrap(w_supplied_flags) + if w_dont_inherit is None: + dont_inherit = 0 + else: + dont_inherit = space.unwrap(w_dont_inherit) c = _b.compile(str, filename, startstr, supplied_flags, dont_inherit) res = pycode.PyByteCode() From arigo at codespeak.net Tue May 27 19:11:16 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 19:11:16 +0200 (MEST) Subject: [pypy-svn] rev 616 - in pypy/trunk/src/pypy: interpreter interpreter/test module Message-ID: <20030527171116.752E45A0BB@thoth.codespeak.net> Author: arigo Date: Tue May 27 19:11:15 2003 New Revision: 616 Modified: pypy/trunk/src/pypy/interpreter/pyframe.py pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py pypy/trunk/src/pypy/module/builtin.py Log: test_executioncontext works again now Modified: pypy/trunk/src/pypy/interpreter/pyframe.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pyframe.py (original) +++ pypy/trunk/src/pypy/interpreter/pyframe.py Tue May 27 19:11:15 2003 @@ -96,47 +96,6 @@ ### frame initialization ### - def setargs(self, w_arguments, w_kwargs=None, - w_defaults=None, w_closure=None): - "Initialize the frame with the given arguments tuple." - arguments = self.decode_arguments(w_arguments, w_kwargs, - w_defaults, w_closure) - for i in range(len(arguments)): - varname = self.getlocalvarname(i) - w_varname = self.space.wrap(varname) - w_arg = arguments[i] - self.space.setitem(self.w_locals, w_varname, w_arg) - - def decode_arguments(self, w_arguments, w_kwargs, w_defaults, w_closure): - # We cannot systematically go to the application-level (_app.py) - # to do this dirty work, for bootstrapping reasons. So we check - # if we are in the most simple case and if so do not go to the - # application-level at all. - co = self.bytecode - if (co.co_flags & (CO_VARARGS|CO_VARKEYWORDS) == 0 and - (w_defaults is None or not self.space.is_true(w_defaults)) and - (w_kwargs is None or not self.space.is_true(w_kwargs)) and - (w_closure is None or not self.space.is_true(w_closure))): - # looks like a simple case, see if we got exactly the correct - # number of arguments - try: - args = self.space.unpacktuple(w_arguments, co.co_argcount) - except ValueError: - pass # no - else: - return args # yes! fine! - # non-trivial case. I won't do it myself. - if w_kwargs is None: w_kwargs = self.space.newdict([]) - if w_defaults is None: w_defaults = self.space.newtuple([]) - if w_closure is None: w_closure = self.space.newtuple([]) - w_bytecode = self.space.wrap(co) - w_arguments = self.space.gethelper(appfile).call( - "decode_frame_arguments", [w_arguments, w_kwargs, w_defaults, - w_closure, w_bytecode]) - # we assume that decode_frame_arguments() gives us a tuple - # of the correct length. - return self.space.unpacktuple(w_arguments) - def load_builtins(self): # initialize self.w_builtins. This cannot be done in the '.app.py' # file for bootstrapping reasons. Modified: pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py Tue May 27 19:11:15 2003 @@ -10,13 +10,13 @@ # build frame space = testsupport.objspace() ec = executioncontext.ExecutionContext(space) - - bytecode = compile('def f(x): return x+1', '', 'exec').co_consts[0] + compile = space.builtin.compile + bytecode = compile(space.wrap('def f(x): return x+1'), + space.wrap(''), + space.wrap('exec')).co_consts[0] w_globals = ec.make_standard_w_globals() - w_locals = space.newdict([]) + w_locals = space.newdict([(space.wrap('x'), space.wrap(5))]) frame = PyFrame(space, bytecode, w_globals, w_locals) - w_input = frame.space.wrap((5,)) - frame.setargs(w_input) w_output = ec.eval_frame(frame) self.assertEquals(frame.space.unwrap(w_output), 6) 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 19:11:15 2003 @@ -13,14 +13,6 @@ __helper_appfile__ = appfile.AppFile('builtin_helper',["module"]) - # we have None! - None = appdata(_b.None) - False = appdata(_b.False) - True = appdata(_b.True) - dict = appdata(_b.dict) # XXX temporary - tuple = appdata(_b.tuple) # XXX temporary - int = appdata(_b.int) # XXX temporary - # temporary hack, until we have a real tuple type for calling #def tuple(self, w_obj): # lis = self.space.unpackiterable(w_obj) @@ -165,3 +157,11 @@ unichr = appmethod(unichr) + # we have None! But leave these at the bottom, otherwise the default + # arguments of the above-defined functions will see this new None... + None = appdata(_b.None) + False = appdata(_b.False) + True = appdata(_b.True) + dict = appdata(_b.dict) # XXX temporary + tuple = appdata(_b.tuple) # XXX temporary + int = appdata(_b.int) # XXX temporary From pedronis at codespeak.net Tue May 27 19:17:10 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Tue, 27 May 2003 19:17:10 +0200 (MEST) Subject: [pypy-svn] rev 617 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030527171710.7F47C5A0BB@thoth.codespeak.net> Author: pedronis Date: Tue May 27 19:17:10 2003 New Revision: 617 Modified: pypy/trunk/src/pypy/objspace/std/dictobject.py Log: added copy,items methods 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 19:17:10 2003 @@ -1,6 +1,7 @@ from objspace import * from stringobject import W_StringObject - +from instmethobject import W_InstMethObject +from pypy.interpreter.extmodule import make_builtin_func class _NoValueInCell: pass @@ -47,6 +48,17 @@ def cell(self,space,w_lookup): return space.wrap(self._cell(space,w_lookup)) + + def copy(w_self): + return W_DictObject(w_self.space,[(w_key,cell.get()) + for w_key,cell in + w_self.non_empties()]) + def items(w_self): + space = w_self.space + return space.newlist([ space.newtuple([w_key,cell.get()]) + for w_key,cell in + w_self.non_empties()]) + def dict_is_true(space, w_dict): return not not w_dict.non_empties() @@ -99,3 +111,14 @@ return space.w_False StdObjSpace.contains.register(contains_dict_any, W_DictObject, W_ANY) + +def getattr_dict(space, w_dict, w_attr): + if space.is_true(space.eq(w_attr, space.wrap('copy'))): + w_builtinfn = make_builtin_func(space, W_DictObject.copy) + return W_InstMethObject(space, w_dict, w_builtinfn) + if space.is_true(space.eq(w_attr, space.wrap('items'))): + w_builtinfn = make_builtin_func(space, W_DictObject.items) + return W_InstMethObject(space, w_dict, w_builtinfn) + raise FailedToImplement(space.w_AttributeError) + +StdObjSpace.getattr.register(getattr_dict, W_DictObject, W_ANY) From arigo at codespeak.net Tue May 27 19:19:52 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Tue, 27 May 2003 19:19:52 +0200 (MEST) Subject: [pypy-svn] rev 618 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030527171952.1293B5A0BB@thoth.codespeak.net> Author: arigo Date: Tue May 27 19:19:51 2003 New Revision: 618 Modified: pypy/trunk/src/pypy/interpreter/test/hello_world.py Log: made hello_world non-crashing Python code again Modified: pypy/trunk/src/pypy/interpreter/test/hello_world.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/hello_world.py (original) +++ pypy/trunk/src/pypy/interpreter/test/hello_world.py Tue May 27 19:19:51 2003 @@ -4,6 +4,6 @@ map(main, ["hello world", "good bye"]) apply(main, ("apply works, too",)) +apply(main, (), {"aStr": "it really works"}) print chr(65) -print chr('!') From mwh at codespeak.net Tue May 27 19:33:08 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Tue, 27 May 2003 19:33:08 +0200 (MEST) Subject: [pypy-svn] rev 619 - in pypy/trunk/src/pypy/interpreter: . test Message-ID: <20030527173308.92D0C5A0BB@thoth.codespeak.net> Author: mwh Date: Tue May 27 19:32:59 2003 New Revision: 619 Modified: pypy/trunk/src/pypy/interpreter/main.py pypy/trunk/src/pypy/interpreter/test/test_main.py Log: rehash main.py slightly to enable rewrite of test_main; rewrite test_main so it works when part of a larger suite. 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 19:32:59 2003 @@ -3,10 +3,10 @@ from pypy.interpreter import executioncontext, baseobjspace, pyframe import sys -def run_string(source, fname): - space = None # in case StdObjSpace.__init__() crashes +def run_string(source, fname, space=None): try: - space = StdObjSpace() + if space is None: + space = StdObjSpace() compile = space.builtin.compile w=space.wrap @@ -27,9 +27,9 @@ else: ec.eval_frame(frame) -def run_file(fname): +def run_file(fname, space=None): istring = open(fname).read() - run_string(istring, fname) + run_string(istring, fname, space) def main(argv=None): if argv is None: Modified: pypy/trunk/src/pypy/interpreter/test/test_main.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_main.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_main.py Tue May 27 19:32:59 2003 @@ -17,14 +17,15 @@ capture = StringIO() def checkoutput(expected_output,f,*args): - import sys - oldout = sys.stdout + space = testsupport.objspace() + w_sys = space.get_builtin_module(space.wrap("sys")) + w_oldout = space.getattr(w_sys, space.wrap("stdout")) + capture.reset() + space.setattr(w_sys, space.wrap("stdout"), space.wrap(capture)) try: - capture.reset() - sys.stdout = capture - f(*args) + f(*(args + (space,))) finally: - sys.stdout = oldout + space.setattr(w_sys, space.wrap("stdout"), w_oldout) return capture.getvalue() == expected_output From mwh at codespeak.net Wed May 28 15:56:12 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Wed, 28 May 2003 15:56:12 +0200 (MEST) Subject: [pypy-svn] rev 620 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030528135612.E038B5A1D6@thoth.codespeak.net> Author: mwh Date: Wed May 28 15:56:11 2003 New Revision: 620 Modified: pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py Log: make work with stdobjspace Modified: pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py Wed May 28 15:56:11 2003 @@ -11,9 +11,9 @@ space = testsupport.objspace() ec = executioncontext.ExecutionContext(space) compile = space.builtin.compile - bytecode = compile(space.wrap('def f(x): return x+1'), - space.wrap(''), - space.wrap('exec')).co_consts[0] + bytecode = space.unwrap(compile(space.wrap('def f(x): return x+1'), + space.wrap(''), + space.wrap('exec'))).co_consts[0] w_globals = ec.make_standard_w_globals() w_locals = space.newdict([(space.wrap('x'), space.wrap(5))]) frame = PyFrame(space, bytecode, w_globals, w_locals) From pedronis at codespeak.net Wed May 28 15:59:47 2003 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Wed, 28 May 2003 15:59:47 +0200 (MEST) Subject: [pypy-svn] rev 621 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030528135947.A02765A263@thoth.codespeak.net> Author: pedronis Date: Wed May 28 15:59:47 2003 New Revision: 621 Modified: pypy/trunk/src/pypy/objspace/std/dictobject.py Log: added keys & values. 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 Wed May 28 15:59:47 2003 @@ -58,7 +58,18 @@ return space.newlist([ space.newtuple([w_key,cell.get()]) for w_key,cell in w_self.non_empties()]) - + + def keys(w_self): + space = w_self.space + return space.newlist([ w_key + for w_key,cell in + w_self.non_empties()]) + + def values(w_self): + space = w_self.space + return space.newlist([ cell.get() + for w_key,cell in + w_self.non_empties()]) def dict_is_true(space, w_dict): return not not w_dict.non_empties() @@ -118,7 +129,13 @@ return W_InstMethObject(space, w_dict, w_builtinfn) if space.is_true(space.eq(w_attr, space.wrap('items'))): w_builtinfn = make_builtin_func(space, W_DictObject.items) - return W_InstMethObject(space, w_dict, w_builtinfn) + return W_InstMethObject(space, w_dict, w_builtinfn) + if space.is_true(space.eq(w_attr, space.wrap('keys'))): + w_builtinfn = make_builtin_func(space, W_DictObject.keys) + return W_InstMethObject(space, w_dict, w_builtinfn) + if space.is_true(space.eq(w_attr, space.wrap('values'))): + w_builtinfn = make_builtin_func(space, W_DictObject.values) + return W_InstMethObject(space, w_dict, w_builtinfn) raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_dict, W_DictObject, W_ANY) From tismer at codespeak.net Wed May 28 16:08:33 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Wed, 28 May 2003 16:08:33 +0200 (MEST) Subject: [pypy-svn] rev 622 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030528140833.9A78A5A10F@thoth.codespeak.net> Author: tismer Date: Wed May 28 16:08:33 2003 New Revision: 622 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py pypy/trunk/src/pypy/objspace/std/test/test_listobject.py pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py pypy/trunk/src/pypy/objspace/std/tupleobject.py Log: added left multiply to ints and tuples, with test working Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Wed May 28 16:08:33 2003 @@ -85,6 +85,11 @@ StdObjSpace.mul.register(list_int_mul, W_ListObject, W_IntObject) +def int_list_mul(space, w_int, w_list): + return list_int_mul(space, w_list, w_int) + +StdObjSpace.mul.register(int_list_mul, W_IntObject, W_ListObject) + def list_eq(space, w_list1, w_list2): items1 = w_list1.wrappeditems items2 = w_list2.wrappeditems @@ -111,6 +116,23 @@ StdObjSpace.setitem.register(setitem_list_int, W_ListObject, W_IntObject, W_ANY) +# not trivial! +def setitem_list_slice(space, w_list, w_slice, w_list2): + items = w_list.wrappeditems + w_length = space.wrap(len(items)) + w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length) + start = space.unwrap(w_start) + step = space.unwrap(w_step) + slicelength = space.unwrap(w_slicelength) + assert slicelength >= 0 + subitems = [None] * slicelength + for i in range(slicelength): + subitems[i] = items[start] + start += step + return W_ListObject(space, subitems) + +StdObjSpace.setitem.register(setitem_list_slice, W_ListObject, W_SliceObject, W_ANY) + def getattr_list(space, w_list, w_attr): if space.is_true(space.eq(w_attr, space.wrap('append'))): w_builtinfn = make_builtin_func(space, W_ListObject.append) Modified: pypy/trunk/src/pypy/objspace/std/test/test_listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_listobject.py Wed May 28 16:08:33 2003 @@ -41,6 +41,9 @@ w_lis3 = lobj.W_ListObject(self.space, [arg]*n) w_res = self.space.mul(w_lis, w(n)) self.assertEqual_w(w_lis3, w_res) + # commute + w_res = self.space.mul(w(n), w_lis) + self.assertEqual_w(w_lis3, w_res) def test_getitem(self): w = self.space.wrap Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Wed May 28 16:08:33 2003 @@ -91,6 +91,9 @@ w_tup3 = tobj.W_TupleObject(self.space, [arg]*n) w_res = self.space.mul(w_tup, w(n)) self.assertEqual_w(w_tup3, w_res) + # commute + w_res = self.space.mul(w(n), w_tup) + self.assertEqual_w(w_tup3, w_res) def test_getslice(self): w = self.space.wrap Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Wed May 28 16:08:33 2003 @@ -79,6 +79,11 @@ StdObjSpace.mul.register(tuple_int_mul, W_TupleObject, W_IntObject) +def int_tuple_mul(space, w_int, w_tuple): + return tuple_int_mul(space, w_tuple, w_int) + +StdObjSpace.mul.register(int_tuple_mul, W_IntObject, W_TupleObject) + def tuple_eq(space, w_tuple1, w_tuple2): items1 = w_tuple1.wrappeditems items2 = w_tuple2.wrappeditems From lac at codespeak.net Wed May 28 16:29:14 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Wed, 28 May 2003 16:29:14 +0200 (MEST) Subject: [pypy-svn] rev 623 - pypy/trunk/src/pypy/module/test Message-ID: <20030528142914.2D26E5A28A@thoth.codespeak.net> Author: lac Date: Wed May 28 16:29:13 2003 New Revision: 623 Modified: pypy/trunk/src/pypy/module/test/test_range.py Log: Add tests to detect the fencepost error Modified: pypy/trunk/src/pypy/module/test/test_range.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_range.py (original) +++ pypy/trunk/src/pypy/module/test/test_range.py Wed May 28 16:29:13 2003 @@ -18,6 +18,13 @@ def test_range_one(self): self.assertEqual(range(1), [0]) + def test_range_posstartisstop(self): + self.assertEqual(range(1, 1), []) + + def test_range_negstartisstop(self): + self.assertEqual(range(-1, -1), []) + + def test_range_zero(self): self.assertEqual(range(0), []) @@ -33,6 +40,24 @@ def test_range_decreasing_negativestep(self): self.assertEqual(range(5, -2, -1), [5, 4, 3, 2, 1, 0 , -1]) + def test_range_posfencepost1(self): + self.assertEqual(range (1, 10, 3), [1, 4, 7]) + + def test_range_posfencepost2(self): + self.assertEqual(range (1, 11, 3), [1, 4, 7, 10]) + + def test_range_posfencepost3(self): + self.assertEqual(range (1, 12, 3), [1, 4, 7, 10]) + + def test_range_negfencepost1(self): + self.assertEqual(range (-1, -10, -3), [-1, -4, -7]) + + def test_range_negfencepost2(self): + self.assertEqual(range (-1, -11, -3), [-1, -4, -7, -10]) + + def test_range_negfencepost3(self): + self.assertEqual(range (-1, -12, -3), [-1, -4, -7, -10]) + def test_range_decreasing_negativelargestep(self): self.assertEqual(range(5, -2, -3), [5, 2, -1]) From lac at codespeak.net Wed May 28 16:30:05 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Wed, 28 May 2003 16:30:05 +0200 (MEST) Subject: [pypy-svn] rev 624 - pypy/trunk/src/pypy/module Message-ID: <20030528143005.B81E05A7BF@thoth.codespeak.net> Author: lac Date: Wed May 28 16:30:05 2003 New Revision: 624 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: Fix the fencepost error. 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 Wed May 28 16:30:05 2003 @@ -29,7 +29,6 @@ else: return res idx = idx + 1 - #print idx def filter(function, collection): res = [] @@ -99,27 +98,26 @@ def range(x, y=None, step=1): "docstring" + if y is None: + start = 0 + stop = x + else: + start = x + stop = y + if step == 0: raise ValueError, 'range() arg 3 must not be zero' - if y is None: - start = 0 - stop = x - else: - start = x - stop = y - - if (stop <= start and step > 0) or (stop >= start and step < 0): - return [] - else: - howmany = abs((stop - start)/step) - if abs(step) != 1: - howmany += 1 - - if howmany == 0: - return [] - else: - arr = [None] * int(howmany) + elif (stop <= start and step > 0) or (stop >= start and step < 0): + return [] # easy, no work for us. + + elif step > 0: + howmany = (stop - start + step - 1)/step + + else: # step must be < 0 + howmany = (start - stop - step - 1)/-step + + arr = [None] * howmany i = start n = 0 From alex at codespeak.net Wed May 28 16:55:34 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Wed, 28 May 2003 16:55:34 +0200 (MEST) Subject: [pypy-svn] rev 625 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030528145534.C0DC85AC59@thoth.codespeak.net> Author: alex Date: Wed May 28 16:55:34 2003 New Revision: 625 Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Log: All tests reviewed: 10 pass with both trivial and standard object spaces, three are currently disabled (renamed to XXXtest_...). Note: this shows exception texts on stdout, but this is NOT an error nor a failure !!!. Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_interpreter.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Wed May 28 16:55:34 2003 @@ -61,8 +61,19 @@ def g(x): return x''', 'g', [666]) self.assertEquals(x, 666) + def test_exception_trivial(self): + x = self.codetest(''' +def f(): + try: + raise Exception() + except Exception, e: + return 1 + return 2 +''', 'f', []) + self.assertEquals(x, 1) + def XXXtest_exception(self): - """ exception raising currently broken """ + """ exception raising currently semi-broken """ x = self.codetest(''' def f(): try: @@ -93,7 +104,8 @@ ''', 'f', []) self.assertEquals(x, '<<>>') - def aatest_except2(self): + def XXXtest_except2(self): + """ depends on being able to import types """ x = self.codetest(''' def f(): try: @@ -108,7 +120,7 @@ ''', 'f', []) self.assertEquals(x, 5) - def aatest_except3(self): + def test_except3(self): code = ''' def f(v): z = 0 @@ -120,9 +132,13 @@ ''' self.assertEquals(self.codetest(code, 'f', [2]), 0) self.assertEquals(self.codetest(code, 'f', [0]), "infinite result") - self.assertEquals(self.codetest(code, 'f', ['x']), "<<>>") + ess = "TypeError: unsupported operand type" + res = self.codetest(code, 'f', ['x']) + self.failUnless(res.index(ess) >= 0) + # the following (original) test was a bit too strict...: + # self.assertEquals(self.codetest(code, 'f', ['x']), "<<>>") - def aatest_break(self): + def test_break(self): code = ''' def f(n): total = 0 @@ -137,7 +153,7 @@ self.assertEquals(self.codetest(code, 'f', [4]), 1+2+3) self.assertEquals(self.codetest(code, 'f', [9]), 1+2+3+4) - def aatest_continue(self): + def test_continue(self): code = ''' def f(n): total = 0 From mwh at codespeak.net Wed May 28 17:15:46 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Wed, 28 May 2003 17:15:46 +0200 (MEST) Subject: [pypy-svn] rev 626 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030528151546.24E875A10F@thoth.codespeak.net> Author: mwh Date: Wed May 28 17:15:45 2003 New Revision: 626 Removed: pypy/trunk/src/pypy/interpreter/test/test_stdobjspace.py Log: this seems to have outlived its usefulness Deleted: pypy/trunk/src/pypy/interpreter/test/test_stdobjspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_stdobjspace.py Wed May 28 17:15:45 2003 +++ (empty file) @@ -1,13 +0,0 @@ -import unittest -import support -import test_interpreter - -class TestStdObjSpace(test_interpreter.TestInterpreter): - - def setUp(self): - from pypy.objspace.std.objspace import StdObjSpace - self.space = StdObjSpace() - - -if __name__ == '__main__': - unittest.main() From mwh at codespeak.net Wed May 28 17:29:43 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Wed, 28 May 2003 17:29:43 +0200 (MEST) Subject: [pypy-svn] rev 627 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030528152943.5FD635A10F@thoth.codespeak.net> Author: mwh Date: Wed May 28 17:29:43 2003 New Revision: 627 Modified: pypy/trunk/src/pypy/objspace/std/test/test_objspace.py Log: modernization, in preparation for a mv into pypy/interpreter/test. fails with TrivialObjSpace, which indicates something of a problem. Modified: pypy/trunk/src/pypy/objspace/std/test/test_objspace.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_objspace.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_objspace.py Wed May 28 17:29:43 2003 @@ -1,14 +1,9 @@ -import unittest, sys import testsupport -from pypy.interpreter import unittest_w -from pypy.objspace.std import noneobject as nobj -from pypy.objspace.std.objspace import * - -class TestStdObjectSpace(unittest_w.TestCase_w): +class TestStdObjectSpace(testsupport.TestCase): def setUp(self): - self.space = StdObjSpace() + self.space = testsupport.objspace() def tearDown(self): pass @@ -31,4 +26,4 @@ [w(-1)]) if __name__ == '__main__': - unittest.main() + testsupport.main() From mwh at codespeak.net Wed May 28 17:31:03 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Wed, 28 May 2003 17:31:03 +0200 (MEST) Subject: [pypy-svn] rev 628 - pypy/trunk/src/pypy/interpreter Message-ID: <20030528153103.DC9965A10F@thoth.codespeak.net> Author: mwh Date: Wed May 28 17:31:03 2003 New Revision: 628 Modified: pypy/trunk/src/pypy/interpreter/unittest_w.py Log: line endings Modified: pypy/trunk/src/pypy/interpreter/unittest_w.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/unittest_w.py (original) +++ pypy/trunk/src/pypy/interpreter/unittest_w.py Wed May 28 17:31:03 2003 @@ -1,41 +1,41 @@ -import sys, os -import unittest - -class TestCase_w(unittest.TestCase): - """ enrich TestCase with wrapped-methods """ - - def failUnless_w(self, w_condition, msg=None): - condition = self.space.is_true(w_condition) - return self.failUnless(condition, msg) - - def failIf_w(self, w_condition, msg=None): - condition = self.space.is_true(w_condition) - return self.failIf(condition, msg) - - def assertEqual_w(self, w_first, w_second, msg=None): - w_condition = self.space.eq(w_first, w_second) - condition = self.space.is_true(w_condition) - return self.failUnless(condition, msg) - - def assertNotEqual_w(self, w_first, w_second, msg=None): - w_condition = self.space.eq(w_first, w_second) - condition = self.space.is_true(w_condition) - return self.failIf(condition, msg) - - def assertRaises_w(self, w_exc_class, callable, *args, **kw): - from pypy.objspace.std.objspace import OperationError - try: - callable(*args, **kw) - except OperationError, e: - self.failUnless(e.match(self.space, w_exc_class)) - else: - self.fail('should have got an exception') - - def assertWRaises_w(self, w_exc_class, w_callable, *args_w, **kw_w): - from pypy.objspace.std.objspace import OperationError - try: - self.space.call_function(w_callable, *args_w, **kw_w) - except OperationError, e: - self.failUnless(e.match(self.space, w_exc_class)) - else: - self.fail('should have got an exception') +import sys, os +import unittest + +class TestCase_w(unittest.TestCase): + """ enrich TestCase with wrapped-methods """ + + def failUnless_w(self, w_condition, msg=None): + condition = self.space.is_true(w_condition) + return self.failUnless(condition, msg) + + def failIf_w(self, w_condition, msg=None): + condition = self.space.is_true(w_condition) + return self.failIf(condition, msg) + + def assertEqual_w(self, w_first, w_second, msg=None): + w_condition = self.space.eq(w_first, w_second) + condition = self.space.is_true(w_condition) + return self.failUnless(condition, msg) + + def assertNotEqual_w(self, w_first, w_second, msg=None): + w_condition = self.space.eq(w_first, w_second) + condition = self.space.is_true(w_condition) + return self.failIf(condition, msg) + + def assertRaises_w(self, w_exc_class, callable, *args, **kw): + from pypy.objspace.std.objspace import OperationError + try: + callable(*args, **kw) + except OperationError, e: + self.failUnless(e.match(self.space, w_exc_class)) + else: + self.fail('should have got an exception') + + def assertWRaises_w(self, w_exc_class, w_callable, *args_w, **kw_w): + from pypy.objspace.std.objspace import OperationError + try: + self.space.call_function(w_callable, *args_w, **kw_w) + except OperationError, e: + self.failUnless(e.match(self.space, w_exc_class)) + else: + self.fail('should have got an exception') From mwh at codespeak.net Wed May 28 17:32:15 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Wed, 28 May 2003 17:32:15 +0200 (MEST) Subject: [pypy-svn] rev 629 - in pypy/trunk/src/pypy: interpreter/test objspace/std/test Message-ID: <20030528153215.CA28F5A10F@thoth.codespeak.net> Author: mwh Date: Wed May 28 17:32:15 2003 New Revision: 629 Added: pypy/trunk/src/pypy/interpreter/test/test_objspace.py - copied unchanged from rev 628, pypy/trunk/src/pypy/objspace/std/test/test_objspace.py Removed: pypy/trunk/src/pypy/objspace/std/test/test_objspace.py Log: move test_objspace into test/interpreter Deleted: pypy/trunk/src/pypy/objspace/std/test/test_objspace.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_objspace.py Wed May 28 17:32:15 2003 +++ (empty file) @@ -1,29 +0,0 @@ -import testsupport - -class TestStdObjectSpace(testsupport.TestCase): - - def setUp(self): - self.space = testsupport.objspace() - - def tearDown(self): - pass - - def test_newstring(self): - w = self.space.wrap - s = 'abc' - chars_w = [w(ord(c)) for c in s] - self.assertEqual_w(w(s), self.space.newstring(chars_w)) - - def test_newstring_fail(self): - w = self.space.wrap - s = 'abc' - not_chars_w = [w(c) for c in s] - self.assertRaises_w(self.space.w_TypeError, - self.space.newstring, - not_chars_w) - self.assertRaises_w(self.space.w_ValueError, - self.space.newstring, - [w(-1)]) - -if __name__ == '__main__': - testsupport.main() From tomek at codespeak.net Wed May 28 17:37:35 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Wed, 28 May 2003 17:37:35 +0200 (MEST) Subject: [pypy-svn] rev 630 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030528153735.5CB935A10F@thoth.codespeak.net> Author: tomek Date: Wed May 28 17:37:34 2003 New Revision: 630 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/stringobject_app.py Log: implemented join Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Wed May 28 17:37:34 2003 @@ -1,6 +1,9 @@ from pypy.objspace.std.objspace import * from intobject import W_IntObject from sliceobject import W_SliceObject +from instmethobject import W_InstMethObject +from pypy.interpreter.extmodule import make_builtin_func + applicationfile = StdObjSpace.AppFile(__name__) @@ -16,6 +19,26 @@ def hash(w_self): return W_IntObject(self, hash(self.value)) + def join(w_self, w_list): + firstelem = 1 + res = "" + for w_item in w_list.wrappeditems: + if firstelem: + res = w_item.value + firstelem = 0 + else: + res = res + w_self.value + w_item.value + + return W_StringObject(w_self.space, res) + +def getattr_str(space, w_list, w_attr): + if space.is_true(space.eq(w_attr, space.wrap('join'))): + w_builtinfn = make_builtin_func(space, W_StringObject.join) + return W_InstMethObject(space, w_list, w_builtinfn) + raise FailedToImplement(space.w_AttributeError) + +StdObjSpace.getattr.register(getattr_str, W_StringObject, W_ANY) + def str_unwrap(space, w_str): return w_str.value Modified: pypy/trunk/src/pypy/objspace/std/stringobject_app.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject_app.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject_app.py Wed May 28 17:37:34 2003 @@ -3,3 +3,4 @@ for i in xrange(*sliceob.indices(len(str))): r.append(str[i]) return ''.join(r) + From anna at codespeak.net Wed May 28 18:00:03 2003 From: anna at codespeak.net (anna at codespeak.net) Date: Wed, 28 May 2003 18:00:03 +0200 (MEST) Subject: [pypy-svn] rev 631 - pypy/trunk/doc Message-ID: <20030528160003.E07E45A10F@thoth.codespeak.net> Author: anna Date: Wed May 28 18:00:03 2003 New Revision: 631 Modified: pypy/trunk/doc/coding-style.txt Log: add coding-style.txt Modified: pypy/trunk/doc/coding-style.txt ============================================================================== --- pypy/trunk/doc/coding-style.txt (original) +++ pypy/trunk/doc/coding-style.txt Wed May 28 18:00:03 2003 @@ -88,8 +88,7 @@ - every non-test file is forbidden to start with "t" -- each test directory might have a 'setpath.py' which sets - import pathes (e.g. relative to its current position) +- each test directory needs a copy of testsupport.py. see doc/using-testsupport.txt for more information. Miscallenous stuff From alex at codespeak.net Wed May 28 18:05:31 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Wed, 28 May 2003 18:05:31 +0200 (MEST) Subject: [pypy-svn] rev 632 - pypy/trunk/src/pypy Message-ID: <20030528160531.0E0C45A10F@thoth.codespeak.net> Author: alex Date: Wed May 28 18:05:30 2003 New Revision: 632 Added: pypy/trunk/src/pypy/testwice.py Log: like testall, but run tests that use testsupport.objspace twice, once each with trivial and standard object spaces Added: pypy/trunk/src/pypy/testwice.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/testwice.py Wed May 28 18:05:30 2003 @@ -0,0 +1,67 @@ +import os +import unittest +import sys + +try: + head = this_path = os.path.abspath(__file__) +except NameError: + head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + PYPYDIR = head + if PYPYDIR not in sys.path: + sys.path.insert(0, PYPYDIR) + break + +def is_flexible(dirname, modname): + filecont = open('%s/%s.py'%(dirname,modname)).read() + return filecont.index('testsupport.objspace') >= 0 + +def find_tests(root, inc_names=[], exc_names=[]): + testmods = [] + testwice = [] + def callback(arg, dirname, names): + if os.path.basename(dirname) == 'test': + parname = os.path.basename(os.path.dirname(dirname)) + if ((not inc_names) or parname in inc_names) and parname not in exc_names: + package = dirname[len(PYPYDIR)+1:].replace(os.sep, '.') + testfiles = [f[:-3] for f in names + if f.startswith('test_') and f.endswith('.py')] + for file in testfiles: + testmods.append(package + '.' + file) + if is_flexible(dirname, file): + testwice.append(package + '.' + file) + + os.path.walk(root, callback, None) + + tl = unittest.TestLoader() + + return tl.loadTestsFromNames(testmods), tl.loadTestsFromNames(testwice) + +def main(argv=None): + if argv is None: + argv = sys.argv + + inc_names = [] + exc_names = [] + + for arg in argv[1:]: + if arg.startswith('--include='): + inc_names = arg[len('--include='):].split(',') + elif arg.startswith('--exclude='): + exc_names = arg[len('--exclude='):].split(',') + else: + raise Exception, "don't know arg " + arg + + runner = unittest.TextTestRunner() + alltests, flexible = find_tests(PYPYDIR, inc_names, exc_names) + os.environ.set('OBJSPACE', '') + runner.run(alltests) + os.environ.set('OBJSPACE', 'pypy.objspace.std.objspace.StdObjSpace') + runner.run(flexible) + +if __name__ == '__main__': + main() From alex at codespeak.net Wed May 28 18:06:26 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Wed, 28 May 2003 18:06:26 +0200 (MEST) Subject: [pypy-svn] rev 633 - pypy/trunk/src/pypy Message-ID: <20030528160626.9DA225A10F@thoth.codespeak.net> Author: alex Date: Wed May 28 18:06:26 2003 New Revision: 633 Modified: pypy/trunk/src/pypy/testwice.py Log: fix usual index/find confusion (!) Modified: pypy/trunk/src/pypy/testwice.py ============================================================================== --- pypy/trunk/src/pypy/testwice.py (original) +++ pypy/trunk/src/pypy/testwice.py Wed May 28 18:06:26 2003 @@ -18,7 +18,7 @@ def is_flexible(dirname, modname): filecont = open('%s/%s.py'%(dirname,modname)).read() - return filecont.index('testsupport.objspace') >= 0 + return filecont.find('testsupport.objspace') >= 0 def find_tests(root, inc_names=[], exc_names=[]): testmods = [] From alex at codespeak.net Wed May 28 18:13:10 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Wed, 28 May 2003 18:13:10 +0200 (MEST) Subject: [pypy-svn] rev 634 - pypy/trunk/src/pypy Message-ID: <20030528161310.3C6985A10F@thoth.codespeak.net> Author: alex Date: Wed May 28 18:13:09 2003 New Revision: 634 Modified: pypy/trunk/src/pypy/testwice.py Log: seem to be working now Modified: pypy/trunk/src/pypy/testwice.py ============================================================================== --- pypy/trunk/src/pypy/testwice.py (original) +++ pypy/trunk/src/pypy/testwice.py Wed May 28 18:13:09 2003 @@ -58,9 +58,9 @@ runner = unittest.TextTestRunner() alltests, flexible = find_tests(PYPYDIR, inc_names, exc_names) - os.environ.set('OBJSPACE', '') + os.environ['OBJSPACE'] = '' runner.run(alltests) - os.environ.set('OBJSPACE', 'pypy.objspace.std.objspace.StdObjSpace') + os.environ['OBJSPACE'] = 'pypy.objspace.std.objspace.StdObjSpace' runner.run(flexible) if __name__ == '__main__': From mwh at codespeak.net Wed May 28 18:19:30 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Wed, 28 May 2003 18:19:30 +0200 (MEST) Subject: [pypy-svn] rev 635 - pypy/trunk/src/pypy/objspace Message-ID: <20030528161930.B5CD95A10F@thoth.codespeak.net> Author: mwh Date: Wed May 28 18:19:30 2003 New Revision: 635 Modified: pypy/trunk/src/pypy/objspace/trivial.py Log: make test_objspace work with trivial object space Modified: pypy/trunk/src/pypy/objspace/trivial.py ============================================================================== --- pypy/trunk/src/pypy/objspace/trivial.py (original) +++ pypy/trunk/src/pypy/objspace/trivial.py Wed May 28 18:19:30 2003 @@ -199,7 +199,10 @@ return nufun(self, code, globals, defaultarguments, closure) def newstring(self, asciilist): - return ''.join([chr(ascii) for ascii in asciilist]) + try: + return ''.join([chr(ascii) for ascii in asciilist]) + except: + raise OperationError(*sys.exc_info()[:2]) def call(self, callable, args, kwds): if isinstance(callable, types.ClassType): From mwh at codespeak.net Wed May 28 18:31:35 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Wed, 28 May 2003 18:31:35 +0200 (MEST) Subject: [pypy-svn] rev 636 - pypy/trunk/src/pypy/interpreter Message-ID: <20030528163135.7677D5A10F@thoth.codespeak.net> Author: mwh Date: Wed May 28 18:31:35 2003 New Revision: 636 Modified: pypy/trunk/src/pypy/interpreter/unittest_w.py Log: fail more helpfully Modified: pypy/trunk/src/pypy/interpreter/unittest_w.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/unittest_w.py (original) +++ pypy/trunk/src/pypy/interpreter/unittest_w.py Wed May 28 18:31:35 2003 @@ -15,11 +15,15 @@ def assertEqual_w(self, w_first, w_second, msg=None): w_condition = self.space.eq(w_first, w_second) condition = self.space.is_true(w_condition) + if msg is None: + msg = '%s != %s'%(w_first, w_second) return self.failUnless(condition, msg) def assertNotEqual_w(self, w_first, w_second, msg=None): w_condition = self.space.eq(w_first, w_second) condition = self.space.is_true(w_condition) + if msg is None: + msg = '%s == %s'%(w_first, w_second) return self.failIf(condition, msg) def assertRaises_w(self, w_exc_class, callable, *args, **kw): From mwh at codespeak.net Wed May 28 18:44:09 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Wed, 28 May 2003 18:44:09 +0200 (MEST) Subject: [pypy-svn] rev 637 - in pypy/trunk/src/pypy: interpreter/test objspace/std Message-ID: <20030528164409.D5F255A10F@thoth.codespeak.net> Author: mwh Date: Wed May 28 18:44:09 2003 New Revision: 637 Modified: pypy/trunk/src/pypy/interpreter/test/test_objspace.py pypy/trunk/src/pypy/objspace/std/dictobject.py pypy/trunk/src/pypy/objspace/std/objspace.py Log: add silly test for space.newlist, which was easy add silly test for space.newdict, which involved: make StdObjSpace.wrap wrap dicts (!) and adding eq_dict_dict Modified: pypy/trunk/src/pypy/interpreter/test/test_objspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_objspace.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_objspace.py Wed May 28 18:44:09 2003 @@ -25,5 +25,19 @@ self.space.newstring, [w(-1)]) + def test_newlist(self): + w = self.space.wrap + l = range(10) + w_l = self.space.newlist([w(i) for i in l]) + self.assertEqual_w(w_l, w(l)) + + def test_newdict(self): + w = self.space.wrap + items = [(0, 1), (3, 4)] + items_w = [(w(k), w(v)) for (k, v) in items] + d = dict(items) + w_d = self.space.newdict(items_w) + self.assertEqual_w(w_d, w(d)) + if __name__ == '__main__': testsupport.main() 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 Wed May 28 18:44:09 2003 @@ -33,6 +33,10 @@ W_Object.__init__(w_self, space) w_self.data = [ (w_key,Cell(w_value)) for w_key,w_value in list_pairs_w ] + def __repr__(w_self): + """ representation for debugging purposes """ + return "%s(%s)" % (w_self.__class__.__name__, w_self.data) + def non_empties(self): return [ (w_key,cell) for w_key,cell in self.data if not cell.is_empty()] @@ -139,3 +143,19 @@ raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_dict, W_DictObject, W_ANY) + +def eq_dict_dict(space, w_left, w_right): + if len(w_left.data) != len(w_right.data): + return self.newbool(0) + for w_k, cell in w_left.data: + try: + w_v = space.getitem(w_right, w_k) + except OperationError: + return self.newbool(0) + r = space.is_true(space.eq(cell.w_value, w_v)) + if not r: + return r + return space.newbool(1) + + +StdObjSpace.eq.register(eq_dict_dict, W_DictObject, W_DictObject) 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 Wed May 28 18:44:09 2003 @@ -65,6 +65,10 @@ if isinstance(x, str): import stringobject return stringobject.W_StringObject(self, x) + if isinstance(x, dict): + items_w = [(self.wrap(k), self.wrap(v)) for (k, v) in x.iteritems()] + import dictobject + return dictobject.W_DictObject(self, items_w) #if isinstance(x, float): # import floatobject # return floatobject.W_FloatObject(self, x) From lac at codespeak.net Wed May 28 18:44:24 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Wed, 28 May 2003 18:44:24 +0200 (MEST) Subject: [pypy-svn] rev 638 - pypy/trunk/src/pypy/module Message-ID: <20030528164424.ABE805A10F@thoth.codespeak.net> Author: lac Date: Wed May 28 18:44:24 2003 New Revision: 638 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: make vars return the locals, not just print them 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 Wed May 28 18:44:24 2003 @@ -170,13 +170,11 @@ def vars(*objectt): if len(objectt) == 0: - locals() + return locals() + elif len(objectt) != 1: + raise TypeError, "vars() takes at most 1 argument." else: try: - object, = objectt - except ValueError: - raise TypeError, "vars() takes at most 1 argument (2 given)" - try: return object.__dict__ except AttributeError: raise TypeError, "vars() argument must have __dict__ attribute" From mwh at codespeak.net Thu May 29 11:26:06 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 11:26:06 +0200 (MEST) Subject: [pypy-svn] rev 641 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030529092606.95F3E5AC87@thoth.codespeak.net> Author: mwh Date: Thu May 29 11:26:06 2003 New Revision: 641 Modified: pypy/trunk/src/pypy/objspace/std/dictobject.py pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py Log: beef up tests of eq_dict_dict; fix bugs thus revealed 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 Thu May 29 11:26:06 2003 @@ -24,6 +24,11 @@ def is_empty(self): return self.w_value is _NoValueInCell + + def __repr__(self): + """ representation for debugging purposes """ + return "%s(%s)" % (self.__class__.__name__, self.w_value) + class W_DictObject(W_Object): @@ -146,15 +151,15 @@ def eq_dict_dict(space, w_left, w_right): if len(w_left.data) != len(w_right.data): - return self.newbool(0) + return space.newbool(0) for w_k, cell in w_left.data: try: w_v = space.getitem(w_right, w_k) except OperationError: - return self.newbool(0) + return space.newbool(0) r = space.is_true(space.eq(cell.w_value, w_v)) if not r: - return r + return space.newbool(r) return space.newbool(1) Modified: pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py Thu May 29 11:26:06 2003 @@ -1,11 +1,10 @@ -import unittest, sys +import sys import testsupport -from pypy.interpreter import unittest_w from pypy.objspace.std import dictobject as dobj from pypy.objspace.std.objspace import * -class TestW_DictObject(unittest_w.TestCase_w): +class TestW_DictObject(testsupport.TestCase): def setUp(self): self.space = StdObjSpace() @@ -61,8 +60,25 @@ space.setitem(d,wk2,space.wrap(2)) cell = space.unwrap(d.cell(space,wk2)) self.assertEqual_w(cell.get(),space.wrap(2)) - - + + def test_wrap_dict(self): + self.assert_(isinstance(self.space.wrap({}), dobj.W_DictObject)) + + + def test_dict_compare(self): + w = self.space.wrap + w0, w1, w2, w3 = map(w, range(4)) + wd1 = self.space.newdict([(w0, w1), (w2, w3)]) + wd2 = self.space.newdict([(w2, w3), (w0, w1)]) + self.assertEqual_w(wd1, wd2) + wd3 = self.space.newdict([(w2, w2), (w0, w1)]) + self.assertNotEqual_w(wd1, wd3) + wd4 = self.space.newdict([(w3, w3), (w0, w1)]) + self.assertNotEqual_w(wd1, wd4) + wd5 = self.space.newdict([(w3, w3)]) + self.assertNotEqual_w(wd1, wd4) + + if __name__ == '__main__': - unittest.main() + testsupport.main() From mwh at codespeak.net Thu May 29 11:30:47 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 11:30:47 +0200 (MEST) Subject: [pypy-svn] rev 642 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030529093047.F01455AC87@thoth.codespeak.net> Author: mwh Date: Thu May 29 11:30:47 2003 New Revision: 642 Modified: pypy/trunk/src/pypy/interpreter/test/test_objspace.py Log: add silly newtuple test Modified: pypy/trunk/src/pypy/interpreter/test/test_objspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_objspace.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_objspace.py Thu May 29 11:30:47 2003 @@ -38,6 +38,12 @@ d = dict(items) w_d = self.space.newdict(items_w) self.assertEqual_w(w_d, w(d)) + + def test_newtuple(self): + w = self.space.wrap + t = tuple(range(10)) + w_t = self.space.newtuple([w(i) for i in t]) + self.assertEqual_w(w_t, w(t)) if __name__ == '__main__': testsupport.main() From mwh at codespeak.net Thu May 29 11:34:35 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 11:34:35 +0200 (MEST) Subject: [pypy-svn] rev 643 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030529093435.6C7145AC87@thoth.codespeak.net> Author: mwh Date: Thu May 29 11:34:35 2003 New Revision: 643 Modified: pypy/trunk/src/pypy/interpreter/test/test_objspace.py Log: add test_is_true Modified: pypy/trunk/src/pypy/interpreter/test/test_objspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_objspace.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_objspace.py Thu May 29 11:34:35 2003 @@ -1,5 +1,8 @@ import testsupport +# this test isn't so much to test that the objspace interface *works* +# -- it's more to test that it's *there* + class TestStdObjectSpace(testsupport.TestCase): def setUp(self): @@ -44,6 +47,15 @@ t = tuple(range(10)) w_t = self.space.newtuple([w(i) for i in t]) self.assertEqual_w(w_t, w(t)) + + def test_is_true(self): + w = self.space.wrap + true = (1==1) + false = (1==0) + w_true = w(true) + w_false = w(false) + self.failUnless(self.space.is_true(w_true)) + self.failIf(self.space.is_true(w_false)) if __name__ == '__main__': testsupport.main() From alex at codespeak.net Thu May 29 11:59:34 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Thu, 29 May 2003 11:59:34 +0200 (MEST) Subject: [pypy-svn] rev 644 - pypy/trunk/src/pypy/interpreter Message-ID: <20030529095934.B9DB55AC87@thoth.codespeak.net> Author: alex Date: Thu May 29 11:59:34 2003 New Revision: 644 Added: pypy/trunk/src/pypy/interpreter/testsupport.py Log: needed here too, to let main.py switch objectspaces easily Added: pypy/trunk/src/pypy/interpreter/testsupport.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/interpreter/testsupport.py Thu May 29 11:59:34 2003 @@ -0,0 +1,63 @@ +""" +Master version of testsupport.py: copy into any subdirectory of pypy +from which scripts need to be run (typically all of the 'test' subdirs) +so that any test can "import testsupport" to ensure the parent of pypy +is on the sys.path -- so that "import pypy.etc.etc." always works. + +Also, this module exposes a member 'TestCase' that is unittest.TestCase +or a subclass thereof supplying extra methods; and a function 'main' +that is unittest.main or the equivalent. + +Furthermore, this module now exposes a member 'objspace' which is +by default class pypy.objspace.trivial.TrivialObjSpace but can be +set to use another objectspace instead; this allows tests to run +under different objectspaces without needing to edit their sources. + +For this setting, use environment variable OBJSPACE and set it to +a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is +also the default if the environment variable is not found or empty +or without any dot in it). + +When run as a script, runs all tests found in files called 'test_*.py' +in the same directory. +""" +import sys, os + +try: + head = this_path = os.path.abspath(__file__) +except NameError: + p = os.path.dirname(sys.argv[0]) + if not p: + p = os.curdir + head = this_path = os.path.abspath(p) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + sys.path.insert(0, head) + break + +import pypy.interpreter.unittest_w +TestCase = pypy.interpreter.unittest_w.TestCase_w +import unittest +main = unittest.main + +from pypy.interpreter import testtools + +objspace_path = os.environ.get('OBJSPACE') +if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + objspace = pypy.objspace.trivial.TrivialObjSpace +else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + objspace = getattr(objspace_module, objspace_classname) + +if __name__ == '__main__': + runner = unittest.TextTestRunner() + runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0]))) From mwh at codespeak.net Thu May 29 11:59:49 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 11:59:49 +0200 (MEST) Subject: [pypy-svn] rev 645 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030529095949.28B015AC87@thoth.codespeak.net> Author: mwh Date: Thu May 29 11:59:48 2003 New Revision: 645 Modified: pypy/trunk/src/pypy/interpreter/test/test_objspace.py Log: add test_newmodule, which tests almost nothing, and test_newfunction which tests almost everything Modified: pypy/trunk/src/pypy/interpreter/test/test_objspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_objspace.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_objspace.py Thu May 29 11:59:48 2003 @@ -56,6 +56,24 @@ w_false = w(false) self.failUnless(self.space.is_true(w_true)) self.failIf(self.space.is_true(w_false)) - + + def test_newmodule(self): + # a shoddy test: + w_mod = self.space.newmodule(self.space.wrap("mod")) + + def test_newfunction(self): + # this tests FAR more than newfunction, but that's probably + # unavoidable + def f(x): + return x + from pypy.interpreter.pycode import PyByteCode + c = PyByteCode() + c._from_code(f.func_code) + w_globals = self.space.newdict([]) + w_defs = self.space.newtuple([]) + w_f = self.space.newfunction(c, w_globals, w_defs) + self.assertEqual_w(self.space.call_function(w_f, self.space.wrap(1)), + self.space.wrap(1)) + if __name__ == '__main__': testsupport.main() From alex at codespeak.net Thu May 29 12:08:14 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Thu, 29 May 2003 12:08:14 +0200 (MEST) Subject: [pypy-svn] rev 647 - pypy/trunk/src/pypy/interpreter Message-ID: <20030529100814.64B955AC87@thoth.codespeak.net> Author: alex Date: Thu May 29 12:08:14 2003 New Revision: 647 Modified: pypy/trunk/src/pypy/interpreter/main.py Log: runs with a specified object-space if environment variable OBJSPACE specifies one (through the logic of testsupport), otherwise (as before) defaults to the standard object space. Modified: pypy/trunk/src/pypy/interpreter/main.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/main.py (original) +++ pypy/trunk/src/pypy/interpreter/main.py Thu May 29 12:08:14 2003 @@ -1,7 +1,8 @@ +import testsupport from pypy.objspace.std import StdObjSpace from pypy.module.builtin import Builtin from pypy.interpreter import executioncontext, baseobjspace, pyframe -import sys +import sys, os def run_string(source, fname, space=None): try: @@ -34,9 +35,14 @@ def main(argv=None): if argv is None: argv = sys.argv + if os.environ.get('OBJSPACE'): + space = testsupport.objspace() + print "Running with %r" % os.environ.get('OBJSPACE') + else: + space = None try: - run_file(argv[1]) + run_file(argv[1], space) except baseobjspace.PyPyError, pypyerr: pypyerr.operationerr.print_detailed_traceback(pypyerr.space) From alex at codespeak.net Thu May 29 12:41:23 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Thu, 29 May 2003 12:41:23 +0200 (MEST) Subject: [pypy-svn] rev 649 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529104123.4B5425AC8A@thoth.codespeak.net> Author: alex Date: Thu May 29 12:41:22 2003 New Revision: 649 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: added a split method (not quite good yet: does not accept being called without arguments, does not work right if len(argument)!=1). Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 12:41:22 2003 @@ -1,6 +1,7 @@ from pypy.objspace.std.objspace import * from intobject import W_IntObject from sliceobject import W_SliceObject +from listobject import W_ListObject from instmethobject import W_InstMethObject from pypy.interpreter.extmodule import make_builtin_func @@ -15,9 +16,9 @@ """ representation for debugging purposes """ return "%s(%r)" % (w_self.__class__.__name__, w_self.value) def nonzero(w_self): - return W_IntObject(self.space, w_self.value != 0) + return W_IntObject(w_self.space, w_self.value != 0) def hash(w_self): - return W_IntObject(self, hash(self.value)) + return W_IntObject(w_self, hash(w_self.value)) def join(w_self, w_list): firstelem = 1 @@ -28,13 +29,34 @@ firstelem = 0 else: res = res + w_self.value + w_item.value - return W_StringObject(w_self.space, res) + def split(w_self, w_by=None): + res = [] + inword = 0 + for ch in w_self.value: + if ch==w_by.value or w_by is None and ch.isspace(): + if inword: + inword = 0 + elif w_by is not None: + res.append('') + else: + if inword: + res[-1] += ch + else: + res.append(ch) + inword = 1 + for i in range(len(res)): + res[i] = W_StringObject(w_self.space, res[i]) + return W_ListObject(w_self.space, res) + def getattr_str(space, w_list, w_attr): if space.is_true(space.eq(w_attr, space.wrap('join'))): w_builtinfn = make_builtin_func(space, W_StringObject.join) return W_InstMethObject(space, w_list, w_builtinfn) + elif space.is_true(space.eq(w_attr, space.wrap('split'))): + w_builtinfn = make_builtin_func(space, W_StringObject.split) + return W_InstMethObject(space, w_list, w_builtinfn) raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_str, W_StringObject, W_ANY) From mwh at codespeak.net Thu May 29 12:42:35 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 12:42:35 +0200 (MEST) Subject: [pypy-svn] rev 650 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030529104235.413DE5AC8A@thoth.codespeak.net> Author: mwh Date: Thu May 29 12:42:34 2003 New Revision: 650 Added: pypy/trunk/src/pypy/objspace/std/test/test_stdobjspace.py Modified: pypy/trunk/src/pypy/objspace/std/objspace.py Log: howl if we try to wrap an already wrapped object. add test for this. 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 Thu May 29 12:42:34 2003 @@ -57,6 +57,8 @@ "Wraps the Python value 'x' into one of the wrapper classes." if x is None: return self.w_None + if isinstance(x, W_Object): + raise TypeError, "attempt to wrap already wrapped object: %s"%(x,) if isinstance(x, int): if isinstance(x, booltype): return self.newbool(x) Added: pypy/trunk/src/pypy/objspace/std/test/test_stdobjspace.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/test/test_stdobjspace.py Thu May 29 12:42:34 2003 @@ -0,0 +1,20 @@ +import testsupport + +from pypy.objspace.std import StdObjSpace + +class TestW_StdObjSpace(testsupport.TestCase): + + def setUp(self): + self.space = StdObjSpace() + + def tearDown(self): + pass + + def test_wrap_wrap(self): + self.assertRaises(TypeError, + self.space.wrap, + self.space.wrap(0)) + + +if __name__ == '__main__': + testsupport.main() From alex at codespeak.net Thu May 29 12:50:44 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Thu, 29 May 2003 12:50:44 +0200 (MEST) Subject: [pypy-svn] rev 653 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030529105044.4932D5AC87@thoth.codespeak.net> Author: alex Date: Thu May 29 12:50:43 2003 New Revision: 653 Added: pypy/trunk/src/pypy/interpreter/test/s1.py Log: almost like our goal program except that str.split needs an explicit parameter Added: pypy/trunk/src/pypy/interpreter/test/s1.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/interpreter/test/s1.py Thu May 29 12:50:43 2003 @@ -0,0 +1,18 @@ + +### a trivial program to test strings, lists, functions and methods ### +## tiny change wrt goal so far needed: explicit parameter to str.split + +def addstr(s1,s2): + return s1 + s2 + +str = "an interesting string" +str2 = 'another::string::xxx::y:aa' +str3 = addstr(str,str2) +arr = [] +for word in str.split(' '): + if word in str2.split('::'): + arr.append(word) +print ''.join(arr) +print "str + str2 = ", str3 + + From mwh at codespeak.net Thu May 29 13:12:30 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 13:12:30 +0200 (MEST) Subject: [pypy-svn] rev 654 - pypy/trunk/src/pypy/objspace Message-ID: <20030529111230.B81D85AC87@thoth.codespeak.net> Author: mwh Date: Thu May 29 13:12:30 2003 New Revision: 654 Modified: pypy/trunk/src/pypy/objspace/trivial.py Log: from the "how the hell did this ever work" department, stop wrapping certain exceptions in OperationErrors Modified: pypy/trunk/src/pypy/objspace/trivial.py ============================================================================== --- pypy/trunk/src/pypy/objspace/trivial.py (original) +++ pypy/trunk/src/pypy/objspace/trivial.py Thu May 29 13:12:30 2003 @@ -219,6 +219,7 @@ args = (callable.im_self,) + args callable = callable.im_func if isinstance(callable, types.FunctionType): + raise Exception, "shouldn't get here, methinks" bytecode = callable.func_code ec = self.getexecutioncontext() w_globals = self.wrap(callable.func_globals) @@ -229,7 +230,4 @@ frame.setargs(args, kwds, w_defaults) return ec.eval_frame(frame) else: - try: - return apply(callable, args, kwds or {}) - except: - raise OperationError(*sys.exc_info()[:2]) + return apply(callable, args, kwds or {}) From lac at codespeak.net Thu May 29 13:37:33 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Thu, 29 May 2003 13:37:33 +0200 (MEST) Subject: [pypy-svn] rev 655 - in pypy/trunk/src/pypy/module: . test Message-ID: <20030529113733.D75775AC87@thoth.codespeak.net> Author: lac Date: Thu May 29 13:37:33 2003 New Revision: 655 Added: pypy/trunk/src/pypy/module/test/test_apply.py Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: Wrote trivial unit test for apply. This assumes that if it ever works, it always works, which is true because apply is just a synonym for return function(*args, **kwds). However, if * or ** are broken, somebody else will have to discover this. This unit test is too trivial. 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 Thu May 29 13:37:33 2003 @@ -1,4 +1,5 @@ def apply(function, args, kwds={}): + """call a function (or other callable object) and return its result""" return function(*args, **kwds) def map(function, *collections): Added: pypy/trunk/src/pypy/module/test/test_apply.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/test_apply.py Thu May 29 13:37:33 2003 @@ -0,0 +1,38 @@ +import testsupport +from pypy.module.builtin_app import apply, min, max + +def myminmax(*arr, **dict): + # trivial function which has the signature *args, **kw + v = list(arr) + dict.values() + return min(v), max(v) + +class TestApply(testsupport.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + +# This is a very trivial series of tests. If apply is subtlely broken, +# we will have to find out some other way. + + def test_trivial_listonly(self): + self.assertEqual(apply(myminmax, + [-1,-2,-3,-4]), + (-4, -1)) + + def test_trivial_dictonly(self): + self.assertEqual(apply(myminmax, + [], {'null' : 0, 'one': 1, 'two' : 2}), + (0, 2)) + def test_trivial(self): + self.assertEqual(apply(myminmax, + [-1,-2,-3,-4], + {'null' : 0, 'one': 1, 'two' : 2}), + (-4, 2)) + +if __name__ == '__main__': + testsupport.main() + + From lac at codespeak.net Thu May 29 14:03:16 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Thu, 29 May 2003 14:03:16 +0200 (MEST) Subject: [pypy-svn] rev 656 - pypy/trunk/src/pypy/module/test Message-ID: <20030529120316.CBADE5AC87@thoth.codespeak.net> Author: lac Date: Thu May 29 14:03:16 2003 New Revision: 656 Added: pypy/trunk/src/pypy/module/test/test_functional.py - copied unchanged from rev 654, pypy/trunk/src/pypy/module/test/test_funtional.py Log: Just fix the typo in this files name. From tomek at codespeak.net Thu May 29 14:08:02 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 14:08:02 +0200 (MEST) Subject: [pypy-svn] rev 657 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529120802.DA8A45AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 14:08:02 2003 New Revision: 657 Added: pypy/trunk/src/pypy/objspace/std/rarray.py Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: small changes.. Added: pypy/trunk/src/pypy/objspace/std/rarray.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/rarray.py Thu May 29 14:08:02 2003 @@ -0,0 +1,67 @@ +#The goal is to use a primitive array, which we +#later implement directly in c. We want to get +#rid of cpython dependencies. We wrap the original +#array module to see, which methods do we need + +import array + +def CharArrayFromStr(newstr): + b = CharArray() + b.setvalue(newstr) + return b + +def CharArraySize(size): + b = CharArray() + b.setsize(size) + return b + +class CharArray: + def __init__(self): + self._value = None + + def setvalue(self, value): + self._value = array.array('c', value) + self.len = len(value) + + def __repr__(self): + return self._value.tostring() + + + def hash(self): + #of cource, it doesn't make much sense hier, but the hash function + #also has to be implemented in c + return hash(self.value()) + + def value(self): + """returns back the string""" + return self._value.tostring() + + def getsubstring(self, startat, length): + """returns back the substring""" + return self._value[startat:startat+length].tostring() + + def charat(self, idx): + """returns char at the index""" + return self._value[idx] + + def setsize(self, size): + """set size of the buffer to size""" + self._value = array.array('c', ' ' * size) + self.len = size + + def append(self, newstr): + """append the new string to the buffer""" + newstr = self._value.tostring() + newstr + self._value = array.array('c', newstr) + self.len = len(newstr) + + def setsubstring(self, idx, substr): + """set the buffer to substr at the idx""" + #it's a hack, but this is not very important, while + #we are going to reimplement this stuff in c + list = self._value.tolist() + for char in substr: + list[idx] = char + idx = idx + 1 + self._value = array.array('c', "".join(list)) + Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 14:08:02 2003 @@ -5,31 +5,51 @@ from instmethobject import W_InstMethObject from pypy.interpreter.extmodule import make_builtin_func +from rarray import CharArrayFromStr + applicationfile = StdObjSpace.AppFile(__name__) class W_StringObject(W_Object): def __init__(w_self, space, str): W_Object.__init__(w_self, space) - w_self.value = str + w_self._value = CharArrayFromStr(str) + def __repr__(w_self): """ representation for debugging purposes """ - return "%s(%r)" % (w_self.__class__.__name__, w_self.value) + return "%s(%r)" % (w_self.__class__.__name__, w_self._value.value()) + def nonzero(w_self): - return W_IntObject(w_self.space, w_self.value != 0) + return W_IntObject(self.space, w_self._value.len != 0) + def hash(w_self): - return W_IntObject(w_self, hash(w_self.value)) + return W_IntObject(self, self._value.hash()) def join(w_self, w_list): - firstelem = 1 - res = "" - for w_item in w_list.wrappeditems: - if firstelem: - res = w_item.value - firstelem = 0 - else: - res = res + w_self.value + w_item.value - return W_StringObject(w_self.space, res) + if w_list: + firstelem = 1 + listlen = 0 + for w_item in w_list.wrappeditems: + reslen = reslen + len(w_item) + lislen = listlen + 1 + + reslen = reslen + (listlen - 1) * w_self._value.len + res = CharArraySize(reslen) + + pos = 0 + for w_item in w_list.wrappeditems: + if firstelem: + res.setsubstring(idx, w_item._value) + idx = idx + w_item._value.len + firstelem = 0 + else: + res.setsubstring(idx, w_self._value) + idx = idx + w_self._value.len + res.setsubstring(idx, w_item._value) + idx = idx + w_item._value.len + return W_StringObject(w_self.space, res.value()) + else: + return W_StringObject(w_self.space, "") def split(w_self, w_by=None): res = [] @@ -63,49 +83,49 @@ def str_unwrap(space, w_str): - return w_str.value + return w_str._value.value() StdObjSpace.unwrap.register(str_unwrap, W_StringObject) def str_str_lt(space, w_str1, w_str2): - i = w_str1.value - j = w_str2.value + i = w_str1._value.value() + j = w_str2._value.value() return space.newbool( i < j ) StdObjSpace.lt.register(str_str_lt, W_StringObject, W_StringObject) def str_str_le(space, w_str1, w_str2): - i = w_str1.value - j = w_str2.value + i = w_str1._value.value() + j = w_str2._value.value() return space.newbool( i <= j ) StdObjSpace.le.register(str_str_le, W_StringObject, W_StringObject) def str_str_eq(space, w_str1, w_str2): - i = w_str1.value - j = w_str2.value + i = w_str1._value.value() + j = w_str2._value.value() return space.newbool( i == j ) StdObjSpace.eq.register(str_str_eq, W_StringObject, W_StringObject) def str_str_ne(space, w_str1, w_str2): - i = w_str1.value - j = w_str2.value + i = w_str1._value.value() + j = w_str2._value.value() return space.newbool( i != j ) StdObjSpace.ne.register(str_str_ne, W_StringObject, W_StringObject) def str_str_gt(space, w_str1, w_str2): - i = w_str1.value - j = w_str2.value + i = w_str1._value.value() + j = w_str2._value.value() return space.newbool( i > j ) StdObjSpace.gt.register(str_str_gt, W_StringObject, W_StringObject) def str_str_ge(space, w_str1, w_str2): - i = w_str1.value - j = w_str2.value + i = w_str1._value.value() + j = w_str2._value.value() return space.newbool( i >= j ) StdObjSpace.ge.register(str_str_ge, W_StringObject, W_StringObject) def getitem_str_int(space, w_str, w_int): - return W_StringObject(space, w_str.value[w_int.intval]) + return W_StringObject(space, w_str._value.value()[w_int.intval]) StdObjSpace.getitem.register(getitem_str_int, W_StringObject, W_IntObject) @@ -117,7 +137,7 @@ W_StringObject, W_SliceObject) def add_str_str(space, w_left, w_right): - return W_StringObject(space, w_left.value + w_right.value) + return W_StringObject(space, w_left._value.value() + w_right._value.value()) StdObjSpace.add.register(add_str_str, W_StringObject, W_StringObject) @@ -128,7 +148,7 @@ notImplemented def len_str(space, w_str): - return space.wrap(len(w_str.value)) + return space.wrap(w_str._value.len) StdObjSpace.len.register(len_str, W_StringObject) From tismer at codespeak.net Thu May 29 14:08:51 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 14:08:51 +0200 (MEST) Subject: [pypy-svn] rev 659 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529120851.C169E5AC87@thoth.codespeak.net> Author: tismer Date: Thu May 29 14:08:51 2003 New Revision: 659 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: re-implemented listobject completely, similar to the CPython implementation. A lot is still missing Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 14:08:51 2003 @@ -3,65 +3,80 @@ from sliceobject import W_SliceObject from instmethobject import W_InstMethObject from pypy.interpreter.extmodule import make_builtin_func - +from restricted_int import r_int, r_uint class W_ListObject(W_Object): def __init__(w_self, space, wrappeditems): W_Object.__init__(w_self, space) - w_self.wrappeditems = wrappeditems # a list of wrapped values + w_self.ob_item = [] + w_self.ob_size = 0 + newlen = len(wrappeditems) + list_resize(w_self, newlen) + w_self.ob_size = newlen + items = w_self.ob_item + p = newlen + while p: + p -= 1 + items[p] = wrappeditems[p] def __repr__(w_self): """ representation for debugging purposes """ - reprlist = [repr(w_item) for w_item in w_self.wrappeditems] + reprlist = [repr(w_item) for w_item in w_self.ob_item[:self.ob_size]] return "%s(%s)" % (w_self.__class__.__name__, ', '.join(reprlist)) def append(w_self, w_obj): - w_self.wrappeditems.append(w_obj) - return w_self.space.w_None + return list_append(w_self.space, w_self, w_obj) + + def insert(w_self, w_idx, w_obj): + return list_insert(w_self.space, w_self, w_idx, w_obj) def list_unwrap(space, w_list): - items = [space.unwrap(w_item) for w_item in w_list.wrappeditems] + items = [space.unwrap(w_item) for w_item in w_list.ob_item[:w_list.ob_size]] return list(items) StdObjSpace.unwrap.register(list_unwrap, W_ListObject) def list_is_true(space, w_list): - return not not w_list.wrappeditems + return not not w_list.ob_size StdObjSpace.is_true.register(list_is_true, W_ListObject) def list_len(space, w_list): - result = len(w_list.wrappeditems) + result = w_list.ob_size return W_IntObject(space, result) StdObjSpace.len.register(list_len, W_ListObject) def getitem_list_int(space, w_list, w_index): - items = w_list.wrappeditems - try: - w_item = items[w_index.intval] - except IndexError: + items = w_list.ob_item + idx = w_index.intval + if idx < 0: idx += w_list.ob_size + if idx < 0 or idx >= w_list.ob_size: raise OperationError(space.w_IndexError, space.wrap("list index out of range")) + w_item = items[idx] return w_item StdObjSpace.getitem.register(getitem_list_int, W_ListObject, W_IntObject) def getitem_list_slice(space, w_list, w_slice): - items = w_list.wrappeditems - w_length = space.wrap(len(items)) + items = w_list.ob_item + w_length = space.wrap(w_list.ob_size) w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length) start = space.unwrap(w_start) step = space.unwrap(w_step) slicelength = space.unwrap(w_slicelength) assert slicelength >= 0 - subitems = [None] * slicelength + w_res = W_ListObject(space, []) + list_resize(w_res, slicelength) + subitems = w_res.ob_item for i in range(slicelength): subitems[i] = items[start] start += step - return W_ListObject(space, subitems) + w_res.ob_size = slicelength + return w_res StdObjSpace.getitem.register(getitem_list_slice, W_ListObject, W_SliceObject) @@ -72,16 +87,39 @@ StdObjSpace.iter.register(list_iter, W_ListObject) def list_add(space, w_list1, w_list2): - items1 = w_list1.wrappeditems - items2 = w_list2.wrappeditems - return W_ListObject(space, items1 + items2) + w_res = W_ListObject(space, []) + newlen = w_list1.ob_size + w_list2.ob_size + list_resize(w_res, newlen) + p = 0 + items = w_res.ob_item + src = w_list1.ob_item + for i in range(w_list1.ob_size): + items[p] = src[i] + p += 1 + src = w_list2.ob_item + for i in range(w_list2.ob_size): + items[p] = src[i] + p += 1 + w_res.ob_size = p + return w_res StdObjSpace.add.register(list_add, W_ListObject, W_ListObject) def list_int_mul(space, w_list, w_int): - items = w_list.wrappeditems + w_res = W_ListObject(space, []) times = w_int.intval - return W_ListObject(space, items * times) + src = w_list.ob_item + size = w_list.ob_size + newlen = size * times # XXX check overflow + list_resize(w_res, newlen) + items = w_res.ob_item + p = 0 + for _ in range(times): + for i in range(size): + items[p] = src[i] + p += 1 + w_res.ob_size = p + return w_res StdObjSpace.mul.register(list_int_mul, W_ListObject, W_IntObject) @@ -91,45 +129,49 @@ StdObjSpace.mul.register(int_list_mul, W_IntObject, W_ListObject) def list_eq(space, w_list1, w_list2): - items1 = w_list1.wrappeditems - items2 = w_list2.wrappeditems - if len(items1) != len(items2): + items1 = w_list1.ob_item + items2 = w_list2.ob_item + if w_list1.ob_size != w_list2.ob_size: return space.w_False - for item1, item2 in zip(items1, items2): - if not space.is_true(space.eq(item1, item2)): + for i in range(w_list1.ob_size): + if not space.is_true(space.eq(items1[i], items2[i])): return space.w_False return space.w_True StdObjSpace.eq.register(list_eq, W_ListObject, W_ListObject) -# upto here, lists are nearly identical to tuples. -# XXX have to add over-allocation! +# upto here, lists are nearly identical to tuples, despite the +# fact that we now support over-allocation! def setitem_list_int(space, w_list, w_index, w_any): - items = w_list.wrappeditems - try: - items[w_index.intval] = w_any - except IndexError: + items = w_list.ob_item + idx = w_index.intval + if idx < 0: idx += w_list.ob_size + if idx < 0 or idx >= w_list.ob_size: raise OperationError(space.w_IndexError, space.wrap("list index out of range")) + items[idx] = w_any return space.w_None StdObjSpace.setitem.register(setitem_list_int, W_ListObject, W_IntObject, W_ANY) # not trivial! def setitem_list_slice(space, w_list, w_slice, w_list2): - items = w_list.wrappeditems - w_length = space.wrap(len(items)) + items = w_list.ob_item + w_length = space.wrap(w_list.ob_size) w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length) start = space.unwrap(w_start) step = space.unwrap(w_step) slicelength = space.unwrap(w_slicelength) assert slicelength >= 0 - subitems = [None] * slicelength + w_res = W_ListObject(space, []) + list_resize(w_res, slicelength) + subitems = w_res.ob_item for i in range(slicelength): subitems[i] = items[start] start += step - return W_ListObject(space, subitems) + w_res.ob_size = slicelength + return w_res StdObjSpace.setitem.register(setitem_list_slice, W_ListObject, W_SliceObject, W_ANY) @@ -137,22 +179,110 @@ if space.is_true(space.eq(w_attr, space.wrap('append'))): w_builtinfn = make_builtin_func(space, W_ListObject.append) return W_InstMethObject(space, w_list, w_builtinfn) + if space.is_true(space.eq(w_attr, space.wrap('insert'))): + w_builtinfn = make_builtin_func(space, W_ListObject.insert) + return W_InstMethObject(space, w_list, w_builtinfn) raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_list, W_ListObject, W_ANY) +# adapted C code +def roundupsize(n): + nbits = r_uint(0) + n2 = n >> 5 + +## /* Round up: +## * If n < 256, to a multiple of 8. +## * If n < 2048, to a multiple of 64. +## * If n < 16384, to a multiple of 512. +## * If n < 131072, to a multiple of 4096. +## * If n < 1048576, to a multiple of 32768. +## * If n < 8388608, to a multiple of 262144. +## * If n < 67108864, to a multiple of 2097152. +## * If n < 536870912, to a multiple of 16777216. +## * ... +## * If n < 2**(5+3*i), to a multiple of 2**(3*i). +## * +## * This over-allocates proportional to the list size, making room +## * for additional growth. The over-allocation is mild, but is +## * enough to give linear-time amortized behavior over a long +## * sequence of appends() in the presence of a poorly-performing +## * system realloc() (which is a reality, e.g., across all flavors +## * of Windows, with Win9x behavior being particularly bad -- and +## * we've still got address space fragmentation problems on Win9x +## * even with this scheme, although it requires much longer lists to +## * provoke them than it used to). +## */ + while 1: + n2 >>= 3 + nbits += 3 + if not n2 : + break + return ((n >> nbits) + 1) << nbits + +# before we have real arrays, +# we use lists, allocated to fixed size. +# XXX memory overflow is ignored here. +# See listobject.c for reference. + +for_later = """ +#define NRESIZE(var, type, nitems) \ +do { \ + size_t _new_size = roundupsize(nitems); \ + if (_new_size <= ((~(size_t)0) / sizeof(type))) \ + PyMem_RESIZE(var, type, _new_size); \ + else \ + var = NULL; \ +} while (0) +""" + +def list_resize(w_list, newlen): + if newlen > len(w_list.ob_item): + true_size = roundupsize(newlen) + old_items = w_list.ob_item + w_list.ob_item = items = [None] * true_size + for p in range(len(old_items)): + items[p] = old_items[p] + +def ins1(w_list, where, w_any): + print w_list.ob_size, w_list.ob_item + list_resize(w_list, w_list.ob_size+1) + print w_list.ob_size, w_list.ob_item + size = w_list.ob_size + items = w_list.ob_item + if where < 0: + where += size + if where < 0: + where = 0 + if (where > size): + where = size + for i in range(size, where, -1): + items[i] = items[i-1] + print w_list.ob_size, w_list.ob_item + items[where] = w_any + print w_list.ob_size, w_list.ob_item + w_list.ob_size += 1 + print w_list.ob_size, w_list.ob_item + +def list_insert(space, w_list, w_where, w_any): + ins1(w_list, w_where.intval, w_any) + return space.w_None + +def list_append(space, w_list, w_any): + ins1(w_list, w_list.ob_size, w_any) + return space.w_None """ static PyMethodDef list_methods[] = { - {"append", (PyCFunction)listappend, METH_O, append_doc}, - {"insert", (PyCFunction)listinsert, METH_VARARGS, insert_doc}, - {"extend", (PyCFunction)listextend, METH_O, extend_doc}, - {"pop", (PyCFunction)listpop, METH_VARARGS, pop_doc}, - {"remove", (PyCFunction)listremove, METH_O, remove_doc}, - {"index", (PyCFunction)listindex, METH_O, index_doc}, - {"count", (PyCFunction)listcount, METH_O, count_doc}, - {"reverse", (PyCFunction)listreverse, METH_NOARGS, reverse_doc}, - {"sort", (PyCFunction)listsort, METH_VARARGS, sort_doc}, - {NULL, NULL} /* sentinel */ + {"append", (PyCFunction)listappend, METH_O, append_doc}, + {"insert", (PyCFunction)listinsert, METH_VARARGS, insert_doc}, + {"extend", (PyCFunction)listextend, METH_O, extend_doc}, + {"pop", (PyCFunction)listpop, METH_VARARGS, pop_doc}, + {"remove", (PyCFunction)listremove, METH_O, remove_doc}, + {"index", (PyCFunction)listindex, METH_O, index_doc}, + {"count", (PyCFunction)listcount, METH_O, count_doc}, + {"reverse", (PyCFunction)listreverse, METH_NOARGS, reverse_doc}, + {"sort", (PyCFunction)listsort, METH_VARARGS, sort_doc}, + {NULL, NULL} /* sentinel */ }; """ From mwh at codespeak.net Thu May 29 14:17:05 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 14:17:05 +0200 (MEST) Subject: [pypy-svn] rev 660 - pypy/trunk/src/pypy/interpreter/test Message-ID: <20030529121705.40EB15AC87@thoth.codespeak.net> Author: mwh Date: Thu May 29 14:17:04 2003 New Revision: 660 Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Log: test for make_builtin_func -- more to follow Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Thu May 29 14:17:04 2003 @@ -70,5 +70,23 @@ 'somedata': BM_with_appdata.somedata} ) self.assertEqual(thedata, 'twentythree') + +class TestPyBuiltinCode(testsupport.TestCase): + + def setUp(self): + self.space = testsupport.objspace() + + def tearDown(self): + pass + + def test_simple(self): + def f(w_x): + return w_x + builtin_f = extmodule.make_builtin_func(self.space, f) + w_input = self.space.wrap(42) + w_res = self.space.call_function(builtin_f, w_input) + self.assertEqual_w(w_res, w_input) + + if __name__ == '__main__': testsupport.main() From mwh at codespeak.net Thu May 29 14:24:47 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 14:24:47 +0200 (MEST) Subject: [pypy-svn] rev 661 - pypy/trunk/src/pypy/interpreter Message-ID: <20030529122447.CA9685AC87@thoth.codespeak.net> Author: mwh Date: Thu May 29 14:24:46 2003 New Revision: 661 Modified: pypy/trunk/src/pypy/interpreter/pycode.py Log: cosmetic + typo fix Modified: pypy/trunk/src/pypy/interpreter/pycode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/pycode.py (original) +++ pypy/trunk/src/pypy/interpreter/pycode.py Thu May 29 14:24:46 2003 @@ -61,8 +61,8 @@ w_bytecode = space.wrap(co) w_arguments = space.gethelper(appfile).call( "decode_code_arguments", [w_arguments, w_kwargs, w_defaults, - w_closure, w_bytecode]) - # we assume that decode_codee_arguments() gives us a dictionary + w_closure, w_bytecode]) + # we assume that decode_code_arguments() gives us a dictionary # of the correct length. return w_arguments From mwh at codespeak.net Thu May 29 14:26:30 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 14:26:30 +0200 (MEST) Subject: [pypy-svn] rev 662 - in pypy/trunk/src/pypy/interpreter: . test Message-ID: <20030529122630.77F065AC87@thoth.codespeak.net> Author: mwh Date: Thu May 29 14:26:30 2003 New Revision: 662 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Log: support default arguments for builtin methods Modified: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Thu May 29 14:26:30 2003 @@ -39,7 +39,6 @@ def eval_code(self, space, w_globals, w_locals): # this isn't quite complete: varargs and kwargs are missing - # defaults are not here either args = [] for argname in self.co_varnames: w_arg = space.getitem(w_locals, space.wrap(argname)) @@ -47,9 +46,10 @@ w_ret = self.func(*args) return w_ret -def make_builtin_func(space,func,boundmethod=False): - code = PyBuiltinCode(func,boundmethod) - w_function = space.newfunction(code, space.w_None, None) +def make_builtin_func(space, func, boundmethod=False): + code = PyBuiltinCode(func, boundmethod) + w_defaults = space.wrap(func.func_defaults) + w_function = space.newfunction(code, space.w_None, w_defaults) return w_function class BuiltinModule: Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Thu May 29 14:26:30 2003 @@ -87,6 +87,18 @@ w_res = self.space.call_function(builtin_f, w_input) self.assertEqual_w(w_res, w_input) + def test_default(self): + space = self.space + w = space.wrap + def f(w_x, w_y=23): + return space.add(w_x, w_y) + builtin_f = extmodule.make_builtin_func(space, f) + w_input = w(42) + w_res = space.call_function(builtin_f, w_input) + self.assertEqual_w(w_res, w(65)) + w_res = space.call_function(builtin_f, w_input, w(100)) + self.assertEqual_w(w_res, w(142)) + if __name__ == '__main__': testsupport.main() From alex at codespeak.net Thu May 29 14:30:19 2003 From: alex at codespeak.net (alex at codespeak.net) Date: Thu, 29 May 2003 14:30:19 +0200 (MEST) Subject: [pypy-svn] rev 663 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529123019.B1C9E5AC87@thoth.codespeak.net> Author: alex Date: Thu May 29 14:30:19 2003 New Revision: 663 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: need to fix split by spaces... Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 14:30:19 2003 @@ -51,15 +51,13 @@ else: return W_StringObject(w_self.space, "") - def split(w_self, w_by=None): + def splitByWhitespace(w_self): res = [] inword = 0 for ch in w_self.value: - if ch==w_by.value or w_by is None and ch.isspace(): + if ch.isspace(): if inword: inword = 0 - elif w_by is not None: - res.append('') else: if inword: res[-1] += ch @@ -70,6 +68,21 @@ res[i] = W_StringObject(w_self.space, res[i]) return W_ListObject(w_self.space, res) + def split(w_self, w_by=None): + if w_by is None: return w_self.splitByWhiteSpace + res = [] + start = 0 + while 1: + next = w_self.value.find(w_by.value, start) + if next < 0: + res.append(w_self.value[start:]) + break + res.append(w_self.value[start:next]) + start = next + len(w_by.value) + for i in range(len(res)): + res[i] = W_StringObject(w_self.space, res[i]) + return W_ListObject(w_self.space, res) + def getattr_str(space, w_list, w_attr): if space.is_true(space.eq(w_attr, space.wrap('join'))): w_builtinfn = make_builtin_func(space, W_StringObject.join) From tomek at codespeak.net Thu May 29 14:47:54 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 14:47:54 +0200 (MEST) Subject: [pypy-svn] rev 664 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529124754.305195AC87@thoth.codespeak.net> Author: tomek Date: Thu May 29 14:47:53 2003 New Revision: 664 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: join now works Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 14:47:53 2003 @@ -5,7 +5,7 @@ from instmethobject import W_InstMethObject from pypy.interpreter.extmodule import make_builtin_func -from rarray import CharArrayFromStr +from rarray import CharArrayFromStr, CharArraySize applicationfile = StdObjSpace.AppFile(__name__) @@ -26,27 +26,29 @@ return W_IntObject(self, self._value.hash()) def join(w_self, w_list): - if w_list: + list = w_self.space.unpackiterable(w_list) + if list: firstelem = 1 listlen = 0 - for w_item in w_list.wrappeditems: - reslen = reslen + len(w_item) - lislen = listlen + 1 + reslen = 0 + for w_item in list: + reslen = reslen + w_item._value.len + listlen = listlen + 1 reslen = reslen + (listlen - 1) * w_self._value.len res = CharArraySize(reslen) pos = 0 - for w_item in w_list.wrappeditems: + for w_item in list: if firstelem: - res.setsubstring(idx, w_item._value) - idx = idx + w_item._value.len + res.setsubstring(pos, w_item._value.value()) + pos = pos + w_item._value.len firstelem = 0 else: - res.setsubstring(idx, w_self._value) - idx = idx + w_self._value.len - res.setsubstring(idx, w_item._value) - idx = idx + w_item._value.len + res.setsubstring(pos, w_self._value.value()) + pos = pos + w_self._value.len + res.setsubstring(pos, w_item._value.value()) + pos = pos + w_item._value.len return W_StringObject(w_self.space, res.value()) else: return W_StringObject(w_self.space, "") From mwh at codespeak.net Thu May 29 14:54:06 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 14:54:06 +0200 (MEST) Subject: [pypy-svn] rev 665 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529125406.D51E75AC87@thoth.codespeak.net> Author: mwh Date: Thu May 29 14:54:06 2003 New Revision: 665 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: change in string implementation broke alex's split implementation; fix Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 14:54:06 2003 @@ -56,7 +56,8 @@ def splitByWhitespace(w_self): res = [] inword = 0 - for ch in w_self.value: + value = w_self._value.value() + for ch in value: if ch.isspace(): if inword: inword = 0 @@ -71,16 +72,18 @@ return W_ListObject(w_self.space, res) def split(w_self, w_by=None): - if w_by is None: return w_self.splitByWhiteSpace + if w_by is w_self.space.w_None: return w_self.splitByWhitespace() res = [] start = 0 + value = w_self._value.value() + by = w_by._value.value() while 1: - next = w_self.value.find(w_by.value, start) + next = value.find(by, start) if next < 0: - res.append(w_self.value[start:]) + res.append(value[start:]) break - res.append(w_self.value[start:next]) - start = next + len(w_by.value) + res.append(value[start:next]) + start = next + len(by) for i in range(len(res)): res[i] = W_StringObject(w_self.space, res[i]) return W_ListObject(w_self.space, res) From tomek at codespeak.net Thu May 29 15:03:56 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 15:03:56 +0200 (MEST) Subject: [pypy-svn] rev 666 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529130356.CDF485AC87@thoth.codespeak.net> Author: tomek Date: Thu May 29 15:03:56 2003 New Revision: 666 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: The implementation of == is now in python Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 15:03:56 2003 @@ -118,9 +118,15 @@ StdObjSpace.le.register(str_str_le, W_StringObject, W_StringObject) def str_str_eq(space, w_str1, w_str2): - i = w_str1._value.value() - j = w_str2._value.value() - return space.newbool( i == j ) + val1 = w_str1._value + val2 = w_str2._value + if val1.len == val2.len: + for i in range(val1.len): + if ord(val1.charat(i)) != ord(val2.charat(i)): + return space.w_False + return space.w_True + else: + return space.w_False StdObjSpace.eq.register(str_str_eq, W_StringObject, W_StringObject) def str_str_ne(space, w_str1, w_str2): From mwh at codespeak.net Thu May 29 15:05:20 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 15:05:20 +0200 (MEST) Subject: [pypy-svn] rev 667 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529130520.ACC555AC8A@thoth.codespeak.net> Author: mwh Date: Thu May 29 15:05:20 2003 New Revision: 667 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: change a self to w_self Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 15:05:20 2003 @@ -22,7 +22,7 @@ def __repr__(w_self): """ representation for debugging purposes """ - reprlist = [repr(w_item) for w_item in w_self.ob_item[:self.ob_size]] + reprlist = [repr(w_item) for w_item in w_self.ob_item[:w_self.ob_size]] return "%s(%s)" % (w_self.__class__.__name__, ', '.join(reprlist)) def append(w_self, w_obj): From mwh at codespeak.net Thu May 29 15:09:35 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 15:09:35 +0200 (MEST) Subject: [pypy-svn] rev 668 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030529130935.7AC905AC8A@thoth.codespeak.net> Author: mwh Date: Thu May 29 15:09:35 2003 New Revision: 668 Modified: pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py Log: this is the file I tend to copy to create new tests, so modernize it Modified: pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py Thu May 29 15:09:35 2003 @@ -1,11 +1,8 @@ -import unittest, sys import testsupport -from pypy.interpreter import unittest_w -from pypy.objspace.std import noneobject as nobj -from pypy.objspace.std.objspace import * +from pypy.objspace.std.objspace import StdObjSpace -class TestW_NoneObject(unittest_w.TestCase_w): +class TestW_NoneObject(testsupport.TestCase): def setUp(self): self.space = StdObjSpace() @@ -25,4 +22,4 @@ if __name__ == '__main__': - unittest.main() + testsupport.main() From lac at codespeak.net Thu May 29 15:10:10 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Thu, 29 May 2003 15:10:10 +0200 (MEST) Subject: [pypy-svn] rev 669 - in pypy/trunk/src/pypy/module: . test Message-ID: <20030529131010.CEC605AC8A@thoth.codespeak.net> Author: lac Date: Thu May 29 15:10:10 2003 New Revision: 669 Modified: pypy/trunk/src/pypy/module/builtin_app.py pypy/trunk/src/pypy/module/test/test_functional.py Log: Added trivial functions to test map. Fixed bug where map(None) did not raise a TypeError. 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 Thu May 29 15:10:10 2003 @@ -3,7 +3,15 @@ return function(*args, **kwds) def map(function, *collections): - if len(collections) == 1: + """does 3 separate things. + 1. if function is None, return a list of tuples, each with one + item from each collection. If the collections have different + lengths, shorter ones are padded with None.""" + + if len(collections) == 0: + raise TypeError, "map() requires at least one sequence" + + elif len(collections) == 1: #it's the most common case, so make it faster if function is None: return collections[0] Modified: pypy/trunk/src/pypy/module/test/test_functional.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_functional.py (original) +++ pypy/trunk/src/pypy/module/test/test_functional.py Thu May 29 15:10:10 2003 @@ -1,15 +1,46 @@ import testsupport from pypy.module.builtin_app import map, filter, reduce, zip +# trivial functions for testing + +def add_two(x): + return x + 2 + +def add_both(x, y): + return x + y + + class TestMap(testsupport.TestCase): + def test_trivial_map_one_seq(self): + self.assertEqual(map(add_two, [1, 2, 3, 4]), [3, 4, 5, 6]) + + def test_trivial_map_two_seq(self): + self.assertEqual(map(add_both, [1, 2, 3, 4],[1, 2, 3, 4]), [2, 4, 6, 8]) + + def test_trivial_map_sizes_dont_match_and_should(self): + self.assertRaises(TypeError, map, add_both, [1, 2, 3, 4], [1, 2, 3]) + + def test_trivial_map_no_arguments(self): + self.assertRaises(TypeError, map) + + def test_trivial_map_no_function_no_seq(self): + self.assertRaises(TypeError, map, None) + + def test_trivial_map_no_fuction_one_seq(self): + self.assertEqual(map(None, [1, 2, 3]), [1, 2, 3]) + + def test_trivial_map_no_function(self): + self.assertEqual(map(None, [1,2,3], [4,5,6], [7,8], [1]), + [(1, 4, 7, 1), (2, 5, 8, None), (3, 6, None, None)]) + def test_map_identity1(self): a = ['1', 2, 3, 'b', None] b = a[:] self.assertEqual(map(lambda x: x, a), a) self.assertEqual(a, b) - def test_map_None1(self): + def test_map_None(self): a = ['1', 2, 3, 'b', None] b = a[:] self.assertEqual(map(None, a), a) From mwh at codespeak.net Thu May 29 15:12:05 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 15:12:05 +0200 (MEST) Subject: [pypy-svn] rev 670 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030529131205.B88E35AC8A@thoth.codespeak.net> Author: mwh Date: Thu May 29 15:12:05 2003 New Revision: 670 Added: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Log: add (empty) test_stringobject.py Added: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Thu May 29 15:12:05 2003 @@ -0,0 +1,16 @@ +import testsupport +from pypy.objspace.std.stringobject import W_StringObject +from pypy.objspace.std.objspace import StdObjSpace + + +class TestW_StringObject(testsupport.TestCase): + + def setUp(self): + self.space = StdObjSpace() + + def tearDown(self): + pass + + +if __name__ == '__main__': + testsupport.main() From arigo at codespeak.net Thu May 29 15:31:37 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 29 May 2003 15:31:37 +0200 (MEST) Subject: [pypy-svn] rev 671 - in pypy/trunk/src/pypy: . interpreter interpreter/test module/test objspace/std objspace/std/test Message-ID: <20030529133137.B814A5AC87@thoth.codespeak.net> Author: arigo Date: Thu May 29 15:31:36 2003 New Revision: 671 Added: pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py (contents, props changed) pypy/trunk/src/pypy/objspace/std/typeobject.py (contents, props changed) pypy/trunk/src/pypy/objspace/std/userobject.py - copied, changed from rev 620, pypy/trunk/src/pypy/objspace/std/usertype.py Removed: pypy/trunk/src/pypy/objspace/std/usertype.py Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py pypy/trunk/src/pypy/interpreter/test/s1.py (props changed) pypy/trunk/src/pypy/interpreter/testsupport.py (props changed) pypy/trunk/src/pypy/module/test/test_apply.py (props changed) pypy/trunk/src/pypy/objspace/std/boolobject.py pypy/trunk/src/pypy/objspace/std/cpythonobject.py pypy/trunk/src/pypy/objspace/std/default.py (contents, props changed) pypy/trunk/src/pypy/objspace/std/floatobject.py pypy/trunk/src/pypy/objspace/std/intobject.py pypy/trunk/src/pypy/objspace/std/multimethod.py pypy/trunk/src/pypy/objspace/std/noneobject.py pypy/trunk/src/pypy/objspace/std/objspace.py pypy/trunk/src/pypy/objspace/std/rarray.py (props changed) pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py pypy/trunk/src/pypy/objspace/std/test/test_stdobjspace.py (props changed) pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py (props changed) pypy/trunk/src/pypy/testwice.py (props changed) Log: multimethods and basic type system coexist now Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/baseobjspace.py (original) +++ pypy/trunk/src/pypy/interpreter/baseobjspace.py Thu May 29 15:31:36 2003 @@ -163,65 +163,65 @@ ## as 'space.op.xxx()' instead of directly 'space.xxx()'. ObjSpace.MethodTable = [ -# method name # symbol # number of arguments - ('id', 'id', 1), - ('type', 'type', 1), - ('issubtype', 'issubtype', 2), # not for old-style classes - ('repr', 'repr', 1), - ('str', 'str', 1), - ('len', 'len', 1), - ('hash', 'hash', 1), - ('getattr', 'getattr', 2), - ('setattr', 'setattr', 3), - ('delattr', 'delattr', 2), - ('getitem', 'getitem', 2), - ('setitem', 'setitem', 3), - ('delitem', 'delitem', 2), - ('pos', 'pos', 1), - ('neg', 'neg', 1), - ('not_', 'not', 1), - ('abs' , 'abs', 1), - ('hex', 'hex', 1), - ('oct', 'oct', 1), - ('ord', 'ord', 1), - ('invert', '~', 1), - ('add', '+', 2), - ('sub', '-', 2), - ('mul', '*', 2), - ('truediv', '/', 2), - ('floordiv', '//', 2), - ('div', 'div', 2), - ('mod', '%', 2), - ('divmod', 'divmod', 2), - ('pow', '**', 3), - ('lshift', '<<', 2), - ('rshift', '>>', 2), - ('and_', '&', 2), - ('or_', '|', 2), - ('xor', '^', 2), - ('inplace_add', '+=', 2), - ('inplace_sub', '-=', 2), - ('inplace_mul', '*=', 2), - ('inplace_truediv', '/=', 2), - ('inplace_floordiv','//=', 2), - ('inplace_div', 'div=', 2), - ('inplace_mod', '%=', 2), - ('inplace_pow', '**=', 2), - ('inplace_lshift', '<<=', 2), - ('inplace_rshift', '>>=', 2), - ('inplace_and', '&=', 2), - ('inplace_or', '|=', 2), - ('inplace_xor', '^=', 2), - ('lt', '<', 2), - ('le', '<=', 2), - ('eq', '==', 2), - ('ne', '!=', 2), - ('gt', '>', 2), - ('ge', '>=', 2), - ('contains', 'contains', 2), - ('iter', 'iter', 1), - ('next', 'next', 1), # iterator interface - ('call', 'call', 3), +# method name # symbol # number of arguments # special method name(s) + ('id', 'id', 1, []), + ('type', 'type', 1, []), + ('issubtype', 'issubtype', 2, []), # not for old-style classes + ('repr', 'repr', 1, ['__repr__']), + ('str', 'str', 1, ['__str__']), + ('len', 'len', 1, ['__len__']), + ('hash', 'hash', 1, ['__hash__']), + ('getattr', 'getattr', 2, ['__getattribute__']), + ('setattr', 'setattr', 3, ['__setattr__']), + ('delattr', 'delattr', 2, ['__delattr__']), + ('getitem', 'getitem', 2, ['__getitem__']), + ('setitem', 'setitem', 3, ['__setitem__']), + ('delitem', 'delitem', 2, ['__delitem__']), + ('pos', 'pos', 1, ['__pos__']), + ('neg', 'neg', 1, ['__neg__']), + ('not_', 'not', 1, []), + ('abs' , 'abs', 1, ['__abs__']), + ('hex', 'hex', 1, ['__hex__']), + ('oct', 'oct', 1, ['__oct__']), + ('ord', 'ord', 1, []), + ('invert', '~', 1, ['__invert__']), + ('add', '+', 2, ['__add__', '__radd__']), + ('sub', '-', 2, ['__sub__', '__rsub__']), + ('mul', '*', 2, ['__mul__', '__rmul__']), + ('truediv', '/', 2, ['__truediv__', '__rtruediv__']), + ('floordiv', '//', 2, ['__floordiv__', '__rfloordiv__']), + ('div', 'div', 2, ['__div__', '__rdiv__']), + ('mod', '%', 2, ['__mod__', '__rmod__']), + ('divmod', 'divmod', 2, ['__divmod__', '__rdivmod__']), + ('pow', '**', 3, ['__pow__', '__rpow__']), + ('lshift', '<<', 2, ['__lshift__', '__rlshift__']), + ('rshift', '>>', 2, ['__rshift__', '__rrshift__']), + ('and_', '&', 2, ['__and__', '__rand__']), + ('or_', '|', 2, ['__or__', '__ror__']), + ('xor', '^', 2, ['__xor__', '__rxor__']), + ('inplace_add', '+=', 2, ['__iadd__']), + ('inplace_sub', '-=', 2, ['__isub__']), + ('inplace_mul', '*=', 2, ['__imul__']), + ('inplace_truediv', '/=', 2, ['__itruediv__']), + ('inplace_floordiv','//=', 2, ['__ifloordiv__']), + ('inplace_div', 'div=', 2, ['__idiv__']), + ('inplace_mod', '%=', 2, ['__imod__']), + ('inplace_pow', '**=', 2, ['__ipow__']), + ('inplace_lshift', '<<=', 2, ['__ilshift__']), + ('inplace_rshift', '>>=', 2, ['__irshift__']), + ('inplace_and', '&=', 2, ['__iand__']), + ('inplace_or', '|=', 2, ['__ior__']), + ('inplace_xor', '^=', 2, ['__ixor__']), + ('lt', '<', 2, ['__lt__', '__gt__']), + ('le', '<=', 2, ['__le__', '__ge__']), + ('eq', '==', 2, ['__eq__', '__eq__']), + ('ne', '!=', 2, ['__ne__', '__ne__']), + ('gt', '>', 2, ['__gt__', '__lt__']), + ('ge', '>=', 2, ['__ge__', '__le__']), + ('contains', 'contains', 2, ['__contains__']), + ('iter', 'iter', 1, ['__iter__']), + ('next', 'next', 1, ['next']), # iterator interface + ('call', 'call', 3, ['__call__']), ] ObjSpace.BuiltinModuleTable = [ Modified: pypy/trunk/src/pypy/objspace/std/boolobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/boolobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/boolobject.py Thu May 29 15:31:36 2003 @@ -3,6 +3,7 @@ class W_BoolObject(W_Object): delegate_once = {} + statictypename = 'bool' def __init__(w_self, space, boolval):# please pass in a real bool, not an int W_Object.__init__(w_self, space) Modified: pypy/trunk/src/pypy/objspace/std/cpythonobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/cpythonobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/cpythonobject.py Thu May 29 15:31:36 2003 @@ -123,7 +123,7 @@ 'iter': iter, } -for _name, _symbol, _arity in ObjSpace.MethodTable: +for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable: f = MethodImplementation.get(_name) if f: if _arity == 1: Modified: pypy/trunk/src/pypy/objspace/std/default.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/default.py (original) +++ pypy/trunk/src/pypy/objspace/std/default.py Thu May 29 15:31:36 2003 @@ -71,7 +71,7 @@ # in-place operators fall back to their non-in-place counterpart -for _name, _symbol, _arity in ObjSpace.MethodTable: +for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable: if _name.startswith('inplace_'): def default_inplace(space, w_1, w_2, baseop=_name[8:]): op = getattr(space, baseop) Modified: pypy/trunk/src/pypy/objspace/std/floatobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/floatobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/floatobject.py Thu May 29 15:31:36 2003 @@ -7,25 +7,40 @@ ############################################################## import math +import intobject applicationfile = StdObjSpace.AppFile(__name__) class W_FloatObject(W_Object): """This is a reimplementation of the CPython "PyFloatObject" it is assumed that the constructor takes a real Python float as - an argument""" + an argument""" + + delegate_once = {} + statictypename = 'float' def __init__(w_self, space, floatval): W_Object.__init__(w_self, space) w_self.floatval = floatval +# int-to-float delegation +def int_to_float(space, w_intobj): + return W_FloatObject(space, float(w_intobj.intval)) +intobject.W_IntObject.delegate_once[W_FloatObject] = int_to_float + + def float_float(space,w_value): if w_value.__class__ == W_FloatObject: return w_value else: return W_FloatObject(space, w_value.floatval) -StdObjSpace.float.register(float_float, W_FloatObject) +#?StdObjSpace.float.register(float_float, W_FloatObject) + +def float_unwrap(space, w_float): + return w_float.floatval + +StdObjSpace.unwrap.register(float_unwrap, W_FloatObject) def float_repr(space, w_float): ## %reimplement% @@ -41,17 +56,41 @@ StdObjSpace.str.register(float_str, W_FloatObject) -def float_float_compare(space, w_float1, w_float2): - x = w_float1.floatval - y = w_float2.floatval - if x < y: - return space.wrap(-1) - elif x > y: - return space.wrap(1) - else: - return space.wrap(0) - -StdObjSpace.cmp.register(float_float_compare, W_FloatObject, W_FloatObject) +def float_float_lt(space, w_float1, w_float2): + i = w_float1.floatval + j = w_float2.floatval + return space.newbool( i < j ) +StdObjSpace.lt.register(float_float_lt, W_FloatObject, W_FloatObject) + +def float_float_le(space, w_float1, w_float2): + i = w_float1.floatval + j = w_float2.floatval + return space.newbool( i <= j ) +StdObjSpace.le.register(float_float_le, W_FloatObject, W_FloatObject) + +def float_float_eq(space, w_float1, w_float2): + i = w_float1.floatval + j = w_float2.floatval + return space.newbool( i == j ) +StdObjSpace.eq.register(float_float_eq, W_FloatObject, W_FloatObject) + +def float_float_ne(space, w_float1, w_float2): + i = w_float1.floatval + j = w_float2.floatval + return space.newbool( i != j ) +StdObjSpace.ne.register(float_float_ne, W_FloatObject, W_FloatObject) + +def float_float_gt(space, w_float1, w_float2): + i = w_float1.floatval + j = w_float2.floatval + return space.newbool( i > j ) +StdObjSpace.gt.register(float_float_gt, W_FloatObject, W_FloatObject) + +def float_float_ge(space, w_float1, w_float2): + i = w_float1.floatval + j = w_float2.floatval + return space.newbool( i >= j ) +StdObjSpace.ge.register(float_float_ge, W_FloatObject, W_FloatObject) def float_hash(space,w_value): ## %reimplement% @@ -188,7 +227,7 @@ def float_nonzero(space, w_float): return w_float.floatval != 0.0 -StdObjSpace.nonzero.register(float_nonzero, W_FloatObject) +StdObjSpace.is_true.register(float_nonzero, W_FloatObject) ######## coersion must be done later later = """ Modified: pypy/trunk/src/pypy/objspace/std/intobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/intobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/intobject.py Thu May 29 15:31:36 2003 @@ -23,6 +23,7 @@ class W_IntObject(W_Object): delegate_once = {} + statictypename = 'int' def __init__(w_self, space, intval): W_Object.__init__(w_self, space) Modified: pypy/trunk/src/pypy/objspace/std/multimethod.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/multimethod.py (original) +++ pypy/trunk/src/pypy/objspace/std/multimethod.py Thu May 29 15:31:36 2003 @@ -6,15 +6,17 @@ class W_ANY: "Placeholder to allow dispatch on any value." + statictype = None class MultiMethod(object): - def __init__(self, operatorsymbol, arity): + def __init__(self, operatorsymbol, arity, specialnames): "MultiMethod dispatching on the first 'arity' arguments." self.arity = arity self.operatorsymbol = operatorsymbol self.dispatch_table = {} + self.specialnames = specialnames # list like ['__xxx__', '__rxxx__'] def register(self, function, *types): # W_ANY can be used as a placeholder to dispatch on any value. @@ -61,6 +63,16 @@ currentdelegators + (delegator,), result) + def slicetable(self, position, statictype): + m = MultiMethod(self.operatorsymbol, self.arity, self.specialnames) + for key, value in self.dispatch_table.iteritems(): + if key[position].statictype == statictype: + m.dispatch_table[key] = value + return m + + def is_empty(self): + return not self.dispatch_table + class BoundMultiMethod: @@ -73,8 +85,26 @@ raise TypeError, ("multimethod needs at least %d arguments" % self.multimethod.arity) dispatchargs = args[:self.multimethod.arity] - extraargs = args[self.multimethod.arity:] initialtypes = tuple([a.__class__ for a in dispatchargs]) + try: + return self.perform_call(args, initialtypes) + except FailedToImplement, e: + if e.args: + raise OperationError(*e.args) + else: + if len(initialtypes) <= 1: + plural = "" + else: + plural = "s" + typenames = [t.__name__ for t in initialtypes] + message = "unsupported operand type%s for %s: %s" % ( + plural, self.multimethod.operatorsymbol, + ', '.join(typenames)) + w_value = self.space.wrap(message) + raise OperationError(self.space.w_TypeError, w_value) + + def perform_call(self, args, initialtypes): + extraargs = args[self.multimethod.arity:] choicelist = self.multimethod.buildchoices(initialtypes) firstfailure = None for delegators, function in choicelist: @@ -90,19 +120,14 @@ # we got FailedToImplement, record the first such error if firstfailure is None: firstfailure = e - if firstfailure is None: - if len(initialtypes) <= 1: - plural = "" - else: - plural = "s" - typenames = [t.__name__ for t in initialtypes] - message = "unsupported operand type%s for %s: %s" % ( - plural, self.multimethod.operatorsymbol, - ', '.join(typenames)) - w_value = self.space.wrap(message) - raise OperationError(self.space.w_TypeError, w_value) - else: - raise OperationError(*e.args) + raise firstfailure or FailedToImplement() + + def slicetable(self, position, statictype): + return BoundMultiMethod(self.space, + self.multimethod.slicetable(position, statictype)) + + def is_empty(self): + return self.multimethod.is_empty() class error(Exception): Modified: pypy/trunk/src/pypy/objspace/std/noneobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/noneobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/noneobject.py Thu May 29 15:31:36 2003 @@ -3,6 +3,7 @@ class W_NoneObject(W_Object): delegate_once = {} + statictypename = 'NoneType' def none_unwrap(space, w_none): 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 Thu May 29 15:31:36 2003 @@ -10,9 +10,14 @@ class W_Object: "Parent base class for wrapped objects." + statictype = None + def __init__(w_self, space): w_self.space = space + def get_builtin_impl_class(w_self): + return w_self.__class__ + ################################################################## @@ -26,24 +31,45 @@ pass AppFile.LOCAL_PATH = [PACKAGE_PATH] + BUILTIN_TYPES = { + 'W_NoneObject': 'noneobject', + 'W_BoolObject': 'boolobject', + 'W_IntObject': 'intobject', + 'W_FloatObject': 'floatobject', + #'W_ListObject': 'listobject', + } + TYPE_CACHE = {} + def initialize(self): from noneobject import W_NoneObject from boolobject import W_BoolObject from cpythonobject import W_CPythonObject + from typeobject import W_TypeObject, make_type_by_name self.w_None = W_NoneObject(self) self.w_False = W_BoolObject(self, False) self.w_True = W_BoolObject(self, True) + self.w_NotImplemented = self.wrap(NotImplemented) # XXX do me # hack in the exception classes import __builtin__, types newstuff = {"False": self.w_False, "True" : self.w_True, "None" : self.w_None, + "NotImplemented": self.w_NotImplemented, } for n, c in __builtin__.__dict__.iteritems(): if isinstance(c, types.ClassType) and issubclass(c, Exception): w_c = W_CPythonObject(self, c) setattr(self, 'w_' + c.__name__, w_c) newstuff[c.__name__] = w_c + # make the types + for classname, modulename in self.BUILTIN_TYPES.iteritems(): + mod = __import__(modulename, globals(), locals(), [classname]) + cls = getattr(mod, classname) + w_type = make_type_by_name(self, cls.statictypename) + w_type.setup_builtin_type(cls) + setattr(self, 'w_' + cls.statictypename, w_type) + newstuff[cls.statictypename] = w_type + self.make_builtins() self.make_sys() # insert these into the newly-made builtins @@ -71,9 +97,9 @@ items_w = [(self.wrap(k), self.wrap(v)) for (k, v) in x.iteritems()] import dictobject return dictobject.W_DictObject(self, items_w) - #if isinstance(x, float): - # import floatobject - # return floatobject.W_FloatObject(self, x) + if isinstance(x, float): + import floatobject + return floatobject.W_FloatObject(self, x) if isinstance(x, tuple): wrappeditems = [self.wrap(item) for item in x] import tupleobject @@ -124,8 +150,9 @@ return stringobject.W_StringObject(self, ''.join(chars)) # special multimethods - unwrap = MultiMethod('unwrap', 1) # returns an unwrapped object - is_true = MultiMethod('nonzero', 1) # returns an unwrapped bool + unwrap = MultiMethod('unwrap', 1, []) # returns an unwrapped object + is_true = MultiMethod('nonzero', 1, []) # returns an unwrapped bool + # XXX do something about __nonzero__ ! ## # handling of the common fall-back cases ## def compare_any_any(self, w_1, w_2, operation): @@ -141,8 +168,8 @@ # add all regular multimethods to StdObjSpace -for _name, _symbol, _arity in ObjSpace.MethodTable: - setattr(StdObjSpace, _name, MultiMethod(_symbol, _arity)) +for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable: + setattr(StdObjSpace, _name, MultiMethod(_symbol, _arity, _specialnames)) # default implementations of some multimethods for all objects # that don't explicitely override them or that raise FailedToImplement Modified: pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py Thu May 29 15:31:36 2003 @@ -44,7 +44,7 @@ return "add_int_any", y1, o2 class FakeObjSpace: - add = MultiMethod('+', 2) + add = MultiMethod('+', 2, []) add.register(add_x_x, X, X) add.register(add_x_y, X, Y) add.register(add_y_y, Y, Y) Added: pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py Thu May 29 15:31:36 2003 @@ -0,0 +1,59 @@ +import unittest, sys +import testsupport +from pypy.interpreter import unittest_w +from pypy.objspace.std import typeobject as tobj +from pypy.objspace.std.objspace import * + + +class TestPyMultimethodCode(unittest_w.TestCase_w): + + def setUp(self): + self.space = StdObjSpace() + + def tearDown(self): + pass + + def test_int_sub(self): + w = self.space.wrap + for i in range(2): + meth = tobj.PyMultimethodCode(self.space.sub, i, self.space.w_int) + self.assertEqual(meth.multimethod.is_empty(), False) + # test int.__sub__ and int.__rsub__ + self.assertEqual_w(meth.eval_code(self.space, None, + w({'x1': 5, 'x2': 7})), + w(-2)) + self.assertEqual_w(meth.eval_code(self.space, None, + w({'x1': 5, 'x2': 7.1})), + self.space.w_NotImplemented) + self.assertEqual_w(meth.eval_code(self.space, None, + w({'x1': 5.5, 'x2': 7})), + self.space.w_NotImplemented) + + def test_empty_inplace_add(self): + for i in range(2): + meth = tobj.PyMultimethodCode(self.space.inplace_add, i, + self.space.w_int) + self.assertEqual(meth.multimethod.is_empty(), True) + + def test_float_sub(self): + w = self.space.wrap + for i in range(2): + meth = tobj.PyMultimethodCode(self.space.sub, i, self.space.w_float) + self.assertEqual(meth.multimethod.is_empty(), False) + # test float.__sub__ and float.__rsub__ + + # some of these tests are pointless for Python because + # float.__(r)sub__ should not accept an int as first argument + self.assertEqual_w(meth.eval_code(self.space, None, + w({'x1': 5, 'x2': 7})), + w(-2.0)) + self.assertEqual_w(meth.eval_code(self.space, None, + w({'x1': 5, 'x2': 7.5})), + w(-2.5)) + self.assertEqual_w(meth.eval_code(self.space, None, + w({'x1': 5.5, 'x2': 7})), + w(-1.5)) + + +if __name__ == '__main__': + unittest.main() Added: pypy/trunk/src/pypy/objspace/std/typeobject.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/typeobject.py Thu May 29 15:31:36 2003 @@ -0,0 +1,62 @@ +from pypy.interpreter import pycode +from pypy.objspace.std.objspace import * + + +class W_TypeObject(W_Object): + delegate_once = {} + statictypename = 'type' + + def __init__(w_self, space, w_tpname): + W_Object.__init__(w_self, space) + w_self.w_tpname = w_tpname + w_self.builtin_implementations = [] + w_self.multimethods = [value for key, value in space.__dict__.iteritems() + if isinstance(value, MultiMethod)] + + def setup_builtin_type(w_self, implementation): + implementation.statictype = w_self + w_self.builtin_implementations.append(implementation) + + +def make_type_by_name(space, tpname): + try: + w_type = space.TYPE_CACHE[tpname] + except KeyError: + w_type = space.TYPE_CACHE[tpname] = W_TypeObject(space, + space.wrap(tpname)) + return w_type + + +class PyMultimethodCode(pycode.PyBaseCode): + + def __init__(self, multimethod, bound_position=None, w_type=None): + pycode.PyBaseCode.__init__(self) + argnames = ['x%d'%(i+1) for i in range(multimethod.multimethod.arity)] + if w_type is not None: + multimethod = multimethod.slicetable(bound_position, w_type) + argnames.insert(0, argnames.pop(bound_position)) + self.multimethod = multimethod + self.co_name = multimethod.multimethod.operatorsymbol + self.co_flags = 0 + self.co_varnames = tuple(argnames) + self.co_argcount = multimethod.multimethod.arity + + def eval_code(self, space, w_globals, w_locals): + """Call the multimethod, ignoring all implementations that do not + have exactly the expected type at the bound_position.""" + multimethod = self.multimethod + dispatchargs = [] + initialtypes = [] + for i in range(multimethod.multimethod.arity): + w_arg = space.getitem(w_locals, space.wrap('x%d'%(i+1))) + dispatchargs.append(w_arg) + initialtypes.append(w_arg.get_builtin_impl_class()) + dispatchargs = tuple(dispatchargs) + initialtypes = tuple(initialtypes) + try: + return multimethod.perform_call(dispatchargs, initialtypes) + except FailedToImplement, e: + if e.args: + raise OperationError(*e.args) + else: + return space.w_NotImplemented Copied: pypy/trunk/src/pypy/objspace/std/userobject.py (from rev 620, pypy/trunk/src/pypy/objspace/std/usertype.py) ============================================================================== --- pypy/trunk/src/pypy/objspace/std/usertype.py (original) +++ pypy/trunk/src/pypy/objspace/std/userobject.py Thu May 29 15:31:36 2003 @@ -1,5 +1,6 @@ +from pypy.objspace.std.objspace import * -class W_UserType: - def __init__(self): - pass +class W_UserObject(W_Object): + pass + Deleted: pypy/trunk/src/pypy/objspace/std/usertype.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/usertype.py Thu May 29 15:31:36 2003 +++ (empty file) @@ -1,5 +0,0 @@ - - -class W_UserType: - def __init__(self): - pass From tismer at codespeak.net Thu May 29 15:38:33 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 15:38:33 +0200 (MEST) Subject: [pypy-svn] rev 672 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529133833.F3E7D5AC87@thoth.codespeak.net> Author: tismer Date: Thu May 29 15:38:33 2003 New Revision: 672 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: more methods for listobject Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 15:38:33 2003 @@ -31,6 +31,9 @@ def insert(w_self, w_idx, w_obj): return list_insert(w_self.space, w_self, w_idx, w_obj) + def extend(w_self, w_seq): + return list_extend(w_self.space, w_self, w_seq) + def list_unwrap(space, w_list): items = [space.unwrap(w_item) for w_item in w_list.ob_item[:w_list.ob_size]] @@ -173,7 +176,7 @@ w_res.ob_size = slicelength return w_res -StdObjSpace.setitem.register(setitem_list_slice, W_ListObject, W_SliceObject, W_ANY) +StdObjSpace.setitem.register(setitem_list_slice, W_ListObject, W_SliceObject, W_ListObject) def getattr_list(space, w_list, w_attr): if space.is_true(space.eq(w_attr, space.wrap('append'))): @@ -182,6 +185,9 @@ if space.is_true(space.eq(w_attr, space.wrap('insert'))): w_builtinfn = make_builtin_func(space, W_ListObject.insert) return W_InstMethObject(space, w_list, w_builtinfn) + if space.is_true(space.eq(w_attr, space.wrap('extend'))): + w_builtinfn = make_builtin_func(space, W_ListObject.extend) + return W_InstMethObject(space, w_list, w_builtinfn) raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_list, W_ListObject, W_ANY) @@ -245,9 +251,7 @@ items[p] = old_items[p] def ins1(w_list, where, w_any): - print w_list.ob_size, w_list.ob_item list_resize(w_list, w_list.ob_size+1) - print w_list.ob_size, w_list.ob_item size = w_list.ob_size items = w_list.ob_item if where < 0: @@ -258,11 +262,8 @@ where = size for i in range(size, where, -1): items[i] = items[i-1] - print w_list.ob_size, w_list.ob_item items[where] = w_any - print w_list.ob_size, w_list.ob_item w_list.ob_size += 1 - print w_list.ob_size, w_list.ob_item def list_insert(space, w_list, w_where, w_any): ins1(w_list, w_where.intval, w_any) @@ -272,6 +273,16 @@ ins1(w_list, w_list.ob_size, w_any) return space.w_None +def list_extend(space, w_list, w_any): + lis = space.unpackiterable(w_any) + newlen = w_list.ob_size + len(lis) + list_resize(w_list, newlen) + d = w_list.ob_size + items = w_list.ob_item + for i in range(len(lis)): + items[d+i] = lis[i] + return space.w_None + """ static PyMethodDef list_methods[] = { {"append", (PyCFunction)listappend, METH_O, append_doc}, From lac at codespeak.net Thu May 29 15:41:17 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Thu, 29 May 2003 15:41:17 +0200 (MEST) Subject: [pypy-svn] rev 673 - in pypy/trunk/src/pypy/module: . test Message-ID: <20030529134117.226805AC8A@thoth.codespeak.net> Author: lac Date: Thu May 29 15:41:16 2003 New Revision: 673 Added: pypy/trunk/src/pypy/module/test/test_map.py Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: test/test_functional was getting too large. Wrote some more map tests and made map tests its own file. Added (over-long)docstring for map. 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 Thu May 29 15:41:16 2003 @@ -3,10 +3,19 @@ return function(*args, **kwds) def map(function, *collections): - """does 3 separate things. + """does 3 separate things, hence this enormous docstring. 1. if function is None, return a list of tuples, each with one item from each collection. If the collections have different - lengths, shorter ones are padded with None.""" + lengths, shorter ones are padded with None. + + 2. if function is not None, and there is only one collection, + apply function to every item in the collection and return a + list of the results. + + 3. if function is not None, and there are several collections, + repeatedly call the function with one argument from each + collection. If the collections have different lengths, + shorter ones are padded with None""" if len(collections) == 0: raise TypeError, "map() requires at least one sequence" Added: pypy/trunk/src/pypy/module/test/test_map.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/test_map.py Thu May 29 15:41:16 2003 @@ -0,0 +1,82 @@ +import testsupport +from pypy.module.builtin_app import map + +# trivial functions for testing + +def add_two(x): + return x + 2 + +def add_both(x, y): + return x + y + +def add_both_with_none(x, y): + if y is None: + y = 1000 + return x + y + +class TestMap(testsupport.TestCase): + + def test_trivial_map_no_arguments(self): + self.assertRaises(TypeError, map) + + def test_trivial_map_no_function_no_seq(self): + self.assertRaises(TypeError, map, None) + + def test_trivial_map_no_fuction_one_seq(self): + self.assertEqual(map(None, [1, 2, 3]), [1, 2, 3]) + + def test_trivial_map_no_function(self): + # test that None padding works + self.assertEqual(map(None, [1,2,3], [4,5,6], [7,8], [1]), + [(1, 4, 7, 1), (2, 5, 8, None), (3, 6, None, None)]) + + def test_trivial_map_one_seq(self): + self.assertEqual(map(add_two, [1, 2, 3, 4]), [3, 4, 5, 6]) + + def test_trivial_map_two_seq(self): + self.assertEqual(map(add_both, [1, 2, 3, 4],[1, 2, 3, 4]), [2, 4, 6, 8]) + + def test_trivial_map_sizes_dont_match_None_padded_unhappy(self): + # Test that None padding works, making add_both unhappy + self.assertRaises(TypeError, map, add_both, [1, 2, 3, 4], [1, 2, 3]) + + def test_trivial_map_sizes_dont_match_None_padded_happy(self): + # Test that None padding works, more work for add_both_with_none + self.assertEqual(map(add_both_with_none, [1, 2, 3, 4], [1, 2, 3]), + [2, 4, 6, 1004]) + + def test_map_identity1(self): + a = ['1', 2, 3, 'b', None] + b = a[:] + self.assertEqual(map(lambda x: x, a), a) + self.assertEqual(a, b) + + def test_map_None(self): + a = ['1', 2, 3, 'b', None] + b = a[:] + self.assertEqual(map(None, a), a) + self.assertEqual(a, b) + + def test_map_badoperation(self): + a = ['1', 2, 3, 'b', None] + self.assertRaises(TypeError, map, lambda x: x+1, a) + + def test_map_multiply_identity(self): + a = ['1', 2, 3, 'b', None] + b = [ 2, 3, 4, 5, 6] + self.assertEqual(map(None, a, b), [('1', 2), (2, 3), (3, 4), ('b', 5), (None, 6)]) + + def test_map_multiply(self): + a = [1, 2, 3, 4] + b = [0, 1, 1, 1] + self.assertEqual(map(lambda x, y: x+y, a, b), [1, 2, 4, 5]) + + def test_map_multiply(self): + a = [1, 2, 3, 4, 5] + b = [] + self.assertEqual(map(lambda x, y: x, a, b), a) + +if __name__ == '__main__': + testsupport.main() + + From tismer at codespeak.net Thu May 29 15:42:35 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 15:42:35 +0200 (MEST) Subject: [pypy-svn] rev 674 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529134235.AFBA25AC8A@thoth.codespeak.net> Author: tismer Date: Thu May 29 15:42:35 2003 New Revision: 674 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: list.extend works Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 15:42:35 2003 @@ -281,6 +281,7 @@ items = w_list.ob_item for i in range(len(lis)): items[d+i] = lis[i] + w_list.ob_size = newlen return space.w_None """ From jacob at codespeak.net Thu May 29 15:43:42 2003 From: jacob at codespeak.net (jacob at codespeak.net) Date: Thu, 29 May 2003 15:43:42 +0200 (MEST) Subject: [pypy-svn] rev 675 - in pypy/trunk/src/pypy: appspace/test objspace/std Message-ID: <20030529134342.561D35AC8A@thoth.codespeak.net> Author: jacob Date: Thu May 29 15:43:41 2003 New Revision: 675 Modified: pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py pypy/trunk/src/pypy/appspace/test/test_exec.py pypy/trunk/src/pypy/objspace/std/classobject_app.py Log: Improved error message Modified: pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py ============================================================================== --- pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py (original) +++ pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py Thu May 29 15:43:41 2003 @@ -1,124 +1,124 @@ -"""Test comparisons of Exceptions in except clauses. - -New for PyPy - Could be incorporated into CPython regression tests. -""" - -import unittest - -class TestExceptionComp(unittest.TestCase): - - def test_string(self): - string = "string" - try: - raise string - except string: - pass - except: - self.fail("Identical string exceptions do not match.") - - def test_stringfail(self): - string1 = "string1" - string1_ = "string" + "1" - assert string1 is not string1_ - try: - raise string1 - except "string2": - self.fail("Different string exceptions match.") - except string1_: - self.fail("Non Identical string exceptions match.") - except string1: - pass - except: - self.fail("Unknown value for variable raise.") - - - def test_exception(self): - try: - raise TypeError, "nothing" - except TypeError: - pass - except: - self.fail("Identical exceptions do not match.") - - def test_exceptionfail(self): - try: - raise TypeError, "nothing" - except KeyError: - self.fail("Different exceptions match.") - except TypeError: - pass - except: - self.fail("Unanticipated value for exception raise.") - - - def test_called(self): - try: - raise SyntaxError("Invalid") - except SyntaxError: - pass - except: - self.fail("Instantiated exception does not match parent class.") - - def test_calledfail(self): - try: - raise SyntaxError("Invalid") - except ZeroDivisionError: - self.fail("Instantiated exception matches different parent class.") - except SyntaxError: - pass - except: - self.fail("Unanticpated value for exception raise.") - - - def test_userclass(self): - class UserExcept(Exception): - pass - try: - raise UserExcept, "nothing" - except UserExcept: - pass - except: - self.fail("User defined class exceptions do not match.") - - def test_subclass(self): - try: - raise KeyError("key") - except LookupError: - pass - except: - self.fail("Exception does not match parent class.") - - def test_deepsubclass(self): - try: - raise FloatingPointError("1.2r") - except Exception: - pass - except: - self.fail("Exception does not match grandparent class.") - - def test_tuple(self): - try: - raise ArithmeticError("2+jack") - except (ZeroDivisionError, ArithmeticError): - pass - except: - self.fail("Exception does not match self in tuple.") - - def test_parenttuple(self): - try: - raise ZeroDivisionError("0") - except (StandardError, SystemExit): - pass - except: - self.fail("Exception does not match parent in tuple.") - - def test_nestedtuples(self): - try: - raise AssertionError("0") - except (SystemExit, (KeyboardInterrupt, AssertionError)): - pass - except: - self.fail("Exception does not match self in nested tuple.") - -if __name__ == "__main__": - unittest.main() +"""Test comparisons of Exceptions in except clauses. + +New for PyPy - Could be incorporated into CPython regression tests. +""" + +import unittest + +class TestExceptionComp(unittest.TestCase): + + def test_string(self): + string = "string" + try: + raise string + except string: + pass + except: + self.fail("Identical string exceptions do not match.") + + def test_stringfail(self): + string1 = "string1" + string1_ = "string" + "1" + assert string1 is not string1_ + try: + raise string1 + except "string2": + self.fail("Different string exceptions match.") + except string1_: + self.fail("Non Identical string exceptions match.") + except string1: + pass + except: + self.fail("Unknown value for variable raise.") + + + def test_exception(self): + try: + raise TypeError, "nothing" + except TypeError: + pass + except: + self.fail("Identical exceptions do not match.") + + def test_exceptionfail(self): + try: + raise TypeError, "nothing" + except KeyError: + self.fail("Different exceptions match.") + except TypeError: + pass + except: + self.fail("Unanticipated value for exception raise.") + + + def test_called(self): + try: + raise SyntaxError("Invalid") + except SyntaxError: + pass + except: + self.fail("Instantiated exception does not match parent class.") + + def test_calledfail(self): + try: + raise SyntaxError("Invalid") + except ZeroDivisionError: + self.fail("Instantiated exception matches different parent class.") + except SyntaxError: + pass + except: + self.fail("Unanticpated value for exception raise.") + + + def test_userclass(self): + class UserExcept(Exception): + pass + try: + raise UserExcept, "nothing" + except UserExcept: + pass + except: + self.fail("User defined class exceptions do not match.") + + def test_subclass(self): + try: + raise KeyError("key") + except LookupError: + pass + except: + self.fail("Exception does not match parent class.") + + def test_deepsubclass(self): + try: + raise FloatingPointError("1.2r") + except Exception: + pass + except: + self.fail("Exception does not match grandparent class.") + + def test_tuple(self): + try: + raise ArithmeticError("2+jack") + except (ZeroDivisionError, ArithmeticError): + pass + except: + self.fail("Exception does not match self in tuple.") + + def test_parenttuple(self): + try: + raise ZeroDivisionError("0") + except (StandardError, SystemExit): + pass + except: + self.fail("Exception does not match parent in tuple.") + + def test_nestedtuples(self): + try: + raise AssertionError("0") + except (SystemExit, (KeyboardInterrupt, AssertionError)): + pass + except: + self.fail("Exception does not match self in nested tuple.") + +if __name__ == "__main__": + unittest.main() Modified: pypy/trunk/src/pypy/appspace/test/test_exec.py ============================================================================== --- pypy/trunk/src/pypy/appspace/test/test_exec.py (original) +++ pypy/trunk/src/pypy/appspace/test/test_exec.py Thu May 29 15:43:41 2003 @@ -1,67 +1,67 @@ -"""Test the exec statement functionality. - -New for PyPy - Could be incorporated into CPython regression tests. -""" - -import unittest - -class TestExecStmt(unittest.TestCase): - - def test_string(self): - g = {} - l = {} - exec "a = 3" in g, l - self.failUnlessEqual(l['a'], 3) - - def test_localfill(self): - g = {} - exec "a = 3" in g - self.failUnlessEqual(g['a'], 3) - - def test_builtinsupply(self): - g = {} - exec "pass" in g - self.failUnless(g.has_key('__builtins__')) - - def test_invalidglobal(self): - self.failUnlessRaises(TypeError,"exec 'pass' in 1") - - def test_invalidlocal(self): - self.failUnlessRaises(TypeError,"exec 'pass' in {}, 2") - - def test_codeobject(self): - co = compile("a = 3", '', 'exec') - g = {} - l = {} - exec co in g, l - self.failUnlessEqual(l['a'], 3) - -## # Commented out as PyPy give errors using open() -## # ["Not availible in restricted mode"] -## def test_file(self): -## fo = open("test_exec.py", 'r') -## g = {} -## exec fo in g -## self.failUnless(g.has_key('TestExecStmt')) - - def test_implicit(self): - a = 4 - exec "a = 3" - self.failUnlessEqual(a,3) - - def test_tuplelocals(self): - g = {} - l = {} - exec ("a = 3", g, l) - self.failUnlessEqual(l['a'], 3) - - def test_tupleglobals(self): - g = {} - exec ("a = 3", g) - self.failUnlessEqual(g['a'], 3) - - def test_exceptionfallthrough(self): - self.failUnlessRaises(TypeError,"exec 'raise TypeError' in {}") - -if __name__ == "__main__": - unittest.main() +"""Test the exec statement functionality. + +New for PyPy - Could be incorporated into CPython regression tests. +""" + +import unittest + +class TestExecStmt(unittest.TestCase): + + def test_string(self): + g = {} + l = {} + exec "a = 3" in g, l + self.failUnlessEqual(l['a'], 3) + + def test_localfill(self): + g = {} + exec "a = 3" in g + self.failUnlessEqual(g['a'], 3) + + def test_builtinsupply(self): + g = {} + exec "pass" in g + self.failUnless(g.has_key('__builtins__')) + + def test_invalidglobal(self): + self.failUnlessRaises(TypeError,"exec 'pass' in 1") + + def test_invalidlocal(self): + self.failUnlessRaises(TypeError,"exec 'pass' in {}, 2") + + def test_codeobject(self): + co = compile("a = 3", '', 'exec') + g = {} + l = {} + exec co in g, l + self.failUnlessEqual(l['a'], 3) + +## # Commented out as PyPy give errors using open() +## # ["Not availible in restricted mode"] +## def test_file(self): +## fo = open("test_exec.py", 'r') +## g = {} +## exec fo in g +## self.failUnless(g.has_key('TestExecStmt')) + + def test_implicit(self): + a = 4 + exec "a = 3" + self.failUnlessEqual(a,3) + + def test_tuplelocals(self): + g = {} + l = {} + exec ("a = 3", g, l) + self.failUnlessEqual(l['a'], 3) + + def test_tupleglobals(self): + g = {} + exec ("a = 3", g) + self.failUnlessEqual(g['a'], 3) + + def test_exceptionfallthrough(self): + self.failUnlessRaises(TypeError,"exec 'raise TypeError' in {}") + +if __name__ == "__main__": + unittest.main() Modified: pypy/trunk/src/pypy/objspace/std/classobject_app.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/classobject_app.py (original) +++ pypy/trunk/src/pypy/objspace/std/classobject_app.py Thu May 29 15:43:41 2003 @@ -12,4 +12,5 @@ try: return self.__dict__[attr] except KeyError: - raise AttributeError, "ksajdakshdskj" % name + raise AttributeError, "Class %s has no attribute %s" % ( + self.__name__, attr) From mwh at codespeak.net Thu May 29 15:44:27 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 15:44:27 +0200 (MEST) Subject: [pypy-svn] rev 676 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030529134427.221CD5AC8A@thoth.codespeak.net> Author: mwh Date: Thu May 29 15:44:26 2003 New Revision: 676 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Log: implement string.is_true enhance str.getitem to handle negative & out-of-bounds indices add tests for these and string equality, order comparisons Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 15:44:26 2003 @@ -105,6 +105,11 @@ StdObjSpace.unwrap.register(str_unwrap, W_StringObject) +def str_is_true(space, w_str): + return w_str._value.len != 0 + +StdObjSpace.is_true.register(str_is_true, W_StringObject) + def str_str_lt(space, w_str1, w_str2): i = w_str1._value.value() j = w_str2._value.value() @@ -149,7 +154,15 @@ def getitem_str_int(space, w_str, w_int): - return W_StringObject(space, w_str._value.value()[w_int.intval]) + ival = w_int.intval + slen = w_str._value.len + if ival < 0: + ival += slen + if ival < 0 or ival >= slen: + exc = space.call_function(space.w_IndexError, + space.wrap("string index out of range")) + raise OperationError(space.w_IndexError, exc) + return W_StringObject(space, w_str._value.charat(ival)) StdObjSpace.getitem.register(getitem_str_int, W_StringObject, W_IntObject) Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Thu May 29 15:44:26 2003 @@ -1,15 +1,44 @@ import testsupport -from pypy.objspace.std.stringobject import W_StringObject -from pypy.objspace.std.objspace import StdObjSpace +#from pypy.objspace.std.stringobject import W_StringObject +#from pypy.objspace.std.objspace import StdObjSpace class TestW_StringObject(testsupport.TestCase): def setUp(self): - self.space = StdObjSpace() + self.space = testsupport.objspace() def tearDown(self): pass + + def test_equality(self): + w = self.space.wrap + self.assertEqual_w(w('abc'), w('abc')) + self.assertNotEqual_w(w('abc'), w('def')) + + def test_order_cmp(self): + space = self.space + w = space.wrap + self.failUnless_w(space.lt(w('a'), w('b'))) + self.failUnless_w(space.lt(w('a'), w('ab'))) + self.failUnless_w(space.le(w('a'), w('a'))) + self.failUnless_w(space.gt(w('a'), w(''))) + + def test_truth(self): + w = self.space.wrap + self.failUnless_w(w('non-empty')) + self.failIf_w(w('')) + + def test_getitem(self): + space = self.space + w = space.wrap + w_str = w('abc') + self.assertEqual_w(space.getitem(w_str, w(0)), w('a')) + self.assertEqual_w(space.getitem(w_str, w(-1)), w('c')) + self.assertRaises_w(space.w_IndexError, + space.getitem, + w_str, + w(3)) if __name__ == '__main__': From tomek at codespeak.net Thu May 29 16:10:52 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 16:10:52 +0200 (MEST) Subject: [pypy-svn] rev 677 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030529141052.A2FF85AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 16:10:52 2003 New Revision: 677 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Log: rich_compare in stringobject.py Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 16:10:52 2003 @@ -110,6 +110,70 @@ StdObjSpace.is_true.register(str_is_true, W_StringObject) + +EQ = 1 +LE = 2 +GE = 3 +GT = 4 +LT = 5 +NE = 6 + +def string_richcompare(space, w_str1, w_str2, op): + str1 = w_str1._value + str2 = w_str2._value + + if space.is_(str1, str2): + if op == EQ or op == LE or op == GE: + return space.w_True + elif op == GT or op == LT or op == NE: + return space.w_False + else: + if op == EQ: + if val1.len == val2.len: + for i in range(val1.len): + if ord(val1.charat(i)) != ord(val2.charat(i)): + return space.w_False + return space.w_True + else: + return space.w_False + else: + if val1.len > val2.len: + min_len = val2.len + else: + min_len = val1.len + + idx = 0 + if (min_len > 0): + while (c == 0) and (idx < min_len): + c = ord(val1.charat[idx]) - ord(val2.charat[idx]) + idx = idx + 1 + else: + c = 0 + + if (c == 0): + if val1.len < val2.len: + c = -1 + elif val1.len > val2.leb: + c = 1 + else: + c = 0 + + if op == LT: + return space.newbool(c < 0) + elif op == LE: + return space.newbool(c <= 0) + elif op == NE: + return space.newbool(c != 0) + elif op == GT: + return space.newbook(c > 0) + elif op == GE: + return space.newbool(c >= 0) + else: + raise NotImplemented + + + + def str_str_lt(space, w_str1, w_str2): i = w_str1._value.value() j = w_str2._value.value() Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Thu May 29 16:10:52 2003 @@ -1,6 +1,11 @@ import testsupport +<<<<<<< .mine +from pypy.objspace.std.stringobject import string_richcompare, W_StringObject, EQ, LT, GT, NE, LE, GE +from pypy.objspace.std.objspace import StdObjSpace +======= #from pypy.objspace.std.stringobject import W_StringObject #from pypy.objspace.std.objspace import StdObjSpace +>>>>>>> .r676 class TestW_StringObject(testsupport.TestCase): From tomek at codespeak.net Thu May 29 16:14:11 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 16:14:11 +0200 (MEST) Subject: [pypy-svn] rev 678 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030529141411.5CE9A5AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 16:14:10 2003 New Revision: 678 Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Log: add test Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Thu May 29 16:14:10 2003 @@ -1,11 +1,6 @@ import testsupport -<<<<<<< .mine from pypy.objspace.std.stringobject import string_richcompare, W_StringObject, EQ, LT, GT, NE, LE, GE from pypy.objspace.std.objspace import StdObjSpace -======= -#from pypy.objspace.std.stringobject import W_StringObject -#from pypy.objspace.std.objspace import StdObjSpace ->>>>>>> .r676 class TestW_StringObject(testsupport.TestCase): @@ -16,6 +11,11 @@ def tearDown(self): pass + def test_order_rich(self): + space = self.space + w = space.wrap + self.failUnless_w(string_richcompare(space, w('abc'), w('abc'), EQ)) + def test_equality(self): w = self.space.wrap self.assertEqual_w(w('abc'), w('abc')) From lac at codespeak.net Thu May 29 16:16:18 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Thu, 29 May 2003 16:16:18 +0200 (MEST) Subject: [pypy-svn] rev 679 - pypy/trunk/src/pypy/module/test Message-ID: <20030529141618.1FBEB5AC8A@thoth.codespeak.net> Author: lac Date: Thu May 29 16:16:17 2003 New Revision: 679 Modified: pypy/trunk/src/pypy/module/test/test_map.py Log: belatedly take 'trivial' out of function names. Modified: pypy/trunk/src/pypy/module/test/test_map.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_map.py (original) +++ pypy/trunk/src/pypy/module/test/test_map.py Thu May 29 16:16:17 2003 @@ -16,31 +16,31 @@ class TestMap(testsupport.TestCase): - def test_trivial_map_no_arguments(self): + def test_map_no_arguments(self): self.assertRaises(TypeError, map) - def test_trivial_map_no_function_no_seq(self): + def test_map_no_function_no_seq(self): self.assertRaises(TypeError, map, None) - def test_trivial_map_no_fuction_one_seq(self): + def test_map_no_fuction_one_seq(self): self.assertEqual(map(None, [1, 2, 3]), [1, 2, 3]) - def test_trivial_map_no_function(self): + def test_map_no_function(self): # test that None padding works self.assertEqual(map(None, [1,2,3], [4,5,6], [7,8], [1]), [(1, 4, 7, 1), (2, 5, 8, None), (3, 6, None, None)]) - def test_trivial_map_one_seq(self): + def test_map_one_seq(self): self.assertEqual(map(add_two, [1, 2, 3, 4]), [3, 4, 5, 6]) - def test_trivial_map_two_seq(self): + def test_map_two_seq(self): self.assertEqual(map(add_both, [1, 2, 3, 4],[1, 2, 3, 4]), [2, 4, 6, 8]) - def test_trivial_map_sizes_dont_match_None_padded_unhappy(self): + def test_map_sizes_dont_match_None_padded_unhappy(self): # Test that None padding works, making add_both unhappy self.assertRaises(TypeError, map, add_both, [1, 2, 3, 4], [1, 2, 3]) - def test_trivial_map_sizes_dont_match_None_padded_happy(self): + def test_map_sizes_dont_match_None_padded_happy(self): # Test that None padding works, more work for add_both_with_none self.assertEqual(map(add_both_with_none, [1, 2, 3, 4], [1, 2, 3]), [2, 4, 6, 1004]) From tismer at codespeak.net Thu May 29 16:21:50 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 16:21:50 +0200 (MEST) Subject: [pypy-svn] rev 680 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529142150.0E4C55AC8A@thoth.codespeak.net> Author: tismer Date: Thu May 29 16:21:49 2003 New Revision: 680 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: list.pop works Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 16:21:49 2003 @@ -12,7 +12,7 @@ w_self.ob_item = [] w_self.ob_size = 0 newlen = len(wrappeditems) - list_resize(w_self, newlen) + _list_resize(w_self, newlen) w_self.ob_size = newlen items = w_self.ob_item p = newlen @@ -34,6 +34,8 @@ def extend(w_self, w_seq): return list_extend(w_self.space, w_self, w_seq) + def pop(w_self, w_idx=-1): + return list_pop(w_self.space, w_self, w_idx) def list_unwrap(space, w_list): items = [space.unwrap(w_item) for w_item in w_list.ob_item[:w_list.ob_size]] @@ -73,7 +75,7 @@ slicelength = space.unwrap(w_slicelength) assert slicelength >= 0 w_res = W_ListObject(space, []) - list_resize(w_res, slicelength) + _list_resize(w_res, slicelength) subitems = w_res.ob_item for i in range(slicelength): subitems[i] = items[start] @@ -92,7 +94,7 @@ def list_add(space, w_list1, w_list2): w_res = W_ListObject(space, []) newlen = w_list1.ob_size + w_list2.ob_size - list_resize(w_res, newlen) + _list_resize(w_res, newlen) p = 0 items = w_res.ob_item src = w_list1.ob_item @@ -114,7 +116,7 @@ src = w_list.ob_item size = w_list.ob_size newlen = size * times # XXX check overflow - list_resize(w_res, newlen) + _list_resize(w_res, newlen) items = w_res.ob_item p = 0 for _ in range(times): @@ -168,7 +170,7 @@ slicelength = space.unwrap(w_slicelength) assert slicelength >= 0 w_res = W_ListObject(space, []) - list_resize(w_res, slicelength) + _list_resize(w_res, slicelength) subitems = w_res.ob_item for i in range(slicelength): subitems[i] = items[start] @@ -188,12 +190,15 @@ if space.is_true(space.eq(w_attr, space.wrap('extend'))): w_builtinfn = make_builtin_func(space, W_ListObject.extend) return W_InstMethObject(space, w_list, w_builtinfn) + if space.is_true(space.eq(w_attr, space.wrap('pop'))): + w_builtinfn = make_builtin_func(space, W_ListObject.pop) + return W_InstMethObject(space, w_list, w_builtinfn) raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_list, W_ListObject, W_ANY) # adapted C code -def roundupsize(n): +def _roundupsize(n): nbits = r_uint(0) n2 = n >> 5 @@ -234,7 +239,7 @@ for_later = """ #define NRESIZE(var, type, nitems) \ do { \ - size_t _new_size = roundupsize(nitems); \ + size_t _new_size = _roundupsize(nitems); \ if (_new_size <= ((~(size_t)0) / sizeof(type))) \ PyMem_RESIZE(var, type, _new_size); \ else \ @@ -242,16 +247,16 @@ } while (0) """ -def list_resize(w_list, newlen): +def _list_resize(w_list, newlen): if newlen > len(w_list.ob_item): - true_size = roundupsize(newlen) + true_size = _roundupsize(newlen) old_items = w_list.ob_item w_list.ob_item = items = [None] * true_size for p in range(len(old_items)): items[p] = old_items[p] -def ins1(w_list, where, w_any): - list_resize(w_list, w_list.ob_size+1) +def _ins1(w_list, where, w_any): + _list_resize(w_list, w_list.ob_size+1) size = w_list.ob_size items = w_list.ob_item if where < 0: @@ -266,17 +271,17 @@ w_list.ob_size += 1 def list_insert(space, w_list, w_where, w_any): - ins1(w_list, w_where.intval, w_any) + _ins1(w_list, w_where.intval, w_any) return space.w_None def list_append(space, w_list, w_any): - ins1(w_list, w_list.ob_size, w_any) + _ins1(w_list, w_list.ob_size, w_any) return space.w_None def list_extend(space, w_list, w_any): lis = space.unpackiterable(w_any) newlen = w_list.ob_size + len(lis) - list_resize(w_list, newlen) + _list_resize(w_list, newlen) d = w_list.ob_size items = w_list.ob_item for i in range(len(lis)): @@ -284,6 +289,37 @@ w_list.ob_size = newlen return space.w_None +def _del_slice(w_list, ilow, ihigh): + """ similar to the deletion part of list_ass_slice in CPython """ + if ilow < 0: + ilow = 0 + elif ilow > w_list.ob_size: + ilow = w_list.ob_size + if ihigh < ilow: + ihigh = ilow + elif ihigh > w_list.ob_size: + ihigh = w_list.ob_size + items = w_list.ob_item + d = ihigh-ilow + recycle = [items[i] for i in range(ilow, ihigh)] + for i in range(ilow, ihigh): + items[i] = items[i+d] + +# note that the default value will come back wrapped!!! +def list_pop(space, w_list, w_idx=-1): + if w_list.ob_size == 0: + raise OperationError(space.w_IndexError, + space.wrap("pop from empty list")) + i = w_idx.intval + if i < 0: + i += w_list.ob_size + if i < 0 or i >= w_list.ob_size: + raise OperationError(space.w_IndexError, + space.wrap("pop index out of range")) + w_res = w_list.ob_item[i] + _del_slice(w_list, i, i+1) + return w_res + """ static PyMethodDef list_methods[] = { {"append", (PyCFunction)listappend, METH_O, append_doc}, From tomek at codespeak.net Thu May 29 16:25:39 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 16:25:39 +0200 (MEST) Subject: [pypy-svn] rev 681 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030529142539.4A2205AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 16:25:38 2003 New Revision: 681 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Log: small changes Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 16:25:38 2003 @@ -129,31 +129,31 @@ return space.w_False else: if op == EQ: - if val1.len == val2.len: - for i in range(val1.len): - if ord(val1.charat(i)) != ord(val2.charat(i)): + if str1.len == str2.len: + for i in range(str1.len): + if ord(str1.charat(i)) != ord(str2.charat(i)): return space.w_False return space.w_True else: return space.w_False else: - if val1.len > val2.len: - min_len = val2.len + if str1.len > str2.len: + min_len = str2.len else: - min_len = val1.len + min_len = str1.len idx = 0 if (min_len > 0): while (c == 0) and (idx < min_len): - c = ord(val1.charat[idx]) - ord(val2.charat[idx]) + c = ord(str1.charat[idx]) - ord(str2.charat[idx]) idx = idx + 1 else: c = 0 if (c == 0): - if val1.len < val2.len: + if str1.len < str2.len: c = -1 - elif val1.len > val2.leb: + elif str1.len > str2.leb: c = 1 else: c = 0 @@ -171,9 +171,6 @@ else: raise NotImplemented - - - def str_str_lt(space, w_str1, w_str2): i = w_str1._value.value() j = w_str2._value.value() Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Thu May 29 16:25:38 2003 @@ -13,7 +13,9 @@ def test_order_rich(self): space = self.space - w = space.wrap + def w(txt): + return W_StringObject(space, txt) + self.failUnless_w(string_richcompare(space, w('abc'), w('abc'), EQ)) def test_equality(self): From mwh at codespeak.net Thu May 29 16:31:53 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 16:31:53 +0200 (MEST) Subject: [pypy-svn] rev 682 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030529143153.141B05AC8A@thoth.codespeak.net> Author: mwh Date: Thu May 29 16:31:53 2003 New Revision: 682 Modified: pypy/trunk/src/pypy/objspace/std/sliceobject.py pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/stringobject_app.py pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Log: make str[slice] work this involved implementing it in interpreter space also exposed a variant of slice.indices to Python, cleanup needed in this area make the app-space version of str[slice] more likely to work, but it still doesn't added tests for simple slicing, tests for extended slicing to follow Modified: pypy/trunk/src/pypy/objspace/std/sliceobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/sliceobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/sliceobject.py Thu May 29 16:31:53 2003 @@ -1,6 +1,7 @@ from pypy.objspace.std.objspace import * from pypy.interpreter.appfile import AppFile - +from pypy.interpreter.extmodule import make_builtin_func +from pypy.objspace.std.instmethobject import W_InstMethObject appfile = AppFile(__name__, ["objspace.std"]) @@ -15,6 +16,10 @@ w_ret = space.gethelper(appfile).call("sliceindices", [w_self, w_length]) w_start, w_stop, w_step, w_slicelength = space.unpackiterable(w_ret, 4) return w_start, w_stop, w_step, w_slicelength + def indices2(w_self, w_length): + w_ret = w_self.space.gethelper(appfile).call("sliceindices", [w_self, w_length]) + w_start, w_stop, w_step, w_slicelength = w_self.space.unpackiterable(w_ret, 4) + return w_self.space.newtuple([w_start, w_stop, w_step, w_slicelength]) def getattr_slice_any(space, w_slice, w_attr): @@ -33,6 +38,10 @@ return space.w_None else: return w_slice.w_step + if space.is_true(space.eq(w_attr, space.wrap('indices'))): + w_builtinfn = make_builtin_func(space, W_SliceObject.indices2) + return W_InstMethObject(space, w_slice, w_builtinfn) + raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_slice_any, W_SliceObject, W_ANY) Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 16:31:53 2003 @@ -229,10 +229,24 @@ W_StringObject, W_IntObject) def getitem_str_slice(space, w_str, w_slice): - return applicationfile.call(space, "getitem_string_slice", [w_str, w_slice]) + w = space.wrap + u = space.unwrap + w_start, w_stop, w_step, w_sl = w_slice.indices(space, w(w_str._value.len)) + start = u(w_start) + stop = u(w_stop) + step = u(w_step) + sl = u(w_sl) + r = [None] * sl + for i in range(sl): + r[i] = space.getitem(w_str, w(start + i*step)) + w_r = space.newlist(r) + w_empty = space.newstring([]) + return w_empty.join(w_r) + return space.gethelper(applicationfile).call( + "getitem_string_slice", [w_str, w_slice]) StdObjSpace.getitem.register(getitem_str_slice, - W_StringObject, W_SliceObject) + W_StringObject, W_SliceObject) def add_str_str(space, w_left, w_right): return W_StringObject(space, w_left._value.value() + w_right._value.value()) Modified: pypy/trunk/src/pypy/objspace/std/stringobject_app.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject_app.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject_app.py Thu May 29 16:31:53 2003 @@ -1,6 +1,6 @@ def getitem_string_slice(str, sliceob): r = [] - for i in xrange(*sliceob.indices(len(str))): + for i in range(*sliceob.indices(len(str))): r.append(str[i]) return ''.join(r) Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Thu May 29 16:31:53 2003 @@ -46,7 +46,28 @@ space.getitem, w_str, w(3)) - + + def test_slice(self): + space = self.space + w = space.wrap + w_str = w('abc') + w_slice = space.newslice(w(0), w(0), None) + self.assertEqual_w(space.getitem(w_str, w_slice), w('')) + w_slice = space.newslice(w(0), w(1), None) + self.assertEqual_w(space.getitem(w_str, w_slice), w('a')) + w_slice = space.newslice(w(0), w(10), None) + self.assertEqual_w(space.getitem(w_str, w_slice), w('abc')) + w_slice = space.newslice(space.w_None, space.w_None, None) + self.assertEqual_w(space.getitem(w_str, w_slice), w('abc')) + w_slice = space.newslice(space.w_None, w(-1), None) + self.assertEqual_w(space.getitem(w_str, w_slice), w('ab')) + w_slice = space.newslice(w(-1), space.w_None, None) + self.assertEqual_w(space.getitem(w_str, w_slice), w('c')) + + def test_extended_slice(self): + space = self.space + w = space.wrap + w_str = w('abc') if __name__ == '__main__': testsupport.main() From arigo at codespeak.net Thu May 29 16:31:55 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 29 May 2003 16:31:55 +0200 (MEST) Subject: [pypy-svn] rev 683 - pypy/trunk/src/pypy/tool Message-ID: <20030529143155.C1DE25AC91@thoth.codespeak.net> Author: arigo Date: Thu May 29 16:31:55 2003 New Revision: 683 Modified: pypy/trunk/src/pypy/tool/test_all.py (contents, props changed) Log: fixed eol style Modified: pypy/trunk/src/pypy/tool/test_all.py ============================================================================== --- pypy/trunk/src/pypy/tool/test_all.py (original) +++ pypy/trunk/src/pypy/tool/test_all.py Thu May 29 16:31:55 2003 @@ -58,8 +58,8 @@ if __name__=='__main__': path = dirname(abspath(sys.argv[0])) - drive, path = os.path.splitdrive(path) - path = path.split(os.sep) + drive, path = os.path.splitdrive(path) + path = path.split(os.sep) if 'pypy' not in path: raise SystemExit, "Need to be somewhere in pypy-tree" @@ -69,7 +69,7 @@ path.insert(0, '/') path.append('pypy') - path = drive + joinfn('/', *path) + path = drive + joinfn('/', *path) print path, dirname(path) sys.path.insert(0, dirname(path)) drive_tests(path) From lac at codespeak.net Thu May 29 16:39:40 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Thu, 29 May 2003 16:39:40 +0200 (MEST) Subject: [pypy-svn] rev 684 - in pypy/trunk/src/pypy/module: . test Message-ID: <20030529143940.DA0E65AC8A@thoth.codespeak.net> Author: lac Date: Thu May 29 16:39:40 2003 New Revision: 684 Added: pypy/trunk/src/pypy/module/test/test_filter.py Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: Wrote some unit tests for filter, broke it out into its own file. 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 Thu May 29 16:39:40 2003 @@ -49,6 +49,10 @@ idx = idx + 1 def filter(function, collection): + """construct a list of those elements of collection for which function + is True. If function is None, then return the items in the sequence + which are True.""" + res = [] if function is None: for elem in collection: Added: pypy/trunk/src/pypy/module/test/test_filter.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/test_filter.py Thu May 29 16:39:40 2003 @@ -0,0 +1,55 @@ +import testsupport +from pypy.module.builtin_app import filter + + +# trivial functions for testing + +def larger_than_three(x): + if x > 3: + return True + else: + return False + +def larger_than_a(c): + if c > 'a': + return True + else: + return False + +class TestFilter(testsupport.TestCase): + + def test_filter_no_arguments(self): + self.assertRaises(TypeError, filter) + + def test_filter_no_function_no_seq(self): + self.assertRaises(TypeError, filter, None) + + def test_filter_function_no_seq(self): + self.assertRaises(TypeError, filter, larger_than_three) + + def test_filter_function_too_many_args(self): + self.assertRaises(TypeError, filter, larger_than_three, [1], [2]) + + def test_filter_no_function_list(self): + self.assertEqual(filter(None, [1, 2, 3]), [1, 2, 3]) + + def test_filter_no_function_tuple(self): + self.assertEqual(filter(None, (1, 2, 3)), (1, 2, 3)) + + def test_filter_no_function_string(self): + self.assertEqual(filter(None, 'mystring'), 'mystring') + + def test_filter_no_function_with_bools(self): + self.assertEqual(filter(None, (True, False, True)), (True, True)) + + def test_filter_list(self): + self.assertEqual(filter(larger_than_three, [1, 2, 3, 4, 5]), [4, 5]) + + def test_filter_tuple(self): + self.assertEqual(filter(larger_than_three, (1, 2, 3, 4, 5)), (4, 5)) + + def test_filter_string(self): + self.assertEqual(filter(larger_than_a, 'xyzabcd'), 'xyzbcd') + +if __name__ == '__main__': + testsupport.main() From lac at codespeak.net Thu May 29 16:44:55 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Thu, 29 May 2003 16:44:55 +0200 (MEST) Subject: [pypy-svn] rev 685 - pypy/trunk/src/pypy/module Message-ID: <20030529144455.AA1005AC8A@thoth.codespeak.net> Author: lac Date: Thu May 29 16:44:55 2003 New Revision: 685 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: make filter use list comprehensions 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 Thu May 29 16:44:55 2003 @@ -53,15 +53,11 @@ is True. If function is None, then return the items in the sequence which are True.""" - res = [] if function is None: - for elem in collection: - if elem: - res.append(elem) - else: - for elem in collection: - if function(elem): - res.append(elem) + res = [item for item in collection if item] + else: + res = [item for item in collection if function(item)] + if type(collection) is tuple: return tuple(res) elif type(collection) is str: From mwh at codespeak.net Thu May 29 16:45:25 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 16:45:25 +0200 (MEST) Subject: [pypy-svn] rev 686 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030529144525.349305AC8A@thoth.codespeak.net> Author: mwh Date: Thu May 29 16:45:24 2003 New Revision: 686 Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Log: add tests for extended slices Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Thu May 29 16:45:24 2003 @@ -51,23 +51,44 @@ space = self.space w = space.wrap w_str = w('abc') + w_slice = space.newslice(w(0), w(0), None) self.assertEqual_w(space.getitem(w_str, w_slice), w('')) + w_slice = space.newslice(w(0), w(1), None) self.assertEqual_w(space.getitem(w_str, w_slice), w('a')) + w_slice = space.newslice(w(0), w(10), None) self.assertEqual_w(space.getitem(w_str, w_slice), w('abc')) + w_slice = space.newslice(space.w_None, space.w_None, None) self.assertEqual_w(space.getitem(w_str, w_slice), w('abc')) + w_slice = space.newslice(space.w_None, w(-1), None) self.assertEqual_w(space.getitem(w_str, w_slice), w('ab')) + w_slice = space.newslice(w(-1), space.w_None, None) self.assertEqual_w(space.getitem(w_str, w_slice), w('c')) def test_extended_slice(self): space = self.space + w_None = space.w_None w = space.wrap - w_str = w('abc') + w_str = w('hello') + + w_slice = space.newslice(w_None, w_None, w(1)) + self.assertEqual_w(space.getitem(w_str, w_slice), w('hello')) + + w_slice = space.newslice(w_None, w_None, w(-1)) + self.assertEqual_w(space.getitem(w_str, w_slice), w('olleh')) + + w_slice = space.newslice(w_None, w_None, w(2)) + self.assertEqual_w(space.getitem(w_str, w_slice), w('hlo')) + + w_slice = space.newslice(w(1), w_None, w(2)) + self.assertEqual_w(space.getitem(w_str, w_slice), w('el')) + + if __name__ == '__main__': testsupport.main() From tomek at codespeak.net Thu May 29 16:46:20 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 16:46:20 +0200 (MEST) Subject: [pypy-svn] rev 687 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030529144620.3F7335AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 16:46:19 2003 New Revision: 687 Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Log: small changes Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Thu May 29 16:46:19 2003 @@ -1,4 +1,6 @@ import testsupport +import pypy.objspace.std.stringobject as so + from pypy.objspace.std.stringobject import string_richcompare, W_StringObject, EQ, LT, GT, NE, LE, GE from pypy.objspace.std.objspace import StdObjSpace @@ -15,8 +17,18 @@ space = self.space def w(txt): return W_StringObject(space, txt) + strs = ['ala', 'bla', 'ala', 'alaaa', 'blaa', 'g'] + ops = [ 'EQ', 'LT', 'GT', 'NE', 'LE', 'GE' ] + + for op in ops: + pass + #print getattr('a', '__%s__' % op.lower()) + #while strs[1:]: + + self.failUnless_w(string_richcompare(space, w('abc'), w('abc'), EQ)) + def test_equality(self): w = self.space.wrap From tismer at codespeak.net Thu May 29 16:54:25 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 16:54:25 +0200 (MEST) Subject: [pypy-svn] rev 688 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529145425.008FF5AC8A@thoth.codespeak.net> Author: tismer Date: Thu May 29 16:54:25 2003 New Revision: 688 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: list.remove works Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 16:54:25 2003 @@ -37,6 +37,9 @@ def pop(w_self, w_idx=-1): return list_pop(w_self.space, w_self, w_idx) + def remove(w_self, w_any): + return list_remove(w_self.space, w_self, w_any) + def list_unwrap(space, w_list): items = [space.unwrap(w_item) for w_item in w_list.ob_item[:w_list.ob_size]] return list(items) @@ -193,6 +196,9 @@ if space.is_true(space.eq(w_attr, space.wrap('pop'))): w_builtinfn = make_builtin_func(space, W_ListObject.pop) return W_InstMethObject(space, w_list, w_builtinfn) + if space.is_true(space.eq(w_attr, space.wrap('remove'))): + w_builtinfn = make_builtin_func(space, W_ListObject.remove) + return W_InstMethObject(space, w_list, w_builtinfn) raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_list, W_ListObject, W_ANY) @@ -304,6 +310,7 @@ recycle = [items[i] for i in range(ilow, ihigh)] for i in range(ilow, ihigh): items[i] = items[i+d] + w_list.ob_size -= d # note that the default value will come back wrapped!!! def list_pop(space, w_list, w_idx=-1): @@ -320,6 +327,17 @@ _del_slice(w_list, i, i+1) return w_res +def list_remove(space, w_list, w_any): + eq = space.eq + items = w_list.ob_item + for i in range(w_list.ob_size): + cmp = eq(items[i], w_any) + if space.is_true(cmp): + _del_slice(w_list, i, i+1) + return space.w_None + raise OperationError(space.w_IndexError, + space.wrap("list.remove(x): x not in list")) + """ static PyMethodDef list_methods[] = { {"append", (PyCFunction)listappend, METH_O, append_doc}, From tismer at codespeak.net Thu May 29 16:58:30 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 16:58:30 +0200 (MEST) Subject: [pypy-svn] rev 689 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529145830.B844E5AC8A@thoth.codespeak.net> Author: tismer Date: Thu May 29 16:58:30 2003 New Revision: 689 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: list.index works Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 16:58:30 2003 @@ -40,6 +40,9 @@ def remove(w_self, w_any): return list_remove(w_self.space, w_self, w_any) + def index(w_self, w_any): + return list_index(w_self.space, w_self, w_any) + def list_unwrap(space, w_list): items = [space.unwrap(w_item) for w_item in w_list.ob_item[:w_list.ob_size]] return list(items) @@ -199,6 +202,9 @@ if space.is_true(space.eq(w_attr, space.wrap('remove'))): w_builtinfn = make_builtin_func(space, W_ListObject.remove) return W_InstMethObject(space, w_list, w_builtinfn) + if space.is_true(space.eq(w_attr, space.wrap('index'))): + w_builtinfn = make_builtin_func(space, W_ListObject.index) + return W_InstMethObject(space, w_list, w_builtinfn) raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_list, W_ListObject, W_ANY) @@ -338,6 +344,17 @@ raise OperationError(space.w_IndexError, space.wrap("list.remove(x): x not in list")) +def list_index(space, w_list, w_any): + eq = space.eq + items = w_list.ob_item + for i in range(w_list.ob_size): + cmp = eq(items[i], w_any) + if space.is_true(cmp): + return space.wrap(i) + raise OperationError(space.w_ValueError, + space.wrap("list.index(x): x not in list")) + + """ static PyMethodDef list_methods[] = { {"append", (PyCFunction)listappend, METH_O, append_doc}, From tismer at codespeak.net Thu May 29 17:01:46 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 17:01:46 +0200 (MEST) Subject: [pypy-svn] rev 690 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529150146.53A2A5AC8A@thoth.codespeak.net> Author: tismer Date: Thu May 29 17:01:45 2003 New Revision: 690 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: list.count works Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 17:01:45 2003 @@ -43,6 +43,9 @@ def index(w_self, w_any): return list_index(w_self.space, w_self, w_any) + def count(w_self, w_any): + return list_count(w_self.space, w_self, w_any) + def list_unwrap(space, w_list): items = [space.unwrap(w_item) for w_item in w_list.ob_item[:w_list.ob_size]] return list(items) @@ -205,6 +208,9 @@ if space.is_true(space.eq(w_attr, space.wrap('index'))): w_builtinfn = make_builtin_func(space, W_ListObject.index) return W_InstMethObject(space, w_list, w_builtinfn) + if space.is_true(space.eq(w_attr, space.wrap('count'))): + w_builtinfn = make_builtin_func(space, W_ListObject.count) + return W_InstMethObject(space, w_list, w_builtinfn) raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_list, W_ListObject, W_ANY) @@ -354,6 +360,15 @@ raise OperationError(space.w_ValueError, space.wrap("list.index(x): x not in list")) +def list_count(space, w_list, w_any): + eq = space.eq + items = w_list.ob_item + count = r_int(0) + for i in range(w_list.ob_size): + cmp = eq(items[i], w_any) + if space.is_true(cmp): + count += 1 + return space.wrap(count) """ static PyMethodDef list_methods[] = { From tomek at codespeak.net Thu May 29 17:03:01 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 17:03:01 +0200 (MEST) Subject: [pypy-svn] rev 691 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030529150301.BDF355AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 17:03:01 2003 New Revision: 691 Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Log: generic tests for rich comparission Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Thu May 29 17:03:01 2003 @@ -17,17 +17,20 @@ space = self.space def w(txt): return W_StringObject(space, txt) - strs = ['ala', 'bla', 'ala', 'alaaa', 'blaa', 'g'] + strs = ['ala', 'bla', 'ala', 'alaaa', '', 'b'] ops = [ 'EQ', 'LT', 'GT', 'NE', 'LE', 'GE' ] - for op in ops: - pass - #print getattr('a', '__%s__' % op.lower()) - #while strs[1:]: - - - - self.failUnless_w(string_richcompare(space, w('abc'), w('abc'), EQ)) + while strs[1:]: + str1 = strs.pop() + for op in ops: + orf = getattr(str1, '__%s__' % op.lower()) #original python function + pypyconst = getattr(so, op) + for str2 in strs: + if orf(str2): + self.failUnless_w(string_richcompare(space, w(str1), w(str2), pypyconst)) + else: + self.failIf_w(string_richcompare(space, w(str1), w(str2), pypyconst)) + def test_equality(self): From mwh at codespeak.net Thu May 29 17:05:07 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 17:05:07 +0200 (MEST) Subject: [pypy-svn] rev 692 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030529150507.709D25AC8A@thoth.codespeak.net> Author: mwh Date: Thu May 29 17:05:06 2003 New Revision: 692 Added: pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py Modified: pypy/trunk/src/pypy/objspace/std/listobject.py pypy/trunk/src/pypy/objspace/std/sliceobject.py pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/tupleobject.py Log: Remove now-superfluous 'space' argument to W_SliceObject.indices and all call sites. Add one test for same. Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 17:05:06 2003 @@ -78,7 +78,7 @@ def getitem_list_slice(space, w_list, w_slice): items = w_list.ob_item w_length = space.wrap(w_list.ob_size) - w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length) + w_start, w_stop, w_step, w_slicelength = w_slice.indices(w_length) start = space.unwrap(w_start) step = space.unwrap(w_step) slicelength = space.unwrap(w_slicelength) @@ -173,7 +173,7 @@ def setitem_list_slice(space, w_list, w_slice, w_list2): items = w_list.ob_item w_length = space.wrap(w_list.ob_size) - w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length) + w_start, w_stop, w_step, w_slicelength = w_slice.indices(w_length) start = space.unwrap(w_start) step = space.unwrap(w_step) slicelength = space.unwrap(w_slicelength) Modified: pypy/trunk/src/pypy/objspace/std/sliceobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/sliceobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/sliceobject.py Thu May 29 17:05:06 2003 @@ -12,14 +12,12 @@ w_self.w_start = w_start w_self.w_stop = w_stop w_self.w_step = w_step - def indices(w_self, space, w_length): - w_ret = space.gethelper(appfile).call("sliceindices", [w_self, w_length]) - w_start, w_stop, w_step, w_slicelength = space.unpackiterable(w_ret, 4) - return w_start, w_stop, w_step, w_slicelength - def indices2(w_self, w_length): + def indices(w_self, w_length): w_ret = w_self.space.gethelper(appfile).call("sliceindices", [w_self, w_length]) w_start, w_stop, w_step, w_slicelength = w_self.space.unpackiterable(w_ret, 4) - return w_self.space.newtuple([w_start, w_stop, w_step, w_slicelength]) + return w_start, w_stop, w_step, w_slicelength + def indices2(w_self, w_length): + return w_self.space.newtuple(w_self.indices(w_length)[:-1]) def getattr_slice_any(space, w_slice, w_attr): Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 17:05:06 2003 @@ -231,7 +231,7 @@ def getitem_str_slice(space, w_str, w_slice): w = space.wrap u = space.unwrap - w_start, w_stop, w_step, w_sl = w_slice.indices(space, w(w_str._value.len)) + w_start, w_stop, w_step, w_sl = w_slice.indices(w(w_str._value.len)) start = u(w_start) stop = u(w_stop) step = u(w_step) Added: pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py Thu May 29 17:05:06 2003 @@ -0,0 +1,24 @@ +import testsupport + +class TestW_SliceObject(testsupport.TestCase): + + def setUp(self): + self.space = testsupport.objspace() + + def tearDown(self): + pass + + def equal_indices(self, got, expected): + for g, e in zip(got, expected): + self.assertEqual_w(g, self.space.wrap(e)) + + def test_indices(self): + space = self.space + w = space.wrap + w_None = space.w_None + w_slice = space.newslice(w_None, w_None, w_None) + self.equal_indices(w_slice.indices(w(6)), (0, 6, 1, 6)) + + +if __name__ == '__main__': + testsupport.main() Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Thu May 29 17:05:06 2003 @@ -46,7 +46,7 @@ def getitem_tuple_slice(space, w_tuple, w_slice): items = w_tuple.wrappeditems w_length = space.wrap(len(items)) - w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length) + w_start, w_stop, w_step, w_slicelength = w_slice.indices(w_length) start = space.unwrap(w_start) step = space.unwrap(w_step) slicelength = space.unwrap(w_slicelength) From tomek at codespeak.net Thu May 29 17:12:07 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 17:12:07 +0200 (MEST) Subject: [pypy-svn] rev 693 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529151207.58E455AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 17:12:06 2003 New Revision: 693 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: ok Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 17:12:06 2003 @@ -142,10 +142,11 @@ else: min_len = str1.len + c = 0 idx = 0 if (min_len > 0): while (c == 0) and (idx < min_len): - c = ord(str1.charat[idx]) - ord(str2.charat[idx]) + c = ord(str1.charat(idx)) - ord(str2.charat(idx)) idx = idx + 1 else: c = 0 @@ -153,7 +154,7 @@ if (c == 0): if str1.len < str2.len: c = -1 - elif str1.len > str2.leb: + elif str1.len > str2.len: c = 1 else: c = 0 @@ -165,7 +166,7 @@ elif op == NE: return space.newbool(c != 0) elif op == GT: - return space.newbook(c > 0) + return space.newbool(c > 0) elif op == GE: return space.newbool(c >= 0) else: From tismer at codespeak.net Thu May 29 17:14:36 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 17:14:36 +0200 (MEST) Subject: [pypy-svn] rev 694 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529151436.7D5685AC8A@thoth.codespeak.net> Author: tismer Date: Thu May 29 17:14:36 2003 New Revision: 694 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: list.reverse works Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 17:14:36 2003 @@ -46,6 +46,9 @@ def count(w_self, w_any): return list_count(w_self.space, w_self, w_any) + def reverse(w_self): + return list_reverse(w_self.space, w_self) + def list_unwrap(space, w_list): items = [space.unwrap(w_item) for w_item in w_list.ob_item[:w_list.ob_size]] return list(items) @@ -211,6 +214,9 @@ if space.is_true(space.eq(w_attr, space.wrap('count'))): w_builtinfn = make_builtin_func(space, W_ListObject.count) return W_InstMethObject(space, w_list, w_builtinfn) + if space.is_true(space.eq(w_attr, space.wrap('reverse'))): + w_builtinfn = make_builtin_func(space, W_ListObject.reverse) + return W_InstMethObject(space, w_list, w_builtinfn) raise FailedToImplement(space.w_AttributeError) StdObjSpace.getattr.register(getattr_list, W_ListObject, W_ANY) @@ -370,6 +376,23 @@ count += 1 return space.wrap(count) +# Reverse a slice of a list in place, from lo up to (exclusive) hi. +# (also used in sort, later) + +def _reverse_slice(lis, lo, hi): + hi -= 1 + while lo < hi: + t = lis[lo] + lis[lo] = lis[hi] + lis[hi] = t + lo += 1 + hi -= 1 + +def list_reverse(space, w_list): + if w_list.ob_size > 1: + _reverse_slice(w_list.ob_item, 0, w_list.ob_size) + return space.w_None + """ static PyMethodDef list_methods[] = { {"append", (PyCFunction)listappend, METH_O, append_doc}, From jacob at codespeak.net Thu May 29 17:14:54 2003 From: jacob at codespeak.net (jacob at codespeak.net) Date: Thu, 29 May 2003 17:14:54 +0200 (MEST) Subject: [pypy-svn] rev 695 - pypy/trunk/src/pypy/interpreter Message-ID: <20030529151454.AB57C5AC8A@thoth.codespeak.net> Author: jacob Date: Thu May 29 17:14:54 2003 New Revision: 695 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py Log: Fixed missing self Modified: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Thu May 29 17:14:54 2003 @@ -86,7 +86,7 @@ w_dict = space.getattr(w_module, space.wrap("__dict__")) appfile.AppHelper(space, sappfile, w_dict) - def callhelp(functioname,argslist): + def callhelp(self, functioname, argslist): if self._helper is None: self._helper = appfile.AppHelper(self.space, self.__helper_appfile__) From arigo at codespeak.net Thu May 29 17:21:49 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 29 May 2003 17:21:49 +0200 (MEST) Subject: [pypy-svn] rev 696 - in pypy/trunk/src/pypy: interpreter objspace/std Message-ID: <20030529152149.CF2415AC8F@thoth.codespeak.net> Author: arigo Date: Thu May 29 17:21:48 2003 New Revision: 696 Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py pypy/trunk/src/pypy/objspace/std/default.py pypy/trunk/src/pypy/objspace/std/dictobject.py pypy/trunk/src/pypy/objspace/std/funcobject.py pypy/trunk/src/pypy/objspace/std/instmethobject.py pypy/trunk/src/pypy/objspace/std/multimethod.py pypy/trunk/src/pypy/objspace/std/objspace.py pypy/trunk/src/pypy/objspace/std/tupleobject.py pypy/trunk/src/pypy/objspace/std/typeobject.py Log: nice general methods for our built-in objects Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/baseobjspace.py (original) +++ pypy/trunk/src/pypy/interpreter/baseobjspace.py Thu May 29 17:21:48 2003 @@ -222,6 +222,7 @@ ('iter', 'iter', 1, ['__iter__']), ('next', 'next', 1, ['next']), # iterator interface ('call', 'call', 3, ['__call__']), + ('get', 'get', 3, ['__get__']), ] ObjSpace.BuiltinModuleTable = [ Modified: pypy/trunk/src/pypy/objspace/std/default.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/default.py (original) +++ pypy/trunk/src/pypy/objspace/std/default.py Thu May 29 17:21:48 2003 @@ -49,13 +49,24 @@ #w_type = space.type(w_obj) #w_typename = space.getattr(w_type, space.wrap('__name__')) #... - - # XXX as long as don't have types... + + w_type = space.type(w_obj) if space.is_true(space.eq(w_attr, space.wrap('__class__'))): - return space.wrap(space.unwrap(w_obj).__class__) + return w_type + # XXX implement lookup as a multimethod + from typeobject import W_TypeObject + if isinstance(w_type, W_TypeObject): # XXX must always be true at some point + try: + w_value = w_type.lookup(space, w_attr) + except KeyError: + pass + else: + return space.get(w_value, w_obj, w_type) + raise OperationError(space.w_AttributeError, w_attr) + StdObjSpace.getattr.register(default_getattr, W_ANY, W_ANY) def default_setattr(space, w_obj, w_attr, w_value): @@ -92,3 +103,23 @@ return space.w_True StdObjSpace.contains.register(default_contains, W_ANY, W_ANY) + + +# '__get__(descr, inst, cls)' returns 'descr' by default + +def default_get(space, w_descr, w_inst, w_cls): + return w_descr + +StdObjSpace.get.register(default_get, W_ANY, W_ANY, W_ANY) + + +# static types + +def default_type(space, w_obj): + w_type = w_obj.statictype + if w_type is None: + # XXX remove me, temporary + return space.wrap(space.unwrap(w_obj).__class__) + return w_type + +StdObjSpace.type.register(default_type, W_ANY) 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 Thu May 29 17:21:48 2003 @@ -33,6 +33,7 @@ class W_DictObject(W_Object): delegate_once = {} + statictypename = 'dict' def __init__(w_self, space, list_pairs_w): W_Object.__init__(w_self, space) @@ -79,7 +80,13 @@ return space.newlist([ cell.get() for w_key,cell in w_self.non_empties()]) - + + copy = implmethod().register(copy) + items = implmethod().register(items) + keys = implmethod().register(keys) + values = implmethod().register(values) + + def dict_is_true(space, w_dict): return not not w_dict.non_empties() @@ -132,22 +139,22 @@ StdObjSpace.contains.register(contains_dict_any, W_DictObject, W_ANY) -def getattr_dict(space, w_dict, w_attr): - if space.is_true(space.eq(w_attr, space.wrap('copy'))): - w_builtinfn = make_builtin_func(space, W_DictObject.copy) - return W_InstMethObject(space, w_dict, w_builtinfn) - if space.is_true(space.eq(w_attr, space.wrap('items'))): - w_builtinfn = make_builtin_func(space, W_DictObject.items) - return W_InstMethObject(space, w_dict, w_builtinfn) - if space.is_true(space.eq(w_attr, space.wrap('keys'))): - w_builtinfn = make_builtin_func(space, W_DictObject.keys) - return W_InstMethObject(space, w_dict, w_builtinfn) - if space.is_true(space.eq(w_attr, space.wrap('values'))): - w_builtinfn = make_builtin_func(space, W_DictObject.values) - return W_InstMethObject(space, w_dict, w_builtinfn) - raise FailedToImplement(space.w_AttributeError) +##def getattr_dict(space, w_dict, w_attr): +## if space.is_true(space.eq(w_attr, space.wrap('copy'))): +## w_builtinfn = make_builtin_func(space, W_DictObject.copy) +## return W_InstMethObject(space, w_dict, w_builtinfn) +## if space.is_true(space.eq(w_attr, space.wrap('items'))): +## w_builtinfn = make_builtin_func(space, W_DictObject.items) +## return W_InstMethObject(space, w_dict, w_builtinfn) +## if space.is_true(space.eq(w_attr, space.wrap('keys'))): +## w_builtinfn = make_builtin_func(space, W_DictObject.keys) +## return W_InstMethObject(space, w_dict, w_builtinfn) +## if space.is_true(space.eq(w_attr, space.wrap('values'))): +## w_builtinfn = make_builtin_func(space, W_DictObject.values) +## return W_InstMethObject(space, w_dict, w_builtinfn) +## raise FailedToImplement(space.w_AttributeError) -StdObjSpace.getattr.register(getattr_dict, W_DictObject, W_ANY) +##StdObjSpace.getattr.register(getattr_dict, W_DictObject, W_ANY) def eq_dict_dict(space, w_left, w_right): if len(w_left.data) != len(w_right.data): Modified: pypy/trunk/src/pypy/objspace/std/funcobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/funcobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/funcobject.py Thu May 29 17:21:48 2003 @@ -1,6 +1,7 @@ from __future__ import nested_scopes from pypy.objspace.std.objspace import * import pypy.interpreter.pyframe +from pypy.objspace.std.instmethobject import W_InstMethObject class W_FuncObject(W_Object): @@ -35,3 +36,9 @@ return w_ret StdObjSpace.call.register(func_call, W_FuncObject, W_ANY, W_ANY) + + +def func_get(space, w_function, w_instance, w_cls): + return W_InstMethObject(space, w_instance, w_function) + +StdObjSpace.get.register(func_get, W_FuncObject, W_ANY, W_ANY) Modified: pypy/trunk/src/pypy/objspace/std/instmethobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/instmethobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/instmethobject.py Thu May 29 17:21:48 2003 @@ -29,3 +29,6 @@ return w_ret StdObjSpace.call.register(instmeth_call, W_InstMethObject, W_ANY, W_ANY) + + +# XXX do __get__ for instance methods Modified: pypy/trunk/src/pypy/objspace/std/multimethod.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/multimethod.py (original) +++ pypy/trunk/src/pypy/objspace/std/multimethod.py Thu May 29 17:21:48 2003 @@ -103,7 +103,7 @@ w_value = self.space.wrap(message) raise OperationError(self.space.w_TypeError, w_value) - def perform_call(self, args, initialtypes): + def perform_call(self, args, initialtypes, prepend_space_argument=True): extraargs = args[self.multimethod.arity:] choicelist = self.multimethod.buildchoices(initialtypes) firstfailure = None @@ -114,8 +114,10 @@ arg = delegator(self.space, arg) newargs.append(arg) newargs = tuple(newargs) + extraargs + if prepend_space_argument: + newargs = (self.space,) + newargs try: - return function(self.space, *newargs) + return function(*newargs) except FailedToImplement, e: # we got FailedToImplement, record the first such error if firstfailure is None: 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 Thu May 29 17:21:48 2003 @@ -19,6 +19,18 @@ return w_self.__class__ +class implmethod(object): + def __init__(self): + self.dispatch_table = {} + def register(self, function, *types): + if types in self.dispatch_table: + raise error, "we already got an implementation for %r" % types + self.dispatch_table[types] = function + return self + def __get__(self, instance, cls=None): + raise "XXX come back later" + + ################################################################## class StdObjSpace(ObjSpace): @@ -37,10 +49,11 @@ 'W_IntObject': 'intobject', 'W_FloatObject': 'floatobject', #'W_ListObject': 'listobject', + 'W_DictObject': 'dictobject', } - TYPE_CACHE = {} def initialize(self): + self.TYPE_CACHE = {} from noneobject import W_NoneObject from boolobject import W_BoolObject from cpythonobject import W_CPythonObject Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Thu May 29 17:21:48 2003 @@ -5,6 +5,9 @@ class W_TupleObject(W_Object): + delegate_once = {} + statictypename = 'tuple' + def __init__(w_self, space, wrappeditems): W_Object.__init__(w_self, space) w_self.wrappeditems = wrappeditems # a list of wrapped values Modified: pypy/trunk/src/pypy/objspace/std/typeobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/typeobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/typeobject.py Thu May 29 17:21:48 2003 @@ -1,5 +1,6 @@ from pypy.interpreter import pycode from pypy.objspace.std.objspace import * +from pypy.objspace.std.dictobject import W_DictObject class W_TypeObject(W_Object): @@ -10,12 +11,41 @@ W_Object.__init__(w_self, space) w_self.w_tpname = w_tpname w_self.builtin_implementations = [] - w_self.multimethods = [value for key, value in space.__dict__.iteritems() - if isinstance(value, MultiMethod)] + w_self.multimethods = {} + # HACK to get to the multimethods of the space + for key, value in space.__class__.__dict__.iteritems(): + if isinstance(value, MultiMethod): + for i in range(len(value.specialnames)): + w_self.multimethods[value.specialnames[i]] = value, i def setup_builtin_type(w_self, implementation): implementation.statictype = w_self w_self.builtin_implementations.append(implementation) + + for key, value in implementation.__dict__.iteritems(): + if isinstance(value, implmethod): + try: + multimethod, bound_pos = w_self.multimethods[key] + except KeyError: + sample = value.dispatch_table.keys()[0] + multimethod = MultiMethod('%s()' % key, len(sample)+1, []) + w_self.multimethods[key] = multimethod, None + for types, func in value.dispatch_table.iteritems(): + multimethod.register(func, implementation, *types) + + def lookup(w_self, space, w_key): + "XXX at some point, turn this into a multimethod" + key = space.unwrap(w_key) + assert isinstance(key, str) + try: + multimethod, bound_pos = w_self.multimethods[key] + except KeyError: + raise KeyError + multimethod = multimethod.__get__(space, None) + code = PyMultimethodCode(multimethod, bound_pos, w_self) + if code.multimethod.is_empty(): + raise KeyError + return space.newfunction(code, space.w_None, space.w_None) def make_type_by_name(space, tpname): @@ -33,8 +63,14 @@ pycode.PyBaseCode.__init__(self) argnames = ['x%d'%(i+1) for i in range(multimethod.multimethod.arity)] if w_type is not None: - multimethod = multimethod.slicetable(bound_position, w_type) - argnames.insert(0, argnames.pop(bound_position)) + # 'bound_pos' hack mode on + multimethod = multimethod.slicetable(bound_position or 0, w_type) + # 'bound_pos' hack mode off + if bound_position: + argnames.insert(0, argnames.pop(bound_position)) + # 'bound_pos' hack mode on + self.prepend_space_argument = bound_position is not None + # 'bound_pos' hack mode off self.multimethod = multimethod self.co_name = multimethod.multimethod.operatorsymbol self.co_flags = 0 @@ -54,7 +90,8 @@ dispatchargs = tuple(dispatchargs) initialtypes = tuple(initialtypes) try: - return multimethod.perform_call(dispatchargs, initialtypes) + return multimethod.perform_call(dispatchargs, initialtypes, + prepend_space_argument = self.prepend_space_argument) except FailedToImplement, e: if e.args: raise OperationError(*e.args) From tomek at codespeak.net Thu May 29 17:26:21 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 17:26:21 +0200 (MEST) Subject: [pypy-svn] rev 697 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529152621.B28E45AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 17:26:21 2003 New Revision: 697 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: a small problem with is_ Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 17:26:21 2003 @@ -119,14 +119,20 @@ NE = 6 def string_richcompare(space, w_str1, w_str2, op): + print "string_richcompare ", w_str1, w_str2, op str1 = w_str1._value str2 = w_str2._value - if space.is_(str1, str2): - if op == EQ or op == LE or op == GE: - return space.w_True - elif op == GT or op == LT or op == NE: - return space.w_False + #There is still problem with it + # + #if space.is_(w_str1, w_str2): + # print "Oooh, str1 and str2 are the same!" + # if op == EQ or op == LE or op == GE: + # return space.w_True + # elif op == GT or op == LT or op == NE: + # return space.w_False + if 0: + pass else: if op == EQ: if str1.len == str2.len: @@ -159,6 +165,7 @@ else: c = 0 + print "c is ", c if op == LT: return space.newbool(c < 0) elif op == LE: @@ -197,9 +204,10 @@ StdObjSpace.eq.register(str_str_eq, W_StringObject, W_StringObject) def str_str_ne(space, w_str1, w_str2): - i = w_str1._value.value() - j = w_str2._value.value() - return space.newbool( i != j ) + #i = w_str1._value.value() + #j = w_str2._value.value() + #return space.newbool( i != j ) + return string_richcompare(space, w_str1, w_str2, NE) StdObjSpace.ne.register(str_str_ne, W_StringObject, W_StringObject) def str_str_gt(space, w_str1, w_str2): From tomek at codespeak.net Thu May 29 17:33:47 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 17:33:47 +0200 (MEST) Subject: [pypy-svn] rev 698 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529153347.3121B5AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 17:33:46 2003 New Revision: 698 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: id now works Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 17:33:46 2003 @@ -123,14 +123,11 @@ str1 = w_str1._value str2 = w_str2._value - #There is still problem with it - # - #if space.is_(w_str1, w_str2): - # print "Oooh, str1 and str2 are the same!" - # if op == EQ or op == LE or op == GE: - # return space.w_True - # elif op == GT or op == LT or op == NE: - # return space.w_False + if space.is_true(space.is_(w_str1, w_str2)): + if op == EQ or op == LE or op == GE: + return space.w_True + elif op == GT or op == LT or op == NE: + return space.w_False if 0: pass else: @@ -165,7 +162,6 @@ else: c = 0 - print "c is ", c if op == LT: return space.newbool(c < 0) elif op == LE: From arigo at codespeak.net Thu May 29 17:35:52 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 29 May 2003 17:35:52 +0200 (MEST) Subject: [pypy-svn] rev 699 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529153552.9AB085AC8A@thoth.codespeak.net> Author: arigo Date: Thu May 29 17:35:52 2003 New Revision: 699 Modified: pypy/trunk/src/pypy/objspace/std/boolobject.py Log: safety check Modified: pypy/trunk/src/pypy/objspace/std/boolobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/boolobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/boolobject.py Thu May 29 17:35:52 2003 @@ -16,6 +16,9 @@ return (isinstance(w_other, W_BoolObject) and w_self.boolval == w_other.boolval) + def __nonzero__(self): + raise "you cannot do that, you must use space.is_true()" + def bool_is_true(space, w_bool): return w_bool.boolval From tomek at codespeak.net Thu May 29 17:36:31 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 17:36:31 +0200 (MEST) Subject: [pypy-svn] rev 700 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529153631.D60885AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 17:36:31 2003 New Revision: 700 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: ok, comparission works now Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 17:36:31 2003 @@ -119,7 +119,6 @@ NE = 6 def string_richcompare(space, w_str1, w_str2, op): - print "string_richcompare ", w_str1, w_str2, op str1 = w_str1._value str2 = w_str2._value @@ -176,40 +175,27 @@ raise NotImplemented def str_str_lt(space, w_str1, w_str2): - i = w_str1._value.value() - j = w_str2._value.value() - return space.newbool( i < j ) + return string_richcompare(space, w_str1, w_str2, LT) + StdObjSpace.lt.register(str_str_lt, W_StringObject, W_StringObject) def str_str_le(space, w_str1, w_str2): - i = w_str1._value.value() - j = w_str2._value.value() - return space.newbool( i <= j ) + return string_richcompare(space, w_str1, w_str2, LE) + StdObjSpace.le.register(str_str_le, W_StringObject, W_StringObject) def str_str_eq(space, w_str1, w_str2): - val1 = w_str1._value - val2 = w_str2._value - if val1.len == val2.len: - for i in range(val1.len): - if ord(val1.charat(i)) != ord(val2.charat(i)): - return space.w_False - return space.w_True - else: - return space.w_False + return string_richcompare(space, w_str1, w_str2, EQ) + StdObjSpace.eq.register(str_str_eq, W_StringObject, W_StringObject) def str_str_ne(space, w_str1, w_str2): - #i = w_str1._value.value() - #j = w_str2._value.value() - #return space.newbool( i != j ) return string_richcompare(space, w_str1, w_str2, NE) StdObjSpace.ne.register(str_str_ne, W_StringObject, W_StringObject) def str_str_gt(space, w_str1, w_str2): - i = w_str1._value.value() - j = w_str2._value.value() - return space.newbool( i > j ) + return string_richcompare(space, w_str1, w_str2, GT) + StdObjSpace.gt.register(str_str_gt, W_StringObject, W_StringObject) def str_str_ge(space, w_str1, w_str2): From lac at codespeak.net Thu May 29 17:39:00 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Thu, 29 May 2003 17:39:00 +0200 (MEST) Subject: [pypy-svn] rev 701 - in pypy/trunk/src/pypy/module: . test Message-ID: <20030529153900.56AB65AC8A@thoth.codespeak.net> Author: lac Date: Thu May 29 17:38:59 2003 New Revision: 701 Added: pypy/trunk/src/pypy/module/test/test_zip.py Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: Made more test for the zip function. 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 Thu May 29 17:38:59 2003 @@ -66,6 +66,11 @@ return res def zip(*collections): + """return a list of tuples, where the nth tuple contains every + nth item of each collection. If the collections have different + lengths, zip returns a list as long as the shortest collection, + ignoring the trailing items in the other collections.""" + if len(collections) == 0: raise TypeError, "zip() requires at least one sequence" res = [] Added: pypy/trunk/src/pypy/module/test/test_zip.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/test_zip.py Thu May 29 17:38:59 2003 @@ -0,0 +1,33 @@ +import testsupport +from pypy.module.builtin_app import zip + +class TestZip(testsupport.TestCase): + + def test_zip_no_arguments(self): + self.assertRaises(TypeError, zip) + + def test_one_list(self): + self.assertEqual(zip([1, 2, 3]), [(1,), (2,), (3,)]) + + def test_three_lists_same_size(self): + self.assertEqual(zip([1, 2, 3], [3, 4, 5], [6, 7, 8]), + [(1, 3, 6), (2, 4, 7), (3, 5, 8)]) + + def test_three_lists_different_sizes(self): + self.assertEqual(zip([1, 2], [3, 4, 5, 6], [6, 7, 8]), + [(1, 3, 6), (2, 4, 7)]) + + def test_tuples(self): + self.assertEqual(zip((1, 2, 3)), [(1,), (2,), (3,)]) + + def test_string(self): + self.assertEqual(zip('hello'), [('h',), ('e',), ('l',), ('l',), ('o',)]) + + def test_mixed_types(self): + self.assertEqual(zip('hello', [1,2,3,4], (7,8,9,10)), + [('h', 1, 7), ('e', 2, 8), ('l', 3, 9), ('l', 4, 10)]) + +if __name__ == '__main__': + testsupport.main() + + From mwh at codespeak.net Thu May 29 17:40:26 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 17:40:26 +0200 (MEST) Subject: [pypy-svn] rev 702 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529154026.E7AF75AC8A@thoth.codespeak.net> Author: mwh Date: Thu May 29 17:40:26 2003 New Revision: 702 Modified: pypy/trunk/src/pypy/objspace/std/boolobject.py Log: string exceptions are eeviil... Modified: pypy/trunk/src/pypy/objspace/std/boolobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/boolobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/boolobject.py Thu May 29 17:40:26 2003 @@ -17,7 +17,7 @@ w_self.boolval == w_other.boolval) def __nonzero__(self): - raise "you cannot do that, you must use space.is_true()" + raise Exception, "you cannot do that, you must use space.is_true()" def bool_is_true(space, w_bool): From mwh at codespeak.net Thu May 29 17:42:12 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 17:42:12 +0200 (MEST) Subject: [pypy-svn] rev 703 - in pypy/trunk/src/pypy/objspace/std: . test Message-ID: <20030529154212.7BEC85AC8A@thoth.codespeak.net> Author: mwh Date: Thu May 29 17:42:12 2003 New Revision: 703 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py Log: app-space string slice works; now we have both, which do we use? also adds a couple tests to test_sliceobject, some disabled pending getting ****ing exceptions working properly Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 17:42:12 2003 @@ -220,6 +220,8 @@ W_StringObject, W_IntObject) def getitem_str_slice(space, w_str, w_slice): +# return space.gethelper(applicationfile).call( +# "getitem_string_slice", [w_str, w_slice]) w = space.wrap u = space.unwrap w_start, w_stop, w_step, w_sl = w_slice.indices(w(w_str._value.len)) @@ -233,8 +235,6 @@ w_r = space.newlist(r) w_empty = space.newstring([]) return w_empty.join(w_r) - return space.gethelper(applicationfile).call( - "getitem_string_slice", [w_str, w_slice]) StdObjSpace.getitem.register(getitem_str_slice, W_StringObject, W_SliceObject) Modified: pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py Thu May 29 17:42:12 2003 @@ -18,7 +18,20 @@ w_None = space.w_None w_slice = space.newslice(w_None, w_None, w_None) self.equal_indices(w_slice.indices(w(6)), (0, 6, 1, 6)) - + w_slice = space.newslice(w(0), w(6), w(1)) + self.equal_indices(w_slice.indices(w(6)), (0, 6, 1, 6)) + w_slice = space.newslice(w_None, w_None, w(-1)) + self.equal_indices(w_slice.indices(w(6)), (5, -1, -1, 6)) + + def XXXtest_indices_fail(self): + """ usual exception problems """ + space = self.space + w = space.wrap + w_None = space.w_None + w_slice = space.newslice(w_None, w_None, w(0)) + self.equal_indices(w_slice.indices(w(6)), (5, -1, -1, 6)) + self.assertRaises_w(space.w_ValueError, + w_slice.indices, w(10)) if __name__ == '__main__': testsupport.main() From arigo at codespeak.net Thu May 29 17:44:06 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 29 May 2003 17:44:06 +0200 (MEST) Subject: [pypy-svn] rev 704 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529154406.4F4545AC8A@thoth.codespeak.net> Author: arigo Date: Thu May 29 17:44:05 2003 New Revision: 704 Modified: pypy/trunk/src/pypy/objspace/std/default.py Log: other comparison operators fall back to 'eq' or 'lt' Modified: pypy/trunk/src/pypy/objspace/std/default.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/default.py (original) +++ pypy/trunk/src/pypy/objspace/std/default.py Thu May 29 17:44:05 2003 @@ -3,17 +3,29 @@ from pypy.objspace.std.objspace import * -# 'eq' and 'ne' fall back to 'is' +# 'eq' falls back to 'is' def default_eq(space, w_a, w_b): return space.is_(w_a, w_b) StdObjSpace.eq.register(default_eq, W_ANY, W_ANY) + +# 'ne' -> 'eq', 'le/gt/ge' -> 'lt' + def default_ne(space, w_a, w_b): - return space.not_(space.is_(w_a, w_b)) + return space.not_(space.eq(w_a, w_b)) +def default_le(space, w_a, w_b): + return space.not_(space.lt(w_b, w_a)) +def default_gt(space, w_a, w_b): + return space.lt(w_b, w_a) +def default_ge(space, w_a, w_b): + return space.not_(space.lt(w_a, w_b)) StdObjSpace.ne.register(default_ne, W_ANY, W_ANY) +StdObjSpace.le.register(default_le, W_ANY, W_ANY) +StdObjSpace.gt.register(default_gt, W_ANY, W_ANY) +StdObjSpace.ge.register(default_ge, W_ANY, W_ANY) # 'id' falls back to the address of the wrapper From tomek at codespeak.net Thu May 29 17:48:01 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 17:48:01 +0200 (MEST) Subject: [pypy-svn] rev 705 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529154801.4998A5AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 17:48:00 2003 New Revision: 705 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: ok Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 17:48:00 2003 @@ -199,9 +199,8 @@ StdObjSpace.gt.register(str_str_gt, W_StringObject, W_StringObject) def str_str_ge(space, w_str1, w_str2): - i = w_str1._value.value() - j = w_str2._value.value() - return space.newbool( i >= j ) + return string_richcompare(space, w_str1, w_str2, GE) + StdObjSpace.ge.register(str_str_ge, W_StringObject, W_StringObject) @@ -240,7 +239,10 @@ W_StringObject, W_SliceObject) def add_str_str(space, w_left, w_right): - return W_StringObject(space, w_left._value.value() + w_right._value.value()) + buf = CharArraySize(w_left._value.len + w_right._value.len) + buf.setsubstring(0, w_left._value.value()) + buf.setsubstring(w_left._value.len, w_right._value.value()) + return W_StringObject(space, buf.value()) StdObjSpace.add.register(add_str_str, W_StringObject, W_StringObject) From lac at codespeak.net Thu May 29 17:48:37 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Thu, 29 May 2003 17:48:37 +0200 (MEST) Subject: [pypy-svn] rev 706 - pypy/trunk/src/pypy/module/test Message-ID: <20030529154837.732A15AC8A@thoth.codespeak.net> Author: lac Date: Thu May 29 17:48:37 2003 New Revision: 706 Added: pypy/trunk/src/pypy/module/test/test_reduce.py Log: test_functional has now become test_map, test_filter, test_zip and test_reduce. test_reduce is the last one, so now test_functional can go away. Added: pypy/trunk/src/pypy/module/test/test_reduce.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/test_reduce.py Thu May 29 17:48:37 2003 @@ -0,0 +1,19 @@ +import testsupport +from pypy.module.builtin_app import reduce + +class TestReduce(testsupport.TestCase): + def test_None(self): + self.assertRaises(TypeError, reduce, lambda x, y: x+y, [1,2,3], None) + + def test_sum(self): + self.assertEqual(reduce(lambda x, y: x+y, [1,2,3,4], 0), 10) + self.assertEqual(reduce(lambda x, y: x+y, [1,2,3,4]), 10) + + def test_minus(self): + self.assertEqual(reduce(lambda x, y: x-y, [10, 2, 8]), 0) + self.assertEqual(reduce(lambda x, y: x-y, [2, 8], 10), 0) + +if __name__ == '__main__': + testsupport.main() + + From lac at codespeak.net Thu May 29 17:52:27 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Thu, 29 May 2003 17:52:27 +0200 (MEST) Subject: [pypy-svn] rev 707 - pypy/trunk/src/pypy/module Message-ID: <20030529155227.F2DB65AC8A@thoth.codespeak.net> Author: lac Date: Thu May 29 17:52:27 2003 New Revision: 707 Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: change reduce to not call its sequence 'list' 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 Thu May 29 17:52:27 2003 @@ -87,19 +87,23 @@ return res -def reduce(function, list, *initialt): +def reduce(function, l, *initialt): + """ Apply function of two arguments cumulatively to the items of + sequence, from left to right, so as to reduce the sequence to a + single value.""" + if initialt: initial, = initialt idx = 0 else: try: - initial = list[0] + initial = l[0] except IndexError: raise TypeError, "reduce() of empty sequence with no initial value" idx = 1 while 1: try: - initial = function(initial, list[idx]) + initial = function(initial, l[idx]) idx = idx + 1 except IndexError: break From lac at codespeak.net Thu May 29 18:01:05 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Thu, 29 May 2003 18:01:05 +0200 (MEST) Subject: [pypy-svn] rev 708 - pypy/trunk/src/pypy/module/test Message-ID: <20030529160105.36CE85AC8A@thoth.codespeak.net> Author: lac Date: Thu May 29 18:01:04 2003 New Revision: 708 Modified: pypy/trunk/src/pypy/module/test/test_zip.py Log: add test to see if zip is broken in ../builtin_app.py, or if the new strings are. zip was fine. Modified: pypy/trunk/src/pypy/module/test/test_zip.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_zip.py (original) +++ pypy/trunk/src/pypy/module/test/test_zip.py Thu May 29 18:01:04 2003 @@ -23,6 +23,10 @@ def test_string(self): self.assertEqual(zip('hello'), [('h',), ('e',), ('l',), ('l',), ('o',)]) + def test_strings(self): + self.assertEqual(zip('hello', 'bye'), + [('h', 'b'), ('e', 'y'), ('l', 'e')]) + def test_mixed_types(self): self.assertEqual(zip('hello', [1,2,3,4], (7,8,9,10)), [('h', 1, 7), ('e', 2, 8), ('l', 3, 9), ('l', 4, 10)]) From tismer at codespeak.net Thu May 29 18:20:55 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 18:20:55 +0200 (MEST) Subject: [pypy-svn] rev 709 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529162055.B5D0A5AC8A@thoth.codespeak.net> Author: tismer Date: Thu May 29 18:20:55 2003 New Revision: 709 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py pypy/trunk/src/pypy/objspace/std/objspace.py Log: list object is using the new method registry Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 18:20:55 2003 @@ -6,6 +6,8 @@ from restricted_int import r_int, r_uint class W_ListObject(W_Object): + delegate_once = {} + statictypename = 'list' def __init__(w_self, space, wrappeditems): W_Object.__init__(w_self, space) @@ -28,27 +30,43 @@ def append(w_self, w_obj): return list_append(w_self.space, w_self, w_obj) + append = implmethod().register(append, W_ANY) + def insert(w_self, w_idx, w_obj): return list_insert(w_self.space, w_self, w_idx, w_obj) + insert = implmethod().register(insert, W_ANY) + def extend(w_self, w_seq): return list_extend(w_self.space, w_self, w_seq) + extend = implmethod().register(extend, W_ANY) + def pop(w_self, w_idx=-1): return list_pop(w_self.space, w_self, w_idx) + pop = implmethod().register(pop, W_IntObject) + def remove(w_self, w_any): return list_remove(w_self.space, w_self, w_any) + remove = implmethod().register(remove, W_ANY) + def index(w_self, w_any): return list_index(w_self.space, w_self, w_any) + index = implmethod().register(index, W_ANY) + def count(w_self, w_any): return list_count(w_self.space, w_self, w_any) + count = implmethod().register(count, W_ANY) + def reverse(w_self): return list_reverse(w_self.space, w_self) + reverse = implmethod().register(reverse) + def list_unwrap(space, w_list): items = [space.unwrap(w_item) for w_item in w_list.ob_item[:w_list.ob_size]] return list(items) @@ -157,6 +175,27 @@ StdObjSpace.eq.register(list_eq, W_ListObject, W_ListObject) +def _min(a, b): + if a < b: + return a + return b + +def list_lt(space, w_list1, w_list2): + items1 = w_list1.ob_item + items2 = w_list2.ob_item + ncmp = _min(w_list1.ob_size, w_list2.ob_size) + # Search for the first index where items are different + p = 0 + while p < ncmp: + if not space.is_true(space.eq(items1[p], items2[p])): + break + if p >= ncmp: + # No more items to compare -- compare sizes + return space.newbool(vs < ws) + return space.lt(items1[p], items2[p]) + +StdObjSpace.lt.register(list_lt, W_ListObject, W_ListObject) + # upto here, lists are nearly identical to tuples, despite the # fact that we now support over-allocation! @@ -192,35 +231,6 @@ StdObjSpace.setitem.register(setitem_list_slice, W_ListObject, W_SliceObject, W_ListObject) -def getattr_list(space, w_list, w_attr): - if space.is_true(space.eq(w_attr, space.wrap('append'))): - w_builtinfn = make_builtin_func(space, W_ListObject.append) - return W_InstMethObject(space, w_list, w_builtinfn) - if space.is_true(space.eq(w_attr, space.wrap('insert'))): - w_builtinfn = make_builtin_func(space, W_ListObject.insert) - return W_InstMethObject(space, w_list, w_builtinfn) - if space.is_true(space.eq(w_attr, space.wrap('extend'))): - w_builtinfn = make_builtin_func(space, W_ListObject.extend) - return W_InstMethObject(space, w_list, w_builtinfn) - if space.is_true(space.eq(w_attr, space.wrap('pop'))): - w_builtinfn = make_builtin_func(space, W_ListObject.pop) - return W_InstMethObject(space, w_list, w_builtinfn) - if space.is_true(space.eq(w_attr, space.wrap('remove'))): - w_builtinfn = make_builtin_func(space, W_ListObject.remove) - return W_InstMethObject(space, w_list, w_builtinfn) - if space.is_true(space.eq(w_attr, space.wrap('index'))): - w_builtinfn = make_builtin_func(space, W_ListObject.index) - return W_InstMethObject(space, w_list, w_builtinfn) - if space.is_true(space.eq(w_attr, space.wrap('count'))): - w_builtinfn = make_builtin_func(space, W_ListObject.count) - return W_InstMethObject(space, w_list, w_builtinfn) - if space.is_true(space.eq(w_attr, space.wrap('reverse'))): - w_builtinfn = make_builtin_func(space, W_ListObject.reverse) - return W_InstMethObject(space, w_list, w_builtinfn) - raise FailedToImplement(space.w_AttributeError) - -StdObjSpace.getattr.register(getattr_list, W_ListObject, W_ANY) - # adapted C code def _roundupsize(n): nbits = r_uint(0) @@ -326,7 +336,7 @@ items = w_list.ob_item d = ihigh-ilow recycle = [items[i] for i in range(ilow, ihigh)] - for i in range(ilow, ihigh): + for i in range(ilow, w_list.ob_size - d): items[i] = items[i+d] w_list.ob_size -= d 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 Thu May 29 18:20:55 2003 @@ -48,7 +48,7 @@ 'W_BoolObject': 'boolobject', 'W_IntObject': 'intobject', 'W_FloatObject': 'floatobject', - #'W_ListObject': 'listobject', + 'W_ListObject': 'listobject', 'W_DictObject': 'dictobject', } From arigo at codespeak.net Thu May 29 18:43:27 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 29 May 2003 18:43:27 +0200 (MEST) Subject: [pypy-svn] rev 710 - pypy/trunk/src/pypy/interpreter Message-ID: <20030529164327.4D7685AC8A@thoth.codespeak.net> Author: arigo Date: Thu May 29 18:43:26 2003 New Revision: 710 Modified: pypy/trunk/src/pypy/interpreter/pycode_app.py Log: fix for some bug (how could it have been unnoticed for so long?) 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 Thu May 29 18:43:26 2003 @@ -1,5 +1,5 @@ # replacement for decode_frame_arguments -# Attention ! All calls here must be "easy", i.e. not involve +# ===== ATTENTION ===== ! All calls here must be "easy", i.e. not involve # default or keyword arguments !! For example, all range() calls # need three arguments. @@ -20,7 +20,7 @@ parameter_names = codeobject.co_varnames[:codeobject.co_argcount] # Normal arguments - for i in range(0, len(args), 1): + for i in range(0, len(args), 1): # see comment above for ", 1" try: argdict[parameter_names[i]] = args[i] except IndexError: @@ -29,6 +29,7 @@ varargs_tuple = args[i:] else: raise TypeError, 'Too many parameters to callable object' + break # Put all suitable keywords into arglist if kws: @@ -65,7 +66,7 @@ if defs: argcount = codeobject.co_argcount defcount = len(defs) - for i in range(argcount - defcount, argcount, 1): + for i in range(argcount - defcount, argcount, 1): # ", 1" comment above if parameter_names[i] in argdict: continue argdict[parameter_names[i]] = defs[i - (argcount - defcount)] From arigo at codespeak.net Thu May 29 18:48:17 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 29 May 2003 18:48:17 +0200 (MEST) Subject: [pypy-svn] rev 711 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529164817.7106B5AC8A@thoth.codespeak.net> Author: arigo Date: Thu May 29 18:48:17 2003 New Revision: 711 Modified: pypy/trunk/src/pypy/objspace/std/moduleobject.py pypy/trunk/src/pypy/objspace/std/objspace.py Log: added the module type 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 Thu May 29 18:48:17 2003 @@ -4,6 +4,7 @@ class W_ModuleObject(W_Object): delegate_once = {} + statictypename = 'module' def __init__(w_self, space, w_name): W_Object.__init__(w_self, space) 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 Thu May 29 18:48:17 2003 @@ -50,6 +50,7 @@ 'W_FloatObject': 'floatobject', 'W_ListObject': 'listobject', 'W_DictObject': 'dictobject', + 'W_ModuleObject':'moduleobject', } def initialize(self): From tomek at codespeak.net Thu May 29 19:02:07 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Thu, 29 May 2003 19:02:07 +0200 (MEST) Subject: [pypy-svn] rev 712 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529170207.4D7A15AC8A@thoth.codespeak.net> Author: tomek Date: Thu May 29 19:02:05 2003 New Revision: 712 Modified: pypy/trunk/src/pypy/objspace/std/objspace.py Log: ok 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 Thu May 29 19:02:05 2003 @@ -50,6 +50,7 @@ 'W_FloatObject': 'floatobject', 'W_ListObject': 'listobject', 'W_DictObject': 'dictobject', + #'W_StringObject': 'stringobject', 'W_ModuleObject':'moduleobject', } From mwh at codespeak.net Thu May 29 19:09:58 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Thu, 29 May 2003 19:09:58 +0200 (MEST) Subject: [pypy-svn] rev 713 - pypy/trunk/src/pypy Message-ID: <20030529170958.180D05AC93@thoth.codespeak.net> Author: mwh Date: Thu May 29 19:09:55 2003 New Revision: 713 Modified: pypy/trunk/src/pypy/testwice.py Log: line endings Modified: pypy/trunk/src/pypy/testwice.py ============================================================================== --- pypy/trunk/src/pypy/testwice.py (original) +++ pypy/trunk/src/pypy/testwice.py Thu May 29 19:09:55 2003 @@ -1,67 +1,67 @@ -import os -import unittest -import sys - -try: - head = this_path = os.path.abspath(__file__) -except NameError: - head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) -while 1: - head, tail = os.path.split(head) - if not tail: - raise EnvironmentError, "pypy not among parents of %r!" % this_path - elif tail.lower()=='pypy': - PYPYDIR = head - if PYPYDIR not in sys.path: - sys.path.insert(0, PYPYDIR) - break - -def is_flexible(dirname, modname): - filecont = open('%s/%s.py'%(dirname,modname)).read() - return filecont.find('testsupport.objspace') >= 0 - -def find_tests(root, inc_names=[], exc_names=[]): - testmods = [] - testwice = [] - def callback(arg, dirname, names): - if os.path.basename(dirname) == 'test': - parname = os.path.basename(os.path.dirname(dirname)) - if ((not inc_names) or parname in inc_names) and parname not in exc_names: - package = dirname[len(PYPYDIR)+1:].replace(os.sep, '.') - testfiles = [f[:-3] for f in names - if f.startswith('test_') and f.endswith('.py')] - for file in testfiles: - testmods.append(package + '.' + file) - if is_flexible(dirname, file): - testwice.append(package + '.' + file) - - os.path.walk(root, callback, None) - - tl = unittest.TestLoader() - - return tl.loadTestsFromNames(testmods), tl.loadTestsFromNames(testwice) - -def main(argv=None): - if argv is None: - argv = sys.argv - - inc_names = [] - exc_names = [] - - for arg in argv[1:]: - if arg.startswith('--include='): - inc_names = arg[len('--include='):].split(',') - elif arg.startswith('--exclude='): - exc_names = arg[len('--exclude='):].split(',') - else: - raise Exception, "don't know arg " + arg - - runner = unittest.TextTestRunner() - alltests, flexible = find_tests(PYPYDIR, inc_names, exc_names) - os.environ['OBJSPACE'] = '' - runner.run(alltests) - os.environ['OBJSPACE'] = 'pypy.objspace.std.objspace.StdObjSpace' - runner.run(flexible) - -if __name__ == '__main__': - main() +import os +import unittest +import sys + +try: + head = this_path = os.path.abspath(__file__) +except NameError: + head = this_path = os.path.abspath(os.path.dirname(sys.argv[0])) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + PYPYDIR = head + if PYPYDIR not in sys.path: + sys.path.insert(0, PYPYDIR) + break + +def is_flexible(dirname, modname): + filecont = open('%s/%s.py'%(dirname,modname)).read() + return filecont.find('testsupport.objspace') >= 0 + +def find_tests(root, inc_names=[], exc_names=[]): + testmods = [] + testwice = [] + def callback(arg, dirname, names): + if os.path.basename(dirname) == 'test': + parname = os.path.basename(os.path.dirname(dirname)) + if ((not inc_names) or parname in inc_names) and parname not in exc_names: + package = dirname[len(PYPYDIR)+1:].replace(os.sep, '.') + testfiles = [f[:-3] for f in names + if f.startswith('test_') and f.endswith('.py')] + for file in testfiles: + testmods.append(package + '.' + file) + if is_flexible(dirname, file): + testwice.append(package + '.' + file) + + os.path.walk(root, callback, None) + + tl = unittest.TestLoader() + + return tl.loadTestsFromNames(testmods), tl.loadTestsFromNames(testwice) + +def main(argv=None): + if argv is None: + argv = sys.argv + + inc_names = [] + exc_names = [] + + for arg in argv[1:]: + if arg.startswith('--include='): + inc_names = arg[len('--include='):].split(',') + elif arg.startswith('--exclude='): + exc_names = arg[len('--exclude='):].split(',') + else: + raise Exception, "don't know arg " + arg + + runner = unittest.TextTestRunner() + alltests, flexible = find_tests(PYPYDIR, inc_names, exc_names) + os.environ['OBJSPACE'] = '' + runner.run(alltests) + os.environ['OBJSPACE'] = 'pypy.objspace.std.objspace.StdObjSpace' + runner.run(flexible) + +if __name__ == '__main__': + main() From arigo at codespeak.net Thu May 29 19:23:15 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 29 May 2003 19:23:15 +0200 (MEST) Subject: [pypy-svn] rev 714 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529172315.8A2355AC8A@thoth.codespeak.net> Author: arigo Date: Thu May 29 19:23:15 2003 New Revision: 714 Modified: pypy/trunk/src/pypy/objspace/std/objspace.py Log: breaking things up purposefully, letting Christian fix them 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 Thu May 29 19:23:15 2003 @@ -23,6 +23,8 @@ def __init__(self): self.dispatch_table = {} def register(self, function, *types): + assert len(types) == function.func_code.co_argcount - 1, \ + "wrong number of W_Xxx arguments to .register()" if types in self.dispatch_table: raise error, "we already got an implementation for %r" % types self.dispatch_table[types] = function From tismer at codespeak.net Thu May 29 19:25:27 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 19:25:27 +0200 (MEST) Subject: [pypy-svn] rev 715 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529172527.C4FA05AC8A@thoth.codespeak.net> Author: tismer Date: Thu May 29 19:25:27 2003 New Revision: 715 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: small corrections to list object Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 19:25:27 2003 @@ -35,7 +35,7 @@ def insert(w_self, w_idx, w_obj): return list_insert(w_self.space, w_self, w_idx, w_obj) - insert = implmethod().register(insert, W_ANY) + insert = implmethod().register(insert, W_IntObject, W_ANY) def extend(w_self, w_seq): return list_extend(w_self.space, w_self, w_seq) From tismer at codespeak.net Thu May 29 19:45:24 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 19:45:24 +0200 (MEST) Subject: [pypy-svn] rev 716 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529174524.69C3B5AC8A@thoth.codespeak.net> Author: tismer Date: Thu May 29 19:45:23 2003 New Revision: 716 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: list object deletion refined to clean the upper end of the array Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 19:45:23 2003 @@ -335,9 +335,14 @@ ihigh = w_list.ob_size items = w_list.ob_item d = ihigh-ilow - recycle = [items[i] for i in range(ilow, ihigh)] + # XXX this is done by CPython to hold the elements + # to be deleted. I have no idea how to express + # this here, but we need to be aware when we write + # a compiler. + # recycle = [items[i] for i in range(ilow, ihigh)] for i in range(ilow, w_list.ob_size - d): items[i] = items[i+d] + items[i+d] = None w_list.ob_size -= d # note that the default value will come back wrapped!!! From tismer at codespeak.net Thu May 29 19:55:03 2003 From: tismer at codespeak.net (tismer at codespeak.net) Date: Thu, 29 May 2003 19:55:03 +0200 (MEST) Subject: [pypy-svn] rev 717 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529175503.5D3115AC8A@thoth.codespeak.net> Author: tismer Date: Thu May 29 19:55:02 2003 New Revision: 717 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: list object small cleanups Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu May 29 19:55:02 2003 @@ -45,7 +45,7 @@ def pop(w_self, w_idx=-1): return list_pop(w_self.space, w_self, w_idx) - pop = implmethod().register(pop, W_IntObject) + pop = implmethod().register(pop, W_IntObject) def remove(w_self, w_any): return list_remove(w_self.space, w_self, w_any) @@ -87,7 +87,8 @@ def getitem_list_int(space, w_list, w_index): items = w_list.ob_item idx = w_index.intval - if idx < 0: idx += w_list.ob_size + if idx < 0: + idx += w_list.ob_size if idx < 0 or idx >= w_list.ob_size: raise OperationError(space.w_IndexError, space.wrap("list index out of range")) @@ -202,7 +203,8 @@ def setitem_list_int(space, w_list, w_index, w_any): items = w_list.ob_item idx = w_index.intval - if idx < 0: idx += w_list.ob_size + if idx < 0: + idx += w_list.ob_size if idx < 0 or idx >= w_list.ob_size: raise OperationError(space.w_IndexError, space.wrap("list index out of range")) From arigo at codespeak.net Thu May 29 20:06:38 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 29 May 2003 20:06:38 +0200 (MEST) Subject: [pypy-svn] rev 718 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529180638.760955AC8A@thoth.codespeak.net> Author: arigo Date: Thu May 29 20:06:37 2003 New Revision: 718 Modified: pypy/trunk/src/pypy/objspace/std/objspace.py pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/typeobject.py Log: types callable but DON'T LOOK it's a hack 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 Thu May 29 20:06:37 2003 @@ -52,8 +52,9 @@ 'W_FloatObject': 'floatobject', 'W_ListObject': 'listobject', 'W_DictObject': 'dictobject', - #'W_StringObject': 'stringobject', + 'W_StringObject':'stringobject', 'W_ModuleObject':'moduleobject', + 'W_TupleObject': 'tupleobject', } def initialize(self): Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 20:06:37 2003 @@ -11,6 +11,10 @@ applicationfile = StdObjSpace.AppFile(__name__) class W_StringObject(W_Object): + + delegate_once = {} + statictypename = 'str' + def __init__(w_self, space, str): W_Object.__init__(w_self, space) w_self._value = CharArrayFromStr(str) Modified: pypy/trunk/src/pypy/objspace/std/typeobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/typeobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/typeobject.py Thu May 29 20:06:37 2003 @@ -97,3 +97,34 @@ raise OperationError(*e.args) else: return space.w_NotImplemented + + +def type_call(space, w_type, w_args, w_kwds): + + # H H AA CCC K K + # H H A A C K K + # HHHH A A C KK + # H H AAAA C K K + # H H A A CCC K K + + tpname = space.unwrap(w_type.w_tpname) + args = space.unpackiterable(w_args) + if tpname == 'type': + assert len(args) == 1 + return space.type(args[0]) + if tpname == 'list': + assert len(args) == 1 + return space.newlist(space.unpackiterable(args[0])) + if tpname == 'tuple': + assert len(args) == 1 + return space.newtuple(space.unpackiterable(args[0])) + if tpname == 'str': + assert len(args) == 1 + return space.str(args[0]) + + import __builtin__ + hacky = getattr(__builtin__, tpname)( + *space.unwrap(w_args), **space.unwrap(w_kwds)) + return space.wrap(hacky) + +StdObjSpace.call.register(type_call, W_TypeObject, W_ANY, W_ANY) From arigo at codespeak.net Thu May 29 20:11:31 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 29 May 2003 20:11:31 +0200 (MEST) Subject: [pypy-svn] rev 719 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030529181131.965B75AC8A@thoth.codespeak.net> Author: arigo Date: Thu May 29 20:11:31 2003 New Revision: 719 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: multimethod dispatch for str.join and str.split Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Thu May 29 20:11:31 2003 @@ -3,6 +3,7 @@ from sliceobject import W_SliceObject from listobject import W_ListObject from instmethobject import W_InstMethObject +from noneobject import W_NoneObject from pypy.interpreter.extmodule import make_builtin_func from rarray import CharArrayFromStr, CharArraySize @@ -57,51 +58,47 @@ else: return W_StringObject(w_self.space, "") - def splitByWhitespace(w_self): - res = [] - inword = 0 - value = w_self._value.value() - for ch in value: - if ch.isspace(): - if inword: - inword = 0 - else: - if inword: - res[-1] += ch - else: - res.append(ch) - inword = 1 - for i in range(len(res)): - res[i] = W_StringObject(w_self.space, res[i]) - return W_ListObject(w_self.space, res) - - def split(w_self, w_by=None): - if w_by is w_self.space.w_None: return w_self.splitByWhitespace() - res = [] - start = 0 - value = w_self._value.value() - by = w_by._value.value() - while 1: - next = value.find(by, start) - if next < 0: - res.append(value[start:]) - break - res.append(value[start:next]) - start = next + len(by) - for i in range(len(res)): - res[i] = W_StringObject(w_self.space, res[i]) - return W_ListObject(w_self.space, res) - -def getattr_str(space, w_list, w_attr): - if space.is_true(space.eq(w_attr, space.wrap('join'))): - w_builtinfn = make_builtin_func(space, W_StringObject.join) - return W_InstMethObject(space, w_list, w_builtinfn) - elif space.is_true(space.eq(w_attr, space.wrap('split'))): - w_builtinfn = make_builtin_func(space, W_StringObject.split) - return W_InstMethObject(space, w_list, w_builtinfn) - raise FailedToImplement(space.w_AttributeError) + join = implmethod().register(join, W_ANY) + split = implmethod() + -StdObjSpace.getattr.register(getattr_str, W_StringObject, W_ANY) +def splitByWhitespace(w_self, w_none): + res = [] + inword = 0 + value = w_self._value.value() + for ch in value: + if ch.isspace(): + if inword: + inword = 0 + else: + if inword: + res[-1] += ch + else: + res.append(ch) + inword = 1 + for i in range(len(res)): + res[i] = W_StringObject(w_self.space, res[i]) + return W_ListObject(w_self.space, res) + +def split(w_self, w_by): + res = [] + start = 0 + value = w_self._value.value() + by = w_by._value.value() + while 1: + next = value.find(by, start) + if next < 0: + res.append(value[start:]) + break + res.append(value[start:next]) + start = next + len(by) + for i in range(len(res)): + res[i] = W_StringObject(w_self.space, res[i]) + return W_ListObject(w_self.space, res) + +# XXX temporary hack +W_StringObject.__dict__['split'].register(split, W_StringObject) +W_StringObject.__dict__['split'].register(splitByWhitespace, W_NoneObject) def str_unwrap(space, w_str): From lac at codespeak.net Fri May 30 11:08:49 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Fri, 30 May 2003 11:08:49 +0200 (MEST) Subject: [pypy-svn] rev 720 - in pypy/trunk/src/pypy/module: . test Message-ID: <20030530090849.EAEA35ACAB@thoth.codespeak.net> Author: lac Date: Fri May 30 11:08:48 2003 New Revision: 720 Added: pypy/trunk/src/pypy/module/test/test_vars.py Modified: pypy/trunk/src/pypy/module/builtin_app.py Log: Added unit tests for vars() 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 Fri May 30 11:08:48 2003 @@ -86,11 +86,10 @@ idx = idx + 1 return res - def reduce(function, l, *initialt): """ Apply function of two arguments cumulatively to the items of sequence, from left to right, so as to reduce the sequence to a - single value.""" + single value. Optionally begin with an initial value.""" if initialt: initial, = initialt @@ -123,9 +122,11 @@ raise TypeError, "isinstance() arg 2 must be a class or type" def range(x, y=None, step=1): - "docstring" + """ returns a list of integers in arithmetic position from start (defaults + to zero) to stop - 1 by step (defaults to 1). Use a negative step to + get a list in decending order.""" - if y is None: + if y is None: start = 0 stop = x else: @@ -135,16 +136,17 @@ if step == 0: raise ValueError, 'range() arg 3 must not be zero' - elif (stop <= start and step > 0) or (stop >= start and step < 0): - return [] # easy, no work for us. - elif step > 0: + if stop <= start: # no work for us + return [] howmany = (stop - start + step - 1)/step - else: # step must be < 0 + else: # step must be < 0, or we would have raised ValueError + if stop >= start: # no work for us + return [] howmany = (start - stop - step - 1)/-step - arr = [None] * howmany + arr = [None] * howmany # this is to avoid using append. i = start n = 0 @@ -155,16 +157,18 @@ return arr +# min and max could be one function if we had operator.__gt__ and +# operator.__lt__ Perhaps later when we have operator. + def min(*arr): - "docstring" + """return the smallest number in a list""" if not arr: raise TypeError, 'min() takes at least one argument' if len(arr) == 1: arr = arr[0] - - + min = arr[0] for i in arr: if min > i: @@ -172,7 +176,7 @@ return min def max(*arr): - "docstring" + """return the largest number in a list""" if not arr: raise TypeError, 'max() takes at least one argument' @@ -188,20 +192,24 @@ def cmp(x, y): - if x < y: - return -1 - elif x == y: - return 0 - else: - return 1 + """return 0 when x == y, -1 when x < y and 1 when x > y """ + if x < y: + return -1 + elif x == y: + return 0 + else: + return 1 + +def vars(*obj): + """return a dictionary of all the attributes currently bound in obj. If + called with no argument, return the variables bound in local scope.""" -def vars(*objectt): - if len(objectt) == 0: + if len(obj) == 0: return locals() - elif len(objectt) != 1: + elif len(obj) != 1: raise TypeError, "vars() takes at most 1 argument." else: try: - return object.__dict__ + return obj.__dict__ except AttributeError: raise TypeError, "vars() argument must have __dict__ attribute" Added: pypy/trunk/src/pypy/module/test/test_vars.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/module/test/test_vars.py Fri May 30 11:08:48 2003 @@ -0,0 +1,34 @@ +import testsupport +from pypy.module.builtin_app import map + +# trivial objects for testing + +class TrivialObject: + + def __init__(self): + self.s1 = 'I am a string' + + def do_something(self): + self.s1 = "Now I am another string" + +t = TrivialObject() +t1 = TrivialObject() +t1.do_something() + +class TestVars(testsupport.TestCase): + + def test_vars_no_arguments(self): + self.assertEqual(vars(), locals()) + + def test_vars_too_many_arguments(self): + self.assertRaises(TypeError, vars, t, t1) + + def test_vars_correct_arguments(self): + self.assertEqual(vars(t), t.__dict__) + self.assertEqual(vars(t1), t1.__dict__) + self.assertNotEqual(vars(t1), t.__dict__) + +if __name__ == '__main__': + testsupport.main() + + From tomek at codespeak.net Fri May 30 12:51:00 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Fri, 30 May 2003 12:51:00 +0200 (MEST) Subject: [pypy-svn] rev 721 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030530105100.BE2F95ACAB@thoth.codespeak.net> Author: tomek Date: Fri May 30 12:51:00 2003 New Revision: 721 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: isspace added Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Fri May 30 12:51:00 2003 @@ -57,6 +57,23 @@ return W_StringObject(w_self.space, res.value()) else: return W_StringObject(w_self.space, "") + + def isspace(self): + space = self.space + v = self._value + if v.len == 0: + return space.w_False + if v.len == 1: + c = v.charat(0) + return space.newbool(ord(c) in (9, 10, 11, 12, 13, 32)) + else: + res = 1 + for idx in range(v.len): + if not (ord(v.charat(idx)) in (9, 10, 11, 12, 13, 32)): + return space.w_False + return space.w_True + + isspace = implmethod().register(isspace) join = implmethod().register(join, W_ANY) split = implmethod() From mwh at codespeak.net Fri May 30 12:52:51 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 30 May 2003 12:52:51 +0200 (MEST) Subject: [pypy-svn] rev 722 - pypy/trunk/src/pypy/interpreter Message-ID: <20030530105251.5238F5ACAB@thoth.codespeak.net> Author: mwh Date: Fri May 30 12:52:50 2003 New Revision: 722 Modified: pypy/trunk/src/pypy/interpreter/opcode.py Log: implement LOAD_NAME in interpreter space as app-space exceptions are STILL annoying... Modified: pypy/trunk/src/pypy/interpreter/opcode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/opcode.py (original) +++ pypy/trunk/src/pypy/interpreter/opcode.py Fri May 30 12:52:50 2003 @@ -375,9 +375,32 @@ def LOAD_NAME(f, nameindex): varname = f.getname(nameindex) w_varname = f.space.wrap(varname) - w_value = f.space.gethelper(appfile).call( - "load_name", [w_varname, f.w_locals, f.w_globals, f.w_builtins]) + try: + w_value = f.space.getitem(f.w_locals, w_varname) + except OperationError, e: + if not e.match(f.space, f.space.w_KeyError): + raise + try: + w_value = f.space.getitem(f.w_globals, w_varname) + except OperationError, e: + if not e.match(f.space, f.space.w_KeyError): + raise + try: + w_value = f.space.getitem(f.w_builtins, w_varname) + except OperationError, e: + if not e.match(f.space, f.space.w_KeyError): + raise + message = "global name '%s' is not defined" % varname + w_exc_type = f.space.w_NameError + w_exc_value = f.space.wrap(message) + raise OperationError(w_exc_type, w_exc_value) f.valuestack.push(w_value) + # XXX the implementation can be pushed back into app-space as an + # when exception handling begins to behave itself. For now, it + # was getting on my nerves -- mwh +# w_value = f.space.gethelper(appfile).call( +# "load_name", [w_varname, f.w_locals, f.w_globals, f.w_builtins]) +# f.valuestack.push(w_value) def LOAD_GLOBAL(f, nameindex): varname = f.getname(nameindex) From tomek at codespeak.net Fri May 30 12:54:43 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Fri, 30 May 2003 12:54:43 +0200 (MEST) Subject: [pypy-svn] rev 723 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030530105443.646DD5ACAB@thoth.codespeak.net> Author: tomek Date: Fri May 30 12:54:43 2003 New Revision: 723 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: a small comment added Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Fri May 30 12:54:43 2003 @@ -115,6 +115,10 @@ # XXX temporary hack W_StringObject.__dict__['split'].register(split, W_StringObject) + +#We should erase the W_NoneObject, but register takes always +#the same number of parameters. So you have to call split with +#None as parameter instead of calling it without any parameter W_StringObject.__dict__['split'].register(splitByWhitespace, W_NoneObject) From mwh at codespeak.net Fri May 30 12:54:57 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 30 May 2003 12:54:57 +0200 (MEST) Subject: [pypy-svn] rev 724 - pypy/trunk/src/pypy Message-ID: <20030530105457.37BED5ACAB@thoth.codespeak.net> Author: mwh Date: Fri May 30 12:54:56 2003 New Revision: 724 Added: pypy/trunk/src/pypy/testcts.py - copied, changed from rev 700, pypy/trunk/src/pypy/testall.py Log: testcts.py is designed to be run over and over and will report changes in test results to stdout currently a bit hackish and unix only (for no good reason, tbh). Copied: pypy/trunk/src/pypy/testcts.py (from rev 700, pypy/trunk/src/pypy/testall.py) ============================================================================== --- pypy/trunk/src/pypy/testall.py (original) +++ pypy/trunk/src/pypy/testcts.py Fri May 30 12:54:56 2003 @@ -34,6 +34,62 @@ return tl.loadTestsFromNames(testmods) +class MyTestResult(unittest.TestResult): + def __init__(self): + unittest.TestResult.__init__(self) + self.successes = [] + def addSuccess(self, test): + self.successes.append(test) + + +class CtsTestRunner: + def run(self, test): + import pickle + + result = MyTestResult() + sys.stdout = open('/dev/null', 'w') + sys.stderr = open('/dev/null', 'w') + test(result) + sys.stdout = sys.__stdout__ + sys.stderr = sys.__stderr__ + + ostatus = {} + if os.path.exists('testcts.pickle'): + ostatus = pickle.load(open('testcts.pickle','r')) + + status = {} + + for e in result.errors: + name = e[0].__class__.__name__ + '.' + e[0]._TestCase__testMethodName + status[name] = 'ERROR' + for f in result.failures: + name = f[0].__class__.__name__ + '.' + f[0]._TestCase__testMethodName + status[name] = 'FAILURE' + for s in result.successes: + name = s.__class__.__name__ + '.' + s._TestCase__testMethodName + status[name] = 'success' + + keys = status.keys() + keys.sort() + + for k in keys: + old = ostatus.get(k, 'success') + if k in ostatus: + del ostatus[k] + new = status[k] + if old != new: + print k, 'has transitioned from', old, 'to', new + elif new != 'success': + print k, "is still a", new + + for k in ostatus: + print k, 'was a', ostatus[k], 'was not run this time' + status[k] = ostatus[k] + + pickle.dump(status, open('testcts.pickle','w')) + + return result + def main(argv=None): if argv is None: argv = sys.argv @@ -41,6 +97,8 @@ inc_names = [] exc_names = [] + os.environ['OBJSPACE'] = 'pypy.objspace.std.objspace.StdObjSpace' + for arg in argv[1:]: if arg.startswith('--include='): inc_names = arg[len('--include='):].split(',') @@ -48,9 +106,10 @@ exc_names = arg[len('--exclude='):].split(',') else: raise Exception, "don't know arg " + arg - - runner = unittest.TextTestRunner() + + runner = CtsTestRunner() runner.run(find_tests(PYPYDIR, inc_names, exc_names)) + if __name__ == '__main__': main() From mwh at codespeak.net Fri May 30 13:15:22 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 30 May 2003 13:15:22 +0200 (MEST) Subject: [pypy-svn] rev 725 - pypy/trunk/src/pypy/interpreter Message-ID: <20030530111522.AD6705ACAB@thoth.codespeak.net> Author: mwh Date: Fri May 30 13:15:22 2003 New Revision: 725 Modified: pypy/trunk/src/pypy/interpreter/extmodule.py Log: scan for appdata and appmethods in instance's dict as well as class' Modified: pypy/trunk/src/pypy/interpreter/extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/extmodule.py Fri May 30 13:15:22 2003 @@ -70,7 +70,7 @@ space = self.space modulename = self.__pythonname__ w_module = space.newmodule(space.wrap(modulename)) - for key, value in self.__class__.__dict__.items(): + for key, value in self.__class__.__dict__.items() + self.__dict__.items(): if isinstance(value, appmethod): w_function = make_builtin_func(space,value.func.__get__(self),boundmethod=True) space.setattr(w_module, space.wrap(key), w_function) From mwh at codespeak.net Fri May 30 13:16:30 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 30 May 2003 13:16:30 +0200 (MEST) Subject: [pypy-svn] rev 726 - pypy/trunk/src/pypy/module Message-ID: <20030530111630.F005C5ACAB@thoth.codespeak.net> Author: mwh Date: Fri May 30 13:16:30 2003 New Revision: 726 Modified: pypy/trunk/src/pypy/module/sysmodule.py Log: make a stab at a better sys.path add less irritating sys.displayhook Modified: pypy/trunk/src/pypy/module/sysmodule.py ============================================================================== --- pypy/trunk/src/pypy/module/sysmodule.py (original) +++ pypy/trunk/src/pypy/module/sysmodule.py Fri May 30 13:16:30 2003 @@ -1,7 +1,32 @@ +from pypy.interpreter.baseobjspace import OperationError from pypy.interpreter.extmodule import * import sys class Sys(BuiltinModule): __pythonname__ = 'sys' + + def __init__(self, space): + BuiltinModule.__init__(self, space) + + import sys, os + import pypy + + opd = os.path.dirname + + pypydir = opd(opd(os.path.abspath(pypy.__file__))) + + self.path = appdata([p for p in sys.path if p != pypydir]) + stdout = appdata(sys.stdout) - displayhook = appdata(sys.displayhook) + + def displayhook(self, w_x): + space = self.space + w = space.wrap + if w_x != space.w_None: + try: + print space.unwrap(self.space.str(w_x)) + except OperationError: + print "! could not print", w_x + space.setitem(space.w_builtins, w('_'), w_x) + displayhook = appmethod(displayhook) + From mwh at codespeak.net Fri May 30 13:20:50 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 30 May 2003 13:20:50 +0200 (MEST) Subject: [pypy-svn] rev 727 - in pypy/trunk/src/pypy/module: . test Message-ID: <20030530112050.E537E5ACAB@thoth.codespeak.net> Author: mwh Date: Fri May 30 13:20:50 2003 New Revision: 727 Modified: pypy/trunk/src/pypy/module/builtin.py pypy/trunk/src/pypy/module/test/test_builtin.py Log: first cut at importing from the file system! there aren't many modules out there that we can actually import successfully, but that's another story... Modified: pypy/trunk/src/pypy/module/builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/builtin.py (original) +++ pypy/trunk/src/pypy/module/builtin.py Fri May 30 13:20:50 2003 @@ -35,6 +35,7 @@ def __import__(self, w_modulename, w_locals, w_globals, w_fromlist): space = self.space + w = space.wrap try: w_mod = space.getitem(space.w_modules, w_modulename) return w_mod @@ -45,6 +46,23 @@ if w_mod is not None: space.setitem(space.w_modules,w_modulename,w_mod) return w_mod + + import os, __future__ + for path in space.unwrap(space.getattr(space.w_sys, w('path'))): + f = os.path.join(path, space.unwrap(w_modulename) + '.py') + if os.path.exists(f): + w_mod = space.newmodule(w_modulename) + space.setitem(space.w_modules, w_modulename, w_mod) + space.setattr(w_mod, w('__file__'), w(f)) + w_source = w(open(f, 'r').read()) + # wrt the __future__.generators.compiler_flag, "um" -- mwh + w_code = self.compile(w_source, w(f), w('exec'), + w(__future__.generators.compiler_flag)) + w_dict = space.getattr(w_mod, w('__dict__')) + space.unwrap(w_code).eval_code(space, w_dict, w_dict) + + return w_mod + w_exc = space.call_function(space.w_ImportError, w_modulename) raise executioncontext.OperationError( space.w_ImportError, w_exc) Modified: pypy/trunk/src/pypy/module/test/test_builtin.py ============================================================================== --- pypy/trunk/src/pypy/module/test/test_builtin.py (original) +++ pypy/trunk/src/pypy/module/test/test_builtin.py Fri May 30 13:20:50 2003 @@ -28,6 +28,16 @@ self.assertWRaises_w(s.w_TypeError, w_chr, w('a')) + + def test_import(self): + s = self.space + w = s.wrap + w_import = self.get_builtin('__import__') + w_dict = s.newdict([]) + w_fromlist = s.newlist([]) + # finding a module to import is an odd game; quopri is + # sufficiently simple + s.call_function(w_import, w('quopri'), w_dict, w_dict, w_fromlist) class TestCmp(testsupport.TestCase): From tomek at codespeak.net Fri May 30 13:48:02 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Fri, 30 May 2003 13:48:02 +0200 (MEST) Subject: [pypy-svn] rev 728 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030530114802.0B7635ACAB@thoth.codespeak.net> Author: tomek Date: Fri May 30 13:48:01 2003 New Revision: 728 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: ok Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Fri May 30 13:48:01 2003 @@ -57,10 +57,13 @@ return W_StringObject(w_self.space, res.value()) else: return W_StringObject(w_self.space, "") - - def isspace(self): - space = self.space - v = self._value + + def char_isspace(ch): + return ord(ch) in (9, 10, 11, 12, 13, 32) + + def isspace(w_self): + space = w_self.space + v = w_self._value if v.len == 0: return space.w_False if v.len == 1: @@ -73,7 +76,34 @@ return space.w_False return space.w_True + def isdigit(w_self): + pass + + def isupper(w_self): + pass + + def isupper(w_self): + pass + + def islower(w_self): + pass + + def istitle(w_self): + pass + + def isalnum(w_self): + pass + + def isalpha(w_self): + pass + isspace = implmethod().register(isspace) + isdigit = implmethod().register(isdigit) + isupper = implmethod().register(isupper) + islower = implmethod().register(islower) + istitle = implmethod().register(istitle) + isalnum = implmethod().register(isalnum) + isalpha = implmethod().register(isalpha) join = implmethod().register(join, W_ANY) split = implmethod() From arigo at codespeak.net Fri May 30 13:52:17 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 30 May 2003 13:52:17 +0200 (MEST) Subject: [pypy-svn] rev 729 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030530115217.D36D75ACAB@thoth.codespeak.net> Author: arigo Date: Fri May 30 13:52:17 2003 New Revision: 729 Modified: pypy/trunk/src/pypy/objspace/std/cpythonobject.py Log: forgot the register() of is_true Modified: pypy/trunk/src/pypy/objspace/std/cpythonobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/cpythonobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/cpythonobject.py Fri May 30 13:52:17 2003 @@ -168,6 +168,8 @@ except: wrap_exception(space) +StdObjSpace.is_true.register(cpython_is_true, W_CPythonObject) + # slicing def old_slice(index): From tomek at codespeak.net Fri May 30 13:55:02 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Fri, 30 May 2003 13:55:02 +0200 (MEST) Subject: [pypy-svn] rev 730 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030530115502.0984F5ACAB@thoth.codespeak.net> Author: tomek Date: Fri May 30 13:55:01 2003 New Revision: 730 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py Log: ok Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Fri May 30 13:55:01 2003 @@ -58,24 +58,27 @@ else: return W_StringObject(w_self.space, "") - def char_isspace(ch): + def _char_isspace(ch): return ord(ch) in (9, 10, 11, 12, 13, 32) - - def isspace(w_self): + + def is_generic(w_self, fun): space = w_self.space v = w_self._value if v.len == 0: return space.w_False if v.len == 1: c = v.charat(0) - return space.newbool(ord(c) in (9, 10, 11, 12, 13, 32)) + return space.newbool(fun(c)) else: res = 1 for idx in range(v.len): - if not (ord(v.charat(idx)) in (9, 10, 11, 12, 13, 32)): + if not fun(v.charat(idx)): return space.w_False return space.w_True + def isspace(w_self): + return is_generic(w_self, _char_isspace) + def isdigit(w_self): pass From arigo at codespeak.net Fri May 30 17:16:11 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 30 May 2003 17:16:11 +0200 (MEST) Subject: [pypy-svn] rev 731 - in pypy/trunk/src/pypy: interpreter objspace/std objspace/std/test Message-ID: <20030530151611.6AB375ACAB@thoth.codespeak.net> Author: arigo Date: Fri May 30 17:16:10 2003 New Revision: 731 Added: pypy/trunk/src/pypy/objspace/std/booltype.py pypy/trunk/src/pypy/objspace/std/dicttype.py pypy/trunk/src/pypy/objspace/std/floattype.py pypy/trunk/src/pypy/objspace/std/inttype.py pypy/trunk/src/pypy/objspace/std/listtype.py pypy/trunk/src/pypy/objspace/std/moduletype.py pypy/trunk/src/pypy/objspace/std/nonetype.py pypy/trunk/src/pypy/objspace/std/stringtype.py pypy/trunk/src/pypy/objspace/std/tupletype.py Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py pypy/trunk/src/pypy/objspace/std/boolobject.py pypy/trunk/src/pypy/objspace/std/default.py pypy/trunk/src/pypy/objspace/std/dictobject.py pypy/trunk/src/pypy/objspace/std/floatobject.py pypy/trunk/src/pypy/objspace/std/intobject.py pypy/trunk/src/pypy/objspace/std/listobject.py pypy/trunk/src/pypy/objspace/std/moduleobject.py pypy/trunk/src/pypy/objspace/std/multimethod.py pypy/trunk/src/pypy/objspace/std/noneobject.py pypy/trunk/src/pypy/objspace/std/objspace.py pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py pypy/trunk/src/pypy/objspace/std/tupleobject.py pypy/trunk/src/pypy/objspace/std/typeobject.py Log: that's it, type methods are now real multimethods just like the space's Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/baseobjspace.py (original) +++ pypy/trunk/src/pypy/interpreter/baseobjspace.py Fri May 30 17:16:10 2003 @@ -223,6 +223,8 @@ ('next', 'next', 1, ['next']), # iterator interface ('call', 'call', 3, ['__call__']), ('get', 'get', 3, ['__get__']), + ('new', 'new', 3, ['__new__']), + ('init', 'init', 3, ['__init__']), ] ObjSpace.BuiltinModuleTable = [ Modified: pypy/trunk/src/pypy/objspace/std/boolobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/boolobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/boolobject.py Fri May 30 17:16:10 2003 @@ -1,9 +1,10 @@ from pypy.objspace.std.objspace import * +from booltype import W_BoolType class W_BoolObject(W_Object): delegate_once = {} - statictypename = 'bool' + statictype = W_BoolType def __init__(w_self, space, boolval):# please pass in a real bool, not an int W_Object.__init__(w_self, space) Added: pypy/trunk/src/pypy/objspace/std/booltype.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/booltype.py Fri May 30 17:16:10 2003 @@ -0,0 +1,7 @@ +from pypy.objspace.std.objspace import * +from typeobject import W_TypeObject + + +class W_BoolType(W_TypeObject): + + typename = 'bool' Modified: pypy/trunk/src/pypy/objspace/std/default.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/default.py (original) +++ pypy/trunk/src/pypy/objspace/std/default.py Fri May 30 17:16:10 2003 @@ -128,10 +128,11 @@ # static types def default_type(space, w_obj): - w_type = w_obj.statictype - if w_type is None: + if w_obj.statictype is None: # XXX remove me, temporary return space.wrap(space.unwrap(w_obj).__class__) - return w_type + else: + w_type = space.get_typeinstance(w_obj.statictype) + return w_type StdObjSpace.type.register(default_type, W_ANY) 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 Fri May 30 17:16:10 2003 @@ -1,4 +1,5 @@ -from objspace import * +from pypy.objspace.std.objspace import * +from dicttype import W_DictType from stringobject import W_StringObject from instmethobject import W_InstMethObject from pypy.interpreter.extmodule import make_builtin_func @@ -33,7 +34,7 @@ class W_DictObject(W_Object): delegate_once = {} - statictypename = 'dict' + statictype = W_DictType def __init__(w_self, space, list_pairs_w): W_Object.__init__(w_self, space) @@ -59,33 +60,6 @@ def cell(self,space,w_lookup): return space.wrap(self._cell(space,w_lookup)) - def copy(w_self): - return W_DictObject(w_self.space,[(w_key,cell.get()) - for w_key,cell in - w_self.non_empties()]) - def items(w_self): - space = w_self.space - return space.newlist([ space.newtuple([w_key,cell.get()]) - for w_key,cell in - w_self.non_empties()]) - - def keys(w_self): - space = w_self.space - return space.newlist([ w_key - for w_key,cell in - w_self.non_empties()]) - - def values(w_self): - space = w_self.space - return space.newlist([ cell.get() - for w_key,cell in - w_self.non_empties()]) - - copy = implmethod().register(copy) - items = implmethod().register(items) - keys = implmethod().register(keys) - values = implmethod().register(values) - def dict_is_true(space, w_dict): return not not w_dict.non_empties() @@ -169,5 +143,29 @@ return space.newbool(r) return space.newbool(1) - StdObjSpace.eq.register(eq_dict_dict, W_DictObject, W_DictObject) + + +def dict_copy(space, w_self): + return W_DictObject(space, [(w_key,cell.get()) + for w_key,cell in + w_self.non_empties()]) +def dict_items(space, w_self): + return space.newlist([ space.newtuple([w_key,cell.get()]) + for w_key,cell in + w_self.non_empties()]) + +def dict_keys(space, w_self): + return space.newlist([ w_key + for w_key,cell in + w_self.non_empties()]) + +def dict_values(space, w_self): + return space.newlist([ cell.get() + for w_key,cell in + w_self.non_empties()]) + +W_DictType.dict_copy .register(dict_copy, W_DictObject) +W_DictType.dict_items .register(dict_items, W_DictObject) +W_DictType.dict_keys .register(dict_keys, W_DictObject) +W_DictType.dict_values.register(dict_values, W_DictObject) Added: pypy/trunk/src/pypy/objspace/std/dicttype.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/dicttype.py Fri May 30 17:16:10 2003 @@ -0,0 +1,12 @@ +from pypy.objspace.std.objspace import * +from typeobject import W_TypeObject + + +class W_DictType(W_TypeObject): + + typename = 'dict' + + dict_copy = MultiMethod('copy', 1) + dict_items = MultiMethod('items', 1) + dict_keys = MultiMethod('keys', 1) + dict_values = MultiMethod('values', 1) Modified: pypy/trunk/src/pypy/objspace/std/floatobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/floatobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/floatobject.py Fri May 30 17:16:10 2003 @@ -1,4 +1,5 @@ -from objspace import * +from pypy.objspace.std.objspace import * +from floattype import W_FloatType ############################################################## # for the time being, all calls that are made to some external @@ -17,7 +18,7 @@ an argument""" delegate_once = {} - statictypename = 'float' + statictype = W_FloatType def __init__(w_self, space, floatval): W_Object.__init__(w_self, space) Added: pypy/trunk/src/pypy/objspace/std/floattype.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/floattype.py Fri May 30 17:16:10 2003 @@ -0,0 +1,7 @@ +from pypy.objspace.std.objspace import * +from typeobject import W_TypeObject + + +class W_FloatType(W_TypeObject): + + typename = 'float' Modified: pypy/trunk/src/pypy/objspace/std/intobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/intobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/intobject.py Fri May 30 17:16:10 2003 @@ -1,4 +1,5 @@ from pypy.objspace.std.objspace import * +from inttype import W_IntType from noneobject import W_NoneObject from boolobject import W_BoolObject from restricted_int import r_int, LONG_BIT @@ -23,7 +24,7 @@ class W_IntObject(W_Object): delegate_once = {} - statictypename = 'int' + statictype = W_IntType def __init__(w_self, space, intval): W_Object.__init__(w_self, space) Added: pypy/trunk/src/pypy/objspace/std/inttype.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/inttype.py Fri May 30 17:16:10 2003 @@ -0,0 +1,7 @@ +from pypy.objspace.std.objspace import * +from typeobject import W_TypeObject + + +class W_IntType(W_TypeObject): + + typename = 'int' Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Fri May 30 17:16:10 2003 @@ -1,13 +1,15 @@ from pypy.objspace.std.objspace import * +from listtype import W_ListType from intobject import W_IntObject from sliceobject import W_SliceObject from instmethobject import W_InstMethObject from pypy.interpreter.extmodule import make_builtin_func from restricted_int import r_int, r_uint + class W_ListObject(W_Object): delegate_once = {} - statictypename = 'list' + statictype = W_ListType def __init__(w_self, space, wrappeditems): W_Object.__init__(w_self, space) @@ -27,45 +29,6 @@ reprlist = [repr(w_item) for w_item in w_self.ob_item[:w_self.ob_size]] return "%s(%s)" % (w_self.__class__.__name__, ', '.join(reprlist)) - def append(w_self, w_obj): - return list_append(w_self.space, w_self, w_obj) - - append = implmethod().register(append, W_ANY) - - def insert(w_self, w_idx, w_obj): - return list_insert(w_self.space, w_self, w_idx, w_obj) - - insert = implmethod().register(insert, W_IntObject, W_ANY) - - def extend(w_self, w_seq): - return list_extend(w_self.space, w_self, w_seq) - - extend = implmethod().register(extend, W_ANY) - - def pop(w_self, w_idx=-1): - return list_pop(w_self.space, w_self, w_idx) - - pop = implmethod().register(pop, W_IntObject) - - def remove(w_self, w_any): - return list_remove(w_self.space, w_self, w_any) - - remove = implmethod().register(remove, W_ANY) - - def index(w_self, w_any): - return list_index(w_self.space, w_self, w_any) - - index = implmethod().register(index, W_ANY) - - def count(w_self, w_any): - return list_count(w_self.space, w_self, w_any) - - count = implmethod().register(count, W_ANY) - - def reverse(w_self): - return list_reverse(w_self.space, w_self) - - reverse = implmethod().register(reverse) def list_unwrap(space, w_list): items = [space.unwrap(w_item) for w_item in w_list.ob_item[:w_list.ob_size]] @@ -410,6 +373,15 @@ _reverse_slice(w_list.ob_item, 0, w_list.ob_size) return space.w_None +W_ListType.list_append .register(list_append, W_ListObject, W_ANY) +W_ListType.list_insert .register(list_insert, W_ListObject, W_IntObject, W_ANY) +W_ListType.list_extend .register(list_extend, W_ListObject, W_ANY) +W_ListType.list_pop .register(list_pop, W_ListObject, W_IntObject) +W_ListType.list_remove .register(list_remove, W_ListObject, W_ANY) +W_ListType.list_index .register(list_index, W_ListObject, W_ANY) +W_ListType.list_count .register(list_count, W_ListObject, W_ANY) +W_ListType.list_reverse.register(list_reverse,W_ListObject) + """ static PyMethodDef list_methods[] = { {"append", (PyCFunction)listappend, METH_O, append_doc}, Added: pypy/trunk/src/pypy/objspace/std/listtype.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/listtype.py Fri May 30 17:16:10 2003 @@ -0,0 +1,35 @@ +from pypy.objspace.std.objspace import * +from typeobject import W_TypeObject + + +class W_ListType(W_TypeObject): + + typename = 'list' + + list_append = MultiMethod('append', 2) + list_insert = MultiMethod('insert', 3) + list_extend = MultiMethod('extend', 2) + list_pop = MultiMethod('pop', 2) + list_remove = MultiMethod('remove', 2) + list_index = MultiMethod('index', 2) + list_count = MultiMethod('count', 2) + list_reverse= MultiMethod('reverse',1) + + +# XXX right now, this is responsible for building a whole new list +# XXX we'll worry about the __new__/__init__ distinction later +def listtype_new(space, w_listtype, w_args, w_kwds): + if space.is_true(w_kwds): + raise OperationError(space.w_TypeError, + space.wrap("no keyword arguments expected")) + args = space.unpackiterable(w_args) + if len(args) == 0: + list_w = [] + elif len(args) == 1: + list_w = space.unpackiterable(args[0]) + else: + raise OperationError(space.w_TypeError, + space.wrap("list() takes at most 1 argument")) + return space.newlist(list_w) + +StdObjSpace.new.register(listtype_new, W_ListType, W_ANY, 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 Fri May 30 17:16:10 2003 @@ -1,10 +1,11 @@ from pypy.objspace.std.objspace import * +from moduletype import W_ModuleType from dictobject import W_DictObject class W_ModuleObject(W_Object): delegate_once = {} - statictypename = 'module' + statictype = W_ModuleType def __init__(w_self, space, w_name): W_Object.__init__(w_self, space) Added: pypy/trunk/src/pypy/objspace/std/moduletype.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/moduletype.py Fri May 30 17:16:10 2003 @@ -0,0 +1,7 @@ +from pypy.objspace.std.objspace import * +from typeobject import W_TypeObject + + +class W_ModuleType(W_TypeObject): + + typename = 'module' Modified: pypy/trunk/src/pypy/objspace/std/multimethod.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/multimethod.py (original) +++ pypy/trunk/src/pypy/objspace/std/multimethod.py Fri May 30 17:16:10 2003 @@ -4,18 +4,16 @@ class FailedToImplement(Exception): "Signals the dispatcher to try harder." -class W_ANY: - "Placeholder to allow dispatch on any value." - statictype = None - class MultiMethod(object): - def __init__(self, operatorsymbol, arity, specialnames): + def __init__(self, operatorsymbol, arity, specialnames=None): "MultiMethod dispatching on the first 'arity' arguments." self.arity = arity self.operatorsymbol = operatorsymbol self.dispatch_table = {} + if specialnames is None: + specialnames = [operatorsymbol] self.specialnames = specialnames # list like ['__xxx__', '__rxxx__'] def register(self, function, *types): @@ -34,39 +32,43 @@ """Build a list of all possible combinations of delegated types, sorted by cost.""" result = [] - self.internal_buildchoices(types, (), (), (), result) - result.sort() - return [(delegators, function) for costs, delegators, function in result] + self.internal_buildchoices(types, (), (), result) + # the result is sorted by costs by construction. + # it is a list of (delegator, function) pairs. + return result def internal_buildchoices(self, initialtypes, currenttypes, - currentcosts, currentdelegators, result): + currentdelegators, result): if len(currenttypes) == self.arity: try: function = self.dispatch_table[currenttypes] except KeyError: pass else: - result.append((currentcosts, currentdelegators, function)) + result.append((currentdelegators, function)) else: nexttype = initialtypes[len(currenttypes)] - self.internal_buildchoices(initialtypes, currenttypes + (nexttype,), - currentcosts + (0,), - currentdelegators + (None,), result) - self.internal_buildchoices(initialtypes, currenttypes + (W_ANY,), - currentcosts + (1,), - currentdelegators + (None,), result) - delegators = getattr(nexttype, "delegate_once", {}) + delegators = {} + while 1: + self.internal_buildchoices(initialtypes, + currenttypes + (nexttype,), + currentdelegators + (None,), result) + delegators.update(getattr(nexttype, "delegate_once", {})) + # before general delegation, try superclasses + if not nexttype.__bases__: + break + nexttype, = nexttype.__bases__ # no multiple inheritance pleeease for othertype, delegator in delegators.items(): self.internal_buildchoices(initialtypes, currenttypes + (othertype,), - currentcosts + (2,), currentdelegators + (delegator,), result) - def slicetable(self, position, statictype): + def slicetable(self, position, slicetype): m = MultiMethod(self.operatorsymbol, self.arity, self.specialnames) for key, value in self.dispatch_table.iteritems(): - if key[position].statictype == statictype: + if (key[position].statictype is not None and + issubclass(key[position].statictype, slicetype.__class__)): m.dispatch_table[key] = value return m @@ -114,6 +116,7 @@ arg = delegator(self.space, arg) newargs.append(arg) newargs = tuple(newargs) + extraargs + # XXX 'prepend_space_argument' should now always be True anyway if prepend_space_argument: newargs = (self.space,) + newargs try: @@ -124,9 +127,9 @@ firstfailure = e raise firstfailure or FailedToImplement() - def slicetable(self, position, statictype): + def slicetable(self, position, slicetype): return BoundMultiMethod(self.space, - self.multimethod.slicetable(position, statictype)) + self.multimethod.slicetable(position, slicetype)) def is_empty(self): return self.multimethod.is_empty() Modified: pypy/trunk/src/pypy/objspace/std/noneobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/noneobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/noneobject.py Fri May 30 17:16:10 2003 @@ -1,9 +1,10 @@ from pypy.objspace.std.objspace import * +from nonetype import W_NoneType class W_NoneObject(W_Object): delegate_once = {} - statictypename = 'NoneType' + statictype = W_NoneType def none_unwrap(space, w_none): Added: pypy/trunk/src/pypy/objspace/std/nonetype.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/nonetype.py Fri May 30 17:16:10 2003 @@ -0,0 +1,7 @@ +from pypy.objspace.std.objspace import * +from typeobject import W_TypeObject + + +class W_NoneType(W_TypeObject): + + typename = 'NoneType' 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 Fri May 30 17:16:10 2003 @@ -18,19 +18,7 @@ def get_builtin_impl_class(w_self): return w_self.__class__ - -class implmethod(object): - def __init__(self): - self.dispatch_table = {} - def register(self, function, *types): - assert len(types) == function.func_code.co_argcount - 1, \ - "wrong number of W_Xxx arguments to .register()" - if types in self.dispatch_table: - raise error, "we already got an implementation for %r" % types - self.dispatch_table[types] = function - return self - def __get__(self, instance, cls=None): - raise "XXX come back later" +W_ANY = W_Object # synonyms for use in .register() ################################################################## @@ -45,24 +33,26 @@ pass AppFile.LOCAL_PATH = [PACKAGE_PATH] - BUILTIN_TYPES = { - 'W_NoneObject': 'noneobject', - 'W_BoolObject': 'boolobject', - 'W_IntObject': 'intobject', - 'W_FloatObject': 'floatobject', - 'W_ListObject': 'listobject', - 'W_DictObject': 'dictobject', - 'W_StringObject':'stringobject', - 'W_ModuleObject':'moduleobject', - 'W_TupleObject': 'tupleobject', - } + + def standard_types(self): + class result: + "Import here the types you want to have appear in __builtin__." + + from booltype import W_BoolType + from inttype import W_IntType + from floattype import W_FloatType + from tupletype import W_TupleType + from listtype import W_ListType + from dicttype import W_DictType + from stringtype import W_StringType + return [value for key, value in result.__dict__.items() + if not key.startswith('_')] # don't look + def initialize(self): - self.TYPE_CACHE = {} from noneobject import W_NoneObject from boolobject import W_BoolObject from cpythonobject import W_CPythonObject - from typeobject import W_TypeObject, make_type_by_name self.w_None = W_NoneObject(self) self.w_False = W_BoolObject(self, False) self.w_True = W_BoolObject(self, True) @@ -80,13 +70,11 @@ setattr(self, 'w_' + c.__name__, w_c) newstuff[c.__name__] = w_c # make the types - for classname, modulename in self.BUILTIN_TYPES.iteritems(): - mod = __import__(modulename, globals(), locals(), [classname]) - cls = getattr(mod, classname) - w_type = make_type_by_name(self, cls.statictypename) - w_type.setup_builtin_type(cls) - setattr(self, 'w_' + cls.statictypename, w_type) - newstuff[cls.statictypename] = w_type + self.types_w = {} + for typeclass in self.standard_types(): + w_type = self.get_typeinstance(typeclass) + setattr(self, 'w_' + typeclass.typename, w_type) + newstuff[typeclass.typename] = w_type self.make_builtins() self.make_sys() @@ -97,6 +85,14 @@ # w_import = self.wrap(__import__) # self.setitem(self.w_builtins, self.wrap("__import__"), w_import) + def get_typeinstance(self, typeclass): + # types_w maps each W_XxxType class to its unique-for-this-space instance + try: + w_type = self.types_w[typeclass] + except: + w_type = self.types_w[typeclass] = typeclass(self) + return w_type + def wrap(self, x): "Wraps the Python value 'x' into one of the wrapper classes." if x is None: Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Fri May 30 17:16:10 2003 @@ -1,4 +1,5 @@ from pypy.objspace.std.objspace import * +from stringtype import W_StringType from intobject import W_IntObject from sliceobject import W_SliceObject from listobject import W_ListObject @@ -12,9 +13,8 @@ applicationfile = StdObjSpace.AppFile(__name__) class W_StringObject(W_Object): - delegate_once = {} - statictypename = 'str' + statictype = W_StringType def __init__(w_self, space, str): W_Object.__init__(w_self, space) @@ -30,34 +30,6 @@ def hash(w_self): return W_IntObject(self, self._value.hash()) - def join(w_self, w_list): - list = w_self.space.unpackiterable(w_list) - if list: - firstelem = 1 - listlen = 0 - reslen = 0 - for w_item in list: - reslen = reslen + w_item._value.len - listlen = listlen + 1 - - reslen = reslen + (listlen - 1) * w_self._value.len - res = CharArraySize(reslen) - - pos = 0 - for w_item in list: - if firstelem: - res.setsubstring(pos, w_item._value.value()) - pos = pos + w_item._value.len - firstelem = 0 - else: - res.setsubstring(pos, w_self._value.value()) - pos = pos + w_self._value.len - res.setsubstring(pos, w_item._value.value()) - pos = pos + w_item._value.len - return W_StringObject(w_self.space, res.value()) - else: - return W_StringObject(w_self.space, "") - def _char_isspace(ch): return ord(ch) in (9, 10, 11, 12, 13, 32) @@ -78,41 +50,39 @@ def isspace(w_self): return is_generic(w_self, _char_isspace) + ## XXX fixme - def isdigit(w_self): - pass +## def isdigit(w_self): +## pass - def isupper(w_self): - pass +## def isupper(w_self): +## pass - def isupper(w_self): - pass +## def isupper(w_self): +## pass - def islower(w_self): - pass +## def islower(w_self): +## pass - def istitle(w_self): - pass +## def istitle(w_self): +## pass - def isalnum(w_self): - pass +## def isalnum(w_self): +## pass - def isalpha(w_self): - pass +## def isalpha(w_self): +## pass - isspace = implmethod().register(isspace) - isdigit = implmethod().register(isdigit) - isupper = implmethod().register(isupper) - islower = implmethod().register(islower) - istitle = implmethod().register(istitle) - isalnum = implmethod().register(isalnum) - isalpha = implmethod().register(isalpha) +## isspace = implmethod().register(isspace) +## isdigit = implmethod().register(isdigit) +## isupper = implmethod().register(isupper) +## islower = implmethod().register(islower) +## istitle = implmethod().register(istitle) +## isalnum = implmethod().register(isalnum) +## isalpha = implmethod().register(isalpha) - join = implmethod().register(join, W_ANY) - split = implmethod() - -def splitByWhitespace(w_self, w_none): +def str_splitByWhitespace(space, w_self, w_none): res = [] inword = 0 value = w_self._value.value() @@ -127,10 +97,10 @@ res.append(ch) inword = 1 for i in range(len(res)): - res[i] = W_StringObject(w_self.space, res[i]) - return W_ListObject(w_self.space, res) + res[i] = W_StringObject(space, res[i]) + return W_ListObject(space, res) -def split(w_self, w_by): +def str_split(space, w_self, w_by): res = [] start = 0 value = w_self._value.value() @@ -147,12 +117,43 @@ return W_ListObject(w_self.space, res) # XXX temporary hack -W_StringObject.__dict__['split'].register(split, W_StringObject) - +W_StringType.str_split.register(str_split, W_StringObject, W_StringObject) +W_StringType.str_split.register(str_splitByWhitespace, + W_StringObject, W_NoneObject) #We should erase the W_NoneObject, but register takes always #the same number of parameters. So you have to call split with #None as parameter instead of calling it without any parameter -W_StringObject.__dict__['split'].register(splitByWhitespace, W_NoneObject) + + +def str_join(space, w_self, w_list): + list = space.unpackiterable(w_list) + if list: + firstelem = 1 + listlen = 0 + reslen = 0 + for w_item in list: + reslen = reslen + w_item._value.len + listlen = listlen + 1 + + reslen = reslen + (listlen - 1) * w_self._value.len + res = CharArraySize(reslen) + + pos = 0 + for w_item in list: + if firstelem: + res.setsubstring(pos, w_item._value.value()) + pos = pos + w_item._value.len + firstelem = 0 + else: + res.setsubstring(pos, w_self._value.value()) + pos = pos + w_self._value.len + res.setsubstring(pos, w_item._value.value()) + pos = pos + w_item._value.len + return W_StringObject(space, res.value()) + else: + return W_StringObject(space, "") + +W_StringType.str_join.register(str_join, W_StringObject, W_ANY) def str_unwrap(space, w_str): @@ -288,7 +289,7 @@ r[i] = space.getitem(w_str, w(start + i*step)) w_r = space.newlist(r) w_empty = space.newstring([]) - return w_empty.join(w_r) + return str_join(w_empty, w_r) StdObjSpace.getitem.register(getitem_str_slice, W_StringObject, W_SliceObject) Added: pypy/trunk/src/pypy/objspace/std/stringtype.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/stringtype.py Fri May 30 17:16:10 2003 @@ -0,0 +1,10 @@ +from pypy.objspace.std.objspace import * +from typeobject import W_TypeObject + + +class W_StringType(W_TypeObject): + + typename = 'str' + + str_join = MultiMethod('join', 2) + str_split = MultiMethod('split', 2) Modified: pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py Fri May 30 17:16:10 2003 @@ -37,6 +37,7 @@ def test_float_sub(self): w = self.space.wrap + w(1.5) # force floatobject imported for i in range(2): meth = tobj.PyMultimethodCode(self.space.sub, i, self.space.w_float) self.assertEqual(meth.multimethod.is_empty(), False) Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupleobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupleobject.py Fri May 30 17:16:10 2003 @@ -1,12 +1,12 @@ from pypy.objspace.std.objspace import * +from tupletype import W_TupleType from intobject import W_IntObject from sliceobject import W_SliceObject class W_TupleObject(W_Object): - delegate_once = {} - statictypename = 'tuple' + statictype = W_TupleType def __init__(w_self, space, wrappeditems): W_Object.__init__(w_self, space) Added: pypy/trunk/src/pypy/objspace/std/tupletype.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/tupletype.py Fri May 30 17:16:10 2003 @@ -0,0 +1,7 @@ +from pypy.objspace.std.objspace import * +from typeobject import W_TypeObject + + +class W_TupleType(W_TypeObject): + + typename = 'tuple' Modified: pypy/trunk/src/pypy/objspace/std/typeobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/typeobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/typeobject.py Fri May 30 17:16:10 2003 @@ -1,37 +1,36 @@ from pypy.interpreter import pycode from pypy.objspace.std.objspace import * -from pypy.objspace.std.dictobject import W_DictObject class W_TypeObject(W_Object): delegate_once = {} - statictypename = 'type' + #statictype = W_TypeType (hacked into place in typetype.py) - def __init__(w_self, space, w_tpname): + def __init__(w_self, space): W_Object.__init__(w_self, space) - w_self.w_tpname = w_tpname - w_self.builtin_implementations = [] + w_self.w_tpname = space.wrap(w_self.typename) w_self.multimethods = {} - # HACK to get to the multimethods of the space - for key, value in space.__class__.__dict__.iteritems(): - if isinstance(value, MultiMethod): - for i in range(len(value.specialnames)): - w_self.multimethods[value.specialnames[i]] = value, i - - def setup_builtin_type(w_self, implementation): - implementation.statictype = w_self - w_self.builtin_implementations.append(implementation) - - for key, value in implementation.__dict__.iteritems(): - if isinstance(value, implmethod): - try: - multimethod, bound_pos = w_self.multimethods[key] - except KeyError: - sample = value.dispatch_table.keys()[0] - multimethod = MultiMethod('%s()' % key, len(sample)+1, []) - w_self.multimethods[key] = multimethod, None - for types, func in value.dispatch_table.iteritems(): - multimethod.register(func, implementation, *types) + # import all multimethods of the space and of the type class + for multimethod in (hack_out_multimethods(space) + + hack_out_multimethods(w_self)): + for i in range(len(multimethod.specialnames)): + w_self.multimethods[multimethod.specialnames[i]] = multimethod, i + +## XXX remove me +## def setup_builtin_type(w_self, implementation): +## implementation.statictype = w_self +## w_self.builtin_implementations.append(implementation) +## +## for key, value in implementation.__dict__.iteritems(): +## if isinstance(value, implmethod): +## try: +## multimethod, bound_pos = w_self.multimethods[key] +## except KeyError: +## sample = value.dispatch_table.keys()[0] +## multimethod = MultiMethod('%s()' % key, len(sample)+1, []) +## w_self.multimethods[key] = multimethod, None +## for types, func in value.dispatch_table.iteritems(): +## multimethod.register(func, implementation, *types) def lookup(w_self, space, w_key): "XXX at some point, turn this into a multimethod" @@ -48,13 +47,9 @@ return space.newfunction(code, space.w_None, space.w_None) -def make_type_by_name(space, tpname): - try: - w_type = space.TYPE_CACHE[tpname] - except KeyError: - w_type = space.TYPE_CACHE[tpname] = W_TypeObject(space, - space.wrap(tpname)) - return w_type +def hack_out_multimethods(instance): + return [value for value in instance.__class__.__dict__.itervalues() + if isinstance(value, MultiMethod)] class PyMultimethodCode(pycode.PyBaseCode): @@ -63,14 +58,8 @@ pycode.PyBaseCode.__init__(self) argnames = ['x%d'%(i+1) for i in range(multimethod.multimethod.arity)] if w_type is not None: - # 'bound_pos' hack mode on - multimethod = multimethod.slicetable(bound_position or 0, w_type) - # 'bound_pos' hack mode off - if bound_position: - argnames.insert(0, argnames.pop(bound_position)) - # 'bound_pos' hack mode on - self.prepend_space_argument = bound_position is not None - # 'bound_pos' hack mode off + multimethod = multimethod.slicetable(bound_position, w_type) + argnames.insert(0, argnames.pop(bound_position)) self.multimethod = multimethod self.co_name = multimethod.multimethod.operatorsymbol self.co_flags = 0 @@ -90,8 +79,7 @@ dispatchargs = tuple(dispatchargs) initialtypes = tuple(initialtypes) try: - return multimethod.perform_call(dispatchargs, initialtypes, - prepend_space_argument = self.prepend_space_argument) + return multimethod.perform_call(dispatchargs, initialtypes) except FailedToImplement, e: if e.args: raise OperationError(*e.args) @@ -100,31 +88,34 @@ def type_call(space, w_type, w_args, w_kwds): + w_newobject = space.new(w_type, w_args, w_kwds) + # XXX call __init__() later + return w_newobject - # H H AA CCC K K - # H H A A C K K - # HHHH A A C KK - # H H AAAA C K K - # H H A A CCC K K - - tpname = space.unwrap(w_type.w_tpname) - args = space.unpackiterable(w_args) - if tpname == 'type': - assert len(args) == 1 - return space.type(args[0]) - if tpname == 'list': - assert len(args) == 1 - return space.newlist(space.unpackiterable(args[0])) - if tpname == 'tuple': - assert len(args) == 1 - return space.newtuple(space.unpackiterable(args[0])) - if tpname == 'str': - assert len(args) == 1 - return space.str(args[0]) - - import __builtin__ - hacky = getattr(__builtin__, tpname)( - *space.unwrap(w_args), **space.unwrap(w_kwds)) - return space.wrap(hacky) +## # H H AA CCC K K +## # H H A A C K K +## # HHHH A A C KK +## # H H AAAA C K K +## # H H A A CCC K K + +## tpname = space.unwrap(w_type.w_tpname) +## args = space.unpackiterable(w_args) +## if tpname == 'type': +## assert len(args) == 1 +## return space.type(args[0]) +## if tpname == 'list': +## assert len(args) == 1 +## return space.newlist(space.unpackiterable(args[0])) +## if tpname == 'tuple': +## assert len(args) == 1 +## return space.newtuple(space.unpackiterable(args[0])) +## if tpname == 'str': +## assert len(args) == 1 +## return space.str(args[0]) + +## import __builtin__ +## hacky = getattr(__builtin__, tpname)( +## *space.unwrap(w_args), **space.unwrap(w_kwds)) +## return space.wrap(hacky) StdObjSpace.call.register(type_call, W_TypeObject, W_ANY, W_ANY) From arigo at codespeak.net Fri May 30 17:25:26 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 30 May 2003 17:25:26 +0200 (MEST) Subject: [pypy-svn] rev 732 - pypy/trunk/src/pypy/objspace/std/test Message-ID: <20030530152526.134145ACAB@thoth.codespeak.net> Author: arigo Date: Fri May 30 17:25:25 2003 New Revision: 732 Modified: pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py Log: added W_ANY back for this test file Modified: pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py Fri May 30 17:25:25 2003 @@ -3,6 +3,7 @@ from pypy.objspace.std.multimethod import * +W_ANY = object class X: From mwh at codespeak.net Fri May 30 17:35:01 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 30 May 2003 17:35:01 +0200 (MEST) Subject: [pypy-svn] rev 733 - in pypy/trunk/src/pypy: . appspace/test interpreter interpreter/test module/test objspace/std objspace/std/test Message-ID: <20030530153501.401E45ACAB@thoth.codespeak.net> Author: mwh Date: Fri May 30 17:34:59 2003 New Revision: 733 Modified: pypy/trunk/src/pypy/appspace/test/testsupport.py pypy/trunk/src/pypy/interpreter/test/testsupport.py pypy/trunk/src/pypy/interpreter/testsupport.py pypy/trunk/src/pypy/module/test/test_filter.py (props changed) pypy/trunk/src/pypy/module/test/test_map.py (props changed) pypy/trunk/src/pypy/module/test/test_reduce.py (props changed) pypy/trunk/src/pypy/module/test/test_vars.py (props changed) pypy/trunk/src/pypy/module/test/test_zip.py (props changed) pypy/trunk/src/pypy/module/test/testsupport.py pypy/trunk/src/pypy/objspace/std/booltype.py (props changed) pypy/trunk/src/pypy/objspace/std/dicttype.py (props changed) pypy/trunk/src/pypy/objspace/std/floattype.py (props changed) pypy/trunk/src/pypy/objspace/std/inttype.py (props changed) pypy/trunk/src/pypy/objspace/std/listtype.py (props changed) pypy/trunk/src/pypy/objspace/std/moduletype.py (props changed) pypy/trunk/src/pypy/objspace/std/nonetype.py (props changed) pypy/trunk/src/pypy/objspace/std/stringtype.py (props changed) pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py (contents, props changed) pypy/trunk/src/pypy/objspace/std/test/testsupport.py pypy/trunk/src/pypy/objspace/std/tupletype.py (props changed) pypy/trunk/src/pypy/testsupport.py Log: line endings + testsupport tweaks Modified: pypy/trunk/src/pypy/appspace/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/appspace/test/testsupport.py (original) +++ pypy/trunk/src/pypy/appspace/test/testsupport.py Fri May 30 17:34:59 2003 @@ -45,18 +45,19 @@ from pypy.interpreter import testtools -objspace_path = os.environ.get('OBJSPACE') -if not objspace_path or '.' not in objspace_path: - import pypy.objspace.trivial - objspace = pypy.objspace.trivial.TrivialObjSpace -else: - objspace_pieces = objspace_path.split('.') - objspace_path = '.'.join(objspace_pieces[:-1]) - objspace_module = __import__(objspace_path) - for piece in objspace_pieces[1:-1]: - objspace_module = getattr(objspace_module, piece) - objspace_classname = objspace_pieces[-1] - objspace = getattr(objspace_module, objspace_classname) +def objspace(): + objspace_path = os.environ.get('OBJSPACE') + if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + return pypy.objspace.trivial.TrivialObjSpace() + else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + return getattr(objspace_module, objspace_classname)() if __name__ == '__main__': runner = unittest.TextTestRunner() Modified: pypy/trunk/src/pypy/interpreter/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/testsupport.py (original) +++ pypy/trunk/src/pypy/interpreter/test/testsupport.py Fri May 30 17:34:59 2003 @@ -45,18 +45,19 @@ from pypy.interpreter import testtools -objspace_path = os.environ.get('OBJSPACE') -if not objspace_path or '.' not in objspace_path: - import pypy.objspace.trivial - objspace = pypy.objspace.trivial.TrivialObjSpace -else: - objspace_pieces = objspace_path.split('.') - objspace_path = '.'.join(objspace_pieces[:-1]) - objspace_module = __import__(objspace_path) - for piece in objspace_pieces[1:-1]: - objspace_module = getattr(objspace_module, piece) - objspace_classname = objspace_pieces[-1] - objspace = getattr(objspace_module, objspace_classname) +def objspace(): + objspace_path = os.environ.get('OBJSPACE') + if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + return pypy.objspace.trivial.TrivialObjSpace() + else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + return getattr(objspace_module, objspace_classname)() if __name__ == '__main__': runner = unittest.TextTestRunner() Modified: pypy/trunk/src/pypy/interpreter/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/testsupport.py (original) +++ pypy/trunk/src/pypy/interpreter/testsupport.py Fri May 30 17:34:59 2003 @@ -1,63 +1,64 @@ -""" -Master version of testsupport.py: copy into any subdirectory of pypy -from which scripts need to be run (typically all of the 'test' subdirs) -so that any test can "import testsupport" to ensure the parent of pypy -is on the sys.path -- so that "import pypy.etc.etc." always works. - -Also, this module exposes a member 'TestCase' that is unittest.TestCase -or a subclass thereof supplying extra methods; and a function 'main' -that is unittest.main or the equivalent. - -Furthermore, this module now exposes a member 'objspace' which is -by default class pypy.objspace.trivial.TrivialObjSpace but can be -set to use another objectspace instead; this allows tests to run -under different objectspaces without needing to edit their sources. - -For this setting, use environment variable OBJSPACE and set it to -a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is -also the default if the environment variable is not found or empty -or without any dot in it). - -When run as a script, runs all tests found in files called 'test_*.py' -in the same directory. -""" -import sys, os - -try: - head = this_path = os.path.abspath(__file__) -except NameError: - p = os.path.dirname(sys.argv[0]) - if not p: - p = os.curdir - head = this_path = os.path.abspath(p) -while 1: - head, tail = os.path.split(head) - if not tail: - raise EnvironmentError, "pypy not among parents of %r!" % this_path - elif tail.lower()=='pypy': - sys.path.insert(0, head) - break - -import pypy.interpreter.unittest_w -TestCase = pypy.interpreter.unittest_w.TestCase_w -import unittest -main = unittest.main - -from pypy.interpreter import testtools - -objspace_path = os.environ.get('OBJSPACE') -if not objspace_path or '.' not in objspace_path: - import pypy.objspace.trivial - objspace = pypy.objspace.trivial.TrivialObjSpace -else: - objspace_pieces = objspace_path.split('.') - objspace_path = '.'.join(objspace_pieces[:-1]) - objspace_module = __import__(objspace_path) - for piece in objspace_pieces[1:-1]: - objspace_module = getattr(objspace_module, piece) - objspace_classname = objspace_pieces[-1] - objspace = getattr(objspace_module, objspace_classname) - -if __name__ == '__main__': - runner = unittest.TextTestRunner() - runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0]))) +""" +Master version of testsupport.py: copy into any subdirectory of pypy +from which scripts need to be run (typically all of the 'test' subdirs) +so that any test can "import testsupport" to ensure the parent of pypy +is on the sys.path -- so that "import pypy.etc.etc." always works. + +Also, this module exposes a member 'TestCase' that is unittest.TestCase +or a subclass thereof supplying extra methods; and a function 'main' +that is unittest.main or the equivalent. + +Furthermore, this module now exposes a member 'objspace' which is +by default class pypy.objspace.trivial.TrivialObjSpace but can be +set to use another objectspace instead; this allows tests to run +under different objectspaces without needing to edit their sources. + +For this setting, use environment variable OBJSPACE and set it to +a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is +also the default if the environment variable is not found or empty +or without any dot in it). + +When run as a script, runs all tests found in files called 'test_*.py' +in the same directory. +""" +import sys, os + +try: + head = this_path = os.path.abspath(__file__) +except NameError: + p = os.path.dirname(sys.argv[0]) + if not p: + p = os.curdir + head = this_path = os.path.abspath(p) +while 1: + head, tail = os.path.split(head) + if not tail: + raise EnvironmentError, "pypy not among parents of %r!" % this_path + elif tail.lower()=='pypy': + sys.path.insert(0, head) + break + +import pypy.interpreter.unittest_w +TestCase = pypy.interpreter.unittest_w.TestCase_w +import unittest +main = unittest.main + +from pypy.interpreter import testtools + +def objspace(): + objspace_path = os.environ.get('OBJSPACE') + if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + return pypy.objspace.trivial.TrivialObjSpace() + else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + return getattr(objspace_module, objspace_classname)() + +if __name__ == '__main__': + runner = unittest.TextTestRunner() + runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0]))) Modified: pypy/trunk/src/pypy/module/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/module/test/testsupport.py (original) +++ pypy/trunk/src/pypy/module/test/testsupport.py Fri May 30 17:34:59 2003 @@ -45,18 +45,19 @@ from pypy.interpreter import testtools -objspace_path = os.environ.get('OBJSPACE') -if not objspace_path or '.' not in objspace_path: - import pypy.objspace.trivial - objspace = pypy.objspace.trivial.TrivialObjSpace -else: - objspace_pieces = objspace_path.split('.') - objspace_path = '.'.join(objspace_pieces[:-1]) - objspace_module = __import__(objspace_path) - for piece in objspace_pieces[1:-1]: - objspace_module = getattr(objspace_module, piece) - objspace_classname = objspace_pieces[-1] - objspace = getattr(objspace_module, objspace_classname) +def objspace(): + objspace_path = os.environ.get('OBJSPACE') + if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + return pypy.objspace.trivial.TrivialObjSpace() + else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + return getattr(objspace_module, objspace_classname)() if __name__ == '__main__': runner = unittest.TextTestRunner() Modified: pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py Fri May 30 17:34:59 2003 @@ -1,4 +1,5 @@ import testsupport +from pypy.objspace.std import StdObjSpace class TestW_SliceObject(testsupport.TestCase): Modified: pypy/trunk/src/pypy/objspace/std/test/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/test/testsupport.py (original) +++ pypy/trunk/src/pypy/objspace/std/test/testsupport.py Fri May 30 17:34:59 2003 @@ -45,18 +45,19 @@ from pypy.interpreter import testtools -objspace_path = os.environ.get('OBJSPACE') -if not objspace_path or '.' not in objspace_path: - import pypy.objspace.trivial - objspace = pypy.objspace.trivial.TrivialObjSpace -else: - objspace_pieces = objspace_path.split('.') - objspace_path = '.'.join(objspace_pieces[:-1]) - objspace_module = __import__(objspace_path) - for piece in objspace_pieces[1:-1]: - objspace_module = getattr(objspace_module, piece) - objspace_classname = objspace_pieces[-1] - objspace = getattr(objspace_module, objspace_classname) +def objspace(): + objspace_path = os.environ.get('OBJSPACE') + if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + return pypy.objspace.trivial.TrivialObjSpace() + else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + return getattr(objspace_module, objspace_classname)() if __name__ == '__main__': runner = unittest.TextTestRunner() Modified: pypy/trunk/src/pypy/testsupport.py ============================================================================== --- pypy/trunk/src/pypy/testsupport.py (original) +++ pypy/trunk/src/pypy/testsupport.py Fri May 30 17:34:59 2003 @@ -45,18 +45,19 @@ from pypy.interpreter import testtools -objspace_path = os.environ.get('OBJSPACE') -if not objspace_path or '.' not in objspace_path: - import pypy.objspace.trivial - objspace = pypy.objspace.trivial.TrivialObjSpace -else: - objspace_pieces = objspace_path.split('.') - objspace_path = '.'.join(objspace_pieces[:-1]) - objspace_module = __import__(objspace_path) - for piece in objspace_pieces[1:-1]: - objspace_module = getattr(objspace_module, piece) - objspace_classname = objspace_pieces[-1] - objspace = getattr(objspace_module, objspace_classname) +def objspace(): + objspace_path = os.environ.get('OBJSPACE') + if not objspace_path or '.' not in objspace_path: + import pypy.objspace.trivial + return pypy.objspace.trivial.TrivialObjSpace() + else: + objspace_pieces = objspace_path.split('.') + objspace_path = '.'.join(objspace_pieces[:-1]) + objspace_module = __import__(objspace_path) + for piece in objspace_pieces[1:-1]: + objspace_module = getattr(objspace_module, piece) + objspace_classname = objspace_pieces[-1] + return getattr(objspace_module, objspace_classname)() if __name__ == '__main__': runner = unittest.TextTestRunner() From mwh at codespeak.net Fri May 30 17:58:15 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 30 May 2003 17:58:15 +0200 (MEST) Subject: [pypy-svn] rev 734 - pypy/trunk/src/pypy/module Message-ID: <20030530155815.B126D5ACAB@thoth.codespeak.net> Author: mwh Date: Fri May 30 17:58:15 2003 New Revision: 734 Modified: pypy/trunk/src/pypy/module/sysmodule.py Log: sys.displayhook should print the repr not the str! this hilights the fact that we don't define many repr methods... Modified: pypy/trunk/src/pypy/module/sysmodule.py ============================================================================== --- pypy/trunk/src/pypy/module/sysmodule.py (original) +++ pypy/trunk/src/pypy/module/sysmodule.py Fri May 30 17:58:15 2003 @@ -24,7 +24,7 @@ w = space.wrap if w_x != space.w_None: try: - print space.unwrap(self.space.str(w_x)) + print space.unwrap(self.space.repr(w_x)) except OperationError: print "! could not print", w_x space.setitem(space.w_builtins, w('_'), w_x) From arigo at codespeak.net Fri May 30 18:06:38 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 30 May 2003 18:06:38 +0200 (MEST) Subject: [pypy-svn] rev 735 - in pypy/trunk/src/pypy: interpreter objspace/std Message-ID: <20030530160638.CA2825ACAB@thoth.codespeak.net> Author: arigo Date: Fri May 30 18:06:38 2003 New Revision: 735 Added: pypy/trunk/src/pypy/objspace/std/typetype.py (contents, props changed) Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py pypy/trunk/src/pypy/objspace/std/objspace.py pypy/trunk/src/pypy/objspace/std/stringtype.py pypy/trunk/src/pypy/objspace/std/tupletype.py Log: a couple more __new__ methods Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/baseobjspace.py (original) +++ pypy/trunk/src/pypy/interpreter/baseobjspace.py Fri May 30 18:06:38 2003 @@ -152,9 +152,7 @@ return self.w_False def call_function(self, w_func, *args_w, **kw_w): - w_kw = self.newdict([]) - for k, w_v in kw_w.iteritems(): - self.setitem(w_kw, self.wrap(k), w_v) + w_kw = self.newdict([(self.wrap(k), w_v) for k, w_v in kw_w.iteritems()]) return self.call(w_func, self.newtuple(list(args_w)), w_kw) ## Table describing the regular part of the interface of object spaces, 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 Fri May 30 18:06:38 2003 @@ -45,6 +45,7 @@ from listtype import W_ListType from dicttype import W_DictType from stringtype import W_StringType + from typetype import W_TypeType return [value for key, value in result.__dict__.items() if not key.startswith('_')] # don't look Modified: pypy/trunk/src/pypy/objspace/std/stringtype.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringtype.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringtype.py Fri May 30 18:06:38 2003 @@ -8,3 +8,20 @@ str_join = MultiMethod('join', 2) str_split = MultiMethod('split', 2) + + +# XXX we'll worry about the __new__/__init__ distinction later +def stringtype_new(space, w_stringtype, w_args, w_kwds): + if space.is_true(w_kwds): + raise OperationError(space.w_TypeError, + space.wrap("no keyword arguments expected")) + args = space.unpackiterable(w_args) + if len(args) == 0: + return space.newstring([]) + elif len(args) == 1: + return space.str(args[0]) + else: + raise OperationError(space.w_TypeError, + space.wrap("str() takes at most 1 argument")) + +StdObjSpace.new.register(stringtype_new, W_StringType, W_ANY, W_ANY) Modified: pypy/trunk/src/pypy/objspace/std/tupletype.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/tupletype.py (original) +++ pypy/trunk/src/pypy/objspace/std/tupletype.py Fri May 30 18:06:38 2003 @@ -5,3 +5,21 @@ class W_TupleType(W_TypeObject): typename = 'tuple' + + +# XXX we'll worry about the __new__/__init__ distinction later +def tupletype_new(space, w_tupletype, w_args, w_kwds): + if space.is_true(w_kwds): + raise OperationError(space.w_TypeError, + space.wrap("no keyword arguments expected")) + args = space.unpackiterable(w_args) + if len(args) == 0: + tuple_w = [] + elif len(args) == 1: + tuple_w = space.unpackiterable(args[0]) + else: + raise OperationError(space.w_TypeError, + space.wrap("tuple() takes at most 1 argument")) + return space.newtuple(tuple_w) + +StdObjSpace.new.register(tupletype_new, W_TupleType, W_ANY, W_ANY) Added: pypy/trunk/src/pypy/objspace/std/typetype.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/typetype.py Fri May 30 18:06:38 2003 @@ -0,0 +1,27 @@ +from pypy.objspace.std.objspace import * +from typeobject import W_TypeObject + + +class W_TypeType(W_TypeObject): + + typename = 'type' + + +# hack that in place +W_TypeObject.statictype = W_TypeType + + +# XXX we'll worry about the __new__/__init__ distinction later +def typetype_new(space, w_typetype, w_args, w_kwds): + if space.is_true(w_kwds): + raise OperationError(space.w_TypeError, + space.wrap("no keyword arguments expected")) + args = space.unpackiterable(w_args) + if len(args) == 1: + return space.type(args[0]) + else: + raise OperationError(space.w_TypeError, + space.wrap("XXX sorry, type() with anything else " + "but 1 argument is for later")) + +StdObjSpace.new.register(typetype_new, W_TypeType, W_ANY, W_ANY) From arigo at codespeak.net Fri May 30 18:20:15 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 30 May 2003 18:20:15 +0200 (MEST) Subject: [pypy-svn] rev 736 - in pypy/trunk/src/pypy: interpreter/test objspace/std Message-ID: <20030530162015.1903D5ACAB@thoth.codespeak.net> Author: arigo Date: Fri May 30 18:20:14 2003 New Revision: 736 Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py pypy/trunk/src/pypy/interpreter/test/test_interpreter.py pypy/trunk/src/pypy/objspace/std/multimethod.py Log: correct some space.call() and added a systematic check in multimethod.py Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Fri May 30 18:20:14 2003 @@ -51,7 +51,7 @@ {'__doc__': BM_with_appmethod.__doc__, '__name__': BM_with_appmethod.__pythonname__, 'amethod': BM_with_appmethod.amethod} ) - result = space.call(w_method, space.wrap(()), None) + result = space.call(w_method, space.wrap(()), space.wrap({})) self.assertEqual(result, 23) def test_appdata(self): Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/test/test_interpreter.py (original) +++ pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Fri May 30 18:20:14 2003 @@ -23,8 +23,9 @@ wrappedargs = w(args) wrappedfunc = space.getitem(w_glob, w(functionname)) + wrappedkwds = space.newdict([]) try: - w_output = space.call(wrappedfunc, wrappedargs, None) + w_output = space.call(wrappedfunc, wrappedargs, wrappedkwds) except baseobjspace.OperationError, e: e.print_detailed_traceback(space) return '<<<%s>>>' % e.errorstr(space) Modified: pypy/trunk/src/pypy/objspace/std/multimethod.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/multimethod.py (original) +++ pypy/trunk/src/pypy/objspace/std/multimethod.py Fri May 30 18:20:14 2003 @@ -56,6 +56,9 @@ delegators.update(getattr(nexttype, "delegate_once", {})) # before general delegation, try superclasses if not nexttype.__bases__: + # debugging assertion + assert nexttype.__name__ == 'W_Object', \ + "calling a multimethod with an argument which is not wrapped" break nexttype, = nexttype.__bases__ # no multiple inheritance pleeease for othertype, delegator in delegators.items(): From mwh at codespeak.net Fri May 30 18:27:37 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 30 May 2003 18:27:37 +0200 (MEST) Subject: [pypy-svn] rev 737 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030530162737.3666D5ACAB@thoth.codespeak.net> Author: mwh Date: Fri May 30 18:27:36 2003 New Revision: 737 Modified: pypy/trunk/src/pypy/objspace/std/default.py pypy/trunk/src/pypy/objspace/std/stringobject.py Log: add default_str which calls the also added default_repr add a bogus str_repr Modified: pypy/trunk/src/pypy/objspace/std/default.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/default.py (original) +++ pypy/trunk/src/pypy/objspace/std/default.py Fri May 30 18:27:36 2003 @@ -136,3 +136,14 @@ return w_type StdObjSpace.type.register(default_type, W_ANY) + +def default_str(space, w_obj): + return space.repr(w_obj) + +StdObjSpace.str.register(default_str, W_ANY) + +def default_repr(space, w_obj): + return space.wrap('<%s object at %s>'%( + space.type(w_obj).typename, space.unwrap(space.id(w_obj)))) + +StdObjSpace.repr.register(default_repr, W_ANY) Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Fri May 30 18:27:36 2003 @@ -317,3 +317,11 @@ return w_str StdObjSpace.str.register(str_str, W_StringObject) + +def str_repr(space, w_str): + # XXX this is bogus -- mwh + a = space.add + q = space.wrap("'") + return a(a(q, w_str), q) + +StdObjSpace.repr.register(str_repr, W_StringObject) From arigo at codespeak.net Fri May 30 19:15:32 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 30 May 2003 19:15:32 +0200 (MEST) Subject: [pypy-svn] rev 738 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030530171532.1CEAB5A23B@thoth.codespeak.net> Author: arigo Date: Fri May 30 19:15:30 2003 New Revision: 738 Added: pypy/trunk/src/pypy/objspace/std/usertype.py Modified: pypy/trunk/src/pypy/objspace/std/booltype.py pypy/trunk/src/pypy/objspace/std/objspace.py pypy/trunk/src/pypy/objspace/std/typeobject.py pypy/trunk/src/pypy/objspace/std/typetype.py pypy/trunk/src/pypy/objspace/std/userobject.py Log: we have basic classes :-) Modified: pypy/trunk/src/pypy/objspace/std/booltype.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/booltype.py (original) +++ pypy/trunk/src/pypy/objspace/std/booltype.py Fri May 30 19:15:30 2003 @@ -5,3 +5,6 @@ class W_BoolType(W_TypeObject): typename = 'bool' + + def getbases(w_self, space): + return (space.w_int,) 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 Fri May 30 19:15:30 2003 @@ -87,6 +87,8 @@ # self.setitem(self.w_builtins, self.wrap("__import__"), w_import) def get_typeinstance(self, typeclass): + assert hasattr(typeclass, 'typename'), \ + "get_typeinstance() cannot be used for W_UserType" # types_w maps each W_XxxType class to its unique-for-this-space instance try: w_type = self.types_w[typeclass] Modified: pypy/trunk/src/pypy/objspace/std/typeobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/typeobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/typeobject.py Fri May 30 19:15:30 2003 @@ -16,6 +16,17 @@ for i in range(len(multimethod.specialnames)): w_self.multimethods[multimethod.specialnames[i]] = multimethod, i + def getbases(w_self, space): + return () + + def getmro(w_self, space): + # XXX this is something that works not too bad right now + # XXX do the complete mro thing later + mro = [w_self] + for w_parent in w_self.getbases(space): + mro += w_parent.getmro(space) + return tuple(mro) + ## XXX remove me ## def setup_builtin_type(w_self, implementation): ## implementation.statictype = w_self @@ -34,6 +45,15 @@ def lookup(w_self, space, w_key): "XXX at some point, turn this into a multimethod" + # note that this doesn't call __get__ on the result at all + for w_class in w_self.getmro(space): + try: + return w_class.lookup_exactly_here(space, w_key) + except KeyError: + pass + raise KeyError + + def lookup_exactly_here(w_self, space, w_key): key = space.unwrap(w_key) assert isinstance(key, str) try: Modified: pypy/trunk/src/pypy/objspace/std/typetype.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/typetype.py (original) +++ pypy/trunk/src/pypy/objspace/std/typetype.py Fri May 30 19:15:30 2003 @@ -19,9 +19,13 @@ args = space.unpackiterable(w_args) if len(args) == 1: return space.type(args[0]) + elif len(args) == 3: + from usertype import W_UserType + w_name, w_bases, w_dict = args + w_usertype = W_UserType(space, w_name, w_bases, w_dict) + return w_usertype else: raise OperationError(space.w_TypeError, - space.wrap("XXX sorry, type() with anything else " - "but 1 argument is for later")) + space.wrap("type() takes 1 or 3 arguments")) StdObjSpace.new.register(typetype_new, W_TypeType, W_ANY, W_ANY) Modified: pypy/trunk/src/pypy/objspace/std/userobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/userobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/userobject.py Fri May 30 19:15:30 2003 @@ -1,6 +1,43 @@ from pypy.objspace.std.objspace import * +from usertype import W_UserType +import typeobject class W_UserObject(W_Object): - pass + delegate_once = {} + def __init__(w_self, space, w_type): + W_Object.__init__(w_self, space) + w_self.w_type = w_type + w_self.w_dict = space.newdict([]) + + +def user_type(space, w_userobj): + return w_userobj.w_type + +StdObjSpace.type.register(user_type, W_UserObject) + + +def user_getattr(space, w_userobj, w_attr): + try: + w_value = space.getitem(w_userobj.w_dict, w_attr) + except OperationError, e: + # catch KeyErrors + if not e.match(space, space.w_KeyError): + raise + raise FailedToImplement(space.w_AttributeError) + return w_value + +StdObjSpace.getattr.register(user_getattr, W_UserObject, W_ANY) + + +def user_setattr(space, w_userobj, w_attr, w_value): + space.setitem(w_userobj.w_dict, w_attr, w_value) + +StdObjSpace.setattr.register(user_setattr, W_UserObject, W_ANY, W_ANY) + + +def user_delattr(space, w_userobj, w_attr): + space.delitem(w_userobj.w_dict, w_attr) + +StdObjSpace.delattr.register(user_delattr, W_UserObject, W_ANY) Added: pypy/trunk/src/pypy/objspace/std/usertype.py ============================================================================== --- (empty file) +++ pypy/trunk/src/pypy/objspace/std/usertype.py Fri May 30 19:15:30 2003 @@ -0,0 +1,36 @@ +from pypy.objspace.std.objspace import * +from typeobject import W_TypeObject + + +class W_UserType(W_TypeObject): + + # 'typename' is an instance property here + + def __init__(w_self, space, w_name, w_bases, w_dict): + w_self.typename = space.unwrap(w_name) + W_TypeObject.__init__(w_self, space) + w_self.w_name = w_name + w_self.w_bases = w_bases + w_self.w_dict = w_dict + + def getbases(w_self, space): + return space.unpackiterable(w_self.w_bases) + + def lookup_exactly_here(w_self, space, w_key): + try: + w_value = space.getitem(w_self.w_dict, w_key) + except OperationError, e: + # catch KeyErrors and turn them into KeyErrors (real ones!) + if not e.match(space, space.w_KeyError): + raise + raise KeyError + return w_value + + +# XXX we'll worry about the __new__/__init__ distinction later +def usertype_new(space, w_usertype, w_args, w_kwds): + # XXX no __init__ support at all here + from userobject import W_UserObject + return W_UserObject(space, w_usertype) + +StdObjSpace.new.register(usertype_new, W_UserType, W_ANY, W_ANY) From tomek at codespeak.net Fri May 30 20:28:40 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Fri, 30 May 2003 20:28:40 +0200 (MEST) Subject: [pypy-svn] rev 739 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030530182840.0D4805A23B@thoth.codespeak.net> Author: tomek Date: Fri May 30 20:28:38 2003 New Revision: 739 Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py pypy/trunk/src/pypy/objspace/std/stringtype.py Log: small changes... Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Fri May 30 20:28:38 2003 @@ -30,56 +30,56 @@ def hash(w_self): return W_IntObject(self, self._value.hash()) - def _char_isspace(ch): - return ord(ch) in (9, 10, 11, 12, 13, 32) +def _isspace(ch): + return ord(ch) in (9, 10, 11, 12, 13, 32) - def is_generic(w_self, fun): - space = w_self.space - v = w_self._value - if v.len == 0: - return space.w_False - if v.len == 1: - c = v.charat(0) - return space.newbool(fun(c)) - else: - res = 1 - for idx in range(v.len): - if not fun(v.charat(idx)): - return space.w_False - return space.w_True +def _isdigit(ch): + o = ord(ch) + return o >= 48 and o <= 57 + +def _isalpha(ch): + o = ord(ch) + return (o>=97 and o<=122) or (o>=65 and o<=90) + +def _isalnum(ch): + o = ord(ch) + return (o>=97 and o<=122) \ + or (o>=65 and o<=90) \ + or (o>=48 and o<=57) + + +def _is_generic(w_self, fun): + space = w_self.space + v = w_self._value + if v.len == 0: + return space.w_False + if v.len == 1: + c = v.charat(0) + return space.newbool(fun(c)) + else: + res = 1 + for idx in range(v.len): + if not fun(v.charat(idx)): + return space.w_False + return space.w_True + +def str_isspace(space, w_self): + return _is_generic(w_self, _isspace) - def isspace(w_self): - return is_generic(w_self, _char_isspace) - ## XXX fixme - -## def isdigit(w_self): -## pass - -## def isupper(w_self): -## pass - -## def isupper(w_self): -## pass - -## def islower(w_self): -## pass - -## def istitle(w_self): -## pass - -## def isalnum(w_self): -## pass - -## def isalpha(w_self): -## pass - -## isspace = implmethod().register(isspace) -## isdigit = implmethod().register(isdigit) -## isupper = implmethod().register(isupper) -## islower = implmethod().register(islower) -## istitle = implmethod().register(istitle) -## isalnum = implmethod().register(isalnum) -## isalpha = implmethod().register(isalpha) +def str_isdigit(space, w_self): + return _is_generic(w_self, _isdigit) + +def str_isalpha(space, w_self): + return _is_generic(w_self, _isalpha) + +def str_isalnum(space, w_self): + return _is_generic(w_self, _isalnum) + +def str_isupper(space, w_self): + return _is_generic(w_self, _isupper) + +def str_islower(space, w_self): + return _is_generic(w_self, _islower) def str_splitByWhitespace(space, w_self, w_none): @@ -124,6 +124,9 @@ #the same number of parameters. So you have to call split with #None as parameter instead of calling it without any parameter +W_StringType.str_isspace.register(str_isspace, W_StringObject) +W_StringType.str_isdigit.register(str_isdigit, W_StringObject) + def str_join(space, w_self, w_list): list = space.unpackiterable(w_list) Modified: pypy/trunk/src/pypy/objspace/std/stringtype.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringtype.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringtype.py Fri May 30 20:28:38 2003 @@ -1,4 +1,4 @@ -from pypy.objspace.std.objspace import * +from pypy.objspace.std.objspace import MultiMethod, StdObjSpace, W_ANY from typeobject import W_TypeObject @@ -6,9 +6,16 @@ typename = 'str' - str_join = MultiMethod('join', 2) - str_split = MultiMethod('split', 2) + str_join = MultiMethod('join', 2) + str_split = MultiMethod('split', 2) + str_isdigit = MultiMethod('isdigit', 1) + str_isalpha = MultiMethod('isalpha', 1) + str_isspace = MultiMethod('isspace', 1) + str_isupper = MultiMethod('isupper', 1) + str_islower = MultiMethod('islower', 1) + str_istitle = MultiMethod('istitle', 1) + str_isalnum = MultiMethod('isalnum', 1) # XXX we'll worry about the __new__/__init__ distinction later def stringtype_new(space, w_stringtype, w_args, w_kwds): From arigo at codespeak.net Fri May 30 20:39:49 2003 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 30 May 2003 20:39:49 +0200 (MEST) Subject: [pypy-svn] rev 740 - in pypy/trunk/src/pypy: interpreter objspace/std Message-ID: <20030530183949.2CADA5A23B@thoth.codespeak.net> Author: arigo Date: Fri May 30 20:39:48 2003 New Revision: 740 Modified: pypy/trunk/src/pypy/interpreter/opcode.py pypy/trunk/src/pypy/interpreter/opcode_app.py pypy/trunk/src/pypy/objspace/std/usertype.py (props changed) Log: enabled 'class' keyword Modified: pypy/trunk/src/pypy/interpreter/opcode.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/opcode.py (original) +++ pypy/trunk/src/pypy/interpreter/opcode.py Fri May 30 20:39:48 2003 @@ -314,8 +314,9 @@ w_methodsdict = f.valuestack.pop() w_bases = f.valuestack.pop() w_name = f.valuestack.pop() - w_newclass = f.space.gethelper(appfile).call( - "build_class", [w_methodsdict, w_bases, w_name]) + w_metaclass = f.space.w_type # XXX do the correct thing here + w_newclass = f.space.call_function(w_metaclass, + w_name, w_bases, w_methodsdict) f.valuestack.push(w_newclass) def STORE_NAME(f, varindex): Modified: pypy/trunk/src/pypy/interpreter/opcode_app.py ============================================================================== --- pypy/trunk/src/pypy/interpreter/opcode_app.py (original) +++ pypy/trunk/src/pypy/interpreter/opcode_app.py Fri May 30 20:39:48 2003 @@ -30,10 +30,6 @@ "strings (deprecated), not %s"%(type(etype).__name__,) return etype, value, traceback -def build_class(methods, bases, name): - import new - return new.classobj(name, bases, methods) - def print_expr(x): import sys try: From tomek at codespeak.net Fri May 30 21:04:39 2003 From: tomek at codespeak.net (tomek at codespeak.net) Date: Fri, 30 May 2003 21:04:39 +0200 (MEST) Subject: [pypy-svn] rev 741 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030530190439.AEAFF5A23B@thoth.codespeak.net> Author: tomek Date: Fri May 30 21:04:39 2003 New Revision: 741 Modified: pypy/trunk/src/pypy/objspace/std/boolobject.py pypy/trunk/src/pypy/objspace/std/stringobject.py Log: ok Modified: pypy/trunk/src/pypy/objspace/std/boolobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/boolobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/boolobject.py Fri May 30 21:04:39 2003 @@ -17,7 +17,7 @@ return (isinstance(w_other, W_BoolObject) and w_self.boolval == w_other.boolval) - def __nonzero__(self): + def __nonzero__(w_self): raise Exception, "you cannot do that, you must use space.is_true()" Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/stringobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/stringobject.py Fri May 30 21:04:39 2003 @@ -46,6 +46,13 @@ return (o>=97 and o<=122) \ or (o>=65 and o<=90) \ or (o>=48 and o<=57) +def _isupper(ch): + o = ord(ch) + return (o>=65 and o<=90) + +def _islower(ch): + o = ord(ch) + return (o>=97 and o<=122) def _is_generic(w_self, fun): @@ -81,6 +88,8 @@ def str_islower(space, w_self): return _is_generic(w_self, _islower) +def str_istitle(space, w_self): + pass def str_splitByWhitespace(space, w_self, w_none): res = [] @@ -126,7 +135,11 @@ W_StringType.str_isspace.register(str_isspace, W_StringObject) W_StringType.str_isdigit.register(str_isdigit, W_StringObject) - +W_StringType.str_isalpha.register(str_isalpha, W_StringObject) +W_StringType.str_isupper.register(str_isupper, W_StringObject) +W_StringType.str_islower.register(str_islower, W_StringObject) +W_StringType.str_istitle.register(str_istitle, W_StringObject) +W_StringType.str_isalnum.register(str_isalnum, W_StringObject) def str_join(space, w_self, w_list): list = space.unpackiterable(w_list) From mwh at codespeak.net Fri May 30 23:51:40 2003 From: mwh at codespeak.net (mwh at codespeak.net) Date: Fri, 30 May 2003 23:51:40 +0200 (MEST) Subject: [pypy-svn] rev 742 - pypy/trunk/src/pypy/objspace/std Message-ID: <20030530215140.066D95A23B@thoth.codespeak.net> Author: mwh Date: Fri May 30 23:51:39 2003 New Revision: 742 Modified: pypy/trunk/src/pypy/objspace/std/listobject.py Log: implement list_repr (caveat emptor: I am not entirely sober). Modified: pypy/trunk/src/pypy/objspace/std/listobject.py ============================================================================== --- pypy/trunk/src/pypy/objspace/std/listobject.py (original) +++ pypy/trunk/src/pypy/objspace/std/listobject.py Fri May 30 23:51:39 2003 @@ -196,6 +196,17 @@ StdObjSpace.setitem.register(setitem_list_slice, W_ListObject, W_SliceObject, W_ListObject) +def repr_list(space, w_list): + w = space.wrap + a = space.add + reprs_w = map(space.repr, space.unpackiterable(w_list)) + from pypy.objspace.std.stringtype import W_StringType + w_bm = space.getattr(space.wrap(', '), space.wrap('join')) + return a(a(w('['), space.call_function(w_bm, space.newlist(reprs_w))), w(']')) + return space.newstring([]) + +StdObjSpace.repr.register(repr_list, W_ListObject) + # adapted C code def _roundupsize(n): nbits = r_uint(0) From lac at codespeak.net Fri May 30 23:52:20 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Fri, 30 May 2003 23:52:20 +0200 (MEST) Subject: [pypy-svn] rev 743 - pypy/trunk/src/goals Message-ID: <20030530215220.9D3FB5A23B@thoth.codespeak.net> Author: lac Date: Fri May 30 23:52:20 2003 New Revision: 743 Added: pypy/trunk/src/goals/foodbill.py Log: Acid test. can we compute our own food bill for Gothenburg Sprint! :-) Added: pypy/trunk/src/goals/foodbill.py ============================================================================== --- (empty file) +++ pypy/trunk/src/goals/foodbill.py Fri May 30 23:52:20 2003 @@ -0,0 +1,52 @@ +slips=[(1, 'Kals MatMarkn', 6150, 'Chutney for Curry', 'dinner Saturday'), + (2, 'Kals MatMarkn', 32000, 'Spaghetti, Beer', 'dinner Monday'), + (2, 'Kals MatMarkn', -810, 'Deposit on Beer Bottles', 'various'), + (3, 'Fram', 7700, 'Rice and Curry Spice', 'dinner Saturday'), + (4, 'Kals MatMarkn', 25000, 'Alcohol-Free Beer, sundries', 'various'), + (4, 'Kals MatMarkn', -1570, "Michael's toothpaste", 'none'), + (4, 'Kals MatMarkn', -1690, "Laura's toothpaste", 'none'), + (4, 'Kals MatMarkn', -720, 'Deposit on Beer Bottles', 'various'), + (4, 'Kals MatMarkn', -60, 'Deposit on another Beer Bottle', 'various'), + (5, 'Kals MatMarkn', 26750, 'lunch bread meat cheese', 'lunch Monday'), + (6, 'Kals MatMarkn', 15950, 'various', 'dinner Tuesday and Thursday'), + (7, 'Kals MatMarkn', 3650, 'Drottningsylt, etc.', 'dinner Thursday'), + (8, 'Kals MatMarkn', 26150, 'Chicken and Mushroom Sauce', 'dinner Wed'), + (8, 'Kals MatMarkn', -2490, 'Jacob and Laura -- juice', 'dinner Wed'), + (8, 'Kals MatMarkn', -2990, "Chicken we didn't cook", 'dinner Wednesday'), + (9, 'Kals MatMarkn', 1380, 'fruit for Curry', 'dinner Saturday'), + (9, 'Kals MatMarkn', 1380, 'fruit for Curry', 'dinner Saturday'), + (10, 'Kals MatMarkn', 26900, 'Jansons Frestelse', 'dinner Sunday'), + (10, 'Kals MatMarkn', -540, 'Deposit on Beer Bottles', 'dinner Sunday'), + (11, 'Kals MatMarkn', 22650, 'lunch bread meat cheese', 'lunch Thursday'), + (11, 'Kals MatMarkn', -2190, 'Jacob and Laura -- juice', 'lunch Thursday'), + (11, 'Kals MatMarkn', -2790, 'Jacob and Laura -- cereal', 'lunch Thurs'), + (11, 'Kals MatMarkn', -760, 'Jacob and Laura -- milk', 'lunch Thursday'), + (12, 'Kals MatMarkn', 18850, 'lunch bread meat cheese', 'lunch Friday'), + (13, 'Kals MatMarkn', 18850, 'lunch bread meat cheese', 'guestimate Sun'), + (14, 'Kals MatMarkn', 18850, 'lunch bread meat cheese', 'guestimate Tues'), + (15, 'Kals MatMarkn', 20000, 'lunch bread meat cheese', 'guestimate Wed'), + (16, 'Kals MatMarkn', 42050, 'grillfest', 'dinner Friday'), + (16, 'Kals MatMarkn', -1350, 'Deposit on Beer Bottles', 'dinner Friday'), + (17, 'System Bolaget', 15500, 'Cederlunds Caloric', 'dinner Thursday'), + (17, 'System Bolaget', 9800, '2 x Saint Paulin 49SEK', 'various'), + (17, 'System Bolaget', 22400, '4 x Farnese Sangiovese 56SEK', 'various'), + (17, 'System Bolaget', 22400, '4 x Farnese Sangiovese 56SEK', 'various'), + (17, 'System Bolaget', 13800, '2 x Jacobs Creek 69SEK', 'various'), + (18, 'J and Ls winecabinet', 10800, '2 x Parrotes 54SEK', 'various'), + (18, 'J and Ls winecabinet', 14700, '3 x Saint Paulin 49SEK', 'various'), + (18, 'J and Ls winecabinet', 10400, '2 x Farnese Sangioves 52SEK', + 'cheaper when we bought it'), + (18, 'J and Ls winecabinet', 17800, '2 x Le Poiane 89SEK', 'various'), + (18, 'J and Ls winecabinet', 9800, '2 x Something Else 49SEK', 'various'), + (19, 'Konsum', 26000, 'Saturday Bread and Fruit', 'Slip MISSING'), + (20, 'Konsum', 15245, 'Mooseburgers', 'found slip'), + (21, 'Kals MatMarkn', 20650, 'Grilling', 'Friday dinner'), + (22, 'J and Ls freezer', 21000, 'Meat for Curry, grilling', ''), + (22, 'J and Ls cupboard', 3000, 'Rice', ''), + (22, 'J and Ls cupboard', 4000, 'Charcoal', ''), + (23, 'Fram', 2975, 'Potatoes', '3.5 kg @ 8.50SEK'), + (23, 'Fram', 1421, 'Peas', 'Thursday dinner') + ] + +print [t[2] for t in slips] +print (reduce(lambda x, y: x+y, [t[2] for t in slips], 0))/900 From lac at codespeak.net Sat May 31 08:55:32 2003 From: lac at codespeak.net (lac at codespeak.net) Date: Sat, 31 May 2003 08:55:32 +0200 (MEST) Subject: [pypy-svn] rev 744 - pypy/trunk/src/goals Message-ID: <20030531065532.5BA3B5A23B@thoth.codespeak.net> Author: lac Date: Sat May 31 08:55:31 2003 New Revision: 744 Modified: pypy/trunk/src/goals/foodbill.py Log: Delete entry for wine we did not drink, add meat we did. Modified: pypy/trunk/src/goals/foodbill.py ============================================================================== --- pypy/trunk/src/goals/foodbill.py (original) +++ pypy/trunk/src/goals/foodbill.py Sat May 31 08:55:31 2003 @@ -28,7 +28,6 @@ (16, 'Kals MatMarkn', 42050, 'grillfest', 'dinner Friday'), (16, 'Kals MatMarkn', -1350, 'Deposit on Beer Bottles', 'dinner Friday'), (17, 'System Bolaget', 15500, 'Cederlunds Caloric', 'dinner Thursday'), - (17, 'System Bolaget', 9800, '2 x Saint Paulin 49SEK', 'various'), (17, 'System Bolaget', 22400, '4 x Farnese Sangiovese 56SEK', 'various'), (17, 'System Bolaget', 22400, '4 x Farnese Sangiovese 56SEK', 'various'), (17, 'System Bolaget', 13800, '2 x Jacobs Creek 69SEK', 'various'), @@ -45,7 +44,10 @@ (22, 'J and Ls cupboard', 3000, 'Rice', ''), (22, 'J and Ls cupboard', 4000, 'Charcoal', ''), (23, 'Fram', 2975, 'Potatoes', '3.5 kg @ 8.50SEK'), - (23, 'Fram', 1421, 'Peas', 'Thursday dinner') + (23, 'Fram', 1421, 'Peas', 'Thursday dinner'), + (24, 'Kals MatMarkn', 20650, 'Grilling', 'Friday dinner'), + (24, 'Kals MatMarkn', -2990, 'TP', 'None'), + (24, 'Kals MatMarkn', -2320, 'T-Gul', 'None') ] print [t[2] for t in slips]