From antocuni at codespeak.net Thu May 1 11:38:50 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Thu, 1 May 2008 11:38:50 +0200 (CEST) Subject: [pypy-svn] r54301 - in pypy/branch/oo-jit/pypy/jit: rainbow rainbow/test timeshifter Message-ID: <20080501093850.E579E2A01B2@codespeak.net> Author: antocuni Date: Thu May 1 11:38:48 2008 New Revision: 54301 Modified: pypy/branch/oo-jit/pypy/jit/rainbow/test/test_llinterp.py pypy/branch/oo-jit/pypy/jit/rainbow/typesystem.py pypy/branch/oo-jit/pypy/jit/timeshifter/rtimeshift.py Log: more translation fixes Modified: pypy/branch/oo-jit/pypy/jit/rainbow/test/test_llinterp.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/rainbow/test/test_llinterp.py (original) +++ pypy/branch/oo-jit/pypy/jit/rainbow/test/test_llinterp.py Thu May 1 11:38:48 2008 @@ -12,6 +12,14 @@ # for the individual tests see # ====> test_portal.py + def skip(self): + py.test.skip('in progress') + + test_dfa_compile = skip + test_dfa_compile2 = skip + test_dfa_compile3 = skip + + class TestLLInterpretedLLType(test_portal.TestPortalLLType): translate_support_code = True Modified: pypy/branch/oo-jit/pypy/jit/rainbow/typesystem.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/rainbow/typesystem.py (original) +++ pypy/branch/oo-jit/pypy/jit/rainbow/typesystem.py Thu May 1 11:38:48 2008 @@ -1,4 +1,6 @@ -from pypy.rpython.annlowlevel import base_ptr_lltype +from pypy.rpython.annlowlevel import base_ptr_lltype, base_obj_ootype +from pypy.rpython.annlowlevel import cast_instance_to_base_ptr +from pypy.rpython.annlowlevel import cast_instance_to_base_obj from pypy.rpython.lltypesystem import lltype, llmemory from pypy.rpython.ootypesystem import ootype @@ -27,6 +29,7 @@ name = 'lltype' ROOT_TYPE = llmemory.Address NULL_OBJECT = base_ptr_lltype()._defl() + cast_instance_to_base_ptr = staticmethod(cast_instance_to_base_ptr) def get_typeptr(self, obj): return obj.typeptr @@ -55,7 +58,8 @@ name = 'ootype' ROOT_TYPE = ootype.Object - NULL_OBJECT = ootype.NULL + NULL_OBJECT = base_obj_ootype()._defl() + cast_instance_to_base_ptr = staticmethod(cast_instance_to_base_obj) def get_typeptr(self, obj): return obj.meta Modified: pypy/branch/oo-jit/pypy/jit/timeshifter/rtimeshift.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/timeshifter/rtimeshift.py (original) +++ pypy/branch/oo-jit/pypy/jit/timeshifter/rtimeshift.py Thu May 1 11:38:48 2008 @@ -777,10 +777,10 @@ else: return ptr -def _cast_promotion_point_to_base_ptr(instance): +def _cast_promotion_point_to_base_ptr(jitstate, instance): assert isinstance(instance, PromotionPoint) if we_are_translated(): - return cast_instance_to_base_ptr(instance) + return jitstate.ts.cast_instance_to_base_ptr(instance) else: return instance @@ -846,7 +846,7 @@ pm = PromotionPoint(flexswitch, incoming_gv, jitstate.promotion_path) #debug_print(lltype.Void, "PROMOTE") - ll_pm = _cast_promotion_point_to_base_ptr(pm) + ll_pm = _cast_promotion_point_to_base_ptr(jitstate, pm) gv_pm = default_builder.rgenop.genconst(ll_pm) gv_switchvar = promotebox.genvar exceptiondesc = promotiondesc.exceptiondesc @@ -1282,7 +1282,7 @@ setexcvaluebox(self, evaluebox) def residual_exception(self, e): - self.residual_ll_exception(cast_instance_to_base_ptr(e)) + self.residual_ll_exception(self.ts.cast_instance_to_base_ptr(e)) def get_resuming(self): if self.frame.dispatchqueue is None: From docgok at codespeak.net Thu May 1 18:07:44 2008 From: docgok at codespeak.net (docgok at codespeak.net) Date: Thu, 1 May 2008 18:07:44 +0200 (CEST) Subject: [pypy-svn] r54308 - pypy/branch/io-improvements/pypy/translator/llvm Message-ID: <20080501160744.3D393169DFB@codespeak.net> Author: docgok Date: Thu May 1 18:07:43 2008 New Revision: 54308 Modified: pypy/branch/io-improvements/pypy/translator/llvm/opwriter.py Log: force_cast implementation for LLVM Modified: pypy/branch/io-improvements/pypy/translator/llvm/opwriter.py ============================================================================== --- pypy/branch/io-improvements/pypy/translator/llvm/opwriter.py (original) +++ pypy/branch/io-improvements/pypy/translator/llvm/opwriter.py Thu May 1 18:07:43 2008 @@ -139,6 +139,8 @@ self.cast_int_to_ptr(opr) else: self.cast_primitive(opr) + elif op.opname == 'force_cast': + self.cast_primitive(opr) else: meth = getattr(self, op.opname, None) if not meth: From bgola at codespeak.net Thu May 1 22:42:33 2008 From: bgola at codespeak.net (bgola at codespeak.net) Date: Thu, 1 May 2008 22:42:33 +0200 (CEST) Subject: [pypy-svn] r54309 - pypy/branch/2.5-features/pypy/interpreter/pyparser/data Message-ID: <20080501204233.82DE1498001@codespeak.net> Author: bgola Date: Thu May 1 22:42:31 2008 New Revision: 54309 Modified: pypy/branch/2.5-features/pypy/interpreter/pyparser/data/Grammar2.5 Log: supporting 2.5 grammar, almost working now Modified: pypy/branch/2.5-features/pypy/interpreter/pyparser/data/Grammar2.5 ============================================================================== --- pypy/branch/2.5-features/pypy/interpreter/pyparser/data/Grammar2.5 (original) +++ pypy/branch/2.5-features/pypy/interpreter/pyparser/data/Grammar2.5 Thu May 1 22:42:31 2008 @@ -62,9 +62,8 @@ raise_stmt: 'raise' [test [',' test [',' test]]] import_stmt: import_name | import_from import_name: 'import' dotted_as_names -import_from: ('from' ('.'* dotted_name | '.'+) - 'import' ('*' | '(' import_as_names ')' | import_as_names)) -import_as_name: NAME [('as' | NAME) NAME] +import_from: 'from' dotted_name 'import' ('*' | '(' import_as_names [','] ')' | import_as_names) +import_as_name: NAME [('as'|NAME) NAME] dotted_as_name: dotted_name [('as' | NAME) NAME] import_as_names: import_as_name (',' import_as_name)* [','] dotted_as_names: dotted_as_name (',' dotted_as_name)* @@ -121,7 +120,7 @@ lambdef: 'lambda' [varargslist] ':' test trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME subscriptlist: subscript (',' subscript)* [','] -subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] +subscript: '.' '.' '.' | [test] ':' [test] [sliceop] | test sliceop: ':' [test] exprlist: expr (',' expr)* [','] testlist: test (',' test)* [','] From antocuni at codespeak.net Fri May 2 12:37:34 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Fri, 2 May 2008 12:37:34 +0200 (CEST) Subject: [pypy-svn] r54316 - in pypy/branch/oo-jit/pypy/rpython/ootypesystem: . test Message-ID: <20080502103734.08CF32A805F@codespeak.net> Author: antocuni Date: Fri May 2 12:37:32 2008 New Revision: 54316 Modified: pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py Log: a hack; since pbc unbound methods are not supported in general, provide a way to build a wrapper that calls it, given the name Modified: pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py ============================================================================== --- pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py (original) +++ pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py Fri May 2 12:37:32 2008 @@ -1882,6 +1882,20 @@ ref.ll_set(obj) return ref +def build_unbound_method_wrapper(meth): + METH = typeOf(meth) + methname = meth._name + funcname = '%s_wrapper' % methname + nb_args = len(METH.ARGS) + arglist = ', '.join('a%d' % i for i in range(nb_args)) + ns = {'methname': methname} + code = py.code.Source(""" + def %s(self, %s): + m = getattr(self, methname) + return m(%s) + """ % (funcname, arglist, arglist)) + exec code.compile() in ns + return ns[funcname] Object = Object() NULL = _object(None) Modified: pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py ============================================================================== --- pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py (original) +++ pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py Fri May 2 12:37:32 2008 @@ -337,3 +337,16 @@ return oodowncast(A, c) py.test.raises(AnnotatorError, interpret, fn, [], type_system='ootype') + +def test_method_wrapper(): + L = List(Signed) + _, meth = L._lookup('ll_getitem_fast') + wrapper = build_unbound_method_wrapper(meth) + + def fn(): + lst = L.ll_newlist(1) + lst.ll_setitem_fast(0, 42) + return wrapper(lst, 0) + + res = interpret(fn, [], type_system='ootype') + assert res == 42 From antocuni at codespeak.net Fri May 2 14:01:59 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Fri, 2 May 2008 14:01:59 +0200 (CEST) Subject: [pypy-svn] r54317 - pypy/branch/oo-jit/pypy/rpython Message-ID: <20080502120159.0B6D8169E87@codespeak.net> Author: antocuni Date: Fri May 2 14:01:57 2008 New Revision: 54317 Modified: pypy/branch/oo-jit/pypy/rpython/annlowlevel.py Log: forgot to checkin this in in r54301; make cast_object_to_ptr and cast_base_ptr_to_instance ootype-friendly Modified: pypy/branch/oo-jit/pypy/rpython/annlowlevel.py ============================================================================== --- pypy/branch/oo-jit/pypy/rpython/annlowlevel.py (original) +++ pypy/branch/oo-jit/pypy/rpython/annlowlevel.py Fri May 2 14:01:57 2008 @@ -472,28 +472,51 @@ return cast_object_to_ptr(base_ptr_lltype(), instance) cast_instance_to_base_ptr._annspecialcase_ = 'specialize:argtype(0)' +def cast_instance_to_base_obj(instance): + return cast_object_to_ptr(base_obj_ootype(), instance) +cast_instance_to_base_obj._annspecialcase_ = 'specialize:argtype(0)' + def base_ptr_lltype(): from pypy.rpython.lltypesystem.rclass import OBJECTPTR return OBJECTPTR +def base_obj_ootype(): + from pypy.rpython.ootypesystem.rclass import OBJECT + return OBJECT + class CastObjectToPtrEntry(extregistry.ExtRegistryEntry): _about_ = cast_object_to_ptr def compute_result_annotation(self, s_PTR, s_object): assert s_PTR.is_constant() - assert isinstance(s_PTR.const, lltype.Ptr) - return annmodel.SomePtr(s_PTR.const) + if isinstance(s_PTR.const, lltype.Ptr): + return annmodel.SomePtr(s_PTR.const) + elif isinstance(s_PTR.const, ootype.Instance): + return annmodel.SomeOOInstance(s_PTR.const) + else: + assert False def specialize_call(self, hop): from pypy.rpython import rpbc PTR = hop.r_result.lowleveltype + if isinstance(PTR, lltype.Ptr): + T = lltype.Ptr + opname = 'cast_pointer' + null = lltype.nullptr(PTR.TO) + elif isinstance(PTR, ootype.Instance): + T = ootype.Instance + opname = 'ooupcast' + null = ootype.null(PTR) + else: + assert False + if isinstance(hop.args_r[1], rpbc.NoneFrozenPBCRepr): - return hop.inputconst(PTR, lltype.nullptr(PTR.TO)) + return hop.inputconst(PTR, null) v_arg = hop.inputarg(hop.args_r[1], arg=1) - assert isinstance(v_arg.concretetype, lltype.Ptr) + assert isinstance(v_arg.concretetype, T) hop.exception_cannot_occur() - return hop.genop('cast_pointer', [v_arg], - resulttype = PTR) + return hop.genop(opname, [v_arg], resulttype = PTR) + # ____________________________________________________________ @@ -510,13 +533,19 @@ def specialize_call(self, hop): v_arg = hop.inputarg(hop.args_r[1], arg=1) - assert isinstance(v_arg.concretetype, lltype.Ptr) + if isinstance(v_arg.concretetype, lltype.Ptr): + opname = 'cast_pointer' + elif isinstance(v_arg.concretetype, ootype.Instance): + opname = 'ooupcast' + else: + assert False hop.exception_cannot_occur() - return hop.genop('cast_pointer', [v_arg], + return hop.genop(opname, [v_arg], resulttype = hop.r_result.lowleveltype) # ____________________________________________________________ + def placeholder_sigarg(s): if s == "self": def expand(s_self, *args_s): From arigo at codespeak.net Fri May 2 15:13:08 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 2 May 2008 15:13:08 +0200 (CEST) Subject: [pypy-svn] r54323 - pypy/dist/pypy/translator/benchmark Message-ID: <20080502131308.425F0169E4C@codespeak.net> Author: arigo Date: Fri May 2 15:13:07 2008 New Revision: 54323 Modified: pypy/dist/pypy/translator/benchmark/bench-custom.py pypy/dist/pypy/translator/benchmark/result.py Log: For very long executable names, this displays the results more readably by splitting the table in two. Modified: pypy/dist/pypy/translator/benchmark/bench-custom.py ============================================================================== --- pypy/dist/pypy/translator/benchmark/bench-custom.py (original) +++ pypy/dist/pypy/translator/benchmark/bench-custom.py Fri May 2 15:13:07 2008 @@ -5,6 +5,8 @@ from pypy.translator.benchmark.benchmarks import BENCHMARKS import os, sys, time, pickle, re, py +SPLIT_TABLE = True # useful when executable names are very long + def get_executables(args): #sorted by revision number (highest first) exes = sorted(args, key=os.path.getmtime) r = [] @@ -52,17 +54,28 @@ pickle.dump(benchmark_result, open(options.picklefile, 'wb')) - stats = ['stat:st_mtime', 'exe_name', 'pypy_rev'] + exe_stats = ['stat:st_mtime', 'exe_name', 'pypy_rev'] + if not SPLIT_TABLE: + stats = exe_stats[:] + else: + stats = ['exe'] for b in benchmarks: stats.append('bench:'+b.name) if options.relto: relto = options.relto else: relto = full_pythons[0] - for row in benchmark_result.txt_summary(stats, - relto=relto, - filteron=lambda r: r.exe_name in exes): + kwds = {'relto': relto, + 'filteron' :lambda r: r.exe_name in exes, + } + for row in benchmark_result.txt_summary(stats, **kwds): print row + if SPLIT_TABLE: + print + print 'Reference:' + for row in benchmark_result.txt_summary(['exe'] + exe_stats, + **kwds): + print row if __name__ == '__main__': from optparse import OptionParser Modified: pypy/dist/pypy/translator/benchmark/result.py ============================================================================== --- pypy/dist/pypy/translator/benchmark/result.py (original) +++ pypy/dist/pypy/translator/benchmark/result.py Fri May 2 15:13:07 2008 @@ -68,6 +68,7 @@ return concretetable class BenchmarkResult(object): + IDS = {} def __init__(self, exe, max_results=10): self.max_results = max_results @@ -116,6 +117,10 @@ return_default = True if hasattr(self, stat): return getattr(self, stat) + if stat == 'exe': + myid = len(BenchmarkResult.IDS) + myid = BenchmarkResult.IDS.setdefault(self, myid) + return '[%s]' % myid statkind, statdetail = stat.split(':') if statkind == 'stat': return getattr(self.exe_stat, statdetail) From antocuni at codespeak.net Fri May 2 16:00:09 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Fri, 2 May 2008 16:00:09 +0200 (CEST) Subject: [pypy-svn] r54324 - in pypy/branch/oo-jit/pypy: annotation jit/codegen/llgraph jit/rainbow/test jit/timeshifter Message-ID: <20080502140009.C6211169ED2@codespeak.net> Author: antocuni Date: Fri May 2 16:00:08 2008 New Revision: 54324 Modified: pypy/branch/oo-jit/pypy/annotation/model.py pypy/branch/oo-jit/pypy/jit/codegen/llgraph/rgenop.py pypy/branch/oo-jit/pypy/jit/rainbow/test/test_llinterp.py pypy/branch/oo-jit/pypy/jit/timeshifter/oop.py Log: more translation fixes; skip tests that are known to fail Modified: pypy/branch/oo-jit/pypy/annotation/model.py ============================================================================== --- pypy/branch/oo-jit/pypy/annotation/model.py (original) +++ pypy/branch/oo-jit/pypy/annotation/model.py Fri May 2 16:00:08 2008 @@ -595,6 +595,8 @@ return s_val.ootype if isinstance(s_val, SomeOOStaticMeth): return s_val.method + if isinstance(s_val, SomeOOClass): + return s_val.ootype if isinstance(s_val, SomeInteriorPtr): p = s_val.ll_ptrtype if 0 in p.offsets: @@ -633,6 +635,8 @@ return SomeOOStaticMeth(T) elif T == ootype.Class: return SomeOOClass(ootype.ROOT) + elif T == ootype.Object: + return SomeOOObject() elif isinstance(T, ExternalType): return SomeExternalInstance(T._class_) elif isinstance(T, lltype.InteriorPtr): Modified: pypy/branch/oo-jit/pypy/jit/codegen/llgraph/rgenop.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/codegen/llgraph/rgenop.py (original) +++ pypy/branch/oo-jit/pypy/jit/codegen/llgraph/rgenop.py Fri May 2 16:00:08 2008 @@ -290,6 +290,11 @@ "genop_oononnull: bad currently_writing") return LLVar(llimpl.genop(self.b, 'oononnull', [gv_obj], gv_Bool.v)) + def genop_ooisnull(self, gv_obj): + ll_assert(self.rgenop.currently_writing is self, + "genop_ooisnull: bad currently_writing") + return LLVar(llimpl.genop(self.b, 'ooisnull', [gv_obj], gv_Bool.v)) + def genop_cast_int_to_ptr(self, gv_PTRTYPE, gv_int): ll_assert(self.rgenop.currently_writing is self, "genop_cast_int_to_ptr: bad currently_writing") Modified: pypy/branch/oo-jit/pypy/jit/rainbow/test/test_llinterp.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/rainbow/test/test_llinterp.py (original) +++ pypy/branch/oo-jit/pypy/jit/rainbow/test/test_llinterp.py Fri May 2 16:00:08 2008 @@ -18,6 +18,15 @@ test_dfa_compile = skip test_dfa_compile2 = skip test_dfa_compile3 = skip + test_multiple_portal_calls = skip + test_cast_ptr_to_int = skip + test_residual_red_call_with_promoted_exc = skip + test_residual_oop_raising = skip + test_simple_recursive_portal_call = skip + test_simple_recursive_portal_call2 = skip + test_recursive_portal_call = skip + test_indirect_call_voidargs = skip + test_vdict_and_vlist = skip Modified: pypy/branch/oo-jit/pypy/jit/timeshifter/oop.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/timeshifter/oop.py (original) +++ pypy/branch/oo-jit/pypy/jit/timeshifter/oop.py Fri May 2 16:00:08 2008 @@ -280,6 +280,9 @@ self.ARGS = [METH.SELFTYPE] + list(METH.ARGS) self.RESULT = METH.RESULT + wrapper = ootype.build_unbound_method_wrapper(meth) + self.fnptr = self.rtyper.annotate_helper_fn(wrapper, self.ARGS) + # we assume the number and position of the arguments are the # same as in the original oosend self.OOPARGTYPES = [self.SELFTYPE] + list(METH.ARGS) @@ -289,7 +292,6 @@ methname = methname.lstrip('ll_') self.method = 'oop_%s_method_%s' % (self.typename, methname) self.is_method = True - self.fnptr = meth class SendOopSpecDesc_list(SendOopSpecDesc): From antocuni at codespeak.net Fri May 2 16:18:51 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Fri, 2 May 2008 16:18:51 +0200 (CEST) Subject: [pypy-svn] r54325 - pypy/branch/oo-jit/pypy/translator/goal Message-ID: <20080502141851.C757B169EEF@codespeak.net> Author: antocuni Date: Fri May 2 16:18:51 2008 New Revision: 54325 Modified: pypy/branch/oo-jit/pypy/translator/goal/timing.py Log: don't crash on error because of missing tk attribute Modified: pypy/branch/oo-jit/pypy/translator/goal/timing.py ============================================================================== --- pypy/branch/oo-jit/pypy/translator/goal/timing.py (original) +++ pypy/branch/oo-jit/pypy/translator/goal/timing.py Fri May 2 16:18:51 2008 @@ -15,6 +15,7 @@ self.next_even = None self.timer = timer self.t0 = None + self.tk = None def start_event(self, event): now = self.timer() @@ -31,6 +32,8 @@ self.tk = now def ttime(self): + if self.tk is None: + return -1 return self.tk - self.t0 def pprint(self): From arigo at codespeak.net Fri May 2 16:49:48 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 2 May 2008 16:49:48 +0200 (CEST) Subject: [pypy-svn] r54326 - pypy/dist/pypy/config Message-ID: <20080502144948.9205D169EF4@codespeak.net> Author: arigo Date: Fri May 2 16:49:46 2008 New Revision: 54326 Modified: pypy/dist/pypy/config/pypyoption.py Log: Reintroduce for now optimized_list_getitem in faassen, because it still helps a bit. Modified: pypy/dist/pypy/config/pypyoption.py ============================================================================== --- pypy/dist/pypy/config/pypyoption.py (original) +++ pypy/dist/pypy/config/pypyoption.py Fri May 2 16:49:46 2008 @@ -315,6 +315,7 @@ # ("objspace.std.withfastslice", True), ("objspace.std.withprebuiltchar", True), ("objspace.std.builtinshortcut", True), + ("objspace.std.optimized_list_getitem", True), ("objspace.std.getattributeshortcut", True), ("translation.list_comprehension_operations",True), ], From arigo at codespeak.net Fri May 2 20:05:02 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 2 May 2008 20:05:02 +0200 (CEST) Subject: [pypy-svn] r54347 - in pypy/dist/pypy/objspace/std: . test Message-ID: <20080502180502.1CE6E169E6E@codespeak.net> Author: arigo Date: Fri May 2 20:05:02 2008 New Revision: 54347 Modified: pypy/dist/pypy/objspace/std/objecttype.py pypy/dist/pypy/objspace/std/test/test_userobject.py Log: Fix object.__repr__() to show the class' module name, as in CPython. Modified: pypy/dist/pypy/objspace/std/objecttype.py ============================================================================== --- pypy/dist/pypy/objspace/std/objecttype.py (original) +++ pypy/dist/pypy/objspace/std/objecttype.py Fri May 2 20:05:02 2008 @@ -9,7 +9,17 @@ def descr__repr__(space, w_obj): w = space.wrap - classname = space.str_w(space.getattr(space.type(w_obj), w("__name__"))) + w_type = space.type(w_obj) + classname = w_type.getname(space, '?') + w_module = w_type.lookup("__module__") + if w_module is not None: + try: + modulename = space.str_w(w_module) + except OperationError, e: + if not e.match(space, space.w_TypeError): + raise + else: + classname = '%s.%s' % (modulename, classname) return w_obj.getrepr(space, '%s object' % (classname,)) def descr__str__(space, w_obj): Modified: pypy/dist/pypy/objspace/std/test/test_userobject.py ============================================================================== --- pypy/dist/pypy/objspace/std/test/test_userobject.py (original) +++ pypy/dist/pypy/objspace/std/test/test_userobject.py Fri May 2 20:05:02 2008 @@ -200,6 +200,13 @@ assert myint(3) - 5 == -2 assert 5 - myint(3) == 'rsub' + def test_repr(self): + class Foo(object): + pass + Foo.__module__ = 'a.b.c' + s = repr(Foo()) + assert s.startswith(' Author: bgola Date: Sat May 3 00:38:21 2008 New Revision: 54356 Added: pypy/branch/2.5-features/pypy/lib/app_test/test_defaultdict.py (contents, props changed) Modified: pypy/branch/2.5-features/pypy/lib/collections.py Log: defaultdict implementation in collections module Added: pypy/branch/2.5-features/pypy/lib/app_test/test_defaultdict.py ============================================================================== --- (empty file) +++ pypy/branch/2.5-features/pypy/lib/app_test/test_defaultdict.py Sat May 3 00:38:21 2008 @@ -0,0 +1,110 @@ +# defaultdict Tests +# from CPython2.5 + +import copy + +# for passing the test on top of 2.3 +from py.builtin import reversed +import pypy.lib.collections +pypy.lib.collections.reversed = reversed + +from pypy.lib.collections import defaultdict + +def foobar(): + return list + +class Test_defaultdict: + + def test_basic(self): + d1 = defaultdict() + assert d1.default_factory is None + d1.default_factory = list + d1[12].append(42) + assert d1 == {12: [42]} + d1[12].append(24) + assert d1 == {12: [42, 24]} + d1[13] + d1[14] + assert d1 == {12: [42, 24], 13: [], 14: []} + assert d1[12] is not d1[13] is not d1[14] + d2 = defaultdict(list, foo=1, bar=2) + assert d2.default_factory == list + assert d2 == {"foo": 1, "bar": 2} + assert d2["foo"] == 1 + assert d2["bar"] == 2 + assert d2[42] == [] + assert "foo" in d2 + assert "foo" in d2.keys() + assert "bar" in d2 + assert "bar" in d2.keys() + assert 42 in d2 + assert 42 in d2.keys() + assert 12 not in d2 + assert 12 not in d2.keys() + d2.default_factory = None + assert d2.default_factory == None + raises(KeyError, d2.__getitem__, 15) + raises(TypeError, defaultdict, 1) + + def test_missing(self): + d1 = defaultdict() + raises(KeyError, d1.__missing__, 42) + d1.default_factory = list + assert d1.__missing__(42) == [] + + def test_repr(self): + d1 = defaultdict() + assert d1.default_factory == None + assert repr(d1) == "defaultdict(None, {})" + d1[11] = 41 + assert repr(d1) == "defaultdict(None, {11: 41})" + d2 = defaultdict(int) + assert d2.default_factory == int + d2[12] = 42 + assert repr(d2), "defaultdict(, {12: 42})" + def foo(): return 43 + d3 = defaultdict(foo) + assert d3.default_factory is foo + d3[13] + assert repr(d3), "defaultdict(%s, {13: 43})" % repr(foo) + + def test_copy(self): + d1 = defaultdict() + d2 = d1.copy() + assert type(d2) == defaultdict + assert d2.default_factory == None + assert d2 == {} + d1.default_factory = list + d3 = d1.copy() + assert type(d3) == defaultdict + assert d3.default_factory == list + assert d3 == {} + d1[42] + d4 = d1.copy() + assert type(d4) == defaultdict + assert d4.default_factory == list + assert d4 == {42: []} + d4[12] + assert d4 == {42: [], 12: []} + + def test_shallow_copy(self): + d1 = defaultdict(foobar, {1: 1}) + d2 = copy.copy(d1) + assert d2.default_factory == foobar + assert d2 == d1 + d1.default_factory = list + d2 = copy.copy(d1) + assert d2.default_factory == list + assert d2 == d1 + + def test_deep_copy(self): + d1 = defaultdict(foobar, {1: [1]}) + d2 = copy.deepcopy(d1) + assert d2.default_factory == foobar + assert d2 == d1 + assert d1[1] is not d2[1] + d1.default_factory = list + d2 = copy.deepcopy(d1) + assert d2.default_factory == list + assert d2 == d1 + Modified: pypy/branch/2.5-features/pypy/lib/collections.py ============================================================================== --- pypy/branch/2.5-features/pypy/lib/collections.py (original) +++ pypy/branch/2.5-features/pypy/lib/collections.py Sat May 3 00:38:21 2008 @@ -308,4 +308,45 @@ def __len__(self): return self.counter - + +class defaultdict(dict): + + def __init__(self, *args, **kwds): + self.default_factory = None + if 'default_factory' in kwds: + self.default_factory = kwds.pop('default_factory') + elif len(args) > 0 and callable(args[0]): + self.default_factory = args[0] + args = args[1:] + super(defaultdict, self).__init__(*args, **kwds) + + def __missing__(self, key): + # from defaultdict docs + if self.default_factory is None: + raise KeyError((key,)) + self[key] = value = self.default_factory() + return value + + def __repr__(self): + return "defaultdict(%s, %s)" % (repr(self.default_factory), super(defaultdict, self).__repr__()) + + def copy(self): + return type(self)(self, default_factory=self.default_factory) + + def __copy__(self): + return self.copy() + + def __reduce__(self): + """ + __reduce__ must return a 5-tuple as follows: + + - factory function + - tuple of args for the factory function + - additional state (here None) + - sequence iterator (here None) + - dictionary iterator (yielding successive (key, value) pairs + + This API is used by pickle.py and copy.py. + """ + return (type(self), (self.default_factory,), None, None, self.iteritems()) + From antocuni at codespeak.net Sat May 3 15:36:12 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 3 May 2008 15:36:12 +0200 (CEST) Subject: [pypy-svn] r54362 - pypy/branch/oo-jit/pypy/jit/rainbow Message-ID: <20080503133612.AC6D716856A@codespeak.net> Author: antocuni Date: Sat May 3 15:36:10 2008 New Revision: 54362 Modified: pypy/branch/oo-jit/pypy/jit/rainbow/codewriter.py Log: remove the (hopefully) last direct references to lltype from codewriter Modified: pypy/branch/oo-jit/pypy/jit/rainbow/codewriter.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/rainbow/codewriter.py (original) +++ pypy/branch/oo-jit/pypy/jit/rainbow/codewriter.py Sat May 3 15:36:10 2008 @@ -368,17 +368,17 @@ def make_own_call_information(self, graph): ARGS = [v.concretetype for v in graph.getargs()] RESULT = graph.getreturnvar().concretetype - FUNCTYPE = lltype.FuncType(ARGS, RESULT) + FUNCTYPE = self.FuncType(ARGS, RESULT) colororder = make_colororder(graph, self.hannotator) owncalldesc = CallDesc(self.RGenOp, self.exceptiondesc, - lltype.Ptr(FUNCTYPE), colororder) + self.Ptr(FUNCTYPE), colororder) # detect the special ts_stub or ts_metacall graphs and replace # a real function pointer to them with a function pointer to # the graph they are stubs for if hasattr(graph, 'ts_stub_for'): graph = graph.ts_stub_for - ownfnptr = lltype.functionptr(FUNCTYPE, graph.name, graph=graph) + ownfnptr = self.functionptr(FUNCTYPE, graph.name, graph=graph) gv_ownfnptr = self.RGenOp.constPrebuiltGlobal(ownfnptr) return owncalldesc, gv_ownfnptr @@ -1635,6 +1635,9 @@ ExceptionDesc = exception.LLTypeExceptionDesc StructTypeDesc = rcontainer.StructTypeDesc + FuncType = staticmethod(lltype.FuncType) + Ptr = staticmethod(lltype.Ptr) + functionptr = staticmethod(lltype.functionptr) def cast_fnptr_to_root(self, fnptr): return llmemory.cast_ptr_to_adr(fnptr) @@ -1672,7 +1675,10 @@ ExceptionDesc = exception.OOTypeExceptionDesc StructTypeDesc = rcontainer.InstanceTypeDesc - + FuncType = staticmethod(ootype.StaticMethod) + Ptr = staticmethod(lambda x: x) + functionptr = staticmethod(ootype.static_meth) + def decompose_oosend(self, op): name = op.args[0].value opargs = op.args[1:] From antocuni at codespeak.net Sat May 3 15:46:10 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 3 May 2008 15:46:10 +0200 (CEST) Subject: [pypy-svn] r54366 - in pypy/branch/oo-jit/pypy: config translator translator/test Message-ID: <20080503134610.5F361168521@codespeak.net> Author: antocuni Date: Sat May 3 15:46:09 2008 New Revision: 54366 Modified: pypy/branch/oo-jit/pypy/config/translationoption.py pypy/branch/oo-jit/pypy/translator/driver.py pypy/branch/oo-jit/pypy/translator/test/test_driver.py Log: add the relevant tasks to driver to do --jit on ootype; fix test_driver Modified: pypy/branch/oo-jit/pypy/config/translationoption.py ============================================================================== --- pypy/branch/oo-jit/pypy/config/translationoption.py (original) +++ pypy/branch/oo-jit/pypy/config/translationoption.py Sat May 3 15:46:09 2008 @@ -31,13 +31,14 @@ "llvm": [("translation.type_system", "lltype"), ("translation.backendopt.raisingop2direct_call", True), ], - "cli": [("translation.type_system", "ootype")], + "cli": [("translation.type_system", "ootype"), + ("translation.jitbackend", "cli")], "jvm": [("translation.type_system", "ootype")], "js": [("translation.type_system", "ootype")], }, cmdline="-b --backend"), ChoiceOption("jitbackend", "Backent to use for JIT code generation", - ["ia32", "i386", "ppc"], cmdline="--jit-backend", + ["ia32", "i386", "ppc", "cli"], cmdline="--jit-backend", default=None), BoolOption("llvm_via_c", "compile llvm via C", default=False, cmdline="--llvm-via-c", Modified: pypy/branch/oo-jit/pypy/translator/driver.py ============================================================================== --- pypy/branch/oo-jit/pypy/translator/driver.py (original) +++ pypy/branch/oo-jit/pypy/translator/driver.py Sat May 3 15:46:09 2008 @@ -378,6 +378,14 @@ [RTYPE], "Backendopt before Hint-annotate") + def task_prehannotatebackendopt_ootype(self): + self.task_prehannotatebackendopt_lltype() + # + task_prehannotatebackendopt_ootype = taskdef( + task_prehannotatebackendopt_ootype, + [OOTYPE], + "Backendopt before Hint-annotate") + def task_hintannotate_lltype(self): from pypy.jit.hintannotator.model import OriginFlags from pypy.jit.hintannotator.model import SomeLLAbstractConstant @@ -416,30 +424,19 @@ ['prehannotatebackendopt_lltype'], "Hint-annotate") - def task_rainbow_lltype(self): - cpu = self.config.translation.jitbackend - if cpu is None: - from pypy.jit.codegen import detect_cpu - cpu = detect_cpu.autodetect() - if cpu == 'i386': - from pypy.jit.codegen.i386.rgenop import RI386GenOp as RGenOp - RGenOp.MC_SIZE = 32 * 1024 * 1024 - elif cpu == 'ia32': - from pypy.jit.codegen.ia32.rgenop import RI386GenOp as RGenOp - RGenOp.MC_SIZE = 32 * 1024 * 1024 - elif cpu == 'ppc': - from pypy.jit.codegen.ppc.rgenop import RPPCGenOp as RGenOp - RGenOp.MC_SIZE = 32 * 1024 * 1024 - else: - raise Exception('Unsuported cpu %r'%cpu) + def task_hintannotate_ootype(self): + self.task_hintannotate_lltype() + task_hintannotate_ootype = taskdef(task_hintannotate_ootype, + ['prehannotatebackendopt_ootype'], + "Hint-annotate") + def do_task_rainbow(self, RGenOp, BytecodeWriter): del self.hint_translator ha = self.hannotator t = self.translator rtyper = t.rtyper # make the bytecode and the rainbow interp - from pypy.jit.rainbow.codewriter import LLTypeBytecodeWriter - writer = LLTypeBytecodeWriter(t, ha, RGenOp, verbose=False) + writer = BytecodeWriter(t, ha, RGenOp, verbose=False) jitcode = writer.make_bytecode(self.portal_graph) if ha.policy.hotpath: from pypy.jit.rainbow.hotpath import HotRunnerDesc @@ -459,11 +456,40 @@ rewriter.rewrite(origportalgraph=self.orig_portal_graph, portalgraph=self.portal_graph, view=False) + + def task_rainbow_lltype(self): + from pypy.jit.rainbow.codewriter import LLTypeBytecodeWriter + cpu = self.config.translation.jitbackend + if cpu is None: + from pypy.jit.codegen import detect_cpu + cpu = detect_cpu.autodetect() + if cpu == 'i386': + from pypy.jit.codegen.i386.rgenop import RI386GenOp as RGenOp + RGenOp.MC_SIZE = 32 * 1024 * 1024 + elif cpu == 'ia32': + from pypy.jit.codegen.ia32.rgenop import RI386GenOp as RGenOp + RGenOp.MC_SIZE = 32 * 1024 * 1024 + elif cpu == 'ppc': + from pypy.jit.codegen.ppc.rgenop import RPPCGenOp as RGenOp + RGenOp.MC_SIZE = 32 * 1024 * 1024 + else: + raise Exception('Unsuported cpu %r'%cpu) + self.do_task_rainbow(RGenOp, LLTypeBytecodeWriter) # task_rainbow_lltype = taskdef(task_rainbow_lltype, ["hintannotate_lltype"], "Create Rainbow-Interpreter") + def task_rainbow_ootype(self): + from pypy.jit.rainbow.codewriter import OOTypeBytecodeWriter + from pypy.jit.codegen.cli.rgenop import RCliGenOp as RGenOp + cpu = self.config.translation.jitbackend + assert cpu == 'cli' + self.do_task_rainbow(RGenOp, OOTypeBytecodeWriter) + task_rainbow_ootype = taskdef(task_rainbow_ootype, + ["hintannotate_ootype"], + "Create Rainbow-Interpreter") + def task_backendopt_lltype(self): from pypy.translator.backendopt.all import backend_optimizations backend_optimizations(self.translator) Modified: pypy/branch/oo-jit/pypy/translator/test/test_driver.py ============================================================================== --- pypy/branch/oo-jit/pypy/translator/test/test_driver.py (original) +++ pypy/branch/oo-jit/pypy/translator/test/test_driver.py Sat May 3 15:46:09 2008 @@ -7,7 +7,7 @@ td = TranslationDriver() expected = ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source', 'compile', 'run', 'prehannotatebackendopt', 'hintannotate', - 'timeshift'] + 'rainbow'] assert set(td.exposed) == set(expected) assert td.backend_select_goals(['compile_c']) == ['compile_c'] @@ -38,7 +38,8 @@ 'run_llvm', 'run_c', 'run_js', 'run_cli', 'compile_jvm', 'source_jvm', 'run_jvm', 'prehannotatebackendopt_lltype', 'hintannotate_lltype', - 'timeshift_lltype'] + 'prehannotatebackendopt_ootype', 'hintannotate_ootype', + 'rainbow_lltype', 'rainbow_ootype'] assert set(td.exposed) == set(expected) td = TranslationDriver({'backend': None, 'type_system': 'lltype'}) @@ -53,6 +54,6 @@ expected = ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source_c', 'source_llvm', 'compile_c', 'compile_llvm', 'run_llvm', - 'run_c', 'prehannotatebackendopt', 'hintannotate', 'timeshift'] + 'run_c', 'prehannotatebackendopt', 'hintannotate', 'rainbow'] assert set(td.exposed) == set(expected) From antocuni at codespeak.net Sat May 3 15:49:49 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 3 May 2008 15:49:49 +0200 (CEST) Subject: [pypy-svn] r54367 - in pypy/branch/oo-jit/pypy: jit/codegen/cli translator/cli Message-ID: <20080503134949.5D66B2A00E0@codespeak.net> Author: antocuni Date: Sat May 3 15:49:48 2008 New Revision: 54367 Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py pypy/branch/oo-jit/pypy/translator/cli/cts.py pypy/branch/oo-jit/pypy/translator/cli/ilgenerator.py pypy/branch/oo-jit/pypy/translator/cli/opcodes.py Log: - store ObjectConst.value as ootype.Object instead of the CLI System.Object - add support for char const - add support for void return values - remove some old code referencing llmemory.Address, which should never be seen here Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py (original) +++ pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py Sat May 3 15:49:48 2008 @@ -1,13 +1,11 @@ from pypy.tool.pairtype import extendabletype from pypy.rpython.ootypesystem import ootype -from pypy.rpython.lltypesystem import lltype, llmemory from pypy.rlib.objectmodel import specialize from pypy.jit.codegen.model import AbstractRGenOp, GenBuilder, GenLabel from pypy.jit.codegen.model import GenVarOrConst, GenVar, GenConst, CodeGenSwitch from pypy.jit.codegen.cli import operation as ops from pypy.jit.codegen.cli.dumpgenerator import DumpGenerator from pypy.translator.cli.dotnet import CLR, typeof, new_array, box, unbox, clidowncast, classof -from pypy.translator.cli.dotnet import cast_record_to_object, cast_object_to_record System = CLR.System Utils = CLR.pypy.runtime.Utils DelegateHolder = CLR.pypy.runtime.DelegateHolder @@ -16,10 +14,13 @@ DUMP_IL = False DEBUG = False +cVoid = ootype.nullruntimeclass cInt32 = classof(System.Int32) cBoolean = classof(System.Boolean) cDouble = classof(System.Double) cObject = classof(System.Object) +cString = classof(System.String) +cChar = classof(System.Char) class SigToken: def __init__(self, args, res, funcclass): @@ -29,7 +30,10 @@ def class2type(cls): 'Cast a PBC of type ootype.Class into a System.Type instance' - return clidowncast(box(cls), System.Type) + if cls is cVoid: + return None + else: + return clidowncast(box(cls), System.Type) class __extend__(GenVarOrConst): __metaclass__ = extendabletype @@ -85,8 +89,9 @@ class IntConst(GenConst): - def __init__(self, value): + def __init__(self, value, clitype): self.value = value + self.clitype = clitype @specialize.arg(1) def revealconst(self, T): @@ -94,17 +99,19 @@ return self.value elif T is ootype.Bool: return bool(self.value) + elif T is ootype.Char: + return chr(self.value) else: assert False def getCliType(self): - return typeof(System.Int32) + return self.clitype def load(self, builder): builder.il.Emit(OpCodes.Ldc_I4, self.value) def __repr__(self): - return "const=%s" % self.value + return "int const=%s" % self.value class FloatConst(GenConst): @@ -115,8 +122,7 @@ @specialize.arg(1) def revealconst(self, T): assert T is ootype.Float - if T is ootype.Float: - return self.value + return self.value def getCliType(self): return typeof(System.Double) @@ -125,7 +131,7 @@ builder.il.Emit(OpCodes.Ldc_R8, self.value) def __repr__(self): - return "const=%s" % self.value + return "float const=%s" % self.value class BaseConst(GenConst): @@ -165,13 +171,7 @@ @specialize.arg(1) def revealconst(self, T): - if T is llmemory.Address: - return unbox(self.obj, ootype.ROOT) # XXX - elif isinstance(T, ootype.Record): - return cast_object_to_record(T, self.obj) - else: - assert isinstance(T, ootype.OOType) - return unbox(self.obj, T) + return ootype.cast_from_object(T, self.obj) OBJECT = System.Object._INSTANCE @@ -217,19 +217,15 @@ def genconst(self, llvalue): T = ootype.typeOf(llvalue) if T is ootype.Signed: - return IntConst(llvalue) + return IntConst(llvalue, typeof(System.Int32)) elif T is ootype.Bool: - return IntConst(int(llvalue)) + return IntConst(int(llvalue), typeof(System.Boolean)) + elif T is ootype.Char: + return IntConst(ord(llvalue), typeof(System.Char)) elif T is ootype.Float: return FloatConst(llvalue) - elif T is llmemory.Address: - assert llvalue is llmemory.NULL - return zero_const - elif isinstance(T, ootype.Record): - obj = cast_record_to_object(llvalue) - return ObjectConst(obj) elif isinstance(T, ootype.OOType): - obj = box(llvalue) + obj = ootype.cast_to_object(llvalue) return ObjectConst(obj) else: assert False, "XXX not implemented" @@ -237,7 +233,7 @@ @staticmethod def genzeroconst(kind): if kind is cInt32: - return IntConst(0) + return IntConst(0, typeof(System.Int32)) else: return zero_const # ??? @@ -245,8 +241,6 @@ @specialize.memo() def sigToken(FUNCTYPE): """Return a token describing the signature of FUNCTYPE.""" - # XXX: the right thing to do would be to have a way to - # represent typeof(t) as a pbc args = [RCliGenOp.kindToken(T) for T in FUNCTYPE.ARGS] res = RCliGenOp.kindToken(FUNCTYPE.RESULT) funcclass = classof(FUNCTYPE) @@ -256,13 +250,17 @@ @specialize.memo() def kindToken(T): if T is ootype.Void: - return None + return cVoid elif T is ootype.Signed: return cInt32 elif T is ootype.Bool: return cBoolean elif T is ootype.Float: return cDouble + elif T is ootype.String: + return cString + elif T is ootype.Char: + return cChar elif isinstance(T, ootype.Instance): return cObject # XXX? else: @@ -469,5 +467,4 @@ global_rgenop = RCliGenOp() RCliGenOp.constPrebuiltGlobal = global_rgenop.genconst -NULL = ootype.null(System.Object._INSTANCE) -zero_const = ObjectConst(NULL) +zero_const = ObjectConst(ootype.NULL) Modified: pypy/branch/oo-jit/pypy/translator/cli/cts.py ============================================================================== --- pypy/branch/oo-jit/pypy/translator/cli/cts.py (original) +++ pypy/branch/oo-jit/pypy/translator/cli/cts.py Sat May 3 15:49:48 2008 @@ -147,6 +147,7 @@ ootype.Unicode: types.string, ootype.UnicodeBuilder: types.string_builder, ootype.WeakReference: types.weakref, + ootype.Object: types.object, # maps generic types to their ordinal ootype.List.SELFTYPE_T: types.list, Modified: pypy/branch/oo-jit/pypy/translator/cli/ilgenerator.py ============================================================================== --- pypy/branch/oo-jit/pypy/translator/cli/ilgenerator.py (original) +++ pypy/branch/oo-jit/pypy/translator/cli/ilgenerator.py Sat May 3 15:49:48 2008 @@ -418,6 +418,9 @@ def dup(self, TYPE): self.ilasm.opcode('dup') + def push_null(self, TYPE): + self.ilasm.opcode('ldnull') + def oonewarray(self, TYPE, length): if TYPE.ITEM is ootype.Void: self.new(TYPE) Modified: pypy/branch/oo-jit/pypy/translator/cli/opcodes.py ============================================================================== --- pypy/branch/oo-jit/pypy/translator/cli/opcodes.py (original) +++ pypy/branch/oo-jit/pypy/translator/cli/opcodes.py Sat May 3 15:49:48 2008 @@ -36,6 +36,8 @@ 'oosend': [CallMethod], 'ooupcast': DoNothing, 'oodowncast': [DownCast], + 'cast_to_object': DoNothing, + 'cast_from_object': [DownCast], 'clibox': [Box], 'cliunbox': [Unbox], 'cli_newarray': [NewArray], From cami at codespeak.net Sat May 3 15:58:36 2008 From: cami at codespeak.net (cami at codespeak.net) Date: Sat, 3 May 2008 15:58:36 +0200 (CEST) Subject: [pypy-svn] r54368 - in pypy/branch/gameboy-emulator/pypy/lang/gameboy: . test test/rom Message-ID: <20080503135836.376E52A01A0@codespeak.net> Author: cami Date: Sat May 3 15:58:35 2008 New Revision: 54368 Added: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/rom/ pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/rom/test_rom1.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/rom/test_rom1.pyc (contents, props changed) Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/constants.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_gameboy.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/video.py Log: added first rom test fixed bugs in sound fixed some bugs in the drivers Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py Sat May 3 15:58:35 2008 @@ -131,7 +131,9 @@ class Cartridge(object): - + """ + File mapping. Holds the file contents + """ def __init__(self, file=None): self.reset() if file != None: Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/constants.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/constants.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/constants.py Sat May 3 15:58:35 2008 @@ -7,6 +7,8 @@ REGISTERED_BITMAP = [ 0x3C, 0x42, 0xB9, 0xA5, 0xB9, 0xA5, 0x42, 0x3C ] +GAMEBOY_SCREEN_WIDTH = 160 +GAMEBOY_SCREEN_HEIGHT = 144 #___________________________________________________________________________ # CATRIGE TYPES # ___________________________________________________________________________ @@ -229,6 +231,8 @@ AUD3WAVERAM = 0xFF30 BUFFER_LOG_SIZE = 5; + + # ___________________________________________________________________________ # TIMER # ___________________________________________________________________________ Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py Sat May 3 15:58:35 2008 @@ -5,32 +5,33 @@ """ from pypy.lang.gameboy import constants -from pyp.lang.gameboy.cpu import * -from pyp.lang.gameboy.cartridge import * -from pyp.lang.gameboy.joypad import * -from pyp.lang.gameboy.ram import * -from pyp.lang.gameboy.serial import * -from pyp.lang.gameboy.sound import * -from pyp.lang.gameboy.video import * -from pyp.lang.gameboy.cartridge import * +from pypy.lang.gameboy.cpu import * +from pypy.lang.gameboy.cartridge import * +from pypy.lang.gameboy.interrupt import * +from pypy.lang.gameboy.joypad import * +from pypy.lang.gameboy.ram import * +from pypy.lang.gameboy.serial import * +from pypy.lang.gameboy.sound import * +from pypy.lang.gameboy.timer import * +from pypy.lang.gameboy.video import * +from pypy.lang.gameboy.cartridge import * class GameBoy(object): def __init__(self): - sel.createDriver() - self.createGamboyPieces() + self.createDrivers() + self.createGamboyElements() def createDrivers(self): - self.createDrivers() self.clock = Clock() + self.joypadDriver = JoypadDriver() self.videoDriver = VideoDriver() self.soundDriver = SoundDriver() - self.joypadDriver = JoypadDriver() - def createGameboyPieces(self): + def createGamboyElements(self): self.ram = RAM() - self.cartridge = Cartridge(storeDriver, self.clock) + self.cartridgeManager = CartridgeManager(self.clock) self.interrupt = Interrupt() self.cpu = CPU(self.interrupt, self) self.serial = Serial(self.interrupt) @@ -39,8 +40,11 @@ self.video = Video(self.videoDriver, self.interrupt, self) self.sound = Sound(self.soundDriver) - def getCartridge(self): - return self.cartridge + def getCartridgeManager(self): + return self.cartridgeManager + + def loadCartridge(self, cartridge): + self.cartridgeManager.load(cartridge) def getFrameSkip(self): return self.video.getFrameSkip() Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py Sat May 3 15:58:35 2008 @@ -12,8 +12,9 @@ audioLength = 0 audioFrequency = 0 - def __init__(self): - + def __init__(self, sampleRate, frequencyTable): + self.sampleRate = sampleRate + self.frequencyTable = frequencyTable self.audioLength=0 self.audioEnvelope=0 self.audioFrequency=0 @@ -26,10 +27,10 @@ self.audioIndex = 0 self.audioLength = 0 self.audioFrequency = 0 + self.enabled = False def reset(self): self.audioIndex = 0 - def getAudioLength(self): return self.audioLength @@ -50,13 +51,15 @@ #SquareWaveGenerator class Channel1(Channel): # Audio Channel 1 int - audioSweep=0 - audio1Index=0 - audio1Length=0 - audioVolume=0 - audio1EnvelopeLength=0 - audioSweepLength=0 - audio1Frequency=0 + def __init__(self, sampleRate, frequencyTable): + Channel.__init__(self, sampleRate, frequencyTable) + self.audioSweep=0 + self.audio1Index=0 + self.audio1Length=0 + self.audioVolume=0 + self.audio1EnvelopeLength=0 + self.audioSweepLength=0 + self.audio1Frequency=0 # Audio Channel 1 def getAudioSweep(self): @@ -72,11 +75,11 @@ def setAudioEnvelope(self, data): self.audioEnvelope = data - if ((self.audioPlayback & 0x40) != 0): + if (self.audioPlayback & 0x40) != 0: return - if ((self.audioEnvelope >> 4) == 0): + if (self.audioEnvelope >> 4) == 0: self.audioVolume = 0 - elif (self.audio1EnvelopeLength == 0 and (self.audioEnvelope & 0x07) == 0): + elif self.audio1EnvelopeLength == 0 and (self.audioEnvelope & 0x07) == 0: self.audioVolume = (self.audioVolume + 1) & 0x0F else: self.audioVolume = (self.audioVolume + 2) & 0x0F @@ -89,9 +92,9 @@ self.audioPlayback = data self.audio1Frequency = self.frequencyTable[self.audioFrequency + ((self.audioPlayback & 0x07) << 8)] - if ((self.audioPlayback & 0x80) != 0): - self.outputEnable |= 0x01 - if ((self.audioPlayback & 0x40) != 0 and self.audio1Length == 0): + if (self.audioPlayback & 0x80) != 0: + self.enabled = True + if (self.audioPlayback & 0x40) != 0 and self.audio1Length == 0: self.audio1Length = (constants.SOUND_CLOCK / 256) * (64 - (self.audioLength & 0x3F)) self.audioSweepLength = (constants.SOUND_CLOCK / 128) * ((self.audioSweep >> 4) & 0x07) self.audioVolume = self.audioEnvelope >> 4 @@ -101,38 +104,36 @@ if (self.audioPlayback & 0x40) != 0 and self.audio1Length > 0: self.audio1Length-=1 if self.audio1Length <= 0: - self.outputEnable &= ~0x01 + self.enabled = False if self.audio1EnvelopeLength > 0: self.audio1EnvelopeLength-=1 - if (self.audio1EnvelopeLength <= 0): - if ((self.audioEnvelope & 0x08) != 0): + if self.audio1EnvelopeLength <= 0: + if (self.audioEnvelope & 0x08) != 0: if (self.audioVolume < 15): self.audioVolume+=1 - elif (self.audioVolume > 0): + elif self.audioVolume > 0: self.audioVolume-=1 self.audio1EnvelopeLength += (constants.SOUND_CLOCK / 64) * (self.audioEnvelope & 0x07) - if (self.audioSweepLength > 0): + if self.audioSweepLength > 0: self.audioSweepLength-=1 - if (self.audioSweepLength <= 0): + if self.audioSweepLength <= 0: sweepSteps = (self.audioSweep & 0x07) - if (sweepSteps != 0): + if sweepSteps != 0: frequency = ((self.audioPlayback & 0x07) << 8) + self.audioFrequency - if ((self.audioSweep & 0x08) != 0): + if (self.audioSweep & 0x08) != 0: frequency -= frequency >> sweepSteps else: frequency += frequency >> sweepSteps - if (frequency < 2048): + if frequency < 2048: self.audio1Frequency = self.frequencyTable[frequency] self.audioFrequency = frequency & 0xFF self.audioPlayback = (self.audioPlayback & 0xF8) + ((frequency >> 8) & 0x07) else: self.audio1Frequency = 0 self.outputEnable &= ~0x01 - self.audioSweepLength += (constants.SOUND_CLOCK / 128) * ((self.audioSweep >> 4) & 0x07) def mixAudio(self, buffer, length): - wavePattern = 0x18 if (self.audioLength & 0xC0) == 0x00: wavePattern = 0x04 @@ -143,41 +144,41 @@ wavePattern << 22 for index in range(0, length, 3): self.audio1Index += self.audio1Frequency - if ((self.audio1Index & (0x1F << 22)) >= wavePattern): - if ((self.outputTerminal & 0x10) != 0): + if (self.audio1Index & (0x1F << 22)) >= wavePattern: + if (self.outputTerminal & 0x10) != 0: buffer[index + 0] -= self.audioVolume - if ((self.outputTerminal & 0x01) != 0): + if (self.outputTerminal & 0x01) != 0: buffer[index + 1] -= self.audioVolume else: - if ((self.outputTerminal & 0x10) != 0): + if (self.outputTerminal & 0x10) != 0: buffer[index + 0] += self.audioVolume - if ((self.outputTerminal & 0x01) != 0): + if (self.outputTerminal & 0x01) != 0: buffer[index + 1] += self.audioVolume #SquareWaveGenerator class Channel2(Channel): - # Audio Channel 2 int - audio2Index=0 - audio2Length=0 - audioVolume=0 - audio2EnvelopeLength=0 - audio2Frequency=0 - - - # Audio Channel 2 + def __init__(self, sampleRate, frequencyTable): + Channel.__init__(self, sampleRate, frequencyTable) + self.audio2Index=0 + self.audio2Length=0 + self.audioVolume=0 + self.audio2EnvelopeLength=0 + self.audio2Frequency=0 + + # Audio Channel 2 def setAudioLength(self, data): self.audioLength = data self.audio2Length = (constants.SOUND_CLOCK / 256) * (64 - (self.audioLength & 0x3F)) def setAudioEnvelope(self, data): self.audioEnvelope = data - if ((self.audioPlayback & 0x40) == 0): - if ((self.audioEnvelope >> 4) == 0): + if (self.audioPlayback & 0x40) == 0: + if (self.audioEnvelope >> 4) == 0: self.audioVolume = 0 - elif (self.audio2EnvelopeLength == 0 and (self.audioEnvelope & 0x07) == 0): + elif self.audio2EnvelopeLength == 0 and (self.audioEnvelope & 0x07) == 0: self.audioVolume = (self.audioVolume + 1) & 0x0F else: self.audioVolume = (self.audioVolume + 2) & 0x0F @@ -191,26 +192,26 @@ self.audioPlayback = data self.audio2Frequency = self.frequencyTable[self.audioFrequency\ + ((self.audioPlayback & 0x07) << 8)] - if ((self.audioPlayback & 0x80) != 0): - self.outputEnable |= 0x02 - if ((self.audioPlayback & 0x40) != 0 and self.audio2Length == 0): + if (self.audioPlayback & 0x80) != 0: + self.enabled = True + if (self.audioPlayback & 0x40) != 0 and self.audio2Length == 0: self.audio2Length = (constants.SOUND_CLOCK / 256) * (64 - (self.audioLength & 0x3F)) self.audioVolume = self.audioEnvelope >> 4 self.audio2EnvelopeLength = (constants.SOUND_CLOCK / 64) * (self.audioEnvelope & 0x07) def updateAudio(self): - if ((self.audioPlayback & 0x40) != 0 and self.audio2Length > 0): + if (self.audioPlayback & 0x40) != 0 and self.audio2Length > 0: self.audio2Length-=1 - if (self.audio2Length <= 0): - self.outputEnable &= ~0x02 - if (self.audio2EnvelopeLength > 0): + if self.audio2Length <= 0: + self.enabled = False + if self.audio2EnvelopeLength > 0: self.audio2EnvelopeLength-=1 - if (self.audio2EnvelopeLength <= 0): - if ((self.audioEnvelope & 0x08) != 0): - if (self.audioVolume < 15): + if self.audio2EnvelopeLength <= 0: + if (self.audioEnvelope & 0x08) != 0: + if self.audioVolume < 15: self.audioVolume+=1 - elif (self.audioVolume > 0): + elif self.audioVolume > 0: self.audioVolume-=1 self.audio2EnvelopeLength += (constants.SOUND_CLOCK / 64) * (self.audioEnvelope & 0x07) @@ -242,13 +243,15 @@ #SquareWaveGenerator class Channel3(Channel): - # Audio Channel 3 int - audioEnable=0 - audioLevel=0 - audio3Index=0 - audio3Length=0 - audio3Frequency=0 - audio3WavePattern = []# = new byte[16] + # Audio Channel 3 int + def __init__(self, sampleRate, frequencyTable): + Channel.__init__(self, sampleRate, frequencyTable) + self.audioEnable=0 + self.audioLevel=0 + self.audio3Index=0 + self.audio3Length=0 + self.audio3Frequency=0 + self.audioWavePattern = [0]*16 # Audio Channel 3 @@ -264,8 +267,8 @@ def setAudioEnable(self, data): self.audioEnable = data & 0x80 - if ((self.audioEnable & 0x80) == 0): - self.outputEnable &= ~0x04 + if (self.audioEnable & 0x80) == 0: + self.enabled = False def setAudioLength(self, data): self.audioLength = data @@ -281,21 +284,21 @@ def setAudioPlayback(self, data): self.audioPlayback = data self.audio3Frequency = self.frequencyTable[((self.audioPlayback & 0x07) << 8) + self.audioFrequency] >> 1 - if ((self.audioPlayback & 0x80) != 0 and (self.audioEnable & 0x80) != 0): - self.outputEnable |= 0x04 - if ((self.audioPlayback & 0x40) != 0 and self.audio3Length == 0): + if (self.audioPlayback & 0x80) != 0 and (self.audioEnable & 0x80) != 0: + self.enabled = True + if (self.audioPlayback & 0x40) != 0 and self.audio3Length == 0: self.audio3Length = (constants.SOUND_CLOCK / 256) * (256 - self.audioLength) def setAudioWavePattern(self, address, data): - self.audio3WavePattern[address & 0x0F] = data + self.audioWavePattern[address & 0x0F] = data def getAudioWavePattern(self, address): - return self.audio3WavePattern[address & 0x0F] & 0xFF + return self.audioWavePattern[address & 0x0F] & 0xFF def updateAudio(self): - if ((self.audioPlayback & 0x40) != 0 and self.audio3Length > 0): + if (self.audioPlayback & 0x40) != 0 and self.audio3Length > 0: self.audio3Length-=1 - if (self.audio3Length <= 0): + if self.audio3Length <= 0: self.outputEnable &= ~0x04 def mixAudio(self, buffer, length): @@ -308,7 +311,7 @@ wavePattern = 1 for index in range(0, length, 2): self.audio3Index += self.audio3Frequency - sample = self.audio3WavePattern[(self.audio3Index >> 23) & 0x0F] + sample = self.audioWavePattern[(self.audio3Index >> 23) & 0x0F] if ((self.audio3Index & (1 << 22)) != 0): sample = (sample >> 0) & 0x0F else: @@ -324,45 +327,43 @@ class NoiseGenerator(Channel): - # Audio Channel 4 int - audioLength=0 - audioPolynomial=0 - audio4Index=0 - audio4Length=0 - audioVolume=0 - audio4EnvelopeLength=0 - audio4Frequency=0 - - # Frequency Table - frequencyTable = [0]*2048#= new int[2048] - noiseFreqRatioTable = [0]*8 #= new int[8] - - # Noise Tables - noiseStep7Table = [0]*4 #= new int[128 / 32] - noiseStep15Table = [0]*1024 #= new int[32768 / 32] - - #Frequency Table Generation - def generateFrequencyTables(self): - sampleRate = self.driver.getSampleRate() - # frequency = (4194304 / 32) / (2048 - period) Hz - for period in range(0, 2048): - skip = (((constants.GAMEBOY_CLOCK << 10) / sampleRate) << 16) / (2048 - period) - if skip >= (32 << 22): - self.frequencyTable[period] = 0 - else: - self.frequencyTable[period] = skip + + def __init__(self, sampleRate, frequencyTable): + Channel.__init__(self, sampleRate, frequencyTable) + # Audio Channel 4 int + self.audioLength=0 + self.audioPolynomial=0 + self.audio4Index=0 + self.audio4Length=0 + self.audioVolume=0 + self.audio4EnvelopeLength=0 + self.audio4Frequency=0 + + self.generateNoiseFrequencyRatioTable() + self.generateNoiseTables() + + + def generateNoiseFrequencyRatioTable(self): + self.noiseFreqRatioTable = [0] * 8 # Polynomial Noise Frequency Ratios # 4194304 Hz * 1/2^3 * 2 4194304 Hz * 1/2^3 * 1 4194304 Hz * 1/2^3 * # 1/2 4194304 Hz * 1/2^3 * 1/3 4194304 Hz * 1/2^3 * 1/4 4194304 Hz * # 1/2^3 * 1/5 4194304 Hz * 1/2^3 * 1/6 4194304 Hz * 1/2^3 * 1/7 + sampleFactor = ((1 << 16) / self.sampleRate) for ratio in range(0, 8): divider = 1 if ratio != 0: divider = 2 * ratio - self.noiseFreqRatioTable[ratio] = (constants.GAMEBOY_CLOCK / divider) * ((1 << 16) / sampleRate) - + self.noiseFreqRatioTable[ratio] = (constants.GAMEBOY_CLOCK / divider) *sampleFactor + # Noise Generation def generateNoiseTables(self): + self.create7StepNoiseTable() + self.create15StepNoiseTable() + + def create7StepNoiseTable(self): + # Noise Tables + self. noiseStep7Table = [0]*4 #= new int[128 / 32] polynomial = 0x7F # 7 steps for index in range(0, 0x7F): @@ -370,7 +371,11 @@ if (index & 31) == 0: self.noiseStep7Table[index >> 5] = 0 self.noiseStep7Table[index >> 5] |= (polynomial & 1) << (index & 31) + + def create15StepNoiseTable(self): # 15 steps& + + self.noiseStep15Table = [0]*1024 #= new int[32768 / 32] polynomial = 0x7FFF for index in range(0, 0x7FFF): polynomial = (((polynomial << 14) ^ (polynomial << 13)) & 0x4000) | (polynomial >> 1) @@ -412,7 +417,7 @@ def setAudioPlayback(self, data): self.audioPlayback = data if (self.audioPlayback & 0x80) != 0: - self.outputEnable |= 0x08 + self.enabled = True if (self.audioPlayback & 0x40) != 0 and self.audio4Length == 0: self.audio4Length = (constants.SOUND_CLOCK / 256) * (64 - (self.audioLength & 0x3F)) self.audioVolume = self.audioEnvelope >> 4 @@ -459,20 +464,6 @@ - -# ------------------------------------------------------------------------------ - - -class VoluntaryWaveGenerator(Channel): - - def __init__(self): - Channel.__init__(self) - self.createWavePatterns() - - def createWavePatterns(self): - self.audioWavePattern = [0]*16 - - # ------------------------------------------------------------------------------ @@ -485,18 +476,29 @@ self.outputEnable=0 self.driver = soundDriver + self.sampleRate = self.driver.getSampleRate() + + self.generateFrequencyTable() self.createAudioChannels() - self.generateFrequencyTables() - self.generateNoiseTables() self.reset() def createAudioChannels(self): - self.channel1 = SquareWaveGenerator(self.sampleRate) - self.channel2 = SquareWaveGenerator(self.sampleRate) - self.channel3 = VoluntaryWaveGenerator(self.sampleRate) - self.channel4 = NoiseGenerator(self.sampleRate) + self.channel1 = Channel1(self.sampleRate, self.frequencyTable) + self.channel2 = Channel2(self.sampleRate, self.frequencyTable) + self.channel3 = Channel3(self.sampleRate, self.frequencyTable) + self.channel4 = NoiseGenerator(self.sampleRate, self.frequencyTable) + + def generateFrequencyTable(self): + self.frequencyTable = [0] * 2048 + # frequency = (4194304 / 32) / (2048 - period) Hz + for period in range(0, 2048): + skip = (((constants.GAMEBOY_CLOCK << 10) / self.sampleRate) << 16) / (2048 - period) + if skip >= (32 << 22): + self.frequencyTable[period] = 0 + else: + self.frequencyTable[period] = skip def reset(self): self.cycles = constants.GAMEBOY_CLOCK / constants.SOUND_CLOCK @@ -533,9 +535,9 @@ self.write(constants.NR43, 0x00) self.write(constants.NR44, 0xBF) - self.write(constants.outputLevel, 0x00) # 0x77 - self.write(constants.outputTerminal, 0xF0) - self.write(constants.outputEnable, 0xFF) # 0xF0 + self.write(constants.NR50, 0x00) # 0x77 + self.write(constants.NR51, 0xF0) + self.write(constants.NR52, 0xFF) # 0xF0 for address in range(0xFF30, 0xFF3F): write = 0xFF @@ -558,7 +560,6 @@ self.updateAudio() if self.driver.isEnabled(): self.mixDownAudio() - self.cycles += constants.GAMEBOY_CLOCK / constants.SOUND_CLOCK def mixDownAudio(self): @@ -609,11 +610,11 @@ elif address==constants.NR44: return self.channel4.getAudioPlayback() - elif address==constants.outputLevel: + elif address==constants.NR50: return self.getOutputLevel() - elif address==constants.outputTerminal: + elif address==constants.NR51: return self.getOutputTerminal() - elif address==constants.outputEnable: + elif address==constants.NR52: return self.getOutputEnable() elif (address >= constants.AUD3WAVERAM and address <= constants.AUD3WAVERAM + 0x3F): @@ -628,7 +629,7 @@ elif address == constants.NR12: self.channel1.setAudioEnvelope(data) elif address == constants.NR13: - self.channel1.setAudi1Frequency(data) + self.channel1.setAudioFrequency(data) elif address == constants.NR14: self.channel1.setAudioPlayback(data) @@ -661,11 +662,11 @@ elif address == constants.NR44: self.channel4.setAudioPlayback(data) - elif address == constants.outputLevel: + elif address == constants.NR50: self.setOutputLevel(data) - elif address == constants.outputTerminal: + elif address == constants.NR51: self.setOutputTerminal(data) - elif address == constants.outputEnable: + elif address == constants.NR52: self.setOutputEnable(data) elif (address >= constants.AUD3WAVERAM and address <= constants.AUD3WAVERAM + 0x3F): @@ -726,12 +727,15 @@ def __init__(self): self.enabled = True + self.sampleRate = 44100 + self.channelCount = 2 + self.bitsPerSample = 8 def isEnabled(self): return self.enabled def getSampleRate(self): - self.sampleRate + return self.sampleRate def getChannels(self): return self.channelCount Added: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/rom/test_rom1.py ============================================================================== --- (empty file) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/rom/test_rom1.py Sat May 3 15:58:35 2008 @@ -0,0 +1,15 @@ + +import py +from pypy.lang.gameboy import constants +from pypy.lang.gameboy.cpu import * +from pypy.lang.gameboy.cartridge import * +from pypy.lang.gameboy.gameboy import * + + +ROM_PATH = str(py.magic.autopath().dirpath().dirpath())+"/rom" + + + +def test_rom1(): + gameBoy = GameBoy() + \ No newline at end of file Added: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/rom/test_rom1.pyc ============================================================================== Binary file. No diff available. Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_gameboy.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_gameboy.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_gameboy.py Sat May 3 15:58:35 2008 @@ -0,0 +1,14 @@ + +import py +from pypy.lang.gameboy.gameboy import * + + + +def get_gameboy(): + gameboy = GameBoy() + return gameboy + + + +def test_init(): + gameboy = get_gameboy() \ No newline at end of file Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/video.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/video.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/video.py Sat May 3 15:58:35 2008 @@ -5,6 +5,7 @@ from pypy.lang.gameboy import constants + class Video(object): #frames = 0 #frameSkip = 0 @@ -15,7 +16,7 @@ #palette = []#= new int[1024] - def __init__(self, videDriver, interrupt, memory): + def __init__(self, videoDriver, interrupt, memory): self.driver = videoDriver self.interrupt = interrupt self.memory = memory @@ -148,7 +149,6 @@ else: self.emulateTransfer() - def getControl(self): return self.control @@ -574,12 +574,12 @@ class VideoDriver(object): - def __init__(self, width, height): - self.width = width - self.height = height + def __init__(self): + self.width = constants.GAMEBOY_SCREEN_WIDTH + self.height = constants.GAMEBOY_SCREEN_HEIGHT self.clearPixels() - def clearPixels(): + def clearPixels(self): self.pixels = [0] * self.width * self.height def getWidth(self): @@ -593,5 +593,4 @@ def updateDisplay(self): self.resetPixels() - \ No newline at end of file From antocuni at codespeak.net Sat May 3 16:18:19 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 3 May 2008 16:18:19 +0200 (CEST) Subject: [pypy-svn] r54369 - in pypy/branch/oo-jit/pypy/jit/codegen: cli/test ia32/test Message-ID: <20080503141819.095E12A01A0@codespeak.net> Author: antocuni Date: Sat May 3 16:18:19 2008 New Revision: 54369 Added: pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_portal.py (contents, props changed) Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_ts.py pypy/branch/oo-jit/pypy/jit/codegen/ia32/test/test_genc_portal.py Log: port test_portal to gencli; no test works so far Added: pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_portal.py ============================================================================== --- (empty file) +++ pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_portal.py Sat May 3 16:18:19 2008 @@ -0,0 +1,39 @@ +import py +from pypy.tool.udir import udir +from pypy.translator.cli.entrypoint import StandaloneEntryPoint +from pypy.translator.cli.gencli import GenCli +from pypy.translator.cli.sdk import SDK +from pypy.jit.codegen.ia32.test.test_genc_portal import I386PortalTestMixin +from pypy.jit.rainbow.test import test_portal +from pypy.jit.codegen.cli.rgenop import RCliGenOp + +class CliPortalTestMixin(I386PortalTestMixin): + RGenOp = RCliGenOp + + def getgraph(self, fn): + bk = self.rtyper.annotator.bookkeeper + return bk.getdesc(fn).getuniquegraph() + + def compile(self, ll_main): + graph = self.getgraph(ll_main) + entrypoint = StandaloneEntryPoint(graph) + gen = GenCli(udir, self.rtyper.annotator.translator, entrypoint) + gen.generate_source() + self.executable_name = gen.build_exe() + + def cmdexec(self, args=''): + assert self.executable_name + mono = ''.join(SDK.runtime()) + return py.process.cmdexec('%s "%s" %s' % (mono, self.executable_name, args)) + + +class TestPortal(CliPortalTestMixin, + test_portal.TestPortalOOType): + + # for the individual tests see + # ====> ../../../rainbow/test/test_portal.py + + def skip(self): + py.test.skip('in progress') + + test_cast_ptr_to_int = skip Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_ts.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_ts.py (original) +++ pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_ts.py Sat May 3 16:18:19 2008 @@ -1,4 +1,5 @@ import py +py.test.skip('port me') from pypy.tool.udir import udir from pypy.translator.cli.entrypoint import StandaloneEntryPoint from pypy.translator.cli.gencli import GenCli Modified: pypy/branch/oo-jit/pypy/jit/codegen/ia32/test/test_genc_portal.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/codegen/ia32/test/test_genc_portal.py (original) +++ pypy/branch/oo-jit/pypy/jit/codegen/ia32/test/test_genc_portal.py Sat May 3 16:18:19 2008 @@ -22,7 +22,7 @@ # ---------- run the stand-alone executable ---------- cmdargs = ' '.join([str(arg) for arg in main_args]) - output = self.cbuilder.cmdexec(cmdargs) + output = self.cmdexec(cmdargs) lines = output.split() lastline = lines[-1] assert not lastline.startswith('EXCEPTION:') @@ -78,19 +78,26 @@ backendoptimize=backendoptimize) # ---------- generate a stand-alone executable ---------- - t = self.rtyper.annotator.translator - t.config.translation.gc = 'boehm' - self.cbuilder = CStandaloneBuilder(t, ll_main, config=t.config) - self.cbuilder.generate_source() - exename = self.cbuilder.compile() + exename = self.compile(ll_main) print '-'*60 print 'Generated executable for %s: %s' % (self.testname, exename) print '-'*60 - def check_insns(self, expected=None, **counts): "Cannot check instructions in the generated assembler." + def compile(self, ll_main): + t = self.rtyper.annotator.translator + t.config.translation.gc = 'boehm' + cbuilder = CStandaloneBuilder(t, ll_main, config=t.config) + cbuilder.generate_source() + exename = cbuilder.compile() + self.main_cbuilder= cbuilder + return exename + + def cmdexec(self, args): + return self.main_cbuilder.cmdexec(args) + class TestPortal(I386PortalTestMixin, test_portal.TestPortalLLType): From antocuni at codespeak.net Sat May 3 16:26:52 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 3 May 2008 16:26:52 +0200 (CEST) Subject: [pypy-svn] r54370 - pypy/branch/oo-jit/pypy/jit/codegen/cli Message-ID: <20080503142652.EBBD12A0151@codespeak.net> Author: antocuni Date: Sat May 3 16:26:52 2008 New Revision: 54370 Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py Log: store the cliclass instead of the clitype on IntConst Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py (original) +++ pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py Sat May 3 16:26:52 2008 @@ -89,9 +89,9 @@ class IntConst(GenConst): - def __init__(self, value, clitype): + def __init__(self, value, cliclass): self.value = value - self.clitype = clitype + self.cliclass = cliclass @specialize.arg(1) def revealconst(self, T): @@ -105,7 +105,7 @@ assert False def getCliType(self): - return self.clitype + return class2type(self.cliclass) def load(self, builder): builder.il.Emit(OpCodes.Ldc_I4, self.value) @@ -217,11 +217,11 @@ def genconst(self, llvalue): T = ootype.typeOf(llvalue) if T is ootype.Signed: - return IntConst(llvalue, typeof(System.Int32)) + return IntConst(llvalue, cInt32) elif T is ootype.Bool: - return IntConst(int(llvalue), typeof(System.Boolean)) + return IntConst(int(llvalue), cBoolean) elif T is ootype.Char: - return IntConst(ord(llvalue), typeof(System.Char)) + return IntConst(ord(llvalue), cChar) elif T is ootype.Float: return FloatConst(llvalue) elif isinstance(T, ootype.OOType): @@ -233,7 +233,7 @@ @staticmethod def genzeroconst(kind): if kind is cInt32: - return IntConst(0, typeof(System.Int32)) + return IntConst(0, cInt32) else: return zero_const # ??? From antocuni at codespeak.net Sat May 3 16:35:13 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 3 May 2008 16:35:13 +0200 (CEST) Subject: [pypy-svn] r54371 - pypy/branch/oo-jit/pypy/jit/rainbow/test Message-ID: <20080503143513.1E6FD2A0151@codespeak.net> Author: antocuni Date: Sat May 3 16:35:12 2008 New Revision: 54371 Modified: pypy/branch/oo-jit/pypy/jit/rainbow/test/test_portal.py Log: rename test so that it's easier to select only this with py.test -k Modified: pypy/branch/oo-jit/pypy/jit/rainbow/test/test_portal.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/rainbow/test/test_portal.py (original) +++ pypy/branch/oo-jit/pypy/jit/rainbow/test/test_portal.py Sat May 3 16:35:12 2008 @@ -85,7 +85,7 @@ class BaseTestPortal(PortalTest): type_system = "lltype" - def test_simple(self): + def test_very_simple(self): def main(code, x): return evaluate(code, x) From cami at codespeak.net Sat May 3 16:47:06 2008 From: cami at codespeak.net (cami at codespeak.net) Date: Sat, 3 May 2008 16:47:06 +0200 (CEST) Subject: [pypy-svn] r54372 - in pypy/branch/gameboy-emulator/pypy/lang/gameboy: . test test/rom Message-ID: <20080503144706.291B12A0151@codespeak.net> Author: cami Date: Sat May 3 16:47:04 2008 New Revision: 54372 Added: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_rom.py Removed: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/rom/ Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/constants.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py Log: cartridge rom loading test completed fixed some inheritence bugs in CatridrgeMemoryBanks Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py Sat May 3 16:47:04 2008 @@ -54,43 +54,43 @@ self.checkROM() self.createRAM() self.loadBattery() - self.mbc = self.createBankController(self.getMemoryBankType(), rom, ram, clock) + self.mbc = self.createBankController(self.getMemoryBankType(), self.rom, self.ram, self.clock) def checkROM(self): if not self.verifyHeader(): raise Exeption("Cartridge header is corrupted") - if romSize < self.getROMSize(): + if self.cartridge.getSize() < self.getROMSize(): raise Exeption("Cartridge is truncated") def createRAM(self): ramSize = self.getRAMSize() - if (getMemoryBankType() >= constants.TYPE_MBC2 - and getMemoryBankType() <= constants.TYPE_MBC2_BATTERY): + if self.getMemoryBankType() >= constants.TYPE_MBC2 \ + and self.getMemoryBankType() <= constants.TYPE_MBC2_BATTERY: ramSize = 512 self.ram = [0xFF]*ramSize def loadBattery(self): - if self.store.hasBattery(cartridgeName): - self.store.readBattery(cartridgeName, self.ram) + if self.cartridge.hasBattery(): + self.ram = self.cartridge.readBattery() def save(self, cartridgeName): - if self.hasBattery(): - self.store.writeBattery(cartridgeName, self.ram) + if self.cartridge.hasBattery(): + self.cartridge.writeBattery(self.ram) def getMemoryBankType(self): - return self.rom[constants.MEMORY_BANK_MAPPING] & 0xFF + return self.rom[constants.CARTRIDGE_TYPE_ADDRESS] & 0xFF def getRom(self): return self.rom def getROMSize(self): - romSize = self.rom[constants.CARTRIDGE_SIZE_ADDRESS] & 0xFF + romSize = self.rom[constants.CARTRIDGE_ROM_SIZE_ADDRESS] & 0xFF if romSize>=0x00 and romSize<=0x07: return 32768 << romSize return -1 def getRAMSize(self): - return constants.RAM_SIZE_MAPPING[self.rom[constants.RAM_SIZE_ADDRESS]] + return constants.CARTRIDGE_RAM_SIZE_MAPPING[self.rom[constants.CARTRIDGE_RAM_SIZE_ADDRESS]] def getDestinationCode(self): return self.rom[constants.DESTINATION_CODE_ADDRESS] & 0xFF @@ -99,13 +99,14 @@ return self.rom[constants.LICENSEE_ADDRESS] & 0xFF def getROMVersion(self): - return self.rom[constants.ROM_VERSION_ADDRESS] & 0xFF + return self.rom[constants.CARTRIDGE_ROM_VERSION_ADDRESS] & 0xFF def getHeaderChecksum(self): return self.rom[constants.HEADER_CHECKSUM_ADDRESS] & 0xFF def getChecksum(self): - return ((rom[constants.CHECKSUM_A_ADDRESS] & 0xFF) << 8) + (rom[constants.CHECKSUM_B_ADDRESS] & 0xFF) + return ((self.rom[constants.CHECKSUM_A_ADDRESS] & 0xFF) << 8) \ + + (self.rom[constants.CHECKSUM_B_ADDRESS] & 0xFF) def hasBattery(self): return hasCartridgeBattery(self.getMemoryBankType()) @@ -118,11 +119,11 @@ return (checksum == self.getChecksum()) def verifyHeader(self): - if self.rom.length < 0x0150: - return false + if len(self.rom) < 0x0150: + return False checksum = 0xE7 for address in range(0x0134, 0x014C): - checksum = (checksum - (rom[address] & 0xFF)) & 0xFF + checksum = (checksum - (self.rom[address] & 0xFF)) & 0xFF return (checksum == self.getHeaderChecksum()) def createBankController(self, type, rom, ram, clockDriver): @@ -142,8 +143,7 @@ def reset(self): self.cartridgeName ="" self.cartridgeFilePath = "" - self.cartridgeFile = None - + self.cartridgeFile = None self.batteryName ="" self.batteryFilePath = "" self.batteryFile = None @@ -191,6 +191,12 @@ def removeBattery(self): if self.hasBattery(): os.remove(self.batteryFilePath) + + def getSize(self): + return os.path.getsize(self.cartridgeFilePath) + + def getBatterySize(self): + return os.path.getsize(self.batteryFilePath) @@ -221,15 +227,15 @@ def setROM(self, buffer): banks = len(buffer) / constants.ROM_BANK_SIZE - if (banks < minRomBankSize or banks > maxRomBankSize): + if banks < self.minRomBankSize or banks > self.maxRomBankSize: raise Exception("Invalid constants.ROM size") self.rom = buffer self.romSize = constants.ROM_BANK_SIZE*banks - 1 - def setRAM(buffer): + def setRAM(self, buffer): banks = len(buffer) / constants.RAM_BANK_SIZE - if (banks < minRamBankSize or banks > maxRamBankSize): + if banks < self.minRamBankSize or banks > self.maxRamBankSize: raise Exception("Invalid constants.RAM size") self.ram = buffer self.ramSize = constants.RAM_BANK_SIZE*banks - 1 @@ -238,14 +244,32 @@ def read(self, address): if address <= 0x3FFF: # 0000-3FFF return self.rom[address] & 0xFF - elif (address <= 0x7FFF):# 4000-7FFF + elif address <= 0x7FFF:# 4000-7FFF return self.rom[romBank + (address & 0x3FFF)] & 0xFF - elif (address >= 0xA000 and address <= 0xBFFF and self.ramEnable): # A000-BFFF + elif address >= 0xA000 and address <= 0xBFFF and self.ramEnable: # A000-BFFF return self.ram[self.ramBank + (address & 0x1FFF)] & 0xFF return 0xFF def write(self, address, data): pass + + +#------------------------------------------------------------------------------- + + +class DefaultMBC(MBC): + + def __init__(self, rom, ram, clockDriver): + self.reset() + self.minRomBankSize = 0 + self.maxRomBankSize = 0xFFFFFF + self.minRamBankSize = 0 + self.maxRamBankSize = 0xFFFFFF + MBC.__init__(self, rom, ram, clockDriver) + + +#------------------------------------------------------------------------------- + class MBC1(MBC): """ @@ -263,42 +287,46 @@ self.maxRamBankSize = 4 self.minRomBankSize = 2 self.maxRomBankSize = 128 - super.__init__(rom, ram, clockDriver) + MBC.__init__(self, rom, ram, clockDriver) def reset(self): - super.reset() + MBC.reset(self) self.memoryModel = 0 def write(self, address, data): - if (address <= 0x1FFF): # 0000-1FFF + if address <= 0x1FFF: # 0000-1FFF self.writeRAMEnable(address, data) - elif (address <= 0x3FFF): # 2000-3FFF + elif address <= 0x3FFF: # 2000-3FFF self.writeROMBank1(address, data) - elif (address <= 0x5FFF): # 4000-5FFF + elif address <= 0x5FFF: # 4000-5FFF self.writeROMBank2(address, data) - elif (address <= 0x7FFF): # 6000-7FFF + elif address <= 0x7FFF: # 6000-7FFF self.memoryModel = data & 0x01 - elif (address >= 0xA000 and address <= 0xBFFF and self.ramEnable): # A000-BFFF + elif address >= 0xA000 and address <= 0xBFFF and self.ramEnable: # A000-BFFF self.ram[self.ramBank + (address & 0x1FFF)] = data def writeRAMEnable(self, address, data): - if (self.ramSize > 0): + if self.ramSize > 0: self.ramEnable = ((data & 0x0A) == 0x0A) def writeROMBank1(self, address, data): - if ((data & 0x1F) == 0): + if (data & 0x1F) == 0: data = 1 - if (self.memoryModel == 0): + if self.memoryModel == 0: self.romBank = ((self.romBank & 0x180000) + ((data & 0x1F) << 14)) & self.romSize else: self.romBank = ((data & 0x1F) << 14) & self.romSize def writeROMBank2(self, address, data): - if (self.memoryModel == 0): + if self.memoryModel == 0: self.romBank = ((self.romBank & 0x07FFFF) + ((data & 0x03) << 19)) & self.romSize else: self.ramBank = ((data & 0x03) << 13) & self.ramSize - + + +#------------------------------------------------------------------------------- + + class MBC2(MBC): """ PyBoy GameBoy (TM) Emulator @@ -318,7 +346,7 @@ self.maxRamBankSize = constants.RAM_BANK_SIZE self.minRomBankSize = 2 self.maxRomBankSize = 16 - super.__init__(rom, ram, clockDriver) + MBC.__init__(self, rom, ram, clockDriver) def read(self, address): @@ -328,11 +356,11 @@ return super.read(address) def write(self, address, data): - if (address <= 0x1FFF): # 0000-1FFF + if address <= 0x1FFF: # 0000-1FFF self.writeRAMEnable(address, data) - elif (address <= 0x3FFF): # 2000-3FFF + elif address <= 0x3FFF: # 2000-3FFF self.writeROMBank() - elif (address >= 0xA000 and address <= 0xA1FF): # A000-A1FF + elif address >= 0xA000 and address <= 0xA1FF: # A000-A1FF self.writeRAMEnable(address, data) def writeRAMEnable(self, address, data): @@ -348,7 +376,11 @@ def writeRAM(self, address, data): if self.ramEnable: - self.ram[address & 0x01FF] = (byte) (data & 0x0F) + self.ram[address & 0x01FF] = data & 0x0F + + +#------------------------------------------------------------------------------- + class MBC3(MBC): """ @@ -360,7 +392,6 @@ 4000-7FFF ROM Bank 1-127 (16KB) A000-BFFF RAM Bank 0-3 (8KB) """ - def __init__(self, rom, ram, clock): self.reset() self.minRamBankSize = 0 @@ -371,12 +402,12 @@ self.clock = clock self.clockLDaysclockLControl = None - super.__init__(rom, ram, clockDriver) + MBC.__init__(self, rom, ram, clockDriver) self.reset() - def reset(): - super.reset() + def reset(self): + MBC.reset(self) self.clockTime = self.clock.getTime() self.clockLatch = self.clockRegister = 0 self.clockSeconds = self.clockMinutes = self.clockHours = self.clockDays = self.clockControl = 0 @@ -417,11 +448,11 @@ self.writeClockData(address, data) def writeRAMEnable(self, address, data): - if (self.ramSize > 0): + if self.ramSize > 0: self.ramEnable = ((data & 0x0A) == 0x0A) def writeROMBank(self, address, data): - if (data == 0): + if data == 0: data = 1 self.romBank = ((data & 0x7F) << 14) & self.romSize @@ -492,6 +523,10 @@ self.clockControl |= 0x80 self.clockTime = now + +#------------------------------------------------------------------------------- + + class MBC5(MBC): """ PyBoy GameBoy (TM) Emulator @@ -510,7 +545,7 @@ self.maxRomBankSize = 512 self.rumble = rumble - super.__init__(rom, ram, clockDriver) + MBC.__init__(self, rom, ram, clockDriver) def write(self, address, data): @@ -535,10 +570,20 @@ else: self.ramBank = ((data & 0x0F) << 13) & self.ramSize + +#------------------------------------------------------------------------------- + + class HuC1(MBC): def __init__(self, ram, rom, clockDriver): self.reset() - super.__init__(rom, ram, clockDriver) + MBC.__init__(self, rom, ram, clockDriver) + + + +#------------------------------------------------------------------------------- + + class HuC3(MBC): """ @@ -565,11 +610,11 @@ self.setRAM(ram) self.ramFlag = 0 self.ramValue = 0 - super.__init__(rom, ram, clockDriver) + MBC.__init__(self, rom, ram, clockDriver) - def reset(): - super.reset() + def reset(self): + MBC.reset(self) self.ramFlag = 0 self.ramValue = 0 self.clockRegister = 0 @@ -668,8 +713,10 @@ self.clockRegister += (1 << 24) - (365 << 12) self.clockTime = now - elapsed + # MEMORY BANK MAPPING ---------------------------------------------------------- + MEMORY_BANK_TYPE_RANGES = [ (constants.TYPE_MBC1, constants.TYPE_MBC1_RAM_BATTERY, MBC1), (constants.TYPE_MBC2, constants.TYPE_MBC2_BATTERY, MBC2), @@ -681,7 +728,7 @@ def initialize_mapping_table(): - result = [None] * 256 + result = [DefaultMBC] * 256 for entry in MEMORY_BANK_TYPE_RANGES: if len(entry) == 2: positions = [entry[0]] Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/constants.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/constants.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/constants.py Sat May 3 16:47:04 2008 @@ -41,9 +41,9 @@ TYPE_HUC1_RAM_BATTERY = 0xFF CARTRIDGE_TYPE_ADDRESS = 0x0147 -ROM_SIZE_ADDRESS = 0x0148 -RAM_SIZE_ADDRESS = 0x0149 -RAM_SIZE_MAPPING = {0x00:0, 0x01:8192, 0x02:8192, 0x03:32768} +CARTRIDGE_ROM_SIZE_ADDRESS = 0x0148 +CARTRIDGE_RAM_SIZE_ADDRESS = 0x0149 +CARTRIDGE_RAM_SIZE_MAPPING = {0x00:0, 0x01:8192, 0x02:8192, 0x03:32768} DESTINATION_CODE_ADDRESS = 0x014A LICENSEE_ADDRESS = 0x014B ROM_VERSION_ADDRESS = 0x014C Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py Sat May 3 16:47:04 2008 @@ -45,6 +45,9 @@ def loadCartridge(self, cartridge): self.cartridgeManager.load(cartridge) + + def loadCartridgeFile(self, path): + self.loadCartridge(Cartridge(path)) def getFrameSkip(self): return self.video.getFrameSkip() @@ -52,8 +55,6 @@ def setFrameSkip(self, frameSkip): self.video.setFrameSkip(frameSkip) - def load(self, cartridgeName): - self.cartridge.load(cartridgeName) def save(self, cartridgeName): self.cartridge.save(cartridgeName) Added: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_rom.py ============================================================================== --- (empty file) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_rom.py Sat May 3 16:47:04 2008 @@ -0,0 +1,63 @@ + +import py +from pypy.lang.gameboy import constants +from pypy.lang.gameboy.cpu import * +from pypy.lang.gameboy.cartridge import * +from pypy.lang.gameboy.gameboy import * + + +ROM_PATH = str(py.magic.autopath().dirpath().dirpath())+"/rom" + + + +def test_rom1(): + gameBoy = GameBoy() + try: + gameBoy.loadCartridgeFile(ROM_PATH+"/rom1/rom1.raw") + py.test.fail() + except: + pass + + +def test_rom2(): + gameBoy = GameBoy() + try: + gameBoy.loadCartridgeFile(ROM_PATH+"/rom2/rom2.raw") + py.test.fail() + except: + pass + + +def test_rom3(): + gameBoy = GameBoy() + gameBoy.loadCartridgeFile(ROM_PATH+"/rom3/rom3.gb") + + +def test_rom4(): + gameBoy = GameBoy() + gameBoy.loadCartridgeFile(ROM_PATH+"/rom4/rom4.gb") + + +def test_rom5(): + gameBoy = GameBoy() + gameBoy.loadCartridgeFile(ROM_PATH+"/rom5/rom5.gb") + + +def test_rom6(): + gameBoy = GameBoy() + gameBoy.loadCartridgeFile(ROM_PATH+"/rom6/rom6.gb") + + +def test_rom7(): + gameBoy = GameBoy() + gameBoy.loadCartridgeFile(ROM_PATH+"/rom7/rom7.gb") + + +def test_rom8(): + gameBoy = GameBoy() + gameBoy.loadCartridgeFile(ROM_PATH+"/rom8/rom8.gb") + + +def test_rom9(): + gameBoy = GameBoy() + gameBoy.loadCartridgeFile(ROM_PATH+"/rom9/rom9.gb") \ No newline at end of file From antocuni at codespeak.net Sat May 3 16:47:52 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 3 May 2008 16:47:52 +0200 (CEST) Subject: [pypy-svn] r54373 - pypy/branch/oo-jit/pypy/jit/codegen/test Message-ID: <20080503144752.EBB2B2A0151@codespeak.net> Author: antocuni Date: Sat May 3 16:47:52 2008 New Revision: 54373 Modified: pypy/branch/oo-jit/pypy/jit/codegen/test/rgenop_tests.py Log: remove two debug prints Modified: pypy/branch/oo-jit/pypy/jit/codegen/test/rgenop_tests.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/codegen/test/rgenop_tests.py (original) +++ pypy/branch/oo-jit/pypy/jit/codegen/test/rgenop_tests.py Sat May 3 16:47:52 2008 @@ -2087,10 +2087,8 @@ builder2.finish_and_goto([v33, v9, v10], label1) - print 'waatch!' builder8.start_writing() builder8.finish_and_goto([v10, v9, v9], label4) - print 'stop!' builder7.start_writing() builder7.finish_and_goto([v24, v4, v5], label0) From antocuni at codespeak.net Sat May 3 17:04:06 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 3 May 2008 17:04:06 +0200 (CEST) Subject: [pypy-svn] r54374 - in pypy/branch/oo-jit/pypy/jit: codegen/cli/test rainbow/test Message-ID: <20080503150406.6CDC02A0151@codespeak.net> Author: antocuni Date: Sat May 3 17:04:05 2008 New Revision: 54374 Added: pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_interpreter.py (contents, props changed) Modified: pypy/branch/oo-jit/pypy/jit/rainbow/test/test_interpreter.py Log: port rainbow tests to cli, to be run under pythonnet Added: pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_interpreter.py ============================================================================== --- (empty file) +++ pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_interpreter.py Sat May 3 17:04:05 2008 @@ -0,0 +1,91 @@ +import py +from pypy.jit.codegen.cli.rgenop import RCliGenOp +from pypy.jit.rainbow.test.test_interpreter import TestOOType as RainbowTest + +class TestRainbowCli(RainbowTest): + RGenOp = RCliGenOp + + # for the individual tests see + # ====> ../../../rainbow/test/test_interpreter.py + + def run_generated(self, writer, generated, residualargs, **kwds): + if 'check_raises' not in kwds: + res = generated(*residualargs) + else: + assert False, 'TODO' + return res + + def check_insns(self, expected=None, **counts): + "Cannot check instructions in the generated assembler." + + def skip(self): + py.test.skip('in progress') + + test_simple_opt_const_propagation1 = skip + test_simple_opt_const_propagation2 = skip + test_simple_fixed = skip + test_red_switch = skip + test_merge = skip + test_loop_merging = skip + test_loop_merging2 = skip + test_two_loops_merging = skip + test_green_across_split = skip + test_merge_const_before_return = skip + test_merge_3_redconsts_before_return = skip + test_merge_const_at_return = skip + test_call_4 = skip + test_call_5 = skip + test_call_6 = skip + test_green_call = skip + test_green_call_void_return = skip + test_split_on_green_return = skip + test_simple_struct = skip + test_complex_struct = skip + test_simple_array = skip + test_arraysize = skip + test_degenerate_with_voids = skip + test_red_virtual_container = skip + test_setarrayitem = skip + test_red_propagate = skip + test_merge_structures = skip + test_green_with_side_effects = skip + test_compile_time_const_tuple = skip + test_green_deepfrozen_oosend = skip + test_direct_oosend_with_green_self = skip + test_residual_red_call = skip + test_residual_red_call_with_exc = skip + test_simple_meth = skip + test_simple_red_meth = skip + test_simple_red_meth_vars_around = skip + test_simple_indirect_call = skip + test_normalize_indirect_call = skip + test_normalize_indirect_call_more = skip + test_green_char_at_merge = skip + test_self_referential_structures = skip + test_known_nonzero = skip + test_debug_assert_ptr_nonzero = skip + test_indirect_red_call = skip + test_indirect_red_call_with_exc = skip + test_indirect_gray_call = skip + test_indirect_residual_red_call = skip + test_constant_indirect_red_call = skip + test_constant_indirect_red_call_no_result = skip + test_indirect_sometimes_residual_pure_red_call = skip + test_indirect_sometimes_residual_pure_but_fixed_red_call = skip + test_manual_marking_of_pure_functions = skip + test_red_int_add_ovf = skip + test_nonzeroness_assert_while_compiling = skip + test_segfault_while_compiling = skip + test_switch = skip + test_switch_char = skip + test_learn_boolvalue = skip + test_learn_nonzeroness = skip + test_freeze_booleffects_correctly = skip + test_ptrequality = skip + test_green_ptrequality = skip + test_void_args = skip + test_degenerated_before_return = skip + test_degenerated_before_return_2 = skip + test_degenerated_at_return = skip + test_degenerated_via_substructure = skip + test_red_subclass = skip Modified: pypy/branch/oo-jit/pypy/jit/rainbow/test/test_interpreter.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/rainbow/test/test_interpreter.py (original) +++ pypy/branch/oo-jit/pypy/jit/rainbow/test/test_interpreter.py Sat May 3 17:04:05 2008 @@ -233,6 +233,9 @@ writer.interpreter.finish_jitstate(sigtoken) builder.end() generated = gv_generated.revealconst(self.Ptr(self.RESIDUAL_FUNCTYPE)) + return self.run_generated(writer, generated, residualargs, **kwds) + + def run_generated(self, writer, generated, residualargs, **kwds): graph = get_funcobj(generated).graph self.residual_graph = graph if conftest.option.view: From antocuni at codespeak.net Sat May 3 17:17:09 2008 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Sat, 3 May 2008 17:17:09 +0200 (CEST) Subject: [pypy-svn] r54375 - in pypy/branch/oo-jit/pypy: annotation jit/codegen/cli/test translator/cli translator/cli/src Message-ID: <20080503151709.D6BE62A0151@codespeak.net> Author: antocuni Date: Sat May 3 17:17:07 2008 New Revision: 54375 Modified: pypy/branch/oo-jit/pypy/annotation/bookkeeper.py pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_interpreter.py pypy/branch/oo-jit/pypy/translator/cli/dotnet.py pypy/branch/oo-jit/pypy/translator/cli/src/pypylib.cs Log: test_simple_fixed passes; we need to use DynamicInvoke to call the delegate, else the result is wrong (not sure if it's a mono or pythonnet bug) Modified: pypy/branch/oo-jit/pypy/annotation/bookkeeper.py ============================================================================== --- pypy/branch/oo-jit/pypy/annotation/bookkeeper.py (original) +++ pypy/branch/oo-jit/pypy/annotation/bookkeeper.py Sat May 3 17:17:07 2008 @@ -8,7 +8,7 @@ from pypy.objspace.flow.model import Constant from pypy.annotation.model import SomeString, SomeChar, SomeFloat, \ SomePtr, unionof, SomeInstance, SomeDict, SomeBuiltin, SomePBC, \ - SomeInteger, SomeOOInstance, TLS, SomeAddress, \ + SomeInteger, SomeOOInstance, SomeOOObject, TLS, SomeAddress, \ SomeUnicodeCodePoint, SomeOOStaticMeth, s_None, s_ImpossibleValue, \ SomeLLADTMeth, SomeBool, SomeTuple, SomeOOClass, SomeImpossibleValue, \ SomeUnicodeString, SomeList, SomeObject, HarmlesslyBlocked, \ @@ -417,6 +417,8 @@ result = SomeOOInstance(ootype.typeOf(x)) elif isinstance(x, (ootype._record, ootype._string)): result = SomeOOInstance(ootype.typeOf(x)) + elif isinstance(x, (ootype._object)): + result = SomeOOObject() elif callable(x): if hasattr(x, '__self__') and x.__self__ is not None: # for cases like 'l.append' where 'l' is a global constant list Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_interpreter.py ============================================================================== --- pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_interpreter.py (original) +++ pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_interpreter.py Sat May 3 17:17:07 2008 @@ -10,7 +10,7 @@ def run_generated(self, writer, generated, residualargs, **kwds): if 'check_raises' not in kwds: - res = generated(*residualargs) + res = generated.DynamicInvoke(residualargs) else: assert False, 'TODO' return res @@ -23,7 +23,6 @@ test_simple_opt_const_propagation1 = skip test_simple_opt_const_propagation2 = skip - test_simple_fixed = skip test_red_switch = skip test_merge = skip test_loop_merging = skip Modified: pypy/branch/oo-jit/pypy/translator/cli/dotnet.py ============================================================================== --- pypy/branch/oo-jit/pypy/translator/cli/dotnet.py (original) +++ pypy/branch/oo-jit/pypy/translator/cli/dotnet.py Sat May 3 17:17:07 2008 @@ -711,6 +711,7 @@ CLR._buildtree() known_delegates = { + ootype.StaticMethod([], ootype.Signed): CLR.pypy.test.DelegateType_int__0, ootype.StaticMethod([ootype.Signed, ootype.Float], ootype.Float): CLR.pypy.test.DelegateType_double_int_double, ootype.StaticMethod([ootype.Float], ootype.Float): CLR.pypy.test.DelegateType_double__double_1, ootype.StaticMethod([ootype.Signed], ootype.Void): CLR.pypy.test.DelegateType_void_int_1, Modified: pypy/branch/oo-jit/pypy/translator/cli/src/pypylib.cs ============================================================================== --- pypy/branch/oo-jit/pypy/translator/cli/src/pypylib.cs (original) +++ pypy/branch/oo-jit/pypy/translator/cli/src/pypylib.cs Sat May 3 17:17:07 2008 @@ -82,6 +82,7 @@ } } + public delegate double DelegateType_int__0(); public delegate double DelegateType_double__double_1(double a); public delegate double DelegateType_double_int_double(int a, double b); public delegate void DelegateType_void_int_1(int a); From cami at codespeak.net Sat May 3 17:19:39 2008 From: cami at codespeak.net (cami at codespeak.net) Date: Sat, 3 May 2008 17:19:39 +0200 (CEST) Subject: [pypy-svn] r54376 - in pypy/branch/gameboy-emulator/pypy/lang/gameboy: . test Message-ID: <20080503151939.425FA2A0151@codespeak.net> Author: cami Date: Sat May 3 17:19:38 2008 New Revision: 54376 Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/joypad.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_rom.py pypy/branch/gameboy-emulator/pypy/lang/gameboy/timer.py Log: started to complete rom test bug in cpu/ram read returns None bug fixes Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py Sat May 3 17:19:38 2008 @@ -80,7 +80,10 @@ def getMemoryBankType(self): return self.rom[constants.CARTRIDGE_TYPE_ADDRESS] & 0xFF - def getRom(self): + def getMemoryBank(self): + return self.mbc + + def getROM(self): return self.rom def getROMSize(self): @@ -130,6 +133,8 @@ return MEMORY_BANK_MAPPING[type](rom, ram, clockDriver) +# ------------------------------------------------------------------------------ + class Cartridge(object): """ Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py Sat May 3 17:19:38 2008 @@ -207,7 +207,8 @@ self.a = Register(self, constants.RESET_A) self.f = FlagRegister(self) self.af = DoubleRegister(self, self.a, self.f) - + + self.rom = [] self.reset() def reset(self): @@ -319,8 +320,8 @@ def emulate(self, ticks): self.cycles += ticks self.handlePendingInterrupt() - while (self.cycles > 0): - self.execute() + while self.cycles > 0: + self.execute(self.fetch()) # Interrupts def handlePendingInterrupt(self): Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py Sat May 3 17:19:38 2008 @@ -1,7 +1,7 @@ """ PyBoy GameBoy (TM) Emulator -Gameboy Scheduler and Memory Mapper +GameBoy Scheduler and Memory Mapper """ from pypy.lang.gameboy import constants @@ -26,25 +26,26 @@ def createDrivers(self): self.clock = Clock() self.joypadDriver = JoypadDriver() - self.videoDriver = VideoDriver() - self.soundDriver = SoundDriver() + self.videoDriver = VideoDriver() + self.soundDriver = SoundDriver() def createGamboyElements(self): - self.ram = RAM() + self.ram = RAM() self.cartridgeManager = CartridgeManager(self.clock) self.interrupt = Interrupt() - self.cpu = CPU(self.interrupt, self) + self.cpu = CPU(self.interrupt, self) self.serial = Serial(self.interrupt) - self.timer = Timer(self.interrupt) + self.timer = Timer(self.interrupt) self.joypad = Joypad(self.joypadDriver, self.interrupt) - self.video = Video(self.videoDriver, self.interrupt, self) - self.sound = Sound(self.soundDriver) + self.video = Video(self.videoDriver, self.interrupt, self) + self.sound = Sound(self.soundDriver) def getCartridgeManager(self): return self.cartridgeManager def loadCartridge(self, cartridge): self.cartridgeManager.load(cartridge) + self.cpu.setROM(self.cartridgeManager.getROM()) def loadCartridgeFile(self, path): self.loadCartridge(Cartridge(path)) @@ -55,7 +56,6 @@ def setFrameSkip(self, frameSkip): self.video.setFrameSkip(frameSkip) - def save(self, cartridgeName): self.cartridge.save(cartridgeName) @@ -75,16 +75,16 @@ self.joypad.reset() self.video.reset() self.sound.reset() - self.cpu.setROM(self.cartridge.getROM()) + self.cpu.setROM(self.cartridgeManager.getROM()) self.drawLogo() def cycles(self): - return min( self.video.cycles(), self.serial.cycles(), - self.timer.cycles(), self.sound.cycles(), - self.joypad.cycles()) + return min( self.video.getCycles(), self.serial.getCycles(), + self.timer.getCycles(), self.sound.getCycles(), + self.joypad.getCycles()) def emulate(self, ticks): - while (ticks > 0): + while ticks > 0: count = self.cycles() self.cpu.emulate(count) self.serial.emulate(count) @@ -95,38 +95,38 @@ ticks -= count def write(self, address, data): - self.getreceiver(address).write(address, data) + self.getReceiver(address).write(address, data) def read(self, address): - self.getreceiver(address).read(address) + self.getReceiver(address).read(address) - def getreceiver(self, address): + def getReceiver(self, address): if 0x0000 <= address <= 0x7FFF: - return Gameboy.cartridge + return self.cartridgeManager.getMemoryBank() elif 0x8000 <= address <= 0x9FFF: - return Gameboy.video + return self.video elif 0xA000 <= address <= 0xBFFF: - return Gameboy.cartridge + return self.cartridgeManager.getMemoryBank() elif 0xC000 <= address <= 0xFDFF: - return Gameboy.ram + return self.ram elif 0xFE00 <= address <= 0xFEFF: - return Gameboy.video + return self.video elif 0xFF00 <= address <= 0xFF00: - return Gameboy.joypad + return self.joypad elif 0xFF01 <= address <= 0xFF02: - return Gameboy.serial + return self.serial elif 0xFF04 <= address <= 0xFF07: - return Gameboy.timer + return self.timer elif 0xFF0F <= address <= 0xFF0F: - return Gameboy.interrupt + return self.interrupt elif 0xFF10 <= address <= 0xFF3F: - return Gameboy.sound + return self.sound elif 0xFF40 <= address <= 0xFF4B: - return Gameboy.video + return self.video elif 0xFF80 <= address <= 0xFFFE: - return Gameboy.ram + return self.ram elif 0xFFFF <= address <= 0xFFFF: - return Gameboy.interrupt + return self.interrupt def drawLogo(self): for index in range(0, 48): Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/joypad.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/joypad.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/joypad.py Sat May 3 17:19:38 2008 @@ -18,7 +18,7 @@ self.buttonCode = 0xF self.cycles = constants.JOYPAD_CLOCK - def cycles(self): + def getCycles(self): return self.cycles def emulate(self, ticks): Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py Sat May 3 17:19:38 2008 @@ -551,7 +551,7 @@ def stop(self): self.driver.stop() - def cycles(self): + def getCycles(self): return self.cycles def emulate(self, ticks): Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_rom.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_rom.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_rom.py Sat May 3 17:19:38 2008 @@ -7,7 +7,9 @@ ROM_PATH = str(py.magic.autopath().dirpath().dirpath())+"/rom" +EMULATION_CYCLES = 64 +# ------------------------------------------------------------------------------ def test_rom1(): @@ -29,35 +31,47 @@ def test_rom3(): + """ some NOP and an endless loop at the end '""" gameBoy = GameBoy() gameBoy.loadCartridgeFile(ROM_PATH+"/rom3/rom3.gb") + gameBoy.emulate(EMULATION_CYCLES) def test_rom4(): gameBoy = GameBoy() gameBoy.loadCartridgeFile(ROM_PATH+"/rom4/rom4.gb") + gameBoy.emulate(EMULATION_CYCLES) def test_rom5(): gameBoy = GameBoy() gameBoy.loadCartridgeFile(ROM_PATH+"/rom5/rom5.gb") + gameBoy.emulate(EMULATION_CYCLES) def test_rom6(): gameBoy = GameBoy() gameBoy.loadCartridgeFile(ROM_PATH+"/rom6/rom6.gb") + gameBoy.emulate(EMULATION_CYCLES) def test_rom7(): + py.test.skip("cpu bug in storeMemoryAtExpandedFetchAddressInA") gameBoy = GameBoy() gameBoy.loadCartridgeFile(ROM_PATH+"/rom7/rom7.gb") + gameBoy.emulate(EMULATION_CYCLES) def test_rom8(): + py.test.skip("cpu bug in storeMemoryAtExpandedFetchAddressInA") gameBoy = GameBoy() gameBoy.loadCartridgeFile(ROM_PATH+"/rom8/rom8.gb") + gameBoy.emulate(EMULATION_CYCLES) def test_rom9(): + py.test.skip("cpu bug in storeMemoryAtExpandedFetchAddressInA") gameBoy = GameBoy() - gameBoy.loadCartridgeFile(ROM_PATH+"/rom9/rom9.gb") \ No newline at end of file + gameBoy.loadCartridgeFile(ROM_PATH+"/rom9/rom9.gb") + gameBoy.emulate(EMULATION_CYCLES) + Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/timer.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/timer.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/timer.py Sat May 3 17:19:38 2008 @@ -65,8 +65,8 @@ self.timerClock = self.timerCycles = constants.TIMER_CLOCK[data & 0x03] self.tac = data - def cycles(self): - if ((self.tac & 0x04) != 0 and self.timerCycles < self.dividerCycles): + def getCycles(self): + if (self.tac & 0x04) != 0 and self.timerCycles < self.dividerCycles: return self.timerCycles return self.dividerCycles From cami at codespeak.net Sat May 3 17:21:20 2008 From: cami at codespeak.net (cami at codespeak.net) Date: Sat, 3 May 2008 17:21:20 +0200 (CEST) Subject: [pypy-svn] r54377 - pypy/branch/gameboy-emulator/pypy/lang/gameboy/test Message-ID: <20080503152120.E7D212A8007@codespeak.net> Author: cami Date: Sat May 3 17:21:20 2008 New Revision: 54377 Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_timer.py Log: updated timer test to the uniform getCycles() instead of cycles() Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_timer.py ============================================================================== --- pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_timer.py (original) +++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_timer.py Sat May 3 17:21:20 2008 @@ -79,11 +79,11 @@ timer = get_timer() value = 10 timer.dividerCycles = value - assert timer.cycles() == timer.dividerCycles + assert timer.getCycles() == timer.dividerCycles timer.tac = 0x04 timer.timerCycles = value-1 timer.timerCycles = value - assert timer.cycles() == timer.timerCycles + assert timer.getCycles() == timer.timerCycles def test_emulateDivider_normal(): timer = get_timer() From arigo at codespeak.net Sat May 3 19:42:57 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sat, 3 May 2008 19:42:57 +0200 (CEST) Subject: [pypy-svn] r54379 - pypy/dist/pypy/config Message-ID: <20080503174257.DC35D2A8083@codespeak.net> Author: arigo Date: Sat May 3 19:42:55 2008 New Revision: 54379 Modified: pypy/dist/pypy/config/pypyoption.py Log: Option no longer used (and undocumented, making test_pypyoption fail) Modified: pypy/dist/pypy/config/pypyoption.py ============================================================================== --- pypy/dist/pypy/config/pypyoption.py (original) +++ pypy/dist/pypy/config/pypyoption.py Sat May 3 19:42:55 2008 @@ -253,9 +253,6 @@ requires=[("objspace.std.withrangelist", False), ("objspace.name", "std"), ("objspace.std.withtproxy", False)]), - BoolOption("withmultituple", - "use tuples optimized for sizes", - default=False), BoolOption("withfastslice", "make list slicing lazy", default=False, From arigo at codespeak.net Sat May 3 20:45:39 2008 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sat, 3 May 2008 20:45:39 +0200 (CEST) Subject: [pypy-svn] r54381 - pypy/dist/pypy/rpython/memory/gc Message-ID: <20080503184539.78660168544@codespeak.net> Author: arigo Date: Sat May 3 20:45:37 2008 New Revision: 54381 Modified: pypy/dist/pypy/rpython/memory/gc/generation.py pypy/dist/pypy/rpython/memory/gc/hybrid.py Log: Add nice DEBUG_PRINTs to the hybrid gc. Modified: pypy/dist/pypy/rpython/memory/gc/generation.py ============================================================================== --- pypy/dist/pypy/rpython/memory/gc/generation.py (original) +++ pypy/dist/pypy/rpython/memory/gc/generation.py Sat May 3 20:45:37 2008 @@ -1,6 +1,7 @@ import sys from pypy.rpython.memory.gc.semispace import SemiSpaceGC from pypy.rpython.memory.gc.semispace import GCFLAG_EXTERNAL, GCFLAG_FORWARDED +from pypy.rpython.memory.gc.semispace import DEBUG_PRINT from pypy.rpython.lltypesystem.llmemory import NULL, raw_malloc_usage from pypy.rpython.lltypesystem import lltype, llmemory, llarena from pypy.rpython.memory.support import DEFAULT_CHUNK_SIZE @@ -19,8 +20,6 @@ # of static roots yet, but will appear with write barrier GCFLAG_NO_HEAP_PTRS = SemiSpaceGC.first_unused_gcflag << 1 -DEBUG_PRINT = False - class GenerationGC(SemiSpaceGC): """A basic generational GC: it's a SemiSpaceGC with an additional nursery for young objects. A write barrier is used to ensure that Modified: pypy/dist/pypy/rpython/memory/gc/hybrid.py ============================================================================== --- pypy/dist/pypy/rpython/memory/gc/hybrid.py (original) +++ pypy/dist/pypy/rpython/memory/gc/hybrid.py Sat May 3 20:45:37 2008 @@ -1,9 +1,11 @@ import sys from pypy.rpython.memory.gc.semispace import SemiSpaceGC +from pypy.rpython.memory.gc.semispace import DEBUG_PRINT from pypy.rpython.memory.gc.generation import GenerationGC, GCFLAG_FORWARDED from pypy.rpython.memory.gc.generation import GCFLAG_NO_YOUNG_PTRS -from pypy.rpython.lltypesystem import llmemory, llarena +from pypy.rpython.lltypesystem import lltype, llmemory, llarena from pypy.rpython.lltypesystem.llmemory import raw_malloc_usage +from pypy.rpython.lltypesystem.lloperation import llop from pypy.rlib.debug import ll_assert from pypy.rlib.rarithmetic import ovfcheck @@ -48,6 +50,8 @@ assert self.nonlarge_gcptrs_max <= self.lb_young_var_basesize assert self.nonlarge_max <= self.nonlarge_gcptrs_max self.large_objects_collect_trigger = self.space_size + if DEBUG_PRINT: + self._initial_trigger = self.large_objects_collect_trigger self.pending_external_object_list = self.AddressDeque() def setup(self): @@ -153,6 +157,11 @@ # XXX more than the current self.space_size. self.large_objects_collect_trigger -= raw_malloc_usage(totalsize) if self.large_objects_collect_trigger < 0: + if DEBUG_PRINT: + llop.debug_print(lltype.Void, "allocated", + self._initial_trigger - + self.large_objects_collect_trigger, + "bytes, triggering full collection") self.semispace_collect() result = self.allocate_external_object(totalsize) if not result: @@ -178,6 +187,9 @@ # this bit set. ll_assert(not self.pending_external_object_list.non_empty(), "pending_external_object_list should be empty at start") + if DEBUG_PRINT: + self._nonmoving_copy_count = 0 + self._nonmoving_copy_size = 0 def surviving(self, obj): # To use during a collection. The objects that survive are the @@ -220,6 +232,9 @@ # NB. the object can have a finalizer or be a weakref, but # it's not an issue. totalsize = self.size_gc_header() + objsize + if DEBUG_PRINT: + self._nonmoving_copy_count += 1 + self._nonmoving_copy_size += raw_malloc_usage(totalsize) newaddr = self.allocate_external_object(totalsize) if not newaddr: return llmemory.NULL # can't raise MemoryError during a collect() @@ -253,12 +268,18 @@ # free all mark-n-s