Skip to content

Commit

Permalink
Support reinterpret primitive types
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Dec 5, 2023
1 parent d7fb937 commit d959c18
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
namespace? package.collections.vector;




/// | pointer(4) | occupied(4) | capacity(4) | item(size) | item(size)
internal class PrimitiveArrayDynamic<T> {
pointer: usize,
occupied: usize,
capacity: usize,
element: PhantomData<T>,
}

class Vector<T> {
private memory: PrimitiveArrayDynamic<T>,
}

extends Vector<T> {
`[]`(self, nth: Ordinal): Option<T> {
if nth < self.pointer {
return null
}
else {
self.memory
`[]`(self, nth: Ordinal?): T? {
self[nth as? isize]
}
`[]`(self, nth: isize?): T? {
switch {
when nth == null:
null
when nth == 0:
null
when nth < 0:
self.memory.get(self.memory.length - nth)
when nth > 0:
self.memory.get(nth - 1)
}
.recast()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
namespace? package.collections.vector;


class PrimitiveEntry<T> {
structure PrimitiveEntry<T> {
private pointer: usize,
private element: PhantomData<T>,
}

structure MemoryEntry {
private pointer: usize,
private size: usize,
}

#[native]
extends PrimitiveEntry<T> {
private pointer: usize,
private element: PhantomData<T>,
violance constructor(pointer: usize) {
self.pointer = pointer;
}
violance reinterpret<U>(move self): PrimitiveEntry<U> {
self.element = PhantomData::<U>();
self
}
violance recast(move self): T {

}
}

0 comments on commit d959c18

Please sign in to comment.