mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
add List.len
This commit is contained in:
parent
a39f610395
commit
cf8d294ec1
3 changed files with 31 additions and 0 deletions
|
@ -892,6 +892,10 @@ impl<
|
|||
}
|
||||
}
|
||||
|
||||
fn build_list_len(&mut self, dst: &Symbol, list: &Symbol) {
|
||||
self.storage_manager.list_len(&mut self.buf, dst, list);
|
||||
}
|
||||
|
||||
fn build_ptr_cast(&mut self, dst: &Symbol, src: &Symbol) {
|
||||
// We may not strictly need an instruction here.
|
||||
// What's important is to load the value, and for src and dest to have different Layouts.
|
||||
|
|
|
@ -606,6 +606,22 @@ impl<
|
|||
}
|
||||
}
|
||||
|
||||
// Loads the dst to be the later 64 bits of a list (its length).
|
||||
pub fn list_len(&mut self, _buf: &mut Vec<'a, u8>, dst: &Symbol, list: &Symbol) {
|
||||
let owned_data = self.remove_allocation_for_sym(list);
|
||||
self.allocation_map.insert(*list, Rc::clone(&owned_data));
|
||||
self.allocation_map.insert(*dst, owned_data);
|
||||
let (list_offset, _) = self.stack_offset_and_size(list);
|
||||
self.symbol_storage_map.insert(
|
||||
*dst,
|
||||
Stack(ReferencedPrimitive {
|
||||
base_offset: list_offset + 8,
|
||||
size: 8,
|
||||
sign_extend: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/// Creates a struct on the stack, moving the data in fields into the struct.
|
||||
pub fn create_struct(
|
||||
&mut self,
|
||||
|
|
|
@ -550,6 +550,14 @@ trait Backend<'a> {
|
|||
arg_layouts,
|
||||
ret_layout,
|
||||
),
|
||||
LowLevel::ListLen => {
|
||||
debug_assert_eq!(
|
||||
1,
|
||||
args.len(),
|
||||
"ListLen: expected to have exactly one argument"
|
||||
);
|
||||
self.build_list_len(sym, &args[0])
|
||||
}
|
||||
LowLevel::StrConcat => self.build_fn_call(
|
||||
sym,
|
||||
bitcode::STR_CONCAT.to_string(),
|
||||
|
@ -685,6 +693,9 @@ trait Backend<'a> {
|
|||
arg_layout: &Layout<'a>,
|
||||
);
|
||||
|
||||
/// build_list_len returns the length of a list.
|
||||
fn build_list_len(&mut self, dst: &Symbol, list: &Symbol);
|
||||
|
||||
/// build_refcount_getptr loads the pointer to the reference count of src into dst.
|
||||
fn build_ptr_cast(&mut self, dst: &Symbol, src: &Symbol);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue