Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/deploy-github-page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
micromamba create -n xeus-lite-host jupyterlite-core
micromamba activate xeus-lite-host
python -m pip install jupyterlite-xeus jupyter_server
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }} --contents notebooks --output-dir dist
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }} --contents notebooks/xeus-cpp-lite-demo.ipynb --output-dir dist
cp $PREFIX/bin/xcpp.data dist/extensions/@jupyterlite/xeus/static
cp $PREFIX/lib/libclangCppInterOp.so dist/extensions/@jupyterlite/xeus/static

Expand Down
370 changes: 370 additions & 0 deletions notebooks/xeus-cpp-lite-demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,370 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "aa9d4f33-5bd8-42f2-918a-e654d4363577",
"metadata": {},
"source": [
"<center>\n",
" <h1>C++ kernel based on xeus</h1>\n",
"</center>\n",
"\n",
"A Jupyter kernel for C++ based on the `CppInterOp`, a clang based C++ Interoperability Library and the `xeus` native implementation of the Jupyter protocol, xeus.\n",
"\n",
"- GitHub repository: https://github.com/compiler-research/xeus-cpp\n",
"- Documentation: https://xeus-cpp.readthedocs.io/en/latest/"
]
},
{
"cell_type": "markdown",
"id": "9af8aa44-7786-47b6-b94b-8579470acb3a",
"metadata": {},
"source": [
"## Usage\n",
"\n",
"<div style=\"background: #efffed;\n",
" border: 1px solid grey;\n",
" margin: 8px 0 8px 0;\n",
" text-align: center;\n",
" padding: 8px; \">\n",
" <i class=\"fa-play fa\" \n",
" style=\"font-size: 40px;\n",
" line-height: 40px;\n",
" margin: 8px;\n",
" color: #444;\">\n",
" </i>\n",
" <div>\n",
" To run the selected code cell, hit <pre style=\"background: #efffed\">Shift + Enter</pre>\n",
" </div>\n",
"</div>"
]
},
{
"cell_type": "markdown",
"id": "be1c8c6c-3fbe-4f53-9deb-8496c43d26ad",
"metadata": {},
"source": [
"## Output and error streams\n",
"\n",
"`std::cout` and `std::cerr` are redirected to the notebook frontend."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "9bd7f767-6c22-4a1b-a1e2-cd4184fd0367",
"metadata": {
"vscode": {
"languageId": "c++"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"some output\n"
]
}
],
"source": [
"#include <iostream>\n",
"\n",
"std::cout << \"some output\" << std::endl;"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9622f20f-5925-4544-a97b-aada3a14209a",
"metadata": {
"vscode": {
"languageId": "c++"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"some error\n"
]
}
],
"source": [
"std::cerr << \"some error\" << std::endl;"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "7af0c962-17dc-47d4-9772-b8a06e2bda3a",
"metadata": {
"vscode": {
"languageId": "c++"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n"
]
}
],
"source": [
"int j = 5;\n",
"std::cout << j << std::endl;"
]
},
{
"cell_type": "markdown",
"id": "526a7dba-4001-47d5-a116-95423118e100",
"metadata": {},
"source": [
"# Interpreting the C++ programming language\n",
"\n",
"You can define functions, classes, templates, etc ..."
]
},
{
"cell_type": "markdown",
"id": "e5b116ce-ced1-4aa4-b14e-ef7d2606202e",
"metadata": {},
"source": [
"## Functions"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "86b08f22-e16c-4eac-917d-ae6eeb7ec7cb",
"metadata": {
"vscode": {
"languageId": "c++"
}
},
"outputs": [],
"source": [
"double sqr(double a)\n",
"{\n",
" return a * a;\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "5aff6711-54bf-4280-a496-c9f7c683eee5",
"metadata": {
"vscode": {
"languageId": "c++"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6.25\n"
]
}
],
"source": [
"double a = 2.5;\n",
"double asqr = sqr(a);\n",
"std::cout << asqr << std::endl;"
]
},
{
"cell_type": "markdown",
"id": "5b3959b0-9dc7-41a4-bba1-e20abd0765f7",
"metadata": {},
"source": [
"## Classes"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "d981a53b-8185-49c5-8a30-02453cc1b9e9",
"metadata": {
"vscode": {
"languageId": "c++"
}
},
"outputs": [],
"source": [
"class Foo\n",
"{\n",
"public:\n",
"\n",
" virtual ~Foo() {}\n",
" \n",
" virtual void print(double value) const\n",
" {\n",
" std::cout << \"Foo value = \" << value << std::endl;\n",
" }\n",
"};"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "195d513f-d5cb-4e3d-a6cb-ae99dfcd9aab",
"metadata": {
"vscode": {
"languageId": "c++"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Foo value = 1.2\n"
]
}
],
"source": [
"Foo bar;\n",
"bar.print(1.2);"
]
},
{
"cell_type": "markdown",
"id": "9ecc1588-cb6e-4676-bb16-b9938e980b06",
"metadata": {},
"source": [
"## Polymorphism"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "4df90bea-5c9e-462e-bd20-d80fd169b7b6",
"metadata": {
"vscode": {
"languageId": "c++"
}
},
"outputs": [],
"source": [
"class Bar : public Foo\n",
"{\n",
"public:\n",
"\n",
" virtual ~Bar() {}\n",
" \n",
" virtual void print(double value) const\n",
" {\n",
" std::cout << \"Bar value = \" << 2 * value << std::endl;\n",
" }\n",
"};"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "f7dbbcc2-0f00-48eb-8bb9-94e871afa2a7",
"metadata": {
"vscode": {
"languageId": "c++"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Bar value = 2.4\n"
]
}
],
"source": [
"Foo* bar2 = new Bar;\n",
"bar2->print(1.2);\n",
"delete bar2;"
]
},
{
"cell_type": "markdown",
"id": "094f4ca7-0aa5-4121-bfff-bf5db1d42c5d",
"metadata": {},
"source": [
"## Templates"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "0df4f3a5-25a1-4548-ba63-54887c770dad",
"metadata": {
"vscode": {
"languageId": "c++"
}
},
"outputs": [],
"source": [
"#include <typeinfo>\n",
"\n",
"template <class T>\n",
"class FooT\n",
"{\n",
"public:\n",
" \n",
" explicit FooT(const T& t) : m_t(t) {}\n",
" \n",
" void print() const\n",
" {\n",
" std::cout << typeid(T).name() << \" m_t = \" << m_t << std::endl;\n",
" }\n",
" \n",
"private:\n",
" \n",
" T m_t;\n",
"};"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e7bcab70-b9db-409c-aa04-9c64b413e266",
"metadata": {
"vscode": {
"languageId": "c++"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"d m_t = 1.2\n"
]
}
],
"source": [
"FooT<double> foot(1.2);\n",
"foot.print();"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "C++20",
"language": "cpp",
"name": "xcpp20"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "C++",
"version": "20"
}
},
"nbformat": 4,
"nbformat_minor": 5
}