Skip to content

Commit 9a4d0e9

Browse files
committed
Update constructor for wasm interpreter
1 parent 619e427 commit 9a4d0e9

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function(configure_native_kernel kernel)
148148
endfunction()
149149

150150
function(configure_wasm_kernel kernel)
151-
set(XEUS_CPP_RESOURCE_DIR "/lib/clang/${CPPINTEROP_LLVM_VERSION_MAJOR}")
151+
set(XEUS_CPP_RESOURCE_DIR "/lib/clang/${CPPINTEROP_LLVM_VERSION_MAJOR}" PARENT_SCOPE)
152152

153153
configure_file (
154154
"${CMAKE_CURRENT_SOURCE_DIR}${kernel}wasm_kernel.json.in"
@@ -437,7 +437,7 @@ if(EMSCRIPTEN)
437437
xeus_wasm_link_options(xcpp "web,worker")
438438
target_link_options(xcpp
439439
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
440-
# PUBLIC "SHELL: --preload-file ${CMAKE_INSTALL_PREFIX}${XEUS_CPP_RESOURCE_DIR}/include@${XEUS_CPP_RESOURCE_DIR}"
440+
#PUBLIC "SHELL: --preload-file ${CMAKE_INSTALL_PREFIX}${XEUS_CPP_RESOURCE_DIR}@${XEUS_CPP_RESOURCE_DIR}"
441441
PUBLIC "SHELL: --preload-file ${XEUS_CPP_DATA_DIR}@/share/xeus-cpp"
442442
PUBLIC "SHELL: --preload-file ${XEUS_CPP_CONF_DIR}@/etc/xeus-cpp"
443443
PUBLIC "SHELL: --post-js ${CMAKE_CURRENT_SOURCE_DIR}/wasm_patches/post.js"

include/xeus-cpp/xinterpreter_wasm.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ namespace xcpp
1919
{
2020
public:
2121

22-
wasm_interpreter();
23-
wasm_interpreter(int argc, char** argv);
22+
wasm_interpreter(int argc = 0, char** argv = nullptr);
2423
virtual ~wasm_interpreter() = default;
2524

2625
};

src/main_emscripten_kernel.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,26 @@
1515

1616
#include "xeus-cpp/xinterpreter_wasm.hpp"
1717

18+
template <class interpreter_type>
19+
static interpreter_type* builder_with_args(emscripten::val js_args)
20+
{
21+
static std::vector<std::string> args = emscripten::vecFromJSArray<std::string>(js_args);
22+
static std::vector<const char*> argv_vec;
23+
24+
for (const auto& s : args)
25+
{
26+
argv_vec.push_back(s.c_str());
27+
}
28+
29+
int argc = static_cast<int>(argv_vec.size());
30+
char** argv = const_cast<char**>(argv_vec.data());
31+
32+
return new interpreter_type(argc, argv);
33+
}
34+
1835
EMSCRIPTEN_BINDINGS(my_module)
1936
{
2037
xeus::export_core();
2138
using interpreter_type = xcpp::wasm_interpreter;
22-
xeus::export_kernel<interpreter_type>("xkernel");
39+
xeus::export_kernel<interpreter_type, &builder_with_args<interpreter_type>>("xkernel");
2340
}

src/xinterpreter_wasm.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515

1616
namespace xcpp
1717
{
18-
19-
wasm_interpreter::wasm_interpreter()
20-
: interpreter(0, nullptr)
21-
{
22-
}
23-
2418
wasm_interpreter::wasm_interpreter(int argc, char** argv)
2519
: interpreter(argc, argv)
2620
{

0 commit comments

Comments
 (0)