TOM: A LITTLE HISTORY

    first definition Nov 16 1995

    object oriented

	descendent of Objective-C
	    safer `C'
	    richer `Objective'

	some `features' from other languages
	    Eiffel, Common Lisp

    fully defined

    goals

	usability
	    vs. reusability

	exploit non-atomicity of class definition
	    at compile time
	    at link time
	    at run time
		early
		late
EXAMPLE CODE 1

    implementation class HelloWorld

    int
      main Array arguments
    {
      [[[stdio out] print "Hello, world!"] nl];

      return 0;
    }

    end;

    implementation instance HelloWorld end;

PROGRAM COMPONENTS

    unit `hello'
	file `hello.t'
	    class HelloWorld

    unit `tom'
	file `streams.t'
	    class stdio
	    ...
	...

    a unit defines a namespace
EXAMPLE COMPILATION

    gi -u hello -U tom hello.t
	create unit file

    gi
	update interface files

    otmc hello
	compile: translate hello.t to hello.c

    gcc -c hello.c
	compile TOM compiler output

    otmr
	resolve: create (partial) runtime data structures

    gcc -c hello-r.c
	compile TOM resolver output

    gcc -o hello hello.o hello-r.o /home/tiggr/tom/tom.o /home/tiggr/tom/trt.o
	link with `tom' unit and TOM runtime library (and libc)
EXAMPLE CODE 2

    implementation class Counter: State end;
    implementation instance Counter
    {
      public int value;
    }

    id
      init
    {
      value = 0;

      = [super init];
    }

    int
      nextValue
    {
      = ++value;
    }

    end;

    Counter c = [[Counter alloc] init];
    int i = [c nextValue];
    int j = [c value];
METHODS

    dynamic binding

	generalized virtual tables

	example
		int a = [foo bar 123];

	    becomes

		a = lookup (foo, `int "bar" int')
			 (foo, `int "bar" int', 123)

    implicit arguments

	self	receiving object
	cmd	selector

    overloaded on argument and return types

        in this context, all objects share same type

            avoid multi-dispatch
OBJECTS

    hierarchy
	strict distinction between classes and instances
	every class defines distinct type (actually 2 types)
	stateless instances can be inherited by classes
	    protocols/signatures/interfaces done right
	multiple inheritance
	    repeated == shared

    class variables
	inherited
	static
	local static

    all objects reside on a garbage collected heap

    no direct instance variable access
	other than through `self' or `isa'

    class definition not atomic
	amend library objects for specific application
	extensions:
	    add or replace methods
	    add static class variables
	    add instance variables (restricted at run-time)
	    add non-static class variables (not at run-time)
METHOD EXAMPLES

	    int
	      multiply int a
		    by int b
	    {
	      = a * b;
	    }

    int c = [foo multiply 6 by 9];

	    (int, int)
	      divmod (int, int) (a, b)
	    {
	      return (a / b, a % b);
	    }

    int dv, md;
    (dv, md) = [foo divmod (8, 3)];

	    MutableArray
	      componentsSeparatedBy char c
			     limit: int limit = -1
		      excludeEmpty: boolean excl = NO;

    ["/aap/noot/mies" componentsSeparatedBy '/' excludeEmpty: YES];
TYPES

    classes

    byte, char, int, long, float, double
	range and precision is defined

    boolean

    id

    tuples

	(a, b) = (b, a);

    class (..), instance (...)

	extern instance (id)
	  alloc;

    selector
	message identification
	examples: (ii)_divmod_(ii), r_alloc

    pointer
	void *

    dynamic
ENCAPSULATION

    protection of class and instance variables

	usual: protected, private

	public int foo;

	    int
	      foo
	    {
	      = foo;
	    }

	mutable int foo;

	    void
	      set_foo int i
	    {
	      foo = i;
	    }
CONSTRUCTING OBJECTS

    construction == allocation and initialization

	Design design1 = ...
	Block n = [[Block alloc]
		   initWithName "box1" inDesign design1];

    initializing super classes:

	implementation class Block: Named, DesignElement end;

	implementation instance Block
	{
	  ... 
	}

	id
	  initWithName String name
	      inDesign Design design
	{
	  if (![super initWithName name]
	      || ![super initInDesign design])
	    return nil;
	  return self;
	}

	end;
CONSTRUCTING OBJECTS, CONTINUED

    convenience object creation method:

	instance (id)
	  withName String name
		in Design design
	{
	  = [[self alloc] initWithName name
			  inDesign design];
	}

    in use:

	Block n = [Block withName "box1" in design1];

    compared with constructors

	conventional

	flexible

	readable
METHOD CONDITIONS

    conditions inherited by overriding methods in subclasses

    optionally compiled in (default yes)

    optionally checked at run time (default no)

    from MutableDictionary:

	void
	  set All value
	   at All key
	pre
	  value != nil && key != nil;

    from All:

	boolean (result)
	  equal id other
	post
	  self == other -> result
	{
	  = self == other;
	}
METHOD CONDITIONS, CONTINUED

    from ObjectArray:

	<doc> Return the object at {index} in the receiving array.  </doc>
	extern Any
	  at int index
	pre
	  index >= 0 && index < length
	post
	  length == old length;
ARCHIVING

    binary format with versioning

    example coding from IntNumber class:

	void
	  encodeUsingCoder Encoder coder
	{
	  if (![coder hasBeenCodedFor [IntNumber self]])
	    {
	      [super encodeUsingCoder coder];
	      [coder encode value];
	    }
	}

	void
	  initWithCoder Decoder coder
	{
	  if (![coder hasBeenCodedFor [IntNumber self]])
	    {
	      [super initWithCoder coder];
	      value = [coder decode];
	    }
	}
 
    generalization: distributed objects

    future: automatic for trivial (== usual) case
OTHER FEATURES

    forwarding

    introspection

    CL-style exceptions

    decent library

	array, hashtable, heap, set, dictionary, list, trie
	numbers, strings, unique strings, byte encodings
	streams, date, thread, locks, invocation
	extension, archiving

	tcp/ip ports, event dispatcher, distributed objects (exp)

    <doc> Structured Comments.  </doc>

    C interface
	to
	    <c>
	    #include <math.h>
	    y = sin (x);
	    </c>
	from

	    tom_object pi = TRT_SEND ((tom_object), CREF (DoubleNumber),
				      SEL (r_with_d), (tom_double) 3.14159265);
MAINTAINABILITY

    `nothing' is implicit

    `nothing' is explicit

    no operator overloading

	example: `+' on lists

	    list: append, list, nconc?

	    element: prepend, append?

	    list as element?
ADVANTAGES

    simple

    safe

    dynamic


DISADVANTAGES

    no `shared units' (yet)

    resolver run time

    dynamic dispatch
FUTURE

    rewrite compiler in TOM

    whole-program compilation

	optional static binding, inlining, etc.

	    limits possibilities for dynamic loading

    generational garbage collector

	avoid spending time on large unchanging data structures

    expanded classes?
