Skip to content

PracticallyNothing/toycpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

toycpp: A toy C++ compiler

I'm interested in implementing a compiler for some subset of the C++ language, as a learning exercise, inspired by Tsoding's recreational programming.

The compiler's goal is to produce X86_64 assembly.

Inspirations/resources

Development and Usage

  1. Install fasm, git, a C++ compiler supporting C++17 and GNU Make:
    sudo apt install git fasm gcc-c++ make
  2. Clone the project and compile toycpp using make:
    git clone https://github.com/PracticallyNothing/toycpp
    cd toycpp
    make -j4
  3. Run toycpp on a C++ file - this will produce a file called executable in the current directory.
    ./toycpp test/add.cpp
  4. Run executable - voila!
    ./executable

Unsupported stuff

Parens around function parameter names

This is to avoid the most vexing parse - C (and C++ by extension) technically allows you to put parentheses around the names of function parameters:

// These two are equivalent.
int main(int  argc,  const char**  argv)
int main(int (argc), const char** (argv));

I have no idea what the use of this is and I've never seen it used anywhere. Skipping support for this makes parsing other things easier.

About

A toy implementation of a compiler for a subset of C++

Topics

Resources

Stars

Watchers

Forks