I tried to follow the Assembly calling conventions the best I could.
I am looking forward to any feedback!
As a matter or preference I really like colons and semi-colons.
That said your work is amazing. This is a true example of simplicity. I don't think most of people would get how difficult it is to keep it simple.
Everything is clear I can read the source code without asking myself "what is that", everything makes sense.
Thanks for presenting your work.
Do you have any constraints, like "no meta programming", "generated library should be as much as possible compatible with C", "it should have one pass optimization" or even "the compiler must be embeddable in most place as possible" ?
Thanks for saying all that. It was a huge amount of work and getting appreciation makes it all worth it!
No hard constraints as of now. But I don't think I want to include meta programming or a pre-processor (don't really like it to be honest). I do want to keep it compatible with C internally, on Assembly level. One thought is, to create a file with function headers/definitions that are then dynamically linked and can just be used.
I used some C std library functions that way for debugging (printf, ...). And as I follow the standard calling conventions, the compiler should automatically generate compatible code.
With this, it would also be possible, to write OpenGL code. That would be really awesome :)
As of usage of my language - Not sure yet. Up until now, the road was more of the goal then the finished language.
Yes, I thought about going for LLVM or another representation but decided to do it once myself (no given performance optimizations or the like) with room for improvement.
The syntax flows well, in fact it feels very intuitive for my taste. I like the type inference and no semicolons. I wonder if the latter posed any trickiness, for example, with the next line starting with an expression "(" or operator like "+".
I'm also curious about use cases, what is possible with this language. I guess anything assembly can do - which is..everything? :) Would it be suitable to run on microcomputers like Raspberry Pi?
EDIT: The Pi and Arduino are typically ARM, it seems, with a different instruction set. Well, that shows how little I know.
That language flow and general simplicity was one of my most important goals. Thanks for noticing :)
No, I had no problems regarding that. What you mention ('+', '(') are all part of simple expressions when parsing. And I strictly parse right recursive and re-order the expressions later (for operator priority). So that was not an issue. Most of these problems I solved, by making my parser a lookahead of >1. In a few cases, there is a lookahead of 3 to determine what exactly should be parsed.
I guess anything, that can run an X86-64 Elf executable? ;) Although there is still a lot missing, for it to be taken serious. Starting with strings, files, input, ... But thats for another time or whenever I need it, I guess.
World needs more of these for other complex topics.
- General compiler design - This was one of the main ressources. https://www.tutorialspoint.com/compiler_design/compiler_desi...
- https://www.lua.org/manual/5.3/manual.html#9
- Linux system call table: http://blog.rchapman.org/posts/Linux_System_Call_Table_for_x...
- A bit on floating point: https://cs.fit.edu/~mmahoney/cse3101/float.html
- Assembly https://www.cs.yale.edu/flint/cs421/papers/x86-asm/asm.html
- More assembly: https://www.complang.tuwien.ac.at/ubvl/amd64/amd64h.html
I'm also influenced by Lua and I picked it up in your grammar right away : )
Let me know, if you have questions or need hints where to find some relevant details in my code.
Then (last year or something) I find out YASM is actually intended to be an improvement to NASM, which I've used for about 6 years. And now I find out FASM is an improvement on YASM? How deep does this go??
To clarify: I had heard of all of these different assemblers and at some point looked at their websites but it was a very, very long time ago :)
But decided, that for the first compiler, I want to actually do all steps manually myself for best possible comprehension of the general topic.
Lastly, the book's appendix has guidance for writing a compiler for a subset of the C language.
For for it! Start small and increase. But seeing a program in your own language output something makes it all worth it :)
If you plan to buy the book, you will have to go to Lulu.com and search for it, as order links seem to be down after a site redesign.