Skip to content

Islam0mar/rcrl

 
 

Repository files navigation

Read-Compile-Run-Loop: tiny and powerful interactive C++ compiler (REPL)

I made some changes to fit my needs.

picture

  • use libclang
  • use sdl2 with opengl3
  • remove tiny-process and glfw
  • add field for compiler flags

The New Recipe

  • Text input is feed to clang.
  • Traverse the parsed code for functions & variables definition "ignore errors".
  • Add export prefix for them and put them in plugin.cpp.
  • Every non-parsed text would be regarded as once in plugin.cpp.
  • Append plugin.hpp with functions prototypes and extern variables.
  • Load library with RTLD_GLOBAL, so variables can be reused.

NOTE

Check cli branch for command line version.

TODO

  • resolve license: GNU General Public License
  • use libclang
  • replace tiny process with boost process
  • rewrite test cases
  • smarter header generation for functions and variables
  • *support class,struct,enum,... def.
  • allow redefinition (currently shadow subsequent variables except in the same buffer RTLD_DEEPBIND)
  • test on windows
  • check for errors in compilation
  • check for errors in compiler command
  • add timeout for compilation
  • fix parser int x = 0!!
  • fix set-flag lag
  • add an option to add link flags
  • maybe use zapcc for better compilation time

Original

Windows status Linux Status Language License

RCRL is a tiny engine for interactive C++ compilation and execution (implemented in just a few source files - src/rcrl) and works on any platform with any toolchain - the main focus is easy integration. It supports:

  • mixing includes, type/function definitions, persistent variable definitions and statements meant only for function scope
  • interacting with the host application through dll-exported symbols (after linking to it)

Watch this youtube video to see it in action with commentary:

youtube video showcase

It is an elegant alternative to cling (and other projects that are built on top of it).

I gave a 30 minute talk about it at CppCon 2018 showing it integrated in a small but functional game engine:

youtube cppcon video showcase

This repository is a demo project with GUI but the RCRL engine can be integrated in any way with host applications - code may be submitted even from external editors with full syntax highlighting and code completion! The goal was not to make a one-size-fits-all solution because that is hardly possible - but to demonstrate how the core of RCRL can be integrated.

Checkout this blog post if you are curious how to use it, how it works and how to integrate it.

Building

The demo is tested on Windows/Linux/MacOS and uses OpenGL 2.

You will need:

  • CMake 3.0 or newer
  • A C++17 capable compiler

The repository makes use of a few third party libraries and they are setup as submodules of the repo (in src/third_party/). Here are the steps you'll need to setup, build and run the project after cloning it:

  • git submodule update --init - checks out the submodules
  • cmake path/to/repo - call cmake to generate the build files
  • cmake --build . - compiles the project
  • the resulting binary is host_app in bin of the build folder

Copyright

Copyright (c) 2018 Viktor Kirilov
Copyright (c) 2020 Islam Omar (io1131@fayoum.edu.eg)

About

Read-Compile-Run-Loop: tiny and powerful interactive C++ compiler (REPL)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 73.1%
  • CMake 25.8%
  • Other 1.1%