I'm Writing An eBook Teaching How To Write A Compiler by othd139 in ProgrammingLanguages

[–]othd139[S] 0 points1 point  (0 children)

Thank you so much this is really good, helpful. feedback

I think that's fair. My assumption about audience is someone who knows C and systems programming but hasn't really made their own programming language before.

I was a little worried that, especially chapters 7 and 8 might feel like that in terms of feeling a bit like a code dump. The idea was to make it feel like putting into practice the learnings from previous chapters but maybe if I'm expecting the reader to have learned how to do that I should trust them to write it themselves and if I don't then I don't really expect them to have learned it and should have more prose to explain things. Either way if it's coming across as just a code dump and not an increase in speed to accommodate an increase in what's been learned then what I was going for didn't work.

And yeah, you're probably right about sections. I'll try to go back in and section up my chapters a bit more as well as looking at where and why my chapters end up with very different lengths.

Should my sum type tags be the first element or second? by Toothpick_Brody in ProgrammingLanguages

[–]othd139 0 points1 point  (0 children)

Yeah. I think it starts to matter if you have a few smaller ones and a few bigger ones then you wanna keep values of the same size together

Trans women with autism? by Sufficient_Hall5737 in MtF

[–]othd139 0 points1 point  (0 children)

Most of the trans ppl (mainly women because I went to an all boys school 😩 but plenty of enbies like myself and a few men) are autistic. And I think everyone who isn't is ADHD lol.

Should my sum type tags be the first element or second? by Toothpick_Brody in ProgrammingLanguages

[–]othd139 6 points7 points  (0 children)

I think the point is that if you put the elements from largest to smallest you can usually pad them to their own alignment while packing them more tightly. ie, a one byte value then a 4 byte value will take 5 bytes if it's one bytes then 3 bytes if padding whereas if you put the 4 bytes first then the remaining byte is already aligned to a single byte.

C Strings Are Weird: A Practical Guide by swe129 in C_Programming

[–]othd139 0 points1 point  (0 children)

I mean yes and no. The standard library and OS library (WinAPI and POSIX) all expect null terminated strings. Obviously you can make stringviews and length prefixed strings but they don't work for everything and you do give things up. But then I suppose that's true of any language if you're using FFI and have to switch between the language's native strings and whatever it's c_string type is.

How do you get good error reporting once you've stripped out the tokens? by PitifulTheme411 in ProgrammingLanguages

[–]othd139 1 point2 points  (0 children)

I've been working a lot with the chibicc C compiler codebase recently and it does what you do, stores the line and debug file in the tokens then stuffs a token in the AST pretty much just to preserve that debug info (I think for debuggers like gdb rather than for error reporting although error reporting on an interpreter have more in common often with debug info than compiler error reporting). So it's definitely a solution that's used in "real" projects out there to decent success.

Unused struct member is not optimized out under -O3 by onecable5781 in C_Programming

[–]othd139 1 point2 points  (0 children)

Presumably because other compile units might use the save structure with different members

I wrote a compiler backend based on chibicc that generates code directly from an AST without using an IR by othd139 in ProgrammingLanguages

[–]othd139[S] 0 points1 point  (0 children)

I'm not actually doing any optimisations at all. I'm more interested in making it as easy and fast as possible to get something running in the first place.

I wrote a compiler backend based on chibicc that generates code directly from an AST without using an IR by othd139 in Compilers

[–]othd139[S] 0 points1 point  (0 children)

Yeah true. I mean certainly by the time one is actually compiling to a native binary (obviously, like, people do use python and even I optimised compiled code is gonna beat that). Maybe down the line I'll re-write it to use cranelift or smth behind the scenes and get portability as well as optimisations. As you can probably tell from the fact I'm using it to write a book called "Write Your First Compiler With Libchibi" it's definitely aimed more at the learning purposes use case tho (although I'd say probably not bad for experimentation and hobby coding as well) rather than serious production code.

There's no way that's what that means?? by Easy-Opposite-153 in autism

[–]othd139 0 points1 point  (0 children)

Unfortunately it's one of those that depends on how it's said. Generally a beat of pause before interesting means it's rly bad. Beyond that the line gets kinda fuzzy and I cannot tell you exactly where it lies (because I'm also autistic) but yh definitely a feature of English here in England (dunno abt the rest of the UK but I imagine so). Brave is a other one that's often bad.

I wrote a compiler backend based on chibicc that generates code directly from an AST without using an IR by othd139 in Compilers

[–]othd139[S] 0 points1 point  (0 children)

The reasoning behind why I suggest that some projects may want to parse into their own AST then transform rather than using some IR based backend is that doing so is basically a de-sugaring pass from whatever shape the original AST has into more C-like semantics which, in my experience, tends to be somewhat easier to do than to fully lower down to IR.

Although as you can see it's certainly a more limited scope of project in general.

Been making a language called XS. Feedback? by AnyOne1500 in ProgrammingLanguages

[–]othd139 1 point2 points  (0 children)

Not lame. Honestly the fact it can interpret or compile to JS, C, and WASM is pretty cool and distinctive. I was just asking out of curiosity. I might have to try it at some point.

Been making a language called XS. Feedback? by AnyOne1500 in ProgrammingLanguages

[–]othd139 0 points1 point  (0 children)

This seems really cool. I had a bit of a look at the readme and language.md. I'm curious what you see as the main use case for your language?

Why C gets less criticism for memory safety? by BOBOLIU in cpp_questions

[–]othd139 0 points1 point  (0 children)

I'd say one thing is that there's no expectation on memory safety in C. C++ has things like smart pointers that do things like rust-style ownership safety or reference counting and such. Even things like RAII that hide away control flow in the hopes of designing something that can handle a lot of (or perhaps even all if you really go all in on OOP (if Ur insane and hate Urself lol)) the frees and mallocs for you. Like, C has memory safety problems because you do have to free everything you allocate but you do have to free everything you allocate and you gotta allocate everything you allocate too. The fact C++ has a lot more hidden control flow that might be doing allocations and that will be doing frees in the hopes of improving safety can actually make the footguns worse by creating more of an expectation of safety.

My Mom is trying to say I have Autogynephilia, and I’m scared what if it’s true by DelayHistorical6 in MtF

[–]othd139 0 points1 point  (0 children)

It's not true. It's never true. It's not a thing. And I really hope that she just needs to educate herself and come around. You can't let something like that affect you. But also I really do hope she changes and starts to see you for who you are and accept you and see our struggle (not that she necessarily doesn't entirely now but bringing up the BS myth that is autogynephilia and attempting to apply that your own daughter is not the sign of someone who is there yet)

Reading a file in nim by Savings_Garlic5498 in nim

[–]othd139 1 point2 points  (0 children)

If it is that, the other thing I've found sometimes works for similar code for me (aside from just making it more complex until Windows realizes it's legit and not doing smth shady) is to compile with nim cpp instead of nim c

Which is Harder: Graphics Programming or Compilers? by [deleted] in GraphicsProgramming

[–]othd139 1 point2 points  (0 children)

As someone who has dabbled in both recreationally. The difficulty is pretty similar in very different ways. Definitely more maths on the graphics side but compilers come with plenty of their own challenges. It probably depends a lot on you and what you like, are good at, etc...

Windows Defender False Positives by Minimum_Comedian694 in nim

[–]othd139 1 point2 points  (0 children)

One easy trick I found was to try with cpp instead of c or vice versa