mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
add pointer Layout
This commit is contained in:
parent
e4566b9757
commit
fbadd9d620
3 changed files with 10 additions and 1 deletions
|
@ -10,7 +10,7 @@ pub fn type_from_layout(cfg: TargetFrontendConfig, layout: &Layout<'_>) -> Type
|
||||||
use roc_mono::layout::Layout::*;
|
use roc_mono::layout::Layout::*;
|
||||||
|
|
||||||
match layout {
|
match layout {
|
||||||
FunctionPointer(_, _) | Struct(_) | Union(_) => cfg.pointer_type(),
|
FunctionPointer(_, _) | Pointer(_) | Struct(_) | Union(_) => cfg.pointer_type(),
|
||||||
Builtin(builtin) => match builtin {
|
Builtin(builtin) => match builtin {
|
||||||
Int64 => types::I64,
|
Int64 => types::I64,
|
||||||
Float64 => types::F64,
|
Float64 => types::F64,
|
||||||
|
|
|
@ -59,6 +59,9 @@ pub fn basic_type_from_layout<'ctx>(
|
||||||
|
|
||||||
ptr_type.as_basic_type_enum()
|
ptr_type.as_basic_type_enum()
|
||||||
}
|
}
|
||||||
|
Pointer(layout) => basic_type_from_layout(arena, context, &layout, ptr_bytes)
|
||||||
|
.ptr_type(AddressSpace::Generic)
|
||||||
|
.into(),
|
||||||
Struct(sorted_fields) => {
|
Struct(sorted_fields) => {
|
||||||
// Determine types
|
// Determine types
|
||||||
let mut field_types = Vec::with_capacity_in(sorted_fields.len(), arena);
|
let mut field_types = Vec::with_capacity_in(sorted_fields.len(), arena);
|
||||||
|
|
|
@ -13,6 +13,7 @@ pub enum Layout<'a> {
|
||||||
Union(&'a [&'a [Layout<'a>]]),
|
Union(&'a [&'a [Layout<'a>]]),
|
||||||
/// A function. The types of its arguments, then the type of its return value.
|
/// A function. The types of its arguments, then the type of its return value.
|
||||||
FunctionPointer(&'a [Layout<'a>], &'a Layout<'a>),
|
FunctionPointer(&'a [Layout<'a>], &'a Layout<'a>),
|
||||||
|
Pointer(&'a Layout<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
@ -93,6 +94,10 @@ impl<'a> Layout<'a> {
|
||||||
// Function pointers are immutable and can always be safely copied
|
// Function pointers are immutable and can always be safely copied
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
Pointer(_) => {
|
||||||
|
// TODO is this accurate?
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +126,7 @@ impl<'a> Layout<'a> {
|
||||||
.max()
|
.max()
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
FunctionPointer(_, _) => pointer_size,
|
FunctionPointer(_, _) => pointer_size,
|
||||||
|
Pointer(_) => pointer_size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue