Author Topic: Cling C++ Interpreter/Debugger  (Read 5091 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Cling C++ Interpreter/Debugger
« on: November 07, 2013, 02:09:13 AM »
Before installing CINT on the All BASIC Cloud9 IDE, I built the current preproduction (6.0) version of CERN ROOT on my Utbuntu 12.04 LTS 64 bit laptop. It took about an hour to build. I have never built anything this big before. Gambas held the record until CERN ROOT CINT. ROOT is more than just a C/C++ interpreter. It has data modelling functions with a GUI canvas. (X11 based) Back to the reason for the post. I'm happy to announce that AIR's C++ BASIC (ccpbas) works with ROOT interpretively.

Code: [Select]
jrs@laptop:~/C_BASIC/cppbasic$ root
  *******************************************
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   5.99/03  9 September 2013   *
  *                                         *
  *  You are welcome to visit our web site  *
  *          http://root.cern.ch            *
  *                                         *
  * !!! THIS IS A PREPRODUCTION VERSION !!! *
  * Please use 5.34 for any real work until *
  * ROOT 6 is released.                     *
  *                                         *
  *******************************************

ROOT 5.99/03 (heads/master@v5-99-03-01-661-ge3f3248, Nov 05 2013, 14:54:36 on linuxx8664gcc)
cling C/C++ Interpreter: type .? for help.
root [0] .?
Cling meta commands usage
Syntax: .Command [arg0 arg1 ... argN]

.q - Exit the program
.L <filename> - Load file or library
.(x|X) <filename>[args] - Same as .L and runs a function with signature ret_type filename(args)
.I [path] - Shows the include path. If a path is given -
adds the path to the include paths
.@ - Cancels and ignores the multiline input
.rawInput [0|1] - Toggle wrapping and printing the execution
results of the input
.dynamicExtensions [0|1] - Toggles the use of the dynamic scopes and the late binding
.printAST [0|1] - Toggles the printing of input's corresponding AST nodes
.help - Shows this information
root [1] .L demo.cpp
In file included from -:1:
In file included from input_line_16:1:
In file included from /home/jrs/C_BASIC/cppbasic/demo.cpp:2:
./cppbas.inc:42:9: warning: 'ADDRESS' macro redefined
#define ADDRESS &
        ^
/home/jrs/C_BASIC/root/include/mmprivate.h:113:9: note: previous definition is here
#define ADDRESS(B) ((PTR) (((B) - 1) * BLOCKSIZE + mdp -> heapbase))
        ^
root [2] CSTRING mystring = "This is a string.";
root [3] PRINT (LEFT$(mystring,4));
This
root [4] PRINT (RIGHT$(mystring,7));
string.
root [5] PRINT (MID$(mystring,5,4));
is a
root [6] PRINT (STR$(INSTR(mystring,"is")));
2
root [7] PRINT (LCASE$(mystring));
this is a string.
root [8] PRINT (UCASE$(mystring));
THIS IS A STRING.
root [9] PRINT (MCASE$(mystring));
This Is A String.
root [10] PRINT (LTRIM$("    This should not have leading spaces    "));
This should not have leading spaces   
root [11] PRINT (RTRIM$("    This should not have any trailing spaces    "));
    This should not have any trailing spaces
root [12] PRINT (TRIM$("    This should not have any leading or trailing spaces     "));
This should not have any leading or trailing spaces
root [13] PRINT (SPLITPATH$("/Users/riveraa/myfile.txt",4));
/Users/riveraa
root [14] PRINT (SPLITPATH$("/Users/riveraa/myfile.txt",8));
myfile
root [15] PRINT (SPLITPATH$("/Users/riveraa/myfile.txt",12));
/Users/riveraa/myfile
root [16] PRINT (SPLITPATH$("/Users/riveraa/myfile.txt",16));
txt
root [17] PRINT (REVERSE$(mystring));
.gnirts a si sihT
root [18] PRINT ( REPLACE$(mystring,"string","Number") );
This is a Number.
root [19] .q
jrs@laptop:~/C_BASIC/cppbasic$

I thought I would give shot at fixing the ADDRESS conflict warning and change the following (unused) #define in his program.

#define ADDR &

Code: [Select]
jrs@laptop:~/C_BASIC/cppbasic$ root
  *******************************************
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   5.99/03  9 September 2013   *
  *                                         *
  *  You are welcome to visit our web site  *
  *          http://root.cern.ch            *
  *                                         *
  * !!! THIS IS A PREPRODUCTION VERSION !!! *
  * Please use 5.34 for any real work until *
  * ROOT 6 is released.                     *
  *                                         *
  *******************************************

ROOT 5.99/03 (heads/master@v5-99-03-01-661-ge3f3248, Nov 05 2013, 14:54:36 on linuxx8664gcc)
cling C/C++ Interpreter: type .? for help.
root [0] .L demo.cpp
root [1] PRINT (UCASE$("it worked!"));
IT WORKED!
root [2] .q
jrs@laptop:~/C_BASIC/cppbasic$

« Last Edit: November 13, 2013, 08:39:38 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: Cling C++ Interpreter/Debugger
« Reply #1 on: November 07, 2013, 02:50:37 AM »
I thought I would try combining AIR's two include files and call it cppbasic.h. My test worked.

Code: [Select]
jrs@laptop:~/C_BASIC/cppbasic$ root
  *******************************************
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   5.99/03  9 September 2013   *
  *                                         *
  *  You are welcome to visit our web site  *
  *          http://root.cern.ch            *
  *                                         *
  * !!! THIS IS A PREPRODUCTION VERSION !!! *
  * Please use 5.34 for any real work until *
  * ROOT 6 is released.                     *
  *                                         *
  *******************************************

ROOT 5.99/03 (heads/master@v5-99-03-01-661-ge3f3248, Nov 05 2013, 14:54:36 on linuxx8664gcc)
cling C/C++ Interpreter: type .? for help.
root [0] .L cppbasic.h
root [1] PRINT (UCASE$("it worked with cppbasic.h"));
IT WORKED WITH CPPBASIC.H
root [2] .q
jrs@laptop:~/C_BASIC/cppbasic$
« Last Edit: November 13, 2013, 08:39:24 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: Cling C++ Interpreter/Debugger
« Reply #2 on: November 07, 2013, 03:55:19 AM »
As I get more into the CERN ROOT project it seems that CINT is being replace with Cling in the upcoming ROOT 6.0 version. Here is their What's Up announcement. I'm excited about the C++ BASIC interactive interpreter/debugger features ROOT brings to our project. I hope this encourages AIR and others to forge on with the C++ BASIC (cppbas) project AIR is developing.

Quote
So when are we going to release ROOT 6? Where are we? Core parts now work completely without CINT: dictionaries are built from the information extracted by clang and thus I/O does not rely on details provided by CINT anymore. TInterpreter is migrated almost completely. Those are major chunks. But we have still have a few details that need to be fixed before we can remove CINT (and Reflex and Cintex) from the repositor. We need one major piece of work before we can release ROOT 6.0.0 (related to clang::Modules).

Then we have to make a cut: what do we really, really need in ROOT 6.0.0, what can wait until ROOT 6.2? Complete error recovery from bogus input? Likely only "to a large extent". Unloading? Likely only in ROOT 6.2. Performance improvements to demonstrate that we can do better than with CINT? Likely only in ROOT 6.2. PyROOT? Definitely in ROOT 6.0.0! We might have to remove features that many see as essential, for instance void f() {gSystem->Load("libEvent"); Event* e = new Event();} Some of these features might come back after ROOT 6.0.0, some of them are the price we pay for having a proper compiler read your code.

Working with ROOT-with-cling over the past months tells me that going to clang + llvm was the right thing to do: it is a major improvement for ROOT, in many, many respects. A nice side effect is that we reduce the amount of "our" code from about 300k (CINT, Cintex, Reflex, rootcint, TCint) to 30k (cling, rootcling, TCling)! But it's wonderful to be able to write any C++ code, not the CINT subset. To use the C++11 "auto". To get error messages that are immediately understandable. I'm positive that you will enjoy ROOT 6, too!
« Last Edit: November 13, 2013, 08:39:08 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: Cling C++ Interpreter/Debugger
« Reply #3 on: November 07, 2013, 04:39:51 AM »
For those (like myself) that aren't smashing atoms, Cling (C++ Interpreter) can be used with C++ BASIC (JADE).

Code: [Select]
jrs@laptop:~/C_BASIC/cppbasic$ cling

****************** CLING ******************
* Type C++ code and press enter to run it *
*             Type .q to exit             *
*******************************************
[cling]$ .L cppbasic.h
[cling]$ PRINT (UCASE$("cppbas works with cling"));
CPPBAS WORKS WITH CLING
[cling]$ .q
jrs@laptop:~/C_BASIC/cppbasic$
« Last Edit: November 13, 2013, 08:38:54 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: Cling C++ Interpreter/Debugger
« Reply #4 on: November 13, 2013, 05:18:33 PM »
I thought I would give the JADE demo.cpp example a try in CLING.

Code: [Select]
jrs@laptop:~/C_BASIC/JADE$ cling

****************** CLING ******************
* Type C++ code and press enter to run it *
*             Type .q to exit             *
*******************************************
[cling]$ .L demo.cpp
[cling]$ main(0,0);
LEFT(mystring,4)
This

MID$(mystring,5,4)
is a

RIGHT$(mystring,7)
string.

INSTR(mystring,"is")
2

LCASE$(mystring)
this is a string.

UCASE$(mystring)
THIS IS A STRING.

MCASE$(mystring)
This Is A String.

LTRIM$, RTRIM$, TRIM$
This should not have leading spaces   
    This should not have any trailing spaces
This should not have any leading or trailing spaces

SPLITPATH$(/Users/riveraa/myfile.txt,4)
/Users/riveraa
SPLITPATH$(/Users/riveraa/myfile.txt,8)
myfile
SPLITPATH$(/Users/riveraa/myfile.txt,12)
/Users/riveraa/myfile
SPLITPATH$(/Users/riveraa/myfile.txt,16)
txt

REVERSE$(mystring)
.gnirts a si sihT

REPLACE$(mystring,"string", "Number"
This is a Number.

VAL("123") + 10
133

LOADFILE$()

SAVEFILE()
Contents saved to 'output.txt'
[cling]$ .q
jrs@laptop:~/C_BASIC/JADE$
« Last Edit: November 13, 2013, 08:38:38 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: Cling C/C++ Interpreter/Debugger
« Reply #5 on: November 13, 2013, 07:36:24 PM »
I was pleasantly surprised to see CLING work with my C BASIC example. (cb.c) If CLING supports C code, maybe the CLING output from Charles's Test.c is meaningful.

Naumann Cling (Cling introduction)

Current CLING binary downloads

Code: [Select]
jrs@laptop:~/C_BASIC/cintbasic$ cling

****************** CLING ******************
* Type C++ code and press enter to run it *
*             Type .q to exit             *
*******************************************
[cling]$ .L cb.c
[cling]$ main();
1
2
3
4
5
x is now 6
My guess is 6
6
Double it up
[cling]$ .q
jrs@laptop:~/C_BASIC/cintbasic$

Good News!

ROOT 6.0 (w/CLING) works with my cb.c example as well.

Code: [Select]
jrs@laptop:~/C_BASIC/cintbasic$ root
  *******************************************
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   5.99/03  9 September 2013   *
  *                                         *
  *  You are welcome to visit our web site  *
  *          http://root.cern.ch            *
  *                                         *
  * !!! THIS IS A PREPRODUCTION VERSION !!! *
  * Please use 5.34 for any real work until *
  * ROOT 6 is released.                     *
  *                                         *
  *******************************************

ROOT 5.99/03 (heads/master@v5-99-03-01-661-ge3f3248, Nov 05 2013, 14:54:36 on linuxx8664gcc)
cling C/C++ Interpreter: type .? for help.
root [0] .L cb.c
root [1] main();
1
2
3
4
5
x is now 6
My guess is 6
6
Double it up
root [2] .?
Cling meta commands usage
Syntax: .Command [arg0 arg1 ... argN]

.q - Exit the program
.L <filename> - Load file or library
.(x|X) <filename>[args] - Same as .L and runs a function with signature ret_type filename(args)
.I [path] - Shows the include path. If a path is given -
adds the path to the include paths
.@ - Cancels and ignores the multiline input
.rawInput [0|1] - Toggle wrapping and printing the execution
results of the input
.dynamicExtensions [0|1] - Toggles the use of the dynamic scopes and the late binding
.printAST [0|1] - Toggles the printing of input's corresponding AST nodes
.help - Shows this information

root [3] .q
jrs@laptop:~/C_BASIC/cintbasic$
« Last Edit: November 13, 2013, 10:20:47 PM by John »