1. Home
  2. Explore
  3. Computer Science
  4. Crust Programming Language

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Crust Programming Language

Transcript

Hello everyone and welcome to yet another recreation programming session with a Mr. Auzin as usual. So on the previous stream we did a little bit of a crust right so for those who doesn't know crust is a version of rust where we fully give in into unsafe right so uh let me actually show you an example of crust I think it was somewhere here so here is no it's not was not here so here it is so essentially we have a bunch of rules in here is that every function is

unsafe we do not use any references only points pointers we don't do not use the std library we use only lip c right and pointers, are a, mutability, default, I'm really not sure about this specific rule right so it's kind of an optional rule so let's actually put opt maybe at some point, we're, going to, remove, it, but, I suppose these three rules are like very important so this language is called crust right so and it it's a variant of rust that is comfortable for C developers to work with right so because in that mode rust cease to be annoying and starts to become actually usable language, right? So that is actually enjoyable to use, right? So the problem with Rust is that it uh it achieves safety by sacrificing the sanity of the programmer, right? So that's how it achieves safety, right? So it becomes absolutely [ __ ] unusable, annoying shitty, language,, but, at least, it's, safe, right? So it was just like a [ __ ] programmers, [ __ ] programmer mental

health, safety above all, think about the children, think about the children right? So we kind of trying to go in the opposite direction, right? Let's actually cut out all of that [ __ ] Let's actually for once think about the mental health of the programmer and just let them enjoy, right? And with the rise of vibe coding, it is obvious that nobody gives a [ __ ] about safety anyway. So why should we? Am I right? Why should we? So but on a serious note I do not recommend using this kind of variant of Rust for like a you know security critical applications just saying this is more for recreational programming right and I was thinking like we did a little bit of stuff in this right so we implemented a simple like hello world we implemented dynamic arrays everyone dynamic arrays we implemented dynamic arrays so where it is here the dynamic arrays and we also actually called some array functions and stuff like that nothing particular particularly fancy right so just

basically hello worlds And I was thinking uh what would be more complex than hello world and I was going through uh my to-do list of things to to implement and I stumbled upon a thing that I wanted to implement for quite some time. So uh not everybody knows that but before C programming language Ken Thompson actually created a B programming language. So why do you think it's it's called C? Because it comes after B. So B is sort of like a prequel to C. It is pretty cool to see.

Uh right. So and it is not even used anywhere. This is one of these rare languages that is actually dead. So the thing about programming language is that uh once like some time ago I said that languages never really die. They never really die because they usually accumulate enough like a legacy code uh that keeps them going. The same with the cobalt for instance, right? So people say that Cobalt is dead in in reality it's not. There is a lot of legacy code bases that actually keep Cobalt alive.

So in the languages because of that are not really dead but B is actually legit dead. Nobody uses it. And as far as I know there's no really like official compilers. There's no compilers at all. Maybe some enthusiast actually implemented some compilers for B, but I mean it's it's kind of difficult to verify that it's this compiler is on spec. And in fact, as far as I know there was never a spec for B, right? So but what there is uh what I found is the um user reference to be written by Ken Thompson. So he he basically wrote like a manual uh like a reference for the language and he described the language and he also provided a bunch of examples of programs here. So here are the programs in B and they kind of look like C except you don't specify types because if I understood correctly there's no types in this language. Well, I mean there's only one type. It's a word, a machine word, right? So, and when you define variables, you basically define a

variable of the type word. And you only use words in here. So, when you use auto, by the way, auto uh was in B, but it was not well, it was in C, right? So was trying to make a joke that B was ahead of its time, but I mean C also has auto, but it it's kind of meaningless right? So the point of auto is that it's an automatic variable meaning that as soon as you close go outside of the scope of the function is going to be automatically delegated from the stack which is the default behavior of all of the modern programming languages. We usually do not explicitly imagine manage stack variables anymore in programming languages, right? And a lot of people don't even remember that was a thing uh at some point, right? But we don't do that anymore. So because of that in C this keyword is kind of actually useless, especially in C++ and that's why in C++ it now means a different thing. Um right so and auto just means that it's allocated on the stack and

when the function exits it's deallocated from the stack. Uh so and the reference for this language is rather simple actually right so it's not that big right if you try to print it it's actually 21 uh page 21 pages is that how we say it in English right so I don't know 21 page uh so and I was thinking what if we just implement a simple compiler for B programming language in crust as an exercise in crust right so because I wanted something more complicated than hello

There you go. Here is the project that I also wanted to implement some for some time. I think it's a uh you know it's a match made in heaven, right? It's a match made in heaven. Two meme languages together synergize each other. So I think we can get something cool out of that. But obviously development programming languages is not an easy task and I'm pretty sure we won't be able to finish the entirety of the B compiler within a single session, right? So I'm not that cracked of a developer right? I actually don't consider myself to be crack developer. So I don't think I'll be able to implement the entirety of this thing in crust in two hours. And I was thought I was thinking uh what if I implement like a small subset of B on today's session and then we see if we want to continue this project or or or not like we'll see how it goes. Right? So that that's basically for the idea for today. Let's come up with a simple program like a simple example and let's

make that specific example compilable. My usual approach right? So every time I implement languages, I start with a very very simple example and I implement enough of the compiler to compile that specific example, right? And then once I get that specific example, I can make it I can put some more meat on it until it sort of resembles the uh the final product so to speak. So that's basically going to be the goal for today. Um let's go ahead and do that. And obviously we're going to be doing that in crust., All right., So, uh, how, we, going, to be calling it? So it's actually called B. So I'm going to create a folder called

B. All right. So let's create maybe main.b. Uh and if I understand correctly, right? So this is the entry point of the B program. So let's actually find some examples in here. So here are some examples in here. So they even try to Yeah. So apparently B doesn't have very editics. Uh, yep. So that's an example of print f. Apparently that's an example of print f. That's very cool. So I need something simple. Uh, let me scroll up. Yes. So here is the entry point. And uh, we also

have extern keyword. Uh, right. And one of the functions that exist in standard library that when you link this entire thing is putchar. So we can take a look at what XTR even means. All right. So there was yeah so external declarations and more broadly we have declarations. So uh declaration in B specify storage class of variables. Such declarations also in some circumstances specify initializations. There are three storage classes in B. Automatic storage is allocated for each function

invocation. Yeah. So basically stack storage, right? So stack external storage is allocated before execution and is available to any and all functions. Internal storage is local to a function and is available only to that function but is available to all invocation of that function. So I suppose internal storage is basically static variables right so you can uh actually even in C define static variables right and essentially they are available to all invocations of the of

the function. So that's probably probably what they're referring to. It's just like they're using a different terminology. So an external declaration um so it has this form external and a bunch of names, right? So these are external names. The external declaration specify that each of the named variables is of the external storage. The declarations must occur before the first use of each of the variable. Each of the variable must also externally defined. So I suppose this is just like external names for the linker at least for us right? So this is external names for for the linker. Um okay so let me find extern char. Um so externch char. So here it is right and in here we just declaring that uh we expect putch char to exist somewhere right? So this is what we expect in here. And I suppose this function I'm going to make a wild assumption. I'm making absolutely wild assumption works exactly as the putch char in C. Right? So it accepts some sort of an integer

and just prints that uh you know uh the ASKI the character that is associated with the ASKI code within that integer right so and that's what it is it just prints the character that you provided anyway so let's actually define something like this so put char and what I want to do here is I suppose I want to define two automatic variables uh a and b right a and b and let's just write a very, simple, program, in, here, all right, so I'm going to assign 34 to A and I'm going to assign 35 to B and then I'm going to do putch char a + b right so this is a very simple program like a very simple hello world and let's write a compiler that compiles that specific thing right so this is a b program right if if I can if I understand correctly so all of that should work in here so you can also do these kind of things so I have no idea what that's supposed to mean uh right it's rather interesting Oh, look at that. So, we externally declared N and V, right? And then we

actually defined them here. So, you can also use externs as a forward declaration. This is actually rather interesting. This is actually rather interesting. And all of the variables are initially integers, right? So, and you can also have uh arrays. And this this initialization, look at this in initialization doesn't have equals. I'm not really sure if that's a correct thing. As far as I know, this entire document was uh basically scanned with OCR, right? So, it was not typed as

these, right? In in a digital form. It was actually just like on the paper. So and they then they digitalized it through OCR. So, maybe some of the things might be missing. So, we have to kind of keep that in mind. So because of that, I'm not really sure uh if that's a really correct thing in here. Right? So initialization of this variable without any equals maybe OCR didn't recognize this entire thing. So it's it's kind of difficult. See, it's a dead language right? So it's it's kind of a dead language. So there's original. So check the original file. Is there original file? An image? Okay. So it's kind of difficult to So there's a PDF in here. Maybe I should actually download PDF. Damn, that sucks. Okay. Uh I wonder. Okay. So it is searchable actually believe it or not. Huh. Uh extern extern putch char. Ah so we found this thing. Look at that. No. There is a space in here straight up. Huh. That is fascinating. Honestly that's Can I save this? Ah I can't really save that. Uh

maybe I can. So I don't see how to save the whole thing. So this uh save page as and this is whatever right. So we're using way back machine so we don't really need to save it. Um okay so let's go ahead and just try to maybe read the file. Second button from the right to save. Uh from the right. Ah here it is. Okay. So you see I'm an old computer user. I expect the save button to look like a floppy disc. None of that Zoomer download folder cloud [ __ ] Get the [ __ ] out of

here with that. Get off my long with that [ __ ] Where is the freaking floppy anyways? Okay. So, let's actually download that. But I mean, for real it's just like so many. I know. Um, and I'm not even joking, by the way. I legit was actually looking for floppy icon. That's how [ __ ] old I am. Um, anyways, so we have that. I already have a copy in here. Okay, so let's go ahead and just like create a main RS. Uh, so I suppose we need to start with fn main. So this is the entry point and uh I don't remember like I probably have to do extern C right and also I have to make it uh unsafe. I need to have my lip seed bindings right. So here is the crust and I'm going to grab my lip seed bindings. Also I should have actually provided uh like no mangle and stuff like that. Okay

the signature is actually more complex than I put in here. So let's actually make it like this. And obviously not going to be using command line arguments yet, but maybe at some point. Uh, okay. So here's the lip. I need my lip in here. Uh, maybe at some point it will make sense to actually like factor it out to a separate file of some sort right? So I don't have to copy paste it around all the time. All right. So in here I return just the zero. And I can do print f uh something like this. Hello world um slash n. And I also have to provide new terminator otherwise it's not going to work. All right. So let's actually also create make files. All right. So and in here we depend on O. And what do we do with that? O. So where is the make file from the crust? So this is how we sort of link everything together. Right? So we include debug information. This is very important. We optimize. So it optimizes the size of the of the executable. I don't really know why

without this thing it just doesn't work. It cannot find certain things from the core. Uh right. So instead of compiling the final executable we're emitting the object. Right? And we're setting the style of panic as a board. Right? So and this is actually needed to create the op file from RS. Right? Okay. So that's fine. So to create the final sort of um you know executable we have to link all of that together. Right. So we provide the uh the name of the final executable.

This has to be actually tab. So here we're just linking with ray lib. I don't think we need a linkage with ray lip and I also don't think we need a linkage with a math library. Right? So we then we're just linking that all file into a final executable. So that's basically what we're doing in here. That's how you enable crust. And there you go. It doesn't [ __ ] work because why? Um so because on top of just enabling some things you also have to um say things like I suppose no main and no std right so that's the things you have to provide in here uh and main uh so core resolved okay so let me see what we have to do in crust I think I forgot to provide some things ah you have to put exclamation mark in here so I don't remember so I think it's needed so it's for the entirety of the crate or something. I do not quite remember, chat. I do not quite remember. Okay. So, you also have to provide the panic handler, right? So

without the panic handler, it cannot do [ __ ] Um, okay. So, can I just build it now? All right. So, you need the panic info. Without the panic info, you can't define the panic handle. Without panic handle, you cannot do [ __ ] Finally, we compiled this piece of [ __ ] Holy [ __ ] Right. So, it has a bunch of warnings right? But I think that's totally fine. We can maybe just allow that code or whatn not. But let's not do that for now. So if I do main something like this, it says hello world as you can see, right? So maybe we need to create some sort of a template so it's easier to start programming in crust. Right? So because as you can see you need to do a lot of like annoying things. Uh right? So but that's the price of crust. That's the price of crust. the price that you pay for actually usable language. Um, okay. So now we need to read the contents of the main RS. So I want to have a function that is something like a read entire file from

nope,, right?, So, in, no.h,, we, have a pretty cool thing called read entire file. So yeah and it accepts the path path to the file and then the string builder and it actually basically populates the string builder. Uh so um then it contains the content of this entire thing and you can just like do something with that content. Um I can try to port this function or I can try to maybe link with that function in crust. That sounds like a cool idea right? Let's actually give it a try. So

maybe we want to try to do that. All right. So let me maybe fetch the latest changes from no because we've done a lot of changes since the last stream. So let me actually merge everything in here. So and yeah that's quite a few changes. So I suppose they still compile, right? So everything is supposed to still compile. All right., So, all, of, the, tests, running correctly. So that's totally fine. All right. So I suppose what we have to do now we have to copy paste no.h. I'm copy pasting it in here. So we can't use the C code in crust directly unfortunately but we can try to compile this entire thing into O file uh right and then just link with that O file and have a little bit of bindings and stuff like that knob. RS right so knobs that's exactly what we're going to be doing in here knob. But the first thing we need to do I suppose we need to create an all file out of knob right so I want to have knob and obviously it depends not knob.h

H. So the thing about node.h is that if you include it by default, it's going to act like a C like a H file, right? So it doesn't contain implementations. So to make it contain implementations, you have to define knob implementation macro. So essentially to compile it what you have to do, you have to, you know, try to compile it and then you have to say uh knob implementation implementation, right? Like this. But the the problem with GCC is that it detects the language by the um by the extension, right? So it will think that you're trying to compile uh pre-ompiled headers. So you have to explicitly say that we're compiling C file, right? And that's how you do that actually. So let me actually try to do that. So make knob O and it it complains that it's undefined main because it tried to create a final executable out of that. we need to have an equivalent of emit object but for C and that equivalent is just - C if I remember correctly and

there we go we finally managed to create an O file right so and it's 38 kilobytes it contains all of these implementations right in object file like this so and that means that we should be able to finally link this final thing in the final executable like so right so now when I try to build this entire thing it actually links the knob uh in here and that means that we should be able to maybe create some sort of a module called knob right and within the knob we can try to have uh read entire file. So let me see read entire file. So this is a write entire file read entire file. So here it is. So to have this kind of thing we also need to have the definition of a string builder. So look look we have a lot of prefixes. We have a lot of prefixes uh for like knob underscore and stuff like that and we have them because we don't have name spacing in C but we do have name spacing in crust because crust is obviously better uh better language than C. So

that means we don't have any of these things in here, right? Because every time we access them, we can actually access them as knob colon read entire file which is basically equivalent to that but actually better, right? It's just semantically better uh in a sense that you can always do something like use and you can just drop this entire thing. So you see mechanism of dropping and stripping the prefixes is built into the language. Think about that. Think about that chat. That's pretty [ __ ] epic. So now, uh, let's actually put this entire thing in here because that's how we're supposed to create structures. So items, this has to be a mutable pointer right? So a mutable pointer to a character. And let's maybe make it U8 instead, right? So this is going to be U8. Maybe I can use a little bit of a EMAC magic, right? So this is U size. Uh, then I uh on all of them. And there we go. This is what we have. And on top of that, as

far as I know, we have to use colons instead of commas instead of semicolons. Um, all right. So, this is the uh string builder. But on top of that, we have to actually say that representation of this thing is a C representation, right? So it packs it like a C structure. Um okay. So, here is the fn uh and it's an external function and it returns it's supposed to return boolean. So, what it accepts in here? It accepts the path which is a constant pointer to U8. Right? So the usual thing in here, nsb is actually a mutable pointer to string builder defined in here. That's what we have in here. So we also probably need some sort of a way to define an empty string builder. So we'll probably have to implement something like this, right? So here is a empty string builder. Uh do does it need generics? I don't think it needs generics. So we need some sort of a constructor in here that returns self. So self uh here is actually items. um

ptr null probably mutable right so this is how we define null in here so count is going to be zero and capacity is also going to be zero string builder by the way is a dynamic array for those who didn't know for those who didn't know uh anyways so that should be it honestly we can try to now compile the whole thing and obviously it wants uh core ptr right so let's actually do use core ptr like so is it going to work and this thing uh it wants a body because I forgot to say

that this entire thing has to be external C right so because we're trying to link with external C code that's what we're trying to do and as you can see it does in fact compile so let's try to read the uh you know the entire of the file in here can can we do that we can uh do something like knob read entire file like this right so we have to put admminate in here because rust crust I'm sorry crust doesn't do that out automatically for you. So we have to treat it as a pointer. Then we have to

allocate this string builder on the stack somewhere, right? So string uh builder SB. In fact, we can just do something like new right away. And here is SB. So and it has to be mutable. It has to be mutable. And then here we take a mutable pointer in here. As far as know, we have to also do row. Uh but I mean it's kind of a new feature. Uh so let's not do that. And here's the thing. If this thing returns false that means we did the [ __ ] wacky we failed we couldn't read the file. So what we have

to do in this situation is just return non-zero exit code that's it. So after that after that we can declare that the file was successfully um you know read I forgot the past of the word red. So we can do in here we can now print the size of the file right. So size of file is something like this where we specify sb count. So, and let's try to compile this entire thing now. Uh, let's try to compile this entire thing now. So string builder is Yeah. So, we need to make all of these things public. I

completely forgot about that because Rust being anno like that. It's always been anal like that. You have to make all of these things public. Uh, all right. So, this is going to be pub. All right. Let's go. And what does it say? Undefined ref. Okay. So, here's the thing. So the name the actual name of the function is not read entire file. The actual name of the function is knob read entire file right. So we have to take that into account. And as far as I know it's pretty easy. You can just specify the link name through this attribute. So let's put this thing in here. And this thing should be just like this. All right. So and it compiles. Not making anything up. It straight up compiles. So and then I can do main and it read 88 bytes right if I take a look at the uh size of n it it's in fact 88 bytes so precisely so now uh right we want to actually print the content of the file we want to print the content of the file so let's actually see how we can do that

I think the easiest way to print the content of the file is f write uh but we need to create like a bindings for this function it's a little bit annoying and by the way uh unsafe RS doesn't have restrict words, right? So, because it's it's a pretty unsafe language, I got to tell you, it's a pretty unsafe language. But anyway, um and also we need to have like a pointer to, you know, stream if we want to actually print properly. Damn, that sucks a little bit. That actually, sucks., But, one, of the, things, we can do, as far as I know, we can just like use print f something like that. And we have to provide either like this or highlight like this. Either like this. I don't remember like I can never remember like where you have to put dot and star but this is something that we can try. So I have to do count uh so and it has to by the way I 32 that's very important and then in here we provide the items and that's what we can do in here hoping

that it will print the content of this thing correctly. So let's actually do make minus b and as you can see it actually successfully printed the content of the file right. So we just used the knob in crust to read the content of the entirety of the file. So again crust is actually pretty cool language. You can't just directly use C code from crust even if it's a header only file right you just have to compile it in a very specific way right so you have to compile it in a very

specific way but I mean you still can use that so that means like we can use STB image right to do some things like we can do a lot of stuff in here just in trust uh absolute coding absolute [ __ ] coding indeed right so coding in the chat everyone coding in the chat uh so that's actually super cool that's actually super cool so let's continue I suppose Um, let's continue. Honestly, I would love to maybe rename the whole thing to something else, right? So, currently it's called

main, but this is um yeah, so it's it's kind the name of the compiler should be different, right? So, let's actually maybe call it B, right? So, and the name of the executable that does the B compilation uh if I understand correctly, it has to be B. Um, right. So there was a B computer language. So there was a some sort of a man page or at least down there. Um so man page h I can't really find that man page B. But I I think I remember that it was actually just the B command, right? So I

think I remember that it was just B command. And let's actually like continue that sort of tradition. So this is going to be B. So B O B O B O and this is B. So but for the rest of the things we're, going to, call, them, as, usual., Uh right. So if I try to build the whole thing uh right it's it's build the final B executable. And if you try to do B uh it actually read the entirety of the source code. And here is the B program. So okay then the next step in um I suppose compilation of the B

program would be to tokenize it right so it's it's always the first step in uh in compilation of any programming language so um we can try to use STB selexer right so I I said multiple time that uh if I try to use STB sele but I actually recently tried to use this tob selelex in my private uh project and I think I figured out more or less the way how to properly use it. So I think I want to give it a try one more time. I think okay look I think I want to okay it's so over. Yeah. So I'm

probably going to waste a lot of time but I mean please but again I used it recently in my private project. Chat chat chat listen. I tried to use it in my private project and I think I figured it out. Uh I think I figured it Alexa I want to use this to be sea. I want to use this to be select. You have Alexa. It's not exactly. So the thing about Alexa is that you need to customize it first before it can do what you want. STB selector already supports all of the

things, right? So STB Lex. Okay, let's give it a try. Okay. So, if I start to sort of like get sucked into the, you know, tarpit, uh, we can always switch to Alexa. Okay. So, let's just give it a try., At least, I, just, want, to, give, it, a try. It's going to work out this time. I swear it's it's going to work out this time. Has to be uh C Alexa. Okay. Um yeah, I have a Stockholm syndrome. That's true. That is true actually. Okay. So, let's download this entire thing. Uh, right. So, let's

[ __ ] go. Um yeah, I can stop at any time. Okay, I I can stop at any time. Uh now let's do this kind of thing. Uh STBC Lexa and here STBC Lexa implementation. So let's give it a try. I'm going to just do boom. And did it create? Yeah. So this seems to be like the final thing that we need in here. That's pretty cool. And in a make file, we are linking the compiler with this thing. So I'm going to do minus B. There we go. We got a final compiler and we link with all of

these things in here. Cool. So I suppose now uh in the B compiler, we need a module uh that is responsible for STBC Lexa. Uh STBC Lexa. It's kind of cool. Here's the knob. Here we're going to have STBC Alexa. Uh here is the lip. Right. So all of the necessary libraries like all of the libraries are here. It's pretty comfortable and without cargo by the way. Like I'm not using any cargo or anything. It's just like yeah. Uh we can have another layer of this thing. Uh

STB, right? So but I don't feel like I want to do that. We could, but I mean why? Um right. So where is the STB? Okay. So here it is. Uh, and yeah that's a lot of things. Well, not that many, honestly. Not that many. So, I think we can I think we can live with that. Um, so I'm going to copy paste this entire stuff like so. And so, let's actually bring this stuff in here. So, this is a char and this is the integer and so on and so forth. For all of that stuff, we'll probably need to have an

FFI. and FFI. By the way, I think instead of use size, I probably should use um you know size T from FFI. I do not quite remember. So, rust updoc. Uh let me find this entire thing. And it's just going to be FFI. So, where is the FFI? Do you have something related to size? I actually don't see it. So, there is no C size or anything straight up. So, C size there is C size T and it's exactly in core actually that's very interesting so that means in here we should have actually used C size T

uh right so let me see C size T C size T so this is going to be U score FFI C size T uh C size T so I have to put additional colon in here and uh in here we also have to do this kind of thing so in terms of char. So there there is some sort of weird discrepancy within between like CR and uh the literals that are used uh in Rust. So it's kind of sus honestly. It's a little bit sus. So this is because they probably expect you to use their C string thingy or whatnot.

But I'm not sure if I can use CSTR from core, right? I mean, FFR there FFI there is a FFI core. So that means I probably can use this kind of thing. Um, so here is the point. So I can create this kind like this is a little bit complicated right? So I don't really like how freaking complicated all all of that stuff is. But I mean, it is what it is and it isn't what it isn't, right? So I like simplicity. They like complexity. Obviously, we're not the same. We're not

the same, chat. Okay, so here's the input string. And this is supposed to be like a mutable uh U8. And I wonder if I can just quickly do some stuff like that. And just, you know, mute U8 and maybe align this entire stuff by a colon. Look at that. Doesn't that look cool? Uh sister is in core. C string is in a lock. Ah, like is there any way like if I could just Well, I mean I I can do something like this. Can can't I? I can't do this kind of stuff. It's just in a different edition of Rust.

[ __ ] Okay, let's give it a try. Let's give a try to that stupid ass edition where we have this. Okay. Okay. Okay. Okay. Let's give it a try. Uh right. So this stuff uh where are the errors? So here uh use unstable and this thing is un unstable library. [ __ ] you. Why every I I'm so tired of ranting about that. It's like insane. Like why this kind of thing is in freaking nightly out of things? This language is 13 years old. 13 years. When you going to [ __ ] finish your language?

So like Rust is develop was developed by myilla right this is what sucking on Google's money do to you instead of making them yourself right like when you don't rely on actually making something valuable for the market and only rely on some big daddy Google giving you money that's the [ __ ] result 13 [ __ ] years size T is an unstable feature. Holy

[Music] [ __ ] I'm sorry. Uh that's a good question. I I approve of that question. I have the same question actually. So uh anyways, uh let's actually try that stupid ass edition. Stupid ass edition, right? See, help. Uh so what do we got? Adit. Maybe we should just jump straight into 2024. That woke up grandma. I'm so sorry. Uh, so 2024. So, is 2024 better than, 2021?, What do, you guys, think?, 2024 is tomorrow

dude. A bad news for you. Anyways, uh so let's let's give it a try. Um so I I I suspect it's not going to even compile. Uh 2024. Let's go. And a boom. Oh [ __ ] Of course it didn't [ __ ] compile. Uh external blocks must be unsafe. Is that what you wasted Google's money on already? Um, really is that what you wasted Google's money? Well [Music] um unsafe

attributes. Okay. So, there's an error. Yeah. And even after that, this stupid ass thing is still un okay it's still in nightly. All right. So, uh, use size. I'm going to use size in here. Uh, so any errors or only warnings, right? So unused import. It's kind of funny that I can import it, but I can't really use it. Okay. So, that seems to be working. That seems to be working. So, and now here is the uh moment of juice, orange juice. Uh, so, okay, that kind of worked, but at the same time

yeah, but I mean, it's actually kind of fine. So, that just means that I can replace all of these U8s with CHR, right? So, I can replace them with CHR and it's gonna be totally fine. So let me actually do something like Cchar. And I'm going to query replace U8 with Cchar. Boom. Boom. Boom. And well obviously in here and in here as well. So, and I don't even have to do the it like that, don't I? Right. So, it complains about Yeah. So, it's a mutable CR. Where is the FFI? Give me FFI. Uh

yeah. U score. Let's put that stuff in here. So ah so also that stuff goes to here. Uh CR and that stuff also should go somewhere, here., All right., So, we, have, to use it everywhere. Uh see too too many like stupid [ __ ] warnings honestly. Ah oh this one is interesting. So the type of this thing is straight up sister. Okay, that's even better I think. Right. So that means all of these things I should be CR. So I should do something like mute uh ch. Oh, and it's a freaking

rep. We can't afford that. It's a freaking reference. We can't do that, Dave. We we can't. This is against like we we just can't. We It's no we can't do that. We have to do SPTR. I'm sorry. Rules are the rules. I didn't make the rules. Actually, I did. But anyway, I didn't make the rules. So we're following the rules. Uh so, what do we have? Okay. So, what do we have here is uh Yep. And we also have to ah this one is interesting. So in print f though yeah so this one also has

to be something like this. Finally it compiled. Hell yeah. So finally it compiled and it kind of works exactly as we need it. So really like that. Really like that. So, uh, yep, yep, yep [Music] yep. So, now let's go ahead and just do this kind of thing. Uh, this one is, uh, C int. This one is a bunch of chars. Emacs, can you just freaking work? Mute C char. And this one, mute C char. All right. Uh, and here's the long. Do we have songlong long shong? So that means I

should be able to do something like c long. And this one is little. And this is double. Do we have a c double? Do we have c double? C double. Uh yeah, we do. Look at that. We do in fact have c double. So int number c double. And this one is immutable to chart. Uh-huh. And this one is C int. That's cool. So, let's actually import all of these things. C long, schlong, C double, and C in. I think that's everything. So, this is basically this uh the definition of the

Alexa. And we also probably do have to do repper C like so. And boom. Does it compile? doesn't even [ __ ] compile because all of that have to be commas not semicolons. All right, it compiles right? So, we just redefine the structure like that. Cool. Uh, and another interesting and quite important thing I think is the initialization of the Lexa, right? So, this is very important function that we have to put in here. And of course it has to be unsafe extern C because that's not enough unsafe

keywords apparently. Uh right. So here's the Alexa and it's a mutable pointer to the Alexa. So here's the const. Okay, that's understandable. So this is a const uh chart. Cool. Uh this one is a const uh chart. This one is not const one. This is a mutable one. Uhhuh. Right. So this is a mutable C char. And this one is just a storage length. It's the C pin. It doesn't really return anything, does it? Okay. So, it, doesn't, return., All right., So, and now I should be able to do some sher

like for example uh I have this B and here I also allocate the Lexa. Um right. So to allocate this entire thing. So I remember there was a zeroed right some somebody suggested zeroed and I kind of dismissed it but we dismissed it because we didn't initialize C runtime correctly. I think we should use zeroed everywhere in here. So it's a yeah so it's probably in core mem right so let's do core me zeroed like this. So that means I should be able to define something like STB C Lexa

and it's a little bit of annoying because we have a prefix stlexer and then I have to do stlexa yet again. So maybe I should actually strip off all of these prefixes somehow. But we'll see. Right. So what I have to do is just like a zeroed like this. And that should work I think. So let me try to compile it. And you expected this thing. So you want me to do it like that. Couldn't you freaking Brvski figure that out from this type? Or do you really want me to explicitly put it somewhere here for you because you're incapable of figuring it all out? Ah, I'm an idiot. I'm a dummy dum dum. I'm sorry. I'm sorry. I'm sorry. I'm sorry. That's fine. Fine. So what do we have in here? So this one is just that stuff. What else do we have in here? STB. Oh, it's all

private of course. Do developers really get a kick up out of being so annually [ __ ] all the time by the compiler? Is that Do they really [ __ ] enjoy that? How is that enjoyable? I don't [ __ ] know. I'm sorry. Yes, I do. Ah, okay. I mean, I don't king shame. Just say you do you. Uh, you do you. Anyway, uh so,, all right,, that, seems, to, be, working. So, that means if we're going to be using like a zero, then maybe we don't even need the constructors anymore. Chat, chat, chat.

That is actually freaking poggers I think. So look at that. I can just do something like that and then I can say zeroed zeroed like this. And where is the implemention for the string buffer and we can nuke this entire thing. Boom. And that works. All right. So we did that and then I have to now finally initialize this entire thing. So this is going to be STBC Lexa. Uh right. So and then we have to take this entire fun uh like this going to put it in here. And now we have to just probably the pointed to this uh thing right. So this is the pointer to just L input stream. This one is interesting. Input stream is SB items. Right? It is straight up SB items. And then we have to provide the end of the input stream. But luckily

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent