C# vs IL to convert

Apr 28, 2013 at 7:47 AM
I'm just curious why you chose to compile C# -> ASM rather than IL -> ASM. If you used IL, you could compile other languages on the .NET framework too.
Apr 28, 2013 at 1:20 PM
Edited Apr 28, 2013 at 1:22 PM
When you say "IL", Do you mean the common intermediate language that is used by the .NET Framework to build asm/binary in run-time?

If so, then I have more than just once answer.
  1. I wanted to be able to replace the microsoft/mono compiler completely. From what I understand, you have to compile the code first and then run it through a disassembler to get the IL code. This is in-efficient and it isn't exactly elegant. I am trying to build a more streamlined elegant.
I appreciate that my code isn't at the stage is not optimized and well thought out. I am kind of playing it by ear as i go along, so some of my decisions are based on just getting it up and running, then I will worry about making it perform better...
  1. the compiler will use an intermediate data structure of some kind and I haven't yet settled on what it will look like. Even though I stated that the compiler won't use CIL, it may be best to do so. I have been trying out different design ideas, to see which ones seem to work best. I want the compiler to be able support pretty much every high level language. I am also thinking about abstracting the writers out so that the compiler can output into any language. This could act like a language conversion program.
  2. My long term goal, is to create an assembler of my own (eg. C# to binary), where the code can be made into portable executables or ELF file for different platforms. Kind of like a one stop shop. Where by you install the sharp compiler, then you configure your IDE or install the an IDE plugin of your choice.
  3. I suppose there is a little of my ego involved in the design choice. I want to be able to say that I built a compiler from scratch. I feel that C# is a really good language to start with, since it is like C. C# in my opinion has a cleaner style.
  4. I wanted developers to be able to treat C# programs like C programs. So I wanted you be able to code in C# without the technical dependency of the .NET framework. This choice comes from the entity os framework that I am apart of. I feel that this would be the best way to write system level code using a high level language. However, I am playing around with the idea. I feel that if you want to use the .NET framework, then this invalidates the need for this compiler.
  5. If I were to create an OS using C# i would also want to be able to develop code on my OS and not on another OS. so I need a compiler that I can use inside my OS. So if i am successful with this project, then I could in effect compile the sharp compiler...using the sharp compiler, resulting in a native version of my compiler. That way I could include this in my OS and build a IDE for my OS that could run on my OS.
And lastly, this project is an exploration of a problem. Can you build low level native code with a language that is designed to be managed?

I am sorry for the long answer. If you have a idea on how i can do this better...then I would gladly welcome it.
Apr 28, 2013 at 1:31 PM
You're correct in the fact that you'd have to compile it, but you could use reflection to get back the IL. I think there are a couple of points that I think would help you:
  1. IL is targeted by multiple languages, so you'd have more flexibility in languages.
  2. The Microsoft C# compiler has been worked on by hundreds of people, and so will probably have more optimizations in it than a one or two man team could ever do (this isn't meant offensively, but Microsoft's manpower is going to be far stronger than a small independent team).
  3. The decompiled code doesn't rely on the .NET framework (in most cases, occasionally there may be some platform invokes), so that isn't an issue.
  4. IL is laid out more like assembler, and has logic more like it. That would probably make it easier to convert.
Nevertheless, full credit to you if you want to write a C# compiler, and you've got my following (and shared it with a few people on IRC). Good luck!
Apr 28, 2013 at 1:53 PM
As we all know cosmos does that already and thats fine but I am making a project called entity os framework which is very heavy on gui to make an os so sharp will help me alot. The other .net languages aren't used much any more vb is dead. I think have a C# compiler to asm will not be hard to make as it is just parsing c# classes into namespaces in asm.
Apr 28, 2013 at 1:54 PM
Edited Apr 28, 2013 at 1:54 PM
Aurora I will take what you said on board and see how i can use it to benefit this project. Thanks for sharing this with others, the more people the better.

As for point 2, you are completely correct. However, if i were to think like that, then I think I would step away from the keyboard, and not bother writing any code. After all, whether its a compiler or an application, companies like microsoft, google, adobe etc... do have more manpower. Open sourcing a project, means allowing an unlimited number of people to work together. Even though in most cases you only get around 3 or 4 people. So please!!! Any help is much appreciated. ;D
Apr 28, 2013 at 2:01 PM
@clearosdev: C# and VB aren't the only .NET languages, there are some good albeit less popular languages that target it.
@danieljsamson: That's good, and like I say great work so far, good luck (and sorry I can't be of much help in coding the compiler - I haven't done much in a while, and definitely nothing on this scale)
Apr 28, 2013 at 2:48 PM
If want to contribute yourself, or you know some who might. Please understand, that i'm not expecting you to write the whole thing. There is a famous saying in japan..."Piled-up specks of dust become of a mountain". For example, right now...all i am doing is referring to the ECMA-334 Document and trying to create small sections of code at a time. A piece of code, one for detecting a lexicon( or word) in the file, another for storing it in some kind of data type, then another for working out how to highlight it in the editor. Thats it....It's when we get into writing the assembly part...is where it gets interesting.

I have a list of things I am working on here. You can see what I am doing by checkout out the comments in the changesets.
Apr 28, 2013 at 2:59 PM
Also we need art work. logos, road maps etc...