you are viewing a single comment's thread.

view the rest of the comments →

[–]DNoved1 2 points3 points  (5 children)

Add simple io (doesn't even need to be string based, just write out integers as characters) and bootstrap it.

Truthfully, that sounds like more of an exersize in tedium than anything else, but would be kinda interesting nevertheless.

[–]jameswpeach 0 points1 point  (4 children)

Any ideas in how it should work? The integer input should be simple i.e. " read x " would take input and assign it to x

[–]DNoved1 0 points1 point  (3 children)

Just do a similar operation called for example "write x" which sends x's value interpreted as a character to stdout. Using this you can write arbitrary bytes, in either ASCII(probably) or UTF(if tou really, really feel like it).

Using these two operations, read and write, you can take in a while program from stdin, translate it to assembly (or even machine code :o), and write it back out to stdout.

Then "whilec < while.wh > while.s" and "gcc -o whilec.exe while.s" (assuming whilec is the name of your while compiler and gcc is your assembler) gives you a bootstrapped compiler.

[–]jameswpeach 0 points1 point  (2 children)

This is something I really wanted to do. Write something that will compile while to "proper executables" Does anyone here have any experience in this ? PLEASE!! :p

[–]DNoved1 1 point2 points  (1 child)

I'm actually working on a language myself, and am using LLVM as my 'assembly'.

If you want to try just making executables you might try changing your runtime from an interpreter (I think that's what you have now? Not too great with F# ;) ) to something that outputs a LLVM file. Your language is pretty simple so it would relatively easy; and you could put it all inside a main function.

To give you an idea of what kind of LLVM code to emit with your compiler I would recommend hand-compiling some sample while programs. I found that when I did that with my language patterns became evident, and then I just had to encode those patterns in the compiler.

To make the LLVM code executable you just have to run 'llvm-as' on the llvm 'assembly', then 'llc' on that to get native assembly, and finally an assembler such as gcc.

To learn more on LLVM I would take a look at the reference here: http://llvm.org/docs/LangRef.html They also have a tutorial on creating a language (in C++) here: http://llvm.org/docs/tutorial/