help-smalltalk
[Top][All Lists]

## [Help-smalltalk] Bootstrapping a Smalltalk image

 From: Paolo Bonzini Subject: [Help-smalltalk] Bootstrapping a Smalltalk image Date: Wed, 30 Jan 2008 17:41:56 +0100 User-agent: Thunderbird 2.0.0.9 (Macintosh/20071031)

Mathieu Suen wrote:


Now it work.
I was looking for how do you booostrap the system.
Do you have some doc, paper on it?


The source code is dict.c and files.c.  Here is a short LaTeX document
that describes it (you can of course read it from here).

Paolo

\documentclass{article}
\usepackage{hyperref}
\begin{document}

\newcommand{\code}[1]{%
\texorpdfstring{%
{\texttt{\hyphenchar\font=-%
\begingroup\protect\frenchspacing#1\endgroup}}}{%
#1}}

Unlike most other image-based Smalltalk systems, GNU Smalltalk is
able to create an image from scratch, only starting from the
definitions of the base classes and the source code to them (that is,
the definitions are not expressed as Smalltalk source code, but
separately).  Other systems, instead, always create an image from a
pre-existing one, possibly stripping out unneeded components.

The bootstrapping process is complex due to the necessity of
recreating the parallel hierarchy of classes and metaclasses, and then
merging them together.

First of all, the system creates the builtin objects (nil, true, false
and the 256 instances of \code{Character}).  The pointer to their
class is not known yet, but the system can store pointers to them even
if they are still in an embryonal state: it is easier to plug the 259
pointers to the classes \code{UndefinedObject}, \code{True},
\code{False} and \code{Character}, than to put back all the pointers
to \code{nil} where they are needed.

As mentioned, the virtual machine code contains the description on the
core classes\footnote{It would be possible to load them from an
external source, with a parser for a subset of Smalltalk or from an
XML description.}.  The hierarchy tree is visited breadth-first,
creating classes and metaclasses along the way.  A few fields are
initialized in class objects: the superclass field, the pointer to the
metaclass, and the \code{instanceSpec}. This is enough for the system to
create their instances.

Now, builtin objects are given a class and other objects can be
created: these include namespaces, and some \code{VariableBinding}
objects through which the virtual machine can pass some information
about the system to the Smalltalk code\footnote{Such as the underlying
operating system, or \code{sizeof(void *)}.}.  C code manipulates
namespaces and fills them with \code{VariableBinding} objects for the
classes.

The remaining fields of class and metaclass objects are filled in,
including linking metaclasses back to their sole instance, making
Metaclass the class of metaclasses and making Class the superclass of
Object class'.

In order to compile the source code for the core classes, GNU
Smalltalk includes a compiler written in C.  This compiler is invoked
once manually to compile the \code{methodsFor:} primitive, and then to
file in the sources for the kernel. As more and more classes are loaded,
the system takes shape: later on, it will be complete enough to be able
to create new classes, and possibly to run another compiler which is
written in Smalltalk.  At this point, the system has bootstrapped.

\end{document}