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

santagada at codespeak.net santagada at codespeak.net
Tue Dec 19 02:05:14 CET 2006


Author: santagada
Date: Tue Dec 19 02:04:55 2006
New Revision: 35869

Modified:
   pypy/dist/pypy/lang/js/context.py
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/reference.py
Log:
more work on the context and interpreter, but still non working


Modified: pypy/dist/pypy/lang/js/context.py
==============================================================================
--- pypy/dist/pypy/lang/js/context.py	(original)
+++ pypy/dist/pypy/lang/js/context.py	Tue Dec 19 02:04:55 2006
@@ -1,3 +1,9 @@
+# encoding: utf-8
+
+from copy import copy
+from pypy.lang.js.jsobj import w_Undefined, Property
+from pypy.lang.js.reference import Reference
+
 
 class ExecutionContext(object):
     def __init__(self):
@@ -5,21 +11,35 @@
         self.this = None
         self.variable = None
         self.property = Property('',w_Undefined) #Attribute flags for new vars
-
-    def get_identifier(self, identifier):
-        """docstring for get_identifier"""
-        pass
-
-
-
-
-class GlobalContext(ExecutionContext):
-    """docstring for GlobalContext"""
-    def __init__(self, global):
-        ExecutionContext.__init__()
-        self.scope.append(global)
-        self.this = global
-        self.variable = global
+    
+    def push_object(self, obj):
+        """push object into scope stack"""
+        self.scope.insert(0, obj)
+    
+    def pop_object(self):
+        """docstring for pop_object"""
+        return self.scope.pop(0)
         
+    def resolve_identifier(self, identifier):
+        for obj in self.scope:
+            if obj.HasProperty(identifier):
+                return Reference(property_name, obj)
+        
+        return Reference(property_name)
+    
 
-
+def global_context(global):
+    ctx = ExecutionContext()
+    ctx.push_object(global)
+    ctx.this = global
+    ctx.variable = global
+    ctx.property = Property('', w_Undefined, DontDelete=True)
+    return ctx
+
+def eval_context(calling_context):
+    ctx = ExecutionContext()
+    ctx.scope = copy(calling_context.scope)
+    ctx.this = calling_context.this
+    ctx.variable = calling_context.variable
+    ctx.property = Property('', w_Undefined)
+    return ctx

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Tue Dec 19 02:04:55 2006
@@ -1,5 +1,6 @@
 
 from pypy.lang.js.astgen import *
+from pypy.lang.js.jsparser import parse
 from pypy.lang.js.context import ExecutionContext
 from pypy.lang.js.jsobj import W_Number, W_String, W_Object 
 from pypy.lang.js.jsobj import w_Undefined, W_Arguments, W_Boolean, NaN
@@ -30,11 +31,12 @@
     
     def load_source(self, script_source):
         """load a source script text to the interpreter"""
-        pass
+        temp_dict = parse(script_source)
+        self.script = from_dict(temp_dict)
     
     def run(self):
         """run the interpreter"""
-        pass
+        self.script.Call(self.global_context)
 
         
 

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Tue Dec 19 02:04:55 2006
@@ -5,8 +5,7 @@
 INFDEF = 1e300 * 1e300
 NaN    = INFDEF/INFDEF
 
-# TODO: Use an integer for attributes
-class Properfty(object):
+class Property(object):
     def __init__(self, name, value, DontDelete=False, 
                  ReadOnly=False, DontEnum=False, Internal=False):
         self.name = name
@@ -123,6 +122,13 @@
 class W_Arguments(W_Object):
     pass
 
+class ActivationObject(W_Object):
+    """The object used on function calls to hold arguments and this"""
+    def __init__(self):
+        W_Object.__init__()
+        self.propdict.pop(P)
+
+
 class W_Undefined(W_Root):
     def __str__(self):
         return ""

Modified: pypy/dist/pypy/lang/js/reference.py
==============================================================================
--- pypy/dist/pypy/lang/js/reference.py	(original)
+++ pypy/dist/pypy/lang/js/reference.py	Tue Dec 19 02:04:55 2006
@@ -1,10 +1,4 @@
-#!/usr/bin/env python
 # encoding: utf-8
-"""
-reference.py
-
-Created by Leonardo Santagada on 2006-12-16.
-"""
 
 class Reference(object):
     """Reference Type"""
@@ -19,10 +13,10 @@
         raise ReferenceError
     return v.baseobject.get(v.propertyname)
 
-def put_value(v, w):
+def put_value(v, w, context):
     if not type(v, Reference):
         raise ReferenceError
     base = v.baseobject
     if v.baseobject is None:
-        base = get_global() #gets the global object of js
+        base = context.scope[-1]
     base.put(v.propertyname, w)
\ No newline at end of file



More information about the Pypy-commit mailing list