@@ -3,14 +3,15 @@ use indexmap::IndexMap;
33use petgraph:: graph:: NodeIndex ;
44use std:: collections:: HashMap ;
55use wac_types:: {
6- CoreExtern , DefinedType , DefinedTypeId , Enum , Flags , FuncResult , FuncTypeId , InterfaceId ,
7- ItemKind , ModuleTypeId , PrimitiveType , Record , ResourceId , Type , Types , UsedType , ValueType ,
8- Variant , WorldId ,
6+ CoreExtern , DefinedType , DefinedTypeId , Enum , Flags , FuncTypeId , InterfaceId , ItemKind ,
7+ ModuleTypeId , PrimitiveType , Record , ResourceId , Type , Types , UsedType , ValueType , Variant ,
8+ WorldId ,
99} ;
1010use wasm_encoder:: {
11- Alias , ComponentBuilder , ComponentExportKind , ComponentOuterAliasKind , ComponentType ,
12- ComponentTypeEncoder , ComponentTypeRef , ComponentValType , CoreTypeEncoder , EntityType ,
13- GlobalType , InstanceType , MemoryType , ModuleType , TableType , TagKind , TagType , TypeBounds ,
11+ Alias , ComponentBuilder , ComponentCoreTypeEncoder , ComponentExportKind ,
12+ ComponentOuterAliasKind , ComponentType , ComponentTypeEncoder , ComponentTypeRef ,
13+ ComponentValType , EntityType , GlobalType , InstanceType , MemoryType , ModuleType , TableType ,
14+ TagKind , TagType , TypeBounds ,
1415} ;
1516
1617/// A type used to abstract the API differences between a component builder,
@@ -55,7 +56,7 @@ impl Encodable {
5556 }
5657 }
5758
58- fn core_type ( & mut self ) -> CoreTypeEncoder {
59+ fn core_type ( & mut self ) -> ComponentCoreTypeEncoder {
5960 match self {
6061 Encodable :: Builder ( t) => t. core_type ( ) . 1 ,
6162 Encodable :: Instance ( t) => t. core_type ( ) ,
@@ -226,27 +227,11 @@ impl<'a> TypeEncoder<'a> {
226227 . map ( |( n, ty) | ( n. as_str ( ) , self . value_type ( state, * ty) ) )
227228 . collect :: < Vec < _ > > ( ) ;
228229
229- let results = match & ty. results {
230- Some ( FuncResult :: Scalar ( ty) ) => vec ! [ ( "" , self . value_type( state, * ty) ) ] ,
231- Some ( FuncResult :: List ( results) ) => results
232- . iter ( )
233- . map ( |( n, ty) | ( n. as_str ( ) , self . value_type ( state, * ty) ) )
234- . collect ( ) ,
235- None => Vec :: new ( ) ,
236- } ;
237-
230+ let result = ty. result . map ( |ty| self . value_type ( state, ty) ) ;
238231 let index = state. current . encodable . type_count ( ) ;
239232 let mut encoder = state. current . encodable . ty ( ) . function ( ) ;
240233 encoder. params ( params) ;
241-
242- match & ty. results {
243- Some ( FuncResult :: Scalar ( _) ) => {
244- encoder. result ( results[ 0 ] . 1 ) ;
245- }
246- _ => {
247- encoder. results ( results) ;
248- }
249- }
234+ encoder. result ( result) ;
250235
251236 log:: debug!( "function type encoded to type index {index}" ) ;
252237 index
@@ -268,6 +253,8 @@ impl<'a> TypeEncoder<'a> {
268253 DefinedType :: Alias ( ValueType :: Borrow ( id) ) => self . borrow ( state, * id) ,
269254 DefinedType :: Alias ( ValueType :: Own ( id) ) => self . own ( state, * id) ,
270255 DefinedType :: Alias ( ValueType :: Defined ( id) ) => self . defined ( state, * id) ,
256+ DefinedType :: Stream ( ty) => self . stream ( state, * ty) ,
257+ DefinedType :: Future ( ty) => self . future ( state, * ty) ,
271258 } ;
272259
273260 log:: debug!( "defined type encoded to type index {index}" ) ;
@@ -476,25 +463,36 @@ impl<'a> TypeEncoder<'a> {
476463 element_type,
477464 initial,
478465 maximum,
466+ table64,
467+ shared,
479468 } => EntityType :: Table ( TableType {
480469 element_type : ( * element_type) . into ( ) ,
481470 minimum : * initial,
482471 maximum : * maximum,
472+ table64 : * table64,
473+ shared : * shared,
483474 } ) ,
484475 CoreExtern :: Memory {
485476 memory64,
486477 shared,
487478 initial,
488479 maximum,
480+ page_size_log2,
489481 } => EntityType :: Memory ( MemoryType {
490482 minimum : * initial,
491483 maximum : * maximum,
492484 memory64 : * memory64,
493485 shared : * shared,
486+ page_size_log2 : * page_size_log2,
494487 } ) ,
495- CoreExtern :: Global { val_type, mutable } => EntityType :: Global ( GlobalType {
488+ CoreExtern :: Global {
489+ val_type,
490+ mutable,
491+ shared,
492+ } => EntityType :: Global ( GlobalType {
496493 val_type : ( * val_type) . into ( ) ,
497494 mutable : * mutable,
495+ shared : * shared,
498496 } ) ,
499497 CoreExtern :: Tag ( func) => {
500498 let index = encodable. type_count ( ) ;
@@ -554,6 +552,20 @@ impl<'a> TypeEncoder<'a> {
554552 index
555553 }
556554
555+ fn stream ( & self , state : & mut State , ty : Option < ValueType > ) -> u32 {
556+ let ty = ty. map ( |ty| self . value_type ( state, ty) ) ;
557+ let index = state. current . encodable . type_count ( ) ;
558+ state. current . encodable . ty ( ) . defined_type ( ) . stream ( ty) ;
559+ index
560+ }
561+
562+ fn future ( & self , state : & mut State , ty : Option < ValueType > ) -> u32 {
563+ let ty = ty. map ( |ty| self . value_type ( state, ty) ) ;
564+ let index = state. current . encodable . type_count ( ) ;
565+ state. current . encodable . ty ( ) . defined_type ( ) . future ( ty) ;
566+ index
567+ }
568+
557569 fn option ( & self , state : & mut State , ty : ValueType ) -> u32 {
558570 let ty = self . value_type ( state, ty) ;
559571 let index = state. current . encodable . type_count ( ) ;
0 commit comments