Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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

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)

It is possible in principle by combining technologies:

  • Jikes RVM is a Java Virtual Machine implementation written in Java.
  • IKVM.NET, an implementation of the Java platform on .NET.

It might also be possible to take Mono, compile to LLVM bytecode, compile the bytecode to Javascript using Emscripten, and run the Javascript on .NET using any of various interpreters.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top