cling goes public!

Hi,

We, the cling team, have announced cling, our C++ interpreter prototype! (note: its SVN repository has changed compared with the announcement email; see the build instructions)

To a large extend thanks to Vassil's impressive commitment, cling now behaves like a good C++ interpreter: it runs C++ code that's entered, and prints the results.

[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"
$ echo 'extern "C" const char* zlibVersion();
 zlibVersion()' | cling -lz
 
(const char * const) "1.2.3.4"

We have of course already added a few features that we liked from CINT - but cling is a completely new development, based on clang and llvm, a set of compiler libraries (to simplify the matter a bit :-) Vassil will present the innards of cling probably in October; I will post the slides here.

So what's special about cling? It's based on a production-grade compiler and it's designed taking decades of experience with CINT into account. And it doesn't need dictionaries! (Disclaimer: that does not mean that ROOT can do without, automatically. But that's our goal, of course.)

The next steps will be the ones most relevant for High Energy Physics: integration into ROOT (Paul is already working on that) and reloading of changed code (.x myCode.C, edit, .x myCode.C). That latter part is horrible for a compiler.

If you want to check cling out you can simply compile it yourself - it's really easy. I'd love to have an interactive, web-based interface once, but an online C++ interpreter is an invitation for script kiddies to hack the server :-( If you have an idea how to do it please let me know!

Cheers,
Axel

cling vs alternatives

Hi, How you would briefly compare cling with alternative projects: Ceemple, Julia, chaiscript ? Thanks, Vladimir

Re: cling vs alternatives

Hi Vladimir,

Well, cling for for C++, to begin with :-) You're welcome to do a proper comparison and post the link here!

Cheers, Axel

Is it possible to redefine

Is it possible to redefine (unload or clean) functions, variables and classes in cling interpretator?

Re: unloading

Hi Andrey,

Thanks for your question! Yes, since recently you can undo declarations; ".undo 2" reverts the two previous declarations.

Cheers, Axel.

windows support

Is there any progress to support Windows ?

Re: Windows support

Hi Vladimir,

Some progress on the clang side, but fundamental things still didn't work last time we tried. I will definitely post once Windows support is there!

Cheers, Axel.

C scripting for Windows until C++ scripting will be available

Is it possible to have fully working C only version for Windows until Clang will properly support Windows C++ ? I mean C scripting from VS C++ ...

Re: C scripting for Windows

Hi Vladimir,

Brilliant idea! Like that it's not useful for ROOT and we cannot run the cling test suite - but at least we can build it! Watch the commit logs for updates - but I suspect that this will not arrive for another month... we are approaching an integration deadline for ROOT and a conference is coming up.

Thanks again for your suggestion!

Cheers, Axel.

Safety idea

There is a similar project called geordi-prime, it's a haskell-based c++ eval irc bot. The only difference is that it cannot keep state. Anyway, it's publicly available on freenode irc (and countless copies are available elsewhere) and it seems its safety measures are more than enough for irc wannabe hackers. The web-based cling could use the same idea to make sure its safe.

The webpage of geordi-prime: http://www.eelis.net/geordi/

Cling is really great !!! I

Cling is really great !!!

I was able to integrate it in my System on Windows and not I can use C++11 interactively.


Unfortunately there are still some problems with it.
If I try to do following:

#include "my_header.h"


and header includes some other headers that Cling can not find then it will
CRASH in ASTNodeEraser.cpp .

Re: cling on Windows

Hi Devid,

Thanks for trying it out! As we said quite a few times already: cling is not supported on Windows yet. I'm surprised it even starts up. Sorry. This is only going to change next year. We do welcome patches even before, though!

Cheers, Axel

Problem interpreting a function

Hello, I've successfully compiled Cling on Mac OSX and seems to work for simple C++ expressions. However when I try to create a C++ function I have a strange error:
[cling]$ void ff() {
[cling]$ ?   int mm;
[cling]$ ?   mm = 5;
[cling]$ ?   }
input_line_4:2:11: error: expected ';' at end of declaration
 void ff() {
          ^
          ;
[cling]$
This is expected behaviour or am I doing something wrong ?

Use .rawInput

Hi,

The preparseing doesn't work yet and defining a function should happen with the meta command:

[cling]$.rawInput
[cling]! void ff() {
[cling]! ?   int mm;
[cling]! ?   mm = 5;
[cling]! ?   }
[cling]$.rawInput

Vassil

build time of cling

Hello, The statement "If you want to check cling out you can simply compile it yourself - it's really easy." sounds interesting ... but the time to build cling is extremely high. It takes round about 12h on dual core machine (2.2 Ghz) ! Is there a way to get a binary version for i386 LINUX ? --Armin

Re: Build time

Hi Armin,

No way does it take 12h, something must be terribly wrong with your setup. It should take < 30 minutes even on a laptop. Nevertheless you can pick up a binary version of cling here: https://ecsft.cern.ch/dist/cling Don't be scared by the invalid SSL certificate: it's the best CERN can give to us...

Cheers, Axel

clang/cling for Windows 32/64 - is there any progress ?

Is there any progress in supporting Windows 32/64 by clang/cling ? I cannot wait when I could start with cling on Windows platform :-)

Re: Win progress

Hi Vladimir,

Not that I am aware of. We will only get to that next year - unless someone else contributes patches before.

Cheers, Axel.

minor windoze build issue

is the export definition outdated? _ZN4llvm11raw_ostream5writeEPKc* -> _ZN4llvm11raw_ostream5writeEPKcj _ZN4llvm5APInt12initSlowCaseEj* -> _ZN4llvm5APInt12initSlowCaseEjyb _ZTVN4llvm16JITEventListenerE -> _ZN4llvm16JITEventListenerD2Ev _ZN4llvm15SmallVectorBase8grow_podE* -> _ZN4llvm15SmallVectorBase8grow_podEjj dunno about * but gcc refuse that and when build llvm as shared library, cling throw local_cxa_atexit symbol unresolved or something during startup. static library of llvm doesn't cause this

Re: minor windoze build issue

Hi,

Okay, so you are building with GCC on Windows - which one, MingW or cygwin? None of that has ever been tried to my knowledge, and it's unfortunate that the linker doesn't cope with the exports table.

The local_cxa_atexit symbol might not even be needed when building with GCC. Could you open a bug report at https://savannah.cern.ch/bugs/?func=additem&group=savroot? I cannot promise that this will get fixed soon, foryhour configuration, but I would nonetheless like to have a reminder that this issue exists.

For now you are much better off building cling on Linux or MacOS. Take a virtual machine and off you go!

Cheers, Axel

I'm sorry but i'm total noob

I'm sorry but i'm total noob at linux Axel :) I dunno why, everytime i try linux it took less than a day to make me revert to windoze XP :D I use gcc 4.6.3 mingw/msys. you mean that wildcard supposed to resolved by the gcc's linker?

Re: mingw build

Hi,

Sorry - if you cannot get it to work on Windows yourself you're out of luck for now... We will attack cling on Windows only next year.

Cheers, Axel.

Hi Axl, I build latest cling

Hi Axl, I build latest cling for windows, apparently load module .L doesn't work as expected (in the example) [cling]$ .L libz input_line_6:1:10: fatal error: 'libz' file not found #include "libz" Load file failed. I have put zlib.dll zlib.dll.a zlib.a in current folder. Even set LLVM_LIB_SEARCH_PATH doesn't help. More importantly why it treated as #include "libz"? Thank you Axl, cling is great for learning!

Re: libz on Windows

Hi,

"zlib" and "libz" are not the same words :-) Try to rename it to libz.dll, or try .L zlib. And please remember that Windows support is still limited for cling due to clang not fully supporting the Windows C++ API yet.

I'm happy to hear that you like cling, even though you take the rocky Windows road!

Cheers, Axel

This time I tried diagnose it

This time I tried diagnose it with filemon (lowlevel filesystem API monitoring), cling first try exact keyword, then add prefix lib and suffix .a if not found if I use .L libz and cling found static/import library it will complain "Bad image" so I assume it's libz.dll that asked? tried .L zlib.dll and cling found it but throw http://pastebin.com/wZMixLfs

Re: Windows dlopen

Hi,

Sorry, we'll be able to help with the Windows build only next year.

Cheers, Axel.

Syntax Error

After I use the make command in the build directory I get this error. I am trying to compile cling. SyntaxError: invalid syntax make[2]: Entering directory `/home/ryan/Documents/build/tools/cling' llvm[2]: Updating Makefile make[2]: Leaving directory `/home/ryan/Documents/build/tools/cling' svn: '/home/ryan/Documents/llvm' is not a working copy File "", line 1 if >= : print "skip" ^ Any help would be appreciated. Thank You.

Re: Syntax Error

Hi,

Can you submit a bug report at https://savannah.cern.ch/bugs/?func=additem&group=savroot, giving the full build log and the output of "svn diff /home/ryan/Documents/llvm"? My suspicion in that you moved / renamed directories after configuring...

Cheers, Axel

clang++

I have built clang/llvm but clang++ doesnt seem to work and i think it could potentially be due to the fact that clang++ only works with mac os as far as i know..could i still run cling if clang++ doesnt work...just to clarify clang works perfectly and it compiles my c code flawlessly just clang++ doesnt work. I am using ubuntu 10.04 Thanks!

Actually clang++ works just

Actually clang++ works just fine on Linux, have a look at this article: http://solarianprogrammer.com/2011/10/16/llvm-clang-libc-linux/

Re: clang++

Hi,

Please discuss clang issues at the clang mailing list cfe-dev@cs.uiuc.edu.

Cheers, Axel.

"LastKnownGoodSVNRevision" of cling for ROOT?

Hello, since i get some errors both during linking (of rootcling_tmp; gives undefined symbol _ZTVN5clang13PragmaHandlerE, though libCling.so is on the path) and compiling (no matching function for call to ‘cling::Interpreter::createUniqueName()’) of ROOT with cling enabled, is it possible to have smth similar to cling's LastKnownGoodLLVMSVNRevision.txt in ROOT?
i.e. some way of telling which revision of Cling does the currently checked-out ROOT revision compile (and link) with?

cheers,
Constantin

Re: cling and ROOT

Hi Constantin!

Thanks for your question. cling is now distributed as part of ROOT, so there cannot be any revision mismatch.

I have updated the build instructions - maybe it's now clearer that one should not build cling next to clang if using ROOT. And I assume that's what's happening in your case, because you seem to have an old libCling used by a new rootcling.

Also, please submit bug reports like this to Savannah, that help's us triaging them properly. Thanks!

Cheers, Axel

osx link issue

Any help much appreciated: llvm[4]: Linking Debug+Asserts Shared Library libcling.dylib Undefined symbols: "llvm::APInt::initSlowCase(unsigned int, unsigned long, bool)", referenced from: -exported_symbol[s_list] command line option "cling::Interpreter::executeFile(std::basic_string, std::allocator > const&)", referenced from: -exported_symbol[s_list] command line option

Re: link issue

Hi,

Thanks for your report - should be fixed! But please future report bugs at our bug tracker.

Cheers, Axel.

Thanks for the fix. I'll use

Thanks for the fix. I'll use your bug tracker in the future. I wasn't certain that it was a bug and not just something missing on my end. I still get one undefined symbol with latest SVN: "cling::Interpreter::createUniqueName()", referenced from: -exported_symbol[s_list] command line option

Re: bug tracker

Hi,

Thanks for your reports; these things just happen because we still haven't integrated cling into our continuous integration system. I assume it was you who submitted this as a bug on savannah, that's really helpful, thanks a lot!

Cheers, Axel

osx link issue

What would cause this after clang builds fine: llvm[4]: Linking Debug+Asserts Shared Library libcling.dylib Undefined symbols: "llvm::APInt::initSlowCase(unsigned int, unsigned long, bool)", referenced from: -exported_symbol[s_list] command line option "cling::Interpreter::executeFile(std::basic_string, std::allocator > const&)", referenced from: -exported_symbol[s_list] command line option "cling::Interpreter::loadFile(std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const*, bool)", referenced from: -exported_symbol[s_list] command line option "cling::MetaProcessor::process(char const*)", referenced from: -exported_symbol[s_list] command line option (maybe you meant: cling::MetaProcessor::process(char const*, cling::Value*))

Re: link issue

Hi,

Thanks for your report - should be fixed! But please future report bugs at our bug tracker.

Cheers, Axel.

cling.exe hangs up ...

I use win32 compiled cling.exe, it hangs up in the simplest cases: int i=1; - OK int i=1 - without ";" - hangs up ++i; - OK ++i - hangs up #include "stdio.h" - OK #include "math.h" - hangs up #include "math_not_exist.h" - OK, informs about error What going wrong in these cases ? Thanks, Vladimir

Re: cling on Windows

Hi Vladimir,

Thanks for your report! C++ on Windows is still only rudimentary supported by clang. And cling depends on clang. The available features have already much improved over the last few months - but e.g. the ValuePrinter template instantiation (needed to print the value of the expression when omitting the ';') still causes an infinite loop on Windows. That's Vassil's diagnosis.

As templates are pretty fundamental for C++, and as work on the Windows C++ ABI has been picked up recently, there is hope that this will get fixed in the near future. We at CERN also need cling to work on Windows...

On Windows, today, cling should work in C-mode (cling -x c).

Cheers, Axel

Hi Axel, I'm a bit confused.

Hi Axel, I'm a bit confused. Please clarify what options I have now to use cling in production win application ? As far as I understood in both win32 and win64 cases I can use C language only (until clang will fully support C++ in win32 and win64). It means that I should write C wrappers for C++ DLLs and any C++ code that I want to embed ? Another critical issue, you wrote that there is a critical bug that will be fixed in the nearest 4 weeks - cling sometimes crashes in the end of parsing... Is it applicable for win32/win64 C too ? Thanks, Vladimir

Re: cling on Windows

Hi Vladimir,

As I said, I expect cling on Windows to only work in C mode for the time being. The other bug will affect cling on Windows, too, whether C mode or not - it's about input buffer handling which is the same everywhere. I hope that clarifies the situation. As it is right now I would not recommend cling for production use on Windows. But I cannot predict how long it will take clang to support (most of) Windows C++ ABI: could be months, could be days.

Cheers, Axel

"using namespace std" and c++11 lambdas don't work?

On MacOSX 10.6.8, on on llvm/clang svn r150068; on cling svn r43013, with the patch below to cling/lib/Interpreter/DynamicLookup.cpp:419 to get compilation, I'm getting a crash when I do "using namespace std".
$ ./cling
**** Welcome to the cling prototype! ****
* Type C code and press enter to run it *
* Type .q, exit or ctrl+D to quit       *
*****************************************
[cling]$ #include iostream   // NB: the html wouldnt let me send angle brackets around iostream, but they were there!
[cling]$ using namespace std;
Declaration name has no FETokenInfo
UNREACHABLE executed at DeclarationName.cpp:339!
Illegal instruction

$ cd ~/pkg/llvm-post-3.0-svn/llvm/tools/cling/lib/Interpreter

# patch previously mentioned... to get compilation.
$ svn diff
Index: DynamicLookup.cpp
===================================================================
--- DynamicLookup.cpp	(revision 43039)
+++ DynamicLookup.cpp	(working copy)
@@ -416,7 +416,7 @@
           // resolution of the constructors and then initializes the new
           // variable with it
 	  ExprResult InitExprResult 
-	    = m_Sema->ActOnParenListExpr(m_NoSLoc,
+	    = m_Sema->ActOnParenOrParenListExpr(m_NoSLoc,
 					 m_NoELoc,
 					 move_arg(Inits));
           m_Sema->AddInitializerToDecl(HandlerInstance,


...also the C++11 lambda feature doesn't seem to work; any clue why? (see below for example)

Thanks!

Jason

$  ./cling -Wc++11-extensions

**** Welcome to the cling prototype! ****
* Type C code and press enter to run it *
* Type .q, exit or ctrl+D to quit       *
*****************************************
[cling]$ #include 
[cling]$ using std::cout
[cling]$ auto func = [] () { cout << "Hello world"; };
input_line_6:2:2: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
 auto func = [] () { cout << "Hello world"; };
 ^
input_line_6:2:14: error: expected expression
 auto func = [] () { cout << "Hello world"; };
             ^
[cling]$ 

Re: using namespace std

Hi Jason,

I have converted your comment into this bug report. Thanks! Note that it does work if you toggle to .rawInput for the using directive using namespace std; - but that's just a woraround.

The mismatch in DynamicLookup.cpp should get fixed later.

Cheers, Axel

Re: Lambda expressions

Hi Jason,

Thanks for your feedback; the compilation problem will get fixed today!

Regarding the lambda, you first need to enable the C++11 standard (you just enabled a warning kind):

$ cling -std=c++11
[cling]$ #include <iostream>
[cling]$ auto func = [] () { std::cout << "Hello world"; };
input_line_5:2:14: error: lambda expressions are not supported yet
 auto func = [] () { std::cout << "Hello world"; };
             ^
Now if you look at the implementation status of lambdas in clang you will see that this is expected. If you want, help the clang guys implement it and we will all benefit from it! :-)

Cheers, Axel

small adjustment needed to compile DynamicLookup.cpp

A quick patch suggestion: Using what seemed to be the latest cling (svn 43039), and the llvm/clang svn r150068 named in LastKnownGoodLLVMSVNRevision.txt, I had to make the following change to the file cint/cling/lib/Interpreter/DynamicLookup.cpp in order to get compilation:

Regards,
Jason

svn diff

=====================
--- DynamicLookup.cpp   (revision 43039)
+++ DynamicLookup.cpp   (working copy)
@@ -416,7 +416,7 @@
           // resolution of the constructors and then initializes the new
           // variable with it
          ExprResult InitExprResult
-           = m_Sema->ActOnParenListExpr(m_NoSLoc,
+           = m_Sema->ActOnParenOrParenListExpr(m_NoSLoc,
                                         m_NoELoc,
                                         move_arg(Inits));
           m_Sema->AddInitializerToDecl(HandlerInstance,



svn info
Path: .
URL: http://root.cern.ch/svn/root/trunk/cint/cling/lib/Interpreter
Repository Root: http://root.cern.ch/svn/root
Repository UUID: 27541ba8-7e3a-0410-8455-c3a389f83636
Revision: 43039
Node Kind: directory
Schedule: normal
Last Changed Author: vvassilev
Last Changed Rev: 42986
Last Changed Date: 2012-02-13 13:20:45 -0600 (Mon, 13 Feb 2012)

Re: trunk

Hi Jason,

Thanks to Vassil this is now fixed, including a proper llvm / clang revision number that works. Again, thanks for your report!

Cheers, Axel

Multi-line mode

I think cling multi-line mode could be less clever, enough to have the following: Enter - expression is fully entered Enter+Shift - expression will be continued in the next line Enter and Enter+Shift - used widely in editors so user is familiar with them

Re: multi-line mode

Hi Vladimir,

Thanks for your suggestion! Another option would be start editor-like behavior, where one moves up and down with the cursor keys, until one sends off the input using shift- or ctrl-enter. What do you think?

Note: this is just brainstorming - I'm not claiming that we have the time to implement it in 2012 :-) But if somebody is looking for something to contribute then this could be a nice extension!

Cheers, Axel

I think cling standalone is

I think cling standalone is mainly for evaluating and studying cling before making decision to use it ? Everybody can wrap cling API with rich editor in some way. So, if I understand cling usage correctly, it could be simple as possible with intuitive commands that don't require long explanations so all set of available commands could be printed in the welcome part. Generally current set of commands seem OK, especially I like the last ";" - print/don't print results. There is only 1 problematic thing - multi-line mode, I think Enter / Enter+Shift is the simplest solution from usability point of view.