C++ repl (IGCC)
artificialworlds.net
artificialworlds.net
It's a simple Python wrapper for gcc. And by simple, I mean, really simple. Meaning the GPL is the biggest file in the source tree.
And it doesn't work:
igcc 0.1 Released under GNU GPL version 2 or later, with NO WARRANTY. Type ".h" for help.
g++> int i = 0;
g++> printf("%d\n", s);
[Compile error - type .e to see it.]
g++> printf("%d\n", i);
[Compile error - type .e to see it.]
g++>
Yes, it does exactly what you think it does. It runs GCC on all the code you've entered.
I've been to the future, and language development does not progress in this direction. Future languages certainly do not have all the elegance of C++ and all the speed of Python.
Instead, why not write a C REPL on the front end of the LLVM Jit!?
No one seems to have even thought of writing a Scheme REPL for the LLVM Jit. And that would be completely doable. Write it in C, use Boehm's garbage collector and the LLVM Jit.
The problem with the approach taken is that it compiles everything you ever typed every time you type something. I honestly can't think of a worse combination. C++ is the language, you need a Python interpreter to run it. And there's no incremental compilation, so it just gets slower and slower the more you do.
People who write stuff in Python need to realise that sometimes you can't solve a problem just by wrapping something in Python. Occasionally you need to do some actual work. I'm afraid I see this all too often.
http://home.mweb.co.za/sd/sdonovan/underc.html
and Ch - (but C only) http://www.softintegration.com/ (commercial)
Second, the language syntax and semantics just don't lend themselves very well to a REPL. For example, there is no top-level execution context in C++. Should we pretend like the lines entered into the interpreter are part of main()? That would mean we couldn't do useful things like define functions. And should typing `int foo = 3` lock up the identifier "foo" for use as an int forever, like it would in normal C++, so that we couldn't later write `float foo` or `string foo` without restarting the interpreter ?
http://root.cern.ch/drupal/content/cint
(also root, of course)
Here's an excerpt from my most recent cint repl session:
cint> {long x = 84bfaad645e2e33f; double * p = &x;}
Warning: Illegal numerical expression 84bfaad645e2e33f FILE:(tmpfile) LINE:1
cint> {long x = 0x84bfaad645e2e33f; double * p = &x;}
cint> p p
(double*)0x100809480
cint> p *p
(double)(-8.31870270613823687e-286)Also you lose certain features that are available to the interpretter - but that's okay - that was the point...
As a REPL CINT actually works surprisingly well. Unfortunately it seems to have some problems interpreting certain "advanced" C++ stuff, such as templates and especially code that uses STL heavily. Another problem with it is that since you still need to manage memory manually and have direct access to pointers it's very easy to make CINT (or ROOT) session crash... :(
Btw, the ROOT developers are also working on a new LLVM based C++ interpreter called Cling: http://root.cern.ch/drupal/category/package-context/cling
Moreover, you need to be able to redefine things. For example, suppose you defined a type or a function and changed your mind and later decided to redefine them.
I doubt the Clang front-end is designed with this sort of thing in mind.