deimos-lang/dvm-lib/mem.md
2026-07-30 21:05:13 -05:00

49 lines
692 B
Markdown

# Object/Memory/Heap Concepts for Deimos/DVM
```rust
use std::any::TypeId;
trait Trace {
fn grays(&self) -> &[GcAny];
}
struct Gc<T: Trace> {
inner: *mut GcInner<T>,
}
impl<T> Gc {
fn data(&self) -> &T {
&self.inner.data
}
}
struct GcMut<T: Trace> {
inner: *mut GcInner<T>,
}
struct GcInner<T: Trace> {
data: T,
gc_count: usize,
gc_mut_count: bool,
next: Option<GcAny>,
color: bool,
}
struct GcAny {
inner: *mut (), // like void* in C
v_table: *const GcAnyVTable,
type_id: *const TypeId,
}
enum Value {
Object(Gc<Object>),
Int(i32),
String(Gc<String>),
Null
}
struct Object {
class: *const Class,
}
```