Working param and return type fn type

This commit is contained in:
2026-06-07 00:30:27 +02:00
parent e7b4e65b71
commit d0796aa5df
3 changed files with 48 additions and 12 deletions
+16 -3
View File
@@ -317,13 +317,26 @@ pub fn gen_method_point(method: &FunctionDecl, ctx: &mut Context, cg: &mut RustC
param_types.remove(0); param_types.remove(0);
// param_types.insert(0, ); param_types.insert(
0,
TypeExpr::UnsafePtr {
mutable: true,
ty: Box::new(TypeExpr::Path(
Path(vec![
Identifier(String::from("std")),
Identifier(String::from("ffi")),
Identifier(String::from("c_void")),
]),
None,
)),
},
);
cg.add(&TypeExpr::StaticFn(param_types).get_rust()); cg.add(&TypeExpr::StaticFn(param_types, method.return_type.clone().map(Box::new)).get_rust());
cg.addln(" = std::mem::transmute(func_ptr);"); cg.addln(" = std::mem::transmute(func_ptr);");
cg.add_indentedln("func(self._m_oop.1);"); cg.add_indentedln("func(self._m_oop.1)");
cg.indent -= 1; cg.indent -= 1;
cg.add_indentedln("}"); cg.add_indentedln("}");
+27 -8
View File
@@ -192,14 +192,33 @@ impl GetRust for TypeExpr {
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", ") .join(", ")
), ),
Self::StaticFn(types) => format!( Self::StaticFn(types, return_type) => {
"fn({})", if let Some(return_type) = return_type {
types format!(
.into_iter() "fn({}) -> {}",
.map(|t| t.get_rust()) types
.collect::<Vec<_>>() .into_iter()
.join(", ") .map(|t| t.get_rust())
), .collect::<Vec<_>>()
.join(", "),
return_type.get_rust()
)
} else {
format!(
"fn({})",
types
.into_iter()
.map(|t| t.get_rust())
.collect::<Vec<_>>()
.join(", "),
)
}
}
Self::UnsafePtr { mutable, ty } => {
let mutable = if *mutable { "mut " } else { "const " };
format!("*{mutable}{}", ty.get_rust())
}
Self::Ref { Self::Ref {
lifetime, lifetime,
+5 -1
View File
@@ -24,9 +24,13 @@ pub enum TypeExpr {
mutable: bool, mutable: bool,
ty: Box<TypeExpr>, ty: Box<TypeExpr>,
}, },
UnsafePtr {
mutable: bool,
ty: Box<TypeExpr>,
},
Dyn(Box<TypeExpr>), Dyn(Box<TypeExpr>),
Path(Path, Option<Generics>), Path(Path, Option<Generics>),
StaticFn(Vec<TypeExpr>), StaticFn(Vec<TypeExpr>, Option<Box<TypeExpr>>),
Tuple(Vec<TypeExpr>), Tuple(Vec<TypeExpr>),
Lifetime(Identifier), Lifetime(Identifier),
} }