[pypy-svn] r33917 - pypy/dist/pypy/lang/js

fijal at codespeak.net fijal at codespeak.net
Mon Oct 30 18:12:23 CET 2006


Author: fijal
Date: Mon Oct 30 18:12:22 2006
New Revision: 33917

Added:
   pypy/dist/pypy/lang/js/context.py   (contents, props changed)
   pypy/dist/pypy/lang/js/jsobj.py   (contents, props changed)
Log:
(santagada, fijal, arigo) - Added missing file


Added: pypy/dist/pypy/lang/js/context.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/js/context.py	Mon Oct 30 18:12:22 2006
@@ -0,0 +1,29 @@
+
+class ExecutionContext(object):
+    def __init__(self, parent = None):
+        self.parent = parent
+        if parent is None:
+            self.globals = {}
+        else:
+            self.globals = parent.globals
+        #self.locals = {}
+
+    def assign(self, name, value):
+        #if name in self.locals:
+        #    self.locals[name] = value
+        #else:
+        #    if self.parent:
+        #        self.parent.assign(name, value)
+        #    else:
+        self.globals[name] = value
+
+    def access(self, name):
+        #if name in self.locals:
+        #    return self.locals[name]
+        #else:
+        #    if self.parent:
+        #        return self.parent.access(name)
+        #    else:
+        if name in self.globals:
+            return self.globals[name]
+        raise NameError("%s is not declared" % name)

Added: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/js/jsobj.py	Mon Oct 30 18:12:22 2006
@@ -0,0 +1,85 @@
+
+class SeePage(NotImplementedError):
+    pass
+
+class W_Root(object):
+    def GetValue(self):
+        return self
+
+    def ToPrimitive(self):
+        return self
+
+    def ToNumber(self):
+        raise SeePage(37)
+
+    def ToString(self):
+        return str(self)
+
+    def __repr__(self):
+        return "<%s(%s)>" % (self.__class__.__name__, str(self))
+
+class W_Undefined(W_Root):
+    def __str__(self):
+        return "undefined"
+
+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"
+
+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):
+        return self.strval
+
+class W_Number(W_Root):
+    def __init__(self, floatval):
+        self.floatval = floatval
+
+    def __str__(self):
+        # XXX: more attention
+        if float(int(self.floatval)) == self.floatval:
+            return str(int(self.floatval))
+        return str(self.floatval)
+
+    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):
+        # string --> W_Root
+        self.dict_w = dict_w
+
+    def ToPrimitive(self):
+        raise SeePage(37)
+
+    def ToString(self):
+        raise SeePage(42)
+
+class W_List(W_Root):
+    def __init__(self, list_w):
+        self.list_w = list_w
+
+    def ToString(self):
+        raise SeePage(42)
+
+w_Undefined = W_Undefined()
+w_Null = W_Null()



More information about the Pypy-commit mailing list