Created
March 21, 2021 19:47
-
-
Save carlopi/74d7dcb986897139d447564d85ced63f to your computer and use it in GitHub Desktop.
Skeleton of Jit implementation with Cheerp
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
namespace [[cheerp::genericjs]] client { | |
//forward declare a bunch of JavaScript APIs existing on the browser | |
namespace WebAssembly { | |
public: | |
Promise* instantiate(ArrayBuffer* code, ImportObject* imports); | |
}; | |
} | |
[[cheerp::genericjs]] void onSuccess(ModuleAndInstance* res) { | |
auto start_function = res->get_instance()->get_start_function(); | |
start_function(); | |
} | |
[[cheerp::genericjs]] void onFailure(Error* error){ | |
//do something | |
} | |
[[cheerp::genericjs]] void compile_and_execute(const ByteCode& bytecode) { | |
ArrayBuffer*array = new ArrayBuffer(bytecode.size()); | |
for (int i=0; i<bytecode.size(); i++) array->set(i, bytecode[i]); | |
ImportObject * imports = new Object(); | |
//initialize imports with whatever method needed | |
Promise* result = WebAssembly::instantiate(array, imports); | |
result->then( onSuccess, onFailure ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment