Giter Site home page Giter Site logo

herrgahr / qling Goto Github PK

View Code? Open in Web Editor NEW
81.0 17.0 11.0 1.85 MB

Qt interface for cling

License: GNU General Public License v3.0

C 34.79% C++ 43.80% Objective-C 0.03% Shell 0.20% Fortran 20.72% Python 0.14% CSS 0.26% IDL 0.02% Assembly 0.04%

qling's Introduction

Qling, the Qt interface for cling

This is a simple Qt interface for cling, the llvm-based C++ interpreter

It is at an early stage and definitely needs some love.

Compiling

First you need to install llvm, clang and cling from SVN. Follow the instructions at http://root.cern.ch/drupal/content/cling-build-instructions

Install it to some folder, either system wide or somewhere in your home (speficy via the --prefix option to llvm's configure-script).

Enter qling's subdirectory "qt-hack" and compile qatomic_sun.s (see Notes for explanation):

$ cd qt-hack
$ as qatomic_sun.s -o qatomic_sun.o
$ cd ..

After you've done this:

$ export LLVM_INSTALL=/dir/that/you/specified/as/llvm/install/prefix
$ qmake
$ make

and

$ ./qling

to start

Usage

Qling's main window consists of a text area that displays the code entered so far, a line edit for entering code line by line and a console-output. Enter the following example snippets at the line edit line by line: TODO: explain the differences between a .cpp file and the interpreter prompt...

Hello, world!

#include <iostream>
std::cout<<"Hello, world!"<<std::endl;

Interact with qling itself

qling's main window is made available to the interpreter as the global "MainWindow& qling". Of course MainWindow inherits QWidget. So the simplest example is closing qling:

qling.close();

Create a simple widget

QWidget w;
w.show();
w.setWindowTitle("Hello, interpreted C++ World");

Create a dock-widget in qling's main window

#include <QLabel>
#include <QDockWidget>
QLabel* label=new QLabel("TestDock-content");
QDockWidget* dynDock=new QDockWidget;
dynDock->setWidget(label);
dynDock->setWindowTitle("DynDock");
qling.addDockWidget(Qt::RightDockWidgetArea,dynDock);
//your qling window should now have an additional dock
//let's undock it:
dynDock->setFloating(true);
//and dock it again:
dynDock->setFloating(false);

Multi-line input

In multi-line mode, you can comfortably enter longer chunks of code and submit it in one go. If multi-line mode is active, the key actions to move in the history and submit code are only triggered when Ctrl is held. so Ctrl+KeyUp and Ctrl+KeyDown move in history, Ctrl+Enter submits code. So you can do stuff like this more naturally:

#include <QPushButton>
#include <QVBoxLayout>
QWidget* w=new QWidget;
QVBoxLayout* l=new QVBoxLayout(w);
QPushButton* b=new QPushButton("close");
l->addWidget(b);
QObject::connect(b,SIGNAL(clicked()),w,SLOT(close()));
w->setMinimumSize(300,300);
w->show();

...hit Ctrl+Enter and happlily look at your new widget... To make the window pop back up after you close it by pushing the button, we can use this (nonsical) hack: Instantiate a QObject-subclass with a timerEvent that calls w->show() every 1000msec.

#include <QTimerEvent>
struct T:public QObject{
T():m_timerId(startTimer(1000)){}
int m_timerId;
void timerEvent(QTimerEvent* e){
if(e->timerId()!=m_timerId)return;
w->show();
}
} timerInstance;

...and hit Ctrl+Enter again.

Notes

Inline assembly and the JIT

At the moment, llvm's JIT does not support inline assembler, which is needed for Qt's atomic stuff. For this reason there is a folder qt-hack, which includes modified qatomic-headers that #ifdef the inline asm away and cause the compiler to use the non-inline functions provided by qatomic_sun.s instead. These inline-asm issues likely cause other libraries that you might want to use from within cling to make the app crash, as well. An example is Eigen3 - I do have a patched version of Eigen3, too but there is a more elegant way to go: Recently the "MC framework" has been included in llvm and MC's JIT does support inline assembly. Unfortunately cling needs to be patched to make use of that and I have not yet been successful in making this work correctly - it segfaults atm which seems to be some JIT-memory-manager issue that I have yet to figure out. I have only spent ~1hour on this and then given up due to lack of time.

Credits

The core part of this program's functionality is provided by cling, which is developed at CERN. A big "thank you" goes out to Axel Naumann and Vassil Vassilev who've been providing me with help, tipps and support.

Have fun!

qling's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qling's Issues

Compile errors on qlinq.cpp

Hi,

I wasn't sure if this was still active, but I get a compilation error on qling.cpp

After first assembling ( as qatomic... ) , I am able to run the build after the following:

export LLVM_INSTALL=/usr/local
qmake-qt4
make

g++ -c -m64 -pipe -I/usr/local/include -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -O3 -fomit-frame-pointer -std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fPIC -ffunction-sections -fdata-sections -Wcast-qual -Wno-unused-parameter -Wno-strict-aliasing -std=c++11 -O2 -fno-omit-frame-pointer -g -Wall -W -D_REENTRANT -DLLVM_INSTALL="/usr/local/" -DQLING_BASE_DIR="/media/jdamon/Development/Documents/Projects/build_cling/qling-master" -DQT_NO_DEBUG -DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtWebKit -I/usr/include/qt4 -I/usr/local//../llvm/tools -I. -o main.o main.cpp
... (more with no problems)

g++ -c -m64 -pipe -I/usr/local/include -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -O3 -fomit-frame-pointer -std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fPIC -ffunction-sections -fdata-sections -Wcast-qual -Wno-unused-parameter -Wno-strict-aliasing -std=c++11 -O2 -fno-omit-frame-pointer -g -Wall -W -D_REENTRANT -DLLVM_INSTALL="/usr/local/" -DQLING_BASE_DIR="/media/jdamon/Development/Documents/Projects/build_cling/qling-master" -DQT_NO_DEBUG -DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtWebKit -I/usr/include/qt4 -I/usr/local//../llvm/tools -I. -o qling.o qling/qling.cpp
qling/qling.cpp:48:44: fatal error: cling/Interpreter/ValuePrinter.h: No such file or directory
#include "cling/Interpreter/ValuePrinter.h"

If I correct these by commenting them out, I get another error which is

qling/qling.cpp:100:19: error: 'class cling::Interpreter' has no member named 'getExecutionEngine'
m_interpreter.getExecutionEngine()->RegisterJITEventListener(&m_jitEventListener);
^
qling/qling.cpp: In member function 'void Qling::exportToInterpreter(const QObject&, const QString&)':
qling/qling.cpp:204:33: warning: cast from type 'const QObject_' to type 'void_' casts away qualifiers -Wcast-qual&obj, name);

I thought I would send this to you first before digging into it too much,

Error running qling compiled with root distributed cling

I compiled qling using cling from an exiting ROOT installation (obtained from git repository)

When I try running it I get this error:
./cling/Interpreter/RuntimeUniverse.h:26:10: fatal error: 'cling/Interpreter/RuntimeException.h' file not found

include "cling/Interpreter/RuntimeException.h"

     ^

input_line_2:1:45: error: no type named 'Interpreter' in namespace 'cling'
namespace cling {namespace runtime { cling::Interpreter gCling=(cling::Interpreter)140736718491952;} }
~~~~~~~^
...

It seems this error happens when the qling interpreter is instantiated (before calling Qling::init()). I checked the llvm_install path and it seems to be the same passed to the interpreter instance used by the root tool itself, which it's working properly

Any suggestions on what can be going wrong?
Thanks a lot.

Fail to compile, missing gdb

Hy!

I'm following your instructions to compile qling, and I'm getting.

WARNING: Failure to find: gdb/gdb.cpp
WARNING: Failure to find: gdb/gdb.h

I have installed qt4-qmake and gdb-dev to try to resolve the problem, but it didn't help. My llvm, cling and cland executables are all located in the home folder (ono is in usr/src or similar)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.