internals - Design and Implementation of Pipp
See pipp.pod on where to get the code.
Not decided yet. Will be documented in pipp.pod. See also ../ROADMAP.
See testing.pod.
Parsing is done with Parrot Compiler Toolkit, PCT.
The parse tree is transformed to a Parrot Abstrace Syntax Tree. PIR und Bytecode is then generated from the PAST.
No return value.
Always returns 1.
List of scopes and types of variables.
- variables outside a function in top file
-
Lexical. Might need extra treatment.
- variables outside a function in included files
-
Lexical in scope of the included file.
- variables declared as 'global' in functions
-
Lexical in outer scope. TODO: not sure of that
- variables declared as 'static' in functions
-
????
- Class constants
-
Class constants are stored a package variables in the namespace
$?NS ~ '\\' ~ $ ?CLASS ~ '::'. The trailing '::' guarantees that there is no conflict with namespace constants.TODO: make them readonly
- Static class members
-
Like class constants, but writable.
- Class members
- function and method scope
-
Lexical is scope of the function or method.
- $this
-
Bound to register
self
. - constants
-
Currently constants are stored in the hash ['pipp'; 'php_constants']. The functions
define
anddefined
access this package scoped hash. This approach works good enough for constants in the global namespace. For namespaced constants the above approach could be extended to consider the namespace part of the constant, the current namespace and the active namespace aliases.Another approach is to treat constants as namespaced variables and work with standard PAST techniques. Experiments using that approach are underway.
TODO: type hints in function declarations
There is a major bug in the implementation. TODO: see t/php/closures.t
A namespace is introduced with the keyword namespace. The namespaced code can be enclosed in brackets. The namespace declaration needs to be the first statement in the file. With brackets, there can be multiple namespaces per file. Nesting is not possible. Namespaces don't carry over to included files. define() doesn't define in the current namespace. The backslash character serves as the namespace separator. Short names can be defined with use. Only classes, functions and constants are namespaced. The current namespace can be queried with __NAMESPACE__. Namespaces are case insensitive. No global code can precede the first namespace directive.
In order to ease implementation and testing, there are some divergences in Pipp.
- Only the bracketed syntax is supported.
- Code outside the scope of namespaces directives is allowed.
- 'const' outside a declared namespace is allowed.
- http://docs.php.net/manual/en/language.namespaces.php
- http://docs.php.net/manual/en/language.namespaces.faq.php
- http://wiki.php.net/rfc/namespaces
- http://wiki.php.net/rfc/namespaceseparator
- http://wiki.php.net/rfc/backslashnamespaces
- http://wiki.php.net/rfc/namespacecurlies
- http://wiki.php.net/rfc/namespaceref
- http://inside.webfactory.de/en/blog/php-namespaces-explained.html
- http://marc.info/?l=php-internals&m=121527668606247
- http://bugs.php.net/bug.php?id=46304
- http://loveandtheft.org/2008/10/26/set-sail-for-fail-php-namespaces/
require_once()
is supported, but might have issues with variables.
Currently, Pipp has no support at all for extensions.
L<http://www.amazon.com/Extending-Embedding-PHP-Developers-Library/dp/067232704X/>
L<http://www.php.net/manual/en/internals2.php>
L<http://www.projectzero.org/zero/sebring/latest/docs/zero.devguide.doc/zero.php/ExtendingPHP.html>
Using Modules from other HLLs. Inlining PIR and other languages.
See pipp.pod for a list of divergences.
See the Wiki. Roadsend, Zend, PHC.
Bernhard Schmalhofer - <Bernhard.Schmalhofer@gmx.de>