[pypy-svn] r14840 - in pypy/dist/pypy: interpreter interpreter/pyparser translator

pedronis at codespeak.net pedronis at codespeak.net
Thu Jul 21 02:08:01 CEST 2005


Author: pedronis
Date: Thu Jul 21 02:07:59 2005
New Revision: 14840

Modified:
   pypy/dist/pypy/interpreter/pycompiler.py
   pypy/dist/pypy/interpreter/pyparser/pythonutil.py
   pypy/dist/pypy/translator/ann_override.py
Log:
issue98: chatting

stop-gap solution so that annotating the trunk at least terminates.

To try that out set CHECK_DIGITS in longobject to False,

then in translator/goal

translate_pypy.py -no-t -no-c -no-o -no-snapshot

will annotate the trunk

Annotation terminates but there are quite a lof of SomeObject in interpreter/pyparser and module/recparser related code.




Modified: pypy/dist/pypy/interpreter/pycompiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycompiler.py	(original)
+++ pypy/dist/pypy/interpreter/pycompiler.py	Thu Jul 21 02:07:59 2005
@@ -178,21 +178,30 @@
          the whole source after having only added a new '\n')
     """
     def compile(self, source, filename, mode, flags):
+        assert isinstance(source, str) # xxx__builtin__.compile is cheating in the unicode case
+                                       # we need to do something about that
+                                       # CPython encode unicode for compilation into utf-8
+                                       # and use a special internal flag to control behavior!
+    
         from pyparser.error import ParseError
-        from pyparser.pythonutil import pypy_parse
+        from pyparser.pythonutil import internal_pypy_parse
         flags |= __future__.generators.compiler_flag   # always on (2.2 compat)
         # XXX use 'flags'
         space = self.space
         try:
-            tuples = pypy_parse(source, mode, True, flags)
+            parse_result = internal_pypy_parse(source, mode, True, flags)
         except ParseError, e:
             raise OperationError(space.w_SyntaxError,
                                  e.wrap_info(space, filename))
-        c = self.compile_tuples(tuples, filename, mode)
-        from pypy.interpreter.pycode import PyCode
-        return space.wrap(PyCode(space)._from_code(c))
+        w_code = self.compile_parse_result(parse_result, filename, mode)
+        return w_code
+
+    def compile_parse_result(self, parse_result, filename, mode):
+        """NOT_RPYTHON"""
+        from pyparser.pythonutil import parse_result_to_nested_tuples
+        # the result of this conversion has no useful type in RPython
+        tuples = parse_result_to_nested_tuples(parse_result, True)
 
-    def compile_tuples(self, tuples, filename, mode):
         # __________
         # XXX this uses the non-annotatable stablecompiler at interp-level
         from pypy.interpreter import stablecompiler
@@ -224,8 +233,9 @@
         except TypeError,e:
             raise OperationError(space.w_TypeError,space.wrap(str(e)))
         # __________ end of XXX above
-        return c
-    compile_tuples._annspecialcase_ = 'override:cpy_stablecompiler'
+        from pypy.interpreter.pycode import PyCode
+        return space.wrap(PyCode(space)._from_code(c))
+    compile_parse_result._annspecialcase_ = 'override:cpy_stablecompiler'
 
 
 class PyPyCompiler(CPythonCompiler):

Modified: pypy/dist/pypy/interpreter/pyparser/pythonutil.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/pythonutil.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/pythonutil.py	Thu Jul 21 02:07:59 2005
@@ -50,8 +50,26 @@
     pyf.close()
     return pypy_parse(source, 'exec', lineno)
 
+def internal_pypy_parse(source, mode='exec', lineno=False, flags=0):
+    builder = TupleBuilder(PYTHON_PARSER.rules, lineno=False)
+    target_rule = TARGET_DICT[mode]
+    PYTHON_PARSER.parse_source(source, target_rule, builder, flags)
+    stack_element = builder.stack[-1]
+    return (builder.source_encoding, stack_element)
+
+def parse_result_to_nested_tuples(parse_result, lineno=False):
+    """NOT_RPYTHON"""
+    source_encoding, stack_element = parse_result
+    nested_tuples = stack_element.as_tuple(lineno)
+    if source_encoding is not None:
+        return (symbol.encoding_decl, nested_tuples, source_encoding)
+    else:
+        return nested_tuples
+
 def pypy_parse(source, mode='exec', lineno=False, flags=0):
-    """parse <source> using PyPy's parser module and return
+    """
+    NOT_RPYTHON !
+    parse <source> using PyPy's parser module and return
     a tuple of three elements :
      - The encoding declaration symbol or None if there were no encoding
        statement
@@ -61,17 +79,10 @@
      - The encoding string or None if there were no encoding statement
     nested tuples
     """
-    builder = TupleBuilder(PYTHON_PARSER.rules, lineno=False)
-    target_rule = TARGET_DICT[mode]
-    PYTHON_PARSER.parse_source(source, target_rule, builder, flags)
-    stack_element = builder.stack[-1]
+    source_encoding, stack_element = internal_pypy_parse(source, mode, lineno=lineno, flags=lineno)
     # convert the stack element into nested tuples (caution, the annotator
     # can't follow this call)
-    nested_tuples = stack_element.as_tuple(lineno)
-    if builder.source_encoding is not None:
-        return (symbol.encoding_decl, nested_tuples, builder.source_encoding)
-    else:
-        return nested_tuples
+    return parse_result_to_nested_tuples((source_encoding, stack_element), lineno=lineno)
 
 ## convenience functions for computing AST objects using recparser
 def ast_from_input(input, mode, transformer):
@@ -95,20 +106,12 @@
 
     annotateme() is basically the same code that pypy_parse(), but with the
     following differences :
-     - directly take a list of strings rather than a filename in input
-       in order to avoid using file() (which is faked for now)
-       
+
      - returns a tuplebuilder.StackElement instead of the *real* nested
        tuples (StackElement is only a wrapper class around these tuples)
 
     """
-    builder = TupleBuilder(PYTHON_PARSER.rules, lineno=False)
-    PYTHON_PARSER.parse_source(source, 'file_input', builder)
-    nested_tuples = builder.stack[-1]
-    if builder.source_encoding is not None:
-        return (symbol.encoding_decl, nested_tuples, builder.source_encoding)
-    else:
-        return (None, nested_tuples, None)
+    return internal_pypy_parse(source, 'exec')
 
 
 if __name__ == "__main__":

Modified: pypy/dist/pypy/translator/ann_override.py
==============================================================================
--- pypy/dist/pypy/translator/ann_override.py	(original)
+++ pypy/dist/pypy/translator/ann_override.py	Thu Jul 21 02:07:59 2005
@@ -22,3 +22,8 @@
         from pypy.interpreter import pycode
         clsdef = getbookkeeper().getclassdef(pycode.PyCode)
         return annmodel.SomeInstance(clsdef)    
+
+    def override__cpy_stablecompiler(pol, self, parse_result, filename, mode):
+        from pypy.interpreter import pycode
+        clsdef = getbookkeeper().getclassdef(pycode.PyCode)
+        return annmodel.SomeInstance(clsdef)    



More information about the Pypy-commit mailing list