Commit fa997a3a authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[wasm-c-api] Roll to upstream 70be7c6

This contains the following upstream commits:

486d3fe: Rename DEBUG to WASM_API_DEBUG
8d8e37d: Explicitly number wasm_valkind_t
299ebe0: Fix underlying types for enums
70be7c6: Fix test
Change-Id: I692fb6c909e5211920438740d2c57ea7ee74ab12
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1745483Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63147}
parent a150f95a
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
#include "src/wasm/wasm-result.h" #include "src/wasm/wasm-result.h"
#include "src/wasm/wasm-serialization.h" #include "src/wasm/wasm-serialization.h"
#ifdef WASM_API_DEBUG
#error "WASM_API_DEBUG is unsupported"
#endif
namespace wasm { namespace wasm {
namespace { namespace {
...@@ -188,14 +192,6 @@ auto seal(const typename implement<C>::type* x) -> const C* { ...@@ -188,14 +192,6 @@ auto seal(const typename implement<C>::type* x) -> const C* {
return reinterpret_cast<const C*>(x); return reinterpret_cast<const C*>(x);
} }
#ifdef DEBUG
template <class T>
void vec<T>::make_data() {}
template <class T>
void vec<T>::free_data() {}
#endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Runtime Environment // Runtime Environment
...@@ -334,18 +330,43 @@ struct implement<ValType> { ...@@ -334,18 +330,43 @@ struct implement<ValType> {
using type = ValTypeImpl; using type = ValTypeImpl;
}; };
ValTypeImpl* valtypes[] = { ValTypeImpl* valtype_i32 = new ValTypeImpl(I32);
new ValTypeImpl(I32), new ValTypeImpl(I64), new ValTypeImpl(F32), ValTypeImpl* valtype_i64 = new ValTypeImpl(I64);
new ValTypeImpl(F64), new ValTypeImpl(ANYREF), new ValTypeImpl(FUNCREF), ValTypeImpl* valtype_f32 = new ValTypeImpl(F32);
}; ValTypeImpl* valtype_f64 = new ValTypeImpl(F64);
ValTypeImpl* valtype_anyref = new ValTypeImpl(ANYREF);
ValTypeImpl* valtype_funcref = new ValTypeImpl(FUNCREF);
ValType::~ValType() {} ValType::~ValType() {}
void ValType::operator delete(void*) {} void ValType::operator delete(void*) {}
auto ValType::make(ValKind k) -> own<ValType*> { own<ValType*> ValType::make(ValKind k) {
auto result = seal<ValType>(valtypes[k]); ValTypeImpl* valtype;
return own<ValType*>(result); switch (k) {
case I32:
valtype = valtype_i32;
break;
case I64:
valtype = valtype_i64;
break;
case F32:
valtype = valtype_f32;
break;
case F64:
valtype = valtype_f64;
break;
case ANYREF:
valtype = valtype_anyref;
break;
case FUNCREF:
valtype = valtype_funcref;
break;
default:
// TODO(wasm+): support new value types
UNREACHABLE();
}
return own<ValType*>(seal<ValType>(valtype));
} }
auto ValType::copy() const -> own<ValType*> { return make(kind()); } auto ValType::copy() const -> own<ValType*> { return make(kind()); }
...@@ -2210,7 +2231,7 @@ extern "C++" inline auto hide(wasm::Mutability mutability) ...@@ -2210,7 +2231,7 @@ extern "C++" inline auto hide(wasm::Mutability mutability)
return static_cast<wasm_mutability_t>(mutability); return static_cast<wasm_mutability_t>(mutability);
} }
extern "C++" inline auto reveal(wasm_mutability_t mutability) extern "C++" inline auto reveal(wasm_mutability_enum mutability)
-> wasm::Mutability { -> wasm::Mutability {
return static_cast<wasm::Mutability>(mutability); return static_cast<wasm::Mutability>(mutability);
} }
...@@ -2228,7 +2249,7 @@ extern "C++" inline auto hide(wasm::ValKind kind) -> wasm_valkind_t { ...@@ -2228,7 +2249,7 @@ extern "C++" inline auto hide(wasm::ValKind kind) -> wasm_valkind_t {
return static_cast<wasm_valkind_t>(kind); return static_cast<wasm_valkind_t>(kind);
} }
extern "C++" inline auto reveal(wasm_valkind_t kind) -> wasm::ValKind { extern "C++" inline auto reveal(wasm_valkind_enum kind) -> wasm::ValKind {
return static_cast<wasm::ValKind>(kind); return static_cast<wasm::ValKind>(kind);
} }
...@@ -2236,7 +2257,7 @@ extern "C++" inline auto hide(wasm::ExternKind kind) -> wasm_externkind_t { ...@@ -2236,7 +2257,7 @@ extern "C++" inline auto hide(wasm::ExternKind kind) -> wasm_externkind_t {
return static_cast<wasm_externkind_t>(kind); return static_cast<wasm_externkind_t>(kind);
} }
extern "C++" inline auto reveal(wasm_externkind_t kind) -> wasm::ExternKind { extern "C++" inline auto reveal(wasm_externkind_enum kind) -> wasm::ExternKind {
return static_cast<wasm::ExternKind>(kind); return static_cast<wasm::ExternKind>(kind);
} }
...@@ -2255,7 +2276,8 @@ extern "C++" inline auto reveal(wasm_externkind_t kind) -> wasm::ExternKind { ...@@ -2255,7 +2276,8 @@ extern "C++" inline auto reveal(wasm_externkind_t kind) -> wasm::ExternKind {
WASM_DEFINE_TYPE(valtype, wasm::ValType) WASM_DEFINE_TYPE(valtype, wasm::ValType)
wasm_valtype_t* wasm_valtype_new(wasm_valkind_t k) { wasm_valtype_t* wasm_valtype_new(wasm_valkind_t k) {
return release(wasm::ValType::make(reveal(k))); return release(
wasm::ValType::make(reveal(static_cast<wasm_valkind_enum>(k))));
} }
wasm_valkind_t wasm_valtype_kind(const wasm_valtype_t* t) { wasm_valkind_t wasm_valtype_kind(const wasm_valtype_t* t) {
...@@ -2285,7 +2307,8 @@ WASM_DEFINE_TYPE(globaltype, wasm::GlobalType) ...@@ -2285,7 +2307,8 @@ WASM_DEFINE_TYPE(globaltype, wasm::GlobalType)
wasm_globaltype_t* wasm_globaltype_new(wasm_valtype_t* content, wasm_globaltype_t* wasm_globaltype_new(wasm_valtype_t* content,
wasm_mutability_t mutability) { wasm_mutability_t mutability) {
return release(wasm::GlobalType::make(adopt(content), reveal(mutability))); return release(wasm::GlobalType::make(
adopt(content), reveal(static_cast<wasm_mutability_enum>(mutability))));
} }
const wasm_valtype_t* wasm_globaltype_content(const wasm_globaltype_t* gt) { const wasm_valtype_t* wasm_globaltype_content(const wasm_globaltype_t* gt) {
...@@ -2504,7 +2527,7 @@ WASM_DEFINE_REF_BASE(ref, wasm::Ref) ...@@ -2504,7 +2527,7 @@ WASM_DEFINE_REF_BASE(ref, wasm::Ref)
extern "C++" { extern "C++" {
inline auto is_empty(wasm_val_t v) -> bool { inline auto is_empty(wasm_val_t v) -> bool {
return !is_ref(reveal(v.kind)) || !v.of.ref; return !is_ref(reveal(static_cast<wasm_valkind_enum>(v.kind))) || !v.of.ref;
} }
inline auto hide(wasm::Val v) -> wasm_val_t { inline auto hide(wasm::Val v) -> wasm_val_t {
...@@ -2558,7 +2581,7 @@ inline auto release(wasm::Val v) -> wasm_val_t { ...@@ -2558,7 +2581,7 @@ inline auto release(wasm::Val v) -> wasm_val_t {
} }
inline auto adopt(wasm_val_t v) -> wasm::Val { inline auto adopt(wasm_val_t v) -> wasm::Val {
switch (reveal(v.kind)) { switch (reveal(static_cast<wasm_valkind_enum>(v.kind))) {
case wasm::I32: case wasm::I32:
return wasm::Val(v.of.i32); return wasm::Val(v.of.i32);
case wasm::I64: case wasm::I64:
...@@ -2586,7 +2609,7 @@ struct borrowed_val { ...@@ -2586,7 +2609,7 @@ struct borrowed_val {
inline auto borrow(const wasm_val_t* v) -> borrowed_val { inline auto borrow(const wasm_val_t* v) -> borrowed_val {
wasm::Val v2; wasm::Val v2;
switch (reveal(v->kind)) { switch (reveal(static_cast<wasm_valkind_enum>(v->kind))) {
case wasm::I32: case wasm::I32:
v2 = wasm::Val(v->of.i32); v2 = wasm::Val(v->of.i32);
break; break;
...@@ -2633,12 +2656,14 @@ void wasm_val_vec_copy(wasm_val_vec_t* out, wasm_val_vec_t* v) { ...@@ -2633,12 +2656,14 @@ void wasm_val_vec_copy(wasm_val_vec_t* out, wasm_val_vec_t* v) {
} }
void wasm_val_delete(wasm_val_t* v) { void wasm_val_delete(wasm_val_t* v) {
if (is_ref(reveal(v->kind))) adopt(v->of.ref); if (is_ref(reveal(static_cast<wasm_valkind_enum>(v->kind)))) {
adopt(v->of.ref);
}
} }
void wasm_val_copy(wasm_val_t* out, const wasm_val_t* v) { void wasm_val_copy(wasm_val_t* out, const wasm_val_t* v) {
*out = *v; *out = *v;
if (is_ref(reveal(v->kind))) { if (is_ref(reveal(static_cast<wasm_valkind_enum>(v->kind)))) {
out->of.ref = release(v->of.ref->copy()); out->of.ref = release(v->of.ref->copy());
} }
} }
......
...@@ -13,19 +13,6 @@ ...@@ -13,19 +13,6 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/wasm-api/wasm.hh" #include "third_party/wasm-api/wasm.hh"
namespace wasm {
// TODO(jkummerow): Drop these from the API.
#ifdef DEBUG
template <class T>
void vec<T>::make_data() {}
template <class T>
void vec<T>::free_data() {}
#endif
} // namespace wasm
namespace v8 { namespace v8 {
namespace internal { namespace internal {
namespace wasm { namespace wasm {
......
...@@ -73,7 +73,7 @@ void run() { ...@@ -73,7 +73,7 @@ void run() {
file.close(); file.close();
if (file.fail()) { if (file.fail()) {
std::cout << "> Error loading module!" << std::endl; std::cout << "> Error loading module!" << std::endl;
return; exit(1);
} }
// Compile. // Compile.
...@@ -81,7 +81,7 @@ void run() { ...@@ -81,7 +81,7 @@ void run() {
auto module = wasm::Module::make(store, binary); auto module = wasm::Module::make(store, binary);
if (!module) { if (!module) {
std::cout << "> Error compiling module!" << std::endl; std::cout << "> Error compiling module!" << std::endl;
return; exit(1);
} }
// Create external print functions. // Create external print functions.
...@@ -107,7 +107,7 @@ void run() { ...@@ -107,7 +107,7 @@ void run() {
auto instance = wasm::Instance::make(store, module.get(), imports); auto instance = wasm::Instance::make(store, module.get(), imports);
if (!instance) { if (!instance) {
std::cout << "> Error instantiating module!" << std::endl; std::cout << "> Error instantiating module!" << std::endl;
return; exit(1);
} }
// Extract export. // Extract export.
...@@ -115,7 +115,7 @@ void run() { ...@@ -115,7 +115,7 @@ void run() {
auto exports = instance->exports(); auto exports = instance->exports();
if (exports.size() == 0 || exports[0]->kind() != wasm::EXTERN_FUNC || !exports[0]->func()) { if (exports.size() == 0 || exports[0]->kind() != wasm::EXTERN_FUNC || !exports[0]->func()) {
std::cout << "> Error accessing export!" << std::endl; std::cout << "> Error accessing export!" << std::endl;
return; exit(1);
} }
auto run_func = exports[0]->func(); auto run_func = exports[0]->func();
...@@ -125,7 +125,7 @@ void run() { ...@@ -125,7 +125,7 @@ void run() {
wasm::Val results[1]; wasm::Val results[1];
if (run_func->call(args, results)) { if (run_func->call(args, results)) {
std::cout << "> Error calling function!" << std::endl; std::cout << "> Error calling function!" << std::endl;
return; exit(1);
} }
// Print result. // Print result.
......
...@@ -34,7 +34,7 @@ void run() { ...@@ -34,7 +34,7 @@ void run() {
file.close(); file.close();
if (file.fail()) { if (file.fail()) {
std::cout << "> Error loading module!" << std::endl; std::cout << "> Error loading module!" << std::endl;
return; exit(1);
} }
// Compile. // Compile.
...@@ -42,7 +42,7 @@ void run() { ...@@ -42,7 +42,7 @@ void run() {
auto module = wasm::Module::make(store, binary); auto module = wasm::Module::make(store, binary);
if (!module) { if (!module) {
std::cout << "> Error compiling module!" << std::endl; std::cout << "> Error compiling module!" << std::endl;
return; exit(1);
} }
// Instantiate. // Instantiate.
...@@ -52,7 +52,7 @@ void run() { ...@@ -52,7 +52,7 @@ void run() {
auto instance = wasm::Instance::make(store, module.get(), nullptr); auto instance = wasm::Instance::make(store, module.get(), nullptr);
if (!instance) { if (!instance) {
std::cout << "> Error instantiating module " << i << "!" << std::endl; std::cout << "> Error instantiating module " << i << "!" << std::endl;
return; exit(1);
} }
instance->set_host_info(reinterpret_cast<void*>(i), &finalize); instance->set_host_info(reinterpret_cast<void*>(i), &finalize);
} }
......
...@@ -67,7 +67,7 @@ void run() { ...@@ -67,7 +67,7 @@ void run() {
file.close(); file.close();
if (file.fail()) { if (file.fail()) {
std::cout << "> Error loading module!" << std::endl; std::cout << "> Error loading module!" << std::endl;
return; exit(1);
} }
// Compile. // Compile.
...@@ -75,7 +75,7 @@ void run() { ...@@ -75,7 +75,7 @@ void run() {
auto module = wasm::Module::make(store, binary); auto module = wasm::Module::make(store, binary);
if (!module) { if (!module) {
std::cout << "> Error compiling module!" << std::endl; std::cout << "> Error compiling module!" << std::endl;
return; exit(1);
} }
// Create external globals. // Create external globals.
...@@ -102,7 +102,7 @@ void run() { ...@@ -102,7 +102,7 @@ void run() {
auto instance = wasm::Instance::make(store, module.get(), imports); auto instance = wasm::Instance::make(store, module.get(), imports);
if (!instance) { if (!instance) {
std::cout << "> Error instantiating module!" << std::endl; std::cout << "> Error instantiating module!" << std::endl;
return; exit(1);
} }
// Extract export. // Extract export.
......
...@@ -35,7 +35,7 @@ void run() { ...@@ -35,7 +35,7 @@ void run() {
file.close(); file.close();
if (file.fail()) { if (file.fail()) {
std::cout << "> Error loading module!" << std::endl; std::cout << "> Error loading module!" << std::endl;
return; exit(1);
} }
// Compile. // Compile.
...@@ -43,7 +43,7 @@ void run() { ...@@ -43,7 +43,7 @@ void run() {
auto module = wasm::Module::make(store, binary); auto module = wasm::Module::make(store, binary);
if (!module) { if (!module) {
std::cout << "> Error compiling module!" << std::endl; std::cout << "> Error compiling module!" << std::endl;
return; exit(1);
} }
// Create external print functions. // Create external print functions.
...@@ -59,7 +59,7 @@ void run() { ...@@ -59,7 +59,7 @@ void run() {
auto instance = wasm::Instance::make(store, module.get(), imports); auto instance = wasm::Instance::make(store, module.get(), imports);
if (!instance) { if (!instance) {
std::cout << "> Error instantiating module!" << std::endl; std::cout << "> Error instantiating module!" << std::endl;
return; exit(1);
} }
// Extract export. // Extract export.
...@@ -67,7 +67,7 @@ void run() { ...@@ -67,7 +67,7 @@ void run() {
auto exports = instance->exports(); auto exports = instance->exports();
if (exports.size() == 0 || exports[0]->kind() != wasm::EXTERN_FUNC || !exports[0]->func()) { if (exports.size() == 0 || exports[0]->kind() != wasm::EXTERN_FUNC || !exports[0]->func()) {
std::cout << "> Error accessing export!" << std::endl; std::cout << "> Error accessing export!" << std::endl;
return; exit(1);
} }
auto run_func = exports[0]->func(); auto run_func = exports[0]->func();
...@@ -75,7 +75,7 @@ void run() { ...@@ -75,7 +75,7 @@ void run() {
std::cout << "Calling export..." << std::endl; std::cout << "Calling export..." << std::endl;
if (run_func->call()) { if (run_func->call()) {
std::cout << "> Error calling function!" << std::endl; std::cout << "> Error calling function!" << std::endl;
return; exit(1);
} }
// Shut down. // Shut down.
......
...@@ -79,7 +79,7 @@ void run() { ...@@ -79,7 +79,7 @@ void run() {
file.close(); file.close();
if (file.fail()) { if (file.fail()) {
std::cout << "> Error loading module!" << std::endl; std::cout << "> Error loading module!" << std::endl;
return; exit(1);
} }
// Compile. // Compile.
...@@ -87,7 +87,7 @@ void run() { ...@@ -87,7 +87,7 @@ void run() {
auto module = wasm::Module::make(store, binary); auto module = wasm::Module::make(store, binary);
if (!module) { if (!module) {
std::cout << "> Error compiling module!" << std::endl; std::cout << "> Error compiling module!" << std::endl;
return; exit(1);
} }
// Instantiate. // Instantiate.
...@@ -95,7 +95,7 @@ void run() { ...@@ -95,7 +95,7 @@ void run() {
auto instance = wasm::Instance::make(store, module.get(), nullptr); auto instance = wasm::Instance::make(store, module.get(), nullptr);
if (!instance) { if (!instance) {
std::cout << "> Error instantiating module!" << std::endl; std::cout << "> Error instantiating module!" << std::endl;
return; exit(1);
} }
// Extract export. // Extract export.
......
...@@ -88,7 +88,7 @@ void run() { ...@@ -88,7 +88,7 @@ void run() {
file.close(); file.close();
if (file.fail()) { if (file.fail()) {
std::cout << "> Error loading module!" << std::endl; std::cout << "> Error loading module!" << std::endl;
return; exit(1);
} }
// Compile. // Compile.
...@@ -96,7 +96,7 @@ void run() { ...@@ -96,7 +96,7 @@ void run() {
auto module = wasm::Module::make(store, binary); auto module = wasm::Module::make(store, binary);
if (!module) { if (!module) {
std::cout << "> Error compiling module!" << std::endl; std::cout << "> Error compiling module!" << std::endl;
return; exit(1);
} }
// Instantiate. // Instantiate.
...@@ -104,7 +104,7 @@ void run() { ...@@ -104,7 +104,7 @@ void run() {
auto instance = wasm::Instance::make(store, module.get(), nullptr); auto instance = wasm::Instance::make(store, module.get(), nullptr);
if (!instance) { if (!instance) {
std::cout << "> Error instantiating module!" << std::endl; std::cout << "> Error instantiating module!" << std::endl;
return; exit(1);
} }
// Extract exports. // Extract exports.
......
...@@ -35,7 +35,7 @@ void run() { ...@@ -35,7 +35,7 @@ void run() {
file.close(); file.close();
if (file.fail()) { if (file.fail()) {
std::cout << "> Error loading module!" << std::endl; std::cout << "> Error loading module!" << std::endl;
return; exit(1);
} }
// Compile. // Compile.
...@@ -43,7 +43,7 @@ void run() { ...@@ -43,7 +43,7 @@ void run() {
auto module = wasm::Module::make(store, binary); auto module = wasm::Module::make(store, binary);
if (!module) { if (!module) {
std::cout << "> Error compiling module!" << std::endl; std::cout << "> Error compiling module!" << std::endl;
return; exit(1);
} }
// Serialize module. // Serialize module.
...@@ -55,7 +55,7 @@ void run() { ...@@ -55,7 +55,7 @@ void run() {
auto deserialized = wasm::Module::deserialize(store, serialized); auto deserialized = wasm::Module::deserialize(store, serialized);
if (!deserialized) { if (!deserialized) {
std::cout << "> Error deserializing module!" << std::endl; std::cout << "> Error deserializing module!" << std::endl;
return; exit(1);
} }
// Create external print functions. // Create external print functions.
...@@ -71,7 +71,7 @@ void run() { ...@@ -71,7 +71,7 @@ void run() {
auto instance = wasm::Instance::make(store, deserialized.get(), imports); auto instance = wasm::Instance::make(store, deserialized.get(), imports);
if (!instance) { if (!instance) {
std::cout << "> Error instantiating module!" << std::endl; std::cout << "> Error instantiating module!" << std::endl;
return; exit(1);
} }
// Extract export. // Extract export.
...@@ -79,15 +79,15 @@ void run() { ...@@ -79,15 +79,15 @@ void run() {
auto exports = instance->exports(); auto exports = instance->exports();
if (exports.size() == 0 || exports[0]->kind() != wasm::EXTERN_FUNC || !exports[0]->func()) { if (exports.size() == 0 || exports[0]->kind() != wasm::EXTERN_FUNC || !exports[0]->func()) {
std::cout << "> Error accessing export!" << std::endl; std::cout << "> Error accessing export!" << std::endl;
return; exit(1);
} }
auto run_func = exports[0]->func(); auto run_func = exports[0]->func();
// Call. // Call.
std::cout << "Calling export..." << std::endl; std::cout << "Calling export..." << std::endl;
if (! run_func->call()) { if (run_func->call()) {
std::cout << "> Error calling function!" << std::endl; std::cout << "> Error calling function!" << std::endl;
return; exit(1);
} }
// Shut down. // Shut down.
......
...@@ -87,7 +87,7 @@ void run() { ...@@ -87,7 +87,7 @@ void run() {
file.close(); file.close();
if (file.fail()) { if (file.fail()) {
std::cout << "> Error loading module!" << std::endl; std::cout << "> Error loading module!" << std::endl;
return; exit(1);
} }
// Compile. // Compile.
...@@ -95,7 +95,7 @@ void run() { ...@@ -95,7 +95,7 @@ void run() {
auto module = wasm::Module::make(store, binary); auto module = wasm::Module::make(store, binary);
if (!module) { if (!module) {
std::cout << "> Error compiling module!" << std::endl; std::cout << "> Error compiling module!" << std::endl;
return; exit(1);
} }
// Instantiate. // Instantiate.
...@@ -103,7 +103,7 @@ void run() { ...@@ -103,7 +103,7 @@ void run() {
auto instance = wasm::Instance::make(store, module.get(), nullptr); auto instance = wasm::Instance::make(store, module.get(), nullptr);
if (!instance) { if (!instance) {
std::cout << "> Error instantiating module!" << std::endl; std::cout << "> Error instantiating module!" << std::endl;
return; exit(1);
} }
// Extract export. // Extract export.
......
...@@ -33,7 +33,7 @@ void run( ...@@ -33,7 +33,7 @@ void run(
if (!module) { if (!module) {
std::lock_guard<std::mutex> lock(*mutex); std::lock_guard<std::mutex> lock(*mutex);
std::cout << "> Error compiling module!" << std::endl; std::cout << "> Error compiling module!" << std::endl;
return; exit(1);
} }
// Run the example N times. // Run the example N times.
...@@ -58,7 +58,7 @@ void run( ...@@ -58,7 +58,7 @@ void run(
if (!instance) { if (!instance) {
std::lock_guard<std::mutex> lock(*mutex); std::lock_guard<std::mutex> lock(*mutex);
std::cout << "> Error instantiating module!" << std::endl; std::cout << "> Error instantiating module!" << std::endl;
return; exit(1);
} }
// Extract export. // Extract export.
...@@ -66,7 +66,7 @@ void run( ...@@ -66,7 +66,7 @@ void run(
if (exports.size() == 0 || exports[0]->kind() != wasm::EXTERN_FUNC || !exports[0]->func()) { if (exports.size() == 0 || exports[0]->kind() != wasm::EXTERN_FUNC || !exports[0]->func()) {
std::lock_guard<std::mutex> lock(*mutex); std::lock_guard<std::mutex> lock(*mutex);
std::cout << "> Error accessing export!" << std::endl; std::cout << "> Error accessing export!" << std::endl;
return; exit(1);
} }
auto run_func = exports[0]->func(); auto run_func = exports[0]->func();
......
...@@ -43,7 +43,7 @@ void run() { ...@@ -43,7 +43,7 @@ void run() {
file.close(); file.close();
if (file.fail()) { if (file.fail()) {
std::cout << "> Error loading module!" << std::endl; std::cout << "> Error loading module!" << std::endl;
return; exit(1);
} }
// Compile. // Compile.
...@@ -51,7 +51,7 @@ void run() { ...@@ -51,7 +51,7 @@ void run() {
auto module = wasm::Module::make(store, binary); auto module = wasm::Module::make(store, binary);
if (!module) { if (!module) {
std::cout << "> Error compiling module!" << std::endl; std::cout << "> Error compiling module!" << std::endl;
return; exit(1);
} }
// Create external print functions. // Create external print functions.
...@@ -69,7 +69,7 @@ void run() { ...@@ -69,7 +69,7 @@ void run() {
auto instance = wasm::Instance::make(store, module.get(), imports); auto instance = wasm::Instance::make(store, module.get(), imports);
if (!instance) { if (!instance) {
std::cout << "> Error instantiating module!" << std::endl; std::cout << "> Error instantiating module!" << std::endl;
return; exit(1);
} }
// Extract export. // Extract export.
...@@ -79,7 +79,7 @@ void run() { ...@@ -79,7 +79,7 @@ void run() {
exports[0]->kind() != wasm::EXTERN_FUNC || !exports[0]->func() || exports[0]->kind() != wasm::EXTERN_FUNC || !exports[0]->func() ||
exports[1]->kind() != wasm::EXTERN_FUNC || !exports[1]->func()) { exports[1]->kind() != wasm::EXTERN_FUNC || !exports[1]->func()) {
std::cout << "> Error accessing exports!" << std::endl; std::cout << "> Error accessing exports!" << std::endl;
return; exit(1);
} }
// Call. // Call.
...@@ -88,7 +88,7 @@ void run() { ...@@ -88,7 +88,7 @@ void run() {
auto trap = exports[i]->func()->call(); auto trap = exports[i]->func()->call();
if (!trap) { if (!trap) {
std::cout << "> Error calling function!" << std::endl; std::cout << "> Error calling function!" << std::endl;
return; exit(1);
} }
std::cout << "Printing message..." << std::endl; std::cout << "Printing message..." << std::endl;
......
...@@ -136,10 +136,11 @@ own wasm_store_t* wasm_store_new(wasm_engine_t*); ...@@ -136,10 +136,11 @@ own wasm_store_t* wasm_store_new(wasm_engine_t*);
// Type attributes // Type attributes
typedef enum wasm_mutability_t { typedef uint8_t wasm_mutability_t;
enum wasm_mutability_enum {
WASM_CONST, WASM_CONST,
WASM_VAR WASM_VAR,
} wasm_mutability_t; };
typedef struct wasm_limits_t { typedef struct wasm_limits_t {
uint32_t min; uint32_t min;
...@@ -162,14 +163,15 @@ static const uint32_t wasm_limits_max_default = 0xffffffff; ...@@ -162,14 +163,15 @@ static const uint32_t wasm_limits_max_default = 0xffffffff;
WASM_DECLARE_TYPE(valtype) WASM_DECLARE_TYPE(valtype)
typedef enum wasm_valkind_t { typedef uint8_t wasm_valkind_t;
enum wasm_valkind_enum {
WASM_I32, WASM_I32,
WASM_I64, WASM_I64,
WASM_F32, WASM_F32,
WASM_F64, WASM_F64,
WASM_ANYREF, WASM_ANYREF = 128,
WASM_FUNCREF WASM_FUNCREF,
} wasm_valkind_t; };
own wasm_valtype_t* wasm_valtype_new(wasm_valkind_t); own wasm_valtype_t* wasm_valtype_new(wasm_valkind_t);
...@@ -236,12 +238,13 @@ const wasm_limits_t* wasm_memorytype_limits(const wasm_memorytype_t*); ...@@ -236,12 +238,13 @@ const wasm_limits_t* wasm_memorytype_limits(const wasm_memorytype_t*);
WASM_DECLARE_TYPE(externtype) WASM_DECLARE_TYPE(externtype)
typedef enum wasm_externkind_t { typedef uint8_t wasm_externkind_t;
enum wasm_externkind_enum {
WASM_EXTERN_FUNC, WASM_EXTERN_FUNC,
WASM_EXTERN_GLOBAL, WASM_EXTERN_GLOBAL,
WASM_EXTERN_TABLE, WASM_EXTERN_TABLE,
WASM_EXTERN_MEMORY WASM_EXTERN_MEMORY,
} wasm_externkind_t; };
wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t*); wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t*);
......
...@@ -111,7 +111,7 @@ class vec { ...@@ -111,7 +111,7 @@ class vec {
size_t size_; size_t size_;
std::unique_ptr<T[]> data_; std::unique_ptr<T[]> data_;
#ifdef DEBUG #ifdef WASM_API_DEBUG
void make_data(); void make_data();
void free_data(); void free_data();
#else #else
...@@ -275,7 +275,7 @@ public: ...@@ -275,7 +275,7 @@ public:
// Type attributes // Type attributes
enum Mutability { CONST, VAR }; enum Mutability : uint8_t { CONST, VAR };
struct Limits { struct Limits {
uint32_t min; uint32_t min;
...@@ -288,7 +288,10 @@ struct Limits { ...@@ -288,7 +288,10 @@ struct Limits {
// Value Types // Value Types
enum ValKind { I32, I64, F32, F64, ANYREF, FUNCREF }; enum ValKind : uint8_t {
I32, I64, F32, F64,
ANYREF = 128, FUNCREF,
};
inline bool is_num(ValKind k) { return k < ANYREF; } inline bool is_num(ValKind k) { return k < ANYREF; }
inline bool is_ref(ValKind k) { return k >= ANYREF; } inline bool is_ref(ValKind k) { return k >= ANYREF; }
...@@ -311,7 +314,7 @@ public: ...@@ -311,7 +314,7 @@ public:
// External Types // External Types
enum ExternKind { enum ExternKind : uint8_t {
EXTERN_FUNC, EXTERN_GLOBAL, EXTERN_TABLE, EXTERN_MEMORY EXTERN_FUNC, EXTERN_GLOBAL, EXTERN_TABLE, EXTERN_MEMORY
}; };
...@@ -344,8 +347,6 @@ public: ...@@ -344,8 +347,6 @@ public:
// Function Types // Function Types
enum class arrow { ARROW };
class FuncType : public ExternType { class FuncType : public ExternType {
public: public:
FuncType() = delete; FuncType() = delete;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment