Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/parser/WASMComponentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class WASMComponentBinaryReader : public wabt::WASMComponentBinaryReaderDelegate
break;
case ComponentSort::Type:
if (externalInfo.external == ComponentExternalDesc::TypeSubRes) {
type = new Walrus::ComponentTypeResource(Walrus::ComponentRefCounted::ResourceKind, false);
type = new Walrus::ComponentTypeSubResource();
} else {
type = m_current->getType(externalInfo.index.index);
type->addRef();
Expand Down Expand Up @@ -672,14 +672,14 @@ class WASMComponentBinaryReader : public wabt::WASMComponentBinaryReaderDelegate

void OnOwnType(Index index)
{
Walrus::ComponentTypeResource* ref = m_current->getType(index)->asTypeResource();
Walrus::ComponentTypeSubResource* ref = m_current->getType(index)->asTypeSubResource();
ref->addRef();
m_current->pushType(new Walrus::ComponentTypeResourceRef(Walrus::ComponentRefCounted::OwnKind, ref));
}

void OnBorrowType(Index index)
{
Walrus::ComponentTypeResource* ref = m_current->getType(index)->asTypeResource();
Walrus::ComponentTypeSubResource* ref = m_current->getType(index)->asTypeSubResource();
ref->addRef();
m_current->pushType(new Walrus::ComponentTypeResourceRef(Walrus::ComponentRefCounted::BorrowKind, ref));
}
Expand Down Expand Up @@ -723,14 +723,14 @@ class WASMComponentBinaryReader : public wabt::WASMComponentBinaryReaderDelegate
void OnResourceType(ComponentResourceRep rep,
Index dtor)
{
m_current->pushType(new Walrus::ComponentTypeResource(Walrus::ComponentRefCounted::ResourceKind, rep == ComponentResourceRep::I64));
m_current->pushType(new Walrus::ComponentTypeResource(rep == ComponentResourceRep::I64, dtor));
}

void OnResourceAsyncType(ComponentResourceRep rep,
Index dtor,
Index callback)
{
m_current->pushType(new Walrus::ComponentTypeResource(Walrus::ComponentRefCounted::ResourceAsyncKind, rep == ComponentResourceRep::I64));
m_current->pushType(new Walrus::ComponentTypeResourceAsync(rep == ComponentResourceRep::I64, dtor, callback));
}

void BeginInstanceType(uint32_t count)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void ComponentRefCounted::releaseAllRefs(ComponentRefCounted* ref)
break;
}
default:
ASSERT(ref->isValueType() || ref->isTypeLabels() || ref->isTypeResource());
ASSERT(ref->isValueType() || ref->isTypeLabels() || ref->isTypeSubResource());
break;
}

Expand Down
81 changes: 75 additions & 6 deletions src/runtime/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class ComponentTypeTuple;
class ComponentTypeLabels;
class ComponentTypeResult;
class ComponentTypeFunc;
class ComponentTypeSubResource;
class ComponentTypeResource;
class ComponentTypeResourceAsync;
class ComponentTypeResourceRef;
class ComponentType;

Expand All @@ -76,6 +78,7 @@ class ComponentRefCounted {
InstanceTypeKind,
ComponentTypeKind,
InstanceKind,
SubResourceKind,
ResourceKind,
ResourceAsyncKind,
};
Expand Down Expand Up @@ -193,6 +196,17 @@ class ComponentRefCounted {
return reinterpret_cast<ComponentTypeFunc*>(this);
}

bool isTypeSubResource() const
{
return kind() == SubResourceKind || kind() == ResourceKind || kind() == ResourceAsyncKind;
}

ComponentTypeSubResource* asTypeSubResource()
{
ASSERT(isTypeSubResource());
return reinterpret_cast<ComponentTypeSubResource*>(this);
}

bool isTypeResource() const
{
return kind() == ResourceKind || kind() == ResourceAsyncKind;
Expand All @@ -204,6 +218,12 @@ class ComponentRefCounted {
return reinterpret_cast<ComponentTypeResource*>(this);
}

ComponentTypeResourceAsync* asTypeResourceAsync()
{
ASSERT(kind() == ResourceAsyncKind);
return reinterpret_cast<ComponentTypeResourceAsync*>(this);
}

bool isComponentType() const
{
return kind() == InstanceTypeKind || kind() == ComponentTypeKind;
Expand Down Expand Up @@ -453,40 +473,89 @@ class ComponentTypeFunc : public ComponentRefCounted {
ComponentTypeRef m_result;
};

class ComponentTypeResource : public ComponentRefCounted {
class ComponentTypeSubResource : public ComponentRefCounted {
public:
ComponentTypeResource(Kind kind, bool i64)
ComponentTypeSubResource()
: ComponentRefCounted(SubResourceKind)
{
}

protected:
ComponentTypeSubResource(Kind kind)
: ComponentRefCounted(kind)
{
ASSERT(kind == ResourceKind || kind == ResourceAsyncKind);
}
};

class ComponentTypeResource : public ComponentTypeSubResource {
public:
static constexpr uint32_t NotDefined = ~static_cast<uint32_t>(0);

ComponentTypeResource(bool i64, uint32_t dtorIndex)
: ComponentTypeSubResource(ResourceKind)
, m_i64(i64)
, m_dtorIndex(dtorIndex)
{
ASSERT(isTypeResource());
}

bool i64() const
{
return m_i64;
}

uint32_t dtorIndex() const
{
return m_dtorIndex;
}

protected:
ComponentTypeResource(Kind kind, bool i64, uint32_t dtorIndex)
: ComponentTypeSubResource(kind)
, m_i64(i64)
, m_dtorIndex(dtorIndex)
{
ASSERT(kind == ResourceAsyncKind);
}

private:
bool m_i64;
uint32_t m_dtorIndex;
};

class ComponentTypeResourceAsync : public ComponentTypeResource {
public:
ComponentTypeResourceAsync(bool i64, uint32_t dtorIndex, uint32_t callbackIndex)
: ComponentTypeResource(ResourceAsyncKind, i64, dtorIndex)
, m_callbackIndex(callbackIndex)
{
}

uint32_t callbackIndex() const
{
return m_callbackIndex;
}

private:
uint32_t m_callbackIndex;
};

class ComponentTypeResourceRef : public ComponentRefCounted {
public:
ComponentTypeResourceRef(Kind kind, ComponentTypeResource* ref)
ComponentTypeResourceRef(Kind kind, ComponentTypeSubResource* ref)
: ComponentRefCounted(kind)
, m_ref(ref)
{
ASSERT(isTypeResourceRef());
}

ComponentTypeResource* ref() const
ComponentTypeSubResource* ref() const
{
return m_ref;
}

private:
ComponentTypeResource* m_ref;
ComponentTypeSubResource* m_ref;
};

// Immutable type declarations for components, instances
Expand Down
Loading
Loading