mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-24 20:42:29 +00:00
add alloca as an expression
This commit is contained in:
parent
750234f2de
commit
cdd2aab217
15 changed files with 171 additions and 14 deletions
|
@ -3007,11 +3007,17 @@ impl<
|
|||
ASM::and_reg64_reg64_reg64(buf, sym_reg, sym_reg, ptr_reg);
|
||||
}
|
||||
|
||||
fn build_alloca(&mut self, sym: Symbol, value: Symbol, element_layout: InLayout<'a>) {
|
||||
fn build_alloca(&mut self, sym: Symbol, value: Option<Symbol>, element_layout: InLayout<'a>) {
|
||||
// 1. acquire some stack space
|
||||
let element_width = self.interner().stack_size(element_layout);
|
||||
let allocation = self.debug_symbol("stack_allocation");
|
||||
let ptr = self.debug_symbol("ptr");
|
||||
|
||||
if element_width == 0 {
|
||||
self.storage_manager.claim_pointer_stack_area(sym);
|
||||
return;
|
||||
}
|
||||
|
||||
let base_offset = self
|
||||
.storage_manager
|
||||
.claim_stack_area(&allocation, element_width);
|
||||
|
@ -3021,7 +3027,13 @@ impl<
|
|||
ASM::mov_reg64_reg64(&mut self.buf, ptr_reg, CC::BASE_PTR_REG);
|
||||
ASM::add_reg64_reg64_imm32(&mut self.buf, ptr_reg, ptr_reg, base_offset);
|
||||
|
||||
self.build_ptr_store(sym, ptr, value, element_layout);
|
||||
if let Some(value) = value {
|
||||
self.build_ptr_store(sym, ptr, value, element_layout);
|
||||
} else {
|
||||
// this is now a pointer to uninitialized memory!
|
||||
let r = self.storage_manager.claim_general_reg(&mut self.buf, &sym);
|
||||
ASM::mov_reg64_reg64(&mut self.buf, r, ptr_reg);
|
||||
}
|
||||
}
|
||||
|
||||
fn expr_box(
|
||||
|
|
|
@ -183,9 +183,14 @@ impl<'a> LastSeenMap<'a> {
|
|||
Expr::Reset { symbol, .. } | Expr::ResetRef { symbol, .. } => {
|
||||
self.set_last_seen(*symbol, stmt);
|
||||
}
|
||||
Expr::Alloca { initializer, .. } => {
|
||||
if let Some(initializer) = initializer {
|
||||
self.set_last_seen(*initializer, stmt);
|
||||
}
|
||||
}
|
||||
Expr::RuntimeErrorFunction(_) => {}
|
||||
Expr::FunctionPointer { .. } => todo_lambda_erasure!(),
|
||||
Expr::EmptyArray => {}
|
||||
Expr::RuntimeErrorFunction(_) => {}
|
||||
}
|
||||
self.scan_ast_help(following);
|
||||
}
|
||||
|
@ -895,6 +900,12 @@ trait Backend<'a> {
|
|||
|
||||
self.build_expr(sym, &new_expr, &Layout::BOOL)
|
||||
}
|
||||
Expr::Alloca {
|
||||
initializer,
|
||||
element_layout,
|
||||
} => {
|
||||
self.build_alloca(*sym, *initializer, *element_layout);
|
||||
}
|
||||
Expr::RuntimeErrorFunction(_) => todo!(),
|
||||
}
|
||||
}
|
||||
|
@ -1616,7 +1627,7 @@ trait Backend<'a> {
|
|||
}
|
||||
|
||||
LowLevel::Alloca => {
|
||||
self.build_alloca(*sym, args[0], arg_layouts[0]);
|
||||
self.build_alloca(*sym, Some(args[0]), arg_layouts[0]);
|
||||
}
|
||||
|
||||
LowLevel::RefCountDecRcPtr => self.build_fn_call(
|
||||
|
@ -2259,7 +2270,7 @@ trait Backend<'a> {
|
|||
|
||||
fn build_ptr_clear_tag_id(&mut self, sym: Symbol, ptr: Symbol);
|
||||
|
||||
fn build_alloca(&mut self, sym: Symbol, value: Symbol, element_layout: InLayout<'a>);
|
||||
fn build_alloca(&mut self, sym: Symbol, value: Option<Symbol>, element_layout: InLayout<'a>);
|
||||
|
||||
/// literal_map gets the map from symbol to literal and layout, used for lazy loading and literal folding.
|
||||
fn literal_map(&mut self) -> &mut MutMap<Symbol, (*const Literal<'a>, *const InLayout<'a>)>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue