mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Reset after each procedure, and reserve space in vecs
This commit is contained in:
parent
9ba7076d8e
commit
0770bb242e
1 changed files with 17 additions and 4 deletions
|
@ -70,10 +70,10 @@ impl<'a> WasmBackend<'a> {
|
||||||
proc_symbol_map: MutMap::default(),
|
proc_symbol_map: MutMap::default(),
|
||||||
|
|
||||||
// Functions: Wasm AST
|
// Functions: Wasm AST
|
||||||
instructions: std::vec::Vec::new(),
|
instructions: std::vec::Vec::with_capacity(256),
|
||||||
ret_type: ValueType::I32,
|
ret_type: ValueType::I32,
|
||||||
arg_types: std::vec::Vec::new(),
|
arg_types: std::vec::Vec::with_capacity(8),
|
||||||
locals: std::vec::Vec::new(),
|
locals: std::vec::Vec::with_capacity(32),
|
||||||
|
|
||||||
// Functions: internal state & IR mappings
|
// Functions: internal state & IR mappings
|
||||||
stack_memory: 0,
|
stack_memory: 0,
|
||||||
|
@ -82,6 +82,18 @@ impl<'a> WasmBackend<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn reset(&mut self) {
|
||||||
|
// Functions: Wasm AST
|
||||||
|
self.instructions.clear();
|
||||||
|
self.arg_types.clear();
|
||||||
|
self.locals.clear();
|
||||||
|
|
||||||
|
// Functions: internal state & IR mappings
|
||||||
|
self.stack_memory = 0;
|
||||||
|
self.symbol_storage_map.clear();
|
||||||
|
// joinpoint_label_map.clear();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build_proc(&mut self, proc: Proc<'a>, sym: Symbol) -> Result<u32, String> {
|
pub fn build_proc(&mut self, proc: Proc<'a>, sym: Symbol) -> Result<u32, String> {
|
||||||
let ret_layout = WasmLayout::new(&proc.ret_layout)?;
|
let ret_layout = WasmLayout::new(&proc.ret_layout)?;
|
||||||
if ret_layout.stack_memory > 0 {
|
if ret_layout.stack_memory > 0 {
|
||||||
|
@ -93,7 +105,7 @@ impl<'a> WasmBackend<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ret_type = ret_layout.value_type;
|
self.ret_type = ret_layout.value_type;
|
||||||
self.arg_types = std::vec::Vec::with_capacity(proc.args.len());
|
self.arg_types.reserve(proc.args.len());
|
||||||
|
|
||||||
for (layout, symbol) in proc.args {
|
for (layout, symbol) in proc.args {
|
||||||
let wasm_layout = WasmLayout::new(layout)?;
|
let wasm_layout = WasmLayout::new(layout)?;
|
||||||
|
@ -119,6 +131,7 @@ impl<'a> WasmBackend<'a> {
|
||||||
let location = self.builder.push_function(function_def);
|
let location = self.builder.push_function(function_def);
|
||||||
let function_index = location.body;
|
let function_index = location.body;
|
||||||
self.proc_symbol_map.insert(sym, location);
|
self.proc_symbol_map.insert(sym, location);
|
||||||
|
self.reset();
|
||||||
|
|
||||||
Ok(function_index)
|
Ok(function_index)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue