tags:

views:

496

answers:

5

I was wondering if there was a .NET-compatible CLR that was implemented using the CLI (common language infrastructure), e.g., using .NET itself, or at least if there were any resources that would help with building one.

Basically, something like a .NET program that loads assemblies as MemoryStreams, parses the bytecode, constructs the types, and executes the instructions. Optionally, it can JIT-compile to standard IL using Reflection.Emit or however.

I don't want to compile a .NET language to be run by the original CLR. I want a CLR that's written in a .NET language (not unmanaged C++ or C as it usually is) and runs CIL. If done right, it should be able to run itself.

Any thoughts on using Mono.Cecil for this kind of thing?

A: 

Look at the System.Reflection.Emit namespace, specifically the ILGenerator class.

You can emit IL on the fly.

http://msdn.microsoft.com/en-us/library/system.reflection.emit.ilgenerator_members.aspx

FlySwat
Not what I'm looking for. I want to execute IL, not compile C#.
Mark Cidade
Perhaps do a little research before downmodding me.
FlySwat
I didn't downmod you and even then you had a different answer (i.e., CodeDom)
Mark Cidade
+1  A: 

I am not aware of one, but ideas frm JVM running on JVM should be helpful.

sanxiyn
cool, Maxine has a metacircularity focus
Mark Cidade
A: 

If you're willing to expand your definition of "runs CIL" to "JIT-Compiles CIL to Native Code," then you should look at the Managed Operating System Alliance -- a group of people (myself included) working toward creating the runtime pieces necessary to write a managed operating system kernel.

Currently, there is quite a bit left to do, but it is possible to JIT-compile and run simple methods (Win32 only -- we currently use P/Invoke to create the native code buffers)

Alex Lyman
+3  A: 

You should check out the IKVM.NET Project. It includes a Java Virtual Machine written in .NET.

http://www.ikvm.net/

I know it's not an actual CLR that runs on top of the CLR, but it's the closest thing I know of that does what you want.

Chris Pietschmann
I'm aware of IKVM but yes it may be helpful to have a look at.
Mark Cidade
+3  A: 

I don't think there are currently any standalone .net VMs that are self hosting but both Cosmos and SharpOS are .net runtimes written in C#.

It may be possible to reuse some of their runtime code to extra a standalone runtime. Cosmos can be used to host a custom application on boot: http://www.codeproject.com/KB/system/CosmosIntro.aspx

Luke Quinane