[pypy-svn] r34090 - pypy/dist/pypy/lang/js
santagada at codespeak.net
santagada at codespeak.net
Fri Nov 3 12:02:01 CET 2006
Author: santagada
Date: Fri Nov 3 12:01:39 2006
New Revision: 34090
Modified:
pypy/dist/pypy/lang/js/astgen.py
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/jsobj.py
Log:
(stephan, santagada) implemented argument list for functions
Modified: pypy/dist/pypy/lang/js/astgen.py
==============================================================================
--- pypy/dist/pypy/lang/js/astgen.py (original)
+++ pypy/dist/pypy/lang/js/astgen.py Fri Nov 3 12:01:39 2006
@@ -15,7 +15,7 @@
# return output
# getlist = staticmethod(getlist)
-
+
class Array(Node):
def __init__(self, items=()):
self.items = items
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Fri Nov 3 12:01:39 2006
@@ -1,7 +1,7 @@
from pypy.lang.js.astgen import *
from pypy.lang.js.context import ExecutionContext
-from pypy.lang.js.jsobj import W_Number, W_String, W_Object, w_Undefined
+from pypy.lang.js.jsobj import W_Number, W_String, W_Object, w_Undefined, W_Arguments
from pypy.lang.js.scope import scope_manager
def writer(x):
@@ -15,7 +15,7 @@
def call(self, context):
d = dict(enumerate(self.items))
return W_Array(d)
-
+
class __extend__(Assign):
def call(self, context):
val = self.expr.call(context)
@@ -116,7 +116,7 @@
#return self.left.call(context).add(self.right.call(context))
class __extend__(Script):
- def call(self, context=None, args=None, this=None, params=None):
+ def call(self, context=None, args=(), this=None, params=None):
if params == None:
params = []
ncontext = ExecutionContext(context)
@@ -126,7 +126,11 @@
except IndexError:
temp = w_Undefined
ncontext.assign(item, temp)
-
+
+ w_Arguments = W_Arguments(dict([(str(x),y) for x,y in enumerate(args)]))
+ print w_Arguments.dict_w
+ ncontext.assign('arguments', w_Arguments)
+
try:
for node in self.nodes:
node.call(ncontext)
Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py (original)
+++ pypy/dist/pypy/lang/js/jsobj.py Fri Nov 3 12:01:39 2006
@@ -24,71 +24,6 @@
def __repr__(self):
return "<%s(%s)>" % (self.__class__.__name__, str(self))
-class W_Array(W_Root):
- # TODO to be continued :-)
- pass
-
-class W_Undefined(W_Root):
- def __str__(self):
- return ""
-
- def ToNumber(self):
- # XXX make NaN
- return NaN
-
-class W_Null(W_Root):
- def __str__(self):
- return "null"
-
-class W_Boolean(W_Root):
- def __init__(self, boolval):
- self.boolval = boolval
-
- def __str__(self):
- if self.boolval:
- return "true"
- return "false"
-
- def ToNumber(self):
- if self.boolval:
- return 1
- return 0
-
-class W_String(W_Root):
- def __init__(self, strval):
- # XXX: Should be unicode object
- self.strval = strval
-
-# def ToString(self):
-# return self.strval
-
- def __str__(self):
- # INSANE - should be like 'str' or so
- return self.strval
-
-class W_Number(W_Root):
- def __init__(self, floatval):
- self.floatval = floatval
-
- def __str__(self):
- # XXX: more attention
- # cough, cough
- if str(self.floatval) == str(NaN):
- return 'NaN'
- if float(int(self.floatval)) == self.floatval:
- return str(int(self.floatval))
- return str(self.floatval)
-
- def Get(self, name):
- return w_Undefined
-
- def ToNumber(self):
- return self.floatval
-
-class W_Reference(W_Root):
- def GetValue(self):
- raise NotImplementedError("W_Reference.GetValue")
-
class W_Object(W_Root):
def __init__(self, dict_w, function=None):
# string --> W_Root
@@ -107,10 +42,10 @@
params= self.function.params)
else:
raise SeePage(33)
-
+
def w_string(self):
return W_String(str(self))
-
+
def DefaultValue(self, hint):
#if hint == "string":
tostring_meth = self.Get("toString")
@@ -130,20 +65,20 @@
## if isinstance(tostring_meth, W_Object):
## return tostring_meth.Call(this=self)
return w_Undefined
-
+
def ToPrimitive(self, hint=""):
return self.DefaultValue(hint)
-
+
def ToNumber(self):
return self.ToPrimitive("number").ToNumber(hint="number")
-
+
def ToString(self):
return str(self.DefaultValue(hint="string"))
-
+
def Get(self, name):
if name in self.dict_w:
return self.dict_w[name]
-
+
return w_Undefined
#def ToPrimitive(self, hint=""):
@@ -151,20 +86,84 @@
#def ToString(self):
# raise SeePage(42)
-
+
def CanPut(self, name):
return True
-
+
def Put(self, name, w_obj):
# INSANE - raise some exceptions in case of read only and such
if not self.CanPut(name):
return # AAAAAAAAAAAAaaaaaaaaaaaa
self.dict_w[name] = w_obj
-
+
def __str__(self):
# INSANE
return "[object Object]"
+class W_Arguments(W_Object):
+ pass
+
+class W_Undefined(W_Root):
+ def __str__(self):
+ return ""
+
+ def ToNumber(self):
+ # XXX make NaN
+ return NaN
+
+class W_Null(W_Root):
+ def __str__(self):
+ return "null"
+
+class W_Boolean(W_Root):
+ def __init__(self, boolval):
+ self.boolval = boolval
+
+ def __str__(self):
+ if self.boolval:
+ return "true"
+ return "false"
+
+ def ToNumber(self):
+ if self.boolval:
+ return 1
+ return 0
+
+class W_String(W_Root):
+ def __init__(self, strval):
+ # XXX: Should be unicode object
+ self.strval = strval
+
+# def ToString(self):
+# return self.strval
+
+ def __str__(self):
+ # INSANE - should be like 'str' or so
+ return self.strval
+
+class W_Number(W_Root):
+ def __init__(self, floatval):
+ self.floatval = floatval
+
+ def __str__(self):
+ # XXX: more attention
+ # cough, cough
+ if str(self.floatval) == str(NaN):
+ return 'NaN'
+ if float(int(self.floatval)) == self.floatval:
+ return str(int(self.floatval))
+ return str(self.floatval)
+
+ def Get(self, name):
+ return w_Undefined
+
+ def ToNumber(self):
+ return self.floatval
+
+class W_Reference(W_Root):
+ def GetValue(self):
+ raise NotImplementedError("W_Reference.GetValue")
+
class W_Builtin(W_Object):
def __init__(self, dict_w, internalfunction):
self.dict_w = {}
More information about the pypy-svn
mailing list