From d959c185e4e1b8838305075081ad63bc5a8dd109 Mon Sep 17 00:00:00 2001 From: Aster Date: Tue, 5 Dec 2023 17:53:16 +0800 Subject: [PATCH] Support reinterpret primitive types --- .../primitive_array/PrimitiveArrayDynamic.vk | 24 ++++++++++++------- .../primitive_array/PrimitiveEntry.vk | 19 ++++++++++++--- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/projects/valkyrie-std/source/collection/primitive_array/PrimitiveArrayDynamic.vk b/projects/valkyrie-std/source/collection/primitive_array/PrimitiveArrayDynamic.vk index b4dee11..b83d672 100644 --- a/projects/valkyrie-std/source/collection/primitive_array/PrimitiveArrayDynamic.vk +++ b/projects/valkyrie-std/source/collection/primitive_array/PrimitiveArrayDynamic.vk @@ -1,8 +1,5 @@ namespace? package.collections.vector; - - - /// | pointer(4) | occupied(4) | capacity(4) | item(size) | item(size) internal class PrimitiveArrayDynamic { pointer: usize, @@ -10,18 +7,27 @@ internal class PrimitiveArrayDynamic { capacity: usize, element: PhantomData, } + class Vector { private memory: PrimitiveArrayDynamic, } extends Vector { - `[]`(self, nth: Ordinal): Option { - 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() } } diff --git a/projects/valkyrie-std/source/collection/primitive_array/PrimitiveEntry.vk b/projects/valkyrie-std/source/collection/primitive_array/PrimitiveEntry.vk index fbecdbc..90b4822 100644 --- a/projects/valkyrie-std/source/collection/primitive_array/PrimitiveEntry.vk +++ b/projects/valkyrie-std/source/collection/primitive_array/PrimitiveEntry.vk @@ -1,13 +1,26 @@ namespace? package.collections.vector; -class PrimitiveEntry { +structure PrimitiveEntry { private pointer: usize, private element: PhantomData, } +structure MemoryEntry { + private pointer: usize, + private size: usize, +} +#[native] extends PrimitiveEntry { - private pointer: usize, - private element: PhantomData, + violance constructor(pointer: usize) { + self.pointer = pointer; + } + violance reinterpret(move self): PrimitiveEntry { + self.element = PhantomData::(); + self + } + violance recast(move self): T { + + } } \ No newline at end of file