" Smalltalk/kernel.st -*- Smalltalk -*- " " The compiler creates literals by sending #_value: to the appropriate primitive prototype object. Before importing real class definitions, bootstrap just enough implementation so that this will work for SmallInteger, String and BlockClosure. Note that (non-inlined) blocks cannot be created until BlockClosure is defined, literal Symbols cannot be created until Set is defined, and Characters cannot be created until Array is defined. Note also that when declaring a prototype 'Foo', the compiler defines the following implicitly: Foo -- a global variable containing the prototype object Foo _sizeof -- answers a C int containing the prototype's size Foo _debugName -- answers a C string containing the prototype's name " " Sufficient hierarchy to reach SmallInteger, BlockClosure, and Immutable{String,[Byte]Array}. " Object () UndefinedObject : Object () StaticBlock : Object ( _function _arity) BlockClosure : StaticBlock ( receiver _state outer ) BlockClosureNLR : BlockClosure ( _envp ) Magnitude : Object () Number : Magnitude () Integer : Number () SmallInteger : Integer () Collection : Object () SequenceableCollection : Collection () ArrayedCollection : SequenceableCollection ( size _elements ) Array : ArrayedCollection () ImmutableArray : Array () ByteArray : ArrayedCollection () ImmutableByteArray : ByteArray () String : ByteArray () ImmutableString : String () [SmallInteger _beTaggedType] [UndefinedObject _beNilType] " Boolean false is nil (oop zero), everything else is true. Note the compiler provides uninitialised globals called 'true', 'false' and 'nil' (which is totally bogus, but makes life simpler). " [ true := Object ] [ false := nil ] " Object allocation. " Object _clone: _size { return _clone(self, (int)v__size) } Object _clone [ ^self _clone: self _sizeof ] " Literal SmallIntegers. " SmallInteger _value: _value { return _integerObject((int)v__value); } SmallInteger _integerValue { return (oop)_integerValue(self); } " Literal Strings. " String _value: _value [ self := self _clone. { struct t_String *this= (struct t_String *)self; int size= strlen((char *)v__value); this->size= _integerObject(size); this->_elements= _newBytes(size); memcpy(this->_elements, v__value, size); } ] String _stringValue { return ((struct t_String *)self)->_elements; } String size [ ^size ] " Bogus printing for debugging. " Object newln { printf("\n"); return 0; } Object println [ self print; newln ] Object print [ self debugName print ] Object debugName [ ^String _value: self _debugName ] UndefinedObject _debugName { return (oop)"nil"; } SmallInteger print { printf("%d", (int)self >> 1); return 0; } String print { struct t_String *this= (struct t_String *)self; int size= _integerValue(this->size); char *elements= (char *)this->_elements; int i; for (i= 0; i < size; ++i) if (isprint(elements[i]) || ('\n' == elements[i]) || ('\t' == elements[i])) putchar(elements[i]); else printf("\\%03o", elements[i]); return 0; } " Smalltalk bindings to the runtime system. NOTE: uncomment the following line to enable. " { import Smalltalk/runtime } " The real kernel Smalltalk hierarchy. " { import Object } { import UndefinedObject } { import BlockClosure } { import Association } { import Collection } { import SequenceableCollection } { import OrderedCollection } { import SortedCollection } { import ArrayedCollection } { import Array } " Object " { import Magnitude } { import Number } { import Integer } { import SmallInteger } { import Character } " Object " " Collection " " SequenceableCollection " " ArrayedCollection " { import WordArray } { import ByteArray } { import String } " Object " " Collection " { import Set } { import IdentitySet } { import Dictionary } { import IdentityDictionary } " Object " " Collection " " SequenceableCollection " " ArrayedCollection " " ByteArray " " String " { import Symbol } " Object " { import Stream } { import PositionableStream } { import ReadStream } { import WriteStream } " Object " { import Smalltalk }