Opened with Brainfuck, compared caveman speak to the x64 instruction set, and created a language even simpler than Python. My god, the steel balls and genius of this man are insane. Good things ahead for you. As an aspiring 17 year old programmer this vid makes me so happy.
Even though I knew basically how it works, the animation at around 4:00 gave me an intuitive understanding about how from binary information and simple register commands complex programs can emerge. I took me a real long time but I think this gave me kind of a breakthrough. Nice..
As a fellow programming language and compiler/program analysis enthusiast, I find your work very inspiring. I've only recently discovered that this is one of my favourite areas of swdev, and I'm very pleased to see someone else out there with the same passion!
The breadth and depth of this video is blowing my mind. I work in storage, and I find working on the data path challenging. I envy you Adam. Very nice video!
@@Microextent it's so bloated that a lot of its "features" make it actually SLOWER than ARM cpu stuff even tho ARM doesn't have as many optimization strategies
@@zackbuildit88 Absolutely, sometimes the phrase keep it simple stupid has great merit. Especially in complex systems like cpus, every one i have designed in logisim has been faster with less instructions. Sometimes you need to supplement with code but that is fine if you have fast clock speeds like all modern cpus do.
This dude casually demonstrates how he programmed a language, a compiler and a OS. He has Terry Davis levels of genius (Strictly talking about programming of course).
@@terminallychill8029 I mean, he said a couple of things that resonate with Diogenes philosophy from time to time. But what I meant it's that he's like Terry Davis without having to bring the other stuff he had.
@@adammcdaniel536 how were you brought up when young? How did you know you were interested in this stuff and how did you get so motivated in this industry?
this was such a good video, you explained these concepts really well and I think you made great choices about what to include/not include. I hope to see more videos in the future but for now I will check out your blog!
A cool way I've found to visualise what a compiler does goes as follows: When I tell you "the apple fell from the tree", we both imagine the same thing. However, our brain learned each of those concepts - apple, fall, origin, tree - and the relationships between them - "from" is synonymous with "origin" - through different ways. Therefore, no two brains are the same, even if they hear the same words and imagine the same concepts. Two computers with different architectures are like two different brains: the words (source code) are the same, and so are the results (the concepts and the relationships between them, the machine code is the neurons interacting to make what the end user sees), but the interpretation of the words into those concepts is different for every one (compiler).
I use a similar analogy to differentiate between interpreters and compilers. If we both know english, then i can give you instructions while you’re doing them like teaching you to cook a particular meal. But if i only know german and you know only english, i need a translator(a compiler) to do translate german to english. In this scenario you are the interpreter, you give meaning to combinations of sounds and the translator is the compiler.
Nice video. I do have to mention that not every compiler needs an IR. In fact, many early C compilers translated directly to machine code. IR does make value tracking much easier which is very important to modern optimizations. Also, not every compiler compiles to machine code. Some compilers compile to bytecode, and others compile to different source code. I would like to see you go over the frontend of a compiler more indepth. Parsing and building the AST and IR is something that can be very interesting.
If you don't use an intermediate representation, you need M * N backends for the compiler, while it's only M + N for those with intermediate representations. This is why GCC, Clang, Rust, Fortran, Haskell, and tons of others use IRs before compiling to machine code -- nearly all modern compiled languages do this Yes, I'm aware many languages don't compile to machine code -- Sage compiles to SageVM code, which can be interpreted or compiled for a target platform. These are really just a hypothetical "machine code" for an imaginary machine. Parsing, to me, is the least fun part of the compiler hahaha. The AST is essentially directly represented as an IR in Sage, and then lowered to another stage before being compiled to the VM.
I have 7 years of software development experience and recently get exposed to compiler, low level representation and type inference 😊. Your demo is clear and easy to follow!
I started coding in the 70s. There were no available languages, just machine code, all hex. That's how my journey started. I eventually went back to university , took a computer science degree, and learned a lot of this kind of stuff. Lots of theory and low-level concepts. I then worked for a company developing its own scripting language and compiler. This was my passion. I feel there are too many programming courses nowadays that focus heavily on web design, client server, Java and Python, etc. And miss out on the beauty hidden behind the scenes.
BF is actually really easy to write a compiler for because of its small instruction set. Its difficulty is that due to Its small instruction set, it's hard to do anything useful.
@@godowskygodowsky1155 I've made addition, subtraction, multiplication, division, greater than and less than in brainfuck, so i think i can actually start making things, but im too lazy to continue working on it lol
Great (albeit super abstract) overview of compilers. 90% of the time will be spent on optimizations, so it's not just important that you get the optimization sequencing correct, but also the AST transformations without losing the original meaning of the tree while still making good use of co-processors in the final binary executable/library output. Although languages like Rust, Haskell, and Idris make this task simpler via structured pattern matching, writing the optimizations themselves and seeing if they break other optimizations will still be a very hard task. Forgot to mention that on some hardware platforms, some very specific optimizations will turn out to be "slow downs", so be wary of that before customizing the optimizations that go into each target CPU/Co-processor.
So it's closer to a literary translation from one modern language to another than the examples given at the top of the video. Using different sets of fixed phrases and cultural references (e.g. Shakespeare quotes to Chinese classics) and convey not just the meaning but the author's intention (for compilers that mostly means recognizing which path is the hot one).
Dear god reading your resume and github as a 17 year old programmer is like a mortal staring at a god? what kind of free time do you have to do all this?
@@adammcdaniel536 oh god.. and your tryna be in the workforce. Dude. Chill. Like seriously you are the definition of talent. But yknow what ill admit youve got me excited to surpass you one day. Your doing much more than i ever thought that just possible for a casual programmer.
Very nice and in-depth overview of those topics. I'm highly interested in more information in those topics, so this is highly appreciated. Thanks for this and please keep it up 🙏
I absolutely adore this video! Hope to see more soon! On a more personal note, I really admire your passion for theoretical CS being taught in an applied manner! Hope we can chat and be friends someday! Would love to read a paper/book with you and discuss to your hearts content! You rock!!! :)
@tgrey_shift..mp334 Wow, thank you so much for the kind words! If you want to hang out with our community, you can join the Sage discord! I'm frequently there talking with others about type system things and off topic subjects! Hopefully I'll be making a new video relatively soon based on a new project I'm working on, which will likely be built on top of Sage's infrastructure!👀
2:36 Sumerian isn't any "smaller" or "simpler" than English just because it's an older language. Obviously this is just a metaphor, but if you know about linguistics then the metaphor kind of falls apart. Instead of translating from 1 natural language to the other, maybe something more accurate would be translating from English to formal logic, with the intermediate representation being a logic-based language like Lojban.
It's always interesting to me how many people think modern humans just a few thousand years ago were stupid idiots who couldn't even speak a proper language. A while ago I overheard a guy confidently explaining to his friends how biblical hebrew was incredibly "primitive" and how they didn't have poetry or complex narratives back then (while talking about the bible?!) because they were too busy getting chased by saber-toothed tigers (?!?). His main piece of evidence? That too many sentences in translations of the bible start with "and", which is obviously not something a "real language" would do. You know, that translation artifact of a grammatical construction (the vav-consecutive) that biblical hebrew had and modern english doesn't? Yeah, real primitive of them.
This video is basically about your personal abstract understanding of intermediate representations with a bit of Turing machines sprinkled in, and not about compilers. 1) Your definition of compilers is too restrictive - the IR is not a necessary step during compilation (if you included it, what about other (more significant than IR in my opinion) aspects of compilation such as lexing, building ATS, parsing, type checking, optimization, etc.) and the result of compilation doesn't have to be an executable binary (for example Cfront, the original compiler for C++, translated C++ source code to C source code, javac translates from Java SC to Java bytecode, and if you make a transpiler from brainfuck SC to C SC without generating an executable, it would still be considered a compiler) 2) The caveman analogy is unhelpful and misleading for programmers who don't know anything about compilers, and for those who do it will look as an unnecessary gross oversimplification 3) The part about translating high level languages to IR doesn't explain anything about compilers, and programmers who aren't familiar with compilers and Rust won't be able to understand it The video production is good though, would be great to see an indepth explanation of all compilation stages for a real language with actual code (tcc for example)
Agreed. I’d be surprised if early C compilers used an IR, and compilers existed way before that. The presenting of IR as a core step is vey misleading. On production values; some of the text is unreadably small. IMO this kind of “instruction” would be clearer in a blog post or similar b
ok so i have a few questions. i really appreciate your comment btw friend. on number 2, could you elaborate on why its a bad example, or perhaps on what a better example would be? also, what resources do you respect for learning how to make a compiler like this? again, thanks for these points :)
Great video. Especially interesting as I'm looking forward to write my first compiler myself soon. I found it quite frustrating to find a language to write the compiler in. As the reason for creating my own language was that I wanted to combine multiple languages powers into one. This however led to frustration while writing the compiler. I ran into the problems I wanted to solve compared to the other languages and wished I could write it in my own language. But I know that I at least have to write a bare minimum compiler in some other language to be able to bootstrap it.
Thanks so much, I appreciate the kind words a ton!! I LOVE the Ukraine flag behind the Haskell logo lamba!!!🇺🇦🇺🇦🇺🇦🇺🇦🇺🇦🇺🇦🐑🐑🐑🐑🐑🐑 SLAVA UKRAINI🇺🇦🇺🇦🇺🇦🇺🇦🇺🇦🇺🇦🇺🇦
Great video. You just earned a new sub at 3:37. I’m starting my courses for B.S. in Cloud Computing in December. All of this is VERY new to me as i had no background in any of it. What you showed at 3:37 helped alot as i didn’t know what any of the instructions translate to. Now that i’ve got the basic knowledge of the symbols and what they do it’s making things alot more easier. Want to ask a favor. Do you think you can make a video thats more in depth and detailed for all the symbols or instructions and their functions please? Also how they could be used as an example. Once again I’m very new to the whole subject of computer coding and the different languages and what they’re used for. Thanks.
One feature I'd like to see in more compilers is full compile time execution. That's what I'm working on in mine. Essentially I'm compiling to a custom byte code, executing it in a VM, and then inserting the output back into the earlier stages of the compiler.
The latest PR for sage DOES have compile time execution!!! Sage has an interpreter which can run at compile time -- also, the new PR adds a Lisp language as an AST preprocessor system which can manipulate user programs to add tests or benchmarks. With this system, you'll be able to write Sage to modify your Sage code!!!!
@@adammcdaniel536 Oh nice! Having one language to do all the things is my goal. For example, one specific feature of many languages that's always bugged me is, meta programming using a totally different syntax to the rest of the language. An example that many will be familiar with is Typescript's mapped types. Consider the following: ``` type Readonly = { +readonly [K in keyof T] T[K], } ``` A fairly simple example. It just adds the readonly attribute to each property of some type T. My problem with this is that it's not really Typescript code. To express the same in normal TS code you'd write something like: ``` function Readonly(T: type): type { const result = typeDescriptorOf(T); for (const prop of result.properties) { prop.readonly = true; } return descriptorToType(result); } ``` It's more verbose, but it's also more accessible to Typescript developers. Because, instead of being a separate syntax with different rules, it's just code. The only difference is it runs at compile time. Prior art would be comptime in the Zig language, and #run in the Jai language. I think D also had something like this, but it's been a really long time since I used that 😅
The Dragon Book would be a kinda obvious reference to cite... but can I also recommend "Understanding and Writing Compilers" by Richard Bornat a particular favourite of mine. :)
Fantastic video dude. A video in more detail about the typechecker would be awesome. Alao youve dine a lot, im only just getting inro compielrs and this stuff blows my mind.
You should mention to people that it is really easy to write an interpreter in JavaScript to have your own programming language, that runs in the browser or in node. Of course that isn't quite as performant as using assembler or C and writing a compiler...but it means they can create almost anything, the very kind of stuff that you would do, without having to do quite as much heavy lifting. I'm working on a programming language with Klingon keywords, myself.
If you're really interested in this topic, I would recommend taking these courses: nand2tetris and nand2tetris2, its heavy, long but totally worth it. You start by building logical gates with boolean algebra, you build an ALU, RAM, Registers... then a CPU and wire everything together using hardware description language (HDL). Then you program your CPU in binary, then you create an assembler for an assembly language, then you build a Java-like language and a compiler, then you build an OS and programs for it on your language. Highly Recommended!!! Thanks for the video.
Or an even deeper course: Project Oberon - a complete RISC CPU + VGA + PS/2 keyboard and mouse controllers + SD card controller, all in a simplified HDL, along with a complete OS and a high level language compiler. With a windowed GUI.
@@jordixboy youtube is likely to delete comments with links. Just search for "Project Oberon", you'll find all the course material in the first few links.
@@knkootbaoat6759 Yep the more time passes, the more I feel like I just have the sound of the voice and that's it. It became almost impossible to follow a video with music.
Great video, however it gives a vibe of the "draw the rest of the owl" meme in terms of how high level the explanations are. I've got an interest in building programming languages and so far the hardest part is changing from an interpreter to a compiler (which I have yet to do). You mention you use IRs to represent the higher level code in a form that's easier for the compiler to deal with. However you didn't really explain about what should go into an IR. How much of the original language should be stripped out? At what point should the IR be translated into another IR (if at all)? Another thing with the same "draw the rest of the owl" feeling is the final SageVM asm to native machine code step. IMO that is the most important step, but you glossed over it so fast that I wondered of it is indeed that easy (probably not). Summing up, I guess I had different expectations for this video based on the title than what was actually presented (a more low level view vs the high level view presented in the video). As another commenter said, great presentation, great dowmo. But as an educational explainer, leaves people more confused after watching it than before.
PLEASE make more videos like this, explaining the base stuff that nobody really bothers to learn because of the complexity in the multi page documents and unclear videos. I'm not very good with code, but you made me understand brainfuck
I created a compiler for my own language but didn't create an IR language. The "compiler" has 2 execution modes: directly intrepret or transpile to another language (C and Java). In either case, the AST is used directly in the final step, without any IR. What advantages would create an IR bring to this compiler? I'm not compiling to assembly, so the "intermediate simpler language" point doesn't seem to matter here. Unless I can use it somehow to simplify the transpilation into other languages. Can you provide insights on how an IR would be useful for this compiler?
You already have an intermediate language: your intermediate language here is C or Java. You're compiling to C or Java before that gets compiled to an even lower form that can be executed. These languages aren't executed by machines in the source code form -- you depend on the abstractions these languages provide that make it easier on you to execute your code. One drawback of relying on C and Java is that it's harder to get it working in an environment like the web -- you'd have to write a JavaScript backend or port the interpreter, which may be difficult depending on how you implemented your other backends. Porting an IR language to the web can be easier if you design it to be more abstract for other platforms The benefit of creating your own IR is that you can perform optimizations with the knowledge of the kind of code your frontend produces -- C can't optimize certain things that might be possible with the knowledge of how it got compiled. You can also represent constructs for your source language in your IR that make it map simpler to your language, so the logic for lowering the AST to your IR is simplified Additionally, you don't have to rely on GCC or Javac -- you can do the compilation yourself with no dependencies
this used to be the case, but CPUs have advanced significantly since C was created, and the C standard has not/will not/cannot change enough to keep up with it. there are a _lot_ of adjustments and optimizations that the GCC does to keep C performing at the blazing speeds we expect of it. see "C Is Not a Low-Level Language".
In all my years of learning and studying, I have found the best people to learn from are the ones that are not geniuses. Geniuses forget they are geniuses, and often leave you behind a few sentences in. I will say, I find people who are physicists usually can explain things a lot clearly than most. Lol.
I just stumbled across your channel and visited your website, and I am awestruck. The number of projects you’ve built with such detail and depth at your age is mad impressive. Do you have any books or resources you could share that you believe helped bring you to where you are today? I’d love to learn more about the topics you’ve covered and cultivating the work ethic you possess :)
Interesting video, thank you. 19:29 constants are a subset of expressions. types are a subset of constants. The arrows in the diagram are pointing from constants to expressions and from constants to types, even though they have opposite relationships. Am I missing something?
@@joviel6620 The reason there are arrows from both Expr and Const to Types is, even though types are a subset of constant expressions, every expression and constant *must* have an associated type with it -- all expressions and constants must be able to produce their "type" papers at the type checking customs office. Maybe I should've had the arrow indicate your understanding, in which case it would be the other way haha. Sorry for the confusion!
Great video! It's really well made and very educational. BTW, your website's About Me has a small error in the spanish section. "He estado hablando" implies you started talking spanish in 2021, and haven't ever stopped since. A more correct way to say that would be "(Yo) Llevo hablando español desde 2021". I'd also recommend changing "puedo hablar muy bien" to "puedo hablar*lo* muy bien" (I can speak very well --> I can speak it very well).
It would be really nice to see the OS run on simple embedded platform (ARM/Risc V) with screen and keyboard. Then you can run compiler on it. No longer need to have PC.
Thanks a lot man for the informations. Hope to see more from you. Really enjoyed the video. [ Tho a bit harsh for my brain to understand it all so I will be watching them for a number of time to understand it whole.] Keep'em coming
Are there compilers or research being carried out that make use of machine learning or some form of AI to optimize the process of converting high-level programming languages to machine code or even in debugging steps? (The AI hype is crazy, I know!)
That's great, writing an interpreter is always a super important first step towards a compiler!!! Have you experimented with lisp at all? Lisp is an incredible start towards making one's own programming language!!!
@@adammcdaniel536 I’ve never tried Lisp, and honestly, given the “mystique” it gives off, it sounds like a mind-bending experience (coming from self-taught web dev trying to learn how computers really work). But I am VERY interested in FP as well: I was thinking about Elixir for future job prospects or OCaml because of its overall shilling on various platforms😄 Any specific variety of Lisp?
x86 and ARM are different organizations of CPU instructions that CPUs can run directly A compiler is a program. It's stored in memory and executed by a CPU
It would be great if you could make a video or just post a blog about the prerequisites to actually make your own compiler or language,though this video serves as a good introduction as to how a compiler is supposed to work,the knowledge can't be directly used to implement a language as such. Alot of things need to be explored prior to even attempting to build your own compiler,i hope that you can make a blog about all the prequisites required from beginning to end.
I made a language called que in 2 weeks from scratch. It used byte code interpretation instead of fully compiling to machine code, but still quite cool. It’s interesting that your byte code is more high level than mine was. Mine was almost one to one with the ARM instruction set. I figured if it were low level it would be easy to translate, but I think that wasn’t correct thinking.
Hey, great video, I juste have a question. I'm finishing programming a chess engine in c and I would like to begin another big project, is creating an os a good idea? It requires a lot of work but it seems like the most instructive
Compilers are not limited to programs that generate machine code... it is any program which takes a language as input and generates another one as output. Not limited to machine code
ITS MY SLEEPOVER AND I GET TO PICK THE MOVIE
please invite me to all your parties! 🎈
so u pick how to write compilers from scratch? 😹
Finished a Masters at 22, and producing such neatly commentated videos... you're spectacular
@@fangbozhu7379 Thank you so much!
Yooo, you were my TA. Quality content and super clear way of explaining!
Hahaha great to see you here! Thanks so much!
Opened with Brainfuck, compared caveman speak to the x64 instruction set, and created a language even simpler than Python. My god, the steel balls and genius of this man are insane. Good things ahead for you. As an aspiring 17 year old programmer this vid makes me so happy.
FALSE is better
Even though I knew basically how it works, the animation at around 4:00 gave me an intuitive understanding about how from binary information and simple register commands complex programs can emerge. I took me a real long time but I think this gave me kind of a breakthrough. Nice..
As a fellow programming language and compiler/program analysis enthusiast, I find your work very inspiring. I've only recently discovered that this is one of my favourite areas of swdev, and I'm very pleased to see someone else out there with the same passion!
The breadth and depth of this video is blowing my mind. I work in storage, and I find working on the data path challenging. I envy you Adam. Very nice video!
Thank you so much, that's super kind!! I'm glad you liked it, I worked hard on it!! Hahaha
1:51 "...very few grunts and gestures"
x86-84 Instruction Set: Am I a joke to you?
Textbook definition of bloat tbh
@@zackbuildit88 i 100% agree
@@Microextent it's so bloated that a lot of its "features" make it actually SLOWER than ARM cpu stuff even tho ARM doesn't have as many optimization strategies
@@zackbuildit88 Absolutely, sometimes the phrase keep it simple stupid has great merit. Especially in complex systems like cpus, every one i have designed in logisim has been faster with less instructions. Sometimes you need to supplement with code but that is fine if you have fast clock speeds like all modern cpus do.
@@Microextent You said "actually" like you were gonna contradict me but, based on what you said, you agree with me. What? [Edit: I misread]
I love your use of Manim! I've always been a fan of PL theory + Compilers, so videos like this are always great to see!
This dude casually demonstrates how he programmed a language, a compiler and a OS. He has Terry Davis levels of genius (Strictly talking about programming of course).
Thank you so much!!! Terry Davis was certainly one of my heroes in highschool; he's God's chosen programmer after all!!!
I'd say that makes this video blasphemy and you a heretic - but in a good way
What other kinds of genius did Terry Davis have 🤔
@@terminallychill8029 I mean, he said a couple of things that resonate with Diogenes philosophy from time to time. But what I meant it's that he's like Terry Davis without having to bring the other stuff he had.
@@adammcdaniel536 how were you brought up when young? How did you know you were interested in this stuff and how did you get so motivated in this industry?
this was such a good video, you explained these concepts really well and I think you made great choices about what to include/not include. I hope to see more videos in the future but for now I will check out your blog!
This is one of those guys that appear from nowhere , drop a banger, then vanish forever
The video is really high quality.
Keep making more.
Thank you so much, I really appreciate the kind words!!!
A cool way I've found to visualise what a compiler does goes as follows:
When I tell you "the apple fell from the tree", we both imagine the same thing. However, our brain learned each of those concepts - apple, fall, origin, tree - and the relationships between them - "from" is synonymous with "origin" - through different ways. Therefore, no two brains are the same, even if they hear the same words and imagine the same concepts.
Two computers with different architectures are like two different brains: the words (source code) are the same, and so are the results (the concepts and the relationships between them, the machine code is the neurons interacting to make what the end user sees), but the interpretation of the words into those concepts is different for every one (compiler).
So we're all imagining that one picture of Newton, right?
I use a similar analogy to differentiate between interpreters and compilers. If we both know english, then i can give you instructions while you’re doing them like teaching you to cook a particular meal. But if i only know german and you know only english, i need a translator(a compiler) to do translate german to english. In this scenario you are the interpreter, you give meaning to combinations of sounds and the translator is the compiler.
@@uncleswell ... I wasn't at first but now I wonder how many different images of Newton there are
@@casev799 7
@@uncleswellwell, I am **now**
Top-notch presentation. I look forward to seeing the subs. rise up.
Thank you so much, I'm really glad you liked it!! I hope to deliver more enjoyable content soon with what I've learned!!!
Really enjoying your output. The music is very complimentary.
Now I won't deny it, I do learn but it's also great to listen to to go to sleep.
The thumbnail attracts me immediately when I saw it, great stuff!
Where were you when I was in school? Real talk, huge respect for your work and your way of presenting and explaining stuff :) Keep up the good work!
This is actually insane! Puts my little scripting language pet project to shame haha
Hahaha thanks so much, I appreciate it!!😄
I love people like you who delve into the fundamentals and build actually cool things.
5 seconds in and i get the best definition of what a computer is in my years of CE
Nice video. I do have to mention that not every compiler needs an IR. In fact, many early C compilers translated directly to machine code. IR does make value tracking much easier which is very important to modern optimizations. Also, not every compiler compiles to machine code. Some compilers compile to bytecode, and others compile to different source code.
I would like to see you go over the frontend of a compiler more indepth. Parsing and building the AST and IR is something that can be very interesting.
If you don't use an intermediate representation, you need M * N backends for the compiler, while it's only M + N for those with intermediate representations.
This is why GCC, Clang, Rust, Fortran, Haskell, and tons of others use IRs before compiling to machine code -- nearly all modern compiled languages do this
Yes, I'm aware many languages don't compile to machine code -- Sage compiles to SageVM code, which can be interpreted or compiled for a target platform. These are really just a hypothetical "machine code" for an imaginary machine.
Parsing, to me, is the least fun part of the compiler hahaha. The AST is essentially directly represented as an IR in Sage, and then lowered to another stage before being compiled to the VM.
I have 7 years of software development experience and recently get exposed to compiler, low level representation and type inference 😊. Your demo is clear and easy to follow!
I started coding in the 70s. There were no available languages, just machine code, all hex. That's how my journey started. I eventually went back to university , took a computer science degree, and learned a lot of this kind of stuff. Lots of theory and low-level concepts. I then worked for a company developing its own scripting language and compiler. This was my passion. I feel there are too many programming courses nowadays that focus heavily on web design, client server, Java and Python, etc. And miss out on the beauty hidden behind the scenes.
Bro opened with brainfuck 💀
Good choice for a simple machine code tbh
Hahahaha I had to do it to 'em
BF is actually really easy to write a compiler for because of its small instruction set. Its difficulty is that due to Its small instruction set, it's hard to do anything useful.
BF is also baby's first esolang. If someone starts off with Malbolge then you know you're in for a wild ride.
@@godowskygodowsky1155 I've made addition, subtraction, multiplication, division, greater than and less than in brainfuck, so i think i can actually start making things, but im too lazy to continue working on it lol
I thought this video had like 1249124 views the first 2 minutes watching, how'd I just come across this randomly? Great stuff!
Thank you so much, I'm glad you enjoyed it!! I think it's an incredibly interesting subject, I'm glad the TH-cam algorithm showed it to you hahaha
real nice. I see a soon-to-be successful channel in CS. keep up the good work!
Great (albeit super abstract) overview of compilers.
90% of the time will be spent on optimizations, so it's not just important that you get the optimization sequencing correct, but also the AST transformations without losing the original meaning of the tree while still making good use of co-processors in the final binary executable/library output.
Although languages like Rust, Haskell, and Idris make this task simpler via structured pattern matching, writing the optimizations themselves and seeing if they break other optimizations will still be a very hard task. Forgot to mention that on some hardware platforms, some very specific optimizations will turn out to be "slow downs", so be wary of that before customizing the optimizations that go into each target CPU/Co-processor.
So it's closer to a literary translation from one modern language to another than the examples given at the top of the video. Using different sets of fixed phrases and cultural references (e.g. Shakespeare quotes to Chinese classics) and convey not just the meaning but the author's intention (for compilers that mostly means recognizing which path is the hot one).
he had to translate it into something my caveman brain could understand
Dear god reading your resume and github as a 17 year old programmer is like a mortal staring at a god? what kind of free time do you have to do all this?
@@obiomajronyekwere4469 Thank you so so much! Hahaha very little free time, but I don't play games or much else. Music and programming are my hobbies!
@@adammcdaniel536 oh god.. and your tryna be in the workforce. Dude. Chill. Like seriously you are the definition of talent. But yknow what ill admit youve got me excited to surpass you one day. Your doing much more than i ever thought that just possible for a casual programmer.
Awesome video and narration! finally got the time to sit down and watch. very informative!
@@abrianabir7127 Thanks so much, Im glad you liked it! :D
You are great, we want a full series on the compiler, language design, type system 😅😅😅
Brainfuck mentioned, let's go! I actually started writing a compiler for (human readable to) Brainfuck a little while ago!
Keep up the good work! Such a concise yet understandable video.
Very nice and in-depth overview of those topics. I'm highly interested in more information in those topics, so this is highly appreciated. Thanks for this and please keep it up 🙏
I absolutely adore this video! Hope to see more soon!
On a more personal note, I really admire your passion for theoretical CS being taught in an applied manner! Hope we can chat and be friends someday!
Would love to read a paper/book with you and discuss to your hearts content!
You rock!!! :)
@tgrey_shift..mp334 Wow, thank you so much for the kind words!
If you want to hang out with our community, you can join the Sage discord! I'm frequently there talking with others about type system things and off topic subjects!
Hopefully I'll be making a new video relatively soon based on a new project I'm working on, which will likely be built on top of Sage's infrastructure!👀
Great content. Much better audio mix.
Thank you so much!! I'm glad it's an improvement!
You live in TN? HELL YEA dude. Exciting to see a programmer content creator living here in this hill Billy hell.
2:36 Sumerian isn't any "smaller" or "simpler" than English just because it's an older language. Obviously this is just a metaphor, but if you know about linguistics then the metaphor kind of falls apart. Instead of translating from 1 natural language to the other, maybe something more accurate would be translating from English to formal logic, with the intermediate representation being a logic-based language like Lojban.
It's always interesting to me how many people think modern humans just a few thousand years ago were stupid idiots who couldn't even speak a proper language.
A while ago I overheard a guy confidently explaining to his friends how biblical hebrew was incredibly "primitive" and how they didn't have poetry or complex narratives back then (while talking about the bible?!) because they were too busy getting chased by saber-toothed tigers (?!?). His main piece of evidence? That too many sentences in translations of the bible start with "and", which is obviously not something a "real language" would do. You know, that translation artifact of a grammatical construction (the vav-consecutive) that biblical hebrew had and modern english doesn't? Yeah, real primitive of them.
1:02 According to Bornat a major role of compilers is giving good error messages when compliation fails.
This guy compiles. Awesome
This is so awesome... Waiting for more such videos. Kudos 🎉
This was pretty useful in increasing my understanding of the subject
@@Miguel_Vitta Thank you, I'm glad it could help!
Really Awesome work! It's really nice to see a fellow Programming Language Enthusiast. Keep up the great work!
Thank you so much!!
This video is basically about your personal abstract understanding of intermediate representations with a bit of Turing machines sprinkled in, and not about compilers.
1) Your definition of compilers is too restrictive - the IR is not a necessary step during compilation (if you included it, what about other (more significant than IR in my opinion) aspects of compilation such as lexing, building ATS, parsing, type checking, optimization, etc.) and the result of compilation doesn't have to be an executable binary (for example Cfront, the original compiler for C++, translated C++ source code to C source code, javac translates from Java SC to Java bytecode, and if you make a transpiler from brainfuck SC to C SC without generating an executable, it would still be considered a compiler)
2) The caveman analogy is unhelpful and misleading for programmers who don't know anything about compilers, and for those who do it will look as an unnecessary gross oversimplification
3) The part about translating high level languages to IR doesn't explain anything about compilers, and programmers who aren't familiar with compilers and Rust won't be able to understand it
The video production is good though, would be great to see an indepth explanation of all compilation stages for a real language with actual code (tcc for example)
Agreed. I’d be surprised if early C compilers used an IR, and compilers existed way before that. The presenting of IR as a core step is vey misleading.
On production values; some of the text is unreadably small.
IMO this kind of “instruction” would be clearer in a blog post or similar b
ok so i have a few questions. i really appreciate your comment btw friend. on number 2, could you elaborate on why its a bad example, or perhaps on what a better example would be? also, what resources do you respect for learning how to make a compiler like this? again, thanks for these points :)
I am waiting for your video
@@chocolatezt no, but its better if he do it ;)
@@bossgd100yeah, just use flawed knowledge until then, because nothing is gospel unless it's on TH-cam. For once in your life, read a textbook.
Good stuff my man!
Thank you!! It took years to get the compiler solid hahaha
Great video. Especially interesting as I'm looking forward to write my first compiler myself soon. I found it quite frustrating to find a language to write the compiler in. As the reason for creating my own language was that I wanted to combine multiple languages powers into one. This however led to frustration while writing the compiler. I ran into the problems I wanted to solve compared to the other languages and wished I could write it in my own language. But I know that I at least have to write a bare minimum compiler in some other language to be able to bootstrap it.
That's the content we need!
Thanks so much, I appreciate the kind words a ton!! I LOVE the Ukraine flag behind the Haskell logo lamba!!!🇺🇦🇺🇦🇺🇦🇺🇦🇺🇦🇺🇦🐑🐑🐑🐑🐑🐑 SLAVA UKRAINI🇺🇦🇺🇦🇺🇦🇺🇦🇺🇦🇺🇦🇺🇦
Just checked out your website and you are truly impressive. Would appreciate having you as mentor or tutor
Thanks so much for this - I was in the process of writing a brainfuck compiler and this gives me a good roadmap of what’s next
Dude! You're not one of the soy boys, this is actually the kind of stuff I wanna watch! I subbed and liked.
Damn, great video, you definitely deserve more views and subs
Thank you so much, I'm really glad you appreciated this content!! I spent a lot of time on it :)
I loved this video, nice job :D
Thanks so much!! :)
awesome quality and very interesting. I really want to take a course in programming language theory in the future.
Great video. You just earned a new sub at 3:37. I’m starting my courses for B.S. in Cloud Computing in December. All of this is VERY new to me as i had no background in any of it. What you showed at 3:37 helped alot as i didn’t know what any of the instructions translate to. Now that i’ve got the basic knowledge of the symbols and what they do it’s making things alot more easier. Want to ask a favor. Do you think you can make a video thats more in depth and detailed for all the symbols or instructions and their functions please? Also how they could be used as an example. Once again I’m very new to the whole subject of computer coding and the different languages and what they’re used for. Thanks.
wow this really helped me understand the basics of it
Shout-out to UT! I still go back to Dr.Plank's course websites years later to refresh on concepts!
This is fantastic, thanks!
Brilliant video! I hope you continue making videos on computer science
One feature I'd like to see in more compilers is full compile time execution. That's what I'm working on in mine. Essentially I'm compiling to a custom byte code, executing it in a VM, and then inserting the output back into the earlier stages of the compiler.
The latest PR for sage DOES have compile time execution!!! Sage has an interpreter which can run at compile time -- also, the new PR adds a Lisp language as an AST preprocessor system which can manipulate user programs to add tests or benchmarks.
With this system, you'll be able to write Sage to modify your Sage code!!!!
@@adammcdaniel536 Oh nice! Having one language to do all the things is my goal. For example, one specific feature of many languages that's always bugged me is, meta programming using a totally different syntax to the rest of the language.
An example that many will be familiar with is Typescript's mapped types. Consider the following:
```
type Readonly = {
+readonly [K in keyof T] T[K],
}
```
A fairly simple example. It just adds the readonly attribute to each property of some type T.
My problem with this is that it's not really Typescript code. To express the same in normal TS code you'd write something like:
```
function Readonly(T: type): type {
const result = typeDescriptorOf(T);
for (const prop of result.properties) {
prop.readonly = true;
}
return descriptorToType(result);
}
```
It's more verbose, but it's also more accessible to Typescript developers. Because, instead of being a separate syntax with different rules, it's just code. The only difference is it runs at compile time.
Prior art would be comptime in the Zig language, and #run in the Jai language. I think D also had something like this, but it's been a really long time since I used that 😅
Brilliant! Keep up the great work.
Another genius kid in programming. They must be stopped
The Dragon Book would be a kinda obvious reference to cite... but can I also recommend "Understanding and Writing Compilers" by Richard Bornat a particular favourite of mine. :)
👌🏾 thank you for sharing your gift with us all
Nice video, I know you from your old blog where you talked about compilers!
Fantastic video dude. A video in more detail about the typechecker would be awesome. Alao youve dine a lot, im only just getting inro compielrs and this stuff blows my mind.
I can tell you are using manim for your visualizations. Awesome job Adam!
Best CS 302 TA out there.
@@worldordergaming3449 Thank you so much for the kind words! It's great to see my fellow classmates here! :D
Great content!
Out of curiosity, are you using manim to do the animations?
@@chiquiflautro Thank you so much, and yes I'm using Manim!
You should mention to people that it is really easy to write an interpreter in JavaScript to have your own programming language, that runs in the browser or in node.
Of course that isn't quite as performant as using assembler or C and writing a compiler...but it means they can create almost anything, the very kind of stuff that you would do, without having to do quite as much heavy lifting.
I'm working on a programming language with Klingon keywords, myself.
If you're really interested in this topic, I would recommend taking these courses: nand2tetris and nand2tetris2, its heavy, long but totally worth it. You start by building logical gates with boolean algebra, you build an ALU, RAM, Registers... then a CPU and wire everything together using hardware description language (HDL). Then you program your CPU in binary, then you create an assembler for an assembly language, then you build a Java-like language and a compiler, then you build an OS and programs for it on your language. Highly Recommended!!!
Thanks for the video.
Or an even deeper course: Project Oberon - a complete RISC CPU + VGA + PS/2 keyboard and mouse controllers + SD card controller, all in a simplified HDL, along with a complete OS and a high level language compiler. With a windowed GUI.
@@vitalyl1327 interesting! any link? is this a course or something?
@@jordixboy youtube is likely to delete comments with links. Just search for "Project Oberon", you'll find all the course material in the first few links.
@@jordixboy just look up the "Wirth Project Oberon". Links are problematic here.
Nice with new audio ahah. Keep it up!
Thank you!!
i didnt view the other videos. but man audio makes such a HUGE difference in terms of watchability (at least for me)
@@knkootbaoat6759 Yep the more time passes, the more I feel like I just have the sound of the voice and that's it. It became almost impossible to follow a video with music.
2:42
Such a great "conveniently". Kinda funny how so many of humanity's greatest inventions work thanks to conveniences like this. 😁
Great video, however it gives a vibe of the "draw the rest of the owl" meme in terms of how high level the explanations are.
I've got an interest in building programming languages and so far the hardest part is changing from an interpreter to a compiler (which I have yet to do).
You mention you use IRs to represent the higher level code in a form that's easier for the compiler to deal with. However you didn't really explain about what should go into an IR. How much of the original language should be stripped out? At what point should the IR be translated into another IR (if at all)?
Another thing with the same "draw the rest of the owl" feeling is the final SageVM asm to native machine code step. IMO that is the most important step, but you glossed over it so fast that I wondered of it is indeed that easy (probably not).
Summing up, I guess I had different expectations for this video based on the title than what was actually presented (a more low level view vs the high level view presented in the video). As another commenter said, great presentation, great dowmo. But as an educational explainer, leaves people more confused after watching it than before.
0:42 damn, you are 22 and finished with your masters damn
I'm 21 and am thinking of opting for a masters degree after I graduate in a year
PhD at 22. That’s it. I’m so cooked 🙏
Stop trying to make “cooked” a thing
@@JohnSmith-op7ls ur right bro. My vocabulary is cooked 😔
i always had a phd, a pretty huge d-
bro it's ok he's a PHD student, he doesn't actually have his PhD yet lol
@@shaquille_oatmeal207chat, are we oatmeal's vocabulary?
Fellow Vol! Great video, interested to see your research.
Exceptional work!
@@kevin42 Thank you!!
PLEASE make more videos like this, explaining the base stuff that nobody really bothers to learn because of the complexity in the multi page documents and unclear videos. I'm not very good with code, but you made me understand brainfuck
I created a compiler for my own language but didn't create an IR language. The "compiler" has 2 execution modes: directly intrepret or transpile to another language (C and Java). In either case, the AST is used directly in the final step, without any IR. What advantages would create an IR bring to this compiler? I'm not compiling to assembly, so the "intermediate simpler language" point doesn't seem to matter here. Unless I can use it somehow to simplify the transpilation into other languages. Can you provide insights on how an IR would be useful for this compiler?
You already have an intermediate language: your intermediate language here is C or Java. You're compiling to C or Java before that gets compiled to an even lower form that can be executed. These languages aren't executed by machines in the source code form -- you depend on the abstractions these languages provide that make it easier on you to execute your code.
One drawback of relying on C and Java is that it's harder to get it working in an environment like the web -- you'd have to write a JavaScript backend or port the interpreter, which may be difficult depending on how you implemented your other backends. Porting an IR language to the web can be easier if you design it to be more abstract for other platforms
The benefit of creating your own IR is that you can perform optimizations with the knowledge of the kind of code your frontend produces -- C can't optimize certain things that might be possible with the knowledge of how it got compiled.
You can also represent constructs for your source language in your IR that make it map simpler to your language, so the logic for lowering the AST to your IR is simplified
Additionally, you don't have to rely on GCC or Javac -- you can do the compilation yourself with no dependencies
Super clear and good content! Btw, what do you use to do these animations?
Holy C compiler translates source to machine code directly line by line.
No intermediate representation is required depending on the language.
this used to be the case, but CPUs have advanced significantly since C was created, and the C standard has not/will not/cannot change enough to keep up with it. there are a _lot_ of adjustments and optimizations that the GCC does to keep C performing at the blazing speeds we expect of it. see "C Is Not a Low-Level Language".
@@toricon8070 OP was talking about Holy C, not C, that's another language. Although I'm not sure if the given information is correct.
@@sudarshanrobot oh thank you! that will be fun to learn about
The tiny C compiler is also famously a single-pass compiler
In all my years of learning and studying, I have found the best people to learn from are the ones that are not geniuses. Geniuses forget they are geniuses, and often leave you behind a few sentences in. I will say, I find people who are physicists usually can explain things a lot clearly than most. Lol.
I just stumbled across your channel and visited your website, and I am awestruck. The number of projects you’ve built with such detail and depth at your age is mad impressive. Do you have any books or resources you could share that you believe helped bring you to where you are today? I’d love to learn more about the topics you’ve covered and cultivating the work ethic you possess :)
Now you became my inspiration ❤️
Interesting video, thank you.
19:29 constants are a subset of expressions. types are a subset of constants. The arrows in the diagram are pointing from constants to expressions and from constants to types, even though they have opposite relationships. Am I missing something?
@@joviel6620 The reason there are arrows from both Expr and Const to Types is, even though types are a subset of constant expressions, every expression and constant *must* have an associated type with it -- all expressions and constants must be able to produce their "type" papers at the type checking customs office. Maybe I should've had the arrow indicate your understanding, in which case it would be the other way haha. Sorry for the confusion!
@@adammcdaniel536thanks for the clarification!
Inspiration dude
20:23 10/10 on intense musical fade-inn on epic greatness 🫡
Great video! It's really well made and very educational.
BTW, your website's About Me has a small error in the spanish section. "He estado hablando" implies you started talking spanish in 2021, and haven't ever stopped since. A more correct way to say that would be "(Yo) Llevo hablando español desde 2021". I'd also recommend changing "puedo hablar muy bien" to "puedo hablar*lo* muy bien" (I can speak very well --> I can speak it very well).
You're a great communicator
@@discotecc Thanks so much!!
It would be really nice to see the OS run on simple embedded platform (ARM/Risc V) with screen and keyboard. Then you can run compiler on it. No longer need to have PC.
Thanks a lot man for the informations. Hope to see more from you. Really enjoyed the video. [ Tho a bit harsh for my brain to understand it all so I will be watching them for a number of time to understand it whole.] Keep'em coming
Are there compilers or research being carried out that make use of machine learning or some form of AI to optimize the process of converting high-level programming languages to machine code or even in debugging steps? (The AI hype is crazy, I know!)
Awesome vid, will follow your content with great pleasure; just started reading crafting interpreters and will try some funky zig stuff
That's great, writing an interpreter is always a super important first step towards a compiler!!! Have you experimented with lisp at all? Lisp is an incredible start towards making one's own programming language!!!
@@adammcdaniel536 I’ve never tried Lisp, and honestly, given the “mystique” it gives off, it sounds like a mind-bending experience (coming from self-taught web dev trying to learn how computers really work). But I am VERY interested in FP as well: I was thinking about Elixir for future job prospects or OCaml because of its overall shilling on various platforms😄 Any specific variety of Lisp?
So x86 and ARM are sets of instructions for compilers?
Is a compiler something physical? Where is it located, in the CPU?
x86 and ARM are different organizations of CPU instructions that CPUs can run directly
A compiler is a program. It's stored in memory and executed by a CPU
@@adammcdaniel536 thanks
Very nice explanation. Not too much whiteboarding and very easy to follow code. Good luck with your PhD :)
Your voice is so cute 🥰. Your promotor is so lucky to work with you
What is the piece that plays at 9:44?
It would be great if you could make a video or just post a blog about the prerequisites to actually make your own compiler or language,though this video serves as a good introduction as to how a compiler is supposed to work,the knowledge can't be directly used to implement a language as such.
Alot of things need to be explored prior to even attempting to build your own compiler,i hope that you can make a blog about all the prequisites required from beginning to end.
Seconded🙋
I made a language called que in 2 weeks from scratch. It used byte code interpretation instead of fully compiling to machine code, but still quite cool. It’s interesting that your byte code is more high level than mine was. Mine was almost one to one with the ARM instruction set. I figured if it were low level it would be easy to translate, but I think that wasn’t correct thinking.
Hey, great video, I juste have a question. I'm finishing programming a chess engine in c and I would like to begin another big project, is creating an os a good idea? It requires a lot of work but it seems like the most instructive
Compilers are not limited to programs that generate machine code... it is any program which takes a language as input and generates another one as output. Not limited to machine code
Yep, you can compile to an IR or another source language if you like
Great video!