add s pointers for strings and partial strings, put_unsafe_value calls store earlier to avoid unnecessary heap writes (#273)

This commit is contained in:
Mark Thom
2020-02-28 23:42:40 -07:00
parent aa5f186a96
commit 2ebcd673c8
3 changed files with 77 additions and 66 deletions

View File

@@ -18,6 +18,7 @@ use std::cmp::Ordering;
use std::io::{stdout, Write};
use std::mem;
use std::ops::{Index, IndexMut};
use std::rc::Rc;
pub struct Ball {
pub(super) boundary: usize,
@@ -245,8 +246,33 @@ pub(super) enum MachineMode {
Write,
}
#[derive(Clone)]
pub(super) enum HeapPtr {
HeapCell(usize),
PStrLocation(usize, usize),
String(usize, Rc<String>),
}
impl HeapPtr {
#[inline]
pub(super)
fn as_addr(&self) -> Addr {
match self {
&HeapPtr::HeapCell(h) => Addr::HeapCell(h),
&HeapPtr::PStrLocation(h, n) => Addr::PStrLocation(h, n),
&HeapPtr::String(n, ref s) => Addr::Con(Constant::String(n, s.clone())),
}
}
}
impl Default for HeapPtr {
fn default() -> Self {
HeapPtr::HeapCell(0)
}
}
pub struct MachineState {
pub(super) s: usize,
pub(super) s: HeapPtr,
pub(super) p: CodePtr,
pub(super) b: usize,
pub(super) b0: usize,