RSS Amplifier

Compiler Spotlight · Aug 11, 2022

Language Showcase: C3

0
Sign in to vote or save

Jeaye Wilkerson · Compiler Spotlight

C3 is a systems programming language based on C. It’s an evolution of C enabling the same paradigms and retaining the same syntax as far as possible. For today’s language showcase, C3’s developer, Christoffer Lernö, talks about what makes it tick.

C3 is an evolution of C: “what could C look like if backwards compatibility wasn’t a concern?”. The main additions are modules, slices and semantic macros, but otherwise it tries to stay close to the look-and-feel of C. Most importantly, it is ABI compatible with C everywhere, meaning functions in C3 are by default callable from C and vice versa.

You don’t have to rewrite everything in C3, you can pick and choose.

C has the burden of backwards compatibility and while it’s possible to add features on top, it’s hard to make them nicely integrated in the overall language. Some parts of C (in particular string handling and arrays) aren’t very ergonomic and makes the language seem harder to use than it needs to be. So it’s about making C programming more accessible and less punishing by providing better tools for the pain points in C.

I don’t know if it is! There are a couple of ”C replacement languages” in development right now: Odin, Jai, Zig and Hare to name a few. What they have in common is that they diverge quite a bit from C syntax and semantics.

C3 is different: you can just lift your C code with just a few changes into C3 and have it run as expected.

I’d love to have more people invested in the project with strong language design sensibilities to bounce ideas off. I love a good argument to be able to narrow down on the essentials of a feature. Luckily there are forums for budding programming language designers to trade ideas which helps. But that’s not quite the same as having someone who really wants to help YOUR language.

The programming is the easy part.

Work on expanding the standard library, I’d like to reach the point where people can feel it has all the necessary basics.

The docs can be found at https://www.c3-lang.org and the compiler can be found on Github: https://github.com/c3lang/c3c

C2, by Bas van den Berg. My first compiler work was actually contributing to the C2 compiler! While Bas wanted a more modest feature set on top of C, I thought more ideas should be tested, and initially C3 was just C2 + some more features. When I decided to write a compiler for my ideas, I picked the name C3 to acknowledge its origins.

Prompt: Implement a program which takes in a single string from stdin containing a basic arithmetic expression, such as “1 + 2 - 5”, evaluate it, and print the result.

No posts

Read the original on compilerspotlight.substack.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.