mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
switch to associated lists since roc_std::roc_dict has not been updated yet
This commit is contained in:
parent
f956be26c1
commit
8d8150e748
2 changed files with 219 additions and 14 deletions
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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<u32>,
|
||||
pub deps: roc_std::RocDict<u32, roc_std::RocList<u32>>,
|
||||
pub deps: roc_std::RocList<Tuple2>,
|
||||
pub sizes: roc_std::RocList<u32>,
|
||||
pub types: roc_std::RocList<RocType>,
|
||||
pub typesByName: roc_std::RocDict<roc_std::RocStr, u32>,
|
||||
pub typesByName: roc_std::RocList<Tuple1>,
|
||||
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<u32>,
|
||||
}
|
||||
|
||||
|
||||
#[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<u32>,
|
||||
pub deps: roc_std::RocDict<u64, roc_std::RocList<u64>>,
|
||||
pub sizes: roc_std::RocList<u32>,
|
||||
pub types: roc_std::RocList<RocType>,
|
||||
pub typesByName: roc_std::RocDict<roc_std::RocStr, u64>,
|
||||
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<u64>,
|
||||
}
|
||||
|
||||
|
||||
#[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<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) -> (u32, roc_std::RocList<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) -> (&u32, &roc_std::RocList<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: u64, f1: roc_std::RocList<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) -> (u64, roc_std::RocList<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) -> (&u64, &roc_std::RocList<u64>) {
|
||||
(&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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue