Git Product home page Git Product logo

cplr's Introduction

cplr - the C piler

The C piler cplr is a tool for executing C code from the shell and is meant to break the barrier between the shell and the core language of UNIX, which it does by making the compiler a tool like sed, grep and awk.

But why!?

The practical purpose of cplr is to allow the compilation and execution of short C programs for testing, system information retrieval, live coding and interactive development of C small sequences and programs.

$ cplr 'puts("hello!")'
hello!
$ cplr 'printf("%d\n", getpagesize())'
4096

Tell me more!

cplr itself is a simple compiler front-end that does not have any comprehension of the C language or even data types, but this is why it works well because it does not try to do something hard. Instead we follow the UNIX philosophy and do just one thing: act as the interactive equivalent of cc.

The current backend of cplr is based on TinyCC, which gives it a language level of C99 or better and the ability to interact with almost any C library on a normal Linux system including large and complicated ones. You can run Gtk or Python in this tool without having to expect any issues.

Usage examples

A basic use is to retrieve type information:

$ cplr -i linux/kvm.h 'printf("%zu\n", sizeof(struct kvm_regs))'
144

You can also use cplr to create ad-hoc executables:

$ cplr -o realpath 'puts(realpath(argv[1],NULL))'
$ ./realpath .
/home/user

Small C libraries can be used directly from source:

$ cplr -s linenoise.c -i linenoise.h 'printf("Line: %s\n", linenoise("% "))'
% hello
Line: hello

Thanks to pkg-config you can easily call any library:

$ cplr -P tinfo -i term.h 'setupterm(NULL,1,NULL)' 'printf("%d\n", tigetnum("colors"))'
256

Building cplr

We build using CMake. You need readline. We bring our own copy of TinyCC.

$ git clone https://github.com/promovicz/cplr.git
$ cd cplr
$ cmake .
$ make
$ make install

Future possibilities

  • C REPL (experimental form exists)
  • Garbage collection (in progress)
  • Crash handlers (easy)
  • Backtrace support
  • Bounds checking
  • Instruction trace
  • Call trace
  • Internal disassembler (capstone)
  • Support other compilers using dlopen
  • Support launching into gdb/lldb
  • Source code and assembly dumping
  • Editor and pager integration
  • Live process code injection (researching)
  • Live kernel code injection (needs gcc)
  • Support for C++ and ObjC (needs gcc/clang)

cplr's People

Contributors

promovicz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.