views:

609

answers:

3

Hi guys,

I would really appreciate it anybody could briefly explain me, what's the general approach to implementing things like MonoTouch? I'm really amazed because it's not the first example I see when people get some platform like Java and make it translate into something like C/Objective-C. I can't really imagine how things like Garbage collector and stuff are being translated.

Thanks in advance.

EDIT: I understand theoretical possibility of translating one language into another. My question is a bit more technical: do they implement a complete runtime in ObjC and bundle it? (I doubt it...) Or they just translate C# code into ObjC/binary/etc?

A: 

Monotouch is presumably a port of Mono to the iPod.

Mono itself is an open source implementation of the .NET runtime (and some dev tools) in various *nix environments.

This was a massive labour led by Miguel de Icaza who realised early the importance of .NET and set about porting it to open platforms. Incidently he receieved a great deal of support from MicroSoft itself as MONO gave ineteroparability between native .NET and mono.

So the first answer is you need to be a well organised, hard working genius.

The second answer is more Comp Sciency. "Turing Complete" is a the minimum set of functions that a system needs to be considered a programable computer. Its actualy a very small set -- subtract, compare, branch and read and store.

The theory is that any "Turing Complete" system can do anything any other "Turing Complete" system can do. So given any reasonably complete programming language environment you should be able to emulate it using another program environment.

There are numerous examples of this around. Jpython runs the emulates C python in a Java JVM. My two personal favourites are which runs original zX spectrum games in your browser and Knuth MIX assembeler machine both of which are pure javascript.

James Anderson
Thank you for the answer! However, I'm aware of Turing completion and other comp-science-related stuff, but my question is a more technical: how do they do it? Do they just implement a runtime and somehow bundle it into the app? Or what?
Anton
They start with the standard, which specifies what components need to be present in a .NET environment and then they implement those components such that they comply with the standard.
Eric
I understand that. But again, HOW MonoTouch app, being written in .NET , runns on iPhone? They have a runtime there? Or they just somehow translate this into Obj-C/Arm Asm/whatever?
Anton
Mono touch is not .NET. Its an implementation of the .NET runtime environment. At the begining of the Mono project .NET was reverse engineered -- they looked at the APIs and generated code and worked out what the runtime environement did, about half way through MS gave them the documentation for the file formats etc. so they could work to spec. Twoards the end these were published as an ECMA standard so anyone could write one.
James Anderson
+3  A: 

Monotouch uses Ahead-Of-Time compilation to produce a single statically compiled file - so it does not implement the .Net runtime on the iPhone. Monotouch uses binding to the iPhone libraries exposed to C#. There is no translation to Objective-C.

Basically, it gives you the familiarity of working in C# and its associated toolchain while exposing the library calls of the underlying iPhone OS.

Miguel di Icaza explained this a bit on the Stackoverflow podcast where he was a guest. link

Ankur Goel
+7  A: 

MonoTouch isn't a translator. It's simply the Mono runtime running on iPhone, with some fancy trickery to make it compatible with the iPhone's restrictions.

The conventional Mono "runtime" isn't just the JIT, it also handles GC, reflection, I/O layer, threading, exceptions etc. There's also the class libraries. In order for your app to run on the iPhone, much of this must be included with the app. Slimming it down presents some challenges. In addition, the iPhone prevents JIT runtime code generation, only runs signed code, and doesn't allow dynamic libraries.

What MonoTouch does is to use an IL linker to combine just the parts of the class libraries that your code uses into a single IL binary. It then uses AOT compilation to pre-generate all the native code that the JIT would normally generate from the IL, then links this together with the JIT-less runtime into a single native binary that can be signed. Finally, the IL is stripped from the managed binary. leaving only metadata.

mhutch