Skip to content

Commit 0f4ae19

Browse files
committed
Add 'magic' types and extern types
Will avoid usage of the never type for 'extern type' declarations. Also avoids things like 'enum PyTypeObject {}'. Magic types will support user-extensions, like VariableId in DuckASM. TODO: Typed pointers (NOTE: Will need to avoid cycles)
1 parent 3b1b8a4 commit 0f4ae19

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/types.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,25 @@ pub enum TypeInfo<'a> {
177177
Structure(&'a StructureDef<'a>),
178178
/// An untagged union
179179
Union(&'a UnionDef<'a>),
180+
/// A named, transparent, extern type
181+
Extern {
182+
/// The name of the type
183+
///
184+
/// Since this is all we have, it's what used
185+
/// to disambiguate between them.
186+
name: &'static str
187+
},
188+
/// A 'magic' type, with a user-defined meaning
189+
///
190+
/// This allows extensions to the type system
191+
Magic {
192+
/// The id of the magic type,
193+
/// giving more information about how its implemented
194+
/// and what it actually means.
195+
id: &'static &'static str,
196+
/// Extra information (if any)
197+
extra: Option<&'a TypeInfo<'a>>,
198+
}
180199
}
181200
/*
182201
* HACK: Implement AsmType as `NullTrace`
@@ -240,7 +259,9 @@ impl<'tp> TypeInfo<'tp> {
240259
#[cfg(feature = "builtins")]
241260
Str => size_of::<AsmStr>(),
242261
Structure(ref def) => def.size,
243-
Union(ref def) => def.size
262+
Union(ref def) => def.size,
263+
// Provide a dummy value
264+
TypeInfo::Magic { .. } | TypeInfo::Extern { .. } => 0xFFFF_FFFF
244265
}
245266
}
246267
/// The alignment of the type, matching `std::mem::align_of`
@@ -250,6 +271,7 @@ impl<'tp> TypeInfo<'tp> {
250271
TypeInfo::Unit => align_of::<()>(),
251272
#[cfg(feature = "never")]
252273
TypeInfo::Never => align_of::<!>(),
274+
TypeInfo::Magic { .. } | TypeInfo::Extern { .. } => 0,
253275
TypeInfo::Bool => align_of::<bool>(),
254276
TypeInfo::Integer { size: IntSize::Byte, signed: false } => align_of::<u8>(),
255277
TypeInfo::Integer { size: IntSize::Short, signed: false } => align_of::<u16>(),
@@ -286,6 +308,9 @@ impl<'a> Display for TypeInfo<'a> {
286308
TypeInfo::Pointer => f.write_str("*mut void"),
287309
TypeInfo::Structure(ref def) => f.write_str(def.name),
288310
TypeInfo::Union(ref def) => f.write_str(def.name),
311+
TypeInfo::Extern { name } => write!(f, "extern {}", name),
312+
TypeInfo::Magic { id, extra: None } => write!(f, "magic::{}", id),
313+
TypeInfo::Magic { id, extra: Some(extra) } => write!(f, "magic::{}<{}>", id, extra)
289314
}
290315
}
291316
}

0 commit comments

Comments
 (0)