Reputation: 99957
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?
Upvotes: 10
Views: 965
Reputation: 30637
It is possible in principle by combining technologies:
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.
Upvotes: 1
Reputation: 16605
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
Upvotes: 5
Reputation: 29885
You should check out the IKVM.NET Project. It includes a Java Virtual Machine written in .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.
Upvotes: 4
Reputation: 15935
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)
Upvotes: 1
Reputation: 175583
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
Upvotes: -2