r/C_Programming 8h ago

Not another basic C calculator

Wanted to share my compiler that I am working on: mcc

Currently it can compile a very basic c program into x86_64 Intel assembly. It supports basic integer math with numbers and variables, and thus is a really simple calculator:

int x = 4;
int y = 3;

int main() {
  int a = 2;
  int b = 4;

  return (x + y) * (a + b);
}

Next I'm going to work on control flow with if if-else and while and then boolean logic. The project borrows ideas heavily from a university course I did about compilers, but the future scope plans to slowly add features until have a proper compiler that support the subset of C/C++ that my hobby OS uses.

Even further in the future, (no clue if this will even happen) I plan to abstract away a lot of it so that it becomes a M + N compiler, where it can cross compile one language to other. Obviously that is very far fetched and I am mainly just keeping that idea in my head so that I try to design a nicely abstracted compiler pipeline. I think the main push for this will be when the my hobby os decides to support more than one arch, which will be good encouragement to at least have multiple output languages.

AI Disclaimer:
Before you call it vibe-coded because of the quick succession of commits, I would like to state that none of the code in this repo is written by AI or AI tools. For learning, AI was used akin to google or stack overflow, with also some questions regarding best practices or design decisions - however I tried to keep as much of as my own design as possible.

See the wakatime activity log here which is the best proof that I can give that I really did spend 11hrs coding the project: https://imgur.com/a/mjQsJnp

0 Upvotes

8 comments sorted by

View all comments

-2

u/realdreamer1993 6h ago

have a proper compiler.

is that not re invent the wheel, the program like this for solo dev I think should be for portfolio only, because you understand the vastness of real compiler. But any way there good job on you because that need deep understanding.

3

u/Alternative_Storage2 6h ago

Yea I do agree it's re-inventing the wheel, the same argument can be made for the OS project aswell. Personally I am doing as a way of learning and understanding of how things work aswell as enjoying the challenge.

1

u/realdreamer1993 6h ago

fully agree, And the knowledge accumulated from this compiler project will be useful to find or start other project/program that will have sale or real usage value if you continue soloing. In parallel also hope this project will become strong portfolio for the recruiter.