mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Pull out string literal creation
This commit is contained in:
parent
d7db10d7b5
commit
2b49aee3d2
1 changed files with 42 additions and 39 deletions
|
@ -1128,6 +1128,18 @@ impl<'a> WasmBackend<'a> {
|
||||||
let (local_id, offset) =
|
let (local_id, offset) =
|
||||||
location.local_and_offset(self.storage.stack_frame_pointer);
|
location.local_and_offset(self.storage.stack_frame_pointer);
|
||||||
|
|
||||||
|
self.expr_string_literal(string, local_id, offset);
|
||||||
|
}
|
||||||
|
// Bools and bytes should not be stored in the stack frame
|
||||||
|
Literal::Bool(_) | Literal::Byte(_) => invalid_error(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => invalid_error(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn expr_string_literal(&mut self, string: &str, local_id: LocalId, offset: u32) {
|
||||||
let len = string.len();
|
let len = string.len();
|
||||||
if len < 12 {
|
if len < 12 {
|
||||||
// Construct the bytes of the small string
|
// Construct the bytes of the small string
|
||||||
|
@ -1136,8 +1148,7 @@ impl<'a> WasmBackend<'a> {
|
||||||
bytes[11] = 0x80 | (len as u8);
|
bytes[11] = 0x80 | (len as u8);
|
||||||
|
|
||||||
// Transform into two integers, to minimise number of instructions
|
// Transform into two integers, to minimise number of instructions
|
||||||
let bytes_split: &([u8; 8], [u8; 4]) =
|
let bytes_split: &([u8; 8], [u8; 4]) = unsafe { std::mem::transmute(&bytes) };
|
||||||
unsafe { std::mem::transmute(&bytes) };
|
|
||||||
let int64 = i64::from_le_bytes(bytes_split.0);
|
let int64 = i64::from_le_bytes(bytes_split.0);
|
||||||
let int32 = i32::from_le_bytes(bytes_split.1);
|
let int32 = i32::from_le_bytes(bytes_split.1);
|
||||||
|
|
||||||
|
@ -1168,14 +1179,6 @@ impl<'a> WasmBackend<'a> {
|
||||||
self.code_builder.i32_store(Align::Bytes4, offset + 8);
|
self.code_builder.i32_store(Align::Bytes4, offset + 8);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Bools and bytes should not be stored in the stack frame
|
|
||||||
Literal::Bool(_) | Literal::Byte(_) => invalid_error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => invalid_error(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a string constant in the module data section
|
/// Create a string constant in the module data section
|
||||||
/// Return the data we need for code gen: linker symbol index and memory address
|
/// Return the data we need for code gen: linker symbol index and memory address
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue