Live data from Hacker News

Show HN: A compiler for a small language into x86-64 assembly

github.com

1–10 of 23 posts

Re: Show HN: A compiler for a small language into x86-64 assembly

#3

This is my first compiler, so I expect there to be several things I can improve :) I tried to follow the Assembly calling conventions the best I could. I am looking forward to any feedback!

Congratulations! It looks like a useful and practical design. How is the performance of the generated code? What are you thinking about doing for memory management? Have you thought about using an intermediate representation to make optimization and retargeting easier?

Re: Show HN: A compiler for a small language into x86-64 assembly

#5

This is my first compiler, so I expect there to be several things I can improve :) I tried to follow the Assembly calling conventions the best I could. I am looking forward to any feedback!

Very cool. What resources did you use to learn how to write the compiler? The "turn code into ASM" step has always mystified me, and I'd like to learn more about how that part of the process works.

Re: Show HN: A compiler for a small language into x86-64 assembly

#6
post #4

You can try FASM ( http://flatassembler.net ) besides YASM and ld.

Well this is funny. Originally (a number of years ago) I looked at using MASM, then I was informed to switch to MASM.

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 :)

Re: Show HN: A compiler for a small language into x86-64 assembly

#8

This is my first compiler, so I expect there to be several things I can improve :) I tried to follow the Assembly calling conventions the best I could. I am looking forward to any feedback!

Very cool! Reading the "Why" section resonated with me, as I think creating one's own language is something every programmer should do for the experience.

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.

Re: Show HN: A compiler for a small language into x86-64 assembly

#9

Curios if you looked into ANTLR? That's what was used most recently as part of my compiler's course at Georgia Tech.

Yes, I did (at least a bit). That and I read, that Go has a build-in yacc as well.

But decided, that for the first compiler, I want to actually do all steps manually myself for best possible comprehension of the general topic.

Re: Show HN: A compiler for a small language into x86-64 assembly

#10
post #3

This is my first compiler, so I expect there to be several things I can improve :) I tried to follow the Assembly calling conventions the best I could. I am looking forward to any feedback!

Congratulations! It looks like a useful and practical design. How is the performance of the generated code? What are you thinking about doing for memory management? Have you thought about using an intermediate representation to make optimization and retargeting easier?

Thanks :) That's where I was trying to get to. I did some smaller performance comparisons against C (with -O0), where I was at about 90% speed. But there is a lot of performance to gain, if I optimize the resulting assembly. There are lots of cases where I push and pop directly afterwards because of the general expression code generation (no real knowledge of broader context). So I expect that to help a lot regarding performance. Also things like jump tables for simple switches are on the table.

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.

Post reply on HN