Closed oovm closed 3 months ago
Consider the following pseudo code
class Fly {
fly: i32
action() {}
}
class Walk {
walk: f32
action() {}
}
class Monster(Fly, Walk) {
monster: f64
action() {
// selected by mro, in compile time
super<Fly>.action()
}
}
I tried
(type $fly (struct (ref $fly-vt) (field "fly" mut i32)))
(type $walk (struct (ref $walk-vt) (field "walk" mut f32)))
(type $monster (struct
(ref $monster-vt)
(field "Fly.fly" mut i32)
(field "Walk.walk" mut f32)
(field "Monster.monster" mut f64)
))
(type $fly-vt (ref $action))
(type $walk-vt (ref $action))
(type $monster-vt (struct
// (inline $fly-vt)
// (inline $walk-vt)
(ref $action)
))
But I still don't know how to determine the runtime subtype, or how to upcast or downcast a runtime type.
GC types are not source language types, rather, they describe to the GC the memory layout of low-level data structures in a language runtime. On that level, multiple inheritance does not make sense, because memory layouts can only be extended in one dimension. Mechanisms like multiple inheritance require indirections, which need to be implemented in Wasm code, in the same way you would with linear memory or in a native compiler. This is expected behaviour.
What should I do if I want a multi-inheritance gc language like python?
Are there any plans to introduce multiple inheritance and mro resolution (C3 linearization process)?
If such a feature cannot be added, what are the better simulation methods?
If I do
Is this a good approach?
Or can this method simulate multiple inheritance?
https://github.com/WebAssembly/gc/blob/main/proposals/gc/Overview.md#objects-and-method-tables