[Mono-list] Making a ruby.net compiler

Miguel de Icaza miguel@ximian.com
10 May 2003 20:49:01 -0400


Hello,

   Turns out, that I rewrote my example before sending this off, so my
comments do not make a lot of sense:

> 	Type t = typeof (o);
> 	if (t == typeof (List)){
> 		List l = (List) o;
> 	} else if (t == typeof (Atom)){
> 		Atom a = (Atom) o; 
> 	} else {
> 		Its some other kind.
> 	}
> 
>     You would inform the runtime about this:
> 
> 	System.Runtime.FastCast (typeof (List));
> 	System.Runtime.FastCast (typeof (Atom));
> 
>     The runtime could reserve a few bits in the pointer.  The lower two
> bits are ideal, the combination "00" means `normal object', and the
> other three combinations 01, 10 and 11 map to special classes.
> 
>     So then the assembly language code for "o is List" instead of
> involving a call to an expensive routine, becomes:

The above should read "t = typeof (o)" instead of "o is List".

> 	mov $eax, o
> 	test $eax, 1
> 	jne 1f
> 	mov $eax, type_of_list_constant
> 	jmp 3f
> 1:
> 	test $eax, 2
> 	jne 2f
> 	mov $eax, type_of_atom_constant
> 	jmp 3f
> 2:
> 	call runtime_type_get_type_of_object
> 3:
> 
>    The GC probably has to be modified to cope with this.

Miguel