Revise lit definitions and layout

next
Sayan Nandan 2 years ago
parent 73df6f9af4
commit 9bc3d85b1c
No known key found for this signature in database
GPG Key ID: 42EEDF4AE9D96B54

@ -176,10 +176,10 @@ impl<'a> From<LitIR<'a>> for Datacell {
fn from(l: LitIR<'a>) -> Self {
match l.kind().tag_class() {
tag if tag < TagClass::Bin => unsafe {
let [a, b] = l.data().load_fat();
// DO NOT RELY ON the payload's bit pattern; it's padded
Datacell::new(
l.kind().tag_class(),
DataRaw::word(SystemDword::store_fat(a, b)),
DataRaw::word(SystemDword::store_qw(l.data().load_qw())),
)
},
tag @ (TagClass::Bin | TagClass::Str) => unsafe {

@ -54,8 +54,8 @@ type Fields = IndexSTSeqCns<Box<str>, Field>;
#[derive(Debug)]
pub struct ModelView {
pub(super) p_key: Box<str>,
pub(super) p_tag: FullTag,
p_key: Box<str>,
p_tag: FullTag,
fields: UnsafeCell<Fields>,
sync_matrix: ISyncMatrix,
}
@ -70,6 +70,12 @@ impl PartialEq for ModelView {
}
impl ModelView {
pub fn p_key(&self) -> &str {
&self.p_key
}
pub fn p_tag(&self) -> FullTag {
self.p_tag
}
pub fn sync_matrix(&self) -> &ISyncMatrix {
&self.sync_matrix
}

@ -38,8 +38,8 @@ mod validation {
#[test]
fn simple() {
let model = create("create model mymodel(username: string, password: binary)").unwrap();
assert_eq!(model.p_key.as_ref(), "username");
assert_eq!(model.p_tag, FullTag::STR);
assert_eq!(model.p_key(), "username");
assert_eq!(model.p_tag(), FullTag::STR);
assert_eq!(
model
.intent_read_model()
@ -58,8 +58,8 @@ mod validation {
fn idiotic_order() {
let model =
create("create model mymodel(password: binary, primary username: string)").unwrap();
assert_eq!(model.p_key.as_ref(), "username");
assert_eq!(model.p_tag, FullTag::STR);
assert_eq!(model.p_key(), "username");
assert_eq!(model.p_tag(), FullTag::STR);
assert_eq!(
model
.intent_read_model()
@ -151,8 +151,8 @@ mod exec {
.stseq_ord_kv()
.map(|(k, v)| (k.to_string(), v.clone()))
.collect();
assert_eq!(model.p_key.as_ref(), "username");
assert_eq!(model.p_tag, FullTag::STR);
assert_eq!(model.p_key(), "username");
assert_eq!(model.p_tag(), FullTag::STR);
assert_eq!(
models,
[

@ -29,7 +29,7 @@ use {
spec::{Dataspec1D, DataspecMeta1D, DataspecMethods1D, DataspecRaw1D},
tag::{DataTag, FullTag},
},
crate::engine::mem::{NativeDword, SystemDword},
crate::engine::mem::{SpecialPaddedWord, SystemDword},
core::{
fmt,
marker::PhantomData,
@ -42,7 +42,7 @@ use {
*/
pub struct Lit<'a> {
data: NativeDword,
data: SpecialPaddedWord,
tag: FullTag,
_lt: PhantomData<&'a [u8]>,
}
@ -58,7 +58,7 @@ impl<'a> Lit<'a> {
impl<'a> DataspecMeta1D for Lit<'a> {
type Tag = FullTag;
type Target = NativeDword;
type Target = SpecialPaddedWord;
type StringItem = Box<str>;
fn new(flag: Self::Tag, data: Self::Target) -> Self {
Self {
@ -174,12 +174,12 @@ direct_from! {
pub struct LitIR<'a> {
tag: FullTag,
data: NativeDword,
data: SpecialPaddedWord,
_lt: PhantomData<&'a str>,
}
impl<'a> DataspecMeta1D for LitIR<'a> {
type Target = NativeDword;
type Target = SpecialPaddedWord;
type StringItem = &'a str;
type Tag = FullTag;
fn new(flag: Self::Tag, data: Self::Target) -> Self {

@ -49,6 +49,18 @@ pub struct NativeDword([usize; 2]);
pub struct NativeTword([usize; 3]);
/// Native quad pointer width (note, native != arch native, but host native)
pub struct NativeQword([usize; 4]);
/// A special word with a special bit pattern padded (with a quad)
///
/// **WARNING**: DO NOT EXPECT this to have the same bit pattern as that of native word sizes. It's called "special" FOR A REASON
pub struct SpecialPaddedWord {
a: u64,
b: usize,
}
impl SpecialPaddedWord {
const fn new(a: u64, b: usize) -> Self {
Self { a, b }
}
}
pub trait StatelessLen {
fn stateless_len(&self) -> usize;

@ -24,7 +24,9 @@
*
*/
use super::{NativeDword, NativeQword, NativeTword};
use super::{NativeDword, NativeQword, NativeTword, SpecialPaddedWord};
static ZERO_BLOCK: [u8; 0] = [];
/// Native quad pointer stack (must also be usable as a double and triple pointer stack. see [`SystemTword`] and [`SystemDword`])
pub trait SystemQword: SystemTword {
@ -36,12 +38,6 @@ pub trait SystemQword: SystemTword {
{
WordRW::store(v)
}
fn ld_special<'a, T>(&'a self) -> T::Target<'a>
where
T: WordRW<Self>,
{
<T>::load(self)
}
fn ld<'a, T>(&'a self) -> T
where
T: WordRW<Self, Target<'a> = T>,
@ -60,12 +56,6 @@ pub trait SystemTword: SystemDword {
{
WordRW::store(v)
}
fn ld_special<'a, T>(&'a self) -> T::Target<'a>
where
T: WordRW<Self>,
{
<T>::load(self)
}
fn ld<'a, T>(&'a self) -> T
where
T: WordRW<Self, Target<'a> = T>,
@ -86,12 +76,6 @@ pub trait SystemDword: Sized {
{
WordRW::store(v)
}
fn ld_special<'a, T>(&'a self) -> T::Target<'a>
where
T: WordRW<Self>,
{
<T>::load(self)
}
fn ld<'a, T>(&'a self) -> T
where
T: WordRW<Self, Target<'a> = T>,
@ -100,6 +84,21 @@ pub trait SystemDword: Sized {
}
}
impl SystemDword for SpecialPaddedWord {
fn store_qw(u: u64) -> Self {
Self::new(u, ZERO_BLOCK.as_ptr() as usize)
}
fn store_fat(a: usize, b: usize) -> Self {
Self::new(a as u64, b)
}
fn load_qw(&self) -> u64 {
self.a
}
fn load_fat(&self) -> [usize; 2] {
[self.a as usize, self.b]
}
}
impl SystemDword for NativeDword {
#[inline(always)]
fn store_qw(u: u64) -> Self {

Loading…
Cancel
Save