Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cling integration initial commit #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14)
project(quick-ftxui
LANGUAGES CXX
LANGUAGES C CXX
VERSION 0.1.0
)

Expand All @@ -9,6 +9,15 @@ set(CMAKE_CXX_STANDARD_REQUIRED 20)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_BUILD_TYPE Debug)

# ----------------- Cling stuff -----------------------------------------------

set(LLVM_NO_DEAD_STRIP 1)

find_package(Cling REQUIRED CONFIG)
#if(NOT DEFINED ENV{CLING_DIR})
# message(FATAL_ERROR "You must set CLING_DIR environment variable")
#endif()

# --- Fetch FTXUI --------------------------------------------------------------
include(FetchContent)

Expand Down Expand Up @@ -53,16 +62,21 @@ target_include_directories(quick-ftxui
PRIVATE include
PRIVATE ${Boost_INCLUDE_DIR}
PRIVATE ${ftxui_SOURCE_DIR}
PRIVATE ${Cling_DIR}/../../../include
)

target_link_libraries(quick-ftxui
PRIVATE ${Boost_LIBRARIES}
PRIVATE ftxui::screen
PRIVATE ftxui::dom
PRIVATE ftxui::component # Not needed for this example.
PRIVATE clingInterpreter
)

target_compile_options(quick-ftxui PRIVATE -fsanitize=address)
target_compile_options(quick-ftxui
PRIVATE -fsanitize=address
PUBLIC -DLLVM_DIR="${LLVM_INSTALL_PREFIX}" -I${LLVM_INSTALL_PREFIX}/include
)
target_link_options(quick-ftxui PRIVATE -fsanitize=address)

install(TARGETS quick-ftxui RUNTIME DESTINATION "bin")
11 changes: 11 additions & 0 deletions include/quick-ftxui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/util/ref.hpp" // for Ref

// Cling
#include <cling/Interpreter/Interpreter.h>
#include <cling/Interpreter/Value.h>
#include <cling/Utils/Casting.h>

#include <iostream>
#include <string>

Expand Down Expand Up @@ -111,6 +116,8 @@ void tab(int indent) {
struct component_meta_data {
ftxui::ScreenInteractive *screen;
ftxui::Components components;
cling::Interpreter *interp;
cling::Value *res;
};

struct ast_printer {
Expand Down Expand Up @@ -139,6 +146,10 @@ struct node_printer : boost::static_visitor<> {
if (text.func == "Exit") {
data->components.push_back(ftxui::Button(
text.placeholder, data->screen->ExitLoopClosure()));
} else {
data->interp->process(text.func, data->res);
data->components.push_back(ftxui::Button(
text.placeholder, data->res->getAs<std::function<void()>>()));
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/quick-ftxui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ int main(int argc, char **argv) {
std::cout << "Parsing succeeded\n";
std::cout << source_code << " Parses OK: " << std::endl;
auto screen = ftxui::ScreenInteractive::Fullscreen();
client::quick_ftxui_parser::component_meta_data data{&screen, {}};
cling::Interpreter interp(0, nullptr, LLVM_DIR);

client::quick_ftxui_parser::component_meta_data data{
&screen, {}, &interp, {}};
client::quick_ftxui_parser::ast_printer printer(&data, 0);
printer(expression);
if (data.components.size()) {
Expand All @@ -59,4 +62,4 @@ int main(int argc, char **argv) {
std::cout << "-------------------------\n";
}
return 0;
}
}