Skip to content
Crystal-to-C++ transpiler [WIP]
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Build status

Crystal-to-C++ transpiler [WIP]

Generated code can be compiled with c++14 compiler (tested with g++ 6.2.0)

List of supported AST nodes can be found here

You can try it here

CLI Usage

  1. Compile src/cppize/ (it may take some time as it requires Crystal parser)
  2. Launch compiled executable with -h flag to view all command line flags

Implemented -fFEATUREs

Flag Description
-funsafe-cast Tells transpiler to transpile casts to C-style casts instead of static_casts
-fprimitive-types Tells transpiler to use fundamental C++ types when possible
-fauto-module-type Allows transpiler to detect if module is included
⚠️ This option can slow down transpilation
-fimplicit-static Enables static module methods' calls

Library Usage

# Initialize transpiler
transpiler =

# Set error and warning callbacks
transpiler.on_warning{|e| puts e.to_s}
transpiler.on_error{|e| puts e.to_s; exit 1}

# Transpile file
transpiled_code = transpiler.parse_and_transpile_file("./")
# Transpile code from IO
transpiled_code = transpiler.parse_and_transpile_file("./"),"./")
# Transpile code from string
transpiled_code = transpiler.parse_and_transpile_file("def foo; bar(true) end","<test>")

Things to improve in already supported AST nodes

  1. Improve automatic return
  2. Improve module type detection (namespace / includable)


Implementing nodes

See src/cppize/nodes/ for example

Adding transpile-time macros

See src/cppize/macros/ for example


  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request


  • unn4m3d unn4m3d - creator, maintainer
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.