Progress update.

This commit is contained in:
yukirij 2024-12-20 14:37:34 -08:00
parent a8468a99eb
commit d53c560f5d
21 changed files with 253 additions and 4 deletions

View File

@ -7,3 +7,6 @@ edition = "2021"
num = "0.4.3"
pack = { git = "https://git.tsukiyo.org/Utility/pack" }
dict = { git = "https://git.tsukiyo.org/Utility/dictionary" }
pool = { git = "https://git.tsukiyo.org/Utility/pool" }
sparse = { git = "https://git.tsukiyo.org/Utility/sparse" }

2
LICENSE.txt Normal file
View File

@ -0,0 +1,2 @@
Project: Suzu
https://ykr.info/license/

1
README.md Normal file
View File

@ -0,0 +1 @@
# Suzu Data System

16
src/bin/schema.rs Normal file
View File

@ -0,0 +1,16 @@
struct Member {
name:Option<usize>,
typeid:usize,
}
struct Schema {
capacity:usize,
length:usize,
data:*mut usize,
}
struct Record {
}
fn main() { }

View File

@ -13,13 +13,16 @@ impl Any {
}
impl Szun for Any {
fn typeid() -> usize { 0 }
fn encode(&self) -> Vec<u8> { Vec::new() }
fn decode(&mut self, _:&Vec<u8>, _:&mut usize) -> Result<(),()> { Err(()) }
}
impl internal::SzunInternal for Any {
fn to_ref(&self) -> Ref { self.refer }
fn from_ref(refer:Ref) -> Self { Self { refer } }
}
impl Clone for Any {
fn clone(&self) -> Self { Self::from_ref(clone(self.to_ref(), None)) }
fn clone(&self) -> Self { println!("tid {}", self.to_ref().typeid()); Self::from_ref(clone(self.to_ref(), None)) }
}
impl Drop for Any {
fn drop(&mut self) { drop(self.to_ref()); }

View File

@ -34,6 +34,20 @@ impl Boolean {
}
impl Szun for Boolean {
fn typeid() -> usize { Runtime::type_from(types::ANY, &[types::BOOLEAN]) }
fn encode(&self) -> Vec<u8> {
vec![self.get() as u8]
}
fn decode(&mut self, bytes:&Vec<u8>, index:&mut usize) -> Result<(),()> {
if bytes.len() - *index >= 1 {
self.set(bytes[*index] != 0);
*index += 1;
Ok(())
} else {
Err(())
}
}
}
impl SzunInternal for Boolean {
fn to_ref(&self) -> Ref { self.refer }

View File

@ -7,3 +7,4 @@ pub mod block; pub use block::Block;
pub mod sequence; pub use sequence::Sequence;
pub mod optional; pub use optional::Optional;
pub mod array; pub use array::Array;
pub mod schema; pub use schema::Schema;

View File

@ -35,6 +35,14 @@ impl Natural {
}
impl Szun for Natural {
fn typeid() -> usize { Runtime::type_from(types::ANY, &[types::NATURAL]) }
fn encode(&self) -> Vec<u8> {
Vec::new()
}
fn decode(&mut self, bytes:&Vec<u8>, index:&mut usize) -> Result<(),()> {
Err(())
}
}
impl SzunInternal for Natural {
fn to_ref(&self) -> Ref { self.refer }

View File

@ -8,6 +8,9 @@ impl Null {
}
impl Szun for Null {
fn typeid() -> usize { Runtime::type_from(types::ANY, &[types::BOOLEAN]) }
fn encode(&self) -> Vec<u8> { Vec::new() }
fn decode(&mut self, _:&Vec<u8>, _:&mut usize) -> Result<(),()> { Err(()) }
}
impl SzunInternal for Null {
fn to_ref(&self) -> Ref { Ref::null() }

View File

@ -94,6 +94,33 @@ impl<T:Szun> Optional<T> {
}
impl<T:Szun> Szun for Optional<T> {
fn typeid() -> usize { Runtime::type_from(T::typeid(), &[types::OPTIONAL]) }
fn encode(&self) -> Vec<u8> {
if let Some(value) = self.get() {
[
vec![0x01],
encode(value.to_ref()),
].concat()
} else {
vec![0x00]
}
}
fn decode(&mut self, bytes:&Vec<u8>, index:&mut usize) -> Result<(),()> {
if bytes.len() - *index >= 1 {
let some = bytes[*index];
*index += 1;
if some != 0 {
self.set_default();
decode(self.to_ref().inner(), bytes, index)
} else {
Ok(())
}
} else {
Err(())
}
}
}
impl<T:Szun> SzunInternal for Optional<T> {
fn to_ref(&self) -> Ref { self.refer }

0
src/implement/record.rs Normal file
View File

42
src/implement/schema.rs Normal file
View File

@ -0,0 +1,42 @@
use crate::{prelude::{*, internal::*}, Runtime, Any, types};
pub(crate) struct SchemaData {
}
pub struct Schema {
refer:Ref,
}
impl Schema {
pub fn new() -> Self {
Self {
refer:Runtime::acquire(Self::typeid()),
}
}
pub fn add<T:Szun>(&mut self) -> Result<(),()>
{
Err(())
}
pub fn add_named<T:Szun>(&mut self, name:&str) -> Result<(),()>
{
Err(())
}
}
impl Szun for Schema {
fn typeid() -> usize { Runtime::type_from(types::ANY, &[types::SCHEMA]) }
fn encode(&self) -> Vec<u8> {
Vec::new()
}
fn decode(&mut self, bytes:&Vec<u8>, index:&mut usize) -> Result<(),()> {
Err(())
}
}
impl SzunInternal for Schema {
fn to_ref(&self) -> Ref { self.refer }
fn from_ref(refer:Ref) -> Self { Self { refer } }
}
crate::impl_szun!(Schema);

View File

@ -101,6 +101,14 @@ impl Sequence {
}
impl Szun for Sequence {
fn typeid() -> usize { Runtime::type_from(types::ANY, &[types::SEQUENCE]) }
fn encode(&self) -> Vec<u8> {
Vec::new()
}
fn decode(&mut self, bytes:&Vec<u8>, index:&mut usize) -> Result<(),()> {
Err(())
}
}
impl internal::SzunInternal for Sequence {
fn to_ref(&self) -> Ref { self.refer }

View File

@ -5,3 +5,6 @@ pub mod prelude; pub use prelude::*;
mod types;
mod runtime; use runtime::Runtime;
mod implement; pub use implement::*;
#[cfg(test)]
mod test;

View File

@ -18,8 +18,8 @@ pub trait Szun : internal::SzunInternal + Clone + TryFrom<Any> + Into<Any> + Dro
|| Runtime::type_in(self_type) == 0
}
fn encode(&self) -> Vec<u8> { encode(self.to_ref()) }
fn decode(&mut self, bytes:&Vec<u8>, index:&mut usize) -> Result<(),()> { decode(self.to_ref(), bytes, index) }
fn encode(&self) -> Vec<u8>;
fn decode(&mut self, bytes:&Vec<u8>, index:&mut usize) -> Result<(),()>;
fn tag(&self) -> Vec<u8>
{

View File

@ -1,10 +1,29 @@
use crate::{prelude::*, types};
use sparse::Sparse;
use pool::Pool;
mod typetree; use typetree::TypeTree;
enum Binding {
Schema {
length:usize,
size:usize,
align:usize,
next:usize,
},
Member {
term:usize,
typeid:usize,
offset:usize,
next:usize,
},
}
struct RuntimeData {
terms:Vec<u8>,
terms:dict::Dictionary,
types:TypeTree,
bindings:Pool<Binding>,
bindings_ext:Sparse<usize>,
}
impl RuntimeData {
const fn init() -> Self
@ -12,6 +31,8 @@ impl RuntimeData {
Self {
terms:Vec::new(),
types:TypeTree::new(),
bindings:Pool::new(),
bindings_ext:Sparse::new(),
}
}

30
src/test/any.rs Normal file
View File

@ -0,0 +1,30 @@
use crate::*;
#[test]
fn any_from_natural()
{
const EXPECT :u32 = 5025;
let any :Any = Natural::new().with(EXPECT).into();
let mut value = 0;
if let Ok(nat) = Natural::try_from(any) {
value = nat.get();
}
assert_eq!(EXPECT, value);
}
#[test]
fn any_clone_natural()
{
const EXPECT :u32 = 5025;
let any :Any = Natural::new().with(EXPECT).into();
let any = any.clone();
let mut value = 0;
if let Ok(nat) = Natural::try_from(any) {
value = nat.get();
}
assert_eq!(EXPECT, value);
}

1
src/test/mod.rs Normal file
View File

@ -0,0 +1 @@
mod any;

View File

@ -0,0 +1,64 @@
#[derive(Clone, Copy)]
pub(crate) struct DynListData {
capacity:usize,
length:usize,
data:*mut u8,
}
#[derive(Clone, Copy)]
pub struct DynList {
size:usize,
align:usize,
data:DynListData,
}
impl DynList<Z> {
pub fn from_parts(ptr:*const DynListData, size:usize, align:usize) -> Self {
Self {
size,
align,
data:unsafe {*ptr},
}
}
pub fn reserve(&mut self) -> Result<*mut u8,()>
{
if self.length == self.capacity {
self.resize(self.capacity * 2)?;
}
self.length += 1;
cell(self.length - 1)
}
pub fn cell(&self, index:usize) -> Result<*mut u8,()>
{
if index < self.length {
Ok(unsafe {self.data.byte_add(index * self.size)})
} else {
Err(())
}
}
pub fn resize(&mut self, capacity:usize) -> Result<(),()>
{
use std::alloc::{alloc_zeroed, Layout};
let ptr = self.data;
if capacity > 0 {
if let Ok(layout) = Layout::from_size_align(size, types::align(typeid)) {
let address :*const u8;
unsafe {
address = alloc_zeroed(layout) as _;
}
Ref::new(typeid, address)
} else {
Ref::null()
}
} else {
Ref::null()
}
self.capacity = capacity;
Ok(())
}
}

View File

@ -0,0 +1 @@
mod dynlist; pub use dynlist::RawList;

View File

@ -1 +1,2 @@
pub mod macros;
mod container; pub use container::*;