Skip to content
Siddhartha Dhar Choudhury edited this page Jan 23, 2021 · 1 revision

What is simC?

"A dynamically typed high-level front end for C" - this is the single line description that you can find in this repository's description. Let's break this down into smaller parts to have an initial idea about the simC compiler:-

dynamically typed - Dynamic typing refers to the fact that a compiler can assign a type to an identifier (variable, function, structure name) during runtime, and an important step towards dynamic typing is inferring the type of the identifier. In context for simC dynamic typing is synonymous to type inference as there is no runtime (I will get back to this later). So, what this means is simC has the capability of inferring (or finding out) the type of the identifier from the type of value it gets.

high-level - As we know, the syntax of C can be categorized as middle-level, there are few programming constructs in the language and almost everything has to be done by the programmer, though this is a huge benefit of C but at times this can be a hindrance. If on the other hand, C had a high level syntax but at the same time allowing one to go to the low level details then it would have been absolutely delightful, won't it? Well, this is what simC aims to do, it introduces a high-level syntax for C.

front end - If you are from a web development background then this word might mean something completely different (a front end design of a web application or website), but in this case the front end refers to front end of the compiler which is the syntax that the user is presented with. Front end here simply means syntax.

Let's sum up what we have defined above. In very simple words, simC is a high-level syntax for C, you write code in this high-level syntax and use the simC compiler to convert it to equivalent C code. So, essentially when you write code in simC that gets compiled (or converted) to C code. simC compiler does not run the code at all, it just converts it into equivalent C code (now you know why I mentioned no runtime before).

Why not use Python then?

You might wonder at this point, that instead of having to write code in a hypothetical syntax (or front end) you can just write code in a high-level language like Python. You will still get a high-level easy to understand syntax, but what you will miss out on is the speed at which your code is executed. Python is an interpreted language (if you are interested in learning how an interpreter works in detail, do go through this great book Crafting Interpreters by Bob Nystrom) and these languages run the code using something called as as interpreter which analyzes users code and then converts it into an internal representation which can then be run using a virtual machine (which is in turn written in a compiled language like C or C++).

Compiled languages, on the other hand, convert your code into assembly or machine code which is much faster, as it is the lowest level of abstraction in programming and something that the computer actually understands. Thus the code written in compiled languages run much faster than interpreted languages. When you write code in Python, you can iterate faster on your idea but what you miss out on is the speed of execution, which C offers you. Using simC you not only get the high-level syntax but also the runtime execution speed as your simC code gets compiled to C which finally gets converted to assembly or machine code and that is blazing fast.

Pipeline

Let us understand the pipeline, from when you write code in simC till it gets executed:-

  1. You write code in simC.
  2. Pass the code through simC compiler, this gives you equivalent C code.
  3. Compile the C code using any standard C compiler (GCC, Clang, MSVC).
  4. Run the executable (or binary) generated.