Skip to content

Commit 41b6f4d

Browse files
committed
more fixed size implementation
1 parent d1b5fb1 commit 41b6f4d

File tree

11 files changed

+85
-4
lines changed

11 files changed

+85
-4
lines changed

crates/c/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,10 @@ impl<'a> wit_bindgen_core::AnonymousTypeGenerator<'a> for InterfaceGenerator<'a>
16651665
fn anonymous_type_type(&mut self, _id: TypeId, _ty: &Type, _docs: &Docs) {
16661666
todo!("print_anonymous_type for type");
16671667
}
1668+
1669+
fn anonymous_type_fixed_size_list(&mut self, _id: TypeId, _ty: &Type, _size: u32, _docs: &Docs) {
1670+
todo!("print_anonymous_type for fixed size list");
1671+
}
16681672
}
16691673

16701674
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
///
@@ -1573,7 +1588,21 @@ impl<'a, B: Bindgen> Generator<'a, B> {
15731588
});
15741589
}
15751590
TypeDefKind::Unknown => unreachable!(),
1576-
TypeDefKind::FixedSizeList(..) => todo!(),
1591+
TypeDefKind::FixedSizeList(ty, size) => {
1592+
let mut temp = Vec::new();
1593+
self.resolve.push_flat(&Type::Id(id), &mut temp);
1594+
let mut args = self
1595+
.stack
1596+
.drain(self.stack.len() - temp.len()..)
1597+
.collect::<Vec<_>>();
1598+
for _ in 0..*size {
1599+
temp.truncate(0);
1600+
self.resolve.push_flat(ty, &mut temp);
1601+
self.stack.extend(args.drain(..temp.len()));
1602+
self.lift(ty);
1603+
}
1604+
self.emit(&FixedSizeListLift { elements: ty, size: *size, id });
1605+
}
15771606
},
15781607
}
15791608
}

crates/core/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ pub trait AnonymousTypeGenerator<'a> {
195195
fn anonymous_type_option(&mut self, id: TypeId, ty: &Type, docs: &Docs);
196196
fn anonymous_type_result(&mut self, id: TypeId, ty: &Result_, docs: &Docs);
197197
fn anonymous_type_list(&mut self, id: TypeId, ty: &Type, docs: &Docs);
198+
fn anonymous_type_fixed_size_list(&mut self, id: TypeId, ty: &Type, size: u32, docs: &Docs);
198199
fn anonymous_type_future(&mut self, id: TypeId, ty: &Option<Type>, docs: &Docs);
199200
fn anonymous_type_stream(&mut self, id: TypeId, ty: &Option<Type>, docs: &Docs);
200201
fn anonymous_type_type(&mut self, id: TypeId, ty: &Type, docs: &Docs);
@@ -217,7 +218,7 @@ pub trait AnonymousTypeGenerator<'a> {
217218
TypeDefKind::Future(f) => self.anonymous_type_future(id, f, &ty.docs),
218219
TypeDefKind::Stream(s) => self.anonymous_type_stream(id, s, &ty.docs),
219220
TypeDefKind::Handle(handle) => self.anonymous_type_handle(id, handle, &ty.docs),
220-
TypeDefKind::FixedSizeList(..) => todo!(),
221+
TypeDefKind::FixedSizeList(t, size) => self.anonymous_type_fixed_size_list(id, t, *size, &ty.docs),
221222
TypeDefKind::Unknown => unreachable!(),
222223
}
223224
}

crates/core/src/types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ impl Types {
203203
// should use the same ownership semantics as `own<T>`
204204
info.has_own_handle = true;
205205
}
206-
TypeDefKind::FixedSizeList(..) => todo!(),
206+
TypeDefKind::FixedSizeList(ty, _) => {
207+
info = self.type_info(resolve, ty);
208+
}
207209
TypeDefKind::Unknown => unreachable!(),
208210
}
209211
let prev = self.type_info.insert(ty, info);

crates/csharp/src/function.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,9 @@ impl Bindgen for FunctionBindgen<'_, '_> {
12641264
| Instruction::ErrorContextLower { .. }
12651265
| Instruction::ErrorContextLift { .. }
12661266
| Instruction::DropHandle { .. }
1267-
=> todo!(),
1267+
=> todo!(),
1268+
Instruction::FixedSizeListLift { .. } => todo!(),
1269+
Instruction::FixedSizeListLower { .. } => todo!(),
12681270
}
12691271
}
12701272

crates/moonbit/src/lib.rs

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

crates/rust/src/bindgen.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,8 @@ impl Bindgen for FunctionBindgen<'_, '_> {
12071207
Instruction::DropHandle { .. } => {
12081208
uwriteln!(self.src, "let _ = {};", operands[0]);
12091209
}
1210+
Instruction::FixedSizeListLift { .. } => todo!(),
1211+
Instruction::FixedSizeListLower { .. } => todo!(),
12101212
}
12111213
}
12121214
}

crates/rust/src/interface.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,4 +2919,8 @@ impl<'a, 'b> wit_bindgen_core::AnonymousTypeGenerator<'a> for AnonTypeGenerator<
29192919
self.interface.print_optional_ty(ty.as_ref(), mode);
29202920
self.interface.push_str(">");
29212921
}
2922+
2923+
fn anonymous_type_fixed_size_list(&mut self, _id: TypeId, _ty: &Type, _size: u32, _docs: &Docs) {
2924+
todo!()
2925+
}
29222926
}
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)