[pypy-svn] r36439 - in pypy/dist/pypy/translator/js: . test
fijal at codespeak.net
fijal at codespeak.net
Wed Jan 10 22:11:16 CET 2007
Author: fijal
Date: Wed Jan 10 22:11:14 2007
New Revision: 36439
Modified:
pypy/dist/pypy/translator/js/_class.py
pypy/dist/pypy/translator/js/database.py
pypy/dist/pypy/translator/js/jts.py
pypy/dist/pypy/translator/js/test/test_rclass.py
Log:
Whack, whack, whack. Another bunch of tests passes, including, but not limited to abstract methods.
Modified: pypy/dist/pypy/translator/js/_class.py
==============================================================================
--- pypy/dist/pypy/translator/js/_class.py (original)
+++ pypy/dist/pypy/translator/js/_class.py Wed Jan 10 22:11:14 2007
@@ -66,8 +66,13 @@
for m_name, m_meth in self.classdef._methods.iteritems():
graph = getattr(m_meth, 'graph', None)
- f = self.db.genoo.Function(self.db, graph, m_name, is_method = True, _class = self.name)
- f.render(ilasm)
+ if graph:
+ f = self.db.genoo.Function(self.db, graph, m_name, is_method = True, _class = self.name)
+ f.render(ilasm)
+ else:
+ pass
+ # XXX: We want to implement an abstract method here
+ self.db.pending_abstract_function(m_name)
self.db.record_class(self.classdef, self.name)
Modified: pypy/dist/pypy/translator/js/database.py
==============================================================================
--- pypy/dist/pypy/translator/js/database.py (original)
+++ pypy/dist/pypy/translator/js/database.py Wed Jan 10 22:11:14 2007
@@ -52,6 +52,10 @@
def pending_function(self, graph):
self.pending_node(self.genoo.Function(self, graph))
+ def pending_abstract_function(self, name):
+ pass
+ # XXX we want to implement it at some point (maybe...)
+
def pending_class(self, classdef):
c = Class(self, classdef)
self.pending_node(c)
Modified: pypy/dist/pypy/translator/js/jts.py
==============================================================================
--- pypy/dist/pypy/translator/js/jts.py (original)
+++ pypy/dist/pypy/translator/js/jts.py Wed Jan 10 22:11:14 2007
@@ -98,8 +98,14 @@
# FIXME: It's not ok to use always empty list
val = "[]"
elif isinstance(_type,StaticMethod):
- self.db.pending_function(v.graph)
+ if hasattr(v, 'graph'):
+ self.db.pending_function(v.graph)
+ else:
+ self.db.pending_abstract_function(v)
val = v._name
+ val = val.replace('.', '_')
+ if val == '?':
+ val = 'undefined'
elif _type is UniChar or _type is Char:
#log("Constant %r"%v)
s = repr(v)
Modified: pypy/dist/pypy/translator/js/test/test_rclass.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_rclass.py (original)
+++ pypy/dist/pypy/translator/js/test/test_rclass.py Wed Jan 10 22:11:14 2007
@@ -11,18 +11,61 @@
pass
class TestJsClass(JsTest, BaseTestRclass):
- def test_common_class_attribute(self):
- py.test.skip("WIP")
-
def test___class___attribute(self):
- py.test.skip("unsuitable")
-
+ class Base(object): pass
+ class A(Base): pass
+ class B(Base): pass
+ class C(A): pass
+ def seelater():
+ C()
+ def f(n):
+ if n == 1:
+ x = A()
+ else:
+ x = B()
+ y = B()
+ result = x.__class__, y.__class__
+ seelater()
+ return result
+ def g():
+ cls1, cls2 = f(1)
+ return cls1 is A, cls2 is B
+
+ res = self.interpret(g, [])
+ assert res[0]
+ assert res[1]
+
def test_mixin(self):
- py.test.skip("unsuitable")
-
- def test_getattr_on_classes(self):
- py.test.skip("WIP")
-
+ class Mixin(object):
+ _mixin_ = True
+
+ def m(self, v):
+ return v
+
+ class Base(object):
+ pass
+
+ class A(Base, Mixin):
+ pass
+
+ class B(Base, Mixin):
+ pass
+
+ class C(B):
+ pass
+
+ def f():
+ a = A()
+ v0 = a.m(2)
+ b = B()
+ v1 = b.m('x')
+ c = C()
+ v2 = c.m('y')
+ return v0, v1, v2
+
+ res = self.interpret(f, [])
+ assert isinstance(res[0], float)
+
def test_hash_preservation(self):
py.test.skip("WIP")
@@ -31,9 +74,6 @@
def test_isinstance(self):
py.test.skip("WIP")
-
- def test_recursive_prebuilt_instance_classattr(self):
- py.test.skip("WIP")
#class TestJsList(JsTest, BaseTestRlist):
# def test_insert_bug(self):
More information about the Pypy-commit
mailing list