[Mono-list] Re: Is Objective-C support possible?

Miguel de Icaza miguel@ximian.com
15 Feb 2002 19:44:47 -0500


> This article suggests it would be impossible to write an Objective-C or TOM compiler for .NET or any .NET clones. Can anybody clarify this issue?
> 
> http://www.javalobby.org/clr.html

Implementing Objective-C in .NET is possible.    Indeed, trivial.

What people do not seen to realize (and they keep banging on this) is
that the Common Type System (CTS) and the Common Language Specification
(CLS) provide a system and a framework for inter-operation.

You are free to follow or ignore those rules, that is up to you.  For
example, lets say the MiguelLisp language is pure and wont even attempt
to follow the CTS or CLS, but I can still use .NET objects with a
special `dotnetcall', so I could do things like:

	(dotnetcall "String.IndexOf" "miguel" "g")

Sure, it does not look as nice as other constructs in MiguelLisp, but
that is not the point.  The point that the dude in JavaLobby is trying
to make that .NET is just a bunch of "skins" on top of .NET is
incorrect.

That being said, the technical details:  He is probably referring to the
fact that in Objective-C you can "add" new methods to the base classes. 
This trick is doable, because calls like this:

	id object;
	[object setTitle: "Hello"];

Are actually translated to something like this:

	method = objc_method_lookup (object, "setTitle:");
	(*method)("Hello");

All the "Objective-C" magic happens in a runtime function called
"objc_method_lookup".  This function should be able to return a pointer
to a function.  The question is: is .NET capable of:

	1. Returning a pointer to a method.
	2. Calling a method from this pointer.

The answer to both of those is yes.  Surprise!  You can implement
objc_method_lookup trivially.

It is a construct not supported directly by the virtual machine, but
hey, operator overloading is not supported by the virtual machine
either, it is a language abstraction that can be mapped into the
underlying execution engine.  

For example, when you overload "+" in C#, the virtual machine will not
redefine the semantics of the "add" opcode.  Instead it will have to
perform a number of steps to map things like "a + b" into a call to your
overloaded operator.

Writing an Objective-C compiler is just a matter of time.  There is no
technological barrier.

Miguel.