-
Notifications
You must be signed in to change notification settings - Fork 24
Description
This is a little idea to get rid of the requirement to specify an additional entry file.
Instead of exporting the IDs, it is also possible to obtain these from RTTI, which is located in static memory at exports.__rtti_base
. RTTI is somewhat limited, but as-bind's currently supported types fit it well.
// ββββββββββββββββββββ Typeinfo interpretation ββββββββββββββββββββ
// 3 2 1
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits
// βββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ΄ββ€ ββ __rtti_base
// β count β
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ‘ β
// β Typeinfo#flags [id=0] β id < count
// β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β€
// β Typeinfo#base [id=0] β
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
// β ... β
All the ArrayBufferViews have a special flag TypeinfoFlags.ARRAYBUFFERVIEW
. Their integer or floating point type can be derived from TypeinfoFlags.VALUE_ALIGN_X
in combination with TypeinfoFlags.VALUE_SIGNED
and TypeinfoFlags.VALUE_FLOAT
.
However, doing so imposes the limitation that if no Int16Array
for example is used within the module, it won't be present in RTTI. Instantiating one should not be useful anyway in this case as there is nothing accepting an Int16Array
on the Wasm side.
This would also work with Array<T>
. These use TypeinfoFlags.ARRAYBUFFERVIEW | TypeinfoFlags.ARRAY
and have the same flags otherwise. However, special care must be taken if T
is managed, which is indicated by TypeinfoFlags.VALUE_MANAGED
.
The other supported types have fixed IDs btw and are always present, so one doesn't need an export for these:
- ArrayBuffer: 0
- String: 1
- ArrayBufferView: 2 (this can be used to find typed arrays, which use this ID as a base)