Skip to content

Commit

Permalink
c89 backend fixes, initialization fixes, deprecated old modes but not…
Browse files Browse the repository at this point in the history
… removed info from AST.
  • Loading branch information
thradams committed Dec 6, 2024
1 parent 015f2a7 commit e345295
Show file tree
Hide file tree
Showing 55 changed files with 22,587 additions and 41,891 deletions.
64 changes: 38 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ The C Programming language Second Edition 1988

# 🍰 Cake

Cake is a compiler front end written from scratch in C, designed from the C23 language specification.
It allows you to translate newer versions of C, such as C23, to C99. Additionally, Cake provides a platform
for experimenting with new features for the C language, including extensions like lambdas, defer and static [object lifetime](ownership.md) checks.
Cake is a compiler front-end written from scratch in C, adhering to the C23 language
specification and beyond.
It serves as a platform for experimenting with new features,
including C2Y language proposals, safety enhancements, and extensions such as
lambda expressions and defer statements.

The current backend generates C89-compatible code, which can be pipelined with existing
compilers to produce executables.

Cake aims to enhance C's safety by providing high-quality warning messages and advanced
flow analysis, including [object lifetime](ownership.md) checks.

# Web Playground

Expand All @@ -27,9 +34,26 @@ http://thradams.com/cake/playground.html

# Use cases

If you have a project that is distributed with code, you don't need to limit the project development at the lower supported language version. For instance, you can use attributes like *nodiscard* during the development or *defer*, both features
improving the code security. Then adding a extra step in your build you can distribute a readable C99 source code that compiles everywhere.
Cake can also be used as static analyzer, especially the new object lifetime analysis.
Note: Cake is still in development and has not yet reached
a stable version.

Cake can be used as a static analyzer alongside other compilers.
It generates SARIF files, which are recognized by popular IDEs
such as Visual Studio and Visual Studio Code, providing a
seamless integration.

It can also function as a preprocessor, converting C23 code to C89.
This allows developers to use modern features while targeting
compilers that do not yet support the latest language standards.

Previous versions of Cake included a conversion mode to
translate code while preserving the preprocessor parts.
Although useful, this process could not guarantee 100% conversion,
functioning more as a tool than a compiler. With the new versions
of Cake moving toward becoming a more traditional compiler,
the previous mode has been discontinued at version 0.9.36.
This version is online here
http://thradams.com/cake3/playground.html.

# Features

Expand All @@ -38,7 +62,7 @@ Cake can also be used as static analyzer, especially the new object lifetime ana
* C23 semantic analysis
* Static [object lifetime](ownership.md) checks (Extension)
* Sarif output
* C backend
* Backend generating C89 compatible code
* AST
* So far, 34 preprocessor diagnostics, 236 compiler diagnostics

Expand Down Expand Up @@ -116,7 +140,8 @@ See [Manual](manual.md)

* Remove all warnings of cake source code in safe mode to validate the design and implementation
* Fixes

* C89 backend

# References

How did we get here?
Expand Down Expand Up @@ -167,27 +192,14 @@ I use Visual Studio code with WSL for testing and compiling the code for Linux.
Cake source code is not using any extension so the output is the same of input.
This compilation is useful for tracking errors together with the unit tests.

# Differences from CFront

CFront was the original compiler for C++, designed to convert C++ code into C.

The code generated by CFront was used solely for direct compilation because
it had all macros expanded, making the generated output unsuitable for
reuse on other platforms.

Cake offers two modes. The first is for direct compilation, similar to CFront.
The second mode preserves macros, includes, and other preprocessor directives,
making the output suitable for distribution.
# Cake is not C++
CFront was the original C++ compiler, designed to translate C++ code into C.

Another key difference is that C++ represents a separate
evolutionary branch, maintaining greater compatibility with C89
than with C99.
Although CFront was initially compatible with C89, it eventually diverged from C’s evolution.

The goal of Cake is to follow the main evolutionary line of C and remain
100% compatible with C.
In contrast, Cake stays true to the core development of C, ensuring full compatibility.

The added extensions aim to uphold the spirit of the language while allowing
developers to experiment with proposed features even before they become standardized.
Its extensions aim to preserve the essence of C while allowing developers to experiment and contribute to C’s evolution using an open-source compiler written in C.



Expand Down
Loading

0 comments on commit e345295

Please sign in to comment.