next up previous
Next: Text Composition Up: The Design and Implementation Previous: String and Symbol Representation

Implicit Conversion

In the m17n image, there are two classses for kinds of characters and two concrete classes for strings. How are they used?

Figure 2: #at:put: is being sent to a String with a MultiCharacter as the argument. The #at:put: primitive fails because of type mismatch. The backup code creates an equivalent copy of MultiString and then becomeForward itself to the newly created instance.
\scalebox{0.6}{\includegraphics{become.eps}}

Similar to the implicit conversions between SmallIntegers and the large integers, Character and MultiCharacter, String and MultiString are chosen appropriately. Namely, if a created instance is representable as an instance of ``smaller'' class, usually the instance of that class is created.

For MultiCharacters, we potentially create multiple instances that share the same code point. The original Character uses the ``flyweight pattern''[8] which create 256 immutable instances beforehand and all subsequent ``instance creation'' method returns the pointer to those instances. However, for MultiCharacters, pre-creating all instances would not use memory efficiently. This sounds as though the system may end up with another space problem by creating unnecessary MultiCharacter instances. However, in practice, there are not many MultiCharacter instances in the system at any given time.

The conversion between String and MultiString is not as easy as for characters. When you want to put a MultiCharacter into a String, the String instance first becomeForward:s itself into a newly created instance of MultiString whose elements are equal to the string, and then the value of MultiCharacter is stored into the MultiString instance. See the figure 2.

Down converting to String from MultiString can't be ``optimal.'' Usually, a MultiString will remain a MultiString indefinitely. However, when the Compiler parses a string literal in a MultiString and finds that it can be representable as String, it creates a String instance. Thus, a String literals can be created in code that was edited as a MultiString.


next up previous
Next: Text Composition Up: The Design and Implementation Previous: String and Symbol Representation
Owner 2003-02-08