-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update README.md to reflect this fork
- Loading branch information
1 parent
8ffb55c
commit 60f6c91
Showing
2 changed files
with
54 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,62 @@ | ||
c4 - C in four functions | ||
======================== | ||
c4 - A self-contained C Compiler and VM that can run itself | ||
=========================================================== | ||
|
||
An exercise in minimalism. | ||
C4 is Robert Swierczek's tour-de-force exercise in minimalism, a four | ||
function C-subset compiler that can run itself. This fork aims to | ||
evolving it a bit, forgoing the "four function" constraint, but | ||
keeping the self-compiling and self-contained property. | ||
|
||
Wishlist | ||
-------- | ||
|
||
- Merge the switch + struct work into c5 (the c4 branch that adds an | ||
intermediate AST) | ||
|
||
- Enable a standalone VM (currently host addresses are embedded into | ||
the instruction stream). Make the VM byte-code based, increasing | ||
the code density substantially. | ||
|
||
- Migrate to a more efficient execution model. The current stack | ||
machine is rather inefficient; for example `x += y` (which both are | ||
local variables) are translated into | ||
|
||
``` | ||
LEA -6; PSH; LEA -6; LI; PSH; LEA -3; LI; ADD; SI | ||
``` | ||
where we really just need something like | ||
``` | ||
ADD -6, -3` | ||
``` | ||
(Note, this looks a lot like a register machine, but the "registers" | ||
here are stack allocated variables). | ||
|
||
- Switch statements should be table-lookup based. | ||
|
||
- Expand the language in the direction of C99, notably adding locals | ||
with initialization. | ||
|
||
|
||
Tricks | ||
------ | ||
|
||
Robert deploys a range of marvelous tricks to keep this simple and | ||
small. An incomplete list includes: | ||
|
||
- Tokens are in operator precedence order which simplifies the | ||
precedence-climbing recursive descent parser. | ||
|
||
- Lvalue addresses are handled by undoing the last load (this only | ||
applies to c4 as with the AST something different is done). | ||
|
||
Usage | ||
===== | ||
|
||
Try the following: | ||
|
||
gcc -o c4 c4.c | ||
./c4 hello.c | ||
./c4 -s hello.c | ||
|
||
./c4 c4.c hello.c | ||
./c4 c4.c c4.c hello.c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters