Module system
Sunday, June 18, 2006
I got sick of having to load dependencies in the right order when
running stuff in contrib/
, so I coded a simple module system.
You can load a module and all dependencies in the listener using the
REQUIRE:
parsing word:
REQUIRE: crypto
This searches for the following files:
contrib/crypto.factor
contrib/crypto/load.factor
A module definition looks like so:
REQUIRES: math ;
PROVIDE: crypto {
"common.factor"
"base64.factor"
"barrett.factor"
"montgomery.factor"
"random.factor"
"miller-rabin.factor"
! Rngs
"blum-blum-shub.factor"
! Hash
"crc32.factor"
"md5.factor"
"sha1.factor"
! Block ciphers
"rc4.factor"
! Public key
"rsa.factor"
} ;
The REQUIRES:
parsing word lists required modules which are loaded
first if they are not already loaded, and PROVIDE:
defines a module
along with its consitutuent files, which are then loaded.
Note that REQUIRE:
takes one module name and is designed for
interactive use, because it recompiles all words after the module has
been loaded. REQUIRES:
does no such thing, and takes multiple module
names; it is designed for use in a load.factor
file.
You can force a module to reload during development:
"x11" reload-module
Another advanced feature is that PROVIDE:
can actually take a second
list of files, which define unit tests:
PROVIDE: concurrency
{ "concurrency.factor" }
{ "concurrency-examples.factor" "concurrency-tests.factor" } ;
Tests can then be run with "concurrency" test-module
or just
test-modules
to test every loaded module.
Future improvements that I plan to implement is using the module system
to organize the core library (the list of files in boot-stage1.factor
is getting rather long), and an UI tool for browsing loaded modules and
loading new modules.
In the long term, the number of contributed libraries may or may not grow to a point where we can switch to a decentralized system, perhaps using a Wiki to store module meta-data and download URLs, together with an automatic downloader tool in Factor (along the lines of ASDF-Install for Common Lisp).
Factor 0.83 looks like a really nice release. I’m disappointed that there won’t be a Windows package this time round – Doug Coleman is on vacation. If you are interested in seeing Factor run better on Windows, please contribute!