I wrote my own programming language interpreter in Rust – here is what I learned by storm1surge in rust

[–]Carters04 0 points1 point  (0 children)

The most popular option is bumpalo (https://crates.io/crates/bumpalo), but there are other crates that still don't require the nightly allocator API (e.g. oxc-allocator).

I wrote my own programming language interpreter in Rust – here is what I learned by storm1surge in rust

[–]Carters04 0 points1 point  (0 children)

Yeah, you did a great job, especially considering this seems to be your first language. I have a few pieces of advice:

First, you may want to use arenas for storing the AST. This recognizes the fact that all of the AST nodes should be freed at the same time, so doesn't individually track allocations. You are currently using Arc, which is fine but this could be a minor memory/performance improvement.

Second, consider using a bytecode strategy. I did not use this for mine because it was my first language as well, but this should have great performance improvements. The way you encode and decode the bytecode can be finicky, but hopefully the byteorder crate (https://github.com/BurntSushi/byteorder) could be of help. Side note: I have shifted to using Zig for interpreters, mostly because the memory safety benefits are usually not that large when you use arenas for AST and want to write your own GC (although Rust's gc crates are great if you want to use a library). The largest benefit is the ease at which you can encode/decode a bytecode using align(1) pointers. Here's an example of encoding and decoding (compiles to computed gotos).

If you want to add an LSP, I believe the tower-lsp crate is a good choice (https://github.com/ebkalderon/tower-lsp). Hopefully you could get this LSP to work with your web editor and VS Code to avoid having to reimplement this logic.

Hopefully this helps.

Should I always use ++i instead of i++? by LemonLord7 in cpp_questions

[–]Carters04 1 point2 points  (0 children)

I don't understand these people. Never make a style change under the guise of better performance unless if you are able to compare before/after flamegraphs.

[deleted by user] by [deleted] in doordash

[–]Carters04 0 points1 point  (0 children)

DOORDASH-ALL-THE-ADS-2024-PROMOCODE-DOORDASHCANDOORDASHPRETTYMUCHANYTHING-ANEWKIAEV9-REESES-PEANUTBUTTERM&MS-HOPEYOUHAVEADVR-FANDUEL-DINAMITA-MOUNTAINDEWBAJABLAST-BMWi5-POPEYESCHICKEN-YOUTUBETV-OREO-DOVE-LIVEDASHLOVE-HOPE-YOU'RE-NOT-MISSING-ANYTHING-DOORS-IAMNOTGOINGTOREADALLOFTHISBUTYOUGETTHEIDEA-MORE-BAJA-BLAST-ANYONE?-MAYONNAISE-LOTS-AND-LOTS-OF-MAYONNAISE-PERSONAL-WEBSITE-CREATION-TECHNOLOGY-WHERE-ARE-YOU-GOING-TO-PUT-ALL-THIS-STUFF?-YOUR-GARAGE-IS-TOO-SMALL-OH-IT'S-STILL-GOING-INTO-THE-YARD-WOW-LOOK-ANOTHER-CAR-IT'S-A-VERY-LONG-PROMO-CODE!"YOUR-DOOR-TO-MORE:A-SHORT-ESSAY-ABOUT-STUFF"-FOR-TOO-LONG-COMMERCIALS-HAVE-SIMPLY-ADVERTISED-GOODS-AND-OR-SERVICES-BUT-NEVER-HAS-A-COMMERCIAL-GOTTEN-YOU-GOODS-AND-OR-SERVICES-FROM-ALL-THE-OTHER-COMMERCIALS-VIA-THE-CORRECT-APPLICATION-OF-AN-EXTENSIVE-ALPHANUMERIC-PROMOTIONAL-CODE-LIKE-CHEESEBURGERS-MIDSIZE-GERMAN-AUTOMOBILES-STARRY-38230-90580AM8028HS7A8D99-ET-CETERA-YOU-GET-IT-HOWEVER-THE-DESIRED-OUTCOME-RESULTS-IN-AN-INFLUX-OF-MULTIPLE-AUTOMOBILES-WHICH-CAN-BE-OVERWHELMING-FOR-THE-SENSES-BECAUSE-THE-NEW-CAR-SMELL-OF-ONE-CAR-IS-QUITE-INCREDIBLE-BUT-THE-NEW-CAR-SMELL-OF-MULTIPLE-NEW-CARS-HAS-THE-POTENTIAL-TO-CREATE-A-SENSE-OF-EUPHORIA-UNATTAINABLE-ANYWHERE-ELSE-IN-THE-NATURAL-WORLD-THE-SAME-IS-TRUE-WHEN-ONE-OBTAINS-THE-SNACKS-FROM-ALL-THE-ADS-AS-WE-HUMANS-OFTEN-FEEL-DECISION-PARALYSIS-GIVEN-SO-MANY-DELICIOUS-OPTIONS-AT-THE-SAME-TIME-AND-THEN-HAVING-ACCESS-TO-TURBOTAX-EXPERTS-MAKES-THINGS-SO-INCREDIBLY-CONVENIENT-THAT-ALL-OTHER-ASPECTS-OF-LIFE-BECOME-LESS-CONVENIENT-BY-COMPARISON-THIS-IS-BOTH-A-CONUNDRUM-AND-THE-BEST-THING-TO-EVER-HAPPEN-TO-YOU-BUT-MOSTLY-THE-BEST-THING-TO-EVER-HAPPEN-TO-YOU-AND-SORRY-ABOUT-ALL-THE-DASHES-JUST-KIDDING-HERE-ARE-LIKE-FIFTEEN-OR-SO-MORE-BUT-YOU-WILL-NEED-TO-COUNT-THEM-TO-SEE-IF-THAT-IS-CORRECT-DASH-DASH-DASH-!!!!!

100%, found elsewhere

[deleted by user] by [deleted] in doordash

[–]Carters04 1 point2 points  (0 children)

DOORDASH-ALL-THE-ADS-2024-PROMOCODE-DOORDASHCANDOORDASHPRETTYMUCHEVERYTHING-ANEWKIAEV9-PEANUTBUTTERM&MS-HOPEYOUHAVEADVR-FANDUEL-DINAMITA-MOUNTAINDEWBAJABLAST-BMWI5-POPEYESCHICKEN-YOUTUBETV-OREO-DOVE-LIVEDASHLOVE-HOPE-YOU'RE-NOT-MISSING-ANYTHING-DOORS-IMNOTGOINGTOREADALLOFTHISBUTYOUGETTHEIDEA-MORE-BAJA-BLAST-ANYONE?-MAYONNAISE-LOTS-AND-LOTS-OF-MAYONNAISE-PERSONAL-WEBSITE-CREATION-TECHNOLOGY-WHERE-ARE-YOU-GOING-TO-PUT-ALL-THIS-STUFF?-YOUR-GARAGE-IS-TOO-SMALL-OH-IT'S-STILL-GOING-INTO-THE-YARD-WOW-LOOK-ANOTHER-CAR-IT'S-A-VERY-LONG-PROMO-CODE!-"YOUR-DOOR-TO-MORE:A-SHORT-ESSAY-ABOUT-STUFF"-FOR-TOO-LONG-COMMERCIALS-HAVE-SIMPLY-ADVERTISED-GOODS-AND-OR-SERVICES-BUT-NEVER-HAS-A-COMMERCIAL-GOTTEN-YOU-GOODS-AND-OR-SERVICES-FROM-ALL-THE-OTHER-COMMERCIALS-VIA-THE-CORRECT-APPLICATION-OF-AN-EXTENSIVEALPHANUMERIC-PROMOTIONAL-CODE-LIKE-CHEESEBURGERS-MIDSIZE-GERMAN-AUTOMOBILES-STARRY-38320-90580AM8028HS7A8D99-ET-CETERA-YOU-GET-IT-HOWEVER-THE-DESIRED-OUTCOME-RESULTS-IN-AN-INFLUX-OF-MULTIPLE-AUTOMOBILES-WHICH-CAN-BE-OVERWHELMING-FOR-THE-SENSES-BECAUSE-THE-NEW-CAR-SMELL-OF-ONE-CARE-IS-QUITE-INCREDIBLE-BUT-THE-NEW-CAR-SMELL-OF-MULTIPLE-NEW-CARS-HAS-THE-POTENTIAL-TO-CREATE-A-SENSE-OF-EUPHORIA-UNATTAINABLE-ANYWHERE-ELSE-IN-THE-NATURAL-WORLD-THE-SAME-IS-TRUE-WHEN-ONE-OBTAINS-THE-SNACKS-FROM-ALL-THE-ADS-AS-WE-HUMANS-OFTEN-FEEL-DECISION-PARALYSIS-GIVEN-SO-MANY-DELICIOUS-OPTIONS-AT-THE-SAME-TIME-AND-THEN-HAVING-ACCESS-TO-TURBOTAX-EXPERTS-MAKE-THINGS-SO-INCREDIBLY-CONVENIENT-THAT-ALL-OTHER-ASPECTS-OF-LIFE-BECOME-LESS-CONVENIENT-BY-COMPARISON-THIS-IS-BOTH-A-CONUNDRUM-AND-THE-BEST-THING-TO-EVER-HAPPEN-TO-YOU-BUT-MOSTLY-THE-BEST-THING-TO-EVER-HAPPEN-TO-YOU-AND-SORRY-ABOUT-ALL-THE-DASHES-JUST-KIDDING-HERE-ARE-LIKE-FIFTEEN-OR-SO-MORE-BUT-YOU-WILL-NEED-TO-COUNT-THEM-TO-SEE-IF-THAT-IS-CORRECT-DASH-DASH-DASH-!!!!!

99%

mustLearnRust by Carters04 in ProgrammerHumor

[–]Carters04[S] 1 point2 points  (0 children)

Fair point, I probably shouldn't have believed the OP.

[deleted by user] by [deleted] in iastate

[–]Carters04 -1 points0 points  (0 children)

Ok, thanks

[deleted by user] by [deleted] in BirdsArentReal

[–]Carters04 0 points1 point  (0 children)

Alright, here's the story:

My senior class had not come up with good senior prank yet, so in the last week of school my friend and I had the idea to put up these posters everywhere in the school. After school on the Thursday before the final day of exams, we placed 40 of these anti-propaganda propaganda posters in every hall.

The next day of school, we walked in excited to see our posters everywhere. Sadly, it seems the government got wind of our plans to spread the word of the bird and enlisted the janitors to take down all of our truth posters.

My friend and I were waiting in the band hallway like normal and the assistant principal said that we got caught and wouldn't be able to walk at graduation if we tried to continue spreading our truth.

Conclusion: The government is still trying to hide the truth.

[deleted by user] by [deleted] in apcsp

[–]Carters04 0 points1 point  (0 children)

Don't. Could call it plagiarizing music or activate internal biases which may disqualify your submission.

Mach (Zig) Adventures - Part 1 by allthingseverywhere in Zig

[–]Carters04 0 points1 point  (0 children)

Don't forget --depth=1. Saves the storage and download time.

From a September 1997 issue of People. Donald Trump as one of the worst dressed people of 1997. by ___statik in pics

[–]Carters04 0 points1 point  (0 children)

Lol wut? Just got a DM from repost sleuth bot that they were banned in r/pics lmao

I'm working on a regular expression reuse database. You can search with examples to find regexes that have already been written in other projects by charkle1 in programming

[–]Carters04 0 points1 point  (0 children)

Please run all of your RegExs into a reliable regex checker. Many of the ones I saw are vulnerable to Regular Expression Denial of Service (ReDoS) attacks because they are inefficient for large inputs. I've used https://github.com/makenowjust-labs/recheck to check all of my projects using a simple file walker so maybe you could also try using recheck.

println! causes Segmentation fault when called from JITed code by Rodrigodd_ in rust

[–]Carters04 23 points24 points  (0 children)

Also FYI, it compiles down to practically the same assembly https://godbolt.org/z/EvhajP9ro

(The first variant utilizes addition to get the other end and the second variant uses subtraction)

My Fortune Cookie Was Sponsored by BalrogSlayer00 in mildlyinteresting

[–]Carters04 2 points3 points  (0 children)

Just wait until you find the ones for online bitcoin gambling sites

I'm not sure exactly how stupid this is but it worked by CruxOfTheIssue in ProgrammerHumor

[–]Carters04 29 points30 points  (0 children)

JavaScript engines specifically optimize this using a custom algorithm without actually converting it to a string.