cling

Hi,

As we announced before
<http://www.llvm.org/devmtg/2010-11/Naumann-Cling.pdf&gt;, we (people from
CERN and Fermilab) are working on the C++ interpreter(*) cling
<http://cern.ch/cling&gt; that's based on clang and llvm. This is in the
context of ROOT <http://root.cern.ch> and CINT
<http://root.cern.ch/cint&gt;, our current C++ interpreter.

We have gotten to a stage where we believe cling is actually useful: it
behaves like a regular interpreter!

[cling]$ #include <cmath>
[cling]$ double x = std::sin(3.1)
(double) 4.158066e-02
[cling]$ .L libz
[cling]$ #include "zlib.h"
[cling]$ zlibVersion()
(const char * const) "1.2.3.4"

or simply

$ echo 'extern "C" const char* zlibVersion();
zlibVersion()' | cling -lz

(const char * const) "1.2.3.4"

and even

$ cat t.cxx
#include "cling/Interpreter/Interpreter.h"
void t() {
   gCling->processLine("gCling->getVersion()");
}
$ cling
[cling]$ .x t.cxx
(const char * const) "$Id: Interpreter.cpp 40322 2011-07-21 14:20:14Z
axel $"

We would like to know whether it's just us finding this spectacular :slight_smile:
or whether there is general interest. Our aim is to get it included in
the clang repository.

For us, this is just the first step; we need to integrate it into the
rest of our software wildlife here at CERN, and we need to continue to
work on robustness and features, e.g. reloading of code. I.e. I expect
we will maintain and continue to develop it for years to come.

Here is the code:
svn co http://root.cern.ch/svn/root/branches/dev/cling

Let us know what you think!

Best regards,
the cling team (Vassil, Philippe, Paul, Lukasz and Axel).

(*) Yes, it's not an interpreter, it's really an incremental compiler
with an interactive shell with (eventually) features like automatic
library loading and late variable binding. But it smells like an
interpreter :slight_smile:

I think this is very cool!

So how well will it scale? For example can we use it to run on/with LLVM/Clang
source? Sorry I have only briefly read through your links.

Keep it up

Garrison

Hi Garrison,

I think this is very cool!

Thanks :slight_smile:

So how well will it scale? For example can we use it to run on/with LLVM/Clang
source?

It scales like a traditional translation unit. I.e. I wouldn't #include
all of clang's sources but pull clang in through shared libraries and
headers. As the example I sent shows, cling can load and reference
shared libs.

Cheers, Axel.

I'll definitely have to check this out!

Thanks for the work

Garrison

Hi Axel,

That is awesome!

So how well will it scale? For example can we use it to run on/with LLVM/Clang
source?

It scales like a traditional translation unit. I.e. I wouldn't #include
all of clang's sources but pull clang in through shared libraries and
headers. As the example I sent shows, cling can load and reference
shared libs.

Technically it should be possible to have a static library in llvm bitcode and load that, is it something you guys can consider ?

-Argyrios

Hi Argyrios,

Technically it should be possible to have a static library in llvm
bitcode and load that, is it something you guys can consider ?

Implemented. You can now do e.g.

$ cat test.cxx
#include <stdio.h>
void HELLO() { printf("HELLO!\n");}
$ clang -emit-llvm -c test.cxx -o test.bc
$ cling -ltest.bc
$ void HELLO();
$ HELLO()
HELLO!

It simply uses the llvm::Linker - whatever that understands should now
be understood by cling.

Thanks for the suggestion!

Cheers, Axel.

Very cool looking. How does it compare to ccons (http://code.google.com/p/ccons/), and any chance we could get C and Objective-C/Objective-C++ support eventually?

-Daniel

Hi Argyrios,

Technically it should be possible to have a static library in llvm
bitcode and load that, is it something you guys can consider ?

Implemented. You can now do e.g.

$ cat test.cxx
#include <stdio.h>
void HELLO() { printf("HELLO!\n");}
$ clang -emit-llvm -c test.cxx -o test.bc
$ cling -ltest.bc
$ void HELLO();
$ HELLO()
HELLO!

It simply uses the llvm::Linker - whatever that understands should now
be understood by cling.

Nice, that's great!

-Argyrios

Hi,
The prompt of ccons looks similar to ours.
I think with few minor tweaks mainly in the prompt it would be possible. If we have usecase for people using it with C and Objective-{C|C++} I am willing to work on that.

Vassil

I'd be very interested in Objective-C support (with the GNU runtimes):

- We use Smalltalk for scripting Objective-C applications, but it would be nice to do the same with Objective-C
- Lots of people use F-Script or similar to test their understanding of Objective-C APIs, since it's trivial to write a few message sends. It would be great if we could just pop up a transcript window that people could run Objective-C code in.

David

-- Sent from my Difference Engine

Hi Daniel,

How does it compare to ccons (Google Code Archive - Long-term storage for Google Code Project Hosting.),

Both looked at one another, but both took different routes in the end;
they have different abilities and do things differently behind the scenes.

E.g. cling has a never-ending translation unit, while ccons (if I
remember correctly) tries to import previous declarations into new
translation units that it then links in. One of the many examples.

ccons seems to not support C++.

and any chance we could get C and

Supporting C should be somewhere between trivial and easy.

Objective-C/Objective-C++ support eventually?

We tried to not deliberately exclude it :slight_smile: My experience with
ObjectiveC/C++ is too limited to estimate how much work it would be.

Cheers, Axel.

Well, I started looking at what it would take to get Objective-C working, but unfortunately cling seems to fail with pretty trivial C code:

$ cling
.
**** Welcome to the cling prototype! ****
* Type C code and press enter to run it *
* Type .q, exit or ctrl+D to quit *

FWIW, that works in ccons:

double zero = 0.000000e+00;
zero;

=> (double) 0.000000

One of my design goals in ccons was to be very faithful to C. For
example, for most things you need to use exact C syntax (e.g. needing
semicolons and such - something I believe cling isn't so strict
about). Even to exit the program, you just call exit(0); :wink:

I think some of the early work in cling was based in some ways on
ccons, though now I see that it looks like most of it has been
refactored and rewritten - I could only find one file in cling that is
credited to my ccons code.

As a successor to my ccons prototype, the only thing I'd like to see
in cling is to have a mode that is strict and faithful to C (and
another to C++), without any CINT extensions.

-Alexei

Hi Alexei,

Great hearing from you!

I think some of the early work in cling was based in some ways on
ccons,

Absolutely! cling was turned inside out several times, and now the core
is stable and functional enough that we wanted to go "public". C++ is
not C :wink:

Btw, the missing semicolon you refer to is our way of signaling that you
want to see the result of an expression.

As a successor to my ccons prototype, the only thing I'd like to see
in cling is to have a mode that is strict and faithful to C (and
another to C++), without any CINT extensions.

We absolutely agree. Disabling of extensions is currently only partially
implemented.

Thanks for your support back then that got us started, and for your
helpful comments now!

Cheers, Axel.

Hi David,
   Thanks for reporting!
   I believe that is fixed now.

cat /tmp/trivial.c
double zero = 0.000000e+00;
cling -x c

**** Welcome to the cling prototype! ****
* Type C code and press enter to run it *
* Type .q, exit or ctrl+D to quit *

Hi Alexei,

mean '::cling::Interpreter'?

Hi,

I downloaded the Mac binary. I get the following error when I run ./cling.

Any help is appreciated.

Regards,
Richard Catlin

SDGL11fd4f1cb:bin rcatlin1$ ./cling
ExecutionContext: use of undefined symbol
'_ZN5cling7runtime8internal21__trigger__cxa_atexitD1Ev'!
ExecutionContext::runStaticInitializersOnce: symbol
'_ZN5cling7runtime8internal21__trigger__cxa_atexitD1Ev' unresolved while
linking static initializer '_GLOBAL__I_a'!
In file included from -:1:
input_line_3:1:45: error: no type named 'Interpreter' in namespace 'cling';
did you mean '::cling::Interpreter'?
namespace cling {namespace runtime { cling::Interpreter
*gCling=(cling::Interpreter*)140734543633080;} }
                                     ~~~~~~~^~~~~~~~~~~
                                            ::cling::Interpreter
Stack dump:
0. input_line_3:1:45: current parser token 'Interpreter'
1. input_line_3:1:1: parsing namespace 'cling'
2. input_line_3:1:18: parsing namespace 'runtime'
Segmentation fault: 11

Hi Richard,
   I have filed a bugreport: [ROOT-5212] Cling binary releases - SFTJIRA
   Please build cling from source, until that issue is fixed.
Cheers,
Vassil

Vassil,

I tried to build from source also, but get this error. I tried both on Lion and Mountain Lion. I am using the svn repo for llvm, clang. Here is the error below. I am attaching the configure log file also.

Any idea? I am really anxious to try cling, as an LLVM developer. I use LLVM as the runtime for a DSL.

Thank you.
Richard Catlin

llvm[4]: Compiling ParseDecl.cpp for Debug+Asserts build
llvm[4]: Compiling ParseDeclCXX.cpp for Debug+Asserts build
llvm[4]: Compiling ParseExpr.cpp for Debug+Asserts build
llvm[4]: Compiling ParseExprCXX.cpp for Debug+Asserts build
llvm[4]: Compiling ParseInit.cpp for Debug+Asserts build
llvm[4]: Compiling ParseObjc.cpp for Debug+Asserts build
llvm[4]: Compiling ParseOpenMP.cpp for Debug+Asserts build
llvm[4]: Compiling ParsePragma.cpp for Debug+Asserts build
llvm[4]: Compiling ParseStmt.cpp for Debug+Asserts build
llvm[4]: Compiling ParseTemplate.cpp for Debug+Asserts build
llvm[4]: Compiling ParseTentative.cpp for Debug+Asserts build
llvm[4]: Compiling Parser.cpp for Debug+Asserts build
/Users/rcatlin1/cling-dev/llvm/tools/clang/lib/Parse/Parser.cpp:548:39: error: variable has incomplete type ‘clang::DestroyTemplateIdAnnotationsRAIIObj’
DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
^
/Users/rcatlin1/cling-dev/llvm/tools/clang/lib/Parse/…/…/include/clang/Parse/Parser.h:48:9: note: forward declaration of ‘clang::DestroyTemplateIdAnnotationsRAIIObj’
class DestroyTemplateIdAnnotationsRAIIObj;
^
/Users/rcatlin1/cling-dev/llvm/tools/clang/lib/Parse/Parser.cpp:602:39: error: variable has incomplete type ‘clang::DestroyTemplateIdAnnotationsRAIIObj’
DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
^
/Users/rcatlin1/cling-dev/llvm/tools/clang/lib/Parse/…/…/include/clang/Parse/Parser.h:48:9: note: forward declaration of ‘clang::DestroyTemplateIdAnnotationsRAIIObj’
class DestroyTemplateIdAnnotationsRAIIObj;
^
2 errors generated.
make[4]: *** [/Users/rcatlin1/cling-dev/build/tools/clang/lib/Parse/Debug+Asserts/Parser.o] Error 1
make[3]: *** [Parse/.makeall] Error 2
make[2]: *** [all] Error 1
make[1]: *** [clang/.makeall] Error 2
make: *** [all] Error 1

configure.log (24.4 KB)

configure.log (24.4 KB)

Vassil,

Thanks. I can now get to the Cling shell.

Regards,
Richard Catlin