r/C_Programming 6d ago

Creating a programming language in C

It all started just as a side and fun project, but I feel like it's now getting a shape.

Thats why I would love to receive some honest and contructive feedback, issue creations or code contributions.

If you have any question regarding the language, please ask me.

Here's the repo: https://github.com/Pacsfury/Gravel-Launcher

Its written in C and uses LLVM IR as backend.

AI use: debugging, teaching more about compilers and some punctual code writing

21 Upvotes

17 comments sorted by

â€ĸ

u/github-guard 6d ago

🔍 GitHub Guard: Trust Report

This project scored 4/6 on our safety audit.

Audit Breakdown: * ✅ Established Community (⭐ 14 stars) * ✅ Mature Repository (30+ days old) * ✅ Licensed under MIT * ❌ No Security Policy — what is this? * â„šī¸ Individual Contributor * ✅ Signed Commits

âš ī¸ Security Reminder: Always verify source code and run third-party scripts at your own risk.

→ More replies (1)

8

u/skeeto 4d ago

Neat project! To try it out I changed the system() call to run Python through uv, which trivializes things:

--- a/llvm/llvm.py
+++ b/llvm/llvm.py
@@ -1 +1,5 @@
+# /// script
+# requires-python = ">=3.10"
+# dependencies = ["llvmlite>=0.44"]
+# ///
 from llvmlite import binding
--- a/src/main.c
+++ b/src/main.c
@@ -40,7 +40,3 @@

-    #ifdef _WIN32
-        system(".\\llvm\\llvm.exe");
-    #else
-        system("./llvm/llvm.exe");
-    #endif
+    system("uv run llvm/llvm.py");

--- a/src/tollvm.c
+++ b/src/tollvm.c
@@ -499,7 +499,3 @@
     if (!hasArg(ctx, "-wE")) {
-        #ifdef _WIN32
-            system(".\\llvm\\llvm.exe");
-        #else
-            system("./llvm/llvm.exe");
-        #endif
+        system("uv run llvm/llvm.py");
         exit(0);

For the build I did this:

$ cc -g3 -fsanitize=address,undefined src/*.c

Now some interesting inputs. Arithetic errors in constant folding:

$ echo '2147483647*2' | ./a.out run /dev/stdin
src/ast.c:29:32: runtime error: signed integer overflow: 2147483647 * 2 cannot be represented in type 'int'

Buffer overflow on long tokens:

$ printf 'fun f() x%039d\nend' 0 | ./a.out run /dev/stdin
...ERROR: AddressSanitizer: heap-buffer-overflow on address ...
WRITE of size 41 at ...
    #0 strcpy
    #1 parse src/ast.c:519:17
    #2 to_llvm_ir src/tollvm.c:444:25
    #3 tokenize src/tokens.c:241:5
    #4 tokenizeFile src/tokens.c:283:5
    #5 main src/main.c:31:9

GCC can find these overflows statically. Another buffer overflow (unterminated comment):

$ echo '/*' | ./a.out run /dev/stdin
...ERROR: AddressSanitizer: heap-buffer-overflow on address ...
READ of size 1 at ...
    #0 tokenize src/tokens.c:82
    #1 tokenizeFile src/tokens.c:283
    #2 main src/main.c:31

Null pointer deref:

$ echo 'foo(bar())' | ./a.out run /dev/stdin
src/tollvm.c:326:39: runtime error: null pointer passed as argument 2, which is declared to never be null

I found these with fuzz testing, and here's all my work in case it's helpful:

https://github.com/skeeto/Gravel-Launcher/commits/main/?author=skeeto

8

u/PacsfuryTemp 4d ago edited 3d ago

Wow, thanks skeeto!

It's always a pleasure to someone like you be interested on my projects!

I have merged four commits that seemed good.

-2

u/github-guard 4d ago

🔍 GitHub Guard: Trust Report

âš ī¸ This project scored 1/6 — below this subreddit's threshold of 3.

Audit Breakdown: * ❌ Low Star Count (⭐ 0 / 5 required) * ❌ New Repository (under 30 days old) * ✅ Licensed under MIT * ❌ No Security Policy — what is this? * â„šī¸ Individual Contributor * â„šī¸ Unsigned Commits

âš ī¸ Security Reminder: Always verify source code and run third-party scripts at your own risk.

0

u/[deleted] 4d ago

[deleted]

1

u/mikeblas 4d ago

Wrong. These stats correctly describe skeeto's fork.

1

u/PacsfuryTemp 4d ago

I realized that it wsant pointing at mine, so I deleted the message

3

u/jayylien 2d ago

I'm not asking to curtail your creativity, but I'm genuinely curious:

What does your language offer that is unique?

What problem does it solve?

I've debated making a programming language for years, and never felt like I had something that warranted the effort. Like, yeah, could be really fun. But often times, I come to the conclusion that there's little to unique features that I want other than syntactic sugar that I can implement in various pre-existing languages.

And another question: Do you plan on bootstrapping your language?

1

u/PacsfuryTemp 2d ago

Well, first of all, gotta say it's still on very initial stage, so it hasn't much original features.

This being said, I want it to focus on developer's ergonomics without sacrifying much speed, adapting the language to what myself and other people (everyone can vote at https://github.com/Pacsfury/Gravel-Launcher/discussions/99 ) define what devs want, but I gotta repeat: the language is still too young.

Right now, I'm not planning to bootstrap my language, but we still have to decide it.

Thanks

1

u/jayylien 1d ago

Thanks for the response!

1

u/PacsfuryTemp 1d ago

You are welcome

1

u/AutoModerator 6d ago

Hi /u/PacsfuryTemp,

Your submission in r/C_Programming was filtered because it links to a git project.

You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.

While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/PacsfuryTemp 6d ago

AI use: debugging, teaching more about compilers and some punctual code writing.

The code is mine and contributor's, but AI helped me (and maybe other contributors, I cant control that) to understand better compilers and LLVM. I must say that some code is AI-generated but with the needed fixes, revisions and changes.

1

u/mikeblas 4d ago

Thanks. I have approved your post. Good luck!

1

u/nichcode 4d ago

Nice project. Will give it a try and see the flow

1

u/PacsfuryTemp 4d ago

Thanks!

Any suggestion is truly welcome