From 7f60265c873933052d3cb3f23b67efd4f601e2ec Mon Sep 17 00:00:00 2001 From: Graham Kelly Date: Wed, 14 Aug 2024 18:14:20 -0400 Subject: [PATCH] structs --- pit-patch/src/util.rs | 23 +++++++++++++---------- pit-rust-host-lib/src/lib.rs | 13 ++++++------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/pit-patch/src/util.rs b/pit-patch/src/util.rs index f5921f4..d6f21ac 100644 --- a/pit-patch/src/util.rs +++ b/pit-patch/src/util.rs @@ -480,19 +480,22 @@ pub fn wrap(m: &mut Module) -> anyhow::Result<()> { } for i in is { let f = waffle_funcs(m, &i,false); + let mut ss = BTreeMap::new(); for mut import in take(&mut m.imports) { if import.module == format!("tpit/{}", i.rid_str()) { match import.name.strip_prefix("~") { Some(a) => { - let p = new_sig( - m, - SignatureData { - params: vec![Type::I32], - returns: vec![Type::ExternRef], - }, - ); - let p = m.funcs.push(waffle::FuncDecl::Import(p, format!("_pit"))); if let ImportKind::Func(f) = &mut import.kind { + let p = m.signatures[m.funcs[*f].sig()].params.clone(); + ss.insert(a.to_owned(), p.clone()); + let p = new_sig( + m, + SignatureData { + params: p, + returns: vec![Type::ExternRef], + }, + ); + let p = m.funcs.push(waffle::FuncDecl::Import(p, format!("_pit"))); let s = m.funcs[*f].sig(); let o = replace(f, p); let mut b = FunctionBody::new(&m, s); @@ -607,8 +610,8 @@ pub fn wrap(m: &mut Module) -> anyhow::Result<()> { let p = new_sig( m, SignatureData { - params: vec![Type::I32] - .into_iter() + params:ss.get(a).cloned() + .into_iter().flatten() .chain(p.params.into_iter()) .collect(), returns: p.returns.into_iter().collect(), diff --git a/pit-rust-host-lib/src/lib.rs b/pit-rust-host-lib/src/lib.rs index aca8065..34c7642 100644 --- a/pit-rust-host-lib/src/lib.rs +++ b/pit-rust-host-lib/src/lib.rs @@ -88,11 +88,8 @@ pub fn emit + 'static, E: WasmEngine>( &mut *ctx, FuncType::new(once(ValueType::I32), once(ValueType::ExternRef)), move |mut ctx, args, rets| { - let Value::I32(a) = &args[0] else { - anyhow::bail!("invalid type"); - }; let i = ctx.data().as_ref().clone(); - let object = Wrapped::new(*a as u32, rid.clone(),t.to_owned(), i, ctx.as_context_mut()); + let object = Wrapped::new(args.to_owned(), rid.clone(),t.to_owned(), i, ctx.as_context_mut()); rets[0] = Value::ExternRef(Some(ExternRef::new(ctx, object))); Ok(()) }, @@ -109,7 +106,7 @@ pub struct Wrapped { } impl Wrapped { pub fn new( - base: u32, + base: Vec, rid: Arc, rs: String, instance: ::wasm_runtime_layer::Instance, @@ -123,13 +120,14 @@ impl Wrapped { let instance2 = instance.clone(); // let ctx2 = ctx.clone(); let rs2 = rs.clone(); + let base2 = base.clone(); return Self { rid: rid.clone(), all: once( Arc::new(move |mut ctx:StoreContextMut<'_,U,E>,vals: Vec| -> anyhow::Result> { // let _ = &ctx2; // let mut b = ctx2.base.lock().unwrap(); - let vals: Vec<_> = vec![Value::I32(base as i32)] + let vals: Vec<_> = base.clone() .into_iter() .chain(vals.into_iter()) .collect(); @@ -150,10 +148,11 @@ impl Wrapped { let b = Arc::new(b.clone()); // let ctx = ctx.clone(); let rs = rs.clone(); + let base = base2.clone(); (Arc::new(move |mut ctx:StoreContextMut<'_,U,E>,vals: Vec| -> anyhow::Result> { // let _ = &ctx; // let mut bi = ctx.base.lock().unwrap(); - let vals: Vec<_> = vec![Value::I32(base as i32)] + let vals: Vec<_> = base.clone() .into_iter() .chain(vals.into_iter()) .collect();