update token type

This commit is contained in:
Mark Thom
2018-01-12 22:26:57 -07:00
parent b5844eaf19
commit 20972f18c2
4 changed files with 14 additions and 23 deletions

View File

@@ -862,17 +862,7 @@ impl Addr {
_ => false
}
}
pub fn as_ref(&self) -> Option<Ref> {
match self {
&Addr::HeapCell(hc) => Some(Ref::HeapCell(hc)),
&Addr::StackCell(fr, sc) => Some(Ref::StackCell(fr, sc)),
&Addr::Lis(hc) => Some(Ref::HeapCell(hc)),
&Addr::Str(hc) => Some(Ref::HeapCell(hc)),
_ => None
}
}
pub fn as_var(&self) -> Option<Ref> {
match self {
&Addr::HeapCell(hc) => Some(Ref::HeapCell(hc)),
@@ -892,7 +882,7 @@ impl Addr {
impl From<Ref> for Addr {
fn from(r: Ref) -> Self {
match r {
Ref::HeapCell(hc) => Addr::HeapCell(hc),
Ref::HeapCell(hc) => Addr::HeapCell(hc),
Ref::StackCell(fr, sc) => Addr::StackCell(fr, sc)
}
}

View File

@@ -179,9 +179,9 @@ pub struct MachineState {
pub(super) num_of_args: usize,
pub(super) cp: CodePtr,
pub(super) fail: bool,
pub(super) heap: Heap,
pub(crate) heap: Heap,
pub(super) mode: MachineMode,
pub(super) and_stack: AndStack,
pub(crate) and_stack: AndStack,
pub(super) or_stack: OrStack,
pub(super) registers: Registers,
pub(super) trail: Vec<Ref>,
@@ -221,7 +221,7 @@ impl MachineState {
if self.b > 0 { self.or_stack[self.b - 1].global_index } else { 0 }) + 1
}
pub fn store(&self, a: Addr) -> Addr {
pub(super) fn store(&self, a: Addr) -> Addr {
match a {
Addr::HeapCell(r) => self.heap[r].as_addr(r),
Addr::StackCell(fr, sc) => self.and_stack[fr][sc].clone(),
@@ -229,9 +229,7 @@ impl MachineState {
}
}
pub fn deref(&self, a: Addr) -> Addr {
let mut a = a;
pub(crate) fn deref(&self, mut a: Addr) -> Addr {
loop {
let value = self.store(a.clone());
@@ -1134,11 +1132,14 @@ impl MachineState {
for heap_value in self.ball.1.iter().cloned() {
self.heap.push(match heap_value {
HeapCellValue::Addr(Addr::Con(c)) => HeapCellValue::Addr(Addr::Con(c)),
HeapCellValue::Addr(Addr::Lis(a)) => HeapCellValue::Addr(Addr::Lis(a - diff)),
HeapCellValue::Addr(Addr::Con(c)) =>
HeapCellValue::Addr(Addr::Con(c)),
HeapCellValue::Addr(Addr::Lis(a)) =>
HeapCellValue::Addr(Addr::Lis(a - diff)),
HeapCellValue::Addr(Addr::HeapCell(hc)) =>
HeapCellValue::Addr(Addr::HeapCell(hc - diff)),
HeapCellValue::Addr(Addr::Str(s)) => HeapCellValue::Addr(Addr::Str(s - diff)),
HeapCellValue::Addr(Addr::Str(s)) =>
HeapCellValue::Addr(Addr::Str(s - diff)),
_ => heap_value
});
}

View File

@@ -4,7 +4,7 @@ use prolog::codegen::*;
use prolog::heapview::*;
use prolog::fixtures::*;
mod machine_state;
pub(crate) mod machine_state;
use std::collections::HashMap;
use std::ops::Index;