Commit 3b45da47 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[wasm-c-api] Roll 70a2889: Remove template meta-programming

This change is very mechanical:
own<Foo*> → own<Foo>
vec<Foo*> → ownvec<Foo>
As usual, everything in third_party/ is straight-up copied from upstream.

Change-Id: If5fabda99e2b281da6f2e71ce23a2f5b68aaac86
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1760815
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63263}
parent 8e478b8d
......@@ -108,30 +108,30 @@ Name GetNameFromWireBytes(const i::wasm::WireBytesRef& ref,
return name;
}
own<FuncType*> FunctionSigToFuncType(const i::wasm::FunctionSig* sig) {
own<FuncType> FunctionSigToFuncType(const i::wasm::FunctionSig* sig) {
size_t param_count = sig->parameter_count();
vec<ValType*> params = vec<ValType*>::make_uninitialized(param_count);
ownvec<ValType> params = ownvec<ValType>::make_uninitialized(param_count);
for (size_t i = 0; i < param_count; i++) {
params[i] = ValType::make(V8ValueTypeToWasm(sig->GetParam(i)));
}
size_t return_count = sig->return_count();
vec<ValType*> results = vec<ValType*>::make_uninitialized(return_count);
ownvec<ValType> results = ownvec<ValType>::make_uninitialized(return_count);
for (size_t i = 0; i < return_count; i++) {
results[i] = ValType::make(V8ValueTypeToWasm(sig->GetReturn(i)));
}
return FuncType::make(std::move(params), std::move(results));
}
own<ExternType*> GetImportExportType(const i::wasm::WasmModule* module,
const i::wasm::ImportExportKindCode kind,
const uint32_t index) {
own<ExternType> GetImportExportType(const i::wasm::WasmModule* module,
const i::wasm::ImportExportKindCode kind,
const uint32_t index) {
switch (kind) {
case i::wasm::kExternalFunction: {
return FunctionSigToFuncType(module->functions[index].sig);
}
case i::wasm::kExternalTable: {
const i::wasm::WasmTable& table = module->tables[index];
own<ValType*> elem = ValType::make(V8ValueTypeToWasm(table.type));
own<ValType> elem = ValType::make(V8ValueTypeToWasm(table.type));
Limits limits(table.initial_size,
table.has_maximum_size ? table.maximum_size : -1);
return TableType::make(std::move(elem), limits);
......@@ -144,7 +144,7 @@ own<ExternType*> GetImportExportType(const i::wasm::WasmModule* module,
}
case i::wasm::kExternalGlobal: {
const i::wasm::WasmGlobal& global = module->globals[index];
own<ValType*> content = ValType::make(V8ValueTypeToWasm(global.type));
own<ValType> content = ValType::make(V8ValueTypeToWasm(global.type));
Mutability mutability = global.mutability ? VAR : CONST;
return GlobalType::make(std::move(content), mutability);
}
......@@ -211,8 +211,8 @@ Config::~Config() { impl(this)->~ConfigImpl(); }
void Config::operator delete(void* p) { ::operator delete(p); }
auto Config::make() -> own<Config*> {
return own<Config*>(seal<Config>(new (std::nothrow) ConfigImpl()));
auto Config::make() -> own<Config> {
return own<Config>(seal<Config>(new (std::nothrow) ConfigImpl()));
}
// Engine
......@@ -244,13 +244,13 @@ Engine::~Engine() { impl(this)->~EngineImpl(); }
void Engine::operator delete(void* p) { ::operator delete(p); }
auto Engine::make(own<Config*>&& config) -> own<Engine*> {
auto Engine::make(own<Config>&& config) -> own<Engine> {
i::FLAG_expose_gc = true;
i::FLAG_experimental_wasm_anyref = true;
i::FLAG_experimental_wasm_bigint = true;
i::FLAG_experimental_wasm_mv = true;
auto engine = new (std::nothrow) EngineImpl;
if (!engine) return own<Engine*>();
if (!engine) return own<Engine>();
engine->platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(engine->platform.get());
v8::V8::Initialize();
......@@ -279,22 +279,22 @@ Store::~Store() { impl(this)->~StoreImpl(); }
void Store::operator delete(void* p) { ::operator delete(p); }
auto Store::make(Engine*) -> own<Store*> {
auto Store::make(Engine*) -> own<Store> {
auto store = make_own(new (std::nothrow) StoreImpl());
if (!store) return own<Store*>();
if (!store) return own<Store>();
// Create isolate.
store->create_params_.array_buffer_allocator =
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
auto isolate = v8::Isolate::New(store->create_params_);
if (!isolate) return own<Store*>();
if (!isolate) return own<Store>();
{
v8::HandleScope handle_scope(isolate);
// Create context.
auto context = v8::Context::New(isolate);
if (context.IsEmpty()) return own<Store*>();
if (context.IsEmpty()) return own<Store>();
v8::Context::Scope context_scope(context);
store->isolate_ = isolate;
......@@ -341,7 +341,7 @@ ValType::~ValType() {}
void ValType::operator delete(void*) {}
own<ValType*> ValType::make(ValKind k) {
own<ValType> ValType::make(ValKind k) {
ValTypeImpl* valtype;
switch (k) {
case I32:
......@@ -366,10 +366,10 @@ own<ValType*> ValType::make(ValKind k) {
// TODO(wasm+): support new value types
UNREACHABLE();
}
return own<ValType*>(seal<ValType>(valtype));
return own<ValType>(seal<ValType>(valtype));
}
auto ValType::copy() const -> own<ValType*> { return make(kind()); }
auto ValType::copy() const -> own<ValType> { return make(kind()); }
auto ValType::kind() const -> ValKind { return impl(this)->kind; }
......@@ -391,7 +391,7 @@ ExternType::~ExternType() { impl(this)->~ExternTypeImpl(); }
void ExternType::operator delete(void* p) { ::operator delete(p); }
auto ExternType::copy() const -> own<ExternType*> {
auto ExternType::copy() const -> own<ExternType> {
switch (kind()) {
case EXTERN_FUNC:
return func()->copy();
......@@ -409,11 +409,11 @@ auto ExternType::kind() const -> ExternKind { return impl(this)->kind; }
// Function Types
struct FuncTypeImpl : ExternTypeImpl {
vec<ValType*> params;
vec<ValType*> results;
ownvec<ValType> params;
ownvec<ValType> results;
FuncTypeImpl(vec<ValType*>& params, // NOLINT(runtime/references)
vec<ValType*>& results) // NOLINT(runtime/references)
FuncTypeImpl(ownvec<ValType>& params, // NOLINT(runtime/references)
ownvec<ValType>& results) // NOLINT(runtime/references)
: ExternTypeImpl(EXTERN_FUNC),
params(std::move(params)),
results(std::move(results)) {}
......@@ -428,23 +428,23 @@ struct implement<FuncType> {
FuncType::~FuncType() {}
auto FuncType::make(vec<ValType*>&& params, vec<ValType*>&& results)
-> own<FuncType*> {
auto FuncType::make(ownvec<ValType>&& params, ownvec<ValType>&& results)
-> own<FuncType> {
return params && results
? own<FuncType*>(seal<FuncType>(new (std::nothrow)
FuncTypeImpl(params, results)))
: own<FuncType*>();
? own<FuncType>(seal<FuncType>(new (std::nothrow)
FuncTypeImpl(params, results)))
: own<FuncType>();
}
auto FuncType::copy() const -> own<FuncType*> {
return make(params().copy(), results().copy());
auto FuncType::copy() const -> own<FuncType> {
return make(params().deep_copy(), results().deep_copy());
}
auto FuncType::params() const -> const vec<ValType*>& {
auto FuncType::params() const -> const ownvec<ValType>& {
return impl(this)->params;
}
auto FuncType::results() const -> const vec<ValType*>& {
auto FuncType::results() const -> const ownvec<ValType>& {
return impl(this)->results;
}
......@@ -463,10 +463,10 @@ auto ExternType::func() const -> const FuncType* {
// Global Types
struct GlobalTypeImpl : ExternTypeImpl {
own<ValType*> content;
own<ValType> content;
Mutability mutability;
GlobalTypeImpl(own<ValType*>& content, // NOLINT(runtime/references)
GlobalTypeImpl(own<ValType>& content, // NOLINT(runtime/references)
Mutability mutability)
: ExternTypeImpl(EXTERN_GLOBAL),
content(std::move(content)),
......@@ -482,14 +482,14 @@ struct implement<GlobalType> {
GlobalType::~GlobalType() {}
auto GlobalType::make(own<ValType*>&& content, Mutability mutability)
-> own<GlobalType*> {
return content ? own<GlobalType*>(seal<GlobalType>(
auto GlobalType::make(own<ValType>&& content, Mutability mutability)
-> own<GlobalType> {
return content ? own<GlobalType>(seal<GlobalType>(
new (std::nothrow) GlobalTypeImpl(content, mutability)))
: own<GlobalType*>();
: own<GlobalType>();
}
auto GlobalType::copy() const -> own<GlobalType*> {
auto GlobalType::copy() const -> own<GlobalType> {
return make(content()->copy(), mutability());
}
......@@ -516,10 +516,10 @@ auto ExternType::global() const -> const GlobalType* {
// Table Types
struct TableTypeImpl : ExternTypeImpl {
own<ValType*> element;
own<ValType> element;
Limits limits;
TableTypeImpl(own<ValType*>& element, // NOLINT(runtime/references)
TableTypeImpl(own<ValType>& element, // NOLINT(runtime/references)
Limits limits)
: ExternTypeImpl(EXTERN_TABLE),
element(std::move(element)),
......@@ -535,14 +535,13 @@ struct implement<TableType> {
TableType::~TableType() {}
auto TableType::make(own<ValType*>&& element, Limits limits)
-> own<TableType*> {
return element ? own<TableType*>(seal<TableType>(
auto TableType::make(own<ValType>&& element, Limits limits) -> own<TableType> {
return element ? own<TableType>(seal<TableType>(
new (std::nothrow) TableTypeImpl(element, limits)))
: own<TableType*>();
: own<TableType>();
}
auto TableType::copy() const -> own<TableType*> {
auto TableType::copy() const -> own<TableType> {
return make(element()->copy(), limits());
}
......@@ -582,12 +581,12 @@ struct implement<MemoryType> {
MemoryType::~MemoryType() {}
auto MemoryType::make(Limits limits) -> own<MemoryType*> {
return own<MemoryType*>(
auto MemoryType::make(Limits limits) -> own<MemoryType> {
return own<MemoryType>(
seal<MemoryType>(new (std::nothrow) MemoryTypeImpl(limits)));
}
auto MemoryType::copy() const -> own<MemoryType*> {
auto MemoryType::copy() const -> own<MemoryType> {
return MemoryType::make(limits());
}
......@@ -610,11 +609,11 @@ auto ExternType::memory() const -> const MemoryType* {
struct ImportTypeImpl {
Name module;
Name name;
own<ExternType*> type;
own<ExternType> type;
ImportTypeImpl(Name& module, // NOLINT(runtime/references)
Name& name, // NOLINT(runtime/references)
own<ExternType*>& type) // NOLINT(runtime/references)
ImportTypeImpl(Name& module, // NOLINT(runtime/references)
Name& name, // NOLINT(runtime/references)
own<ExternType>& type) // NOLINT(runtime/references)
: module(std::move(module)),
name(std::move(name)),
type(std::move(type)) {}
......@@ -631,15 +630,15 @@ ImportType::~ImportType() { impl(this)->~ImportTypeImpl(); }
void ImportType::operator delete(void* p) { ::operator delete(p); }
auto ImportType::make(Name&& module, Name&& name, own<ExternType*>&& type)
-> own<ImportType*> {
auto ImportType::make(Name&& module, Name&& name, own<ExternType>&& type)
-> own<ImportType> {
return module && name && type
? own<ImportType*>(seal<ImportType>(
? own<ImportType>(seal<ImportType>(
new (std::nothrow) ImportTypeImpl(module, name, type)))
: own<ImportType*>();
: own<ImportType>();
}
auto ImportType::copy() const -> own<ImportType*> {
auto ImportType::copy() const -> own<ImportType> {
return make(module().copy(), name().copy(), type()->copy());
}
......@@ -655,10 +654,10 @@ auto ImportType::type() const -> const ExternType* {
struct ExportTypeImpl {
Name name;
own<ExternType*> type;
own<ExternType> type;
ExportTypeImpl(Name& name, // NOLINT(runtime/references)
own<ExternType*>& type) // NOLINT(runtime/references)
ExportTypeImpl(Name& name, // NOLINT(runtime/references)
own<ExternType>& type) // NOLINT(runtime/references)
: name(std::move(name)), type(std::move(type)) {}
~ExportTypeImpl() {}
......@@ -673,14 +672,13 @@ ExportType::~ExportType() { impl(this)->~ExportTypeImpl(); }
void ExportType::operator delete(void* p) { ::operator delete(p); }
auto ExportType::make(Name&& name, own<ExternType*>&& type)
-> own<ExportType*> {
return name && type ? own<ExportType*>(seal<ExportType>(
auto ExportType::make(Name&& name, own<ExternType>&& type) -> own<ExportType> {
return name && type ? own<ExportType>(seal<ExportType>(
new (std::nothrow) ExportTypeImpl(name, type)))
: own<ExportType*>();
: own<ExportType>();
}
auto ExportType::copy() const -> own<ExportType*> {
auto ExportType::copy() const -> own<ExportType> {
return make(name().copy(), type()->copy());
}
......@@ -706,7 +704,7 @@ i::Handle<i::String> VecToString(i::Isolate* isolate,
template <class Ref, class JSType>
class RefImpl {
public:
static own<Ref*> make(StoreImpl* store, i::Handle<JSType> obj) {
static own<Ref> make(StoreImpl* store, i::Handle<JSType> obj) {
RefImpl* self = new (std::nothrow) RefImpl();
if (!self) return nullptr;
i::Isolate* isolate = store->i_isolate();
......@@ -724,7 +722,7 @@ class RefImpl {
}
}
own<Ref*> copy() const { return make(store(), v8_object()); }
own<Ref> copy() const { return make(store(), v8_object()); }
StoreImpl* store() const { return StoreImpl::get(isolate()); }
......@@ -781,7 +779,7 @@ Ref::~Ref() {
void Ref::operator delete(void* p) {}
auto Ref::copy() const -> own<Ref*> { return impl(this)->copy(); }
auto Ref::copy() const -> own<Ref> { return impl(this)->copy(); }
auto Ref::same(const Ref* that) const -> bool {
i::HandleScope handle_scope(impl(this)->isolate());
......@@ -802,7 +800,7 @@ void Ref::set_host_info(void* info, void (*finalizer)(void*)) {
namespace {
struct FrameImpl {
FrameImpl(own<Instance*>&& instance, uint32_t func_index, size_t func_offset,
FrameImpl(own<Instance>&& instance, uint32_t func_index, size_t func_offset,
size_t module_offset)
: instance(std::move(instance)),
func_index(func_index),
......@@ -811,7 +809,7 @@ struct FrameImpl {
~FrameImpl() {}
own<Instance*> instance;
own<Instance> instance;
uint32_t func_index;
size_t func_offset;
size_t module_offset;
......@@ -828,9 +826,9 @@ Frame::~Frame() { impl(this)->~FrameImpl(); }
void Frame::operator delete(void* p) { ::operator delete(p); }
own<Frame*> Frame::copy() const {
own<Frame> Frame::copy() const {
auto self = impl(this);
return own<Frame*>(seal<Frame>(
return own<Frame>(seal<Frame>(
new (std::nothrow) FrameImpl(self->instance->copy(), self->func_index,
self->func_offset, self->module_offset)));
}
......@@ -852,9 +850,9 @@ struct implement<Trap> {
Trap::~Trap() {}
auto Trap::copy() const -> own<Trap*> { return impl(this)->copy(); }
auto Trap::copy() const -> own<Trap> { return impl(this)->copy(); }
auto Trap::make(Store* store_abs, const Message& message) -> own<Trap*> {
auto Trap::make(Store* store_abs, const Message& message) -> own<Trap> {
auto store = impl(store_abs);
i::Isolate* isolate = store->i_isolate();
i::HandleScope handle_scope(isolate);
......@@ -880,11 +878,11 @@ auto Trap::message() const -> Message {
namespace {
own<Instance*> GetInstance(StoreImpl* store,
i::Handle<i::WasmInstanceObject> instance);
own<Instance> GetInstance(StoreImpl* store,
i::Handle<i::WasmInstanceObject> instance);
own<Frame*> CreateFrameFromInternal(i::Handle<i::FixedArray> frames, int index,
i::Isolate* isolate, StoreImpl* store) {
own<Frame> CreateFrameFromInternal(i::Handle<i::FixedArray> frames, int index,
i::Isolate* isolate, StoreImpl* store) {
i::Handle<i::StackTraceFrame> frame(i::StackTraceFrame::cast(frames->get(0)),
isolate);
i::Handle<i::WasmInstanceObject> instance =
......@@ -892,13 +890,13 @@ own<Frame*> CreateFrameFromInternal(i::Handle<i::FixedArray> frames, int index,
uint32_t func_index = i::StackTraceFrame::GetLineNumber(frame);
size_t func_offset = i::StackTraceFrame::GetFunctionOffset(frame);
size_t module_offset = i::StackTraceFrame::GetColumnNumber(frame);
return own<Frame*>(seal<Frame>(new (std::nothrow) FrameImpl(
return own<Frame>(seal<Frame>(new (std::nothrow) FrameImpl(
GetInstance(store, instance), func_index, func_offset, module_offset)));
}
} // namespace
own<Frame*> Trap::origin() const {
own<Frame> Trap::origin() const {
i::Isolate* isolate = impl(this)->isolate();
i::HandleScope handle_scope(isolate);
......@@ -910,7 +908,7 @@ own<Frame*> Trap::origin() const {
return CreateFrameFromInternal(frames, 0, isolate, impl(this)->store());
}
vec<Frame*> Trap::trace() const {
ownvec<Frame> Trap::trace() const {
i::Isolate* isolate = impl(this)->isolate();
i::HandleScope handle_scope(isolate);
......@@ -920,7 +918,7 @@ vec<Frame*> Trap::trace() const {
isolate);
int num_frames = frames->length();
DCHECK_GT(num_frames, 0);
vec<Frame*> result = vec<Frame*>::make_uninitialized(num_frames);
ownvec<Frame> result = ownvec<Frame>::make_uninitialized(num_frames);
for (int i = 0; i < num_frames; i++) {
result[i] =
CreateFrameFromInternal(frames, i, isolate, impl(this)->store());
......@@ -937,9 +935,9 @@ struct implement<Foreign> {
Foreign::~Foreign() {}
auto Foreign::copy() const -> own<Foreign*> { return impl(this)->copy(); }
auto Foreign::copy() const -> own<Foreign> { return impl(this)->copy(); }
auto Foreign::make(Store* store_abs) -> own<Foreign*> {
auto Foreign::make(Store* store_abs) -> own<Foreign> {
StoreImpl* store = impl(store_abs);
i::Isolate* isolate = store->i_isolate();
i::HandleScope handle_scope(isolate);
......@@ -958,7 +956,7 @@ struct implement<Module> {
Module::~Module() {}
auto Module::copy() const -> own<Module*> { return impl(this)->copy(); }
auto Module::copy() const -> own<Module> { return impl(this)->copy(); }
auto Module::validate(Store* store_abs, const vec<byte_t>& binary) -> bool {
i::wasm::ModuleWireBytes bytes(
......@@ -975,7 +973,7 @@ class NopErrorThrower : public i::wasm::ErrorThrower {
~NopErrorThrower() { Reset(); }
};
auto Module::make(Store* store_abs, const vec<byte_t>& binary) -> own<Module*> {
auto Module::make(Store* store_abs, const vec<byte_t>& binary) -> own<Module> {
StoreImpl* store = impl(store_abs);
i::Isolate* isolate = store->i_isolate();
i::HandleScope scope(isolate);
......@@ -992,42 +990,42 @@ auto Module::make(Store* store_abs, const vec<byte_t>& binary) -> own<Module*> {
return implement<Module>::type::make(store, module);
}
auto Module::imports() const -> vec<ImportType*> {
auto Module::imports() const -> ownvec<ImportType> {
const i::wasm::NativeModule* native_module =
impl(this)->v8_object()->native_module();
const i::wasm::WasmModule* module = native_module->module();
const i::Vector<const uint8_t> wire_bytes = native_module->wire_bytes();
const std::vector<i::wasm::WasmImport>& import_table = module->import_table;
size_t size = import_table.size();
vec<ImportType*> imports = vec<ImportType*>::make_uninitialized(size);
ownvec<ImportType> imports = ownvec<ImportType>::make_uninitialized(size);
for (uint32_t i = 0; i < size; i++) {
const i::wasm::WasmImport& imp = import_table[i];
Name module_name = GetNameFromWireBytes(imp.module_name, wire_bytes);
Name name = GetNameFromWireBytes(imp.field_name, wire_bytes);
own<ExternType*> type = GetImportExportType(module, imp.kind, imp.index);
own<ExternType> type = GetImportExportType(module, imp.kind, imp.index);
imports[i] = ImportType::make(std::move(module_name), std::move(name),
std::move(type));
}
return imports;
}
vec<ExportType*> ExportsImpl(i::Handle<i::WasmModuleObject> module_obj) {
ownvec<ExportType> ExportsImpl(i::Handle<i::WasmModuleObject> module_obj) {
const i::wasm::NativeModule* native_module = module_obj->native_module();
const i::wasm::WasmModule* module = native_module->module();
const i::Vector<const uint8_t> wire_bytes = native_module->wire_bytes();
const std::vector<i::wasm::WasmExport>& export_table = module->export_table;
size_t size = export_table.size();
vec<ExportType*> exports = vec<ExportType*>::make_uninitialized(size);
ownvec<ExportType> exports = ownvec<ExportType>::make_uninitialized(size);
for (uint32_t i = 0; i < size; i++) {
const i::wasm::WasmExport& exp = export_table[i];
Name name = GetNameFromWireBytes(exp.name, wire_bytes);
own<ExternType*> type = GetImportExportType(module, exp.kind, exp.index);
own<ExternType> type = GetImportExportType(module, exp.kind, exp.index);
exports[i] = ExportType::make(std::move(name), std::move(type));
}
return exports;
}
auto Module::exports() const -> vec<ExportType*> {
auto Module::exports() const -> ownvec<ExportType> {
return ExportsImpl(impl(this)->v8_object());
}
......@@ -1050,11 +1048,11 @@ auto Module::serialize() const -> vec<byte_t> {
{reinterpret_cast<uint8_t*>(ptr), serial_size})) {
buffer.reset();
}
return std::move(buffer);
return buffer;
}
auto Module::deserialize(Store* store_abs, const vec<byte_t>& serialized)
-> own<Module*> {
-> own<Module> {
StoreImpl* store = impl(store_abs);
i::Isolate* isolate = store->i_isolate();
i::HandleScope handle_scope(isolate);
......@@ -1090,13 +1088,12 @@ void Shared<Module>::operator delete(void* p) {
::operator delete(p);
}
auto Module::share() const -> own<Shared<Module>*> {
auto Module::share() const -> own<Shared<Module>> {
auto shared = seal<Shared<Module>>(new vec<byte_t>(serialize()));
return make_own(shared);
}
auto Module::obtain(Store* store, const Shared<Module>* shared)
-> own<Module*> {
auto Module::obtain(Store* store, const Shared<Module>* shared) -> own<Module> {
return Module::deserialize(store, *impl(shared));
}
......@@ -1109,7 +1106,7 @@ struct implement<Extern> {
Extern::~Extern() {}
auto Extern::copy() const -> own<Extern*> { return impl(this)->copy(); }
auto Extern::copy() const -> own<Extern> { return impl(this)->copy(); }
auto Extern::kind() const -> ExternKind {
i::Handle<i::JSReceiver> obj = impl(this)->v8_object();
......@@ -1122,7 +1119,7 @@ auto Extern::kind() const -> ExternKind {
UNREACHABLE();
}
auto Extern::type() const -> own<ExternType*> {
auto Extern::type() const -> own<ExternType> {
switch (kind()) {
case EXTERN_FUNC:
return func()->type();
......@@ -1180,11 +1177,11 @@ struct implement<Func> {
Func::~Func() {}
auto Func::copy() const -> own<Func*> { return impl(this)->copy(); }
auto Func::copy() const -> own<Func> { return impl(this)->copy(); }
struct FuncData {
Store* store;
own<FuncType*> type;
own<FuncType> type;
enum Kind { kCallback, kCallbackWithEnv } kind;
union {
Func::callback callback;
......@@ -1238,11 +1235,11 @@ class SignatureHelper : public i::AllStatic {
return sig;
}
static own<FuncType*> Deserialize(i::PodArray<i::wasm::ValueType> sig) {
static own<FuncType> Deserialize(i::PodArray<i::wasm::ValueType> sig) {
int result_arity = ResultArity(sig);
int param_arity = sig.length() - result_arity - 1;
vec<ValType*> results = vec<ValType*>::make_uninitialized(result_arity);
vec<ValType*> params = vec<ValType*>::make_uninitialized(param_arity);
ownvec<ValType> results = ownvec<ValType>::make_uninitialized(result_arity);
ownvec<ValType> params = ownvec<ValType>::make_uninitialized(param_arity);
int i = 0;
for (; i < result_arity; ++i) {
......@@ -1273,7 +1270,7 @@ class SignatureHelper : public i::AllStatic {
}
};
auto make_func(Store* store_abs, FuncData* data) -> own<Func*> {
auto make_func(Store* store_abs, FuncData* data) -> own<Func> {
auto store = impl(store_abs);
i::Isolate* isolate = store->i_isolate();
i::HandleScope handle_scope(isolate);
......@@ -1288,14 +1285,14 @@ auto make_func(Store* store_abs, FuncData* data) -> own<Func*> {
} // namespace
auto Func::make(Store* store, const FuncType* type, Func::callback callback)
-> own<Func*> {
-> own<Func> {
auto data = new FuncData(store, type, FuncData::kCallback);
data->callback = callback;
return make_func(store, data);
}
auto Func::make(Store* store, const FuncType* type, callback_with_env callback,
void* env, void (*finalizer)(void*)) -> own<Func*> {
void* env, void (*finalizer)(void*)) -> own<Func> {
auto data = new FuncData(store, type, FuncData::kCallbackWithEnv);
data->callback_with_env = callback;
data->env = env;
......@@ -1303,7 +1300,7 @@ auto Func::make(Store* store, const FuncType* type, callback_with_env callback,
return make_func(store, data);
}
auto Func::type() const -> own<FuncType*> {
auto Func::type() const -> own<FuncType> {
i::Handle<i::JSFunction> func = impl(this)->v8_object();
if (i::WasmCapiFunction::IsWasmCapiFunction(*func)) {
return SignatureHelper::Deserialize(SignatureHelper::GetSig(func));
......@@ -1441,8 +1438,8 @@ void PopArgs(i::wasm::FunctionSig* sig, Val results[],
}
}
own<Trap*> CallWasmCapiFunction(i::WasmCapiFunctionData data, const Val args[],
Val results[]) {
own<Trap> CallWasmCapiFunction(i::WasmCapiFunctionData data, const Val args[],
Val results[]) {
FuncData* func_data = reinterpret_cast<FuncData*>(data.embedder_data());
if (func_data->kind == FuncData::kCallback) {
return (func_data->callback)(args, results);
......@@ -1453,7 +1450,7 @@ own<Trap*> CallWasmCapiFunction(i::WasmCapiFunctionData data, const Val args[],
} // namespace
auto Func::call(const Val args[], Val results[]) const -> own<Trap*> {
auto Func::call(const Val args[], Val results[]) const -> own<Trap> {
auto func = impl(this);
auto store = func->store();
auto isolate = store->i_isolate();
......@@ -1533,8 +1530,8 @@ i::Address FuncData::v8_callback(void* data, i::Address argv) {
i::Isolate* isolate = impl(self->store)->i_isolate();
i::HandleScope scope(isolate);
const vec<ValType*>& param_types = self->type->params();
const vec<ValType*>& result_types = self->type->results();
const ownvec<ValType>& param_types = self->type->params();
const ownvec<ValType>& result_types = self->type->results();
int num_param_types = static_cast<int>(param_types.size());
int num_result_types = static_cast<int>(result_types.size());
......@@ -1576,7 +1573,7 @@ i::Address FuncData::v8_callback(void* data, i::Address argv) {
}
}
own<Trap*> trap;
own<Trap> trap;
if (self->kind == kCallbackWithEnv) {
trap = self->callback_with_env(self->env, params.get(), results.get());
} else {
......@@ -1638,10 +1635,10 @@ struct implement<Global> {
Global::~Global() {}
auto Global::copy() const -> own<Global*> { return impl(this)->copy(); }
auto Global::copy() const -> own<Global> { return impl(this)->copy(); }
auto Global::make(Store* store_abs, const GlobalType* type, const Val& val)
-> own<Global*> {
-> own<Global> {
StoreImpl* store = impl(store_abs);
i::Isolate* isolate = store->i_isolate();
i::HandleScope handle_scope(isolate);
......@@ -1663,7 +1660,7 @@ auto Global::make(Store* store_abs, const GlobalType* type, const Val& val)
return global;
}
auto Global::type() const -> own<GlobalType*> {
auto Global::type() const -> own<GlobalType> {
i::Handle<i::WasmGlobalObject> v8_global = impl(this)->v8_object();
ValKind kind = V8ValueTypeToWasm(v8_global->type());
Mutability mutability = v8_global->is_mutable() ? VAR : CONST;
......@@ -1732,10 +1729,10 @@ struct implement<Table> {
Table::~Table() {}
auto Table::copy() const -> own<Table*> { return impl(this)->copy(); }
auto Table::copy() const -> own<Table> { return impl(this)->copy(); }
auto Table::make(Store* store_abs, const TableType* type, const Ref* ref)
-> own<Table*> {
-> own<Table> {
StoreImpl* store = impl(store_abs);
i::Isolate* isolate = store->i_isolate();
i::HandleScope scope(isolate);
......@@ -1784,7 +1781,7 @@ auto Table::make(Store* store_abs, const TableType* type, const Ref* ref)
return implement<Table>::type::make(store, table_obj);
}
auto Table::type() const -> own<TableType*> {
auto Table::type() const -> own<TableType> {
i::Handle<i::WasmTableObject> table = impl(this)->v8_object();
uint32_t min = table->current_length();
uint32_t max;
......@@ -1803,14 +1800,14 @@ auto Table::type() const -> own<TableType*> {
return TableType::make(ValType::make(kind), Limits(min, max));
}
auto Table::get(size_t index) const -> own<Ref*> {
auto Table::get(size_t index) const -> own<Ref> {
i::Handle<i::WasmTableObject> table = impl(this)->v8_object();
if (index >= table->current_length()) return own<Ref*>();
if (index >= table->current_length()) return own<Ref>();
i::Isolate* isolate = table->GetIsolate();
i::HandleScope handle_scope(isolate);
i::Handle<i::Object> result =
i::WasmTableObject::Get(isolate, table, static_cast<uint32_t>(index));
if (result->IsNull(isolate)) return own<Ref*>();
if (result->IsNull(isolate)) return own<Ref>();
// TODO(jkummerow): If we support both JavaScript and the C-API at the same
// time, we need to handle Smis and other JS primitives here.
DCHECK(result->IsJSReceiver());
......@@ -1858,9 +1855,9 @@ struct implement<Memory> {
Memory::~Memory() {}
auto Memory::copy() const -> own<Memory*> { return impl(this)->copy(); }
auto Memory::copy() const -> own<Memory> { return impl(this)->copy(); }
auto Memory::make(Store* store_abs, const MemoryType* type) -> own<Memory*> {
auto Memory::make(Store* store_abs, const MemoryType* type) -> own<Memory> {
StoreImpl* store = impl(store_abs);
i::Isolate* isolate = store->i_isolate();
i::HandleScope scope(isolate);
......@@ -1877,12 +1874,12 @@ auto Memory::make(Store* store_abs, const MemoryType* type) -> own<Memory*> {
i::Handle<i::WasmMemoryObject> memory_obj;
if (!i::WasmMemoryObject::New(isolate, minimum, maximum, is_shared)
.ToHandle(&memory_obj)) {
return own<Memory*>();
return own<Memory>();
}
return implement<Memory>::type::make(store, memory_obj);
}
auto Memory::type() const -> own<MemoryType*> {
auto Memory::type() const -> own<MemoryType> {
i::Handle<i::WasmMemoryObject> memory = impl(this)->v8_object();
uint32_t min = static_cast<uint32_t>(memory->array_buffer().byte_length() /
i::wasm::kWasmPageSize);
......@@ -1923,10 +1920,10 @@ struct implement<Instance> {
Instance::~Instance() {}
auto Instance::copy() const -> own<Instance*> { return impl(this)->copy(); }
auto Instance::copy() const -> own<Instance> { return impl(this)->copy(); }
auto Instance::make(Store* store_abs, const Module* module_abs,
const Extern* const imports[]) -> own<Instance*> {
const Extern* const imports[]) -> own<Instance> {
StoreImpl* store = impl(store_abs);
const implement<Module>::type* module = impl(module_abs);
i::Isolate* isolate = store->i_isolate();
......@@ -1934,11 +1931,11 @@ auto Instance::make(Store* store_abs, const Module* module_abs,
DCHECK_EQ(module->v8_object()->GetIsolate(), isolate);
vec<ImportType*> import_types = module_abs->imports();
ownvec<ImportType> import_types = module_abs->imports();
i::Handle<i::JSObject> imports_obj =
isolate->factory()->NewJSObject(isolate->object_function());
for (size_t i = 0; i < import_types.size(); ++i) {
auto type = import_types[i];
ImportType* type = import_types[i].get();
i::Handle<i::String> module_str = VecToString(isolate, type->module());
i::Handle<i::String> name_str = VecToString(isolate, type->name());
......@@ -1968,14 +1965,14 @@ auto Instance::make(Store* store_abs, const Module* module_abs,
namespace {
own<Instance*> GetInstance(StoreImpl* store,
i::Handle<i::WasmInstanceObject> instance) {
own<Instance> GetInstance(StoreImpl* store,
i::Handle<i::WasmInstanceObject> instance) {
return implement<Instance>::type::make(store, instance);
}
} // namespace
auto Instance::exports() const -> vec<Extern*> {
auto Instance::exports() const -> ownvec<Extern> {
const implement<Instance>::type* instance = impl(this);
StoreImpl* store = instance->store();
i::Isolate* isolate = store->i_isolate();
......@@ -1985,9 +1982,10 @@ auto Instance::exports() const -> vec<Extern*> {
isolate);
i::Handle<i::JSObject> exports_obj(instance_obj->exports_object(), isolate);
vec<ExportType*> export_types = ExportsImpl(module_obj);
vec<Extern*> exports = vec<Extern*>::make_uninitialized(export_types.size());
if (!exports) return vec<Extern*>::invalid();
ownvec<ExportType> export_types = ExportsImpl(module_obj);
ownvec<Extern> exports =
ownvec<Extern>::make_uninitialized(export_types.size());
if (!exports) return ownvec<Extern>::invalid();
for (size_t i = 0; i < export_types.size(); ++i) {
auto& name = export_types[i]->name();
......@@ -2000,20 +1998,20 @@ auto Instance::exports() const -> vec<Extern*> {
switch (type->kind()) {
case EXTERN_FUNC: {
DCHECK(i::WasmExportedFunction::IsWasmExportedFunction(*obj));
exports[i].reset(implement<Func>::type::make(
store, i::Handle<i::WasmExportedFunction>::cast(obj)));
exports[i] = implement<Func>::type::make(
store, i::Handle<i::WasmExportedFunction>::cast(obj));
} break;
case EXTERN_GLOBAL: {
exports[i].reset(implement<Global>::type::make(
store, i::Handle<i::WasmGlobalObject>::cast(obj)));
exports[i] = implement<Global>::type::make(
store, i::Handle<i::WasmGlobalObject>::cast(obj));
} break;
case EXTERN_TABLE: {
exports[i].reset(implement<Table>::type::make(
store, i::Handle<i::WasmTableObject>::cast(obj)));
exports[i] = implement<Table>::type::make(
store, i::Handle<i::WasmTableObject>::cast(obj));
} break;
case EXTERN_MEMORY: {
exports[i].reset(implement<Memory>::type::make(
store, i::Handle<i::WasmMemoryObject>::cast(obj)));
exports[i] = implement<Memory>::type::make(
store, i::Handle<i::WasmMemoryObject>::cast(obj));
} break;
}
}
......@@ -2065,103 +2063,84 @@ struct borrowed_vec {
->const Name* { \
return x; \
} \
extern "C++" inline auto get_##name(wasm::own<Name*>& x)->wasm_##name##_t* { \
extern "C++" inline auto get_##name(wasm::own<Name>& x)->wasm_##name##_t* { \
return hide_##name(x.get()); \
} \
extern "C++" inline auto get_##name(const wasm::own<Name*>& x) \
extern "C++" inline auto get_##name(const wasm::own<Name>& x) \
->const wasm_##name##_t* { \
return hide_##name(x.get()); \
} \
extern "C++" inline auto release_##name(wasm::own<Name*>&& x) \
extern "C++" inline auto release_##name(wasm::own<Name>&& x) \
->wasm_##name##_t* { \
return hide_##name(x.release()); \
} \
extern "C++" inline auto adopt_##name(wasm_##name##_t* x) \
->wasm::own<Name*> { \
extern "C++" inline auto adopt_##name(wasm_##name##_t* x)->wasm::own<Name> { \
return make_own(x); \
}
// Vectors
#define WASM_DEFINE_VEC_BASE(name, Name, ptr_or_none) \
extern "C++" inline auto hide_##name##_vec(wasm::vec<Name ptr_or_none>& v) \
#define WASM_DEFINE_VEC_BASE(name, Name, vec, ptr_or_none) \
static_assert(sizeof(wasm_##name##_vec_t) == sizeof(vec<Name>), \
"C/C++ incompatibility"); \
static_assert( \
sizeof(wasm_##name##_t ptr_or_none) == sizeof(vec<Name>::elem_type), \
"C/C++ incompatibility"); \
extern "C++" inline auto hide_##name##_vec(vec<Name>& v) \
->wasm_##name##_vec_t* { \
static_assert( \
sizeof(wasm_##name##_vec_t) == sizeof(wasm::vec<Name ptr_or_none>), \
"C/C++ incompatibility"); \
return reinterpret_cast<wasm_##name##_vec_t*>(&v); \
} \
extern "C++" inline auto hide_##name##_vec( \
const wasm::vec<Name ptr_or_none>& v) \
extern "C++" inline auto hide_##name##_vec(const vec<Name>& v) \
->const wasm_##name##_vec_t* { \
static_assert( \
sizeof(wasm_##name##_vec_t) == sizeof(wasm::vec<Name ptr_or_none>), \
"C/C++ incompatibility"); \
return reinterpret_cast<const wasm_##name##_vec_t*>(&v); \
} \
extern "C++" inline auto hide_##name##_vec(Name ptr_or_none* v) \
extern "C++" inline auto hide_##name##_vec(vec<Name>::elem_type* v) \
->wasm_##name##_t ptr_or_none* { \
static_assert( \
sizeof(wasm_##name##_t ptr_or_none) == sizeof(Name ptr_or_none), \
"C/C++ incompatibility"); \
return reinterpret_cast<wasm_##name##_t ptr_or_none*>(v); \
} \
extern "C++" inline auto hide_##name##_vec(Name ptr_or_none const* v) \
extern "C++" inline auto hide_##name##_vec(const vec<Name>::elem_type* v) \
->wasm_##name##_t ptr_or_none const* { \
static_assert( \
sizeof(wasm_##name##_t ptr_or_none) == sizeof(Name ptr_or_none), \
"C/C++ incompatibility"); \
return reinterpret_cast<wasm_##name##_t ptr_or_none const*>(v); \
} \
extern "C++" inline auto reveal_##name##_vec(wasm_##name##_t ptr_or_none* v) \
->Name ptr_or_none* { \
static_assert( \
sizeof(wasm_##name##_t ptr_or_none) == sizeof(Name ptr_or_none), \
"C/C++ incompatibility"); \
return reinterpret_cast<Name ptr_or_none*>(v); \
->vec<Name>::elem_type* { \
return reinterpret_cast<vec<Name>::elem_type*>(v); \
} \
extern "C++" inline auto reveal_##name##_vec( \
wasm_##name##_t ptr_or_none const* v) \
->Name ptr_or_none const* { \
static_assert( \
sizeof(wasm_##name##_t ptr_or_none) == sizeof(Name ptr_or_none), \
"C/C++ incompatibility"); \
return reinterpret_cast<Name ptr_or_none const*>(v); \
->const vec<Name>::elem_type* { \
return reinterpret_cast<const vec<Name>::elem_type*>(v); \
} \
extern "C++" inline auto get_##name##_vec(wasm::vec<Name ptr_or_none>& v) \
extern "C++" inline auto get_##name##_vec(vec<Name>& v) \
->wasm_##name##_vec_t { \
wasm_##name##_vec_t v2 = {v.size(), hide_##name##_vec(v.get())}; \
return v2; \
} \
extern "C++" inline auto get_##name##_vec( \
const wasm::vec<Name ptr_or_none>& v) \
extern "C++" inline auto get_##name##_vec(const vec<Name>& v) \
->const wasm_##name##_vec_t { \
wasm_##name##_vec_t v2 = { \
v.size(), \
const_cast<wasm_##name##_t ptr_or_none*>(hide_##name##_vec(v.get()))}; \
return v2; \
} \
extern "C++" inline auto release_##name##_vec( \
wasm::vec<Name ptr_or_none>&& v) \
extern "C++" inline auto release_##name##_vec(vec<Name>&& v) \
->wasm_##name##_vec_t { \
wasm_##name##_vec_t v2 = {v.size(), hide_##name##_vec(v.release())}; \
return v2; \
} \
extern "C++" inline auto adopt_##name##_vec(wasm_##name##_vec_t* v) \
->wasm::vec<Name ptr_or_none> { \
return wasm::vec<Name ptr_or_none>::adopt(v->size, \
reveal_##name##_vec(v->data)); \
->vec<Name> { \
return vec<Name>::adopt(v->size, reveal_##name##_vec(v->data)); \
} \
extern "C++" inline auto borrow_##name##_vec(const wasm_##name##_vec_t* v) \
->borrowed_vec<Name ptr_or_none> { \
return borrowed_vec<Name ptr_or_none>(wasm::vec<Name ptr_or_none>::adopt( \
v->size, reveal_##name##_vec(v->data))); \
->borrowed_vec<vec<Name>::elem_type> { \
return borrowed_vec<vec<Name>::elem_type>( \
vec<Name>::adopt(v->size, reveal_##name##_vec(v->data))); \
} \
\
void wasm_##name##_vec_new_uninitialized(wasm_##name##_vec_t* out, \
size_t size) { \
*out = release_##name##_vec( \
wasm::vec<Name ptr_or_none>::make_uninitialized(size)); \
*out = release_##name##_vec(vec<Name>::make_uninitialized(size)); \
} \
void wasm_##name##_vec_new_empty(wasm_##name##_vec_t* out) { \
wasm_##name##_vec_new_uninitialized(out, 0); \
......@@ -2172,43 +2151,44 @@ struct borrowed_vec {
}
// Vectors with no ownership management of elements
#define WASM_DEFINE_VEC_PLAIN(name, Name, ptr_or_none) \
WASM_DEFINE_VEC_BASE(name, Name, ptr_or_none) \
\
void wasm_##name##_vec_new(wasm_##name##_vec_t* out, size_t size, \
wasm_##name##_t ptr_or_none const data[]) { \
auto v2 = wasm::vec<Name ptr_or_none>::make_uninitialized(size); \
if (v2.size() != 0) { \
memcpy(v2.get(), data, size * sizeof(wasm_##name##_t ptr_or_none)); \
} \
*out = release_##name##_vec(std::move(v2)); \
} \
\
void wasm_##name##_vec_copy(wasm_##name##_vec_t* out, \
wasm_##name##_vec_t* v) { \
wasm_##name##_vec_new(out, v->size, v->data); \
#define WASM_DEFINE_VEC_PLAIN(name, Name) \
WASM_DEFINE_VEC_BASE(name, Name, \
wasm::vec, ) /* NOLINT(whitespace/parens) */ \
\
void wasm_##name##_vec_new(wasm_##name##_vec_t* out, size_t size, \
const wasm_##name##_t data[]) { \
auto v2 = wasm::vec<Name>::make_uninitialized(size); \
if (v2.size() != 0) { \
memcpy(v2.get(), data, size * sizeof(wasm_##name##_t)); \
} \
*out = release_##name##_vec(std::move(v2)); \
} \
\
void wasm_##name##_vec_copy(wasm_##name##_vec_t* out, \
wasm_##name##_vec_t* v) { \
wasm_##name##_vec_new(out, v->size, v->data); \
}
// Vectors that own their elements
#define WASM_DEFINE_VEC(name, Name, ptr_or_none) \
WASM_DEFINE_VEC_BASE(name, Name, ptr_or_none) \
\
void wasm_##name##_vec_new(wasm_##name##_vec_t* out, size_t size, \
wasm_##name##_t ptr_or_none const data[]) { \
auto v2 = wasm::vec<Name ptr_or_none>::make_uninitialized(size); \
for (size_t i = 0; i < v2.size(); ++i) { \
v2[i] = adopt_##name(data[i]); \
} \
*out = release_##name##_vec(std::move(v2)); \
} \
\
void wasm_##name##_vec_copy(wasm_##name##_vec_t* out, \
wasm_##name##_vec_t* v) { \
auto v2 = wasm::vec<Name ptr_or_none>::make_uninitialized(v->size); \
for (size_t i = 0; i < v2.size(); ++i) { \
v2[i] = adopt_##name(wasm_##name##_copy(v->data[i])); \
} \
*out = release_##name##_vec(std::move(v2)); \
#define WASM_DEFINE_VEC_OWN(name, Name) \
WASM_DEFINE_VEC_BASE(name, Name, wasm::ownvec, *) \
\
void wasm_##name##_vec_new(wasm_##name##_vec_t* out, size_t size, \
wasm_##name##_t* const data[]) { \
auto v2 = wasm::ownvec<Name>::make_uninitialized(size); \
for (size_t i = 0; i < v2.size(); ++i) { \
v2[i] = adopt_##name(data[i]); \
} \
*out = release_##name##_vec(std::move(v2)); \
} \
\
void wasm_##name##_vec_copy(wasm_##name##_vec_t* out, \
wasm_##name##_vec_t* v) { \
auto v2 = wasm::ownvec<Name>::make_uninitialized(v->size); \
for (size_t i = 0; i < v2.size(); ++i) { \
v2[i] = adopt_##name(wasm_##name##_copy(v->data[i])); \
} \
*out = release_##name##_vec(std::move(v2)); \
}
extern "C++" {
......@@ -2221,7 +2201,7 @@ inline auto is_empty(T* p) -> bool {
// Byte vectors
using byte = byte_t;
WASM_DEFINE_VEC_PLAIN(byte, byte, )
WASM_DEFINE_VEC_PLAIN(byte, byte)
///////////////////////////////////////////////////////////////////////////////
// Runtime Environment
......@@ -2300,7 +2280,7 @@ extern "C++" inline auto reveal_externkind(wasm_externkind_enum kind)
#define WASM_DEFINE_TYPE(name, Name) \
WASM_DEFINE_OWN(name, Name) \
WASM_DEFINE_VEC(name, Name, *) \
WASM_DEFINE_VEC_OWN(name, Name) \
\
wasm_##name##_t* wasm_##name##_copy(wasm_##name##_t* t) { \
return release_##name(t->copy()); \
......@@ -2680,7 +2660,7 @@ inline auto borrow_val(const wasm_val_t* v) -> borrowed_val {
} // extern "C++"
WASM_DEFINE_VEC_BASE(val, wasm::Val, )
WASM_DEFINE_VEC_BASE(val, wasm::Val, wasm::vec, )
void wasm_val_vec_new(wasm_val_vec_t* out, size_t size,
wasm_val_t const data[]) {
......@@ -2720,7 +2700,7 @@ void wasm_val_copy(wasm_val_t* out, const wasm_val_t* v) {
// Frames
WASM_DEFINE_OWN(frame, wasm::Frame)
WASM_DEFINE_VEC(frame, wasm::Frame, *)
WASM_DEFINE_VEC_OWN(frame, wasm::Frame)
wasm_frame_t* wasm_frame_copy(const wasm_frame_t* frame) {
return release_frame(frame->copy());
......@@ -2821,7 +2801,7 @@ WASM_DEFINE_REF(func, wasm::Func)
extern "C++" {
auto wasm_callback(void* env, const wasm::Val args[], wasm::Val results[])
-> wasm::own<wasm::Trap*> {
-> wasm::own<wasm::Trap> {
auto f = reinterpret_cast<wasm_func_callback_t>(env);
return adopt_trap(f(hide_val_vec(args), hide_val_vec(results)));
}
......@@ -2833,7 +2813,7 @@ struct wasm_callback_env_t {
};
auto wasm_callback_with_env(void* env, const wasm::Val args[],
wasm::Val results[]) -> wasm::own<wasm::Trap*> {
wasm::Val results[]) -> wasm::own<wasm::Trap> {
auto t = static_cast<wasm_callback_env_t*>(env);
return adopt_trap(
t->callback(t->env, hide_val_vec(args), hide_val_vec(results)));
......@@ -2965,7 +2945,7 @@ bool wasm_memory_grow(wasm_memory_t* memory, wasm_memory_pages_t delta) {
// Externals
WASM_DEFINE_REF(extern, wasm::Extern)
WASM_DEFINE_VEC(extern, wasm::Extern, *)
WASM_DEFINE_VEC_OWN(extern, wasm::Extern)
wasm_externkind_t wasm_extern_kind(const wasm_extern_t* external) {
return hide_externkind(external->kind());
......@@ -3051,7 +3031,7 @@ wasm_instance_t* wasm_frame_instance(const wasm_frame_t* frame) {
#undef WASM_DEFINE_OWN
#undef WASM_DEFINE_VEC_BASE
#undef WASM_DEFINE_VEC_PLAIN
#undef WASM_DEFINE_VEC
#undef WASM_DEFINE_VEC_OWN
#undef WASM_DEFINE_TYPE
#undef WASM_DEFINE_REF_BASE
#undef WASM_DEFINE_REF
......
......@@ -28,7 +28,7 @@ class StoreImpl {
}
private:
friend own<Store*> Store::make(Engine*);
friend own<Store> Store::make(Engine*);
StoreImpl() {}
......
......@@ -14,11 +14,11 @@ namespace wasm {
namespace {
own<Trap*> Stage2(void* env, const Val args[], Val results[]) {
own<Trap> Stage2(void* env, const Val args[], Val results[]) {
printf("Stage2...\n");
WasmCapiTest* self = reinterpret_cast<WasmCapiTest*>(env);
Func* stage3 = self->GetExportedFunction(1);
own<Trap*> trap = stage3->call(args, results);
own<Trap> trap = stage3->call(args, results);
if (trap) {
printf("Stage2: got exception: %s\n", trap->message().get());
} else {
......@@ -27,7 +27,7 @@ own<Trap*> Stage2(void* env, const Val args[], Val results[]) {
return trap;
}
own<Trap*> Stage4_GC(void* env, const Val args[], Val results[]) {
own<Trap> Stage4_GC(void* env, const Val args[], Val results[]) {
printf("Stage4...\n");
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env);
isolate->heap()->PreciseCollectAllGarbage(
......@@ -57,7 +57,7 @@ class WasmCapiCallbacksTest : public WasmCapiTest {
}
private:
own<Func*> stage2_;
own<Func> stage2_;
};
} // namespace
......@@ -72,7 +72,7 @@ TEST_F(WasmCapiCallbacksTest, Trap) {
Instantiate(imports);
Val args[] = {Val::i32(42)};
Val results[1];
own<Trap*> trap = GetExportedFunction(0)->call(args, results);
own<Trap> trap = GetExportedFunction(0)->call(args, results);
EXPECT_NE(trap, nullptr);
printf("Stage0: Got trap as expected: %s\n", trap->message().get());
}
......@@ -87,21 +87,21 @@ TEST_F(WasmCapiCallbacksTest, GC) {
i::Isolate* isolate =
reinterpret_cast<::wasm::StoreImpl*>(store())->i_isolate();
own<Func*> stage4 = Func::make(store(), cpp_i_i_sig(), Stage4_GC, isolate);
own<Func> stage4 = Func::make(store(), cpp_i_i_sig(), Stage4_GC, isolate);
EXPECT_EQ(cpp_i_i_sig()->params().size(), stage4->type()->params().size());
EXPECT_EQ(cpp_i_i_sig()->results().size(), stage4->type()->results().size());
Extern* imports[] = {stage2(), stage4.get()};
Instantiate(imports);
Val args[] = {Val::i32(42)};
Val results[1];
own<Trap*> trap = GetExportedFunction(0)->call(args, results);
own<Trap> trap = GetExportedFunction(0)->call(args, results);
EXPECT_EQ(trap, nullptr);
EXPECT_EQ(43, results[0].i32());
}
namespace {
own<Trap*> FibonacciC(void* env, const Val args[], Val results[]) {
own<Trap> FibonacciC(void* env, const Val args[], Val results[]) {
int32_t x = args[0].i32();
if (x == 0 || x == 1) {
results[0] = Val::i32(x);
......@@ -113,7 +113,7 @@ own<Trap*> FibonacciC(void* env, const Val args[], Val results[]) {
// style, but this test intentionally ensures that it works if someone
// insists on doing it.
Val recursive_args[] = {Val::i32(x - 1)};
own<Trap*> trap = fibo_wasm->call(recursive_args, results);
own<Trap> trap = fibo_wasm->call(recursive_args, results);
DCHECK_NULL(trap);
int32_t x1 = results[0].i32();
recursive_args[0] = Val::i32(x - 2);
......@@ -148,20 +148,20 @@ TEST_F(WasmCapiTest, Recursion) {
AddExportedFunction(CStrVector("fibonacci_wasm"), code_fibo,
sizeof(code_fibo), wasm_i_i_sig());
own<Func*> fibonacci = Func::make(store(), cpp_i_i_sig(), FibonacciC, this);
own<Func> fibonacci = Func::make(store(), cpp_i_i_sig(), FibonacciC, this);
Extern* imports[] = {fibonacci.get()};
Instantiate(imports);
// Enough iterations to make it interesting, few enough to keep it fast.
Val args[] = {Val::i32(15)};
Val results[1];
own<Trap*> result = GetExportedFunction(0)->call(args, results);
own<Trap> result = GetExportedFunction(0)->call(args, results);
EXPECT_EQ(result, nullptr);
EXPECT_EQ(610, results[0].i32());
}
namespace {
own<Trap*> PlusOne(const Val args[], Val results[]) {
own<Trap> PlusOne(const Val args[], Val results[]) {
int32_t a0 = args[0].i32();
results[0] = Val::i32(a0 + 1);
int64_t a1 = args[1].i64();
......@@ -177,16 +177,16 @@ own<Trap*> PlusOne(const Val args[], Val results[]) {
} // namespace
TEST_F(WasmCapiTest, DirectCallCapiFunction) {
own<FuncType*> cpp_sig =
FuncType::make(vec<ValType*>::make(
own<FuncType> cpp_sig =
FuncType::make(ownvec<ValType>::make(
ValType::make(::wasm::I32), ValType::make(::wasm::I64),
ValType::make(::wasm::F32), ValType::make(::wasm::F64),
ValType::make(::wasm::ANYREF)),
vec<ValType*>::make(
ownvec<ValType>::make(
ValType::make(::wasm::I32), ValType::make(::wasm::I64),
ValType::make(::wasm::F32), ValType::make(::wasm::F64),
ValType::make(::wasm::ANYREF)));
own<Func*> func = Func::make(store(), cpp_sig.get(), PlusOne);
own<Func> func = Func::make(store(), cpp_sig.get(), PlusOne);
Extern* imports[] = {func.get()};
ValueType wasm_types[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64,
kWasmAnyRef, kWasmI32, kWasmI64, kWasmF32,
......@@ -203,7 +203,7 @@ TEST_F(WasmCapiTest, DirectCallCapiFunction) {
Val::ref(func->copy())};
Val results[5];
// Test that {func} can be called directly.
own<Trap*> trap = func->call(args, results);
own<Trap> trap = func->call(args, results);
EXPECT_EQ(nullptr, trap);
EXPECT_EQ(a0 + 1, results[0].i32());
EXPECT_EQ(a1 + 1, results[1].i64());
......
......@@ -49,15 +49,15 @@ TEST_F(WasmCapiTest, InstanceFinalization) {
static const int kIterations = 10;
for (int iteration = 0; iteration < kIterations; iteration++) {
void* finalizer_data = reinterpret_cast<void*>(iteration);
own<Instance*> instance = Instance::make(store(), module(), nullptr);
own<Instance> instance = Instance::make(store(), module(), nullptr);
EXPECT_NE(nullptr, instance.get());
instance->set_host_info(finalizer_data, &FinalizeInstance);
own<Func*> func = instance->exports()[0]->func()->copy();
own<Func> func = instance->exports()[0]->func()->copy();
ASSERT_NE(func, nullptr);
func->set_host_info(finalizer_data, &FinalizeFunction);
own<Foreign*> foreign = Foreign::make(store());
own<Foreign> foreign = Foreign::make(store());
foreign->set_host_info(finalizer_data, &FinalizeForeign);
}
Shutdown();
......
......@@ -90,21 +90,21 @@ TEST_F(WasmCapiTest, Globals) {
&param_i64);
// Create imported globals.
own<GlobalType*> const_f32_type =
own<GlobalType> const_f32_type =
GlobalType::make(ValType::make(::wasm::F32), ::wasm::CONST);
own<GlobalType*> const_i64_type =
own<GlobalType> const_i64_type =
GlobalType::make(ValType::make(::wasm::I64), ::wasm::CONST);
own<GlobalType*> var_f32_type =
own<GlobalType> var_f32_type =
GlobalType::make(ValType::make(::wasm::F32), ::wasm::VAR);
own<GlobalType*> var_i64_type =
own<GlobalType> var_i64_type =
GlobalType::make(ValType::make(::wasm::I64), ::wasm::VAR);
own<Global*> const_f32_import =
own<Global> const_f32_import =
Global::make(store(), const_f32_type.get(), Val::f32(1));
own<Global*> const_i64_import =
own<Global> const_i64_import =
Global::make(store(), const_i64_type.get(), Val::i64(2));
own<Global*> var_f32_import =
own<Global> var_f32_import =
Global::make(store(), var_f32_type.get(), Val::f32(3));
own<Global*> var_i64_import =
own<Global> var_i64_import =
Global::make(store(), var_i64_type.get(), Val::i64(4));
Extern* imports[] = {const_f32_import.get(), const_i64_import.get(),
var_f32_import.get(), var_i64_import.get()};
......
......@@ -15,7 +15,7 @@ using ::wasm::Message;
namespace {
own<Trap*> IdentityCallback(const Val args[], Val results[]) {
own<Trap> IdentityCallback(const Val args[], Val results[]) {
results[0] = args[0].copy();
return nullptr;
}
......@@ -55,10 +55,10 @@ TEST_F(WasmCapiTest, HostRef) {
AddExportedFunction(CStrVector("func.call"), func_call_code,
sizeof(func_call_code), &r_r_sig);
own<FuncType*> func_type =
FuncType::make(vec<ValType*>::make(ValType::make(::wasm::ANYREF)),
vec<ValType*>::make(ValType::make(::wasm::ANYREF)));
own<Func*> callback = Func::make(store(), func_type.get(), IdentityCallback);
own<FuncType> func_type =
FuncType::make(ownvec<ValType>::make(ValType::make(::wasm::ANYREF)),
ownvec<ValType>::make(ValType::make(::wasm::ANYREF)));
own<Func> callback = Func::make(store(), func_type.get(), IdentityCallback);
Extern* imports[] = {callback.get()};
Instantiate(imports);
......@@ -68,8 +68,8 @@ TEST_F(WasmCapiTest, HostRef) {
const Func* table_get = GetExportedFunction(3);
const Func* func_call = GetExportedFunction(4);
own<Foreign*> host1 = Foreign::make(store());
own<Foreign*> host2 = Foreign::make(store());
own<Foreign> host1 = Foreign::make(store());
own<Foreign> host2 = Foreign::make(store());
host1->set_host_info(reinterpret_cast<void*>(1));
host2->set_host_info(reinterpret_cast<void*>(2));
......@@ -78,14 +78,14 @@ TEST_F(WasmCapiTest, HostRef) {
EXPECT_TRUE(host2->copy()->same(host2.get()));
Val val = Val::ref(host1->copy());
EXPECT_TRUE(val.ref()->copy()->same(host1.get()));
own<Ref*> ref = val.release_ref();
own<Ref> ref = val.release_ref();
EXPECT_EQ(nullptr, val.ref());
EXPECT_TRUE(ref->copy()->same(host1.get()));
// Interact with the Global.
Val args[2];
Val results[1];
own<Trap*> trap = global_get->call(nullptr, results);
own<Trap> trap = global_get->call(nullptr, results);
EXPECT_EQ(nullptr, trap);
EXPECT_EQ(nullptr, results[0].release_ref());
args[0] = Val::ref(host1.get()->copy());
......@@ -100,7 +100,7 @@ TEST_F(WasmCapiTest, HostRef) {
trap = global_get->call(nullptr, results);
EXPECT_EQ(nullptr, trap);
EXPECT_TRUE(results[0].release_ref()->same(host2.get()));
args[0] = Val::ref(own<Ref*>());
args[0] = Val::ref(own<Ref>());
trap = global_set->call(args, nullptr);
EXPECT_EQ(nullptr, trap);
trap = global_get->call(nullptr, results);
......@@ -133,7 +133,7 @@ TEST_F(WasmCapiTest, HostRef) {
EXPECT_EQ(nullptr, trap);
EXPECT_TRUE(results[0].release_ref()->same(host2.get()));
args[0] = Val::i32(0);
args[1] = Val::ref(own<Ref*>());
args[1] = Val::ref(own<Ref>());
trap = table_set->call(args, nullptr);
EXPECT_EQ(nullptr, trap);
trap = table_get->call(args, results);
......@@ -141,7 +141,7 @@ TEST_F(WasmCapiTest, HostRef) {
EXPECT_EQ(nullptr, results[0].release_ref());
// Interact with the Function.
args[0] = Val::ref(own<Ref*>());
args[0] = Val::ref(own<Ref>());
trap = func_call->call(args, results);
EXPECT_EQ(nullptr, trap);
EXPECT_EQ(nullptr, results[0].release_ref());
......
......@@ -73,7 +73,7 @@ TEST_F(WasmCapiTest, Memory) {
EXPECT_EQ(0, result[0].i32());
// load(0x20000) -> trap
args[0] = Val::i32(0x20000);
own<Trap*> trap = load_func->call(args, result);
own<Trap> trap = load_func->call(args, result);
EXPECT_NE(nullptr, trap.get());
// Mutate memory.
......@@ -114,8 +114,8 @@ TEST_F(WasmCapiTest, Memory) {
// Create standalone memory.
// TODO(wasm): Once Wasm allows multiple memories, turn this into an import.
own<MemoryType*> mem_type = MemoryType::make(Limits(5, 5));
own<Memory*> memory2 = Memory::make(store(), mem_type.get());
own<MemoryType> mem_type = MemoryType::make(Limits(5, 5));
own<Memory> memory2 = Memory::make(store(), mem_type.get());
EXPECT_EQ(5u, memory2->size());
EXPECT_EQ(false, memory2->grow(1));
EXPECT_EQ(true, memory2->grow(0));
......
......@@ -51,8 +51,8 @@ TEST_F(WasmCapiTest, Reflect) {
Instantiate(nullptr);
vec<ExportType*> export_types = module()->exports();
const vec<Extern*>& exports = this->exports();
ownvec<ExportType> export_types = module()->exports();
const ownvec<Extern>& exports = this->exports();
EXPECT_EQ(exports.size(), export_types.size());
EXPECT_EQ(4u, exports.size());
for (size_t i = 0; i < exports.size(); i++) {
......@@ -62,13 +62,13 @@ TEST_F(WasmCapiTest, Reflect) {
if (kind == ::wasm::EXTERN_FUNC) {
ExpectName(kFuncName, export_types[i]->name());
const FuncType* type = extern_type->func();
const vec<ValType*>& params = type->params();
const ownvec<ValType>& params = type->params();
EXPECT_EQ(4u, params.size());
EXPECT_EQ(::wasm::I32, params[0]->kind());
EXPECT_EQ(::wasm::I64, params[1]->kind());
EXPECT_EQ(::wasm::F32, params[2]->kind());
EXPECT_EQ(::wasm::F64, params[3]->kind());
const vec<ValType*>& results = type->results();
const ownvec<ValType>& results = type->results();
EXPECT_EQ(2u, results.size());
EXPECT_EQ(::wasm::I32, results[0]->kind());
EXPECT_EQ(::wasm::ANYREF, results[1]->kind());
......
......@@ -12,7 +12,7 @@ namespace {
bool g_callback_called;
own<Trap*> Callback(const Val args[], Val results[]) {
own<Trap> Callback(const Val args[], Val results[]) {
g_callback_called = true;
return nullptr;
}
......@@ -27,16 +27,15 @@ TEST_F(WasmCapiTest, Serialize) {
Compile();
vec<byte_t> serialized = module()->serialize();
own<Module*> deserialized = Module::deserialize(store(), serialized);
own<Module> deserialized = Module::deserialize(store(), serialized);
own<FuncType*> callback_type =
FuncType::make(vec<ValType*>::make(), vec<ValType*>::make());
own<Func*> callback = Func::make(store(), callback_type.get(), Callback);
own<FuncType> callback_type =
FuncType::make(ownvec<ValType>::make(), ownvec<ValType>::make());
own<Func> callback = Func::make(store(), callback_type.get(), Callback);
Extern* imports[] = {callback.get()};
own<Instance*> instance =
Instance::make(store(), deserialized.get(), imports);
vec<Extern*> exports = instance->exports();
own<Instance> instance = Instance::make(store(), deserialized.get(), imports);
ownvec<Extern> exports = instance->exports();
Func* run = exports[0]->func();
g_callback_called = false;
run->call();
......
......@@ -14,7 +14,7 @@ using ::wasm::TableType;
namespace {
own<Trap*> Negate(const Val args[], Val results[]) {
own<Trap> Negate(const Val args[], Val results[]) {
results[0] = Val(-args[0].i32());
return nullptr;
}
......@@ -22,14 +22,14 @@ own<Trap*> Negate(const Val args[], Val results[]) {
void ExpectTrap(const Func* func, int arg1, int arg2) {
Val args[2] = {Val::i32(arg1), Val::i32(arg2)};
Val results[1];
own<Trap*> trap = func->call(args, results);
own<Trap> trap = func->call(args, results);
EXPECT_NE(nullptr, trap);
}
void ExpectResult(int expected, const Func* func, int arg1, int arg2) {
Val args[2] = {Val::i32(arg1), Val::i32(arg2)};
Val results[1];
own<Trap*> trap = func->call(args, results);
own<Trap> trap = func->call(args, results);
EXPECT_EQ(nullptr, trap);
EXPECT_EQ(expected, results[0].i32());
}
......@@ -60,7 +60,7 @@ TEST_F(WasmCapiTest, Table) {
Func* call_indirect = GetExportedFunction(1);
Func* f = GetExportedFunction(2);
Func* g = GetExportedFunction(3);
own<Func*> h = Func::make(store(), cpp_i_i_sig(), Negate);
own<Func> h = Func::make(store(), cpp_i_i_sig(), Negate);
// Try cloning.
EXPECT_TRUE(table->copy()->same(table));
......@@ -106,9 +106,9 @@ TEST_F(WasmCapiTest, Table) {
// Create standalone table.
// TODO(wasm+): Once Wasm allows multiple tables, turn this into import.
own<TableType*> tabletype =
own<TableType> tabletype =
TableType::make(ValType::make(FUNCREF), Limits(5, 5));
own<Table*> table2 = Table::make(store(), tabletype.get());
own<Table> table2 = Table::make(store(), tabletype.get());
EXPECT_EQ(5u, table2->size());
EXPECT_FALSE(table2->grow(1));
EXPECT_TRUE(table2->grow(0));
......
......@@ -19,26 +19,27 @@ const int kNumThreads = 10;
const int kIterationsPerThread = 3;
int g_traces;
own<Trap*> Callback(void* env, const Val args[], Val results[]) {
own<Trap> Callback(void* env, const Val args[], Val results[]) {
std::lock_guard<std::mutex> lock(*reinterpret_cast<std::mutex*>(env));
g_traces += args[0].i32();
return nullptr;
}
void Main(Engine* engine, Shared<Module>* shared, std::mutex* mutex, int id) {
own<Store*> store = Store::make(engine);
own<Module*> module = Module::obtain(store.get(), shared);
own<Store> store = Store::make(engine);
own<Module> module = Module::obtain(store.get(), shared);
EXPECT_NE(nullptr, module.get());
for (int i = 0; i < kIterationsPerThread; i++) {
std::this_thread::sleep_for(std::chrono::microseconds(100));
// Create imports.
own<FuncType*> func_type = FuncType::make(
vec<ValType*>::make(ValType::make(::wasm::I32)), vec<ValType*>::make());
own<Func*> func = Func::make(store.get(), func_type.get(), Callback, mutex);
own<::wasm::GlobalType*> global_type =
own<FuncType> func_type =
FuncType::make(ownvec<ValType>::make(ValType::make(::wasm::I32)),
ownvec<ValType>::make());
own<Func> func = Func::make(store.get(), func_type.get(), Callback, mutex);
own<::wasm::GlobalType> global_type =
::wasm::GlobalType::make(ValType::make(::wasm::I32), ::wasm::CONST);
own<Global*> global =
own<Global> global =
Global::make(store.get(), global_type.get(), Val::i32(id));
// Instantiate and run.
......@@ -46,9 +47,8 @@ void Main(Engine* engine, Shared<Module>* shared, std::mutex* mutex, int id) {
// imports always come before function imports, regardless of the
// order of builder()->Add*Import() calls below.
Extern* imports[] = {global.get(), func.get()};
own<Instance*> instance =
Instance::make(store.get(), module.get(), imports);
vec<Extern*> exports = instance->exports();
own<Instance> instance = Instance::make(store.get(), module.get(), imports);
ownvec<Extern> exports = instance->exports();
Func* run_func = exports[0]->func();
run_func->call();
}
......@@ -70,7 +70,7 @@ TEST_F(WasmCapiTest, Threads) {
FunctionSig empty_sig(0, 0, nullptr);
AddExportedFunction(CStrVector("run"), code, sizeof(code), &empty_sig);
Compile();
own<Shared<Module>*> shared = module()->share();
own<Shared<Module>> shared = module()->share();
// Spawn threads.
g_traces = 0;
......@@ -92,9 +92,9 @@ TEST_F(WasmCapiTest, Threads) {
TEST_F(WasmCapiTest, MultiStoresOneThread) {
// These Stores intentionally have overlapping, but non-nested lifetimes.
own<Store*> store1 = Store::make(engine());
own<Store*> store2 = Store::make(engine());
own<Store*> store3 = Store::make(engine());
own<Store> store1 = Store::make(engine());
own<Store> store2 = Store::make(engine());
own<Store> store3 = Store::make(engine());
store1.reset();
store2.reset();
store3.reset();
......
......@@ -20,7 +20,7 @@ using ::wasm::Message;
namespace {
own<Trap*> FailCallback(void* env, const Val args[], Val results[]) {
own<Trap> FailCallback(void* env, const Val args[], Val results[]) {
Store* store = reinterpret_cast<Store*>(env);
Message message = Message::make(std::string("callback abort"));
return Trap::make(store, message);
......@@ -45,10 +45,11 @@ TEST_F(WasmCapiTest, Traps) {
byte code2[] = {WASM_I32V_3(0), WASM_UNREACHABLE, WASM_I32V_1(1)};
AddExportedFunction(CStrVector("unreachable"), code2, sizeof(code2), &sig);
own<FuncType*> func_type = FuncType::make(
vec<ValType*>::make(), vec<ValType*>::make(ValType::make(::wasm::I32)));
own<Func*> cpp_callback = Func::make(store(), func_type.get(), FailCallback,
reinterpret_cast<void*>(store()));
own<FuncType> func_type =
FuncType::make(ownvec<ValType>::make(),
ownvec<ValType>::make(ValType::make(::wasm::I32)));
own<Func> cpp_callback = Func::make(store(), func_type.get(), FailCallback,
reinterpret_cast<void*>(store()));
Extern* imports[] = {cpp_callback.get()};
Instantiate(imports);
......@@ -67,24 +68,24 @@ TEST_F(WasmCapiTest, Traps) {
const uint32_t func2_offset = func2->code.offset();
Func* cpp_trapping_func = GetExportedFunction(0);
own<Trap*> cpp_trap = cpp_trapping_func->call();
own<Trap> cpp_trap = cpp_trapping_func->call();
EXPECT_NE(nullptr, cpp_trap.get());
ExpectMessage("Uncaught Error: callback abort", cpp_trap->message());
own<Frame*> frame = cpp_trap->origin();
own<Frame> frame = cpp_trap->origin();
EXPECT_TRUE(frame->instance()->same(instance()));
EXPECT_EQ(1u, frame->func_index());
EXPECT_EQ(1u, frame->func_offset());
EXPECT_EQ(func1_offset + frame->func_offset(), frame->module_offset());
vec<Frame*> trace = cpp_trap->trace();
ownvec<Frame> trace = cpp_trap->trace();
EXPECT_EQ(1u, trace.size());
frame = trace[0].move();
frame.reset(trace[0].release());
EXPECT_TRUE(frame->instance()->same(instance()));
EXPECT_EQ(1u, frame->func_index());
EXPECT_EQ(1u, frame->func_offset());
EXPECT_EQ(func1_offset + frame->func_offset(), frame->module_offset());
Func* wasm_trapping_func = GetExportedFunction(1);
own<Trap*> wasm_trap = wasm_trapping_func->call();
own<Trap> wasm_trap = wasm_trapping_func->call();
EXPECT_NE(nullptr, wasm_trap.get());
ExpectMessage("Uncaught RuntimeError: unreachable", wasm_trap->message());
frame = wasm_trap->origin();
......@@ -94,7 +95,7 @@ TEST_F(WasmCapiTest, Traps) {
EXPECT_EQ(func2_offset + frame->func_offset(), frame->module_offset());
trace = wasm_trap->trace();
EXPECT_EQ(1u, trace.size());
frame = trace[0].move();
frame.reset(trace[0].release());
EXPECT_TRUE(frame->instance()->same(instance()));
EXPECT_EQ(2u, frame->func_index());
EXPECT_EQ(5u, frame->func_offset());
......
......@@ -27,6 +27,7 @@ using ::wasm::Instance;
using ::wasm::Memory;
using ::wasm::Module;
using ::wasm::own;
using ::wasm::ownvec;
using ::wasm::Ref;
using ::wasm::Store;
using ::wasm::Table;
......@@ -42,13 +43,13 @@ class WasmCapiTest : public ::testing::Test {
zone_(&allocator_, ZONE_NAME),
wire_bytes_(&zone_),
builder_(&zone_),
exports_(vec<Extern*>::make()),
exports_(ownvec<Extern>::make()),
wasm_i_i_sig_(1, 1, wasm_i_i_sig_types_) {
engine_ = Engine::make();
store_ = Store::make(engine_.get());
cpp_i_i_sig_ =
FuncType::make(vec<ValType*>::make(ValType::make(::wasm::I32)),
vec<ValType*>::make(ValType::make(::wasm::I32)));
FuncType::make(ownvec<ValType>::make(ValType::make(::wasm::I32)),
ownvec<ValType>::make(ValType::make(::wasm::I32)));
}
void Compile() {
......@@ -79,7 +80,7 @@ class WasmCapiTest : public ::testing::Test {
Func* GetExportedFunction(size_t index) {
DCHECK_GT(exports_.size(), index);
Extern* exported = exports_[index];
Extern* exported = exports_[index].get();
DCHECK_EQ(exported->kind(), ::wasm::EXTERN_FUNC);
Func* func = exported->func();
DCHECK_NE(func, nullptr);
......@@ -88,7 +89,7 @@ class WasmCapiTest : public ::testing::Test {
Global* GetExportedGlobal(size_t index) {
DCHECK_GT(exports_.size(), index);
Extern* exported = exports_[index];
Extern* exported = exports_[index].get();
DCHECK_EQ(exported->kind(), ::wasm::EXTERN_GLOBAL);
Global* global = exported->global();
DCHECK_NE(global, nullptr);
......@@ -97,7 +98,7 @@ class WasmCapiTest : public ::testing::Test {
Memory* GetExportedMemory(size_t index) {
DCHECK_GT(exports_.size(), index);
Extern* exported = exports_[index];
Extern* exported = exports_[index].get();
DCHECK_EQ(exported->kind(), ::wasm::EXTERN_MEMORY);
Memory* memory = exported->memory();
DCHECK_NE(memory, nullptr);
......@@ -106,7 +107,7 @@ class WasmCapiTest : public ::testing::Test {
Table* GetExportedTable(size_t index) {
DCHECK_GT(exports_.size(), index);
Extern* exported = exports_[index];
Extern* exported = exports_[index].get();
DCHECK_EQ(exported->kind(), ::wasm::EXTERN_TABLE);
Table* table = exported->table();
DCHECK_NE(table, nullptr);
......@@ -125,7 +126,7 @@ class WasmCapiTest : public ::testing::Test {
Store* store() { return store_.get(); }
Module* module() { return module_.get(); }
Instance* instance() { return instance_.get(); }
const vec<Extern*>& exports() { return exports_; }
const ownvec<Extern>& exports() { return exports_; }
ZoneBuffer* wire_bytes() { return &wire_bytes_; }
FunctionSig* wasm_i_i_sig() { return &wasm_i_i_sig_; }
......@@ -136,12 +137,12 @@ class WasmCapiTest : public ::testing::Test {
Zone zone_;
ZoneBuffer wire_bytes_;
WasmModuleBuilder builder_;
own<Engine*> engine_;
own<Store*> store_;
own<Module*> module_;
own<Instance*> instance_;
vec<Extern*> exports_;
own<FuncType*> cpp_i_i_sig_;
own<Engine> engine_;
own<Store> store_;
own<Module> module_;
own<Instance> instance_;
ownvec<Extern> exports_;
own<FuncType> cpp_i_i_sig_;
ValueType wasm_i_i_sig_types_[2] = {kWasmI32, kWasmI32};
FunctionSig wasm_i_i_sig_;
};
......
......@@ -36,7 +36,7 @@ auto operator<<(std::ostream& out, const wasm::Val& val) -> std::ostream& {
// A function to be called from Wasm code.
auto print_callback(
const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl << "> " << args[0] << std::endl;
results[0] = args[0].copy();
return nullptr;
......@@ -46,7 +46,7 @@ auto print_callback(
// A function closure.
auto closure_callback(
void* env, const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
auto i = *reinterpret_cast<int*>(env);
std::cout << "Calling back closure..." << std::endl;
std::cout << "> " << i << std::endl;
......@@ -87,8 +87,8 @@ void run() {
// Create external print functions.
std::cout << "Creating callback..." << std::endl;
auto print_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32)),
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32))
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32)),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32))
);
auto print_func = wasm::Func::make(store, print_type.get(), print_callback);
......@@ -96,8 +96,8 @@ void run() {
std::cout << "Creating closure..." << std::endl;
int i = 42;
auto closure_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(),
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32))
wasm::ownvec<wasm::ValType>::make(),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32))
);
auto closure_func = wasm::Func::make(store, closure_type.get(), closure_callback, &i);
......
......@@ -7,7 +7,7 @@
#include "wasm.hh"
auto get_export_global(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Global* {
auto get_export_global(wasm::ownvec<wasm::Extern>& exports, size_t i) -> wasm::Global* {
if (exports.size() <= i || !exports[i]->global()) {
std::cout << "> Error accessing global export " << i << "!" << std::endl;
exit(1);
......@@ -15,7 +15,7 @@ auto get_export_global(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Glo
return exports[i]->global();
}
auto get_export_func(const wasm::vec<wasm::Extern*>& exports, size_t i) -> const wasm::Func* {
auto get_export_func(const wasm::ownvec<wasm::Extern>& exports, size_t i) -> const wasm::Func* {
if (exports.size() <= i || !exports[i]->func()) {
std::cout << "> Error accessing function export " << i << "!" << std::endl;
exit(1);
......
......@@ -10,7 +10,7 @@
// A function to be called from Wasm code.
auto hello_callback(
const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl;
std::cout << "> Hello world!" << std::endl;
return nullptr;
......@@ -49,7 +49,7 @@ void run() {
// Create external print functions.
std::cout << "Creating callback..." << std::endl;
auto hello_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(), wasm::vec<wasm::ValType*>::make()
wasm::ownvec<wasm::ValType>::make(), wasm::ownvec<wasm::ValType>::make()
);
auto hello_func = wasm::Func::make(store, hello_type.get(), hello_callback);
......
......@@ -10,7 +10,7 @@
// A function to be called from Wasm code.
auto callback(
const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl;
std::cout << "> " << (args[0].ref() ? args[0].ref()->get_host_info() : nullptr) << std::endl;
results[0] = args[0].copy();
......@@ -18,7 +18,7 @@ auto callback(
}
auto get_export_func(const wasm::vec<wasm::Extern*>& exports, size_t i) -> const wasm::Func* {
auto get_export_func(const wasm::ownvec<wasm::Extern>& exports, size_t i) -> const wasm::Func* {
if (exports.size() <= i || !exports[i]->func()) {
std::cout << "> Error accessing function export " << i << "/" << exports.size() << "!" << std::endl;
exit(1);
......@@ -28,7 +28,7 @@ auto get_export_func(const wasm::vec<wasm::Extern*>& exports, size_t i) -> const
void call_r_v(const wasm::Func* func, const wasm::Ref* ref) {
std::cout << "call_r_v... " << std::flush;
wasm::Val args[1] = {wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref*>())};
wasm::Val args[1] = {wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref>())};
if (func->call(args, nullptr)) {
std::cout << "> Error calling function!" << std::endl;
exit(1);
......@@ -36,7 +36,7 @@ void call_r_v(const wasm::Func* func, const wasm::Ref* ref) {
std::cout << "okay" << std::endl;
}
auto call_v_r(const wasm::Func* func) -> wasm::own<wasm::Ref*> {
auto call_v_r(const wasm::Func* func) -> wasm::own<wasm::Ref> {
std::cout << "call_v_r... " << std::flush;
wasm::Val results[1];
if (func->call(nullptr, results)) {
......@@ -47,9 +47,9 @@ auto call_v_r(const wasm::Func* func) -> wasm::own<wasm::Ref*> {
return results[0].release_ref();
}
auto call_r_r(const wasm::Func* func, const wasm::Ref* ref) -> wasm::own<wasm::Ref*> {
auto call_r_r(const wasm::Func* func, const wasm::Ref* ref) -> wasm::own<wasm::Ref> {
std::cout << "call_r_r... " << std::flush;
wasm::Val args[1] = {wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref*>())};
wasm::Val args[1] = {wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref>())};
wasm::Val results[1];
if (func->call(args, results)) {
std::cout << "> Error calling function!" << std::endl;
......@@ -61,7 +61,7 @@ auto call_r_r(const wasm::Func* func, const wasm::Ref* ref) -> wasm::own<wasm::R
void call_ir_v(const wasm::Func* func, int32_t i, const wasm::Ref* ref) {
std::cout << "call_ir_v... " << std::flush;
wasm::Val args[2] = {wasm::Val::i32(i), wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref*>())};
wasm::Val args[2] = {wasm::Val::i32(i), wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref>())};
if (func->call(args, nullptr)) {
std::cout << "> Error calling function!" << std::endl;
exit(1);
......@@ -69,7 +69,7 @@ void call_ir_v(const wasm::Func* func, int32_t i, const wasm::Ref* ref) {
std::cout << "okay" << std::endl;
}
auto call_i_r(const wasm::Func* func, int32_t i) -> wasm::own<wasm::Ref*> {
auto call_i_r(const wasm::Func* func, int32_t i) -> wasm::own<wasm::Ref> {
std::cout << "call_i_r... " << std::flush;
wasm::Val args[1] = {wasm::Val::i32(i)};
wasm::Val results[1];
......@@ -81,7 +81,7 @@ auto call_i_r(const wasm::Func* func, int32_t i) -> wasm::own<wasm::Ref*> {
return results[0].release_ref();
}
void check(wasm::own<wasm::Ref*> actual, const wasm::Ref* expected) {
void check(wasm::own<wasm::Ref> actual, const wasm::Ref* expected) {
if (actual.get() != expected &&
!(actual && expected && actual->same(expected))) {
std::cout << "> Error reading reference, expected "
......@@ -123,8 +123,8 @@ void run() {
// Create external callback function.
std::cout << "Creating callback..." << std::endl;
auto callback_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::ANYREF)),
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::ANYREF))
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::ANYREF)),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::ANYREF))
);
auto callback_func = wasm::Func::make(store, callback_type.get(), callback);
......
......@@ -7,7 +7,7 @@
#include "wasm.hh"
auto get_export_memory(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Memory* {
auto get_export_memory(wasm::ownvec<wasm::Extern>& exports, size_t i) -> wasm::Memory* {
if (exports.size() <= i || !exports[i]->memory()) {
std::cout << "> Error accessing memory export " << i << "!" << std::endl;
exit(1);
......@@ -15,7 +15,7 @@ auto get_export_memory(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Mem
return exports[i]->memory();
}
auto get_export_func(const wasm::vec<wasm::Extern*>& exports, size_t i) -> const wasm::Func* {
auto get_export_func(const wasm::ownvec<wasm::Extern>& exports, size_t i) -> const wasm::Func* {
if (exports.size() <= i || !exports[i]->func()) {
std::cout << "> Error accessing function export " << i << "!" << std::endl;
exit(1);
......
......@@ -33,7 +33,7 @@ auto operator<<(std::ostream& out, const wasm::ValType& type) -> std::ostream& {
return out;
}
auto operator<<(std::ostream& out, const wasm::vec<wasm::ValType*>& types) -> std::ostream& {
auto operator<<(std::ostream& out, const wasm::ownvec<wasm::ValType>& types) -> std::ostream& {
bool first = true;
for (size_t i = 0; i < types.size(); ++i) {
if (first) {
......
......@@ -10,7 +10,7 @@
// A function to be called from Wasm code.
auto hello_callback(
const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl;
std::cout << "> Hello world!" << std::endl;
return nullptr;
......@@ -61,7 +61,7 @@ void run() {
// Create external print functions.
std::cout << "Creating callback..." << std::endl;
auto hello_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(), wasm::vec<wasm::ValType*>::make()
wasm::ownvec<wasm::ValType>::make(), wasm::ownvec<wasm::ValType>::make()
);
auto hello_func = wasm::Func::make(store, hello_type.get(), hello_callback);
......
......@@ -10,14 +10,14 @@
// A function to be called from Wasm code.
auto neg_callback(
const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl;
results[0] = wasm::Val(-args[0].i32());
return nullptr;
}
auto get_export_table(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Table* {
auto get_export_table(wasm::ownvec<wasm::Extern>& exports, size_t i) -> wasm::Table* {
if (exports.size() <= i || !exports[i]->table()) {
std::cout << "> Error accessing table export " << i << "!" << std::endl;
exit(1);
......@@ -25,7 +25,7 @@ auto get_export_table(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Tabl
return exports[i]->table();
}
auto get_export_func(const wasm::vec<wasm::Extern*>& exports, size_t i) -> const wasm::Func* {
auto get_export_func(const wasm::ownvec<wasm::Extern>& exports, size_t i) -> const wasm::Func* {
if (exports.size() <= i || !exports[i]->func()) {
std::cout << "> Error accessing function export " << i << "!" << std::endl;
exit(1);
......@@ -118,8 +118,8 @@ void run() {
// Create external function.
std::cout << "Creating callback..." << std::endl;
auto neg_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32)),
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32))
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32)),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32))
);
auto h = wasm::Func::make(store, neg_type.get(), neg_callback);
......
......@@ -11,7 +11,7 @@ const int N_REPS = 3;
// A function to be called from Wasm code.
auto callback(
void* env, const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
assert(args[0].kind() == wasm::I32);
std::lock_guard<std::mutex>(*reinterpret_cast<std::mutex*>(env));
std::cout << "Thread " << args[0].i32() << " running..." << std::endl;
......@@ -42,8 +42,8 @@ void run(
// Create imports.
auto func_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32)),
wasm::vec<wasm::ValType*>::make()
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32)),
wasm::ownvec<wasm::ValType>::make()
);
auto func = wasm::Func::make(store, func_type.get(), callback, mutex);
......
......@@ -9,7 +9,7 @@
// A function to be called from Wasm code.
auto fail_callback(
void* env, const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl;
auto store = reinterpret_cast<wasm::Store*>(env);
auto message = wasm::Name::make(std::string("callback abort"));
......@@ -57,8 +57,8 @@ void run() {
// Create external print functions.
std::cout << "Creating callback..." << std::endl;
auto fail_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(),
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32))
wasm::ownvec<wasm::ValType>::make(),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32))
);
auto fail_func =
wasm::Func::make(store, fail_type.get(), fail_callback, store);
......
......@@ -29,81 +29,8 @@ using float64_t = double;
namespace wasm {
// Ownership
template<class T> struct owner { using type = T; };
template<class T> struct owner<T*> { using type = std::unique_ptr<T>; };
template<class T>
using own = typename owner<T>::type;
template<class T>
auto make_own(T x) -> own<T> { return own<T>(std::move(x)); }
// Vectors
template<class T>
struct vec_traits {
static void construct(size_t size, T data[]) {}
static void destruct(size_t size, T data[]) {}
static void move(size_t size, T* data, T init[]) {
for (size_t i = 0; i < size; ++i) data[i] = std::move(init[i]);
}
static void copy(size_t size, T data[], const T init[]) {
for (size_t i = 0; i < size; ++i) data[i] = init[i];
}
using proxy = T&;
};
template<class T>
struct vec_traits<T*> {
static void construct(size_t size, T* data[]) {
for (size_t i = 0; i < size; ++i) data[i] = nullptr;
}
static void destruct(size_t size, T* data[]) {
for (size_t i = 0; i < size; ++i) {
if (data[i]) delete data[i];
}
}
static void move(size_t size, T* data[], own<T*> init[]) {
for (size_t i = 0; i < size; ++i) data[i] = init[i].release();
}
static void copy(size_t size, T* data[], const T* const init[]) {
for (size_t i = 0; i < size; ++i) {
if (init[i]) data[i] = init[i]->copy().release();
}
}
class proxy {
T*& elem_;
public:
proxy(T*& elem) : elem_(elem) {}
operator T*() { return elem_; }
operator const T*() const { return elem_; }
auto operator=(own<T*>&& elem) -> proxy& {
reset(std::move(elem));
return *this;
}
void reset(own<T*>&& val = own<T*>()) {
if (elem_) delete elem_;
elem_ = val.release();
}
auto release() -> T* {
auto elem = elem_;
elem_ = nullptr;
return elem;
}
auto move() -> own<T*> { return make_own(release()); }
auto get() -> T* { return elem_; }
auto get() const -> const T* { return elem_; }
auto operator->() -> T* { return elem_; }
auto operator->() const -> const T* { return elem_; }
};
};
template<class T>
class vec {
static const size_t invalid_size = SIZE_MAX;
......@@ -128,11 +55,11 @@ class vec {
}
public:
template<class U>
vec(vec<U>&& that) : vec(that.size_, that.data_.release()) {}
using elem_type = T;
vec(vec<T>&& that) : vec(that.size_, that.data_.release()) {}
~vec() {
if (data_) vec_traits<T>::destruct(size_, data_.get());
free_data();
}
......@@ -157,14 +84,13 @@ public:
}
void reset() {
if (data_) vec_traits<T>::destruct(size_, data_.get());
free_data();
size_ = 0;
size_ = invalid_size;
data_.reset();
}
void reset(vec& that) {
reset();
free_data();
size_ = that.size_;
data_.reset(that.data_.release());
}
......@@ -174,31 +100,36 @@ public:
return *this;
}
auto operator[](size_t i) -> typename vec_traits<T>::proxy {
auto operator[](size_t i) -> T& {
assert(i < size_);
return typename vec_traits<T>::proxy(data_[i]);
return data_[i];
}
auto operator[](size_t i) const -> const typename vec_traits<T>::proxy {
auto operator[](size_t i) const -> const T& {
assert(i < size_);
return typename vec_traits<T>::proxy(data_[i]);
return data_[i];
}
auto copy() const -> vec {
auto v = vec(size_);
if (v) vec_traits<T>::copy(size_, v.data_.get(), data_.get());
if (v) for (size_t i = 0; i < size_; i++) v.data_[i] = data_[i];
return v;
}
static auto make_uninitialized(size_t size = 0) -> vec {
auto v = vec(size);
if (v) vec_traits<T>::construct(size, v.data_.get());
// TODO: This can't be used for e.g. vec<Val>
auto deep_copy() const -> vec {
auto v = vec(size_);
if (v) for (size_t i = 0; i < size_; ++i) v.data_[i] = data_[i]->copy();
return v;
}
static auto make(size_t size, own<T> init[]) -> vec {
static auto make_uninitialized(size_t size = 0) -> vec {
return vec(size);
}
static auto make(size_t size, T init[]) -> vec {
auto v = vec(size);
if (v) vec_traits<T>::move(size, v.data_.get(), init);
if (v) for (size_t i = 0; i < size; ++i) v.data_[i] = std::move(init[i]);
return v;
}
......@@ -215,7 +146,7 @@ public:
template<class... Ts>
static auto make(Ts&&... args) -> vec {
own<T> data[] = { make_own(std::move(args))... };
T data[] = { std::move(args)... };
return make(sizeof...(Ts), data);
}
......@@ -229,6 +160,15 @@ public:
};
// Ownership
template<class T> using own = std::unique_ptr<T>;
template<class T> using ownvec = vec<own<T>>;
template<class T>
auto make_own(T* x) -> own<T> { return own<T>(x); }
///////////////////////////////////////////////////////////////////////////////
// Runtime Environment
......@@ -240,7 +180,7 @@ public:
~Config();
void operator delete(void*);
static auto make() -> own<Config*>;
static auto make() -> own<Config>;
// Implementations may provide custom methods for manipulating Configs.
};
......@@ -254,7 +194,7 @@ public:
~Engine();
void operator delete(void*);
static auto make(own<Config*>&& = Config::make()) -> own<Engine*>;
static auto make(own<Config>&& = Config::make()) -> own<Engine>;
};
......@@ -266,7 +206,7 @@ public:
~Store();
void operator delete(void*);
static auto make(Engine*) -> own<Store*>;
static auto make(Engine*) -> own<Store>;
};
......@@ -303,8 +243,8 @@ public:
~ValType();
void operator delete(void*);
static auto make(ValKind) -> own<ValType*>;
auto copy() const -> own<ValType*>;
static auto make(ValKind) -> own<ValType>;
auto copy() const -> own<ValType>;
auto kind() const -> ValKind;
auto is_num() const -> bool { return wasm::is_num(kind()); }
......@@ -329,7 +269,7 @@ public:
~ExternType();
void operator delete(void*);
auto copy() const-> own<ExternType*>;
auto copy() const-> own<ExternType>;
auto kind() const -> ExternKind;
......@@ -353,14 +293,14 @@ public:
~FuncType();
static auto make(
vec<ValType*>&& params = vec<ValType*>::make(),
vec<ValType*>&& results = vec<ValType*>::make()
) -> own<FuncType*>;
ownvec<ValType>&& params = ownvec<ValType>::make(),
ownvec<ValType>&& results = ownvec<ValType>::make()
) -> own<FuncType>;
auto copy() const -> own<FuncType*>;
auto copy() const -> own<FuncType>;
auto params() const -> const vec<ValType*>&;
auto results() const -> const vec<ValType*>&;
auto params() const -> const ownvec<ValType>&;
auto results() const -> const ownvec<ValType>&;
};
......@@ -371,8 +311,8 @@ public:
GlobalType() = delete;
~GlobalType();
static auto make(own<ValType*>&&, Mutability) -> own<GlobalType*>;
auto copy() const -> own<GlobalType*>;
static auto make(own<ValType>&&, Mutability) -> own<GlobalType>;
auto copy() const -> own<GlobalType>;
auto content() const -> const ValType*;
auto mutability() const -> Mutability;
......@@ -386,8 +326,8 @@ public:
TableType() = delete;
~TableType();
static auto make(own<ValType*>&&, Limits) -> own<TableType*>;
auto copy() const -> own<TableType*>;
static auto make(own<ValType>&&, Limits) -> own<TableType>;
auto copy() const -> own<TableType>;
auto element() const -> const ValType*;
auto limits() const -> const Limits&;
......@@ -401,8 +341,8 @@ public:
MemoryType() = delete;
~MemoryType();
static auto make(Limits) -> own<MemoryType*>;
auto copy() const -> own<MemoryType*>;
static auto make(Limits) -> own<MemoryType>;
auto copy() const -> own<MemoryType>;
auto limits() const -> const Limits&;
};
......@@ -418,9 +358,9 @@ public:
~ImportType();
void operator delete(void*);
static auto make(Name&& module, Name&& name, own<ExternType*>&&) ->
own<ImportType*>;
auto copy() const -> own<ImportType*>;
static auto make(Name&& module, Name&& name, own<ExternType>&&) ->
own<ImportType>;
auto copy() const -> own<ImportType>;
auto module() const -> const Name&;
auto name() const -> const Name&;
......@@ -436,8 +376,8 @@ public:
~ExportType();
void operator delete(void*);
static auto make(Name&&, own<ExternType*>&&) -> own<ExportType*>;
auto copy() const -> own<ExportType*>;
static auto make(Name&&, own<ExternType>&&) -> own<ExportType>;
auto copy() const -> own<ExportType>;
auto name() const -> const Name&;
auto type() const -> const ExternType*;
......@@ -455,7 +395,7 @@ public:
~Ref();
void operator delete(void*);
auto copy() const -> own<Ref*>;
auto copy() const -> own<Ref>;
auto same(const Ref*) const -> bool;
auto get_host_info() const -> void*;
......@@ -483,7 +423,7 @@ public:
Val(int64_t i) : kind_(I64) { impl_.i64 = i; }
Val(float32_t z) : kind_(F32) { impl_.f32 = z; }
Val(float64_t z) : kind_(F64) { impl_.f64 = z; }
Val(own<Ref*>&& r) : kind_(ANYREF) { impl_.ref = r.release(); }
Val(own<Ref>&& r) : kind_(ANYREF) { impl_.ref = r.release(); }
Val(Val&& that) : kind_(that.kind_), impl_(that.impl_) {
if (is_ref()) that.impl_.ref = nullptr;
......@@ -500,7 +440,7 @@ public:
static auto i64(int64_t x) -> Val { return Val(x); }
static auto f32(float32_t x) -> Val { return Val(x); }
static auto f64(float64_t x) -> Val { return Val(x); }
static auto ref(own<Ref*>&& x) -> Val { return Val(std::move(x)); }
static auto ref(own<Ref>&& x) -> Val { return Val(std::move(x)); }
template<class T> inline static auto make(T x) -> Val;
template<class T> inline static auto make(own<T>&& x) -> Val;
......@@ -531,11 +471,11 @@ public:
auto ref() const -> Ref* { assert(is_ref()); return impl_.ref; }
template<class T> inline auto get() const -> T;
auto release_ref() -> own<Ref*> {
auto release_ref() -> own<Ref> {
assert(is_ref());
auto ref = impl_.ref;
impl_.ref = nullptr;
return own<Ref*>(ref);
return own<Ref>(ref);
}
auto copy() const -> Val {
......@@ -556,7 +496,7 @@ template<> inline auto Val::make<int32_t>(int32_t x) -> Val { return Val(x); }
template<> inline auto Val::make<int64_t>(int64_t x) -> Val { return Val(x); }
template<> inline auto Val::make<float32_t>(float32_t x) -> Val { return Val(x); }
template<> inline auto Val::make<float64_t>(float64_t x) -> Val { return Val(x); }
template<> inline auto Val::make<Ref*>(own<Ref*>&& x) -> Val {
template<> inline auto Val::make<Ref>(own<Ref>&& x) -> Val {
return Val(std::move(x));
}
......@@ -593,7 +533,7 @@ public:
~Frame();
void operator delete(void*);
auto copy() const -> own<Frame*>;
auto copy() const -> own<Frame>;
auto instance() const -> Instance*;
auto func_index() const -> uint32_t;
......@@ -606,12 +546,12 @@ public:
Trap() = delete;
~Trap();
static auto make(Store*, const Message& msg) -> own<Trap*>;
auto copy() const -> own<Trap*>;
static auto make(Store*, const Message& msg) -> own<Trap>;
auto copy() const -> own<Trap>;
auto message() const -> Message;
auto origin() const -> own<Frame*>; // may be null
auto trace() const -> vec<Frame*>; // may be empty, origin first
auto origin() const -> own<Frame>; // may be null
auto trace() const -> ownvec<Frame>; // may be empty, origin first
};
......@@ -634,17 +574,17 @@ public:
~Module();
static auto validate(Store*, const vec<byte_t>& binary) -> bool;
static auto make(Store*, const vec<byte_t>& binary) -> own<Module*>;
auto copy() const -> own<Module*>;
static auto make(Store*, const vec<byte_t>& binary) -> own<Module>;
auto copy() const -> own<Module>;
auto imports() const -> vec<ImportType*>;
auto exports() const -> vec<ExportType*>;
auto imports() const -> ownvec<ImportType>;
auto exports() const -> ownvec<ExportType>;
auto share() const -> own<Shared<Module>*>;
static auto obtain(Store*, const Shared<Module>*) -> own<Module*>;
auto share() const -> own<Shared<Module>>;
static auto obtain(Store*, const Shared<Module>*) -> own<Module>;
auto serialize() const -> vec<byte_t>;
static auto deserialize(Store*, const vec<byte_t>&) -> own<Module*>;
static auto deserialize(Store*, const vec<byte_t>&) -> own<Module>;
};
......@@ -655,8 +595,8 @@ public:
Foreign() = delete;
~Foreign();
static auto make(Store*) -> own<Foreign*>;
auto copy() const -> own<Foreign*>;
static auto make(Store*) -> own<Foreign>;
auto copy() const -> own<Foreign>;
};
......@@ -672,10 +612,10 @@ public:
Extern() = delete;
~Extern();
auto copy() const -> own<Extern*>;
auto copy() const -> own<Extern>;
auto kind() const -> ExternKind;
auto type() const -> own<ExternType*>;
auto type() const -> own<ExternType>;
auto func() -> Func*;
auto global() -> Global*;
......@@ -696,19 +636,19 @@ public:
Func() = delete;
~Func();
using callback = auto (*)(const Val[], Val[]) -> own<Trap*>;
using callback_with_env = auto (*)(void*, const Val[], Val[]) -> own<Trap*>;
using callback = auto (*)(const Val[], Val[]) -> own<Trap>;
using callback_with_env = auto (*)(void*, const Val[], Val[]) -> own<Trap>;
static auto make(Store*, const FuncType*, callback) -> own<Func*>;
static auto make(Store*, const FuncType*, callback) -> own<Func>;
static auto make(Store*, const FuncType*, callback_with_env,
void*, void (*finalizer)(void*) = nullptr) -> own<Func*>;
auto copy() const -> own<Func*>;
void*, void (*finalizer)(void*) = nullptr) -> own<Func>;
auto copy() const -> own<Func>;
auto type() const -> own<FuncType*>;
auto type() const -> own<FuncType>;
auto param_arity() const -> size_t;
auto result_arity() const -> size_t;
auto call(const Val[] = nullptr, Val[] = nullptr) const -> own<Trap*>;
auto call(const Val[] = nullptr, Val[] = nullptr) const -> own<Trap>;
};
......@@ -719,10 +659,10 @@ public:
Global() = delete;
~Global();
static auto make(Store*, const GlobalType*, const Val&) -> own<Global*>;
auto copy() const -> own<Global*>;
static auto make(Store*, const GlobalType*, const Val&) -> own<Global>;
auto copy() const -> own<Global>;
auto type() const -> own<GlobalType*>;
auto type() const -> own<GlobalType>;
auto get() const -> Val;
void set(const Val&);
};
......@@ -738,11 +678,11 @@ public:
using size_t = uint32_t;
static auto make(
Store*, const TableType*, const Ref* init = nullptr) -> own<Table*>;
auto copy() const -> own<Table*>;
Store*, const TableType*, const Ref* init = nullptr) -> own<Table>;
auto copy() const -> own<Table>;
auto type() const -> own<TableType*>;
auto get(size_t index) const -> own<Ref*>;
auto type() const -> own<TableType>;
auto get(size_t index) const -> own<Ref>;
auto set(size_t index, const Ref*) -> bool;
auto size() const -> size_t;
auto grow(size_t delta, const Ref* init = nullptr) -> bool;
......@@ -756,14 +696,14 @@ public:
Memory() = delete;
~Memory();
static auto make(Store*, const MemoryType*) -> own<Memory*>;
auto copy() const -> own<Memory*>;
static auto make(Store*, const MemoryType*) -> own<Memory>;
auto copy() const -> own<Memory>;
using pages_t = uint32_t;
static const size_t page_size = 0x10000;
auto type() const -> own<MemoryType*>;
auto type() const -> own<MemoryType>;
auto data() const -> byte_t*;
auto data_size() const -> size_t;
auto size() const -> pages_t;
......@@ -779,15 +719,15 @@ public:
~Instance();
static auto make(
Store*, const Module*, const Extern* const[]) -> own<Instance*>;
auto copy() const -> own<Instance*>;
Store*, const Module*, const Extern* const[]) -> own<Instance>;
auto copy() const -> own<Instance>;
auto exports() const -> vec<Extern*>;
auto exports() const -> ownvec<Extern>;
};
///////////////////////////////////////////////////////////////////////////////
} // namespave wasm
} // namespace wasm
#endif // #ifdef __WASM_HH
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