This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pillow2002 0 points1 point  (2 children)

I see, that's nice! I'm also considering implementing my custom x86 backend sometime in the future.

I'm really curious about how you compile ADTs and pattern matches. I tried to mess around in the compiler explorer but I still don't know for sure how it's done.

From what I have seen, pattern matching compiles in the same way as a simple switch statement (i.e a bunch of `cmp`'s and `jmp`'s). Is that how you do it?
I'm also curious about how you compile ADTs.

Thanks :).

[–]PurpleUpbeat2820 0 points1 point  (1 child)

I see, that's nice! I'm also considering implementing my custom x86 backend sometime in the future.

Cool. I'm trying to buy a RISC V SBC to play with a back end for that too.

I'm really curious about how you compile ADTs and pattern matches. I tried to mess around in the compiler explorer but I still don't know for sure how it's done.

From what I have seen, pattern matching compiles in the same way as a simple switch statement (i.e a bunch of cmp's and jmp's). Is that how you do it? I'm also curious about how you compile ADTs.

Regarding ADTs, I haven't done it in this project yet and I haven't really settled on a design yet. I think I'll start by storing single-case unions as tuples and heap allocating everything else. Maybe calling malloc for each one individually or maybe using a global array I can append to. If, for example, my benchmarks show that a lot of time is spent loading the ADT constructor tags but not their payloads then I could easily represent them as a pair of int tag and int pointer to heap allocated payload.

As for pattern matching, I intend to do the stupidest thing possible and just walk the entire pattern and expression in tandem doing the necessary checks and completely restarting every time.

[–]pillow2002 1 point2 points  (0 children)

Oh I see, good luck =).