[pypy-svn] r44522 - in pypy/dist/pypy/lang/scheme: . test

jlg at codespeak.net jlg at codespeak.net
Mon Jun 25 20:12:58 CEST 2007


Author: jlg
Date: Mon Jun 25 20:12:58 2007
New Revision: 44522

Modified:
   pypy/dist/pypy/lang/scheme/object.py
   pypy/dist/pypy/lang/scheme/ssparser.py
   pypy/dist/pypy/lang/scheme/test/test_eval.py
   pypy/dist/pypy/lang/scheme/test/test_object.py
   pypy/dist/pypy/lang/scheme/test/test_parser.py
Log:
W_Identifier added, W_Identifier != W_Symbol

Modified: pypy/dist/pypy/lang/scheme/object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/object.py	(original)
+++ pypy/dist/pypy/lang/scheme/object.py	Mon Jun 25 20:12:58 2007
@@ -16,7 +16,7 @@
     def eval(self, ctx):
         return self
 
-class W_Symbol(W_Root):
+class W_Identifier(W_Root):
     def __init__(self, val):
         self.name = val
 
@@ -24,7 +24,7 @@
         return self.name
 
     def __repr__(self):
-        return "<W_Symbol " + self.name + ">"
+        return "<W_Identifier " + self.name + ">"
 
     def eval(self, ctx):
 
@@ -38,6 +38,16 @@
             #reference to undefined identifier
             raise NotImplementedError
 
+class W_Symbol(W_Root):
+    def __init__(self, val):
+        self.name = val
+
+    def to_string(self):
+        return self.name
+
+    def __repr__(self):
+        return "<W_symbol " + self.name + ">"
+
 class W_Boolean(W_Root):
     def __init__(self, val):
         self.boolval = bool(val)
@@ -164,7 +174,7 @@
 
 def define(ctx, lst):
     w_identifier = lst.car
-    assert isinstance(w_identifier, W_Symbol)
+    assert isinstance(w_identifier, W_Identifier)
 
     w_val = lst.cdr.car.eval(ctx)
     ctx.put(w_identifier.name, w_val)

Modified: pypy/dist/pypy/lang/scheme/ssparser.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/ssparser.py	(original)
+++ pypy/dist/pypy/lang/scheme/ssparser.py	Mon Jun 25 20:12:58 2007
@@ -1,6 +1,6 @@
 import autopath
 from pypy.rlib.parsing.pypackrat import PackratParser
-from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Symbol
+from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Identifier
 from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Float
 
 def unquote(s):
@@ -16,7 +16,7 @@
     IDENTIFIER:
         c = `[\+\-\*\^\?a-zA-Z!<=>_~/$%&:][\+\-\*\^\?a-zA-Z0-9!<=>_~/$%&:]*`
         IGNORE*
-        return {W_Symbol(c)};
+        return {W_Identifier(c)};
 
     FIXNUM:
         c = `\-?(0|([1-9][0-9]*))`

Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/test/test_eval.py	(original)
+++ pypy/dist/pypy/lang/scheme/test/test_eval.py	Mon Jun 25 20:12:58 2007
@@ -1,6 +1,7 @@
 from pypy.lang.scheme.ssparser import parse
-from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_Float, W_String
-from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Symbol, ExecutionContext
+from pypy.lang.scheme.object import W_Boolean, W_Fixnum, W_Float, W_String
+from pypy.lang.scheme.object import W_Nil, W_Pair, W_Symbol, W_Identifier
+from pypy.lang.scheme.object import ExecutionContext
 from pypy.lang.scheme.operation import mul, add
 
 def test_operations_simple():
@@ -25,7 +26,7 @@
             + w_num3.to_number())
 
 def test_eval_obj():
-    w_num = W_Pair(W_Symbol("+"),
+    w_num = W_Pair(W_Identifier("+"),
                    W_Pair(W_Fixnum(4), W_Pair(W_Fixnum(5), W_Nil())))
     assert w_num.eval(None).to_number() == 9 
 

Modified: pypy/dist/pypy/lang/scheme/test/test_object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/test/test_object.py	(original)
+++ pypy/dist/pypy/lang/scheme/test/test_object.py	Mon Jun 25 20:12:58 2007
@@ -44,6 +44,10 @@
     w_sym = W_Symbol("symb")
     assert w_sym.to_string() == "symb"
 
+def test_symbol():
+    w_id = W_Identifier("ident")
+    assert w_id.to_string() == "ident"
+
 def test_ctx():
     w_fnum = W_Fixnum(12)
     w_symb = W_Symbol("symb")

Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/test/test_parser.py	(original)
+++ pypy/dist/pypy/lang/scheme/test/test_parser.py	Mon Jun 25 20:12:58 2007
@@ -1,7 +1,7 @@
 import py
 from pypy.lang.scheme.ssparser import parse
-from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Symbol
-from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Float
+from pypy.lang.scheme.object import W_Boolean, W_Float, W_Fixnum, W_String
+from pypy.lang.scheme.object import W_Pair, W_Nil, W_Symbol, W_Identifier
 
 def unwrap(w_obj):
     """for testing purposes: unwrap a scheme object into a python object"""
@@ -11,6 +11,8 @@
         return w_obj.to_number()
     elif isinstance(w_obj, W_String):
         return w_obj.strval
+    elif isinstance(w_obj, W_Identifier):
+        return w_obj.name
     elif isinstance(w_obj, W_Symbol):
         return w_obj.name
     elif isinstance(w_obj, W_Boolean):
@@ -34,7 +36,7 @@
     assert unwrap(w_fixnum) == 1123
     assert isinstance(w_fixnum, W_Fixnum)
     w_fixnum = parse('abfa__')
-    assert isinstance(w_fixnum, W_Symbol)
+    assert isinstance(w_fixnum, W_Identifier)
     t = parse(r'''"don't believe \"them\""''')
     assert isinstance(t, W_String)
     assert unwrap(t) == 'don\'t believe "them"'
@@ -56,7 +58,7 @@
 def test_sexpr():
     w_list = parse('(+ 1 2)')
     assert isinstance(w_list, W_Pair)
-    assert isinstance(w_list.car, W_Symbol)
+    assert isinstance(w_list.car, W_Identifier)
     assert isinstance(w_list.cdr, W_Pair)
     assert isinstance(w_list.cdr.car, W_Fixnum)
     assert isinstance(w_list.cdr.cdr.car, W_Fixnum)
@@ -82,7 +84,7 @@
 def check_ident_ch(char):
     t = parse("(" + char + ")")
     assert isinstance(t, W_Pair)
-    assert isinstance(t.car, W_Symbol)
+    assert isinstance(t.car, W_Identifier)
     assert unwrap(t.car) == char
     assert isinstance(t.cdr, W_Nil)
 
@@ -91,3 +93,4 @@
     assert unwrap(t) == False
     t = parse("#t")
     assert unwrap(t) == True
+



More information about the Pypy-commit mailing list