aboutsummaryrefslogtreecommitdiff
path: root/src/memory.rs
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2016-01-04 18:30:23 -0700
committerDavid Li <li.davidm96@gmail.com>2016-01-04 18:30:23 -0700
commit6b3d1df04776406a39b3fd0fab18e49b92c84190 (patch)
treeda3e8ca5c302342661f966d2ebec2c242e92530c /src/memory.rs
parentbb8162c22e34ac588f92b4d3783c39d04a67ec2c (diff)
Make memory construction from segments a method instead
Diffstat (limited to 'src/memory.rs')
-rw-r--r--src/memory.rs22
1 files changed, 4 insertions, 18 deletions
diff --git a/src/memory.rs b/src/memory.rs
index 9bc3643..371a0a3 100644
--- a/src/memory.rs
+++ b/src/memory.rs
@@ -201,24 +201,10 @@ impl Memory {
}
}
- pub fn new_from_text_and_data(size: usize,
- text: &[u8], text_offset: usize,
- data: &[u8], data_offset: usize) -> Memory {
- let mut memory = vec![0; size];
-
- {
- let mut text_segment = &mut memory[(text_offset / 4)..size];
- copy_u8_into_u32(text, text_segment);
- }
-
- {
- let mut data_segment = &mut memory[(data_offset / 4)..size];
- copy_u8_into_u32(data, data_segment);
- }
-
- Memory {
- memory: memory,
- }
+ pub fn write_segment(&mut self, data: &[u8], offset: usize) {
+ let size = self.memory.len();
+ let mut segment = &mut self.memory[(offset / 4)..size];
+ copy_u8_into_u32(data, segment);
}
}