c-repl

(last updated: 2008-08-13.)

Many programming languages come with a REPL (read-eval-print loop), which allows you to type in code line by line and see what it does. This is quite useful for prototyping, experimentation, and debugging code.

Other programming languages, and especially C, use a "compile-run" model, and don't provide a REPL. Let's fix that.

What you get

This approach is actually more of a read-eval loop, as c-repl doesn't know much about the types and parse trees of the code it's running. But unlike other approaches to solving the "C interpreter" problem, c-repl works directly with unmodified libraries and system headers.

This means you can experiment with a new library without writing a test program or any bindings. Or just use it as a simple calculator, content in knowing it is much faster than your neighbors using irb, like driving a Ferarri on city streets.

Some especially cute frosting features:

Example Session

Here's an example session demonstrating using c-repl:

% ./c-repl
> int x = 3
> ++x
> .p x
int: 4
> printf("%d %p\n", x, &x)
4 0xb7f1b53c
> .t fprintf
fprintf(FILE* const stream, char const* const format)
> #include <unistd.h>
> getp<TAB>
getpagesize  getpass      getpgid      getpgrp      getpid       getppid
> printf("%d\n", getpid())
19094

How to get and use it

Git repository contains a README.

Bugs

c-repl is very much in progress, so bug reports would be appreciated.

Evan Martin, martine@danga.com