Bootstrapping is the process of building up functionality of the system until
all Ruby code can be executed. There are eight stages to the bootstrap process:
1. VM: The virtual machine is able to load and execute bytecode, send messages
(i.e. look up and execute methods), and all primitive functions are
available, but not yet hooked up as Ruby methods.
2. alpha: This starts the loading of Ruby code. The ability to open classes
and modules and define methods exists. The minimum functionality to
support the following methods is implemented in kernel/alpha.rb:
attr_reader :sym
attr_writer :sym
attr_accessor :sym
private :sym
protected :sym
module_function :sym
include mod
Also, it is possible to raise exceptions and cause the running process to
exit. This stage lays the foundation for the next two stages.
3. bootstrap: This stage continues to add the minimum functionality to
support loading platform and common. The primitive functions are added for
most of the kernel classes.
4. platform: The FFI (foreign function interface) system is implemented and
Ruby method interfaces to platform-specific functions are created
5. common: The vast majority of the Ruby core library classes are
implemented. The Ruby core classes are kept as implementation-neutral as
possible. Also, most of the functionality for Rubinius specific classes
is added.
6. delta: Final versions of methods like #attr_reader, etc. are added. Also,
implementation-specific versions of methods that override the versions
provided in common are added.
7. compiler: The compiler files are loaded.
8. loader: The compiled version of kernel/loader.rb is run.
The files in the kernel directories bootstrap, platform, common, delta, and
compiler implement the respective bootstrapping stages above. The order in
which these directories are loaded is specified in runtime/index.
When an rbc file is loaded, code at the script level and in class or module
bodies is executed. For instance, when loading
class SomeClass
attr_accessor :value
end
the call to #attr_accessor will be run. This requires that any code called
in script, class, or module bodies must be loaded before the file that calls
the code is loaded. The kernel/alpha.rb defines most of the code that will be
needed at the script or module level. However, other load order dependencies
exist between some of the platform, common, delta, and compiler files.
These load order dependencies are addressed by the load_order.txt file located
in each of the kernel/** directories. If you modify code that adds a load
order dependency, you must edit the load_order.txt files to place the depended
on file above the file that depends on it. Also, if you add a new file to one
of the kernel directories, you must add the file name to the load_order.txt
file in that directory. These files are copied to the appropriate runtime/**
directories during build. During each of the bootstrap stages above, the VM
loads the files listed in load_order.txt in order.
## Kernel Coding Guidelines
The primary guideline for all kernel code is simple and efficient. Simple code
is often more efficient and generally more comprehensible. There should be no
metaprogramming code in bootstrap. Use the #attr_xxx methods throughout the
kernel source. Also, alias methods using the #alias_method call next to the
method definition. Specify private methods with the 'private :sym' method next
to the method definition. Remember that the versions of the methods listed
above in the alpha stage take a single, symbol argument.