Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added StorageValue for tuples up to size 4. #3674

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 234 additions & 0 deletions corelib/src/starknet/storage_access.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,237 @@ impl StorageValueClassHash of StorageValue<ClassHash> {
1_u8
}
}

impl TupleSize0StorageValue of StorageValue<()> {
#[inline(always)]
fn read(address_domain: u32, base: StorageBaseAddress) -> SyscallResult<()> {
Result::Ok(())
}
#[inline(always)]
fn write(address_domain: u32, base: StorageBaseAddress, value: ()) -> SyscallResult<()> {
Result::Ok(())
}
#[inline(always)]
fn read_at_offset(
address_domain: u32, base: StorageBaseAddress, offset: u8
) -> SyscallResult<()> {
Result::Ok(())
}
#[inline(always)]
fn write_at_offset(
address_domain: u32, base: StorageBaseAddress, offset: u8, value: ()
) -> SyscallResult<()> {
Result::Ok(())
}
#[inline(always)]
fn size() -> u8 {
0
}
}

impl TupleSize1StorageValue<
E0, impl E0StorageValue: StorageValue<E0>, impl E0Drop: Drop<E0>
> of StorageValue<(E0, )> {
#[inline(always)]
fn read(address_domain: u32, base: StorageBaseAddress) -> SyscallResult<(E0, )> {
Result::Ok((E0StorageValue::read(address_domain, base)?, ))
}
#[inline(always)]
fn write(address_domain: u32, base: StorageBaseAddress, value: (E0, )) -> SyscallResult<()> {
let (e0, ) = value;
E0StorageValue::write(address_domain, base, e0)
}
#[inline(always)]
fn read_at_offset(
address_domain: u32, base: StorageBaseAddress, offset: u8
) -> SyscallResult<(E0, )> {
Result::Ok((E0StorageValue::read_at_offset(address_domain, base, offset)?, ))
}
#[inline(always)]
fn write_at_offset(
address_domain: u32, base: StorageBaseAddress, offset: u8, value: (E0, )
) -> SyscallResult<()> {
let (e0, ) = value;
E0StorageValue::write_at_offset(address_domain, base, offset, e0)
}
#[inline(always)]
fn size() -> u8 {
E0StorageValue::size()
}
}

impl TupleSize2StorageValue<
E0,
E1,
impl E0StorageValue: StorageValue<E0>,
impl E0Drop: Drop<E0>,
impl E1StorageValue: StorageValue<E1>,
impl E0Drop: Drop<E1>
> of StorageValue<(E0, E1)> {
#[inline(always)]
fn read(address_domain: u32, base: StorageBaseAddress) -> SyscallResult<(E0, E1)> {
let e0 = E0StorageValue::read(address_domain, base)?;
let e1 = E1StorageValue::read_at_offset(address_domain, base, E0StorageValue::size())?;
Result::Ok((e0, e1))
}
#[inline(always)]
fn write(address_domain: u32, base: StorageBaseAddress, value: (E0, E1)) -> SyscallResult<()> {
let (e0, e1) = value;
E0StorageValue::write(address_domain, base, e0)?;
E1StorageValue::write_at_offset(address_domain, base, E0StorageValue::size(), e1)
}
#[inline(always)]
fn read_at_offset(
address_domain: u32, base: StorageBaseAddress, mut offset: u8
) -> SyscallResult<(E0, E1)> {
let e0 = E0StorageValue::read_at_offset(address_domain, base, offset)?;
offset += E0StorageValue::size();
let e1 = E1StorageValue::read_at_offset(address_domain, base, offset)?;
Result::Ok((e0, e1))
}
#[inline(always)]
fn write_at_offset(
address_domain: u32, base: StorageBaseAddress, mut offset: u8, value: (E0, E1)
) -> SyscallResult<()> {
let (e0, e1) = value;
E0StorageValue::write_at_offset(address_domain, base, offset, e0)?;
offset += E0StorageValue::size();
E1StorageValue::write_at_offset(address_domain, base, offset, e1)
}
#[inline(always)]
fn size() -> u8 {
E0StorageValue::size() + E1StorageValue::size()
}
}

impl TupleSize3StorageValue<
E0,
E1,
E2,
impl E0StorageValue: StorageValue<E0>,
impl E0Drop: Drop<E0>,
impl E1StorageValue: StorageValue<E1>,
impl E1Drop: Drop<E1>,
impl E2StorageValue: StorageValue<E2>,
impl E2Drop: Drop<E2>
> of StorageValue<(E0, E1, E2)> {
#[inline(always)]
fn read(address_domain: u32, base: StorageBaseAddress) -> SyscallResult<(E0, E1, E2)> {
let e0 = E0StorageValue::read(address_domain, base)?;
let mut offset = E0StorageValue::size();
let e1 = E1StorageValue::read_at_offset(address_domain, base, offset)?;
offset += E1StorageValue::size();
let e2 = E2StorageValue::read_at_offset(address_domain, base, offset)?;
Result::Ok((e0, e1, e2))
}
#[inline(always)]
fn write(
address_domain: u32, base: StorageBaseAddress, value: (E0, E1, E2)
) -> SyscallResult<()> {
let (e0, e1, e2) = value;
E0StorageValue::write(address_domain, base, e0)?;
let mut offset = E0StorageValue::size();
E1StorageValue::write_at_offset(address_domain, base, offset, e1)?;
offset += E1StorageValue::size();
E2StorageValue::write_at_offset(address_domain, base, offset, e2)
}
#[inline(always)]
fn read_at_offset(
address_domain: u32, base: StorageBaseAddress, mut offset: u8
) -> SyscallResult<(E0, E1, E2)> {
let e0 = E0StorageValue::read_at_offset(address_domain, base, offset)?;
offset += E0StorageValue::size();
let e1 = E1StorageValue::read_at_offset(address_domain, base, offset)?;
offset += E1StorageValue::size();
let e2 = E2StorageValue::read_at_offset(address_domain, base, offset)?;
Result::Ok((e0, e1, e2))
}
#[inline(always)]
fn write_at_offset(
address_domain: u32, base: StorageBaseAddress, mut offset: u8, value: (E0, E1, E2)
) -> SyscallResult<()> {
let (e0, e1, e2) = value;
E0StorageValue::write_at_offset(address_domain, base, offset, e0)?;
offset += E0StorageValue::size();
E1StorageValue::write_at_offset(address_domain, base, offset, e1)?;
offset += E1StorageValue::size();
E2StorageValue::write_at_offset(address_domain, base, offset, e2)
}
#[inline(always)]
fn size() -> u8 {
E0StorageValue::size() + E1StorageValue::size() + E2StorageValue::size()
}
}

impl TupleSize4StorageValue<
E0,
E1,
E2,
E3,
impl E0StorageValue: StorageValue<E0>,
impl E0Drop: Drop<E0>,
impl E1StorageValue: StorageValue<E1>,
impl E1Drop: Drop<E1>,
impl E2StorageValue: StorageValue<E2>,
impl E2Drop: Drop<E2>,
impl E3StorageValue: StorageValue<E3>,
impl E3Drop: Drop<E3>
> of StorageValue<(E0, E1, E2, E3)> {
#[inline(always)]
fn read(address_domain: u32, base: StorageBaseAddress) -> SyscallResult<(E0, E1, E2, E3)> {
let e0 = E0StorageValue::read(address_domain, base)?;
let mut offset = E0StorageValue::size();
let e1 = E1StorageValue::read_at_offset(address_domain, base, offset)?;
offset += E1StorageValue::size();
let e2 = E2StorageValue::read_at_offset(address_domain, base, offset)?;
offset += E2StorageValue::size();
let e3 = E3StorageValue::read_at_offset(address_domain, base, offset)?;
Result::Ok((e0, e1, e2, e3))
}
#[inline(always)]
fn write(
address_domain: u32, base: StorageBaseAddress, value: (E0, E1, E2, E3)
) -> SyscallResult<()> {
let (e0, e1, e2, e3) = value;
E0StorageValue::write(address_domain, base, e0)?;
let mut offset = E0StorageValue::size();
E1StorageValue::write_at_offset(address_domain, base, offset, e1)?;
offset += E1StorageValue::size();
E2StorageValue::write_at_offset(address_domain, base, offset, e2)?;
offset += E2StorageValue::size();
E3StorageValue::write_at_offset(address_domain, base, offset, e3)
}
#[inline(always)]
fn read_at_offset(
address_domain: u32, base: StorageBaseAddress, mut offset: u8
) -> SyscallResult<(E0, E1, E2, E3)> {
let e0 = E0StorageValue::read_at_offset(address_domain, base, offset)?;
offset += E0StorageValue::size();
let e1 = E1StorageValue::read_at_offset(address_domain, base, offset)?;
offset += E1StorageValue::size();
let e2 = E2StorageValue::read_at_offset(address_domain, base, offset)?;
offset += E2StorageValue::size();
let e3 = E3StorageValue::read_at_offset(address_domain, base, offset)?;
Result::Ok((e0, e1, e2, e3))
}
#[inline(always)]
fn write_at_offset(
address_domain: u32, base: StorageBaseAddress, mut offset: u8, value: (E0, E1, E2, E3)
) -> SyscallResult<()> {
let (e0, e1, e2, e3) = value;
E0StorageValue::write_at_offset(address_domain, base, offset, e0)?;
offset += E0StorageValue::size();
E1StorageValue::write_at_offset(address_domain, base, offset, e1)?;
offset += E1StorageValue::size();
E2StorageValue::write_at_offset(address_domain, base, offset, e2)?;
offset += E2StorageValue::size();
E3StorageValue::write_at_offset(address_domain, base, offset, e3)
}
#[inline(always)]
fn size() -> u8 {
E0StorageValue::size()
+ E1StorageValue::size()
+ E2StorageValue::size()
+ E3StorageValue::size()
}
}