In compiler development, designing an intermediate representation (IR) requires careful consideration of scope management, instruction generation, and control flow handling. The IR must preserve sufficient information for optimization while remaining simple enough for efficient code generation. Key components include scope tracking for variable resolution, instruction buffers for code organization, and proper handling of expressions, declarations, and control flow constructs. The design process involves iterative refinement, where initial implementations may require significant restructuring to address fundamental issues like control flow generation and type handling.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
studying compilers every day until i land a compiler role (day 199)Added:
And we're live. Um I don't know if I'm on time or late. I don't remember what time I set the stream, but I remembered it had a six in it. So, um yeah, we're just gonna we're just going to stream now. Um this is day 199 of studying compilers every day until I land a compiler roll. Um last time we continued doing the big rewrite. This time we're going to continue continuing doing the big rewrite. Um yeah, it's it's going to be a good time. So yeah. Uh what's good is earth? Good to see you.
Um okay, get log. Let's see. We were we were making this new like 2 mir thing and it was going all right. I won't say it was going great, but it was going it was going passively. So we got a we got a lot of stuff to do here.
Um let's see.
I think we finished up the like function def and function prototype stuff for the most part. Am I regular? Yes, you you very definitively are. Um I gave you the role in Discord as well. So yeah.
Um okay, let's see what is the best place to start here.
Um hi, I'm also writing compiler. Nice.
Well, welcome. Um hopefully hopefully this is like a little bit interesting then improving reel. Hell yeah. Yeah, reel is reel is hard. I I struggled a lot with it. I just my IR doesn't preserve enough information to do it very well. So we just have a really we have a questionable heristic, but like it's it's fine.
Um, okay. Let's see.
What do we even do here? I think we should So, maybe I should start with the experts or maybe I should have like a h maybe I should have a pass that like dugars and that like replaces the hir pass.
That might actually make things easier now that I think about it. Um.
Huh.
Yeah, this is this is rough.
Um h I think that would simplify a lot of the logic, but I guess the big the big thing I'm concerned about is generating like control flow. That scares me a lot and I don't I don't even know how I'd go about doing that.
I guess it'd be no different than what we currently do, right? Like we just have to like manage more basic blocks at a time, which is like fine.
So if we look at like HR to MR, if there's anything like interesting that we do, I think that might be difficult.
H I guess we don't really do anything interesting with it then, huh? Um yeah, it's kind of just like one to one. We just we just make more of a mess. So I guess we could we could try that. Um let's start with exper because I think all the expressions will handle pretty similarly to what they did before.
Um, where do we start with this?
I guess yeah, we can kind of we can kind of yank some of this.
So h so terminal expert we want to oh I guess we need to figure out like uh we want to figure out like scopes and stuff. Uh compiler it's called panic. Uh it should be it should be pinned on my uh on my GitHub which is in the description.
Um h yeah this is this is annoying actually.
This is really annoying.
Um yeah we're we're in we're in some trouble here.
Yeah. Okay. Maybe we should start with instructions and then that will that will help make things make sense. Um scope might be easy or at least it's supposed to be easy.
Um Oh man.
Okay. So then we want like Yeah, this is this is kind of awkward to reason about.
What do we have in the header to work with? We have like this cur scope thing.
Uh we also need to set that in the constructor. I just realized. So let's do that real quick.
Give that cur scope is zero.
Yeah. So that's good.
Um H and then everything else I think we can leave default. So now if we go into scope.
So we want curcope++ and then afterwards we want to decrement it.
And then inside here I guess each I in S we want to get instructions and what type is this unique pointer to instruction. So, we want to then we want to visit that. I guess we can kind of just steal what we had before here for the most part. I think yeah, we can we can kind of just do that. Um, it looks like we it looks like we will make a new scope. So, I guess that makes sense. Um, yeah, we should we should do it like that.
So, we want to accept this Yeah.
So that's what we need this like scope mappings thing for and I think we will probably keep that as well. Um yeah because this resolves like variable names I think.
So like the current alive variable I guess or the current shadowing variable.
I don't really know what the like precise term is but we should we should track it like that. So we have cur scope and then we have like stood vector of stood ordered set of stood string.
So we have scope mappings or I guess we should call it bindings.
Binding is that is that the right term for this bootstrapping approach? Uh what do you mean?
Yeah. Okay. So this should be scope bindings.
That might be more precise. So, we'll call it that.
So, I can do that. And then here we pop back.
Okay. So, that's straightforward enough at least.
Um, let's see.
So, okay.
So, an expert. This should be straightforward. I think somehow I think we I think we do something with it here.
Right. Instruction expert. Where does this live?
Okay. Yeah. So, we just we just accept that which makes sense.
So, that seems straightforward enough.
Um declaration we kind of have to make a little bit of glue code, but we we can do it a little bit differently.
So we want So what do we want from this? Right. We want we want an allocate and yeah we want an allocate and we want to guess we should we should steal from this like declaration assign thing for the most part.
Um, yeah, it doesn't look like we get rid of a temporary.
I think that's what we do. Uh, what's a Vansu?
Okay, well, we'll skip declaration for a second. Uh, return should be pretty simple, though, cuz that we just generate a little bit of boiler plate.
So, we definitely want these two.
Uh, and then we can get rid of this like last extra thing, right? Cuz we we just generate code and then let's see what do we do from here?
Where's our return? There's our return.
Yeah. So we do that and then we make an allocate of some sort.
Wait, what?
Oh, we make this ahead of time. I see.
Okay. Yeah, that makes that makes sense.
Um, so definition we also want Oh man. Okay, so there's like a rat allocate that we store. Yeah, maybe we could just make it here. Or I guess we wanted to dduplicate it, which is why we did it like this.
Um, I don't know. Maybe we should maybe we should just like have duplicative returns then. That might be cleaner and then we can like we can like GBN it out.
I guess [snorts] we'll we'll do it like this for now.
We'll do it the way we did and then like we could think about maybe doing it a different way.
Um yeah.
So, let's make a retake. Or that's that's what we call it.
When do we make that?
I see. We do it up here. Okay.
So, we do it at the top of a We do it at the top of the entry block. It looks like so we should h Yeah. What is the correct order to do this then?
Um maybe we should do it before then and then Huh.
Yeah, we definitely need to do that anyway because we need to put all the damn allocates somewhere.
So that would that seems like something we need to do beforehand. Um h so then yeah, this is this is getting a little it's getting a little messy.
Okay. So, we got So, we make the entry block and then that's also presumably where we will make this rat allocate thing.
Yeah, we'll just we'll plaster this somewhere here.
So we want we want middle and mirror instruction alloc star that's alloc.
Yeah. So we make that and then in here we should Yeah. We will we will make this here.
And this should this should go at the front of the list, I think. Right.
Actually, we could just we could write this real quick. We don't need to do this. So, um, so let's make unique. Actually, can we just steal it from like here?
Yeah, we can yank that.
Uh, and then we need the function type here, right? So, we want type we can do that.
Then we should also change the signature real quick.
Yeah, we'll just do that.
Okay, so we have that. We make the alloc and then we need to make the basic block.
So we want entry block equals make unique uh we can get rid of some of this.
So this should be MI basic block and then that's fine I think right um oh wait no we need to this constructor is annoying.
Yeah.
So what what did this constructor take again?
[clears throat] Oh, I see.
Okay, let's So we can make a no point.
We could like no pointer that, right?
Oh, right. That's annoying, actually.
Okay.
On second thought, maybe we can't actually do that, huh?
Well, crap.
Um.
H.
have the type.
Maybe we should make that after and then we should like we should make a list of all and that will that will fit in the entry block perhaps.
Yeah, I like I like that idea more more I think about this.
Yeah. So we want that and we give it type I think.
Yeah.
And then Yeah. And then we can figure out the terminator from there, I think.
Yeah, we need a basic block buffer, which we have. So we can probably just put it in the front of that.
Or you could make it point to next in there.
Um we should also we should make the entry block and we should definitely we should make the return block as well I think.
Uh hi from India. Welcome.
H what am I doing here?
Does like the return block always just get made at the top then? Is that Is that how I do it?
Huh?
Wow. I guess it just I guess that is just how it gets made.
Um yeah, not returns like function.
This is per function. So that makes that makes sense.
Um okay. Okay. So, we should probably make an instruction buffer then of some sort, right? Do we have an instruction buffer in here?
No, we don't. Okay, we need to do that.
So, we can do that and then Okay, that that simplifies it actually.
So then we don't need like we don't need that in there at least.
Um yeah, we don't even need this helper to be honest cuz then we can just get the frontmost block, right?
Yeah. Wait, what am I doing here?
What?
Oh, I see. We put all the allocates in.
Okay, that makes that makes sense.
Um, yeah. Okay, that makes that makes so much sense. So, we want to Oh, man.
Okay. So, we still want like create entry block like I guess I don't know create sounds wrong here at least.
Let's at least put this up here somewhere.
Yeah, we should we should do that.
So, this should be set up return uh return block I guess.
Yeah. So, we want to do that anyways.
Maybe we want an allocate creator.
Yeah. So, we want to do that, I guess.
Um, maybe close entry block. I don't know. I don't know what to call it. I think crate's probably fine.
Yeah. Okay, we'll just do that for now.
Okay.
Or we could call convert. I don't know.
Yeah, there we go.
Ah, what the hell? We'll keep it crate.
Me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me me trying trying to make any semblance of a decision. Um okay anyways so that should just move the allocates into the entry block. So we can kind of steal this to be honest I think um what is wrong with this again? Oh, that's what we needed.
I guess like front body.
Okay. So, now we need to make this alloc list as well. So, we're we're holding on to more things, I guess, which is fine. We're kind of We're kind of getting to this point.
Yeah. Okay.
So, that's fine.
Um Oh, man.
We should probably have a helper that like makes an all Yeah, we should insert allocate or something. Is that what we want to call it?
Yeah. So, that probably goes like somewhere here above this.
Um, yeah. And then we give it like or this doesn't even need a function.
This is just like two lines of code. I think it's probably fine to make this not really reused.
Um, okay. So, we want So, we make that we could just Can we just push back this?
Yeah, we definitely want that.
And then actually Oh, wait. That shadows that.
Yeah. So those should be value return value.
Um yeah, I guess we would do that.
So here I guess this is pretty trivial at the top.
Um here we should do parse body or I guess lower body and uh I guess yeah I guess we could just yeah we could just call it lower body I if I can type.
Okay.
So, that that does that. Uh the nice thing about prototype is that it's pretty easy.
Um okay, we'll worry about this later. So, we'll delete that. Expert is pretty straightforward though, I think, because we don't really do much else with it.
Uh, good luck, bro. Thank you. Um, I'm not sure if I've seen you around here, so if if you haven't been here, then welcome. And if you have, then also welcome, I guess. [laughter] Um, yeah, let's do let's do return because this is what we wanted to do.
Um, yeah. So, we we definitely want that.
And then I forget why we didn't need like the last thing. Oh, we have preexper. So, we do want to do something like that.
Um, okay. We we might want to redo that at some point, but for now we just want to like make a return.
So that lives in instruction return wherever that is.
There we are.
Um okay. Wait. So, what does this take again?
So, we store into the thing and then Oh, I see.
Okay, I understand why we do this.
Uh, what's up, Kaso? Uh, why we don't use Edge? because Firefox is fine and well on my Linux machine I use Firefox so I figured I may as well use Firefox here as well.
Um, okay. So, let's let's see. What do we want to call this?
That name seems wrong.
Um, I guess we could call we could make like an outgoing edges. I don't know. I don't know what to call this.
We should we should clean this up somehow.
These are definitely buffers.
So, we should treat them as such.
And then these are all like temporary slash like stateful things. I guess maybe this also goes up here. I don't know. This is this is all very confusing.
I guess this is like stuff we necessarily consume. I don't know. Well, I don't know how I'm sorting this. I'll figure that out at some other time. I might end up just not sorting it and it will it will have to burn for better or for worse.
Um, yeah. So, we're going to need this like block edges maybe I guess like outgoing edges.
Yeah. Yeah. So, what is this instruction to basic blocks thing?
Oh my god, that's awful.
Okay, we're going to we're just going to lift that.
Um, so this should be um what do we call this? I guess.
Yeah, I don't know.
Um, have you tried the Chris Teris utility tool? I haven't. Um, I just I just make a mess with my windows to be honest. I kind of gave up on keeping it clean. I've decided that it's just going to be messy for whatever unfortunate reason.
Okay, so we have this which is also why we have some other mapping type mappings I think.
Uh that's not helpful.
That's really not helpful. I guess labels I guess labels is probably what we want.
Um Huh.
Okay. Well, I'm going to go to the bathroom real quick. Um, I'll be right back. Should be like a minute or two.
Okay, I'm back.
Um, all right. Where was I? We were We were figuring out how to do returns properly.
Um, outgoing edges.
What was I doing with this again?
Um, huh.
Yeah, I don't remember what I was how I mapped this at least. So, let's let's see how I did that.
Connect basic blocks.
Um, okay. So we have like this dangling terminator.
Um so zero is the return block I think is how we did that.
And then what the hell.
Okay. And then we make the return block.
I see.
Oh, that's really awful. Oh, I really don't like that.
Um, so this labels thing. How the hell did we How do we do this? This is like completely unreadable.
It's a wonder that this hasn't this wasn't the thing that broke the most frequently actually. This is like really really poorly written. So yeah.
Okay.
Okay. So, how do we even Yeah, actually, how do we even do this?
H.
So, where where did this go to? Labels.
Oh, I see. That's how we identified it.
Okay. So, we just went by the label of value, I guess. Okay.
Wow, man. This is terrible. Okay, we're going to need to This is actually just way more mess than I thought it was. We'll figure that out in a second.
Um, but we can at least make a return instruction maybe, right? Surely we can do that.
All right, we Yeah. So, we make a store and then uh map the branch for uh yeah, we can we'll do something like that later.
We can kind of yank that. I think I violated some naming convention somewhere here.
Um, yeah. So, we want that and then Oh, man.
We do want some way of like resolving atoms, I think.
So, this would be like use, right?
Um, yeah, this is this is terrible.
Uh, which language? Um, I'm writing I'm writing this in uh I'm writing this in C++, but I'm compiling C down to x8664.
Okay, so we can do this and then instead of putter we can do red allocate.
Yeah, good luck. Thank you.
Okay. So then cur or we just do instructions.
Yeah. So we can do that.
Yeah. Yeah. So, I think we should probably we should probably handle these things sooner than later, the experts, cuz I think that will help us figure out what we need to do for like scopes and stuff. Um, I I have an idea on how to simplify it. So, that will that will be very positive, but hopefully hopefully that all goes to plan.
Um, okay. So, we do that and then we can kind of just yank that, I think.
And then we want a thing to make a basic block out of this, I think, is how we do this.
Um yeah.
Um we can figure out how to like dduplicate later, but for now I want to just like keep this as as straight line as possible.
So, where's our crate basic block? Yeah.
So, we do this.
So we give this stood move instructions and then stood move branch.
Yes, we do that and push back uh we can push back basic block or Let's do that.
Um, and then Oh man.
Then we have to clear that presumably.
Okay.
So that's actually a lot shorter than it was here. At least this this function looks so much messier than the actual internal logic. So, I'm I'm kind of glad I decided to not do it that way.
Um, yeah, we'll figure we'll figure right Bell out. Um, good luck, bro. Thank you.
I I do appreciate it a lot.
Uh, let's see what else do we need to do here. If we actually we could kind of do the same thing here with if and while. I think these instructions shouldn't be that bad.
Um h Oh man. [laughter] Yeah. How do we How do we want it to do this?
H.
Luckily, scope is like pretty easy, so I'm not that concerned about that. Um, yeah.
Okay, let's let's work on the experts now. I think I think that that will help us figure out what we need. So, we probably want helpers for like uh we probably will want more helpers, but we will we will build those out as as we see fit.
Um let's see.
So let's start with terminal expert.
Um how's job search going for compiler roles? Um AMD and Nvidia have this. Um but also like quant firms sometimes hire um compiler engineers because they invest a lot in various different languages. Um yeah, hardware is like another big place. Big tech's another really big place.
Um, right now I'm like I'm kind of chilling for a bit because I have an internship for the upcoming summer. So, I'll just like I'll kind of wait until then to like start applying to full-time proper. But yeah, that's kind of that's kind of where I'm at right now.
Um, okay.
So, what do we do with this?
>> [snorts] >> Okay.
I graduated from undergrad. Um I'm I'm like I guess I technically have finished my undergrad, but I'm I'm also finishing up my masters right now. So um I'm in like the combined BSMS program.
So the consequence of that is I've got an extra I've got an extra summer to work with pretty much.
Okay, we definitely need a way to resolve scopes because I'm going to go insane if I don't have that.
So, let's see.
I don't want to do it like this super convoluted way that I did here, though.
I think cuz I have like four different Yeah, I have like four different functions for this.
So, uh, what's up, Euglver?
So, we want Oh, man.
This is terrible. This is This is actually truly terrible.
Um, let's see.
Yeah, this is really difficult actually.
This is difficult to figure out what to do what what to even do with cuz like here we're kind of making the thing. Um if it's a number then like we should probably just make a number. If it's I guess terminal expert we necessarily should be making the thing.
Hm.
Um, okay. Let's do if E.
If it's the identifier, then we need to figure that out.
Or actually, wait, what do we do here?
So, we have this like last expert thing.
Last expert should become a value star.
I think I think that's what we want to do with it.
Yeah, we should make this a value star.
What's wrong with this? Oh, right. This is this is the one place where I actually can't do that.
Yeah. Okay.
With prev expert equals.
So if it is identifier then we want to we want it to do otherwise then we should um oh man do we need this to be unique pointer? I think we need this to be unique pointer right or wait no uh we have literal We have this literal map thing.
How the hell did we use this? This was like so dumb.
A We did this thing.
Okay, that makes that makes a lot of sense.
Um Oh crap.
[laughter] God damn it. Okay, this is so dumb.
What type is this? We don't know what type this is. That's the problem.
Um, okay. Uh, what's the status of your code genen? Um, it's it's outputting x86 um with or in an ELF format.
Um, prerequisites for developing a compiler. Um, kind of just like I don't know just like basic systems knowledge. Um, OS is probably helpful, but I think systems knowledge is probably the big thing. Also, probably some PL experience as well.
Um, oh man.
Okay.
H. Yeah. What do we do with this?
Let's just let's just wishlist program this.
So, we can do get value or we'll just do like get literal.
I don't know what type it is though.
That's a really big problem actually.
Um I think we do something like that in here though, right? We Right. We figure out the type Where's all of you scope?
That doesn't help me at all.
That's really annoying.
That's so so so incredibly annoying.
Now, where's the part where we figure out the type of things, right? Is this ever a problem at this in this?
Yeah, this is this is causing a lot of headache.
So, we want like I guess get use maybe and then we'll figure out what to do with that in a second.
Oh man.
Um, we can do get use and then let's give it like we can get the value. Maybe this is this is not going great. This is going very poorly actually.
Yeah. Okay, we'll do that, I guess.
Um, I see. If direction if direction is your problem, I think just like just like learning more different things or like trying to figure out how you can like add depth to whatever you're working on. Um, I know that doesn't really like say a lot, but yeah.
Um, what are you doing on your masters?
Um, it's focused on compilers in some capacity. Um, a lot of like analyzing codegen. I'm not going to like get too too into it right now, but that's kind of the that's kind of the short version.
Um, okay. We'll we'll figure out what the hell we're going to do with get use and get literal.
Um, yeah, we can probably just do prev expert.
Yeah, that actually works perfectly.
Then we'll figure out what goes in there later. Um, PN, this should be straightforward, I think.
Um, yeah. How did we do this? Is Was it literally just like visit or visit the child?
Yeah.
Okay. And then call. We can kind of we can kind of reuse some of this. I think that that's also a little bit annoying.
Let's do unary op and binary op. I think those are less annoying.
Or actually, we could just make this last ex or private expert, I think we called it. Yeah, let's rename that.
Um, oh yeah, I guess that kind of cleans things up a little bit.
So you can just make variables now.
So then we can just switch on e get or get up. I guess we can yank some of this.
Uh, what are we doing here?
Oh, right. We just like one to one this.
This isn't really useful. This isn't useful for us. But I guess this type stuff might be helpful. I'm going to yink these case statements, though.
Um yeah. So here we're just skipping ahead and we're just directly generating the thing.
I think we have a unary op thing somewhere here.
Yeah.
So if it's maryy plus we don't need to do anything here I think um or we could actually yeah like wait like all of the times we call get literal I think, right? Wait. Yeah. Every time it's literally just I32. Like, there's no reason to make this complex.
I should just make it I32 necessarily for now until we like stick types on things.
Then we might make a bit of a mess, but that's fine.
Um, let me fix my camera.
Okay.
Okay. So, what what was I looking at again?
This was useful because we need to do stuff here.
Um, yeah. So, we want Uny plus type conversion, right?
So, this matters now because we have like a pointer type.
Uh, what's up, Panda? I'm I'm doing all right. Hopefully hopefully you're chilling as well.
Yeah. Okay. So, it promotes to int, I guess.
Yeah, I had I had Chipotle for dinner.
It was It was fine.
Um, let's see.
Yeah, we can do we can just get away with doing nothing here, I think.
Um, yeah, we can keep prev expert I think here we want to zero.
Oh, we want like we want these buffers for some reason.
Oh, we need to store. Oh crap.
Oh no. Okay.
All right. We need these buffers then.
That's That's so annoying.
Okay.
Uh, thank you confusing all for the $10.
Um, yeah, I I appreciate it a lot.
Uh, exam day for systems architecture and discrete structures. Yuch. That is that is rough. Hopefully you had time to eat between then. Or is that tomorrow?
And then and then DSA. Damn. Wow, you're you're in you're in super hell. I hope I hope all goes well. Uh, what terminal are you using? Um, I'm using Westerm for my terminal emulator.
We love Westerm.
Uh, yeah. So, we can do this and this equals V, I guess.
Have you think about adding some notif?
Um, I've been pretty low production. Uh, very low on like production at least.
So, like my setup is literally like this scene here and then like my camera here.
So, um, I don't know. I haven't I haven't like heard that much about like about like production stuff.
Um, but maybe in the future I'll take a look into it.
Um, I was going to like invest a little bit more time into production overbreak and then I didn't. So, uh, whoops, I guess. But yeah, it will it'll happen at some point.
Uh, let's see. So, minus we need to literal equals get literal zero. I guess we'll make get literal a thing at some point.
Um, also, what the hell am I doing with literal map here?
I guess we could we could just stick a type in here. Literal map like we will be dealing with types in the future. So, I think that's probably fine. Um, I should probably also have a type conversion instruction, but that's a future issue to worry about.
Um, yeah.
So, we can do type i32.
We'll we'll make the function a thing at some point.
Yeah. If if you're new here, you will find out very quickly that I frequently leave problems for my future self to resolve. And very rarely does that go well for me, but it's very pleasant in the present. So, we will we will keep that up because it makes me happy.
Yeah. Okay. So, then we can kind of just copy this line as well, I think.
Um, let's see. What is type here again?
Type mappings at variable.
Oh, I see. That's how we do it. Okay.
Um.
Huh.
G.
Yeah, we'll we'll figure that in a second. Let's clean this up a little bit though.
So subtract we subtract val we subtract from zero cast to int question mark.
Uh yeah, we'll just do that.
What am I doing here?
What am I casting that to? What the hell? Wait.
H.
Do I have to like double static cast this?
Is that a thing?
So, value star.
Uh, let's see.
Is there a way to not do this?
Okay.
H. Okay. Let's Let's just static cast it twice.
This is a binary op star.
And then this takes bin up.
There we go. Okay.
Um, and then we want [snorts] uh, so we can do that. Let's give it stood move bin op.
Uh, is it worth writing compiler and C only or is that too much pain? Um, it is definitely rough. Um, I think it's pretty doable though. Um, you'll just have to like limit your scope a little bit.
Um, specifically the middle end is like really awkward if you want to make it like modular.
Um, okay. We also need to figure out this type thing.
And where did we get type from? Up here.
from the variable in that. Okay. Well, that doesn't that doesn't help me at all.
Yeah, that really doesn't help me. Okay.
Um I guess we can just get the type of this. We we can get the type of preexper.
Yeah, we can literally do that.
Yeah, let's let's do that.
Um, okay.
So, we can uh Ryan compiler in C++ to learn C++.
That's exactly what I'm doing here. So, I' I'd say it went pretty well, but um your mileage may vary depending on how willing you are to like self-study stuff.
Oh, what the hell am I doing here?
What the [ __ ] What was I doing? Wait, this this change is nothing useful for me.
Where do we use value? What the Wow, this was terrible.
Okay, I think I think here I just gave up on like fixing things.
So, this is not great reference code, but we will we will figure that out.
Um, let's see.
We should just not use a switch for this. I feel like I feel like that just makes things too messy.
Which is insane to say, but we we've got all these like temporary buffers that we've like stuck at the top here. I don't really like it.
Um let's see.
I guess we could like put a lambda here, huh? And like it'd be perfectly fine.
I don't know. Before I before I like tempt myself too much with that idea, we'll just move on swiftly.
Um, what's wrong here? Oh, instructions.
Okay. So if that uh what do we do with unop res?
Oh, we do a store. Okay.
Um ah this is getting really annoying.
This is getting really hard to reason about at least. Maybe I shouldn't have started with unary op.
Um, yeah, this is this is actually like breaking my brain. Uh, looking for C++ ideas. I see. Um, yeah, there's there's plenty of stuff you can do. Um, it it all kind of just depends on what you're interested in though. Um, I don't really have any generic recommendations, but I think if you like if you have something that you are very clearly interested in, then I think like that will lend itself pretty nicely. Um, there's a lot of different systems projects ideas that you can probably get started with. Um, compiler might be like a little bit insane for a first project, but um, it can be done. Um, yeah, I don't have any like great general recommendations though, at least unfortunately.
Um, oh man.
So we subtract from zero, we get the result of it.
Yeah, of course.
Oh boy.
I guess we do need to make a temporary.
I think that's probably what we want to do, actually.
Yeah. Okay. That's actually I think that's what we want to do.
So that's the result of that.
Let's make an alloc.
So we have I think we have a helper function to make an allocate, right?
So we have like I guess I swear we have a thing, right? We better have a thing for this.
No, we don't have a thing for it. Okay.
All right. Fine. Fine. We'll make a we'll make a damn function for it. This is actually getting annoying.
Yeah. Okay. So, let's let's add the helpers while we're at it. So, we want So, we want to like get allocate uh what the hell?
Okay. So we want allocate. We want literal.
Let's just look at it here.
And then we want get use. And then we want a deaf as well, I think, probably because those will handle scope differently.
Yeah. So, I think that makes sense.
I guess this should be make allocate.
Yeah, I want to keep this like resolve terminology. I don't know.
So, this returns a literal and then these are death and use. Okay. Yeah, I think I think this makes sense.
Um, let's actually rename that to make pms as well.
Yeah. So, we need to we need to change some things, but we'll do that in a second.
Okay. So, we've we fixed that up.
Um, all right. Let's let's figure out the types for these now.
So, this should be middle end mir instruction allocate star make allocate.
And this should get a middle end and our type type.
Uh, does your compiler work currently?
Um, well, if I wasn't like completely tearing up the plumbing right now, um, it would work. Um, I believe the main branch is updated to work on the compiler.
Uh, yeah, this should this should work.
So, we'll just we'll just clone this.
Uh yeah. So, if we build this, hopefully it works. Let's This actually a good test to see if I've set it up properly.
paint drying slow build. Uh uh while this builds, uh the test suite I have is pretty crap.
There's just a couple of tests here.
There's like silly Fibonacci.
There's some like really basic stuff.
Um so on and so forth. This is broken I believe. Putter might be broken.
Is this building with J32?
It's supposed to be building with J32.
That's odd.
Uh what's up, Mike? Um I've been doing all right. Uh hopefully your day has been all right as well.
Um there's also Oh, yeah. There's a really stupid benchmark here as well.
This is just like a big Fibonacci.
Are you using Ninja? No, I'm just I'm just using like raw CMake.
Maybe I should use Ninja, but I recently learned CMake has a J30 has a - J flag, so I was like sure. Um, it looks like it failed one test.
That one fails sometimes for some reason.
I don't know why. And right now I don't care to figure out why.
Uh many reg.
Um so let's go do many regge that lives here.
It's a pretty funny test. Um yeah, most of these pass. It just like it just runs the I guess that that's not really a good these are regression tests. So that doesn't test like the output correctness. Um like if you compare it to like the expected like there's the a this is the thing that this is the thing we're getting rid of. Um eventually you go down to like actual assembly and it's like really ugly but it works.
Um, and then if we do uh test benchmark, and then this benchmark script is really stupid. Um, something appears to have broken somewhere um in my setup. But yeah, uh why would anyone build a compiler? Um cuz well, we don't we don't want to write assembly uh by hand. So to support more powerful languages, a compiler is used to, I guess, do the translation.
Um, they're better than interpreters when you care about performance. And we need new compilers because we're making new languages and we're making new, I guess, assembly languages. So, we're going to need to update our existing technology as we go.
Um, yeah, it looks like it looks like benchmark was broken, but that's that's fine. We'll we'll fix that later.
Yeah, there was there was one point where it worked. I don't remember when it stopped working.
Uh, you can probably check a stream from like two or 3 weeks ago for a reference.
Um, okay. So, these should be MI value star I guess. H maybe this can be literal star even it should be value star.
Yeah and then we can do that as well.
Well, we need to change these types.
Uh value and then we want type.
Um let's see what what do we even do with def definite use?
Um is there any language that's converted into machine code directly without transforming it to assembly?
Um, I don't think so. I don't think there's at least any reason to do that. Like, um, like assemblers and linkers have been like a thing for a while. So, like it, um, it feels a little bit I don't really see why anyone would do that necessarily.
Like, yeah, it it just feels like like it just feels like why, you know? Um but like um the other big reason I think people don't do it is because um C interoperability is like a really big thing. So yeah.
Yeah. I guess I guess in a sense that is like assembly which is really funny to think about.
Um, okay. So, what do we pass this at least?
Oh, man. I guess we could just give it a Yeah, we could just give it in 64T ID.
Yeah, we could like do that again as well.
We could we could leave it like that for now.
Okay. So, res putter equals get or make allocate and then this takes uh yeah, we'll we'll we'll save this for later. Um, let's make an I32 just to be boring.
Okay, so that fixes most of our stuff. Um, value doesn't exist here. This is val now.
Oh, we need to load. Okay, that's I'm not thinking an SSA right now. This is very awkward.
Um, I'll just you know what? Let's just to do review it all. [laughter] Yeah, we need to we need to do some SSA stuff. Thanks for answers. Good luck.
Um, thank you. Um, let me know if you have any other questions and I will I will attempt to explain them the best I can.
Um, okay. This should be fine, I think.
Uh, okay. Take care, Earth. Um, thanks thanks for stopping by.
Okay. Um, yeah, let's let's make these helpers a thing and I think we will call it a day to be honest. I'm getting tired of this.
Um, what version of C++ um are you using or would recommend? Um, I think it's always good to use latest, but um if you I think like generally C++ 17 has been a good stasis. Um I think one before most recent generally speaking is what people keep as a stasis. Um people residually have been using C++ 17 but uh I think technically C++ 20 is supposed to be the norm right now and 23 is just nice to use. So, I think it's probably good to like use 23 just because it's there's some cool features in there, but if you want like a very portable version of C++, I think 17 is probably like really safe. Or 17 is probably like the furthest back you could go without like going insane, I think.
Um, okay, let's see. So, get result is here. So, let's just paste this whole pile here.
Yeah, let's do more trimming. Okay, so this is two. Am I a visitor?
Okay, we can do that.
Yeah, it's it's not even it's not even complete. That's that's the kicker. Like we're they're still adding like they're still trying to implement features, but that's kind of that's kind of inevitable, I guess.
Yeah, I think 23 is probably fine. Like all this I think I'm building with 23, right? Let's see. Yeah, I'm using 23.
All this code is written manually. Yes, I am I'm trying to avoid using an LLM as much as possible. Um I'm still using it for like debugging sometimes or like if I'm really stuck trying to figure out what to do. Then like maybe I'll like maybe I'll like prompt Claude or something, but I'm not using it to generate code for the most part.
Uh because it's just boring. It's just boring to sit there and like vibe code.
Part of the like the fun part about writing code has always been like doing the tap in by hand.
It's never been like a difficulty problem.
It's just like a fun thing.
Um, okay. What was I going to copy from?
It was this thing.
Uh, yeah. So, we want that.
Yeah. Let's actually go back down here.
We can figure that out in a second.
Um ah oh I don't know what the best sequencing for this is. So we can just return K's back and get I think I think that's the best sequencing.
What?
Oh, I see. We can't do it that way. So we want we want resz or or let's call it all putter like that. There we go. So now we can replace this whole thing or we can replace this with or we don't even need this. We can just do make allocate of whatever type it was. It was just type.
Nice.
So that actually cleans things up a little bit.
Uh what's your intellisense/stack analysis tool? Um yeah, I'm just using cling d um lsp.
Yeah, my flags are very boring actually.
I don't I don't do a whole lot with it.
Okay, this is that's cleaned up. Uh let's implement get literal. I think we can just yank this for the most part from here.
Yeah, we kind of we can kind of just do this.
Yeah. So we can do that.
Yeah. We want it to create the thing.
So if it contains it then we return the thing. Otherwise we make the literal.
Yeah. So we make it it has a type it has a value.
Um, we have that.
Uh, what bro is building? Um, I'm making a compiler from C to x8664. So, a compiler is a program that translates programming languages. Um, C is a programming language. x8664 is an assembly language. It's like kind of close to machine code.
Um, okay. So, we do this. This is fine.
Yeah, this this is fine. I think I like this implementation.
Okay. And now we get to have we get to have more fun.
Um Oh, no. [laughter] I'm so scared. I don't I don't even know what to do with this. I actually just don't know. Um crap. Okay.
Okay. Um deaf. I think we can kind of draw inspiration from what we've done here.
Uh where is this little where does this live? Yeah. This like declaration scope thing.
Yeah. So we have declaration scope. So um let's see.
Yeah. So the problem with the way I implemented this was I have like I like overloaded the hell out of this. And the upshot of that if we look in the header is we have we have so much bloat. We have resolve declaration scope resolve decoration scope and then like two uses as well. It's just like it's just awful.
So, we're just going to resolve that externally and then we will do this here and it will it will be much less awful.
So, and also instead of making just like atoms, we will be uh I guess we will just we will just straight up make uh what's it called?
But I'm blinking. Uh we'll just make values actually or we're not making values.
We're just getting a value from a mapping.
So we can h What was I doing here?
I see. So, oh man, this doesn't make sense because we necessar if it's a death, then we're just making the thing.
So, this doesn't exist.
Yeah, this shouldn't this just shouldn't exist, I feel like. So, we can get rid of this, to be honest.
Yeah, we should just be inserting it in in the back scope. And there's like only two places that that happens.
Um, okay. So now use [laughter] okay.
Uh, yeah. What even is this mapping? I guess we should rename this to get value, I guess. Eh, yeah, we'll just call it get use. Um, so this is we want to like yank this sort of thing pretty much.
Scope bindings. We want the size of that or size. Is there a way we can just reverse iterate for each?
There should be like a very Okay, I guess there isn't a convenient way to do it.
Okay, we'll just H Oh, we could we have that actually.
But I really don't want to use ranges cuz ranges are annoying.
Um okay. So yeah. So we can actually just use the reverse iterator.
So we can use scope map uh bindings r begin iterator is not equals scope bindings r end.
I don't remember what direction it goes actually.
Oh so we plus plus it. Okay.
Yeah. So, we can do that and then if Yeah. So if it contains ID then we can do something.
What key type is this? Oh it's by string.
Uh okay we we got to change that.
Why did I do string?
Yeah, it should be just by identifier.
So this is 64t.
Um, okay. Okay. So, we should actually just like we should just make this a map actually from that to middle end and our value star.
Yeah, much better.
Um, let's rename this to like uh scope it iterator. I guess this this really sucks. Naming things is hard.
Uh what do we do here? What is the best way to do this?
Um, this should unreachable out of here then, right? Surely there shouldn't be a world where that goes wrong, right?
Yeah, cuz this definitely should exist unless we like completely broke something. So, let's just unreachable at this here.
What could possibly go wrong?
Uh, what's up, Skittles? I am I'm just making some helpers and probably going to call it a day. I'm I'm a little bit tired.
Yeah, I am this this codebase has really really exploded uh for the worse, but you know that's how it goes. Um yeah, what do we do? What do we do with this?
Check something.
Okay.
Uh, should you start with C or C++? Um, I I would say start with C because I think it helps motivate a lot of C++.
Um, I've heard people say that the other way is fine as well. Um, I don't think there's a wrong answer though. I personally would start with C.
Okay. So, [sighs] yeah. What do we do with this?
So I guess bindings equals dref it iterator and then if bindings or I guess so what does find take?
I see you.
So, we want to find uh ID, I think.
Um, okay. So, we can do that and then Okay, wait. So, can we actually Okay, let's do mapping equals that I or I guess binding.
So if that equals bindings and or if not equals then we can return binding second I think arrow. Whoops. There we go.
So we want to do it like that I guess.
Otherwise it's unreachable.
Uh, it doesn't exist.
Get use it.
Okay. Well, we we named it poorly.
We should still call it get use, I think. Okay.
Okay. So, that's fine.
Yeah. Okay.
So, now all of that kind of works sort of. Not really. A little bit.
Is there anything else we can do real quick?
We can probably do declaration real quick, actually.
Um.
Uh, good luck. Thank you.
We can probably yank this real quick.
This shouldn't be that bad.
Yeah, we can kind of just copy this for the most part.
Yeah. So, we can do that. auto [snorts] allocate.
You want to make allocate with type I guess and that should be good.
Yeah. So we can do that maybe and then if I get variable or get value and then we want to do something.
Yeah. So if that's not a null pointer.
Yeah.
Um then we want to then we want to I get value accept this and then we want to make an assign. So, so assign equals or it should be store.
You can kind of yank that and then we can give it Yeah. So we can do that and then here we give it okay and then we store the assign val there and then we can paste that there.
Yeah, that wasn't so bad actually.
That was pretty that was pretty reasonable.
Okay.
Um, okay. These are control flow and I'm lazy, so I'm going to do those later.
Um, but it shouldn't be that hard in theory. We just have to like play around with scope a little bit. Um, and then the experts. Lord knows what I'm going to do with those. Um, yeah, I think that's I think this is a pretty good place to start.
Um I guess here we can do start let's rename this more properly.
Uh start to mr for experts and instruction or experts plus instructions plus some helpers.
Okay.
All right. I think that is a good place to call today's stream though. Um, [sighs] yeah. Uh, thank you all so much for showing up today. Um, I don't know what I'm going to do tomorrow actually because it is day 200 tomorrow and I need to do something I want to do something special for that. Um, I was thinking about doing some config rewrite stuff, but I'm not sure how interesting that would be. And yeah, so uh stay tuned on that. I'll I'll plan that out. Um, if you haven't already, like the stream, sub to the channel. Um, if you want to support me financially, my GitHub sponsors is in the description. Um, that would be probably the least that would probably be the best place to do that. Um, join the Discord. That's in the description. Um, best place to get pinged. And yeah, I guess there are like two socials down there as well. Um, yeah, that's about it. I've dragged this on for long enough. Take care, y'all. Take it easy.
And I will see you all
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29











