mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Allocate and free stack frames
This commit is contained in:
parent
036503c750
commit
4f55b7a56e
3 changed files with 43 additions and 21 deletions
|
@ -25,7 +25,7 @@ pub const ALIGN_8: u32 = 3;
|
|||
pub const STACK_POINTER_GLOBAL_ID: u32 = 0;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct LocalId(u32);
|
||||
pub struct LocalId(u32);
|
||||
|
||||
pub struct Env<'a> {
|
||||
pub arena: &'a Bump, // not really using this much, parity_wasm works with std::vec a lot
|
||||
|
@ -152,3 +152,23 @@ fn copy_memory(
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn allocate_stack_frame(instructions: &mut Vec<Instruction>, size: i32) {
|
||||
if size == 0 {
|
||||
return;
|
||||
}
|
||||
instructions.push(GetGlobal(STACK_POINTER_GLOBAL_ID));
|
||||
instructions.push(I32Const(size));
|
||||
instructions.push(I32Sub);
|
||||
instructions.push(SetGlobal(STACK_POINTER_GLOBAL_ID));
|
||||
}
|
||||
|
||||
pub fn free_stack_frame(instructions: &mut Vec<Instruction>, size: i32) {
|
||||
if size == 0 {
|
||||
return;
|
||||
}
|
||||
instructions.push(GetGlobal(STACK_POINTER_GLOBAL_ID));
|
||||
instructions.push(I32Const(size));
|
||||
instructions.push(I32Add);
|
||||
instructions.push(SetGlobal(STACK_POINTER_GLOBAL_ID));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue