@@ -1203,8 +1203,8 @@ impl ComponentState {
12031203 self . task_return ( & result, & options, types, offset)
12041204 }
12051205 CanonicalFunction :: TaskCancel => self . task_cancel ( types, offset) ,
1206- CanonicalFunction :: ContextGet ( i ) => self . context_get ( i , types, offset) ,
1207- CanonicalFunction :: ContextSet ( i ) => self . context_set ( i , types, offset) ,
1206+ CanonicalFunction :: ContextGet { ty , slot } => self . context_get ( ty , slot , types, offset) ,
1207+ CanonicalFunction :: ContextSet { ty , slot } => self . context_set ( ty , slot , types, offset) ,
12081208 CanonicalFunction :: ThreadYield { cancellable : _ } => self . thread_yield ( types, offset) ,
12091209 CanonicalFunction :: SubtaskDrop => self . subtask_drop ( types, offset) ,
12101210 CanonicalFunction :: SubtaskCancel { async_ } => {
@@ -1517,34 +1517,64 @@ impl ComponentState {
15171517 Ok ( ( ) )
15181518 }
15191519
1520- fn context_get ( & mut self , i : u32 , types : & mut TypeAlloc , offset : usize ) -> Result < ( ) > {
1520+ fn context_get (
1521+ & mut self ,
1522+ ty : ValType ,
1523+ i : u32 ,
1524+ types : & mut TypeAlloc ,
1525+ offset : usize ,
1526+ ) -> Result < ( ) > {
15211527 if !self . features . cm_async ( ) {
15221528 bail ! (
15231529 offset,
15241530 "`context.get` requires the component model async feature"
15251531 )
15261532 }
1533+ self . validate_context_type ( ty, "context.get" , offset) ?;
15271534 self . validate_context_immediate ( i, "context.get" , offset) ?;
15281535
15291536 self . core_funcs
1530- . push ( types. intern_func_type ( FuncType :: new ( [ ] , [ ValType :: I32 ] ) , offset) ) ;
1537+ . push ( types. intern_func_type ( FuncType :: new ( [ ] , [ ty ] ) , offset) ) ;
15311538 Ok ( ( ) )
15321539 }
15331540
1534- fn context_set ( & mut self , i : u32 , types : & mut TypeAlloc , offset : usize ) -> Result < ( ) > {
1541+ fn context_set (
1542+ & mut self ,
1543+ ty : ValType ,
1544+ i : u32 ,
1545+ types : & mut TypeAlloc ,
1546+ offset : usize ,
1547+ ) -> Result < ( ) > {
15351548 if !self . features . cm_async ( ) {
15361549 bail ! (
15371550 offset,
15381551 "`context.set` requires the component model async feature"
15391552 )
15401553 }
1554+ self . validate_context_type ( ty, "context.set" , offset) ?;
15411555 self . validate_context_immediate ( i, "context.set" , offset) ?;
15421556
15431557 self . core_funcs
1544- . push ( types. intern_func_type ( FuncType :: new ( [ ValType :: I32 ] , [ ] ) , offset) ) ;
1558+ . push ( types. intern_func_type ( FuncType :: new ( [ ty ] , [ ] ) , offset) ) ;
15451559 Ok ( ( ) )
15461560 }
15471561
1562+ fn validate_context_type ( & self , ty : ValType , intrinsic : & str , offset : usize ) -> Result < ( ) > {
1563+ match ty {
1564+ ValType :: I32 => Ok ( ( ) ) ,
1565+ ValType :: I64 => {
1566+ if !self . features . cm64 ( ) {
1567+ bail ! (
1568+ offset,
1569+ "64-bit `{intrinsic}` requires the component model 64-bit feature"
1570+ )
1571+ }
1572+ Ok ( ( ) )
1573+ }
1574+ _ => bail ! ( offset, "`{intrinsic}` only supports `i32` or `i64`" ) ,
1575+ }
1576+ }
1577+
15481578 fn thread_yield ( & mut self , types : & mut TypeAlloc , offset : usize ) -> Result < ( ) > {
15491579 if !self . features . cm_async ( ) {
15501580 bail ! (
0 commit comments