-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First functional kernel based on clang-repl
- Loading branch information
1 parent
11a0b9a
commit aef99bd
Showing
37 changed files
with
2,357 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/************************************************************************************ | ||
* Copyright (c) 2023, xeus-cpp contributors * | ||
* Copyright (c) 2023, Johan Mabille, Loic Gouarin, Sylvain Corlay, Wolf Vollprecht * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
************************************************************************************/ | ||
|
||
#ifndef XCPP_DISPLAY_HPP | ||
#define XCPP_DISPLAY_HPP | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
#include "xcpp/xmime.hpp" | ||
|
||
namespace nl = nlohmann; | ||
|
||
namespace xcpp | ||
{ | ||
// Adding a dummy non-template display overload as a workaround to | ||
// Issue https://reviews.llvm.org/D147319 | ||
class dummy_display | ||
{ | ||
}; | ||
|
||
void display(dummy_display i) | ||
{ | ||
} | ||
|
||
template <class T> | ||
void display(const T& t) | ||
{ | ||
using ::xcpp::mime_bundle_repr; | ||
xeus::get_interpreter().display_data(mime_bundle_repr(t), nl::json::object(), nl::json::object()); | ||
} | ||
|
||
template <class T> | ||
void display(const T& t, xeus::xguid id, bool update = false) | ||
{ | ||
nl::json transient; | ||
transient["display_id"] = id; | ||
using ::xcpp::mime_bundle_repr; | ||
if (update) | ||
{ | ||
xeus::get_interpreter() | ||
.update_display_data(mime_bundle_repr(t), nl::json::object(), std::move(transient)); | ||
} | ||
else | ||
{ | ||
xeus::get_interpreter().display_data(mime_bundle_repr(t), nl::json::object(), std::move(transient)); | ||
} | ||
} | ||
|
||
inline void clear_output(bool wait = false) | ||
{ | ||
xeus::get_interpreter().clear_output(wait); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/************************************************************************************ | ||
* Copyright (c) 2023, xeus-cpp contributors * | ||
* Copyright (c) 2023, Johan Mabille, Loic Gouarin, Sylvain Corlay, Wolf Vollprecht * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
************************************************************************************/ | ||
|
||
#ifndef XCPP_MIME_HPP | ||
#define XCPP_MIME_HPP | ||
|
||
#include <sstream> | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
namespace nl = nlohmann; | ||
|
||
namespace xcpp | ||
{ | ||
namespace detail | ||
{ | ||
// Generic mime_bundle_repr() implementation | ||
// via std::ostringstream. | ||
template <class T> | ||
nl::json mime_bundle_repr_via_sstream(const T& value) | ||
{ | ||
auto bundle = nl::json::object(); | ||
|
||
std::ostringstream oss; | ||
oss << value; | ||
|
||
bundle["text/plain"] = oss.str(); | ||
return bundle; | ||
} | ||
|
||
} | ||
|
||
// Default implementation of mime_bundle_repr | ||
template <class T> | ||
nl::json mime_bundle_repr(const T& value) | ||
{ | ||
return detail::mime_bundle_repr_via_sstream(&value); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/************************************************************************************ | ||
* Copyright (c) 2023, xeus-cpp contributors * | ||
* Copyright (c) 2023, Johan Mabille, Loic Gouarin, Sylvain Corlay, Wolf Vollprecht * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
************************************************************************************/ | ||
|
||
#ifndef XEUS_CPP_BUFFER_HPP | ||
#define XEUS_CPP_BUFFER_HPP | ||
|
||
#include <functional> | ||
#include <memory> | ||
#include <mutex> | ||
#include <streambuf> | ||
#include <string> | ||
|
||
namespace xcpp | ||
{ | ||
/******************** | ||
* output streambuf * | ||
********************/ | ||
|
||
class xoutput_buffer : public std::streambuf | ||
{ | ||
public: | ||
|
||
using base_type = std::streambuf; | ||
using callback_type = std::function<void(const std::string&)>; | ||
using traits_type = base_type::traits_type; | ||
|
||
xoutput_buffer(callback_type callback) | ||
: m_callback(std::move(callback)) | ||
{ | ||
} | ||
|
||
protected: | ||
|
||
traits_type::int_type overflow(traits_type::int_type c) override | ||
{ | ||
std::lock_guard<std::mutex> lock(m_mutex); | ||
// Called for each output character. | ||
if (!traits_type::eq_int_type(c, traits_type::eof())) | ||
{ | ||
m_output.push_back(traits_type::to_char_type(c)); | ||
} | ||
return c; | ||
} | ||
|
||
std::streamsize xsputn(const char* s, std::streamsize count) override | ||
{ | ||
std::lock_guard<std::mutex> lock(m_mutex); | ||
// Called for a string of characters. | ||
m_output.append(s, count); | ||
return count; | ||
} | ||
|
||
traits_type::int_type sync() override | ||
{ | ||
std::lock_guard<std::mutex> lock(m_mutex); | ||
// Called in case of flush. | ||
if (!m_output.empty()) | ||
{ | ||
m_callback(m_output); | ||
m_output.clear(); | ||
} | ||
return 0; | ||
} | ||
|
||
callback_type m_callback; | ||
std::string m_output; | ||
std::mutex m_mutex; | ||
}; | ||
|
||
/******************* | ||
* input streambuf * | ||
*******************/ | ||
|
||
class xinput_buffer : public std::streambuf | ||
{ | ||
public: | ||
|
||
using base_type = std::streambuf; | ||
using callback_type = std::function<void(std::string&)>; | ||
using traits_type = base_type::traits_type; | ||
|
||
xinput_buffer(callback_type callback) | ||
: m_callback(std::move(callback)) | ||
, m_value() | ||
{ | ||
char* data = const_cast<char*>(m_value.data()); | ||
this->setg(data, data, data); | ||
} | ||
|
||
protected: | ||
|
||
traits_type::int_type underflow() override | ||
{ | ||
m_callback(m_value); | ||
// Terminate the string to trigger parsing. | ||
m_value += '\n'; | ||
char* data = const_cast<char*>(m_value.data()); | ||
setg(data, data, data + m_value.size()); | ||
return traits_type::to_int_type(*gptr()); | ||
} | ||
|
||
callback_type m_callback; | ||
std::string m_value; | ||
}; | ||
|
||
/************************* | ||
* output null streambuf * | ||
*************************/ | ||
|
||
class xnull : public std::streambuf | ||
{ | ||
using base_type = std::streambuf; | ||
using traits_type = base_type::traits_type; | ||
|
||
traits_type::int_type overflow(traits_type::int_type c) override | ||
{ | ||
return c; | ||
} | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.