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:
- tab-completion of in-scope symbols
- inspection of in-scope variables (via the .t command)
Example Session
Here's an example session demonstrating using c-repl:
% ./dist/build/c-repl/c-repl
> int x = 3
> ++x
> .i 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
This code is managed with darcs. Fetch it with
darcs get http://neugierig.org/software/darcs/c-replor browse the source. Recent patches:
- (3 months ago) rename executable, use libexec dir
- (3 months ago) try multiple paths for child
- (3 months ago) .i for include for symmetry with .l
Please see the README for details.
Bugs
c-repl is very much in progress, so bug reports would be appreciated.