@@ -0,0 +1,62 @@
|
||||
use wasmtime::*;
|
||||
use memoize::memoize;
|
||||
|
||||
pub fn heap_object_struct (store : impl AsContext) -> Result<StructType> {
|
||||
let ctx = store.as_context ();
|
||||
let engine = ctx.engine ();
|
||||
Ok (
|
||||
StructType::with_finality_and_supertype (
|
||||
engine,
|
||||
Finality::NonFinal,
|
||||
None,
|
||||
vec![
|
||||
hash_field ()
|
||||
]
|
||||
)?
|
||||
)
|
||||
}
|
||||
|
||||
pub fn heap_object (_store : impl AsContext) -> Result<HeapType> {
|
||||
todo! ()
|
||||
}
|
||||
|
||||
#[memoize]
|
||||
pub fn hash_field () -> FieldType {
|
||||
FieldType::new (
|
||||
Mutability::Var,
|
||||
StorageType::ValType (ValType::I32)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn closure (store : impl AsContext) -> Result<HeapType> {
|
||||
let ctx = store.as_context ();
|
||||
let engine = ctx.engine ();
|
||||
Ok (
|
||||
HeapType::ConcreteStruct (
|
||||
StructType::with_finality_and_supertype (
|
||||
engine,
|
||||
Finality::NonFinal,
|
||||
Some (&heap_object_struct (&store)?),
|
||||
vec![
|
||||
hash_field (),
|
||||
FieldType::new (
|
||||
Mutability::Const,
|
||||
StorageType::ValType (ValType::Ref (
|
||||
RefType::new (
|
||||
false,
|
||||
HeapType::ConcreteFunc (
|
||||
FuncType::new (
|
||||
engine,
|
||||
vec![ValType::I32],
|
||||
vec![],
|
||||
)
|
||||
)
|
||||
)
|
||||
))
|
||||
),
|
||||
]
|
||||
)?
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user