mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Merge pull request #4976 from thehabbos007/list-concat
gen_dev: add `List.concat` and fix element width bug
This commit is contained in:
commit
6fc57f0a0c
6 changed files with 128 additions and 20 deletions
|
@ -1299,6 +1299,7 @@ impl<
|
|||
dst: &Symbol,
|
||||
capacity: Symbol,
|
||||
capacity_layout: InLayout<'a>,
|
||||
element_layout: InLayout<'a>,
|
||||
ret_layout: &InLayout<'a>,
|
||||
) {
|
||||
// List alignment argument (u32).
|
||||
|
@ -1312,7 +1313,7 @@ impl<
|
|||
|
||||
// Load element_width argument (usize).
|
||||
let u64_layout = Layout::U64;
|
||||
let element_width = self.layout_interner.stack_size(*ret_layout);
|
||||
let element_width = self.layout_interner.stack_size(element_layout);
|
||||
self.load_literal(
|
||||
&Symbol::DEV_TMP2,
|
||||
&u64_layout,
|
||||
|
@ -1681,6 +1682,82 @@ impl<
|
|||
self.free_symbol(&Symbol::DEV_TMP5);
|
||||
}
|
||||
|
||||
fn build_list_concat(
|
||||
&mut self,
|
||||
dst: &Symbol,
|
||||
args: &'a [Symbol],
|
||||
arg_layouts: &[InLayout<'a>],
|
||||
element_layout: InLayout<'a>,
|
||||
ret_layout: &InLayout<'a>,
|
||||
) {
|
||||
let list_a = args[0];
|
||||
let list_a_layout = arg_layouts[0];
|
||||
let list_b = args[1];
|
||||
let list_b_layout = arg_layouts[1];
|
||||
|
||||
// Load list alignment argument (u32).
|
||||
let u32_layout = Layout::U32;
|
||||
let list_alignment = self.layout_interner.alignment_bytes(*ret_layout);
|
||||
self.load_literal(
|
||||
&Symbol::DEV_TMP,
|
||||
&u32_layout,
|
||||
&Literal::Int((list_alignment as i128).to_ne_bytes()),
|
||||
);
|
||||
|
||||
// Load element_width argument (usize).
|
||||
let u64_layout = Layout::U64;
|
||||
let element_width = self.layout_interner.stack_size(element_layout);
|
||||
self.load_literal(
|
||||
&Symbol::DEV_TMP2,
|
||||
&u64_layout,
|
||||
&Literal::Int((element_width as i128).to_ne_bytes()),
|
||||
);
|
||||
|
||||
// Setup the return location.
|
||||
let base_offset = self
|
||||
.storage_manager
|
||||
.claim_stack_area(dst, self.layout_interner.stack_size(*ret_layout));
|
||||
|
||||
let lowlevel_args = bumpalo::vec![
|
||||
in self.env.arena;
|
||||
list_a,
|
||||
list_b,
|
||||
// alignment
|
||||
Symbol::DEV_TMP,
|
||||
// element_width
|
||||
Symbol::DEV_TMP2,
|
||||
];
|
||||
let lowlevel_arg_layouts = bumpalo::vec![
|
||||
in self.env.arena;
|
||||
list_a_layout,
|
||||
list_b_layout,
|
||||
u32_layout,
|
||||
u64_layout
|
||||
];
|
||||
|
||||
self.build_fn_call(
|
||||
&Symbol::DEV_TMP3,
|
||||
bitcode::LIST_CONCAT.to_string(),
|
||||
&lowlevel_args,
|
||||
&lowlevel_arg_layouts,
|
||||
ret_layout,
|
||||
);
|
||||
|
||||
self.free_symbol(&Symbol::DEV_TMP);
|
||||
self.free_symbol(&Symbol::DEV_TMP2);
|
||||
|
||||
// Return list value from fn call
|
||||
self.storage_manager.copy_symbol_to_stack_offset(
|
||||
self.layout_interner,
|
||||
&mut self.buf,
|
||||
base_offset,
|
||||
&Symbol::DEV_TMP3,
|
||||
ret_layout,
|
||||
);
|
||||
|
||||
self.free_symbol(&Symbol::DEV_TMP3);
|
||||
}
|
||||
|
||||
fn build_ptr_cast(&mut self, dst: &Symbol, src: &Symbol) {
|
||||
let dst_reg = self.storage_manager.claim_general_reg(&mut self.buf, dst);
|
||||
self.storage_manager
|
||||
|
|
|
@ -21,6 +21,7 @@ use roc_mono::layout::{
|
|||
Builtin, InLayout, Layout, LayoutId, LayoutIds, LayoutInterner, STLayoutInterner, TagIdIntType,
|
||||
UnionLayout,
|
||||
};
|
||||
use roc_mono::list_element_layout;
|
||||
|
||||
mod generic64;
|
||||
mod object_builder;
|
||||
|
@ -706,7 +707,14 @@ trait Backend<'a> {
|
|||
args.len(),
|
||||
"ListWithCapacity: expected to have exactly one argument"
|
||||
);
|
||||
self.build_list_with_capacity(sym, args[0], arg_layouts[0], ret_layout)
|
||||
let element_layout = list_element_layout!(self.interner(), *ret_layout);
|
||||
self.build_list_with_capacity(
|
||||
sym,
|
||||
args[0],
|
||||
arg_layouts[0],
|
||||
element_layout,
|
||||
ret_layout,
|
||||
)
|
||||
}
|
||||
LowLevel::ListReserve => {
|
||||
debug_assert_eq!(
|
||||
|
@ -740,6 +748,15 @@ trait Backend<'a> {
|
|||
);
|
||||
self.build_list_replace_unsafe(sym, args, arg_layouts, ret_layout)
|
||||
}
|
||||
LowLevel::ListConcat => {
|
||||
debug_assert_eq!(
|
||||
2,
|
||||
args.len(),
|
||||
"ListConcat: expected to have exactly two arguments"
|
||||
);
|
||||
let element_layout = list_element_layout!(self.interner(), *ret_layout);
|
||||
self.build_list_concat(sym, args, arg_layouts, element_layout, ret_layout)
|
||||
}
|
||||
LowLevel::StrConcat => self.build_fn_call(
|
||||
sym,
|
||||
bitcode::STR_CONCAT.to_string(),
|
||||
|
@ -996,6 +1013,7 @@ trait Backend<'a> {
|
|||
dst: &Symbol,
|
||||
capacity: Symbol,
|
||||
capacity_layout: InLayout<'a>,
|
||||
element_layout: InLayout<'a>,
|
||||
ret_layout: &InLayout<'a>,
|
||||
);
|
||||
|
||||
|
@ -1035,6 +1053,16 @@ trait Backend<'a> {
|
|||
ret_layout: &InLayout<'a>,
|
||||
);
|
||||
|
||||
/// build_list_concat returns a new list containing the two argument lists concatenated.
|
||||
fn build_list_concat(
|
||||
&mut self,
|
||||
dst: &Symbol,
|
||||
args: &'a [Symbol],
|
||||
arg_layouts: &[InLayout<'a>],
|
||||
element_layout: InLayout<'a>,
|
||||
ret_layout: &InLayout<'a>,
|
||||
);
|
||||
|
||||
/// 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