Compare commits

...

1 Commits

Author SHA1 Message Date
d39a55a038 nac3artiq: rpc support host object as parameter 2022-05-16 04:26:37 +08:00

View File

@ -274,6 +274,9 @@ fn gen_rpc_tag<'ctx, 'a>(
buffer.push(b'l'); buffer.push(b'l');
gen_rpc_tag(ctx, *ty, buffer)?; gen_rpc_tag(ctx, *ty, buffer)?;
} }
TObj { .. } => {
buffer.push(b'O');
}
_ => return Err(format!("Unsupported type: {:?}", ctx.unifier.stringify(ty))), _ => return Err(format!("Unsupported type: {:?}", ctx.unifier.stringify(ty))),
} }
} }
@ -373,11 +376,11 @@ fn rpc_codegen_callback_fn<'ctx, 'a>(
.0 .0
.args .args
.iter() .iter()
.map(|arg| mapping.remove(&arg.name).unwrap().to_basic_value_enum(ctx, generator, arg.ty)) .map(|arg| mapping.remove(&arg.name).unwrap())
.collect::<Result<Vec<_>, _>>()?; .collect::<Vec<ValueEnum>>();
if let Some(obj) = obj { if let Some(obj) = obj {
if let ValueEnum::Static(obj) = obj.1 { if let ValueEnum::Static(obj) = obj.1 {
real_params.insert(0, obj.get_const_obj(ctx, generator)); real_params.insert(0, ValueEnum::Dynamic(obj.get_const_obj(ctx, generator)));
} else { } else {
// should be an error here... // should be an error here...
panic!("only host object is allowed"); panic!("only host object is allowed");
@ -385,6 +388,8 @@ fn rpc_codegen_callback_fn<'ctx, 'a>(
} }
for (i, arg) in real_params.iter().enumerate() { for (i, arg) in real_params.iter().enumerate() {
match arg {
ValueEnum::Dynamic(arg) => {
let arg_slot = ctx.builder.build_alloca(arg.get_type(), &format!("rpc.arg{}", i)); let arg_slot = ctx.builder.build_alloca(arg.get_type(), &format!("rpc.arg{}", i));
ctx.builder.build_store(arg_slot, *arg); ctx.builder.build_store(arg_slot, *arg);
let arg_slot = ctx.builder.build_bitcast(arg_slot, ptr_type, "rpc.arg"); let arg_slot = ctx.builder.build_bitcast(arg_slot, ptr_type, "rpc.arg");
@ -397,6 +402,23 @@ fn rpc_codegen_callback_fn<'ctx, 'a>(
}; };
ctx.builder.build_store(arg_ptr, arg_slot); ctx.builder.build_store(arg_ptr, arg_slot);
} }
ValueEnum::Static(arg) => {
let arg = arg.get_const_obj(ctx, generator);
let arg_slot = ctx.builder.build_alloca(arg.get_type(), &format!("rpc.arg{}", i));
ctx.builder.build_store(arg_slot, arg);
let arg_slot = ctx.builder.build_bitcast(arg_slot, ptr_type, "rpc.arg");
let arg_ptr = unsafe {
ctx.builder.build_gep(
args_ptr,
&[int32.const_int(i as u64, false)],
&format!("rpc.arg{}", i),
)
};
ctx.builder.build_store(arg_ptr, arg_slot);
}
}
}
// call // call
let rpc_send = ctx.module.get_function("rpc_send").unwrap_or_else(|| { let rpc_send = ctx.module.get_function("rpc_send").unwrap_or_else(|| {