[pypy-svn] r18273 - in pypy/dist/pypy/translator/js: . test
ericvrp at codespeak.net
ericvrp at codespeak.net
Fri Oct 7 22:08:43 CEST 2005
Author: ericvrp
Date: Fri Oct 7 22:08:42 2005
New Revision: 18273
Added:
pypy/dist/pypy/translator/js/test/test_class.py (contents, props changed)
Modified:
pypy/dist/pypy/translator/js/codewriter.py
pypy/dist/pypy/translator/js/opwriter.py
Log:
* Added comparison and condition branches (exitswitch)
* Added testfile which needs PBC's to pass more tests
Modified: pypy/dist/pypy/translator/js/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/codewriter.py (original)
+++ pypy/dist/pypy/translator/js/codewriter.py Fri Oct 7 22:08:42 2005
@@ -62,8 +62,9 @@
#self.llvm("br label %s" %(blockname,))
def br(self, cond, blockname_false, blockname_true):
- self.llvm("br bool %s, label %s, label %s"
- % (cond, blockname_true, blockname_false))
+ self.append('prevblock = block')
+ self.append('block = %s ? %d : %d' % (cond, blockname_true, blockname_false))
+ #self.llvm("br bool %s, label %s, label %s" % (cond, blockname_true, blockname_false))
def switch(self, intty, cond, defaultdest, value_label):
labels = ''
@@ -130,10 +131,10 @@
n += 1
def binaryop(self, name, targetvar, type_, ref1, ref2):
- conv = { 'mul':'*', 'add':'+', 'sub':'-', 'div':'/' }
- if name in conv:
- c = conv[name]
- self.append("%(targetvar)s = %(ref1)s %(c)s %(ref2)s" % locals())
+ arithmetic = '*/+-'
+ comparison = ('<', '<=', '==', '!=', '>=', '>')
+ if name in arithmetic or name in comparison:
+ self.append("%(targetvar)s = %(ref1)s %(name)s %(ref2)s" % locals())
else:
self.llvm("%s = %s %s %s, %s" % (targetvar, name, type_, ref1, ref2))
Modified: pypy/dist/pypy/translator/js/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/opwriter.py (original)
+++ pypy/dist/pypy/translator/js/opwriter.py Fri Oct 7 22:08:42 2005
@@ -7,57 +7,57 @@
log = log.opwriter
class OpWriter(object):
- binary_operations = {'int_mul': 'mul',
- 'int_add': 'add',
- 'int_sub': 'sub',
- 'int_floordiv': 'div',
+ binary_operations = {'int_mul': '*',
+ 'int_add': '+',
+ 'int_sub': '-',
+ 'int_floordiv': '/',
'int_mod': 'rem',
'int_and': 'and',
'int_or': 'or',
'int_xor': 'xor',
- 'int_lt': 'setlt',
- 'int_le': 'setle',
- 'int_eq': 'seteq',
- 'int_ne': 'setne',
- 'int_ge': 'setge',
- 'int_gt': 'setgt',
-
- 'uint_mul': 'mul',
- 'uint_add': 'add',
- 'uint_sub': 'sub',
- 'uint_floordiv': 'div',
+ 'int_lt': '<',
+ 'int_le': '<=',
+ 'int_eq': '==',
+ 'int_ne': '!=',
+ 'int_ge': '>=',
+ 'int_gt': '>',
+
+ 'uint_mul': '*',
+ 'uint_add': '+',
+ 'uint_sub': '-',
+ 'uint_floordiv': '/',
'uint_mod': 'rem',
'uint_and': 'and',
'uint_or': 'or',
'uint_xor': 'xor',
- 'uint_lt': 'setlt',
- 'uint_le': 'setle',
- 'uint_eq': 'seteq',
- 'uint_ne': 'setne',
- 'uint_ge': 'setge',
- 'uint_gt': 'setgt',
-
- 'unichar_lt': 'setlt',
- 'unichar_le': 'setle',
- 'unichar_eq': 'seteq',
- 'unichar_ne': 'setne',
- 'unichar_ge': 'setge',
- 'unichar_gt': 'setgt',
-
- 'float_mul': 'mul',
- 'float_add': 'add',
- 'float_sub': 'sub',
- 'float_truediv': 'div',
+ 'uint_lt': '<',
+ 'uint_le': '<=',
+ 'uint_eq': '==',
+ 'uint_ne': '!=',
+ 'uint_ge': '>=',
+ 'uint_gt': '>',
+
+ 'unichar_lt': '<',
+ 'unichar_le': '<=',
+ 'unichar_eq': '==',
+ 'unichar_ne': '!=',
+ 'unichar_ge': '>=',
+ 'unichar_gt': '>',
+
+ 'float_mul': '*',
+ 'float_add': '+',
+ 'float_sub': '-',
+ 'float_truediv': '/',
'float_mod': 'rem',
- 'float_lt': 'setlt',
- 'float_le': 'setle',
- 'float_eq': 'seteq',
- 'float_ne': 'setne',
- 'float_ge': 'setge',
- 'float_gt': 'setgt',
+ 'float_lt': '<',
+ 'float_le': '<=',
+ 'float_eq': '==',
+ 'float_ne': '!=',
+ 'float_ge': '>=',
+ 'float_gt': '>',
- 'ptr_eq': 'seteq',
- 'ptr_ne': 'setne',
+ 'ptr_eq': '==',
+ 'ptr_ne': '!=',
}
shift_operations = {'int_lshift': 'shl',
@@ -68,12 +68,12 @@
}
- char_operations = {'char_lt': 'setlt',
- 'char_le': 'setle',
- 'char_eq': 'seteq',
- 'char_ne': 'setne',
- 'char_ge': 'setge',
- 'char_gt': 'setgt'}
+ char_operations = {'char_lt': '<',
+ 'char_le': '<=',
+ 'char_eq': '==',
+ 'char_ne': '!=',
+ 'char_ge': '>=',
+ 'char_gt': '>'}
def __init__(self, db, codewriter, node, block):
self.db = db
@@ -133,7 +133,8 @@
self.codewriter.cast(targetvar, mult_type, res_val, mult_type)
def _skipped(self, op):
- self.codewriter.comment('Skipping operation %s()' % op.opname)
+ #self.codewriter.comment('Skipping operation %s()' % op.opname)
+ pass
keepalive = _skipped
def int_abs(self, op):
@@ -247,7 +248,7 @@
same_as = cast_primitive
def int_is_true(self, op):
- self.codewriter.binaryop("setne",
+ self.codewriter.binaryop("!=",
self.db.repr_arg(op.result),
self.db.repr_arg_type(op.args[0]),
self.db.repr_arg(op.args[0]),
@@ -255,21 +256,21 @@
uint_is_true = int_is_true
def float_is_true(self, op):
- self.codewriter.binaryop("setne",
+ self.codewriter.binaryop("!=",
self.db.repr_arg(op.result),
self.db.repr_arg_type(op.args[0]),
self.db.repr_arg(op.args[0]),
"0.0")
def ptr_nonzero(self, op):
- self.codewriter.binaryop("setne",
+ self.codewriter.binaryop("!=",
self.db.repr_arg(op.result),
self.db.repr_arg_type(op.args[0]),
self.db.repr_arg(op.args[0]),
"null")
def ptr_iszero(self, op):
- self.codewriter.binaryop("seteq",
+ self.codewriter.binaryop("==",
self.db.repr_arg(op.result),
self.db.repr_arg_type(op.args[0]),
self.db.repr_arg(op.args[0]),
Added: pypy/dist/pypy/translator/js/test/test_class.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js/test/test_class.py Fri Oct 7 22:08:42 2005
@@ -0,0 +1,78 @@
+from __future__ import division
+import py
+
+from pypy.translator.js.test.runtest import compile_function
+from pypy.translator.llvm.test import llvmsnippet
+
+class TestClass(object):
+ def test_classsimple(self):
+ f = compile_function(llvmsnippet.class_simple, [])
+ assert f() == 14
+
+ def test_classsimple1(self):
+ f = compile_function(llvmsnippet.class_simple1, [int])
+ assert f(2) == 10
+
+ def test_id_int(self):
+ f = compile_function(llvmsnippet.id_int, [int])
+ for i in range(1, 20):
+ assert f(i) == i
+
+ def test_classsimple2(self):
+ f = compile_function(llvmsnippet.class_simple2, [int])
+ assert f(2) == 10
+
+ def test_inherit1(self):
+ f = compile_function(llvmsnippet.class_inherit1, [])
+ assert f() == 11
+
+ def test_inherit2(self):
+ f = compile_function(llvmsnippet.class_inherit2, [])
+ assert f() == 1
+
+ def test_method_of_base_class(self):
+ f = compile_function(llvmsnippet.method_of_base_class, [])
+ assert f() == 14
+
+ def test_attribute_from_base_class(self):
+ f = compile_function(llvmsnippet.attribute_from_base_class, [])
+ assert f() == 4
+
+ def test_direct_call_of_virtual_method(self):
+ f = compile_function(llvmsnippet.direct_call_of_virtual_method, [])
+ assert f() == 14
+
+ def test_flow_type(self):
+ f = compile_function(llvmsnippet.flow_type, [])
+ assert f() == 16
+
+ def test_merge_class(self):
+ f = compile_function(llvmsnippet.merge_classes, [bool])
+ assert f(True) == 1
+ assert f(False) == 2
+
+ def test_attribute_instance(self):
+ f = compile_function(llvmsnippet.attribute_instance, [bool])
+ assert f(True) == 1
+ assert f(False) == 2
+
+ def test_global_instance(self):
+ f = compile_function(llvmsnippet.global_instance, [int])
+ assert f(-1) == llvmsnippet.global_instance(-1)
+ for i in range(20):
+ x = f(i)
+ y = llvmsnippet.global_instance(i)
+ assert x == y
+
+ def test_getset(self):
+ f = compile_function(llvmsnippet.testgetset, [int])
+ assert f(15) == 25
+
+ def test_call_degrading_func(self):
+ f = compile_function(llvmsnippet.call_degrading_func, [bool])
+ assert f(True) == llvmsnippet.call_degrading_func(True)
+ assert f(False) == llvmsnippet.call_degrading_func(False)
+
+ def test_circular_classdef(self):
+ f = compile_function(llvmsnippet.circular_classdef, [])
+ assert f() == 10
More information about the Pypy-commit
mailing list