@@ -45,7 +45,7 @@ impl ClassProcessedData {
|
||||
.collect::<Vec<Spanned<FunctionDecl>>>();
|
||||
|
||||
let mut v_table = Vec::new();
|
||||
let mut override_v_table = std::collections::HashMap::new();
|
||||
let mut override_v_table = HashMap::new();
|
||||
|
||||
for method in &methods {
|
||||
if matches!(method.item.visibility, Visibility::Public) {
|
||||
@@ -113,7 +113,7 @@ impl ClassProcessedData {
|
||||
cg.add(&get_type_from_path(inherits).get_rust());
|
||||
cg.addln(",");
|
||||
} else {
|
||||
cg.add_indentedln("pub _vptr: &'static [*const std::ffi::c_void],");
|
||||
cg.add_indentedln("pub _vptr: &'static [*const core::ffi::c_void],");
|
||||
}
|
||||
|
||||
for field in &self.fields {
|
||||
@@ -174,11 +174,11 @@ impl ClassProcessedData {
|
||||
self.v_table.len()
|
||||
));
|
||||
|
||||
cg.add_indentedln("pub const __V_TABLE: &'static [*const std::ffi::c_void] = &{");
|
||||
cg.add_indentedln("pub const __V_TABLE: &'static [*const core::ffi::c_void] = &{");
|
||||
cg.indent += 1;
|
||||
|
||||
if has_parent {
|
||||
cg.add_indentedln("let mut table = [std::ptr::null(); Self::__V_COUNT];");
|
||||
cg.add_indentedln("let mut table = [core::ptr::null(); Self::__V_COUNT];");
|
||||
|
||||
cg.add_indentedln(&format!("let parent_table = {}::__V_TABLE;", parent_path));
|
||||
cg.add_indentedln(
|
||||
@@ -193,7 +193,7 @@ impl ClassProcessedData {
|
||||
.get_rust();
|
||||
for (method_ident, is_virtual) in &overriden_method_idents.item {
|
||||
cg.add_indentedln(&format!(
|
||||
"table[{}::__FN_{}] = {}::{} as *const std::ffi::c_void;",
|
||||
"table[{}::__FN_{}] = {}::{} as *const core::ffi::c_void;",
|
||||
base_class_path,
|
||||
method_ident.0.to_uppercase(),
|
||||
self.self_path.get_rust(),
|
||||
@@ -204,7 +204,7 @@ impl ClassProcessedData {
|
||||
|
||||
for method_name in &self.v_table {
|
||||
cg.add_indentedln(&format!(
|
||||
"table[Self::__FN_{}] = Self::__m_{} as *const std::ffi::c_void;",
|
||||
"table[Self::__FN_{}] = Self::__m_{} as *const core::ffi::c_void;",
|
||||
method_name.0.to_uppercase(),
|
||||
method_name.get_rust()
|
||||
));
|
||||
@@ -216,7 +216,7 @@ impl ClassProcessedData {
|
||||
cg.indent += 1;
|
||||
for method_name in &self.v_table {
|
||||
cg.add_indentedln(&format!(
|
||||
"Self::__m_{} as *const std::ffi::c_void,",
|
||||
"Self::__m_{} as *const core::ffi::c_void,",
|
||||
method_name.get_rust()
|
||||
));
|
||||
}
|
||||
@@ -293,7 +293,7 @@ impl ClassProcessedData {
|
||||
|
||||
// Deref tests for override targets
|
||||
if self.inherits.is_some() && !self.override_v_table.is_empty() {
|
||||
cg.add_indentedln("let this: &Self = &unsafe { std::mem::MaybeUninit::<Self>::zeroed().assume_init() };");
|
||||
cg.add_indentedln("let this: &Self = &unsafe { core::mem::MaybeUninit::<Self>::zeroed().assume_init() };");
|
||||
|
||||
for (override_tier, v) in &self.override_v_table {
|
||||
if let Some(path) = &override_tier.0 {
|
||||
@@ -346,7 +346,7 @@ impl ClassProcessedData {
|
||||
cg.addln(") -> Self {");
|
||||
cg.indent += 1;
|
||||
|
||||
cg.add_indentedln("let mut this: Self = unsafe { std::mem::MaybeUninit::<Self>::zeroed().assume_init() };");
|
||||
cg.add_indentedln("let mut this: Self = unsafe { core::mem::MaybeUninit::<Self>::zeroed().assume_init() };");
|
||||
cg.add_indentedln("this._vptr = &Self::__V_TABLE;");
|
||||
|
||||
for field in &self.fields {
|
||||
@@ -433,7 +433,7 @@ impl ClassProcessedData {
|
||||
let generics_expr_str = Generics::from(self.generics.clone()).get_rust();
|
||||
|
||||
cg.add(&format!(
|
||||
"impl{} std::ops::Deref for {}{}",
|
||||
"impl{} core::ops::Deref for {}{}",
|
||||
generics_str,
|
||||
self.name.get_rust(),
|
||||
generics_expr_str
|
||||
@@ -452,7 +452,7 @@ impl ClassProcessedData {
|
||||
cg.addln("}");
|
||||
|
||||
cg.add(&format!(
|
||||
"impl{} std::ops::DerefMut for {}{}",
|
||||
"impl{} core::ops::DerefMut for {}{}",
|
||||
generics_str,
|
||||
self.name.get_rust(),
|
||||
generics_expr_str
|
||||
@@ -580,7 +580,7 @@ pub fn gen_method_point(method: &FunctionDecl, ctx: &mut Context, cg: &mut RustC
|
||||
mutable: mutable_self,
|
||||
ty: Box::new(TypeExpr::Path(
|
||||
Path(vec![
|
||||
Identifier(String::from("std")),
|
||||
Identifier(String::from("core")),
|
||||
Identifier(String::from("ffi")),
|
||||
Identifier(String::from("c_void")),
|
||||
]),
|
||||
@@ -590,12 +590,12 @@ pub fn gen_method_point(method: &FunctionDecl, ctx: &mut Context, cg: &mut RustC
|
||||
);
|
||||
|
||||
cg.add(&TypeExpr::StaticFn(param_types, method.return_type.clone().map(Box::new)).get_rust());
|
||||
cg.addln(" = std::mem::transmute(func_ptr);");
|
||||
cg.addln(" = core::mem::transmute(func_ptr);");
|
||||
|
||||
if mutable_self {
|
||||
cg.add_indented("func(self as *mut Self as *const std::ffi::c_void");
|
||||
cg.add_indented("func(self as *mut Self as *const core::ffi::c_void");
|
||||
} else {
|
||||
cg.add_indented("func(self as *const Self as *const std::ffi::c_void");
|
||||
cg.add_indented("func(self as *const Self as *const core::ffi::c_void");
|
||||
}
|
||||
|
||||
for (_, param) in ¶ms {
|
||||
|
||||
@@ -239,7 +239,6 @@ impl GetRust for TypeExpr {
|
||||
path.get_rust()
|
||||
}
|
||||
}
|
||||
Self::Lifetime(name) => format!("'{}", name.get_rust()),
|
||||
Self::Tuple(types) => format!(
|
||||
"({})",
|
||||
types
|
||||
|
||||
@@ -24,7 +24,21 @@ impl GetRust for GenericsDecl {
|
||||
impl GetRust for GenericDecl {
|
||||
fn get_rust(&self) -> String {
|
||||
match self {
|
||||
GenericDecl::Lifetime(name) => format!("'{}", name.get_rust()),
|
||||
GenericDecl::Lifetime(name, requirements) => {
|
||||
format!("'{}", name.get_rust())
|
||||
+ &(if requirements.len() != 0 {
|
||||
format!(
|
||||
": {}",
|
||||
requirements
|
||||
.into_iter()
|
||||
.map(GetRust::get_rust)
|
||||
.collect::<Vec<_>>()
|
||||
.join("+")
|
||||
)
|
||||
} else {
|
||||
String::new()
|
||||
})
|
||||
}
|
||||
GenericDecl::Type(name, requirements) => {
|
||||
name.get_rust()
|
||||
+ &(if requirements.len() != 0 {
|
||||
@@ -32,7 +46,7 @@ impl GetRust for GenericDecl {
|
||||
": {}",
|
||||
requirements
|
||||
.into_iter()
|
||||
.map(TypeExpr::get_rust)
|
||||
.map(GetRust::get_rust)
|
||||
.collect::<Vec<_>>()
|
||||
.join("+")
|
||||
)
|
||||
|
||||
@@ -41,7 +41,6 @@ pub enum TypeExpr {
|
||||
Path(Path, Option<Generics>),
|
||||
StaticFn(Vec<TypeExpr>, Option<Box<TypeExpr>>),
|
||||
Tuple(Vec<TypeExpr>),
|
||||
Lifetime(Identifier),
|
||||
Void,
|
||||
Fn {
|
||||
kind: FnKind,
|
||||
@@ -61,7 +60,7 @@ pub struct Spanned<T> {
|
||||
impl From<GenericDecl> for Generic {
|
||||
fn from(value: GenericDecl) -> Self {
|
||||
match value {
|
||||
GenericDecl::Lifetime(life) => Generic::Lifetime(life),
|
||||
GenericDecl::Lifetime(life, _) => Generic::Lifetime(life),
|
||||
GenericDecl::Type(ty, _) => Generic::Type(TypeExpr::Path(Path(vec![ty]), None)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,8 +82,8 @@ pub struct GenericsDecl(pub Vec<GenericDecl>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum GenericDecl {
|
||||
Lifetime(Identifier),
|
||||
Type(Identifier, Vec<TypeExpr>),
|
||||
Lifetime(Identifier, Vec<Generic>),
|
||||
Type(Identifier, Vec<Generic>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
@@ -90,7 +90,7 @@ mutable = { "mut" }
|
||||
// ======================================================
|
||||
// GENERICS
|
||||
// ======================================================
|
||||
generic_decl = { lifetime | (identifier ~ (":" ~ generic ~ ("+" ~ generic)*)?) }
|
||||
generic_decl = { (lifetime | identifier) ~ (":" ~ generic ~ ("+" ~ generic)*)? }
|
||||
generics_decl = { "<" ~ (generic_decl ~ ("," ~ generic_decl)*)? ~ ">" }
|
||||
|
||||
generic = { lifetime | type_expr }
|
||||
@@ -125,9 +125,9 @@ fn_kind_mut = { "FnMut" }
|
||||
fn_kind = _{
|
||||
fn_kind_fn
|
||||
| fn_kind_unsafe
|
||||
| fn_kind_closure
|
||||
| fn_kind_once
|
||||
| fn_kind_mut
|
||||
| fn_kind_closure
|
||||
}
|
||||
|
||||
fn_type = {
|
||||
|
||||
@@ -75,7 +75,6 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TypeExpr {
|
||||
|
||||
Ok(ty)
|
||||
}
|
||||
Rule::lifetime => Ok(TypeExpr::Lifetime(inner.next().unwrap().try_into()?)),
|
||||
|
||||
Rule::void_type => Ok(TypeExpr::Void),
|
||||
Rule::tuple_type => Ok(TypeExpr::Tuple(collect_recovered(inner)?)),
|
||||
@@ -132,6 +131,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for GenericDecl {
|
||||
if let Some(pair) = consume_rule(&mut inner, Rule::lifetime) {
|
||||
Ok(GenericDecl::Lifetime(
|
||||
pair.into_inner().next().unwrap().try_into()?,
|
||||
collect_recovered(inner)?,
|
||||
))
|
||||
} else {
|
||||
Ok(GenericDecl::Type(
|
||||
|
||||
Reference in New Issue
Block a user