Skip to content

Commit fb3080b

Browse files
committed
more fixed size implementation
1 parent 9b94c11 commit fb3080b

File tree

11 files changed

+84
-3
lines changed

11 files changed

+84
-3
lines changed

crates/c/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,10 @@ impl<'a> wit_bindgen_core::AnonymousTypeGenerator<'a> for InterfaceGenerator<'a>
14571457
fn anonymous_type_type(&mut self, _id: TypeId, _ty: &Type, _docs: &Docs) {
14581458
todo!("print_anonymous_type for type");
14591459
}
1460+
1461+
fn anonymous_type_fixed_size_list(&mut self, _id: TypeId, _ty: &Type, _size: u32, _docs: &Docs) {
1462+
todo!("print_anonymous_type for fixed size list");
1463+
}
14601464
}
14611465

14621466
pub enum CTypeNameInfo<'a> {

crates/core/src/abi.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,21 @@ def_instruction! {
307307
ty: TypeId,
308308
} : [2] => [1],
309309

310+
/// Pops all fields for a fixed list off the stack and then composes them
311+
/// into an array.
312+
FixedSizeListLift {
313+
elements: &'a Type,
314+
size: u32,
315+
id: TypeId,
316+
} : [*size as usize] => [1],
317+
318+
/// Pops an array off the stack, decomposes the elements and then pushes them onto the stack.
319+
FixedSizeListLower {
320+
elements: &'a Type,
321+
size: u32,
322+
id: TypeId,
323+
} : [1] => [*size as usize],
324+
310325
/// Pushes an operand onto the stack representing the list item from
311326
/// each iteration of the list.
312327
///
@@ -1550,7 +1565,21 @@ impl<'a, B: Bindgen> Generator<'a, B> {
15501565
});
15511566
}
15521567
TypeDefKind::Unknown => unreachable!(),
1553-
TypeDefKind::FixedSizeList(_, _) => todo!(),
1568+
TypeDefKind::FixedSizeList(ty, size) => {
1569+
let mut temp = Vec::new();
1570+
self.resolve.push_flat(&Type::Id(id), &mut temp);
1571+
let mut args = self
1572+
.stack
1573+
.drain(self.stack.len() - temp.len()..)
1574+
.collect::<Vec<_>>();
1575+
for _ in 0..*size {
1576+
temp.truncate(0);
1577+
self.resolve.push_flat(ty, &mut temp);
1578+
self.stack.extend(args.drain(..temp.len()));
1579+
self.lift(ty);
1580+
}
1581+
self.emit(&FixedSizeListLift { elements: ty, size: *size, id });
1582+
}
15541583
},
15551584
}
15561585
}

crates/core/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ pub trait AnonymousTypeGenerator<'a> {
193193
fn anonymous_type_option(&mut self, id: TypeId, ty: &Type, docs: &Docs);
194194
fn anonymous_type_result(&mut self, id: TypeId, ty: &Result_, docs: &Docs);
195195
fn anonymous_type_list(&mut self, id: TypeId, ty: &Type, docs: &Docs);
196+
fn anonymous_type_fixed_size_list(&mut self, id: TypeId, ty: &Type, size: u32, docs: &Docs);
196197
fn anonymous_type_future(&mut self, id: TypeId, ty: &Option<Type>, docs: &Docs);
197198
fn anonymous_type_stream(&mut self, id: TypeId, ty: &Option<Type>, docs: &Docs);
198199
fn anonymous_type_type(&mut self, id: TypeId, ty: &Type, docs: &Docs);
@@ -216,7 +217,7 @@ pub trait AnonymousTypeGenerator<'a> {
216217
TypeDefKind::Stream(s) => self.anonymous_type_stream(id, s, &ty.docs),
217218
TypeDefKind::Handle(handle) => self.anonymous_type_handle(id, handle, &ty.docs),
218219
TypeDefKind::Unknown => unreachable!(),
219-
TypeDefKind::FixedSizeList(_, _) => todo!(),
220+
TypeDefKind::FixedSizeList(t, size) => self.anonymous_type_fixed_size_list(id, t, *size, &ty.docs),
220221
}
221222
}
222223
}

crates/core/src/types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ impl Types {
204204
info.has_own_handle = true;
205205
}
206206
TypeDefKind::Unknown => unreachable!(),
207-
TypeDefKind::FixedSizeList(_, _) => todo!(),
207+
TypeDefKind::FixedSizeList(ty, _) => {
208+
info = self.type_info(resolve, ty);
209+
}
208210
}
209211
let prev = self.type_info.insert(ty, info);
210212
assert!(prev.is_none());

crates/csharp/src/function.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,8 @@ impl Bindgen for FunctionBindgen<'_, '_> {
12631263
| Instruction::StreamLift { .. }
12641264
| Instruction::ErrorContextLower { .. }
12651265
| Instruction::ErrorContextLift { .. } => todo!(),
1266+
Instruction::FixedSizeListLift { .. } => todo!(),
1267+
Instruction::FixedSizeListLower { .. } => todo!(),
12661268
}
12671269
}
12681270

crates/moonbit/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,6 +2667,8 @@ impl Bindgen for FunctionBindgen<'_, '_> {
26672667
| Instruction::StreamLift { .. }
26682668
| Instruction::ErrorContextLower { .. }
26692669
| Instruction::ErrorContextLift { .. } => todo!(),
2670+
Instruction::FixedSizeListLift { .. } => todo!(),
2671+
Instruction::FixedSizeListLower { .. } => todo!(),
26702672
}
26712673
}
26722674

crates/rust/src/bindgen.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,8 @@ impl Bindgen for FunctionBindgen<'_, '_> {
12021202
align = align.format(POINTER_SIZE_EXPRESSION)
12031203
));
12041204
}
1205+
Instruction::FixedSizeListLift { .. } => todo!(),
1206+
Instruction::FixedSizeListLower { .. } => todo!(),
12051207
}
12061208
}
12071209
}

crates/rust/src/interface.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,4 +2932,8 @@ impl<'a, 'b> wit_bindgen_core::AnonymousTypeGenerator<'a> for AnonTypeGenerator<
29322932
self.interface.print_optional_ty(ty.as_ref(), mode);
29332933
self.interface.push_str(">");
29342934
}
2935+
2936+
fn anonymous_type_fixed_size_list(&mut self, _id: TypeId, _ty: &Type, _size: u32, _docs: &Docs) {
2937+
todo!()
2938+
}
29352939
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include!(env!("BINDINGS"));
2+
3+
use test::lists::to_test::*;
4+
5+
fn main() {
6+
}

tests/runtime/fixed-size-list/test.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include!(env!("BINDINGS"));
2+
3+
struct Component;
4+
5+
export!(Component);
6+
7+
impl exports::test::lists::to_test::Guest for Component {
8+
}

0 commit comments

Comments
 (0)