GOL simulation in custom CLI-focused language

Tiny high-level programming language built in less than a month as my first ever C++ project at 17.

- No dependencies
- Close to Python/NodeJS performance, in some cases faster (see benchmark)
- Tiny memory footprint
- Tiny executable size
- Incredibly modular. Pick & choose everything.
- Nones, Bools, Ints, Floats, Strings, Arrays, Maps (dict), & user defineable types*
- I/O, Math, File Managment, Time, Str/Arr Util, & full ANSI modules all included, most are embedded into the executable itself.

Why make this? I wanted a portable & embeddable language that was fully sandboxed, very memory efficient, & has all the essential high-level language features, all while being under 200KB in size. I have looked all over, the language I was looking for just didn't exist, so I made it myself.

I want to keep working on it & improving this because I know this is something a lot of people beside me would find useful, giving a star really helps

https://github.com/PhosXD/Ity

Everything is open source & free to use!

reddit.com
u/PhosXD — 4 days ago
▲ 50 r/teenagersbutcode+4 crossposts

GOL simulation in hand-made CLI-focused language

Tiny high-level programming language built in less than a month *without* any AI assistance as my first ever C++ project at 17.

- No dependencies
- Close to Python/NodeJS performance, in some cases faster (see benchmark)
- Tiny memory footprint
- Tiny executable size
- Incredibly modular. Pick & choose everything.
- Nones, Bools, Ints, Floats, Strings, Arrays, Maps (dict), & user defineable types*
- I/O, Math, File Managment, Time, Str/Arr Util, & full ANSI modules all included, most are embedded into the executable itself.

Why make this? I wanted a portable & embeddable language that was fully sandboxed, very memory efficient, & has all the essential high-level language features, all while being under 200KB in size. I have looked all over, the language I was looking for just didn't exist, so I made it myself.

I want to keep working on it & improving this because I know this is something a lot of people beside me would find useful, giving a star really helps

https://github.com/PhosXD/Ity

Everything is open source & free to use!

u/PhosXD — 3 days ago

std::filesystem::exists throwing `std::bad_alloc`?

Any reason? Cant find anything online about this. But I cant check whether or not a file exists, no matter what path I give it. I am using C++ 26 compiled with GCC.

This is literally all I am calling: const bool exists = std::filesystem::exists("file.txt")

This is the exact error: terminate called after throwing an instance of 'std::bad_alloc'
 what():  std::bad_alloc

No it's not coming from anywhere else in my code. Minimal reproduction code, include "filesystem" call the line above. I am on Fedora Linux if that matters at all

EDIT: moving the include into my main file instead of the only file it's being used in somehow fixed it. Literally all I do is move "#include <filesystem>" from "do_things_with_filesystem.hpp" to "Main.cpp". No compilation errors when it was in the first file, why does it rely on this?? Is there some weird declarations in my codebase or something, i dont know but it works now so why should I care.

reddit.com
u/PhosXD — 6 days ago
▲ 16 r/gameoflife+2 crossposts

Implemented game of life in terminal as a test for my language lol

The script & interpreter are both open source at github/phosxd/Ity

I just thought I'd share a fun little 2 hour terminal project

u/PhosXD — 8 days ago

How do you solve the problem of dangling pointers?

I store some data in an unordered map, create a pointer to an item in that map, then say I want to delete the item but I still have the pointer. How would I know that the item is no longer there without going and manually searching the map for the name of the item we pointed to?

I'm new to C++ & especially pointers, so forgive me for this stupid question...

EDIT: A lot of good solutions suggested, I really appreciate it! I ended up going with key lookup instead of storing pointers. The reason I didn't want to do this in the first place is because it increases complexity & I didn't want to overcomplicate

reddit.com
u/PhosXD — 19 days ago

Made a programming language in &lt; 1 month (no ai), looking for feedback

I'm 17 & have been programming for roughly 5 years now, so I thought it was about time to get low-level & start learning C & C++. I gave myself a goal to implement a fully functional, high-level interpreted programming language in C++, in 1 month without using AI, reference material, or any help other than simple google searches for when I have questions about the syntax of C++.

I started this challenge exactly on July 1st, & now that the month is coming to an end I want to show off my progress so far!

Here is the source code if you want to to take a look, see my approach to things, or to just try it out: https://github.com/phosxd/Ity

Enough of all that though, what is the language actually capable of? Well, I think the best way to explain, is to just show you a snippet of code, so here is a little script that calculates & prints prime numbers:

merge IO; merge Time;


func INT isqrt; arg INT n;
	if n &lt; 0; throw "'n' cannot be negative."; /;
	var INT x = n;
	var INT y = ((x+1) / 2); while y &lt; x;
		x = y;
		y = ( ((n/x) + x) / 2);
	/; return x;
/;


func BOOL is_prime; arg INT n;
	if n%2 == 0; return n == 2; /;
	var INT r = isqrt:[n];
	var INT i = 3; while i &lt;= r;
		if n%i == 0; return false; /;
		i += 2;
	/;
	return true;
/;


const * count = prompt:['Count: '] -&gt; INT;
const INT start = now:['us'];


var INT p = 2; while p &lt;= count;
	if is_prime:[p]; print:[p]; /;
	p += 1;
/;


print:['\nDone in ', (now:['us']-start / 1_000_000.0), 's.'];

So in this script we do a various number of things.

First we import the modules we are going to be using. The `merge` instruction particularly imports a module then merges all it's members into the current scope, so you don't have to access by name. So for example usually when importing say the `IO` module, we would have to call a function like so `IO.print:[]`, but if it's merged we can just ignore the "IO" & just do `print:[]`.

Secondly we declare a couple of functions, these functions have explicit return & argument types. You may notice that we don't use curly braces to wrap the code we want inside of the function, instead we use `/;`. Well what does that mean exactly? `/` is the instruction, `;` is the instruction delimiter (end of instruction). `func` is something called a "composite instruction" in Ity, composite instructions basically contain every instruction after it until the final end instruction (`/`). So that's how things like functions & loops contain code.

Arguments are another thing to note, in Ity they aren't something you define as part of the function, rather they are ambiguous until execution. This means a function can be called with any number of arguments of any type, & it is not the function's job to verify the argument count or the argument types, that would all be handled inside of the function code. How you grab an argument is by using the `arg` instruction to assign the next argument to a variable of whatever type you set, if the type doesn't match or there is no next argument, then an error would be thrown.

Now that I have explained composite instructions, functions, arguments, & importing behavior, let's move on to the final part of this script that I feel needs explaining, & that is this little section here:

const * count = prompt:['Count: '] -> INT;

What is happening exactly? So we use the `const` instruction (which is like `var`, but the data is immutable) & assign it the type of... star? Ok so "*" represents an "inferred" type, meaning if you set the variable to an integer, then the variable type will be integer, if you set it to a string or whatever, then it will be a string & you cant change the type after declaration.

So in this case, we are setting the variable's type to the result of the call to `prompt`. What is "prompt"? This is a function that asks for user input through the terminal, & returns a string of whatever was typed in. But we want count to be a number! So the final part of this line is the type cast, which is expressed through an arrow symbol ("->") pointing to the type you want it to be (in this case "INT" for integer). So in the end the type of the `count` variable is integer, & the value is the integer representation of the string the user entered in the terminal.

Wow, okay that was a lot of explaining, but hopefully now you have a better understanding of how the language works & you will be more prepared if / when you try it out yourself.

I am very interested in all of your thoughts on this little project & if you have any tips for me as a C++ beginner. Also I am open to contributions, if this project is something you're interested in definitely let me know! Just be aware that I won't accept any AI assisted PRs or issues.

Thanks for sparing your time, reading through my ramblings, I really appreciate it! Have a great day! 👋

u/PhosXD — 23 days ago

Looking for feedback on my first project (programming language)!

So over the past 20 days I have been working on a project to get familiar with C++, I didn't want to use AI, references, or pre-made snippets of code. Only standard google for basic questions about the workings of C++ & it's syntax.

I think I picked up most of the language rather quickly because I'm already used to programming in Python, TypeScript, & GDScript. But it was still difficult understanding the differences between references, pointers, shared pointers & such..

Anyway, as a challenge to hopefully get fluent in C++, I decided to do something not-so-simple like creating my own programming language from scratch, no third-party libraries, pure C++. After 20 days here is the result: https://github.com/phosxd/Ity

So what are the capabilities? Well I think it's best explained through code, here is an example script that calculates the fibonacci sequence:

#!/usr/local/bin/ity
import IO;

const * n = IO.prompt:['Number: '] -&gt; INT;

var INT a = 0;
var INT b = 1;

var INT i = 0; while i &lt; n;
    var INT c = a;
    a = b;
    b = (c+b);

    IO.print:[a];
    i += 1;
/;

We can also do functions, complex math expressions, type-casting, arrays, hash maps, & objects (without inheritence). Some features have been purposefully omitted due to personal preference in the way I like to code, such as lambdas & try-except.

The performance is also something to note, it's not blazing fast, but it's not the slowest out there either.

I took some simple benchmark tests on my system to compare with other languages:

https://preview.redd.it/6km2w3j8lleh1.png?width=651&format=png&auto=webp&s=f9e5236a9e1e1f52aba6dd77fce4561cc19c4a9e

Note: every language is running the same exact script with the same exact logic, just with changes to suit each one's syntax. is-prime & square root functions have been written into the code instead of being off-loaded to a library.

If you know of other interpreted languages I can test against, let me know!

Now finally, I am new at this stuff, but I am very passionate about programming in general,I've made countless projects & met good people along the way. Usually I drop a project like a month or two after I start it, but I don't want that to be the case for this. I want to continue polishing, improving, & actually trying to make this into something usable/practical.

If you are knowledgeable in C++, I ask of you if you have the time to spare, take a look at the codebase, give me suggestions, show me where I messed up because I know I probably did in multiple places. If you made it to the end & actually read all this, thank you so much for giving me a chance 🙃

reddit.com
u/PhosXD — 1 month ago
▲ 35 r/teenagersbutcode+3 crossposts

Built an interpreted programming language from scratch in 19 days without AI

I built a functional interpreted programming language from scratch in 19 days **without** AI, reference material, or borrowed code, as my first ever project in C++. It is platform agnostic, faster than Bash by a long shot (not that it was meant to be a replacement), & is only 104kb with IO, time, & math modules.

Despite the time frame & the small size, the syntax is more modern than you'd expect but is definitely different. However, you will be lacking advanced language features such as lambdas, variadic arguments, & inheritence.

https://github.com/phosxd/Ity

I plan on working on this continuously, adding more functionality, making it more performant, & making the code as readable & understandable as possible so that hopefully a beginner can take a look, & maybe use this as a guide for their first project too!

Any & all feedback is encouraged, I would really like to know your thoughts, if you have any tips!

u/PhosXD — 24 days ago

std::move overwrites the contents of the original variable?

Imagine this scenario: You have an unordered map which you take a value from as a reference. If I were to then pass that reference under a new name the reference is still in tact & the original item in the map stays the same, nothing happened, which is expected.

However, I have a case where I need to move the renamed reference to yet another name, so that it can be accessed in a higher scope. You cant do this with references, not by assigning it. The way you would do this is with the `std::move` function which performs some kind of conversion from what I can tell, it works great in my case except for the fact that now the original item in my map has been set to an undefined value.

How would I go about moving my reference without `std::move` since it kills the original item?
I would use a pointer to store the reference itself (which does work somewhat surprisingly), however in my case I do 2 things. First is the storing of the reference, the second is storing just a raw value, but whether something is a safe reference or just a normal value is not differentiated (I dont know how to) so I cant be sure that the reference wont be invalidated after the scope has exited for normal values.

I hope I explained my scenario well enough, it is quite a specific case that I am not sure how to work around. Due to how my project is set up I cant just make every value I work with a shared pointer (so that I wouldnt have to worry about references) because firstly the codebase is already a bit too large for that kind of refactor, & secondly my project does millions of iterations which it needs to do quickly (sub 200ms), making everything a shared pointer would slow that down to an unacceptable level.

reddit.com
u/PhosXD — 1 month ago

I'm sorry? I thought we knew basic moral principles!

https://preview.redd.it/0w4qx0u24ach1.png?width=672&format=png&auto=webp&s=d86f57dff68d1d57bbd044bb3303c142bd868081

Context: this is under a comment claiming I was guilt tripping because I was comparing thieves to idle spectators of thieves. The reason "rapist" is coming up is because the commenter lumped my depiction of who I was describing (the thieves) in with rapists/killers/terrorists, even though the words or the like never came up in my comment. So even though the replier was exaggerating my words in attempt to frame me as someone calling everyone I don't like the worst of the worst, I ignored it & just replied with the top comment you see in the image now, to try & correct them but apparently I'm the one who needs corrected

reddit.com
u/PhosXD — 1 month ago

Why does assigning a function to a struct bloat my binary size?

For some reason when I assign a function to a struct, my compiled binary size jumps up 0.5kb. I know it is the struct causing this because I can use the function in other parts of my code without it jumping up.

The reason I am storing it in a struct anyways is because I need to iterate over some data & find the relevant function to act on that data. Checking every possibility & calling the specific function name from there doesn't sound fun.

I wouldn't mind the 0.5k if it was just that, but I have a ton of little modules each with their own struct instance holding their own separate function & it stacks up quick.

Here is one of my modules so I can show an example of what EXACTLY I am doing that is causing this behavior:

\#pragma once



\#include "../Common.hpp"

\#include "../ScopeState.hpp"





void INST\_End\_exec(const Instruction&amp; inst, const InstToken&amp; token, ScopeState&amp; state, const std::vector&lt;std::string&gt;&amp; args, const std::string&amp; symbol) {

	return;

}





Instruction INST\_End {

	0,

	0,

	//INST\_End\_exec,

};

Un-commenting the `//INST_End_exec` line bumps the size, & I'm pretty sure it's not that the compiler was just passing over the function before, because I use it in other parts of my code-base.

I would be really grateful if someone told me why this is the case & if theres an alternative way I can store my functions...

reddit.com
u/PhosXD — 2 months ago

Inexplicable / unpredictable error with std::unordered_map.find?

Hello all, I started my first project in C++ as a learning experience just about 3 days ago & I have already run into various blood boiling frustrations, but most of all THIS one! For the past 18 hours I have been trying to figure out why for the love of everything good why this code here results in a runtime termination:

op.type_map.find(get_variant_data_type(first.d))

First let me explain everything here.
- `op` This is the struct which holds my unordered map. Confirmed to exist & be properly defined.
- `type_map` This is the actual unordered map, it's type is such: `std::unordered_map<VariantType,std::vector<VariantType>`
- `VariantType` is an enum, but the bug still happens with strings as well, so I dont think this has any correlation.
- `get_variant_data_type` is a function that takes a `VariantData` struct & gets it's corresponding `VariantType`, I have confirmed this is returning the correct value.

Here is the actual value of `op.type_map`:
```
{

{INT, {INT,FLOAT}},

{FLOAT, {FLOAT,INT}},

{STR, {STR}},

},
```

I genuinely have no idea what's going on, `.find` works everywhere else in my code but this specific line has problems, here is the runtime error it produces:
```
terminate called after throwing an instance of 'std::out_of_range'
 what():  unordered_map::at

```

I am not using `.at` anywhere in my code base btw, & the error goes away after removing the use of `.find`. If anyone has any idea why this might be happening please do tell me this has been so frustrating to deal with not knowing the actual cause.

reddit.com
u/PhosXD — 2 months ago
▲ 316 r/godot

It's a joke... Right?

Charging for a simple plugin that honestly doesn't even need to be a plugin with how simple the functionality it claims to implement is. At least there's a free version, but still.

https://preview.redd.it/39g3qikqx39h1.png?width=912&format=png&auto=webp&s=6d0a6d1914cb99796eb3e720776e1a0eb068bf1a

https://preview.redd.it/jl5nh9vby39h1.png?width=900&format=png&auto=webp&s=a3ce68384d991588e17d1355441106ce14be10e7

But maybe I'm wrong & the plugin is so good that it's worth paying $5 for, maybe I'm just misunderstanding what it is, I hope I am.

Help me out here. Let me know if I'm just crazy.

https://preview.redd.it/8nqcsimoz39h1.png?width=897&format=png&auto=webp&s=8388df240e4d291f656f0dff4e2ec10378b3c5a4

Oh wait... They got a whole business going. All released in the same 3-day period. Github account created 2 days ago. Their username is the most generic thing ever.

Btw Im looking at some of these plugins & the things they do are exactly what the title says, there's nothing special to it, no special features any developer couldn't add themselves with a few spare minutes. The only thing special about these plugins is that they are artificially limited & you have to purchase the "PRO" version to unlock basic stuff built into Godot.

Sorry if I am coming off mean or angry here. I genuinely am a little mad that someone is trying to profit off of basic stuff, like they're targeting newbies who don't know better, who likely don't know that free & far better solutions exist. I guess this is what eventually happens to any community when it gets popular.

Yikes sorry for the rant. Let me know your thoughts on this

reddit.com
u/PhosXD — 2 months ago

Fortnite is infiltrating my feed, help.

I dont play fortnite. I never interacted with anything fortnite related on reddit. I dont watch fortnite content. I dont like fortnite.

Everytime I see a fortnite post I hide & click "show fewer posts like this" it because I am genuinely not interested. But every time I get on reddit it's 3 or 4 new fortnite posts in my feed. Its to the point where the "Show fewer like this" button has disappeared & now it only lets me hide individual posts which is useless.

Why wont rFortNiteBR go the fuck away & how do I exile the bastard?

reddit.com
u/PhosXD — 2 months ago
▲ 5 r/aiwars

Literally sums up my stance perfectly.

If you have the time, sit down, watch the video, he makes a lot of good points.

Here's a list of my top arguments most of which are partially covered in the video, discuss them with me:

AI is a net negative

For every good thing it can do, there's twice as many terrible things it can do.

Video generation:

- Harmless memes (sure ok)

- Cheap, high-volume advertising (I don't like it, but sure if it saves you a few bucks have the fuck at it)

- Scam videos (bad)

- Propaganda (bad)

- Deceptive videos (fake news, events, people, etc, BAD)

- Generating sexual videos of children, & unwilling people on the internet (I shouldn't even have to say this, but this is BAD)

Text generation:

- Touch up your emails (sure ok)

- Haha look funny chatbot said funny thing (sure whatever)

- Dynamic dialogue in games (sure ok)

- Data analysis & or sorting (GOOD, probably the only justifiable use case imo)

- High-volume & highly optimized scam texts / emails or whatever (BAD, I know not everyone is easily scammed, but it is still potentially dangerous to the elderly, mentally ill, or just those who aren't very aware of the technology)

- High-volume misinformation in books, news articles, & scientific papers (BAD)

- High-volume & highly convincing fake comments & product reviews (BAD)

- Confidently incorrect & emotionally manipulative chatbots (BAD. Lead to many proven supa side & murder cases, also causes delusion)

Actual scientific research:

Well pretty much all of it is good, the problem is that it is few & far between.

When you compare the pros & cons all up against each other, it's impossible to deny that the world would be & wouldve been an all around better place for everybody if the technology didn't exist.

AI devalues everything it touches

Image & video generation has gotten to the point where leading models are most of the time impossible to tell apart from real images or videos. When everyone has the ability to create near perfect looking images in a matter of seconds, you in specific stop being special, you have no skill or experience that sets you apart from everyone else who has access to an image generator.

What's ironic though, is that real artists are less affected by this than regular people, because they understand the value in their craft. It's less the raw output that matters, but more what went into it.

Art stripped of it's soul, intent, or emotion, is not art, it's a product. When a machine does all the work for you, any meaning you thought you had put into your work has been invalidated because when you remove the effort, you enforce the idea that whatever meaning you are trying to convey isn't *worth* putting effort into, it is therefor worthless by your own.

AI is costly

Okay, so even if you are fine with consuming & creating Gen AI content (which I maintain the right to call you a sloplover or slopfactory if you do, because I personally don't like it, it's my preference) you still can't deny that there is a real world environmental & economical cost to what you are doing which is where the morality argument comes into play because you are affecting real lives. Let's break down what the cost is exactly:

Water:

Yes I know this is sometimes overblown, & doesn't use as much water as other industries. But it's still a lot of water that is used for cooling the data centers powering Gen AI. Most of the numbers aren't even very public, still the numbers we ARE provided with aren't very good & that should be a sign. New datacenters have been proven to cause local water shortage in some local areas.

Electricity:

This is a much larger issue than water. The price for electricity is actively going up & some power grids cannot even keep up with the demand datacenteres are bringing. Now let me ask you something: how do you think electricity is made? What happens when we cant keep up with the energy demand? Do you really think this is a good thing for the environment & your energy bill?

youtube.com
u/PhosXD — 3 months ago
▲ 36 r/ask

Is it normal to have a "cold" eye &amp; a "warm" eye?

Just wanted to ask because I never bothered to before, just want to check if it's one of those things that feel normal until you find out it's not...

Edit: to test this yourself, close one eye & compare the colors you see on a solid color background. For me my right eye has a warmer tone than my left

reddit.com
u/PhosXD — 3 months ago
▲ 7 r/lmms

No matter where I look, there seems to be no clear answer whether or not LINUX VSTs are able to be used on the LINUX version of LMMS. Hoping this sub will be able to help, I really would want to get back into LMMS but no VST support is really putting me off.

reddit.com
u/PhosXD — 4 months ago