diff --git a/crates/glue/src/RocType.roc b/crates/glue/src/RocType.roc index ee0e00e136..9c97e382dd 100644 --- a/crates/glue/src/RocType.roc +++ b/crates/glue/src/RocType.roc @@ -44,6 +44,10 @@ TypeId : Nat # isEqTypeId = \@TypeId lhs, @TypeId rhs -> lhs == rhs # hashTypeId = \hasher, @TypeId id -> Hash.hash hasher id +# TODO: switch AssocList uses to Dict once roc_std is updated. +Tuple1 : [ T Str TypeId ] +Tuple2 : [ T TypeId (List TypeId) ] + Types : { # These are all indexed by TypeId types: List RocType, @@ -51,12 +55,12 @@ Types : { aligns: List U32, # Needed to check for duplicates - typesByName: Dict Str TypeId, + typesByName: List Tuple1, ## Dependencies - that is, which type depends on which other type. ## This is important for declaration order in C; we need to output a ## type declaration earlier in the file than where it gets referenced by another type. - deps: Dict TypeId (List TypeId), + deps: List Tuple2, target: Target, } diff --git a/crates/glue/src/roc_type/mod.rs b/crates/glue/src/roc_type/mod.rs index f6e55508d9..20e8a5fbf3 100644 --- a/crates/glue/src/roc_type/mod.rs +++ b/crates/glue/src/roc_type/mod.rs @@ -32,20 +32,35 @@ pub struct File { #[cfg(any( target_arch = "arm", + target_arch = "aarch64", target_arch = "wasm32", - target_arch = "x86" + target_arch = "x86", + target_arch = "x86_64" ))] #[derive(Clone, Debug, Eq, Ord, Hash, PartialEq, PartialOrd)] #[repr(C)] pub struct Types { pub aligns: roc_std::RocList, - pub deps: roc_std::RocDict>, + pub deps: roc_std::RocList, pub sizes: roc_std::RocList, pub types: roc_std::RocList, - pub typesByName: roc_std::RocDict, + pub typesByName: roc_std::RocList, pub target: Target, } +#[cfg(any( + target_arch = "arm", + target_arch = "wasm32", + target_arch = "x86" +))] +#[repr(C)] +#[derive(Clone, Default, Eq, Ord, Hash, PartialEq, PartialOrd)] +pub struct Tuple1 { + f0: roc_std::RocStr, + f1: u32, +} + + #[cfg(any( target_arch = "arm", target_arch = "aarch64", @@ -154,6 +169,19 @@ pub struct R3 { pub r#type: u32, } +#[cfg(any( + target_arch = "arm", + target_arch = "wasm32", + target_arch = "x86" +))] +#[repr(C)] +#[derive(Clone, Default, Eq, Ord, Hash, PartialEq, PartialOrd)] +pub struct Tuple2 { + f0: u32, + f1: roc_std::RocList, +} + + #[cfg(any( target_arch = "arm", target_arch = "aarch64", @@ -516,17 +544,14 @@ pub struct R1 { target_arch = "aarch64", target_arch = "x86_64" ))] -#[derive(Clone, Debug, Eq, Ord, Hash, PartialEq, PartialOrd)] -#[repr(C)] -pub struct Types { - pub aligns: roc_std::RocList, - pub deps: roc_std::RocDict>, - pub sizes: roc_std::RocList, - pub types: roc_std::RocList, - pub typesByName: roc_std::RocDict, - pub target: Target, +#[repr(transparent)] +#[derive(Clone, Default, Eq, Ord, Hash, PartialEq, PartialOrd)] +pub struct Tuple1 { + f0: roc_std::RocStr, + f1: u64, } + #[cfg(any( target_arch = "aarch64", target_arch = "x86_64" @@ -569,6 +594,18 @@ pub struct R3 { pub r#type: u64, } +#[cfg(any( + target_arch = "aarch64", + target_arch = "x86_64" +))] +#[repr(transparent)] +#[derive(Clone, Default, Eq, Ord, Hash, PartialEq, PartialOrd)] +pub struct Tuple2 { + f0: u64, + f1: roc_std::RocList, +} + + #[cfg(any( target_arch = "aarch64", target_arch = "x86_64" @@ -695,6 +732,88 @@ pub struct R1 { pub ret: u64, } +impl Tuple1 { + #[cfg(any( + target_arch = "arm", + target_arch = "wasm32", + target_arch = "x86" + ))] + /// A tag named T, with the given payload. + pub fn T(f0: roc_std::RocStr, f1: u32) -> Self { + Self { + f0, + f1, + } + } + + #[cfg(any( + target_arch = "arm", + target_arch = "wasm32", + target_arch = "x86" + ))] + /// Since `T` only has one tag (namely, `T`), + /// convert it to `T`'s payload. + pub fn into_T(self) -> (roc_std::RocStr, u32) { + (self.f0, self.f1) + } + + #[cfg(any( + target_arch = "arm", + target_arch = "wasm32", + target_arch = "x86" + ))] + /// Since `T` only has one tag (namely, `T`), + /// convert it to `T`'s payload. + pub fn as_T(&self) -> (&roc_std::RocStr, &u32) { + (&self.f0, &self.f1) + } + + #[cfg(any( + target_arch = "aarch64", + target_arch = "x86_64" + ))] + /// A tag named T, with the given payload. + pub fn T(f0: roc_std::RocStr, f1: u64) -> Self { + Self { + f0, + f1, + } + } + + #[cfg(any( + target_arch = "aarch64", + target_arch = "x86_64" + ))] + /// Since `T` only has one tag (namely, `T`), + /// convert it to `T`'s payload. + pub fn into_T(self) -> (roc_std::RocStr, u64) { + (self.f0, self.f1) + } + + #[cfg(any( + target_arch = "aarch64", + target_arch = "x86_64" + ))] + /// Since `T` only has one tag (namely, `T`), + /// convert it to `T`'s payload. + pub fn as_T(&self) -> (&roc_std::RocStr, &u64) { + (&self.f0, &self.f1) + } +} + +impl core::fmt::Debug for Tuple1 { + #[cfg(any( + target_arch = "arm", + target_arch = "aarch64", + target_arch = "wasm32", + target_arch = "x86", + target_arch = "x86_64" + ))] + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_tuple("Tuple1::T") .field(&self.f0) .field(&self.f1) .finish() } + +} + impl RocType { #[cfg(any( target_arch = "arm", @@ -2175,6 +2294,88 @@ impl core::fmt::Debug for RocType { } } +impl Tuple2 { + #[cfg(any( + target_arch = "arm", + target_arch = "wasm32", + target_arch = "x86" + ))] + /// A tag named T, with the given payload. + pub fn T(f0: u32, f1: roc_std::RocList) -> Self { + Self { + f0, + f1, + } + } + + #[cfg(any( + target_arch = "arm", + target_arch = "wasm32", + target_arch = "x86" + ))] + /// Since `T` only has one tag (namely, `T`), + /// convert it to `T`'s payload. + pub fn into_T(self) -> (u32, roc_std::RocList) { + (self.f0, self.f1) + } + + #[cfg(any( + target_arch = "arm", + target_arch = "wasm32", + target_arch = "x86" + ))] + /// Since `T` only has one tag (namely, `T`), + /// convert it to `T`'s payload. + pub fn as_T(&self) -> (&u32, &roc_std::RocList) { + (&self.f0, &self.f1) + } + + #[cfg(any( + target_arch = "aarch64", + target_arch = "x86_64" + ))] + /// A tag named T, with the given payload. + pub fn T(f0: u64, f1: roc_std::RocList) -> Self { + Self { + f0, + f1, + } + } + + #[cfg(any( + target_arch = "aarch64", + target_arch = "x86_64" + ))] + /// Since `T` only has one tag (namely, `T`), + /// convert it to `T`'s payload. + pub fn into_T(self) -> (u64, roc_std::RocList) { + (self.f0, self.f1) + } + + #[cfg(any( + target_arch = "aarch64", + target_arch = "x86_64" + ))] + /// Since `T` only has one tag (namely, `T`), + /// convert it to `T`'s payload. + pub fn as_T(&self) -> (&u64, &roc_std::RocList) { + (&self.f0, &self.f1) + } +} + +impl core::fmt::Debug for Tuple2 { + #[cfg(any( + target_arch = "arm", + target_arch = "aarch64", + target_arch = "wasm32", + target_arch = "x86", + target_arch = "x86_64" + ))] + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_tuple("Tuple2::T") .field(&self.f0) .field(&self.f1) .finish() } + +} + impl RocTagUnion { #[cfg(any( target_arch = "arm",