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

jlg at codespeak.net jlg at codespeak.net
Fri Jun 22 20:35:04 CEST 2007


Author: jlg
Date: Fri Jun 22 20:35:04 2007
New Revision: 44438

Added:
   pypy/dist/pypy/lang/scheme/TODO.txt   (contents, props changed)
   pypy/dist/pypy/lang/scheme/astbuilder.py   (contents, props changed)
Modified:
   pypy/dist/pypy/lang/scheme/object.py
   pypy/dist/pypy/lang/scheme/ssparser.py
   pypy/dist/pypy/lang/scheme/test/test_parser.py
Log:
Added TODO.txt and astbuilder in separate file

Added: pypy/dist/pypy/lang/scheme/TODO.txt
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/scheme/TODO.txt	Fri Jun 22 20:35:04 2007
@@ -0,0 +1,27 @@
+Do now
+------
+
+- evaluate simple expressions like
+  (* 6 7) or even (+ 1 2 3 4)
+  - convert nodes from AST tree into W_xxx - tree.dispatch()
+  - evaluate the tree
+    W_xxx object like W_Fixnum should eval to itself despite context
+  - implement basic operations like * / and so on
+
+Do next
+-------
+
+- symbols, variables and execution context
+- control structures
+- functions
+
+Do in some future
+-----------------
+
+Here starts the real fun!
+
+- delayed evaluation
+- macros
+- proper tail-recursion
+- continuations
+

Added: pypy/dist/pypy/lang/scheme/astbuilder.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/scheme/astbuilder.py	Fri Jun 22 20:35:04 2007
@@ -0,0 +1,16 @@
+import autopath
+from pypy.rlib.parsing.tree import RPythonVisitor
+
+class ASTBuilder(RPythonVisitor):
+
+    def visit_STRING(self, node):
+        print node.symbol + ":" + node.additional_info
+
+    def visit_IDENTIFIER(self, node):
+        print node.symbol + ":" + node.additional_info
+
+    def visit_sexpr(self, node):
+        print node.symbol + ":("
+        nodes = [self.dispatch(child) for child in node.children]
+        print ")"
+

Modified: pypy/dist/pypy/lang/scheme/object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/object.py	(original)
+++ pypy/dist/pypy/lang/scheme/object.py	Fri Jun 22 20:35:04 2007
@@ -1,5 +1,21 @@
 import autopath
 
+class ExecutionContext(object):
+    """Execution context implemented as a dict.
+
+    { "IDENTIFIER": W_Root }
+    """
+    def __init__(self, scope):
+        assert scope is not None
+        self.scope = scope
+
+    def __get__(self, name):
+        # shouldn't neme be instance of sth like W_Identifier
+        return self.scope.get(name, None)
+
+    def __put__(self, name, obj):
+        self.scope[name] = obj
+
 class W_Root(object):
     def to_string(self):
         return ''
@@ -13,6 +29,16 @@
     def __repr__(self):
         return "<W_Root " + self.to_string + " >"
 
+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)

Modified: pypy/dist/pypy/lang/scheme/ssparser.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/ssparser.py	(original)
+++ pypy/dist/pypy/lang/scheme/ssparser.py	Fri Jun 22 20:35:04 2007
@@ -1,7 +1,6 @@
 import autopath
 from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function
 from pypy.rlib.parsing.parsing import ParseError
-from pypy.rlib.parsing.tree import RPythonVisitor
 
 DEBUG = False
 
@@ -21,22 +20,10 @@
 parsef = make_parse_function(regexs, rules, eof=True)
 
 def parse(code):
-    t = parsef(code) 
-    tree = t.visit(ToAST())[0]
+    t = parsef(code)
+    #tree = t.visit(ToAST())[0]
+    tree = ToAST().transform(t)
     if DEBUG:
-        ToAST().transform(t).view()
+        tree.view()
     return tree
 
-class ASTBuilder(RPythonVisitor):
-
-    def visit_STRING(self, node):
-        print node.symbol + ":" + node.additional_info
-
-    def visit_IDENTIFIER(self, node):
-        print node.symbol + ":" + node.additional_info
-
-    def visit_sexpr(self, node):
-        print node.symbol + ":("
-        nodes = [self.dispatch(child) for child in node.children]
-        print ")"
-

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	Fri Jun 22 20:35:04 2007
@@ -4,7 +4,7 @@
 def test_simple_sexpr():
     #parse simple sexpr
     t = parse(r'''(+ 1 2)''')
-    assert isinstance(t, Nonterminal) 
+    assert isinstance(t, Nonterminal)
     assert len(t.children) == 3
 
 def test_string():



More information about the Pypy-commit mailing list