[pypy-svn] r53234 - pypy/branch/js-refactoring/pypy/lang/js

fijal at codespeak.net fijal at codespeak.net
Tue Apr 1 18:02:32 CEST 2008


Author: fijal
Date: Tue Apr  1 18:02:31 2008
New Revision: 53234

Modified:
   pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py
   pypy/branch/js-refactoring/pypy/lang/js/baseop.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
Log:
support for NEW opcode.


Modified: pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py	(original)
+++ pypy/branch/js-refactoring/pypy/lang/js/astbuilder.py	Tue Apr  1 18:02:31 2008
@@ -130,7 +130,6 @@
     def visit_memberexpression(self, node):
         if isinstance(node.children[0], Symbol) and \
            node.children[0].additional_info == 'new': # XXX could be a identifier?
-            raise NotImplementedError
             pos = self.get_pos(node)
             left = self.dispatch(node.children[1])
             right = self.dispatch(node.children[2])

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	Tue Apr  1 18:02:31 2008
@@ -2,7 +2,8 @@
 """ Base operations implementations
 """
 
-from pypy.lang.js.jsobj import W_String, W_IntNumber, W_FloatNumber
+from pypy.lang.js.jsobj import W_String, W_IntNumber, W_FloatNumber,\
+     W_PrimitiveObject
 from pypy.rlib.rarithmetic import r_uint, intmask, INFINITY, NAN, ovfcheck,\
      isnan, isinf
 
@@ -199,3 +200,13 @@
     if type1 == "boolean":
         return x.ToBoolean() == x.ToBoolean()
     return x == y
+
+
+def commonnew(ctx, obj, args):
+    if not isinstance(obj, W_PrimitiveObject):
+        raise ThrowException(W_String('it is not a constructor'))
+    try:
+        res = obj.Construct(ctx=ctx, args=args)
+    except JsTypeError:
+        raise ThrowException(W_String('it is not a constructor'))
+    return res

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	Tue Apr  1 18:02:31 2008
@@ -2,11 +2,11 @@
 from pypy.lang.js.jsobj import W_IntNumber, W_FloatNumber, W_String,\
      W_Array, W_PrimitiveObject, W_Reference, ActivationObject,\
      create_object, W_Object, w_Undefined, W_Boolean, newbool,\
-     w_True, w_False
+     w_True, w_False, W_List
 from pypy.lang.js.execution import JsTypeError, ReturnException, ThrowException
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.lang.js.baseop import plus, sub, compare, AbstractEC, StrictEC,\
-     compare_e, increment
+     compare_e, increment, commonnew
 from pypy.rlib.jit import hint
 
 class AlreadyRun(Exception):
@@ -229,6 +229,16 @@
     def __repr__(self):
         return 'LOAD_ARRAY %d' % (self.counter,)
 
+class LOAD_LIST(Opcode):
+    def __init__(self, counter):
+        self.counter = counter
+
+    def eval(self, ctx, stack):
+        to_cut = len(stack)-self.counter
+        list_w = stack[to_cut:]
+        del stack[to_cut:]
+        stack.append(W_List(list_w))
+
 class LOAD_FUNCTION(Opcode):
     def __init__(self, funcobj):
         self.funcobj = funcobj
@@ -589,6 +599,14 @@
     def __repr__(self):
         return "TRYCATCHBLOCK" # XXX shall we add stuff here???
 
+class NEW(Opcode):        
+    def eval(self, ctx, stack):
+        y = stack.pop()
+        x = stack.pop()
+        assert isinstance(y, W_List)
+        args = y.get_args()
+        stack.append(commonnew(ctx, x, args))
+
 OpcodeMap = {}
 
 for name, value in locals().items():

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	Tue Apr  1 18:02:31 2008
@@ -488,6 +488,9 @@
     def get_args(self):
         return self.list_w
 
+    def tolist(self):
+        return self.list_w
+
     def __repr__(self):
         return 'W_List(%s)' % (self.list_w,)
     

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	Tue Apr  1 18:02:31 2008
@@ -552,7 +552,7 @@
     def emit(self, bytecode):
         for node in self.nodes:
             node.emit(bytecode)
-        bytecode.emit('LOAD_ARRAY', len(self.nodes))
+        bytecode.emit('LOAD_LIST', len(self.nodes))
 
 ##############################################################################
 #
@@ -577,26 +577,21 @@
 #
 ##############################################################################
 
-def commonnew(ctx, obj, args):
-    if not isinstance(obj, W_PrimitiveObject):
-        raise ThrowException(W_String('it is not a constructor'))
-    try:
-        res = obj.Construct(ctx=ctx, args=args)
-    except JsTypeError:
-        raise ThrowException(W_String('it is not a constructor'))
-    return res
-
 #class New(UnaryOp):
 #    def eval(self, ctx):
 #        x = self.expr.eval(ctx).GetValue()
 #        return commonnew(ctx, x, [])
     
-
-# class NewWithArgs(BinaryOp):
-#     def eval(self, ctx):
-#         x = self.left.eval(ctx).GetValue()
-#         args = self.right.eval(ctx).get_args()
-#         return commonnew(ctx, x, args)
+class NewWithArgs(Expression):
+    def __init__(self, pos, left, right):
+        self.pos = pos
+        self.left = left
+        self.right = right
+    
+    def emit(self, bytecode):
+        self.left.emit(bytecode)
+        self.right.emit(bytecode)
+        bytecode.emit('NEW')
 
 class BaseNumber(Expression):
     pass



More information about the Pypy-commit mailing list