mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Simplify CodeBuilder::call
This commit is contained in:
parent
3a751aa3e8
commit
4b3538dc58
1 changed files with 5 additions and 18 deletions
|
@ -520,27 +520,14 @@ impl<'a> CodeBuilder<'a> {
|
||||||
n_args: usize,
|
n_args: usize,
|
||||||
has_return_val: bool,
|
has_return_val: bool,
|
||||||
) {
|
) {
|
||||||
let stack_depth = self.vm_stack.len();
|
self.inst(CALL, n_args, has_return_val);
|
||||||
if n_args > stack_depth {
|
|
||||||
panic!(
|
|
||||||
"Trying to call to call function {:?} with {:?} values but only {:?} on the VM stack\n{:?}",
|
|
||||||
function_index, n_args, stack_depth, self
|
|
||||||
);
|
|
||||||
}
|
|
||||||
self.vm_stack.truncate(stack_depth - n_args);
|
|
||||||
if has_return_val {
|
|
||||||
self.vm_stack.push(Symbol::WASM_ANONYMOUS_STACK_VALUE);
|
|
||||||
}
|
|
||||||
self.code.push(CALL as u8);
|
|
||||||
|
|
||||||
// println!("CALL \t{:?}", &self.vm_stack);
|
|
||||||
|
|
||||||
// Write the index of the function to be called.
|
|
||||||
// Also make a RelocationEntry so the linker can see that this byte offset relates to a function by name.
|
|
||||||
// Here we initialise the offset to an index of self.code. After completing the function, we'll add
|
|
||||||
// other factors to make it relative to the code section. (All insertions will be known then.)
|
|
||||||
let offset = self.code.len() as u32;
|
let offset = self.code.len() as u32;
|
||||||
self.code.encode_padded_u32(function_index);
|
self.code.encode_padded_u32(function_index);
|
||||||
|
|
||||||
|
// Make a RelocationEntry so the linker can see that this byte offset relates to a function by name.
|
||||||
|
// Here we initialise the offset to an index of self.code. After completing the function, we'll add
|
||||||
|
// other factors to make it relative to the code section. (All insertions will be known then.)
|
||||||
self.relocations.push(RelocationEntry::Index {
|
self.relocations.push(RelocationEntry::Index {
|
||||||
type_id: IndexRelocType::FunctionIndexLeb,
|
type_id: IndexRelocType::FunctionIndexLeb,
|
||||||
offset,
|
offset,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue