# HG changeset patch # User Paul Boddie # Date 1358012314 -3600 # Node ID 83db2cdbc1d082c77aeea668745676a565578792 # Parent 8718a18bb7018464cf27f5fb393b02201f8e5c4c Added notes about a systems programming language to target instead of RSVP. Added a note about the problems with trying to perform analysis on PyPy code. diff -r 8718a18bb701 -r 83db2cdbc1d0 docs/rpython.txt --- a/docs/rpython.txt Fri Nov 16 00:29:15 2012 +0100 +++ b/docs/rpython.txt Sat Jan 12 18:38:34 2013 +0100 @@ -1,6 +1,11 @@ Analysis of the PyPy Interpreter ================================ +Analysis of PyPy is likely to be rather difficult because the method of +collecting information about the interpreter's behaviour and characteristics +initially involves introspection of the loaded program, thus taking advantage +of the capabilities of any existing Python interpreter implementation. + Program used for analysis: pypy/pypy/bin/py.py Errors diff -r 8718a18bb701 -r 83db2cdbc1d0 docs/syspython.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/syspython.txt Sat Jan 12 18:38:34 2013 +0100 @@ -0,0 +1,150 @@ +A Systems Programming Language Target for Micropython +===================================================== + +Python-compatible syntax for processing using the compiler module. + +The principal focus is on specific machine code generation and not +analysis. Thus, only block generation, address reference generation, +temporary storage administration and other code generation tasks are to be +left to the systems programming language compiler. + +Given that micropython has already deduced object and parameter details, +such information must be communicated in the systems programming language +so that the compiler does not have to deduce it again. + +Explicit constant declaration shall be done at the start of the main +module: + + __constants__(...) + +Explicit structure declaration is still performed using class statements, +but base classes are omitted and attributes are declared explicitly as +follows: + + class C: + __instattrs__(member...) + __classattrs__(member...) + +Other object table information, such as inherited class attributes and +class compatibility (to support isinstance) are also declared explicitly: + + __inherited__(superclass, member...) + __descendants__(class...) + +Other than function definitions, no other code statements shall appear in +class definitions; such statements will appear after classes have been +defined in a __main__ function collecting together all "loose" +(module-level) statements. + +Imports act as invocations of module code and name assignments within a +particular scope and are defined as follows: + + # import package + package.__main__() + package = __module__(package) + + # import package.module + package.__main__() + package.module.__main__() + package = __module__(package) + + # from package.module import cls + package.__main__() + package.module.__main__() + cls = __loadattribute__(package.module, cls) # see below + +Since import statements can appear in code that may be executed more than +once, __main__ functions should test and set a flag indicating whether the +function has already been called. + +Python would arguably be more sensible as a language if imports were +processed separately, but this would then rule out logic controlling the +use of modules. + +Assignments and name usage involves locals and globals but usage is +declared explicitly: + + __localnames__(...) + +At the function level, locals are genuine local name definitions whereas +globals refer to module globals: + + __globalnames__(...) + +Although at the module level, locals are effectively equivalent to module +globals, each module's __main__ function will declare them as globals. + +Such declarations must appear first in a program unit (module, function). +For example: + + def f(a, b): + __localnames__(a, b, x, y) + __globalnames__(f, g) + + x = 1 # local + y = x # locals + a = b # locals + g = f # globals + +No operator usage: all operators are converted to invocations, including +all attribute access except static references to modules using the +following notation: + + __module__(package) + __module__(package.module) + package.module # shorthand where dot notation is used + +In general, attribute access must use an explicit function indicating the +kind of access operation being performed. For example: + + __loadaddress__(obj, attrname) + __loadaddresscontext__(obj, attrname) + __loadaddresscontextcond__(obj, attrname) + __loadattr__(obj, attrname) + __loadattrindex__(obj, attrname) + __loadattrindexcontext__(obj, attrname) + __loadattrindexcontextcond__(obj, attrname) + + __storeaddress__(obj, attrname, value) + __storeaddresscontext__(obj, attrname, value) + __storeattr__(obj, attrname, value) + __storeattrindex__(obj, attrname, value) + +Conventional operators use the operator functions. + +Special operators could also use the operator functions (where available) +but might as well be supported directly: + + __is__(a, b) + +Logical operators involving short-circuit evaluation could be represented +as function calls, but the evaluation semantics would be preserved: + + __and__(...) # returns the first non-true value or the final value + __not__(obj) # returns the inverse of the boolean interpretation of obj + __or__(...) # returns the first true value or the final value + +Comparisons could be rephrased in a verbose fashion: + + a < b < c becomes lt(a, b) and lt(b, c) + or __and__(lt(a, b), lt(b, c)) + +Any statements requiring control-flow definition in terms of blocks must +be handled in the language as the notions of labels and blocks are not +introduced earlier apart from the special case of jumping to another +callable (described below). + +Special functions for low-level operations: + + __check__(obj, type) + __jump__(callable) + +Function/subroutine definition with entry points for checked and unchecked +parameters. + + def fn_checked(self, ...): + __check__(self, Type) # raises a TypeError if not isinstance(self, Type) + __jump__(fn_unchecked) # preserves the frame and return address + + def fn_unchecked(self, ...): + ...