[pypy-svn] r18387 - pypy/dist/pypy/translator/js

ericvrp at codespeak.net ericvrp at codespeak.net
Tue Oct 11 13:12:50 CEST 2005


Author: ericvrp
Date: Tue Oct 11 13:12:48 2005
New Revision: 18387

Modified:
   pypy/dist/pypy/translator/js/codewriter.py
   pypy/dist/pypy/translator/js/js.py
   pypy/dist/pypy/translator/js/node.py
   pypy/dist/pypy/translator/js/opwriter.py
Log:
* Fixed neg operation

* Simplified codewriter binaryop

* Simplified filenaming (we no longer have to import as Python module)

* Fixed function naming when testing

[72 passed, 91 failed]



Modified: pypy/dist/pypy/translator/js/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/codewriter.py	(original)
+++ pypy/dist/pypy/translator/js/codewriter.py	Tue Oct 11 13:12:48 2005
@@ -136,13 +136,11 @@
                         n += 1
 
     def binaryop(self, name, targetvar, type_, ref1, ref2):
-        arithmetic = ('*', '/', '+', '-', '%', '^', '&', '|', '<<', '>>')
-        comparison = ('<', '<=', '==', '!=', '>=', '>')
-        if name in arithmetic or name in comparison:    #XXX this should now always true
-            self.append("%(targetvar)s = %(ref1)s %(name)s %(ref2)s" % locals())
-        else:
-            self.llvm("%s = %s %s %s, %s" % (targetvar, name, type_, ref1, ref2))
+        self.append("%(targetvar)s = %(ref1)s %(name)s %(ref2)s" % locals())
 
+    def neg(self, targetvar, source):
+        self.append('%(targetvar)s = -%(source)s' % locals())
+        
     def call(self, targetvar, returntype, functionref, argrefs, argtypes, label=None, except_label=None):
         #args = ", ".join(["%s %s" % item for item in zip(argtypes, argrefs)])
         args = ", ".join(argrefs)

Modified: pypy/dist/pypy/translator/js/js.py
==============================================================================
--- pypy/dist/pypy/translator/js/js.py	(original)
+++ pypy/dist/pypy/translator/js/js.py	Tue Oct 11 13:12:48 2005
@@ -16,6 +16,7 @@
 from pypy.rpython.rmodel import inputconst, getfunctionptr
 from pypy.rpython import lltype
 from pypy.tool.udir import udir
+from pypy.translator.js.node import LLVMNode
 from pypy.translator.js.database import Database 
 from pypy.translator.js.codewriter import CodeWriter
 from pypy.translator.js.gc import GcPolicy
@@ -24,13 +25,12 @@
 
 
 class JS(object):   # JS = Javascript
-    function_count = {}
-    
     def __init__(self, translator, function=None, gcpolicy=None, exceptionpolicy=None, debug=False):
         self.db = Database(self, translator)
         self.translator = translator
         self.gcpolicy = GcPolicy.new(gcpolicy)
         self.exceptionpolicy = ExceptionPolicy.new(exceptionpolicy)
+        LLVMNode.reset_nodename_count()
         #extfuncnode.ExternalFuncNode.used_external_functions = {}
         self.debug = debug # for debug we create comments of every operation that may be executed
         if debug:
@@ -69,14 +69,7 @@
         #if llexterns_header is None and using_external_functions:
         #    llexterns_header, llexterns_functions = generate_llfile(self.db, extern_decls, support_functions, self.debug)
  
-        # prevent running the same function twice in a test
-        if func.func_name in self.function_count:
-            postfix = '_%d' % self.function_count[func.func_name]
-            self.function_count[func.func_name] += 1
-        else:
-            postfix = ''
-            self.function_count[func.func_name] = 1
-        self.filename = udir.join(func.func_name + postfix).new(ext='.js')
+        self.filename = udir.join(func.func_name).new(ext='.js')
         f = open(str(self.filename),'w')
         codewriter = CodeWriter(f, self)
 

Modified: pypy/dist/pypy/translator/js/node.py
==============================================================================
--- pypy/dist/pypy/translator/js/node.py	(original)
+++ pypy/dist/pypy/translator/js/node.py	Tue Oct 11 13:12:48 2005
@@ -1,21 +1,28 @@
 from pypy.rpython import lltype
 
+
+_nodename_count = {}
+
 class LLVMNode(object):
     __slots__ = "".split()
 
-    nodename_count = {}
+    def reset_nodename_count():
+        global _nodename_count
+        _nodename_count = {}
+    reset_nodename_count = staticmethod(reset_nodename_count)
 
     def make_name(self, name):
         " helper for creating names"
         if " " in name or "<" in name: 
             name = '"%s"' % name
-            
-        if name in self.nodename_count:
-            postfix = '.%d' % self.nodename_count[name]
-            self.nodename_count[name] += 1
+
+        global _nodename_count 
+        if name in _nodename_count:
+            postfix = '_%d' % _nodename_count[name]
+            _nodename_count[name] += 1
         else:
             postfix = ''
-            self.nodename_count[name] = 1
+            _nodename_count[name] = 1
         return name + postfix
 
     def make_ref(self, prefix, name):

Modified: pypy/dist/pypy/translator/js/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/opwriter.py	(original)
+++ pypy/dist/pypy/translator/js/opwriter.py	Tue Oct 11 13:12:48 2005
@@ -64,7 +64,6 @@
                          'ptr_ne': '!=',
                          }
 
-
     char_operations  = {'char_lt': '<',
                         'char_le': '<=',
                         'char_eq': '==',
@@ -133,11 +132,10 @@
     keepalive = _skipped 
     
     def int_abs(self, op):
-        functionref = '%' + op.opname
-        ExternalFuncNode.used_external_functions[functionref] = True
+        #ExternalFuncNode.used_external_functions[functionref] = True
         self.codewriter.call(self.db.repr_arg(op.result),
                              self.db.repr_arg_type(op.result),
-                             functionref,
+                             'Math.abs',
                              [self.db.repr_arg(op.args[0])],
                              [self.db.repr_arg_type(op.args[0])])
     float_abs = int_abs
@@ -149,22 +147,12 @@
     def float_pow(self, op):
         self._generic_pow(op, "1.0") 
 
-    def _generic_neg(self, op, zerostr): 
-        self.codewriter.binaryop("sub", 
-                                 self.db.repr_arg(op.result),
-                                 self.db.repr_arg_type(op.args[0]),
-                                 zerostr, 
-                                 self.db.repr_arg(op.args[0]),
-                                 )
-    def int_neg(self, op):
-        self._generic_neg(op, "0")
-
-    #this is really generated, don't know why
-    # XXX rxe: Surely that cant be right?
-    uint_neg = int_neg
-
-    def float_neg(self, op):
-        self._generic_neg(op, "0.0") 
+    def _generic_neg(self, op): 
+        self.codewriter.neg(self.db.repr_arg(op.result),
+                            self.db.repr_arg(op.args[0]))
+    int_neg   = _generic_neg
+    uint_neg  = _generic_neg
+    float_neg = _generic_neg
 
     def bool_not(self, op):
         self.codewriter.binaryop('^',



More information about the Pypy-commit mailing list