add library implementation note

This commit is contained in:
Yuichi Nishiwaki 2013-12-04 20:33:24 +09:00
parent 43dccb30a4
commit c7f4d6e791
1 changed files with 15 additions and 0 deletions

15
etc/LIBRARY_IMPL.md Normal file
View File

@ -0,0 +1,15 @@
# How to implement `define-library`?
* define-library can be nested
* expressions inside define-library are compiled and evaluated in order sequentially
* import declarations inside define-library and on the top level are semantically the same
* each define-library creates one syntactic-env
* and the body is evaluated as if it's on the top level
* so each `toplevel definitions`' results are registered to the global table
* but their renamed symbols are known only to who imported the library.
## export table
* import syntax destructively registers renamed symbols taken from export table of the specified library to syntactic env of the library
* export syntax registers correspoindings of original and renamed symbols to export table of the current library
* therefore, we need some kind of `forward declaration` support, because export syntax is usually placed at the beginning of source code.