adrianensis / Compiler

Simplified C++ to modern C++ transpiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README


Compiler

This project is actually a transpiler, I just stared it as a compiler study/practice. Here I attempt to translate from a simplified form of C++ to modern C++.

(I should think in a better name for my simplified C++ version)

This was a couple of months side project, feel free to learn from it, but please don't expect a stable tool. There's half done stuff and buggy features here and there.

Still, I managed to port some classes from my game engine math library to simplified C++, which was way more than expected when I started this. Compilers are intimidating, but once you get to have a basic one working, it feels very powerful.


Features

  • No pointers or references
  • Define the memory space for each class (stack or heap) by using stack keyword before class definition: stack class Line: public Shape
  • Single file (no declaration/implementation separation)
  • Modules!
  • Automatic includes and circular dependency
  • It relies on C++ linters and Language Servers for coloring/autocompletion
    • Some errors may be spotted (related with includes etc)
  • It relies on some silly macros (see code/core/FakeMacros.hpp) to fake some keywords

Experimental

  • Access to C++ std stuff

Bugs

  • Recursive Scope search must be improved

TODO

  • Access to STL containers
  • Reflection (it should come almost for free)
  • Lambdas syntax

Build

  • RECOMENDED
    1. to build compiler + ToCPP tool: python3 -B scripts/build.py -xl
      • it will generate: binaries/tools_ToCPP
      • NOTICE this IS the transpiler
      • you can use it like this: ./binaries/tools_ToCPP file1.cxx file2.cxx ...
      • I usually run the tool from VSCode with launch.json and tasks.json configurations
    2. build integration test suite: python3 -B scripts/build.py -xil
      • this will build the generated C++ files test/integration/BasicTest

Linux

  • First, download and install dependencies: ./scripts/dependencies.sh
  • Build project: python -B ./scripts/build.py -[ruixlch]
    • -h Show help.
    • -r Compile Release, Debug by default.
    • -u Compile Unit Tests suite. (NEEDED BY test.sh)
    • -i Compile Integration Tests suite. (NEEDED BY test.sh)
    • -x Compile Tools.
    • -l Enable Logs.
    • -c Clean the project.
  • Run unitary tests (optional): ./scripts/test.sh

Windows

Not available yet.


Directories

  • code: Source and Headers.
  • config: Engine and scenes config files.
  • scripts: Contains scripts described above.
  • compiledLibs: Contains the libcompiler.a. Generated by scripts/build.py.
  • binaries: Generated by scripts/test.sh.. Contains the test executable files (both unitary and integration).
  • test: Set of tests. Unitary and Integration.
  • tools: Set of tools.
  • dependencies: Generated by scripts/dependencies.sh. Contains third party libraries.
  • build: Generated by scripts/build.py.

Unitary Tests

Run unitary tests with ./scripts/test.sh. Result are stored in binaries/output. This command will print the results in terminal.

Integration Tests

Run integration test by executing ./binaries/test_integration. Result is stored in log.txt.

About

Simplified C++ to modern C++ transpiler


Languages

Language:C++ 94.9%Language:CMake 2.9%Language:Python 1.9%Language:Shell 0.4%