1.1 --- a/docs/rpython.txt Fri Nov 16 00:29:15 2012 +0100
1.2 +++ b/docs/rpython.txt Sat Jan 12 18:38:34 2013 +0100
1.3 @@ -1,6 +1,11 @@
1.4 Analysis of the PyPy Interpreter
1.5 ================================
1.6
1.7 +Analysis of PyPy is likely to be rather difficult because the method of
1.8 +collecting information about the interpreter's behaviour and characteristics
1.9 +initially involves introspection of the loaded program, thus taking advantage
1.10 +of the capabilities of any existing Python interpreter implementation.
1.11 +
1.12 Program used for analysis: pypy/pypy/bin/py.py
1.13
1.14 Errors
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/docs/syspython.txt Sat Jan 12 18:38:34 2013 +0100
2.3 @@ -0,0 +1,150 @@
2.4 +A Systems Programming Language Target for Micropython
2.5 +=====================================================
2.6 +
2.7 +Python-compatible syntax for processing using the compiler module.
2.8 +
2.9 +The principal focus is on specific machine code generation and not
2.10 +analysis. Thus, only block generation, address reference generation,
2.11 +temporary storage administration and other code generation tasks are to be
2.12 +left to the systems programming language compiler.
2.13 +
2.14 +Given that micropython has already deduced object and parameter details,
2.15 +such information must be communicated in the systems programming language
2.16 +so that the compiler does not have to deduce it again.
2.17 +
2.18 +Explicit constant declaration shall be done at the start of the main
2.19 +module:
2.20 +
2.21 + __constants__(...)
2.22 +
2.23 +Explicit structure declaration is still performed using class statements,
2.24 +but base classes are omitted and attributes are declared explicitly as
2.25 +follows:
2.26 +
2.27 + class C:
2.28 + __instattrs__(member...)
2.29 + __classattrs__(member...)
2.30 +
2.31 +Other object table information, such as inherited class attributes and
2.32 +class compatibility (to support isinstance) are also declared explicitly:
2.33 +
2.34 + __inherited__(superclass, member...)
2.35 + __descendants__(class...)
2.36 +
2.37 +Other than function definitions, no other code statements shall appear in
2.38 +class definitions; such statements will appear after classes have been
2.39 +defined in a __main__ function collecting together all "loose"
2.40 +(module-level) statements.
2.41 +
2.42 +Imports act as invocations of module code and name assignments within a
2.43 +particular scope and are defined as follows:
2.44 +
2.45 + # import package
2.46 + package.__main__()
2.47 + package = __module__(package)
2.48 +
2.49 + # import package.module
2.50 + package.__main__()
2.51 + package.module.__main__()
2.52 + package = __module__(package)
2.53 +
2.54 + # from package.module import cls
2.55 + package.__main__()
2.56 + package.module.__main__()
2.57 + cls = __loadattribute__(package.module, cls) # see below
2.58 +
2.59 +Since import statements can appear in code that may be executed more than
2.60 +once, __main__ functions should test and set a flag indicating whether the
2.61 +function has already been called.
2.62 +
2.63 +Python would arguably be more sensible as a language if imports were
2.64 +processed separately, but this would then rule out logic controlling the
2.65 +use of modules.
2.66 +
2.67 +Assignments and name usage involves locals and globals but usage is
2.68 +declared explicitly:
2.69 +
2.70 + __localnames__(...)
2.71 +
2.72 +At the function level, locals are genuine local name definitions whereas
2.73 +globals refer to module globals:
2.74 +
2.75 + __globalnames__(...)
2.76 +
2.77 +Although at the module level, locals are effectively equivalent to module
2.78 +globals, each module's __main__ function will declare them as globals.
2.79 +
2.80 +Such declarations must appear first in a program unit (module, function).
2.81 +For example:
2.82 +
2.83 + def f(a, b):
2.84 + __localnames__(a, b, x, y)
2.85 + __globalnames__(f, g)
2.86 +
2.87 + x = 1 # local
2.88 + y = x # locals
2.89 + a = b # locals
2.90 + g = f # globals
2.91 +
2.92 +No operator usage: all operators are converted to invocations, including
2.93 +all attribute access except static references to modules using the
2.94 +following notation:
2.95 +
2.96 + __module__(package)
2.97 + __module__(package.module)
2.98 + package.module # shorthand where dot notation is used
2.99 +
2.100 +In general, attribute access must use an explicit function indicating the
2.101 +kind of access operation being performed. For example:
2.102 +
2.103 + __loadaddress__(obj, attrname)
2.104 + __loadaddresscontext__(obj, attrname)
2.105 + __loadaddresscontextcond__(obj, attrname)
2.106 + __loadattr__(obj, attrname)
2.107 + __loadattrindex__(obj, attrname)
2.108 + __loadattrindexcontext__(obj, attrname)
2.109 + __loadattrindexcontextcond__(obj, attrname)
2.110 +
2.111 + __storeaddress__(obj, attrname, value)
2.112 + __storeaddresscontext__(obj, attrname, value)
2.113 + __storeattr__(obj, attrname, value)
2.114 + __storeattrindex__(obj, attrname, value)
2.115 +
2.116 +Conventional operators use the operator functions.
2.117 +
2.118 +Special operators could also use the operator functions (where available)
2.119 +but might as well be supported directly:
2.120 +
2.121 + __is__(a, b)
2.122 +
2.123 +Logical operators involving short-circuit evaluation could be represented
2.124 +as function calls, but the evaluation semantics would be preserved:
2.125 +
2.126 + __and__(...) # returns the first non-true value or the final value
2.127 + __not__(obj) # returns the inverse of the boolean interpretation of obj
2.128 + __or__(...) # returns the first true value or the final value
2.129 +
2.130 +Comparisons could be rephrased in a verbose fashion:
2.131 +
2.132 + a < b < c becomes lt(a, b) and lt(b, c)
2.133 + or __and__(lt(a, b), lt(b, c))
2.134 +
2.135 +Any statements requiring control-flow definition in terms of blocks must
2.136 +be handled in the language as the notions of labels and blocks are not
2.137 +introduced earlier apart from the special case of jumping to another
2.138 +callable (described below).
2.139 +
2.140 +Special functions for low-level operations:
2.141 +
2.142 + __check__(obj, type)
2.143 + __jump__(callable)
2.144 +
2.145 +Function/subroutine definition with entry points for checked and unchecked
2.146 +parameters.
2.147 +
2.148 + def fn_checked(self, ...):
2.149 + __check__(self, Type) # raises a TypeError if not isinstance(self, Type)
2.150 + __jump__(fn_unchecked) # preserves the frame and return address
2.151 +
2.152 + def fn_unchecked(self, ...):
2.153 + ...