crementally adding features from the
Étoilé runtime. Some features were
possible to add, others were not.
The GNUstep runtime is the spiritual successor to the Étoilé runtime,
and shares some of the code, but it was
designed to work as a drop-in replacement for the GCC runtime and so retains backward compatibility.
object model
To retain binary compatibility, the
GNUstep Objective-C runtime was not
able to adopt the same object model as
the Étoilé runtime. The Étoilé runtime
began with a prototype-based model
and then layered classes on top. Experimentation with prototype-based
languages, including JavaScript and
Self, indicated this level of flexibility
may not be necessary at the runtime
layer. Given a flexible prototype-based
language such as JavaScript, the first
thing a typical programmer does is
implement a less-flexible class-based
model on top. A large number of JavaScript frameworks provide off-the-shelf class models to make life easier
for JavaScript developers. Google’s
Dart—a language designed as a successor to JavaScript—returns to a
class-based model as the core model,
indicating its designers found a class-based model easier for most JavaScript programmers.
More interestingly, the places
where people actually do make use of
the full power of prototypes tend to be
relatively few and not in performance-critical code—for example, creating
one-off delegates for user-interface
objects. This corresponds to the findings of Apple’s Newton team, which
proposed using class-based languages
for models and prototype-based languages for views, eliminating the need
for controllers.
Both the Self virtual machine (VM)
and, more recently, the V8 JavaScript
VM from Google, use hidden-class
transforms. This technique maps
from a prototype-based model to a
class-based model. With this in mind,
it made more sense for the GNUstep
runtime to assist compilers wishing
to provide a prototype-based model,
rather than to provide such a model
directly.
The object model in the GNUstep
runtime is therefore largely the same
as the traditional GCC model but with
some important changes. In tradition-
al Objective-C, like Smalltalk, the first
instance variable of every object is the
isa pointer, which points to the ob-
ject’s class. In newer dialects of Objec-
tive-C, accessing this pointer directly
is deprecated in favor of calling a run-
time library function. This has a vari-
ety of advantages, described later, but
the first is that it means you can make
this pointer point to something else.
A runtime-supported notion of hid-
den classes is used to support proto-
types. A hidden class is visible only
from inside the runtime, so calls to
object _ getClass() will return
the superclass. This function is the
supported way for user code to look
up the class for an object and is used
in implementing the +class method.
This allows, for example, an object
to have a hidden class inserted and
a method modified, so only this in-
stance of the object and not any oth-
ers gain the method. The runtime also
supports a clone function, which cre-
ates a new object with a hidden class
that inherits from the original object,
allowing differential inheritance.
method Lookup
In any Smalltalk-family language such
as Objective-C, message sending takes
place in two conceptual steps. The first
is a mapping from a selector (method
name) to a function or closure implementing the method. The second is
calling that method.
These steps can be combined in several ways. In a very static language such