[pypy-svn] r53249 - in pypy/branch/js-refactoring/pypy/lang/js: . test

fijal at codespeak.net fijal at codespeak.net
Wed Apr 2 05:35:41 CEST 2008


Author: fijal
Date: Wed Apr  2 05:35:41 2008
New Revision: 53249

Modified:
   pypy/branch/js-refactoring/pypy/lang/js/baseop.py
   pypy/branch/js-refactoring/pypy/lang/js/constants.py
   pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
   pypy/branch/js-refactoring/pypy/lang/js/jscode.py
   pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
   pypy/branch/js-refactoring/pypy/lang/js/operations.py
   pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py
Log:
* Get rid of horrible SLASH
* general progress
* get rid of W_Reference for good
* get rid of GetValue


Modified: pypy/branch/js-refactoring/pypy/lang/js/baseop.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/baseop.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/baseop.py	Wed Apr  2 05:35:41 2008
@@ -6,6 +6,7 @@
      W_PrimitiveObject
 from pypy.rlib.rarithmetic import r_uint, intmask, INFINITY, NAN, ovfcheck,\
      isnan, isinf
+from pypy.lang.js.execution import ThrowException, JsTypeError
 
 def plus(ctx, nleft, nright):
     if isinstance(nleft, W_String) or isinstance(nright, W_String):

Modified: pypy/branch/js-refactoring/pypy/lang/js/constants.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/constants.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/constants.py	Wed Apr  2 05:35:41 2008
@@ -27,4 +27,3 @@
 escapedict = dict(zip(codes, escapes))
 unescapedict = dict(zip(escapes, codes))
 
-SLASH = "\\"
\ No newline at end of file

Modified: pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/interpreter.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/interpreter.py	Wed Apr  2 05:35:41 2008
@@ -152,7 +152,7 @@
     
 
 def printjs(ctx, args, this):
-    writer(",".join([i.GetValue().ToString(ctx) for i in args]))
+    writer(",".join([i.ToString(ctx) for i in args]))
     return w_Undefined
 
 def isnanjs(ctx, args, this):

Modified: pypy/branch/js-refactoring/pypy/lang/js/jscode.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jscode.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jscode.py	Wed Apr  2 05:35:41 2008
@@ -1,6 +1,6 @@
 
 from pypy.lang.js.jsobj import W_IntNumber, W_FloatNumber, W_String,\
-     W_Array, W_PrimitiveObject, W_Reference, ActivationObject,\
+     W_Array, W_PrimitiveObject, ActivationObject,\
      create_object, W_Object, w_Undefined, W_Boolean, newbool,\
      w_True, w_False, W_List
 from pypy.lang.js.execution import JsTypeError, ReturnException, ThrowException
@@ -92,6 +92,8 @@
         return "\n".join([repr(i) for i in self.opcodes])
 
     def __eq__(self, list_of_opcodes):
+        if not isinstance(list_of_opcodes, list):
+            return False
         if len(list_of_opcodes) != len(self.opcodes):
             return False
         return all([i == j for i, j in zip(self.opcodes, list_of_opcodes)])
@@ -383,20 +385,19 @@
 
 
 class BaseStoreMember(Opcode):
-    pass
-    #def eval(self, ctx, ):
-    #    XXX
+    def eval(self, ctx, stack):
+        XXX
 
-class STORE_MEMBER(Opcode):
+class STORE_MEMBER(BaseStoreMember):
     pass
 
-class STORE_MEMBER_POSTINCR(Opcode):
+class STORE_MEMBER_POSTINCR(BaseStoreMember):
     pass
 
-class STORE_MEMBER_PREINCR(Opcode):
+class STORE_MEMBER_PREINCR(BaseStoreMember):
     pass
 
-class STORE_MEMBER_SUB(Opcode):
+class STORE_MEMBER_SUB(BaseStoreMember):
     pass
 
 class BaseStore(Opcode):
@@ -544,17 +545,8 @@
         args = stack.pop()
         if not isinstance(r1, W_PrimitiveObject):
             raise ThrowException(W_String("it is not a callable"))
-            
-        if isinstance(r1, W_Reference):
-            r6 = r1.GetBase()
-        else:
-            r6 = None
-        if isinstance(args, ActivationObject):
-            r7 = None
-        else:
-            r7 = r6
         try:
-            res = r1.Call(ctx=ctx, args=args.tolist(), this=r7)
+            res = r1.Call(ctx=ctx, args=args.tolist(), this=None)
         except JsTypeError:
             raise ThrowException(W_String('it is not a function'))
         stack.append(res)

Modified: pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jsobj.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jsobj.py	Wed Apr  2 05:35:41 2008
@@ -2,7 +2,7 @@
 from pypy.rlib.rarithmetic import r_uint, intmask, isnan, isinf,\
      ovfcheck_float_to_int
 from pypy.lang.js.execution import ThrowException, JsTypeError,\
-     RangeError
+     RangeError, ReturnException
 
 class SeePage(NotImplementedError):
     pass
@@ -29,8 +29,8 @@
     return Property(name, value, True, True, True, True)
 
 class W_Root(object):
-    def GetValue(self):
-        return self
+    #def GetValue(self):
+    #    return self
 
     def ToBoolean(self):
         return False
@@ -159,10 +159,9 @@
         try: #this is a hack to be compatible to spidermonkey
             self.Call(ctx, args, this=obj)
             return obj
-        except ExecutionReturned, e:
+        except ReturnException, e:
             return e.value
         
-        
     def Get(self, P):
         try:
             return self.propdict[P].value
@@ -557,8 +556,7 @@
                 return obj.propdict[identifier].value
             except KeyError:
                 pass
-        raise Exception("XXX shall never land here, fix")
-        #return W_Reference(identifier)
+        raise ThrowException(W_String("ReferenceError: %s is not defined" % identifier))
 
 def global_context(w_global):
     assert isinstance(w_global, W_PrimitiveObject)
@@ -591,36 +589,36 @@
                             jsproperty = Property('', w_Undefined))
     return ctx
 
-class W_Reference(W_Root):
-    """Reference Type"""
-    def __init__(self, property_name, base=None):
-        self.base = base
-        self.property_name = property_name
-
-    def check_empty(self):
-        if self.base is None:
-            exception = "ReferenceError: %s is not defined"%(self.property_name,)
-            raise ThrowException(W_String(exception))        
+# class W_Reference(W_Root):
+#     """Reference Type"""
+#     def __init__(self, property_name, base=None):
+#         self.base = base
+#         self.property_name = property_name
+
+#     def check_empty(self):
+#         if self.base is None:
+#             exception = "ReferenceError: %s is not defined"%(self.property_name,)
+#             raise ThrowException(W_String(exception))        
+
+#     #def GetValue(self):
+#     #    self.check_empty()
+#     #    return self.base.Get(self.property_name)
+
+#     #def PutValue(self, w, ctx):
+#     #    base = self.base
+#     #    if base is None:
+#     #        base = ctx.scope[-1]
+#     #    base.Put(self.property_name, w)
+#     #    return w
 
-    #def GetValue(self):
-    #    self.check_empty()
-    #    return self.base.Get(self.property_name)
+#     #def GetBase(self):
+#     #    return self.base
 
-    #def PutValue(self, w, ctx):
-    #    base = self.base
-    #    if base is None:
-    #        base = ctx.scope[-1]
-    #    base.Put(self.property_name, w)
-    #    return w
+#     #def GetPropertyName(self):
+#     #    return self.property_name
 
-    #def GetBase(self):
-    #    return self.base
-
-    #def GetPropertyName(self):
-    #    return self.property_name
-
-    def __str__(self):
-        return "<" + str(self.base) + " -> " + str(self.property_name) + ">"
+#     def __str__(self):
+#         return "<" + str(self.base) + " -> " + str(self.property_name) + ">"
     
 def create_object(ctx, prototypename, callfunc=None, Value=w_Undefined):
     proto = ctx.get_global().Get(prototypename).Get('prototype')

Modified: pypy/branch/js-refactoring/pypy/lang/js/operations.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/operations.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/operations.py	Wed Apr  2 05:35:41 2008
@@ -6,12 +6,12 @@
 
 from pypy.lang.js.jsobj import W_IntNumber, W_FloatNumber, W_Object,\
      w_Undefined, W_NewBuiltin, W_String, create_object, W_List,\
-     W_PrimitiveObject, W_Reference, ActivationObject, W_Array, W_Boolean,\
+     W_PrimitiveObject, ActivationObject, W_Array, W_Boolean,\
      w_Null, W_BaseNumber, isnull_or_undefined
 from pypy.rlib.parsing.ebnfparse import Symbol, Nonterminal
 from pypy.lang.js.execution import JsTypeError, ThrowException
 from pypy.lang.js.jscode import JsCode, JsFunction
-from constants import unescapedict, SLASH
+from constants import unescapedict
 from pypy.rlib.unroll import unrolling_iterable
 
 import sys
@@ -205,6 +205,7 @@
         self.prefix = prefix
 
     def emit(self, bytecode):
+        # XXX optimize this a bit
         if self.right is not None:
             self.right.emit(bytecode)
         bytecode.emit('LOAD_STRINGCONSTANT', self.itemname)
@@ -618,11 +619,11 @@
         internalstring = string[1:stop]
         
         for c in internalstring:
-            if last == SLASH:
+            if last == "\\":
                 unescapeseq = unescapedict[last+c]
                 temp.append(unescapeseq)
                 c = ' ' # Could be anything
-            elif c != SLASH:
+            elif c != "\\":
                 temp.append(c)
             last = c
         return ''.join(temp)

Modified: pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py	Wed Apr  2 05:35:41 2008
@@ -12,7 +12,7 @@
     bytecode.emit('LOAD_FLOATCONSTANT', 4)
     bytecode.emit('ADD')
     bytecode.run(ExecutionContext([W_Object()]), check_stack=False)
-    assert bytecode.stack[0].GetValue().ToNumber() == 6.0
+    assert bytecode.stack[0].ToNumber() == 6.0
 
 def assertp(code, prints):
     l = []
@@ -39,7 +39,7 @@
         assert isinstance(bytecode.opcodes[-1], POP)
         bytecode.opcodes.pop()
         bytecode.run(ExecutionContext([ctx]), check_stack=False)
-        code_val = bytecode.stack[0].GetValue()
+        code_val = bytecode.stack[0]
     except ThrowException, excpt:
         code_val = excpt.exception
     print code_val, value



More information about the Pypy-commit mailing list