[Grace-core] Modules description

Michael Homer mwh at ecs.vuw.ac.nz
Tue Nov 15 16:15:01 PST 2011


Hi,
James asked for a description of how my module system works at the
moment, so here it is. There isn't any particular design to it; the
arrangement is really more for breaking up the code of the compiler
into manageable chunks pending the specification of the actual module
system. At the moment it also allows for separate compilation. The
short version is that modules present as objects to the outside and
internally like a file of code run top-to-bottom (Python-like).

- A module is a single file of code, modulename.grace, containing any
code at all.
- When a module is imported (using "import modulename"), the
"modulename" is bound to an object. Every method defined in the
top-level scope of that file is defined on the module object.
- The module file can also contain code other than definitions, which
is executed on import. That code can invoke other methods and define
local vars and defs. Those are not exported.
- "self" inside the module is bound to the module object itself.
- All import sites get the same module object bound.
- Type information does not (currently) cross module boundaries.

That is how it stands at the moment. All the backends should have the
same semantics for them, although user code in the JavaScript backend
demonstration is always compiled in its own unnameable module. It has
mostly been put together to allow partial recompilation during
development and keep the code files to somewhat reasonable lengths.
-Michael


More information about the Grace-core mailing list