structs
This commit is contained in:
parent
fbb61e4a94
commit
7f60265c87
|
@ -480,19 +480,22 @@ pub fn wrap(m: &mut Module) -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
for i in is {
|
for i in is {
|
||||||
let f = waffle_funcs(m, &i,false);
|
let f = waffle_funcs(m, &i,false);
|
||||||
|
let mut ss = BTreeMap::new();
|
||||||
for mut import in take(&mut m.imports) {
|
for mut import in take(&mut m.imports) {
|
||||||
if import.module == format!("tpit/{}", i.rid_str()) {
|
if import.module == format!("tpit/{}", i.rid_str()) {
|
||||||
match import.name.strip_prefix("~") {
|
match import.name.strip_prefix("~") {
|
||||||
Some(a) => {
|
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 {
|
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 s = m.funcs[*f].sig();
|
||||||
let o = replace(f, p);
|
let o = replace(f, p);
|
||||||
let mut b = FunctionBody::new(&m, s);
|
let mut b = FunctionBody::new(&m, s);
|
||||||
|
@ -607,8 +610,8 @@ pub fn wrap(m: &mut Module) -> anyhow::Result<()> {
|
||||||
let p = new_sig(
|
let p = new_sig(
|
||||||
m,
|
m,
|
||||||
SignatureData {
|
SignatureData {
|
||||||
params: vec![Type::I32]
|
params:ss.get(a).cloned()
|
||||||
.into_iter()
|
.into_iter().flatten()
|
||||||
.chain(p.params.into_iter())
|
.chain(p.params.into_iter())
|
||||||
.collect(),
|
.collect(),
|
||||||
returns: p.returns.into_iter().collect(),
|
returns: p.returns.into_iter().collect(),
|
||||||
|
|
|
@ -88,11 +88,8 @@ pub fn emit<U: AsRef<Instance> + 'static, E: WasmEngine>(
|
||||||
&mut *ctx,
|
&mut *ctx,
|
||||||
FuncType::new(once(ValueType::I32), once(ValueType::ExternRef)),
|
FuncType::new(once(ValueType::I32), once(ValueType::ExternRef)),
|
||||||
move |mut ctx, args, rets| {
|
move |mut ctx, args, rets| {
|
||||||
let Value::I32(a) = &args[0] else {
|
|
||||||
anyhow::bail!("invalid type");
|
|
||||||
};
|
|
||||||
let i = ctx.data().as_ref().clone();
|
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)));
|
rets[0] = Value::ExternRef(Some(ExternRef::new(ctx, object)));
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
|
@ -109,7 +106,7 @@ pub struct Wrapped<U: 'static, E: wasm_runtime_layer::backend::WasmEngine> {
|
||||||
}
|
}
|
||||||
impl<U: 'static, E: wasm_runtime_layer::backend::WasmEngine> Wrapped<U,E> {
|
impl<U: 'static, E: wasm_runtime_layer::backend::WasmEngine> Wrapped<U,E> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
base: u32,
|
base: Vec<wasm_runtime_layer::Value>,
|
||||||
rid: Arc<Interface>,
|
rid: Arc<Interface>,
|
||||||
rs: String,
|
rs: String,
|
||||||
instance: ::wasm_runtime_layer::Instance,
|
instance: ::wasm_runtime_layer::Instance,
|
||||||
|
@ -123,13 +120,14 @@ impl<U: 'static, E: wasm_runtime_layer::backend::WasmEngine> Wrapped<U,E> {
|
||||||
let instance2 = instance.clone();
|
let instance2 = instance.clone();
|
||||||
// let ctx2 = ctx.clone();
|
// let ctx2 = ctx.clone();
|
||||||
let rs2 = rs.clone();
|
let rs2 = rs.clone();
|
||||||
|
let base2 = base.clone();
|
||||||
return Self {
|
return Self {
|
||||||
rid: rid.clone(),
|
rid: rid.clone(),
|
||||||
all: once(
|
all: once(
|
||||||
Arc::new(move |mut ctx:StoreContextMut<'_,U,E>,vals: Vec<Value>| -> anyhow::Result<Vec<Value>> {
|
Arc::new(move |mut ctx:StoreContextMut<'_,U,E>,vals: Vec<Value>| -> anyhow::Result<Vec<Value>> {
|
||||||
// let _ = &ctx2;
|
// let _ = &ctx2;
|
||||||
// let mut b = ctx2.base.lock().unwrap();
|
// let mut b = ctx2.base.lock().unwrap();
|
||||||
let vals: Vec<_> = vec![Value::I32(base as i32)]
|
let vals: Vec<_> = base.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(vals.into_iter())
|
.chain(vals.into_iter())
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -150,10 +148,11 @@ impl<U: 'static, E: wasm_runtime_layer::backend::WasmEngine> Wrapped<U,E> {
|
||||||
let b = Arc::new(b.clone());
|
let b = Arc::new(b.clone());
|
||||||
// let ctx = ctx.clone();
|
// let ctx = ctx.clone();
|
||||||
let rs = rs.clone();
|
let rs = rs.clone();
|
||||||
|
let base = base2.clone();
|
||||||
(Arc::new(move |mut ctx:StoreContextMut<'_,U,E>,vals: Vec<Value>| -> anyhow::Result<Vec<Value>> {
|
(Arc::new(move |mut ctx:StoreContextMut<'_,U,E>,vals: Vec<Value>| -> anyhow::Result<Vec<Value>> {
|
||||||
// let _ = &ctx;
|
// let _ = &ctx;
|
||||||
// let mut bi = ctx.base.lock().unwrap();
|
// let mut bi = ctx.base.lock().unwrap();
|
||||||
let vals: Vec<_> = vec![Value::I32(base as i32)]
|
let vals: Vec<_> = base.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(vals.into_iter())
|
.chain(vals.into_iter())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
Loading…
Reference in a new issue