split into lib and bin
* makes most pub things in src/ pub(crate) as not to expose things accidentally
* only those things needed by src/bin/scryer-prolog.rs and tests/scryer.rs
should be pub
* split src/main.rs into src/lib.rs and src/bin/scryer-prolog.rs
* add tests folder and run most of the files in src/tests with cargo test
added bytes method to Stream in src/machine/streams.rs to check if stdout is as expected
This commit is contained in:
@@ -3,58 +3,44 @@ use crate::instructions::*;
|
||||
use crate::machine::machine_indices::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CodeRepo {
|
||||
pub(crate) struct CodeRepo {
|
||||
pub(super) code: Code,
|
||||
}
|
||||
|
||||
impl CodeRepo {
|
||||
#[inline]
|
||||
pub(super)
|
||||
fn new() -> Self {
|
||||
CodeRepo {
|
||||
code: Code::new(),
|
||||
}
|
||||
pub(super) fn new() -> Self {
|
||||
CodeRepo { code: Code::new() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(super)
|
||||
fn lookup_local_instr<'a>(
|
||||
&'a self,
|
||||
p: LocalCodePtr,
|
||||
) -> RefOrOwned<'a, Line> {
|
||||
pub(super) fn lookup_local_instr<'a>(&'a self, p: LocalCodePtr) -> RefOrOwned<'a, Line> {
|
||||
match p {
|
||||
LocalCodePtr::Halt => {
|
||||
// exit with the interrupt exit code.
|
||||
std::process::exit(1);
|
||||
}
|
||||
LocalCodePtr::DirEntry(p) => {
|
||||
RefOrOwned::Borrowed(&self.code[p as usize])
|
||||
}
|
||||
LocalCodePtr::IndexingBuf(p, o, i) => {
|
||||
match &self.code[p] {
|
||||
&Line::IndexingCode(ref indexing_lines) => {
|
||||
match &indexing_lines[o] {
|
||||
&IndexingLine::IndexedChoice(ref indexed_choice_instrs) => {
|
||||
RefOrOwned::Owned(Line::IndexedChoice(indexed_choice_instrs[i]))
|
||||
}
|
||||
&IndexingLine::DynamicIndexedChoice(ref indexed_choice_instrs) => {
|
||||
RefOrOwned::Owned(Line::DynamicIndexedChoice(indexed_choice_instrs[i]))
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
LocalCodePtr::DirEntry(p) => RefOrOwned::Borrowed(&self.code[p as usize]),
|
||||
LocalCodePtr::IndexingBuf(p, o, i) => match &self.code[p] {
|
||||
&Line::IndexingCode(ref indexing_lines) => match &indexing_lines[o] {
|
||||
&IndexingLine::IndexedChoice(ref indexed_choice_instrs) => {
|
||||
RefOrOwned::Owned(Line::IndexedChoice(indexed_choice_instrs[i]))
|
||||
}
|
||||
&IndexingLine::DynamicIndexedChoice(ref indexed_choice_instrs) => {
|
||||
RefOrOwned::Owned(Line::DynamicIndexedChoice(indexed_choice_instrs[i]))
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(super)
|
||||
fn lookup_instr<'a>(
|
||||
pub(super) fn lookup_instr<'a>(
|
||||
&'a self,
|
||||
last_call: bool,
|
||||
p: &CodePtr,
|
||||
@@ -63,9 +49,7 @@ impl CodeRepo {
|
||||
&CodePtr::Local(local) => {
|
||||
return Some(self.lookup_local_instr(local));
|
||||
}
|
||||
&CodePtr::REPL(..) => {
|
||||
None
|
||||
}
|
||||
&CodePtr::REPL(..) => None,
|
||||
&CodePtr::BuiltInClause(ref built_in, _) => {
|
||||
let call_clause = call_clause!(
|
||||
ClauseType::BuiltIn(built_in.clone()),
|
||||
@@ -77,26 +61,26 @@ impl CodeRepo {
|
||||
Some(RefOrOwned::Owned(call_clause))
|
||||
}
|
||||
&CodePtr::CallN(arity, _, last_call) => {
|
||||
let call_clause = call_clause!(
|
||||
ClauseType::CallN,
|
||||
arity,
|
||||
0,
|
||||
last_call
|
||||
);
|
||||
let call_clause = call_clause!(ClauseType::CallN, arity, 0, last_call);
|
||||
|
||||
Some(RefOrOwned::Owned(call_clause))
|
||||
}
|
||||
&CodePtr::VerifyAttrInterrupt(p) => {
|
||||
Some(RefOrOwned::Borrowed(&self.code[p]))
|
||||
}
|
||||
&CodePtr::VerifyAttrInterrupt(p) => Some(RefOrOwned::Borrowed(&self.code[p])),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super)
|
||||
fn find_living_dynamic_else(&self, mut p: usize, cc: usize) -> Option<(usize, usize)> {
|
||||
pub(super) fn find_living_dynamic_else(
|
||||
&self,
|
||||
mut p: usize,
|
||||
cc: usize,
|
||||
) -> Option<(usize, usize)> {
|
||||
loop {
|
||||
match &self.code[p] {
|
||||
&Line::Choice(ChoiceInstruction::DynamicElse(birth, death, NextOrFail::Next(i))) => {
|
||||
&Line::Choice(ChoiceInstruction::DynamicElse(
|
||||
birth,
|
||||
death,
|
||||
NextOrFail::Next(i),
|
||||
)) => {
|
||||
if birth < cc && Death::Finite(cc) <= death {
|
||||
return Some((p, i));
|
||||
} else if i > 0 {
|
||||
@@ -105,7 +89,11 @@ impl CodeRepo {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
&Line::Choice(ChoiceInstruction::DynamicElse(birth, death, NextOrFail::Fail(_))) => {
|
||||
&Line::Choice(ChoiceInstruction::DynamicElse(
|
||||
birth,
|
||||
death,
|
||||
NextOrFail::Fail(_),
|
||||
)) => {
|
||||
if birth < cc && Death::Finite(cc) <= death {
|
||||
return Some((p, 0));
|
||||
} else {
|
||||
@@ -128,8 +116,8 @@ impl CodeRepo {
|
||||
&Line::Choice(ChoiceInstruction::DynamicInternalElse(
|
||||
birth,
|
||||
death,
|
||||
NextOrFail::Fail(_)),
|
||||
) => {
|
||||
NextOrFail::Fail(_),
|
||||
)) => {
|
||||
if birth < cc && Death::Finite(cc) <= death {
|
||||
return Some((p, 0));
|
||||
} else {
|
||||
@@ -146,8 +134,11 @@ impl CodeRepo {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super)
|
||||
fn find_living_dynamic(&self, p: LocalCodePtr, cc: usize) -> Option<(usize, usize, usize, bool)> {
|
||||
pub(super) fn find_living_dynamic(
|
||||
&self,
|
||||
p: LocalCodePtr,
|
||||
cc: usize,
|
||||
) -> Option<(usize, usize, usize, bool)> {
|
||||
let (p, oi, mut ii) = match p {
|
||||
LocalCodePtr::IndexingBuf(p, oi, ii) => (p, oi, ii),
|
||||
_ => unreachable!(),
|
||||
@@ -158,27 +149,27 @@ impl CodeRepo {
|
||||
IndexingLine::DynamicIndexedChoice(ref indexed_choice_instrs) => {
|
||||
indexed_choice_instrs
|
||||
}
|
||||
_ => unreachable!()
|
||||
}
|
||||
_ => unreachable!()
|
||||
_ => unreachable!(),
|
||||
},
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
loop {
|
||||
match &indexed_choice_instrs.get(ii) {
|
||||
Some(&offset) => {
|
||||
match &self.code[p + offset - 1] {
|
||||
&Line::Choice(ChoiceInstruction::DynamicInternalElse(
|
||||
birth, death, next_or_fail,
|
||||
)) => {
|
||||
if birth < cc && Death::Finite(cc) <= death {
|
||||
return Some((offset, oi, ii, next_or_fail.is_next()));
|
||||
} else {
|
||||
ii += 1;
|
||||
}
|
||||
Some(&offset) => match &self.code[p + offset - 1] {
|
||||
&Line::Choice(ChoiceInstruction::DynamicInternalElse(
|
||||
birth,
|
||||
death,
|
||||
next_or_fail,
|
||||
)) => {
|
||||
if birth < cc && Death::Finite(cc) <= death {
|
||||
return Some((offset, oi, ii, next_or_fail.is_next()));
|
||||
} else {
|
||||
ii += 1;
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
None => return None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@ fn capture_offset(line: &Line, index: usize, stack: &mut Vec<usize>) -> bool {
|
||||
&Line::Choice(ChoiceInstruction::TryMeElse(offset)) if offset > 0 => {
|
||||
stack.push(index + offset);
|
||||
}
|
||||
&Line::Choice(ChoiceInstruction::DefaultRetryMeElse(offset)) |
|
||||
&Line::Choice(ChoiceInstruction::RetryMeElse(offset)) if offset > 0 => {
|
||||
&Line::Choice(ChoiceInstruction::DefaultRetryMeElse(offset))
|
||||
| &Line::Choice(ChoiceInstruction::RetryMeElse(offset))
|
||||
if offset > 0 =>
|
||||
{
|
||||
stack.push(index + offset);
|
||||
}
|
||||
&Line::Choice(ChoiceInstruction::DynamicElse(_, _, NextOrFail::Next(offset)))
|
||||
@@ -26,8 +28,8 @@ fn capture_offset(line: &Line, index: usize, stack: &mut Vec<usize>) -> bool {
|
||||
stack.push(index + offset);
|
||||
return true;
|
||||
}
|
||||
&Line::Control(ControlInstruction::Proceed) |
|
||||
&Line::Control(ControlInstruction::CallClause(_, _, _, true, _)) => {
|
||||
&Line::Control(ControlInstruction::Proceed)
|
||||
| &Line::Control(ControlInstruction::CallClause(_, _, _, true, _)) => {
|
||||
return true;
|
||||
}
|
||||
&Line::Control(ControlInstruction::RevJmpBy(offset)) => {
|
||||
@@ -37,8 +39,7 @@ fn capture_offset(line: &Line, index: usize, stack: &mut Vec<usize>) -> bool {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
false
|
||||
@@ -48,8 +49,7 @@ fn capture_offset(line: &Line, index: usize, stack: &mut Vec<usize>) -> bool {
|
||||
* begin in code at the offset p. Each instruction is passed to the
|
||||
* walker function.
|
||||
*/
|
||||
pub fn walk_code(code: &Code, p: usize, mut walker: impl FnMut(&Line))
|
||||
{
|
||||
pub(crate) fn walk_code(code: &Code, p: usize, mut walker: impl FnMut(&Line)) {
|
||||
let mut stack = vec![p];
|
||||
let mut visited_indices = IndexSet::new();
|
||||
|
||||
@@ -60,7 +60,7 @@ pub fn walk_code(code: &Code, p: usize, mut walker: impl FnMut(&Line))
|
||||
visited_indices.insert(first_index);
|
||||
}
|
||||
|
||||
for (index, instr) in code[first_index ..].iter().enumerate() {
|
||||
for (index, instr) in code[first_index..].iter().enumerate() {
|
||||
walker(instr);
|
||||
|
||||
if capture_offset(instr, first_index + index, &mut stack) {
|
||||
@@ -74,7 +74,7 @@ pub fn walk_code(code: &Code, p: usize, mut walker: impl FnMut(&Line))
|
||||
* the code. Otherwise identical to walk_code.
|
||||
*/
|
||||
/*
|
||||
pub fn walk_code_mut(code: &mut Code, p: usize, mut walker: impl FnMut(&mut Line))
|
||||
pub(crate) fn walk_code_mut(code: &mut Code, p: usize, mut walker: impl FnMut(&mut Line))
|
||||
{
|
||||
let mut queue = VecDeque::from(vec![p]);
|
||||
|
||||
|
||||
@@ -7,13 +7,12 @@ use std::ops::IndexMut;
|
||||
type Trail = Vec<(Ref, HeapCellValue)>;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum AttrVarPolicy {
|
||||
pub(crate) enum AttrVarPolicy {
|
||||
DeepCopy,
|
||||
StripAttributes
|
||||
StripAttributes,
|
||||
}
|
||||
|
||||
pub(crate)
|
||||
trait CopierTarget: IndexMut<usize, Output = HeapCellValue> {
|
||||
pub(crate) trait CopierTarget: IndexMut<usize, Output = HeapCellValue> {
|
||||
fn deref(&self, val: Addr) -> Addr;
|
||||
fn push(&mut self, val: HeapCellValue);
|
||||
fn stack(&mut self) -> &mut Stack;
|
||||
@@ -21,8 +20,7 @@ trait CopierTarget: IndexMut<usize, Output = HeapCellValue> {
|
||||
fn threshold(&self) -> usize;
|
||||
}
|
||||
|
||||
pub(crate)
|
||||
fn copy_term<T: CopierTarget>(target: T, addr: Addr, attr_var_policy: AttrVarPolicy) {
|
||||
pub(crate) fn copy_term<T: CopierTarget>(target: T, addr: Addr, attr_var_policy: AttrVarPolicy) {
|
||||
let mut copy_term_state = CopyTermState::new(target, attr_var_policy);
|
||||
copy_term_state.copy_term_impl(addr);
|
||||
}
|
||||
@@ -43,7 +41,7 @@ impl<T: CopierTarget> CopyTermState<T> {
|
||||
scan: 0,
|
||||
old_h: target.threshold(),
|
||||
target,
|
||||
attr_var_policy
|
||||
attr_var_policy,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,14 +57,11 @@ impl<T: CopierTarget> CopyTermState<T> {
|
||||
HeapCellValue::Addr(Addr::Lis(threshold)),
|
||||
);
|
||||
|
||||
self.trail.push((
|
||||
Ref::HeapCell(addr),
|
||||
trail_item,
|
||||
));
|
||||
self.trail.push((Ref::HeapCell(addr), trail_item));
|
||||
}
|
||||
|
||||
fn copy_list(&mut self, addr: usize) {
|
||||
for offset in 0 .. 2 {
|
||||
for offset in 0..2 {
|
||||
if let Addr::Lis(h) = self.target[addr + offset].as_addr(addr + offset) {
|
||||
if h >= self.old_h {
|
||||
*self.value_at_scan() = HeapCellValue::Addr(Addr::Lis(h));
|
||||
@@ -81,12 +76,14 @@ impl<T: CopierTarget> CopyTermState<T> {
|
||||
|
||||
*self.value_at_scan() = HeapCellValue::Addr(Addr::Lis(threshold));
|
||||
|
||||
for i in 0 .. 2 {
|
||||
for i in 0..2 {
|
||||
let hcv = self.target[addr + i].context_free_clone();
|
||||
self.target.push(hcv);
|
||||
}
|
||||
|
||||
let cdr = self.target.store(self.target.deref(Addr::HeapCell(addr + 1)));
|
||||
let cdr = self
|
||||
.target
|
||||
.store(self.target.deref(Addr::HeapCell(addr + 1)));
|
||||
|
||||
if !cdr.is_ref() {
|
||||
self.trail_list_cell(addr + 1, threshold);
|
||||
@@ -113,34 +110,27 @@ impl<T: CopierTarget> CopyTermState<T> {
|
||||
|
||||
let threshold = self.target.threshold();
|
||||
|
||||
*self.value_at_scan() =
|
||||
HeapCellValue::Addr(Addr::PStrLocation(threshold, n));
|
||||
*self.value_at_scan() = HeapCellValue::Addr(Addr::PStrLocation(threshold, n));
|
||||
|
||||
self.scan += 1;
|
||||
|
||||
let (pstr, has_tail) =
|
||||
match &self.target[addr] {
|
||||
&HeapCellValue::PartialString(ref pstr, has_tail) => {
|
||||
(pstr.clone_from_offset(0), has_tail)
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
};
|
||||
let (pstr, has_tail) = match &self.target[addr] {
|
||||
&HeapCellValue::PartialString(ref pstr, has_tail) => {
|
||||
(pstr.clone_from_offset(0), has_tail)
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
};
|
||||
|
||||
self.target.push(HeapCellValue::PartialString(pstr, has_tail));
|
||||
self.target
|
||||
.push(HeapCellValue::PartialString(pstr, has_tail));
|
||||
|
||||
let replacement = HeapCellValue::Addr(Addr::PStrLocation(threshold, n));
|
||||
|
||||
let trail_item = mem::replace(
|
||||
&mut self.target[addr],
|
||||
replacement,
|
||||
);
|
||||
let trail_item = mem::replace(&mut self.target[addr], replacement);
|
||||
|
||||
self.trail.push((
|
||||
Ref::HeapCell(addr),
|
||||
trail_item,
|
||||
));
|
||||
self.trail.push((Ref::HeapCell(addr), trail_item));
|
||||
|
||||
if has_tail {
|
||||
let tail_addr = self.target[addr + 1].as_addr(addr + 1);
|
||||
@@ -154,10 +144,8 @@ impl<T: CopierTarget> CopyTermState<T> {
|
||||
self.target[frontier] = HeapCellValue::Addr(Addr::HeapCell(frontier));
|
||||
self.target[h] = HeapCellValue::Addr(Addr::HeapCell(frontier));
|
||||
|
||||
self.trail.push((
|
||||
Ref::HeapCell(h),
|
||||
HeapCellValue::Addr(Addr::HeapCell(h)),
|
||||
));
|
||||
self.trail
|
||||
.push((Ref::HeapCell(h), HeapCellValue::Addr(Addr::HeapCell(h))));
|
||||
}
|
||||
Addr::StackCell(fr, sc) => {
|
||||
self.target[frontier] = HeapCellValue::Addr(Addr::HeapCell(frontier));
|
||||
@@ -178,13 +166,12 @@ impl<T: CopierTarget> CopyTermState<T> {
|
||||
self.target[frontier] = HeapCellValue::Addr(Addr::HeapCell(threshold));
|
||||
self.target[h] = HeapCellValue::Addr(Addr::HeapCell(threshold));
|
||||
|
||||
self.trail.push((
|
||||
Ref::AttrVar(h),
|
||||
HeapCellValue::Addr(Addr::AttrVar(h)),
|
||||
));
|
||||
self.trail
|
||||
.push((Ref::AttrVar(h), HeapCellValue::Addr(Addr::AttrVar(h))));
|
||||
|
||||
if let AttrVarPolicy::DeepCopy = self.attr_var_policy {
|
||||
self.target.push(HeapCellValue::Addr(Addr::AttrVar(threshold)));
|
||||
self.target
|
||||
.push(HeapCellValue::Addr(Addr::AttrVar(threshold)));
|
||||
|
||||
let list_val = self.target[h + 1].context_free_clone();
|
||||
self.target.push(list_val);
|
||||
@@ -226,12 +213,10 @@ impl<T: CopierTarget> CopyTermState<T> {
|
||||
HeapCellValue::Addr(Addr::Str(threshold)),
|
||||
);
|
||||
|
||||
self.trail.push((
|
||||
Ref::HeapCell(addr),
|
||||
trail_item,
|
||||
));
|
||||
self.trail.push((Ref::HeapCell(addr), trail_item));
|
||||
|
||||
self.target.push(HeapCellValue::NamedStr(arity, name, fixity));
|
||||
self.target
|
||||
.push(HeapCellValue::NamedStr(arity, name, fixity));
|
||||
|
||||
for i in 0..arity {
|
||||
let hcv = self.target[addr + 1 + i].context_free_clone();
|
||||
@@ -255,43 +240,41 @@ impl<T: CopierTarget> CopyTermState<T> {
|
||||
|
||||
while self.scan < self.target.threshold() {
|
||||
match self.value_at_scan() {
|
||||
&mut HeapCellValue::Addr(addr) => {
|
||||
match addr {
|
||||
Addr::Con(h) => {
|
||||
let addr = self.target[h].as_addr(h);
|
||||
&mut HeapCellValue::Addr(addr) => match addr {
|
||||
Addr::Con(h) => {
|
||||
let addr = self.target[h].as_addr(h);
|
||||
|
||||
if addr == Addr::Con(h) {
|
||||
*self.value_at_scan() = self.target[h].context_free_clone();
|
||||
} else {
|
||||
*self.value_at_scan() = HeapCellValue::Addr(addr);
|
||||
}
|
||||
}
|
||||
Addr::Lis(h) => {
|
||||
if h >= self.old_h {
|
||||
self.scan += 1;
|
||||
} else {
|
||||
self.copy_list(h);
|
||||
}
|
||||
}
|
||||
addr @ Addr::AttrVar(_) |
|
||||
addr @ Addr::HeapCell(_) |
|
||||
addr @ Addr::StackCell(..) => {
|
||||
self.copy_var(addr);
|
||||
}
|
||||
Addr::Str(addr) => {
|
||||
self.copy_structure(addr);
|
||||
}
|
||||
Addr::PStrLocation(addr, n) => {
|
||||
self.copy_partial_string(addr, n);
|
||||
}
|
||||
Addr::Stream(h) => {
|
||||
if addr == Addr::Con(h) {
|
||||
*self.value_at_scan() = self.target[h].context_free_clone();
|
||||
}
|
||||
_ => {
|
||||
self.scan += 1;
|
||||
} else {
|
||||
*self.value_at_scan() = HeapCellValue::Addr(addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Addr::Lis(h) => {
|
||||
if h >= self.old_h {
|
||||
self.scan += 1;
|
||||
} else {
|
||||
self.copy_list(h);
|
||||
}
|
||||
}
|
||||
addr @ Addr::AttrVar(_)
|
||||
| addr @ Addr::HeapCell(_)
|
||||
| addr @ Addr::StackCell(..) => {
|
||||
self.copy_var(addr);
|
||||
}
|
||||
Addr::Str(addr) => {
|
||||
self.copy_structure(addr);
|
||||
}
|
||||
Addr::PStrLocation(addr, n) => {
|
||||
self.copy_partial_string(addr, n);
|
||||
}
|
||||
Addr::Stream(h) => {
|
||||
*self.value_at_scan() = self.target[h].context_free_clone();
|
||||
}
|
||||
_ => {
|
||||
self.scan += 1;
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
self.scan += 1;
|
||||
}
|
||||
@@ -304,10 +287,10 @@ impl<T: CopierTarget> CopyTermState<T> {
|
||||
fn unwind_trail(&mut self) {
|
||||
for (r, value) in self.trail.drain(0..) {
|
||||
match r {
|
||||
Ref::AttrVar(h) | Ref::HeapCell(h) =>
|
||||
self.target[h] = value,
|
||||
Ref::StackCell(fr, sc) =>
|
||||
self.target.stack().index_and_frame_mut(fr)[sc] = value.as_addr(0),
|
||||
Ref::AttrVar(h) | Ref::HeapCell(h) => self.target[h] = value,
|
||||
Ref::StackCell(fr, sc) => {
|
||||
self.target.stack().index_and_frame_mut(fr)[sc] = value.as_addr(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,7 +429,7 @@ impl<T: RawBlockTraits> HeapTemplate<T> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn index_addr<'a>(&'a self, addr: &Addr) -> RefOrOwned<'a, HeapCellValue> {
|
||||
pub(crate) fn index_addr<'a>(&'a self, addr: &Addr) -> RefOrOwned<'a, HeapCellValue> {
|
||||
match addr {
|
||||
&Addr::Con(h) | &Addr::Str(h) | &Addr::Stream(h) | &Addr::TcpListener(h) => {
|
||||
RefOrOwned::Borrowed(&self[h])
|
||||
|
||||
@@ -184,18 +184,16 @@ impl<'a> Drop for LoadState<'a> {
|
||||
module_decl,
|
||||
listing_src,
|
||||
local_extensible_predicates,
|
||||
) => {
|
||||
match self.wam.indices.modules.get_mut(&module_decl.name) {
|
||||
Some(ref mut module) => {
|
||||
module.module_decl = module_decl;
|
||||
module.listing_src = listing_src;
|
||||
module.local_extensible_predicates = local_extensible_predicates;
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
) => match self.wam.indices.modules.get_mut(&module_decl.name) {
|
||||
Some(ref mut module) => {
|
||||
module.module_decl = module_decl;
|
||||
module.listing_src = listing_src;
|
||||
module.local_extensible_predicates = local_extensible_predicates;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
},
|
||||
RetractionRecord::AddedDiscontiguousPredicate(compilation_target, key) => {
|
||||
match compilation_target {
|
||||
CompilationTarget::User => {
|
||||
@@ -487,17 +485,15 @@ impl<'a> Drop for LoadState<'a> {
|
||||
}
|
||||
}
|
||||
RetractionRecord::SkeletonLocalClauseClausePopFront(
|
||||
src_compilation_target, local_compilation_target, key,
|
||||
src_compilation_target,
|
||||
local_compilation_target,
|
||||
key,
|
||||
) => {
|
||||
match self
|
||||
.wam
|
||||
.indices
|
||||
.get_local_predicate_skeleton_mut(
|
||||
&src_compilation_target,
|
||||
local_compilation_target,
|
||||
key,
|
||||
)
|
||||
{
|
||||
match self.wam.indices.get_local_predicate_skeleton_mut(
|
||||
&src_compilation_target,
|
||||
local_compilation_target,
|
||||
key,
|
||||
) {
|
||||
Some(skeleton) => {
|
||||
skeleton.clause_clause_locs.pop_front();
|
||||
}
|
||||
@@ -505,17 +501,15 @@ impl<'a> Drop for LoadState<'a> {
|
||||
}
|
||||
}
|
||||
RetractionRecord::SkeletonLocalClauseClausePopBack(
|
||||
src_compilation_target, local_compilation_target, key,
|
||||
src_compilation_target,
|
||||
local_compilation_target,
|
||||
key,
|
||||
) => {
|
||||
match self
|
||||
.wam
|
||||
.indices
|
||||
.get_local_predicate_skeleton_mut(
|
||||
&src_compilation_target,
|
||||
local_compilation_target,
|
||||
key,
|
||||
)
|
||||
{
|
||||
match self.wam.indices.get_local_predicate_skeleton_mut(
|
||||
&src_compilation_target,
|
||||
local_compilation_target,
|
||||
key,
|
||||
) {
|
||||
Some(skeleton) => {
|
||||
skeleton.clause_clause_locs.pop_back();
|
||||
}
|
||||
@@ -528,15 +522,11 @@ impl<'a> Drop for LoadState<'a> {
|
||||
key,
|
||||
len,
|
||||
) => {
|
||||
match self
|
||||
.wam
|
||||
.indices
|
||||
.get_local_predicate_skeleton_mut(
|
||||
&src_compilation_target,
|
||||
local_compilation_target,
|
||||
key,
|
||||
)
|
||||
{
|
||||
match self.wam.indices.get_local_predicate_skeleton_mut(
|
||||
&src_compilation_target,
|
||||
local_compilation_target,
|
||||
key,
|
||||
) {
|
||||
Some(skeleton) => {
|
||||
skeleton.clause_clause_locs.truncate_back(len);
|
||||
}
|
||||
@@ -603,15 +593,11 @@ impl<'a> Drop for LoadState<'a> {
|
||||
key,
|
||||
clause_locs,
|
||||
) => {
|
||||
match self
|
||||
.wam
|
||||
.indices
|
||||
.get_local_predicate_skeleton_mut(
|
||||
&compilation_target,
|
||||
local_compilation_target,
|
||||
key,
|
||||
)
|
||||
{
|
||||
match self.wam.indices.get_local_predicate_skeleton_mut(
|
||||
&compilation_target,
|
||||
local_compilation_target,
|
||||
key,
|
||||
) {
|
||||
Some(skeleton) => skeleton.clause_clause_locs = clause_locs,
|
||||
None => {}
|
||||
}
|
||||
@@ -663,7 +649,7 @@ impl<'a> Drop for LoadState<'a> {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
||||
pub enum CompilationTarget {
|
||||
pub(crate) enum CompilationTarget {
|
||||
Module(ClauseName),
|
||||
User,
|
||||
}
|
||||
@@ -682,7 +668,7 @@ impl CompilationTarget {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn module_name(&self) -> ClauseName {
|
||||
pub(crate) fn module_name(&self) -> ClauseName {
|
||||
match self {
|
||||
CompilationTarget::User => {
|
||||
clause_name!("user")
|
||||
@@ -692,7 +678,7 @@ impl CompilationTarget {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PredicateQueue {
|
||||
pub(crate) struct PredicateQueue {
|
||||
pub(super) predicates: Vec<Term>,
|
||||
pub(super) compilation_target: CompilationTarget,
|
||||
}
|
||||
@@ -781,10 +767,9 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
||||
}
|
||||
|
||||
let term = match term {
|
||||
Term::Clause(_, name, terms, _)
|
||||
if name.as_str() == ":-" && terms.len() == 1 => {
|
||||
return Ok(Some(setup_declaration(&self.load_state, terms)?));
|
||||
},
|
||||
Term::Clause(_, name, terms, _) if name.as_str() == ":-" && terms.len() == 1 => {
|
||||
return Ok(Some(setup_declaration(&self.load_state, terms)?));
|
||||
}
|
||||
term => term,
|
||||
};
|
||||
|
||||
@@ -808,8 +793,7 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
||||
self.load_state.compilation_target =
|
||||
CompilationTarget::Module(module_decl.name.clone());
|
||||
|
||||
self.predicates.compilation_target =
|
||||
self.load_state.compilation_target.clone();
|
||||
self.predicates.compilation_target = self.load_state.compilation_target.clone();
|
||||
|
||||
self.load_state
|
||||
.add_module(module_decl, self.term_stream.listing_src().clone());
|
||||
@@ -975,9 +959,10 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
||||
if !*flag_accessor(skeleton) {
|
||||
*flag_accessor(skeleton) = true;
|
||||
|
||||
self.load_state.retraction_info.push_record(
|
||||
retraction_fn(compilation_target.clone(), key.clone()),
|
||||
);
|
||||
self.load_state.retraction_info.push_record(retraction_fn(
|
||||
compilation_target.clone(),
|
||||
key.clone(),
|
||||
));
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@@ -1003,9 +988,10 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
||||
if !*flag_accessor(skeleton) {
|
||||
*flag_accessor(skeleton) = true;
|
||||
|
||||
self.load_state.retraction_info.push_record(
|
||||
retraction_fn(compilation_target.clone(), key.clone()),
|
||||
);
|
||||
self.load_state.retraction_info.push_record(retraction_fn(
|
||||
compilation_target.clone(),
|
||||
key.clone(),
|
||||
));
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@@ -1024,7 +1010,8 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
||||
}
|
||||
},
|
||||
None => {
|
||||
self.load_state.add_dynamically_generated_module(module_name);
|
||||
self.load_state
|
||||
.add_dynamically_generated_module(module_name);
|
||||
|
||||
let mut skeleton = PredicateSkeleton::new();
|
||||
*flag_accessor(&mut skeleton) = true;
|
||||
@@ -1068,28 +1055,29 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
||||
}
|
||||
CompilationTarget::Module(ref module_name) => {
|
||||
match self.load_state.wam.indices.modules.get_mut(module_name) {
|
||||
Some(ref mut module) =>
|
||||
match module.local_extensible_predicates.get_mut(
|
||||
&(compilation_target.clone(), key.clone()),
|
||||
) {
|
||||
Some(ref mut skeleton) => {
|
||||
if !*flag_accessor(skeleton) {
|
||||
*flag_accessor(skeleton) = true;
|
||||
}
|
||||
Some(ref mut module) => match module
|
||||
.local_extensible_predicates
|
||||
.get_mut(&(compilation_target.clone(), key.clone()))
|
||||
{
|
||||
Some(ref mut skeleton) => {
|
||||
if !*flag_accessor(skeleton) {
|
||||
*flag_accessor(skeleton) = true;
|
||||
}
|
||||
None => {
|
||||
let mut skeleton = PredicateSkeleton::new();
|
||||
*flag_accessor(&mut skeleton) = true;
|
||||
}
|
||||
None => {
|
||||
let mut skeleton = PredicateSkeleton::new();
|
||||
*flag_accessor(&mut skeleton) = true;
|
||||
|
||||
self.load_state.add_local_extensible_predicate(
|
||||
compilation_target.clone(),
|
||||
key.clone(),
|
||||
skeleton,
|
||||
);
|
||||
}
|
||||
},
|
||||
self.load_state.add_local_extensible_predicate(
|
||||
compilation_target.clone(),
|
||||
key.clone(),
|
||||
skeleton,
|
||||
);
|
||||
}
|
||||
},
|
||||
None => {
|
||||
self.load_state.add_dynamically_generated_module(module_name);
|
||||
self.load_state
|
||||
.add_dynamically_generated_module(module_name);
|
||||
|
||||
let mut skeleton = PredicateSkeleton::new();
|
||||
*flag_accessor(&mut skeleton) = true;
|
||||
@@ -1106,7 +1094,10 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
Err(SessionError::PredicateNotMultifileOrDiscontiguous(compilation_target, key))
|
||||
Err(SessionError::PredicateNotMultifileOrDiscontiguous(
|
||||
compilation_target,
|
||||
key,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1139,10 +1130,9 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
||||
RetractionRecord::AddedDynamicPredicate,
|
||||
)?;
|
||||
|
||||
let code_index = self.load_state.get_or_insert_code_index(
|
||||
(name.clone(), arity),
|
||||
compilation_target.clone(),
|
||||
);
|
||||
let code_index = self
|
||||
.load_state
|
||||
.get_or_insert_code_index((name.clone(), arity), compilation_target.clone());
|
||||
|
||||
if let IndexPtr::Undefined = code_index.get() {
|
||||
set_code_index(
|
||||
@@ -1204,12 +1194,11 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
||||
&self.load_state.compilation_target,
|
||||
self.predicates.compilation_target.clone(),
|
||||
key.clone(),
|
||||
)
|
||||
{
|
||||
Some(skeleton) if !skeleton.clause_clause_locs.is_empty() =>
|
||||
mem::replace(&mut skeleton.clause_clause_locs, sdeq![]),
|
||||
_ =>
|
||||
return,
|
||||
) {
|
||||
Some(skeleton) if !skeleton.clause_clause_locs.is_empty() => {
|
||||
mem::replace(&mut skeleton.clause_clause_locs, sdeq![])
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
|
||||
self.load_state.retraction_info.push_record(
|
||||
@@ -1233,10 +1222,8 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
||||
module_name => module_name.clone(),
|
||||
};
|
||||
|
||||
self.load_state.retract_local_clause_clauses(
|
||||
clause_clause_compilation_target,
|
||||
&clause_locs,
|
||||
);
|
||||
self.load_state
|
||||
.retract_local_clause_clauses(clause_clause_compilation_target, &clause_locs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1305,7 +1292,9 @@ impl Machine {
|
||||
if export_list.is_empty() {
|
||||
loader.load_state.import_module(library)?;
|
||||
} else {
|
||||
loader.load_state.import_qualified_module(library, export_list)?;
|
||||
loader
|
||||
.load_state
|
||||
.import_qualified_module(library, export_list)?;
|
||||
}
|
||||
|
||||
LiveTermStream::evacuate(loader)
|
||||
@@ -1347,29 +1336,39 @@ impl Machine {
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn add_discontiguous_predicate(&mut self) {
|
||||
self.add_extensible_predicate_declaration(|loader, compilation_target, clause_name, arity| {
|
||||
loader.add_discontiguous_predicate(compilation_target, clause_name, arity)
|
||||
});
|
||||
self.add_extensible_predicate_declaration(
|
||||
|loader, compilation_target, clause_name, arity| {
|
||||
loader.add_discontiguous_predicate(compilation_target, clause_name, arity)
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn add_dynamic_predicate(&mut self) {
|
||||
self.add_extensible_predicate_declaration(|loader, compilation_target, clause_name, arity| {
|
||||
loader.add_dynamic_predicate(compilation_target, clause_name, arity)
|
||||
});
|
||||
self.add_extensible_predicate_declaration(
|
||||
|loader, compilation_target, clause_name, arity| {
|
||||
loader.add_dynamic_predicate(compilation_target, clause_name, arity)
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn add_multifile_predicate(&mut self) {
|
||||
self.add_extensible_predicate_declaration(|loader, compilation_target, clause_name, arity| {
|
||||
loader.add_multifile_predicate(compilation_target, clause_name, arity)
|
||||
});
|
||||
self.add_extensible_predicate_declaration(
|
||||
|loader, compilation_target, clause_name, arity| {
|
||||
loader.add_multifile_predicate(compilation_target, clause_name, arity)
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn add_extensible_predicate_declaration(
|
||||
&mut self,
|
||||
decl_adder: impl Fn(&mut Loader<LiveTermStream>, CompilationTarget, ClauseName, usize)
|
||||
-> Result<(), SessionError>,
|
||||
decl_adder: impl Fn(
|
||||
&mut Loader<LiveTermStream>,
|
||||
CompilationTarget,
|
||||
ClauseName,
|
||||
usize,
|
||||
) -> Result<(), SessionError>,
|
||||
) {
|
||||
let module_name = atom_from!(
|
||||
self.machine_st,
|
||||
@@ -1805,15 +1804,10 @@ impl Machine {
|
||||
let mut loader = Loader::new(LiveTermStream::new(ListingSource::User), self);
|
||||
loader.load_state.compilation_target = compilation_target;
|
||||
|
||||
let clause_clause_compilation_target =
|
||||
match &loader.load_state.compilation_target {
|
||||
CompilationTarget::User => {
|
||||
CompilationTarget::Module(clause_name!("builtins"))
|
||||
}
|
||||
module => {
|
||||
module.clone()
|
||||
}
|
||||
};
|
||||
let clause_clause_compilation_target = match &loader.load_state.compilation_target {
|
||||
CompilationTarget::User => CompilationTarget::Module(clause_name!("builtins")),
|
||||
module => module.clone(),
|
||||
};
|
||||
|
||||
let mut clause_clause_target_poses: Vec<_> = loader
|
||||
.load_state
|
||||
@@ -1830,12 +1824,13 @@ impl Machine {
|
||||
&(clause_name!("$clause"), 2),
|
||||
)
|
||||
.map(|clause_clause_skeleton| {
|
||||
skeleton.clause_clause_locs
|
||||
skeleton
|
||||
.clause_clause_locs
|
||||
.iter()
|
||||
.map(|clause_clause_loc| {
|
||||
clause_clause_skeleton.target_pos_of_clause_clause_loc(
|
||||
*clause_clause_loc,
|
||||
).unwrap()
|
||||
clause_clause_skeleton
|
||||
.target_pos_of_clause_clause_loc(*clause_clause_loc)
|
||||
.unwrap()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
@@ -1850,17 +1845,18 @@ impl Machine {
|
||||
.get_predicate_skeleton_mut(&loader.load_state.compilation_target, &key)
|
||||
.map(|skeleton| skeleton.reset());
|
||||
|
||||
let code_index = loader.load_state.get_or_insert_code_index(
|
||||
key,
|
||||
loader.load_state.compilation_target.clone(),
|
||||
);
|
||||
let code_index = loader
|
||||
.load_state
|
||||
.get_or_insert_code_index(key, loader.load_state.compilation_target.clone());
|
||||
|
||||
code_index.set(IndexPtr::DynamicUndefined);
|
||||
|
||||
loader.load_state.compilation_target = clause_clause_compilation_target;
|
||||
|
||||
while let Some(target_pos) = clause_clause_target_poses.pop() {
|
||||
loader.load_state.retract_clause((clause_name!("$clause"), 2), target_pos);
|
||||
loader
|
||||
.load_state
|
||||
.retract_clause((clause_name!("$clause"), 2), target_pos);
|
||||
}
|
||||
|
||||
LiveTermStream::evacuate(loader)
|
||||
@@ -1918,11 +1914,9 @@ impl Machine {
|
||||
&clause_clause_compilation_target,
|
||||
&(clause_name!("$clause"), 2),
|
||||
) {
|
||||
Some(skeleton) => {
|
||||
skeleton.target_pos_of_clause_clause_loc(
|
||||
clause_clause_loc,
|
||||
).unwrap()
|
||||
}
|
||||
Some(skeleton) => skeleton
|
||||
.target_pos_of_clause_clause_loc(clause_clause_loc)
|
||||
.unwrap(),
|
||||
None => {
|
||||
unreachable!();
|
||||
}
|
||||
@@ -1962,10 +1956,9 @@ impl Machine {
|
||||
|
||||
let (loader, evacuable_h) = self.loader_from_heap_evacuable(temp_v!(4));
|
||||
|
||||
loader.load_state.wam.machine_st.fail =
|
||||
(!loader.predicates.is_empty() &&
|
||||
loader.predicates.compilation_target != compilation_target) ||
|
||||
!key.is_consistent(&loader.predicates);
|
||||
loader.load_state.wam.machine_st.fail = (!loader.predicates.is_empty()
|
||||
&& loader.predicates.compilation_target != compilation_target)
|
||||
|| !key.is_consistent(&loader.predicates);
|
||||
|
||||
let result = LiveTermStream::evacuate(loader);
|
||||
self.restore_load_state_payload(result, evacuable_h);
|
||||
@@ -2263,5 +2256,6 @@ pub(super) fn load_module(
|
||||
code_dir,
|
||||
op_dir,
|
||||
meta_predicate_dir,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ use prolog_parser::ast::*;
|
||||
use prolog_parser::{clause_name, temp_v};
|
||||
|
||||
use crate::forms::{ModuleSource, Number}; //, PredicateKey};
|
||||
use crate::machine::PredicateKey;
|
||||
use crate::machine::heap::*;
|
||||
use crate::machine::loader::CompilationTarget;
|
||||
use crate::machine::machine_indices::*;
|
||||
use crate::machine::machine_state::*;
|
||||
use crate::machine::PredicateKey;
|
||||
use crate::rug::Integer;
|
||||
|
||||
use std::rc::Rc;
|
||||
@@ -321,14 +321,12 @@ impl MachineError {
|
||||
// SessionError::InvalidFileName(filename) => {
|
||||
// Self::existence_error(h, ExistenceError::Module(filename))
|
||||
// }
|
||||
SessionError::ModuleDoesNotContainExport(..) => {
|
||||
Self::permission_error(
|
||||
h,
|
||||
Permission::Access,
|
||||
"private_procedure",
|
||||
functor!("module_does_not_contain_claimed_export"),
|
||||
)
|
||||
}
|
||||
SessionError::ModuleDoesNotContainExport(..) => Self::permission_error(
|
||||
h,
|
||||
Permission::Access,
|
||||
"private_procedure",
|
||||
functor!("module_does_not_contain_claimed_export"),
|
||||
),
|
||||
SessionError::ModuleCannotImportSelf(module_name) => Self::permission_error(
|
||||
h,
|
||||
Permission::Modify,
|
||||
@@ -417,7 +415,7 @@ impl MachineError {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CompilationError {
|
||||
pub(crate) enum CompilationError {
|
||||
Arithmetic(ArithmeticError),
|
||||
ParserError(ParserError),
|
||||
// BadPendingByte,
|
||||
@@ -454,14 +452,14 @@ impl From<ParserError> for CompilationError {
|
||||
}
|
||||
|
||||
impl CompilationError {
|
||||
pub fn line_and_col_num(&self) -> Option<(usize, usize)> {
|
||||
pub(crate) fn line_and_col_num(&self) -> Option<(usize, usize)> {
|
||||
match self {
|
||||
&CompilationError::ParserError(ref err) => err.line_and_col_num(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_functor(&self, _h: usize) -> MachineStub {
|
||||
pub(crate) fn as_functor(&self, _h: usize) -> MachineStub {
|
||||
match self {
|
||||
&CompilationError::Arithmetic(..) => functor!("arithmetic_error"),
|
||||
// &CompilationError::BadPendingByte =>
|
||||
@@ -494,7 +492,7 @@ impl CompilationError {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Permission {
|
||||
pub(crate) enum Permission {
|
||||
Access,
|
||||
Create,
|
||||
InputStream,
|
||||
@@ -506,7 +504,7 @@ pub enum Permission {
|
||||
|
||||
impl Permission {
|
||||
#[inline]
|
||||
pub fn as_str(self) -> &'static str {
|
||||
pub(crate) fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Permission::Access => "access",
|
||||
Permission::Create => "create",
|
||||
@@ -521,7 +519,7 @@ impl Permission {
|
||||
|
||||
// from 7.12.2 b) of 13211-1:1995
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ValidType {
|
||||
pub(crate) enum ValidType {
|
||||
Atom,
|
||||
Atomic,
|
||||
// Boolean,
|
||||
@@ -543,7 +541,7 @@ pub enum ValidType {
|
||||
}
|
||||
|
||||
impl ValidType {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
pub(crate) fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
ValidType::Atom => "atom",
|
||||
ValidType::Atomic => "atomic",
|
||||
@@ -568,7 +566,7 @@ impl ValidType {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum DomainErrorType {
|
||||
pub(crate) enum DomainErrorType {
|
||||
IOMode,
|
||||
NotLessThanZero,
|
||||
Order,
|
||||
@@ -578,7 +576,7 @@ pub enum DomainErrorType {
|
||||
}
|
||||
|
||||
impl DomainErrorType {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
pub(crate) fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
DomainErrorType::IOMode => "io_mode",
|
||||
DomainErrorType::NotLessThanZero => "not_less_than_zero",
|
||||
@@ -592,7 +590,7 @@ impl DomainErrorType {
|
||||
|
||||
// from 7.12.2 f) of 13211-1:1995
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum RepFlag {
|
||||
pub(crate) enum RepFlag {
|
||||
Character,
|
||||
CharacterCode,
|
||||
InCharacterCode,
|
||||
@@ -602,7 +600,7 @@ pub enum RepFlag {
|
||||
}
|
||||
|
||||
impl RepFlag {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
pub(crate) fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
RepFlag::Character => "character",
|
||||
RepFlag::CharacterCode => "character_code",
|
||||
@@ -616,7 +614,7 @@ impl RepFlag {
|
||||
|
||||
// from 7.12.2 g) of 13211-1:1995
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum EvalError {
|
||||
pub(crate) enum EvalError {
|
||||
FloatOverflow,
|
||||
Undefined,
|
||||
// Underflow,
|
||||
@@ -624,7 +622,7 @@ pub enum EvalError {
|
||||
}
|
||||
|
||||
impl EvalError {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
pub(crate) fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
EvalError::FloatOverflow => "float_overflow",
|
||||
EvalError::Undefined => "undefined",
|
||||
@@ -806,7 +804,7 @@ impl MachineState {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ExistenceError {
|
||||
pub(crate) enum ExistenceError {
|
||||
Module(ClauseName),
|
||||
ModuleSource(ModuleSource),
|
||||
Procedure(ClauseName, usize),
|
||||
@@ -815,7 +813,7 @@ pub enum ExistenceError {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SessionError {
|
||||
pub(crate) enum SessionError {
|
||||
CompilationError(CompilationError),
|
||||
// CannotOverwriteBuiltIn(ClauseName),
|
||||
// CannotOverwriteImport(ClauseName),
|
||||
@@ -830,7 +828,7 @@ pub enum SessionError {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum EvalSession {
|
||||
pub(crate) enum EvalSession {
|
||||
// EntrySuccess,
|
||||
Error(SessionError),
|
||||
}
|
||||
|
||||
@@ -29,12 +29,12 @@ use std::ops::{Add, AddAssign, Deref, Sub, SubAssign};
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct OrderedOpDirKey(pub ClauseName, pub Fixity);
|
||||
pub(crate) struct OrderedOpDirKey(pub(crate) ClauseName, pub(crate) Fixity);
|
||||
|
||||
pub type OssifiedOpDir = BTreeMap<OrderedOpDirKey, (usize, Specifier)>;
|
||||
pub(crate) type OssifiedOpDir = BTreeMap<OrderedOpDirKey, (usize, Specifier)>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum DBRef {
|
||||
pub(crate) enum DBRef {
|
||||
NamedPred(ClauseName, usize, Option<SharedOpDesc>),
|
||||
Op(
|
||||
usize,
|
||||
@@ -47,7 +47,7 @@ pub enum DBRef {
|
||||
|
||||
// 7.2
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum TermOrderCategory {
|
||||
pub(crate) enum TermOrderCategory {
|
||||
Variable,
|
||||
FloatingPoint,
|
||||
Integer,
|
||||
@@ -56,7 +56,7 @@ pub enum TermOrderCategory {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Addr {
|
||||
pub(crate) enum Addr {
|
||||
AttrVar(usize),
|
||||
Char(char),
|
||||
Con(usize),
|
||||
@@ -76,14 +76,14 @@ pub enum Addr {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, PartialOrd)]
|
||||
pub enum Ref {
|
||||
pub(crate) enum Ref {
|
||||
AttrVar(usize),
|
||||
HeapCell(usize),
|
||||
StackCell(usize, usize),
|
||||
}
|
||||
|
||||
impl Ref {
|
||||
pub fn as_addr(self) -> Addr {
|
||||
pub(crate) fn as_addr(self) -> Addr {
|
||||
match self {
|
||||
Ref::AttrVar(h) => Addr::AttrVar(h),
|
||||
Ref::HeapCell(h) => Addr::HeapCell(h),
|
||||
@@ -141,7 +141,7 @@ impl PartialOrd<Ref> for Addr {
|
||||
|
||||
impl Addr {
|
||||
#[inline]
|
||||
pub fn is_heap_bound(&self) -> bool {
|
||||
pub(crate) fn is_heap_bound(&self) -> bool {
|
||||
match self {
|
||||
Addr::Char(_)
|
||||
| Addr::EmptyList
|
||||
@@ -154,7 +154,7 @@ impl Addr {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_ref(&self) -> bool {
|
||||
pub(crate) fn is_ref(&self) -> bool {
|
||||
match self {
|
||||
Addr::HeapCell(_) | Addr::StackCell(_, _) | Addr::AttrVar(_) => true,
|
||||
_ => false,
|
||||
@@ -162,7 +162,7 @@ impl Addr {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_var(&self) -> Option<Ref> {
|
||||
pub(crate) fn as_var(&self) -> Option<Ref> {
|
||||
match self {
|
||||
&Addr::AttrVar(h) => Some(Ref::AttrVar(h)),
|
||||
&Addr::HeapCell(h) => Some(Ref::HeapCell(h)),
|
||||
@@ -202,7 +202,7 @@ impl Addr {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_constant_index(&self, machine_st: &MachineState) -> Option<Constant> {
|
||||
pub(crate) fn as_constant_index(&self, machine_st: &MachineState) -> Option<Constant> {
|
||||
match self {
|
||||
&Addr::Char(c) => Some(Constant::Char(c)),
|
||||
&Addr::Con(h) => match &machine_st.heap[h] {
|
||||
@@ -222,7 +222,7 @@ impl Addr {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_protected(&self, e: usize) -> bool {
|
||||
pub(crate) fn is_protected(&self, e: usize) -> bool {
|
||||
match self {
|
||||
&Addr::StackCell(addr, _) if addr >= e => false,
|
||||
_ => true,
|
||||
@@ -292,7 +292,7 @@ impl SubAssign<usize> for Addr {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum TrailRef {
|
||||
pub(crate) enum TrailRef {
|
||||
Ref(Ref),
|
||||
AttrVarHeapLink(usize),
|
||||
AttrVarListLink(usize, usize),
|
||||
@@ -307,7 +307,7 @@ impl From<Ref> for TrailRef {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum HeapCellValue {
|
||||
pub(crate) enum HeapCellValue {
|
||||
Addr(Addr),
|
||||
Atom(ClauseName, Option<SharedOpDesc>),
|
||||
DBRef(DBRef),
|
||||
@@ -322,13 +322,13 @@ pub enum HeapCellValue {
|
||||
|
||||
impl HeapCellValue {
|
||||
#[inline]
|
||||
pub fn as_addr(&self, focus: usize) -> Addr {
|
||||
pub(crate) fn as_addr(&self, focus: usize) -> Addr {
|
||||
match self {
|
||||
HeapCellValue::Addr(ref a) => *a,
|
||||
HeapCellValue::Atom(..) |
|
||||
HeapCellValue::DBRef(..) |
|
||||
HeapCellValue::Integer(..) |
|
||||
HeapCellValue::Rational(..) => Addr::Con(focus),
|
||||
HeapCellValue::Atom(..)
|
||||
| HeapCellValue::DBRef(..)
|
||||
| HeapCellValue::Integer(..)
|
||||
| HeapCellValue::Rational(..) => Addr::Con(focus),
|
||||
HeapCellValue::LoadStatePayload(_) => Addr::LoadStatePayload(focus),
|
||||
HeapCellValue::NamedStr(_, _, _) => Addr::Str(focus),
|
||||
HeapCellValue::PartialString(..) => Addr::PStrLocation(focus, 0),
|
||||
@@ -338,7 +338,7 @@ impl HeapCellValue {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn context_free_clone(&self) -> HeapCellValue {
|
||||
pub(crate) fn context_free_clone(&self) -> HeapCellValue {
|
||||
match self {
|
||||
&HeapCellValue::Addr(addr) => HeapCellValue::Addr(addr),
|
||||
&HeapCellValue::Atom(ref name, ref op) => HeapCellValue::Atom(name.clone(), op.clone()),
|
||||
@@ -370,7 +370,7 @@ impl From<Addr> for HeapCellValue {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub enum IndexPtr {
|
||||
pub(crate) enum IndexPtr {
|
||||
DynamicUndefined, // a predicate, declared as dynamic, whose location in code is as yet undefined.
|
||||
DynamicIndex(usize),
|
||||
Index(usize),
|
||||
@@ -378,7 +378,7 @@ pub enum IndexPtr {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct CodeIndex(pub Rc<Cell<IndexPtr>>);
|
||||
pub(crate) struct CodeIndex(pub(crate) Rc<Cell<IndexPtr>>);
|
||||
|
||||
impl Deref for CodeIndex {
|
||||
type Target = Cell<IndexPtr>;
|
||||
@@ -396,14 +396,14 @@ impl CodeIndex {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_undefined(&self) -> bool {
|
||||
pub(crate) fn is_undefined(&self) -> bool {
|
||||
match self.0.get() {
|
||||
IndexPtr::Undefined => true, // | &IndexPtr::DynamicUndefined => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn local(&self) -> Option<usize> {
|
||||
pub(crate) fn local(&self) -> Option<usize> {
|
||||
match self.0.get() {
|
||||
IndexPtr::Index(i) => Some(i),
|
||||
IndexPtr::DynamicIndex(i) => Some(i),
|
||||
@@ -419,7 +419,7 @@ impl Default for CodeIndex {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq)]
|
||||
pub enum REPLCodePtr {
|
||||
pub(crate) enum REPLCodePtr {
|
||||
AddDiscontiguousPredicate,
|
||||
AddDynamicPredicate,
|
||||
AddMultifilePredicate,
|
||||
@@ -456,7 +456,7 @@ pub enum REPLCodePtr {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum CodePtr {
|
||||
pub(crate) enum CodePtr {
|
||||
BuiltInClause(BuiltInClauseType, LocalCodePtr), // local is the successor call.
|
||||
CallN(usize, LocalCodePtr, bool), // arity, local, last call.
|
||||
Local(LocalCodePtr),
|
||||
@@ -466,7 +466,7 @@ pub enum CodePtr {
|
||||
}
|
||||
|
||||
impl CodePtr {
|
||||
pub fn local(&self) -> LocalCodePtr {
|
||||
pub(crate) fn local(&self) -> LocalCodePtr {
|
||||
match self {
|
||||
&CodePtr::BuiltInClause(_, ref local)
|
||||
| &CodePtr::CallN(_, ref local, _)
|
||||
@@ -477,7 +477,7 @@ impl CodePtr {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_halt(&self) -> bool {
|
||||
pub(crate) fn is_halt(&self) -> bool {
|
||||
if let CodePtr::Local(LocalCodePtr::Halt) = self {
|
||||
true
|
||||
} else {
|
||||
@@ -487,7 +487,7 @@ impl CodePtr {
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum LocalCodePtr {
|
||||
pub(crate) enum LocalCodePtr {
|
||||
DirEntry(usize), // offset
|
||||
Halt,
|
||||
IndexingBuf(usize, usize, usize), // DirEntry offset, first internal offset, second internal offset
|
||||
@@ -659,22 +659,23 @@ impl SubAssign<usize> for CodePtr {
|
||||
}
|
||||
}
|
||||
|
||||
pub type HeapVarDict = IndexMap<Rc<Var>, Addr>;
|
||||
pub type AllocVarDict = IndexMap<Rc<Var>, VarData>;
|
||||
pub(crate) type HeapVarDict = IndexMap<Rc<Var>, Addr>;
|
||||
pub(crate) type AllocVarDict = IndexMap<Rc<Var>, VarData>;
|
||||
|
||||
pub type GlobalVarDir = IndexMap<ClauseName, (Ball, Option<Addr>)>;
|
||||
pub(crate) type GlobalVarDir = IndexMap<ClauseName, (Ball, Option<Addr>)>;
|
||||
|
||||
pub(crate) type StreamAliasDir = IndexMap<ClauseName, Stream>;
|
||||
pub(crate) type StreamDir = BTreeSet<Stream>;
|
||||
|
||||
pub type MetaPredicateDir = IndexMap<PredicateKey, Vec<MetaSpec>>;
|
||||
pub(crate) type MetaPredicateDir = IndexMap<PredicateKey, Vec<MetaSpec>>;
|
||||
|
||||
pub type ExtensiblePredicates = IndexMap<PredicateKey, PredicateSkeleton>;
|
||||
pub(crate) type ExtensiblePredicates = IndexMap<PredicateKey, PredicateSkeleton>;
|
||||
|
||||
pub type LocalExtensiblePredicates = IndexMap<(CompilationTarget, PredicateKey), PredicateSkeleton>;
|
||||
pub(crate) type LocalExtensiblePredicates =
|
||||
IndexMap<(CompilationTarget, PredicateKey), PredicateSkeleton>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IndexStore {
|
||||
pub(crate) struct IndexStore {
|
||||
pub(super) code_dir: CodeDir,
|
||||
pub(super) extensible_predicates: ExtensiblePredicates,
|
||||
pub(super) local_extensible_predicates: LocalExtensiblePredicates,
|
||||
@@ -694,7 +695,7 @@ impl Default for IndexStore {
|
||||
}
|
||||
|
||||
impl IndexStore {
|
||||
pub fn get_predicate_skeleton_mut(
|
||||
pub(crate) fn get_predicate_skeleton_mut(
|
||||
&mut self,
|
||||
compilation_target: &CompilationTarget,
|
||||
key: &PredicateKey,
|
||||
@@ -714,29 +715,25 @@ impl IndexStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_local_predicate_skeleton_mut(
|
||||
pub(crate) fn get_local_predicate_skeleton_mut(
|
||||
&mut self,
|
||||
src_compilation_target: &CompilationTarget,
|
||||
local_compilation_target: CompilationTarget,
|
||||
key: PredicateKey,
|
||||
) -> Option<&mut PredicateSkeleton> {
|
||||
match (key.0.as_str(), key.1) {
|
||||
("term_expansion", 2) => {
|
||||
self.local_extensible_predicates.get_mut(
|
||||
&(local_compilation_target, key),
|
||||
)
|
||||
}
|
||||
("term_expansion", 2) => self
|
||||
.local_extensible_predicates
|
||||
.get_mut(&(local_compilation_target, key)),
|
||||
_ => match src_compilation_target {
|
||||
CompilationTarget::User => {
|
||||
self.local_extensible_predicates.get_mut(
|
||||
&(local_compilation_target, key),
|
||||
)
|
||||
}
|
||||
CompilationTarget::User => self
|
||||
.local_extensible_predicates
|
||||
.get_mut(&(local_compilation_target, key)),
|
||||
CompilationTarget::Module(ref module_name) => {
|
||||
if let Some(module) = self.modules.get_mut(module_name) {
|
||||
module.local_extensible_predicates.get_mut(
|
||||
&(local_compilation_target, key),
|
||||
)
|
||||
module
|
||||
.local_extensible_predicates
|
||||
.get_mut(&(local_compilation_target, key))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -745,29 +742,25 @@ impl IndexStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_local_predicate_skeleton(
|
||||
pub(crate) fn get_local_predicate_skeleton(
|
||||
&self,
|
||||
src_compilation_target: &CompilationTarget,
|
||||
local_compilation_target: CompilationTarget,
|
||||
key: PredicateKey,
|
||||
) -> Option<&PredicateSkeleton> {
|
||||
match (key.0.as_str(), key.1) {
|
||||
("term_expansion", 2) => {
|
||||
self.local_extensible_predicates.get(
|
||||
&(local_compilation_target, key),
|
||||
)
|
||||
}
|
||||
("term_expansion", 2) => self
|
||||
.local_extensible_predicates
|
||||
.get(&(local_compilation_target, key)),
|
||||
_ => match src_compilation_target {
|
||||
CompilationTarget::User => {
|
||||
self.local_extensible_predicates.get(
|
||||
&(local_compilation_target, key),
|
||||
)
|
||||
}
|
||||
CompilationTarget::User => self
|
||||
.local_extensible_predicates
|
||||
.get(&(local_compilation_target, key)),
|
||||
CompilationTarget::Module(ref module_name) => {
|
||||
if let Some(module) = self.modules.get(module_name) {
|
||||
module.local_extensible_predicates.get(
|
||||
&(local_compilation_target, key),
|
||||
)
|
||||
module
|
||||
.local_extensible_predicates
|
||||
.get(&(local_compilation_target, key))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -776,7 +769,7 @@ impl IndexStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_predicate_skeleton(
|
||||
pub(crate) fn get_predicate_skeleton(
|
||||
&self,
|
||||
compilation_target: &CompilationTarget,
|
||||
key: &PredicateKey,
|
||||
@@ -796,19 +789,15 @@ impl IndexStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_predicate_skeleton(
|
||||
pub(crate) fn remove_predicate_skeleton(
|
||||
&mut self,
|
||||
compilation_target: &CompilationTarget,
|
||||
key: &PredicateKey,
|
||||
) -> Option<PredicateSkeleton> {
|
||||
match (key.0.as_str(), key.1) {
|
||||
("term_expansion", 2) => {
|
||||
self.extensible_predicates.remove(key)
|
||||
}
|
||||
("term_expansion", 2) => self.extensible_predicates.remove(key),
|
||||
_ => match compilation_target {
|
||||
CompilationTarget::User => {
|
||||
self.extensible_predicates.remove(key)
|
||||
}
|
||||
CompilationTarget::User => self.extensible_predicates.remove(key),
|
||||
CompilationTarget::Module(ref module_name) => {
|
||||
if let Some(module) = self.modules.get_mut(module_name) {
|
||||
module.extensible_predicates.remove(key)
|
||||
@@ -820,7 +809,7 @@ impl IndexStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_predicate_code_index(
|
||||
pub(crate) fn get_predicate_code_index(
|
||||
&self,
|
||||
name: ClauseName,
|
||||
arity: usize,
|
||||
@@ -848,7 +837,7 @@ impl IndexStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_meta_predicate_spec(
|
||||
pub(crate) fn get_meta_predicate_spec(
|
||||
&self,
|
||||
name: ClauseName,
|
||||
arity: usize,
|
||||
@@ -866,7 +855,7 @@ impl IndexStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_dynamic_predicate(&self, module_name: ClauseName, key: PredicateKey) -> bool {
|
||||
pub(crate) fn is_dynamic_predicate(&self, module_name: ClauseName, key: PredicateKey) -> bool {
|
||||
match module_name.as_str() {
|
||||
"user" => self
|
||||
.extensible_predicates
|
||||
@@ -911,9 +900,9 @@ impl IndexStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub type CodeDir = BTreeMap<PredicateKey, CodeIndex>;
|
||||
pub(crate) type CodeDir = BTreeMap<PredicateKey, CodeIndex>;
|
||||
|
||||
pub enum RefOrOwned<'a, T: 'a> {
|
||||
pub(crate) enum RefOrOwned<'a, T: 'a> {
|
||||
Borrowed(&'a T),
|
||||
Owned(T),
|
||||
}
|
||||
@@ -928,14 +917,14 @@ impl<'a, T: 'a + fmt::Debug> fmt::Debug for RefOrOwned<'a, T> {
|
||||
}
|
||||
|
||||
impl<'a, T> RefOrOwned<'a, T> {
|
||||
pub fn as_ref(&'a self) -> &'a T {
|
||||
pub(crate) fn as_ref(&'a self) -> &'a T {
|
||||
match self {
|
||||
&RefOrOwned::Borrowed(r) => r,
|
||||
&RefOrOwned::Owned(ref r) => r,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_owned(self) -> T
|
||||
pub(crate) fn to_owned(self) -> T
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ use std::ops::{Index, IndexMut};
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Ball {
|
||||
pub(crate) struct Ball {
|
||||
pub(super) boundary: usize,
|
||||
pub(super) stub: Heap,
|
||||
}
|
||||
@@ -225,7 +225,7 @@ impl IndexMut<RegType> for MachineState {
|
||||
}
|
||||
}
|
||||
|
||||
pub type Registers = Vec<Addr>;
|
||||
pub(crate) type Registers = Vec<Addr>;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(super) enum MachineMode {
|
||||
@@ -276,7 +276,7 @@ pub enum FirstOrNext {
|
||||
}
|
||||
|
||||
// #[derive(Debug)]
|
||||
pub struct MachineState {
|
||||
pub(crate) struct MachineState {
|
||||
pub(crate) atom_tbl: TabledData<Atom>,
|
||||
pub(super) s: HeapPtr,
|
||||
pub(super) p: CodePtr,
|
||||
@@ -347,7 +347,7 @@ impl MachineState {
|
||||
pub(crate) fn read_term(&mut self, mut stream: Stream, indices: &mut IndexStore) -> CallResult {
|
||||
fn push_var_eq_functors<'a>(
|
||||
heap: &mut Heap,
|
||||
iter: impl Iterator<Item=(&'a Rc<Var>, &'a Addr)>,
|
||||
iter: impl Iterator<Item = (&'a Rc<Var>, &'a Addr)>,
|
||||
op_dir: &OpDir,
|
||||
atom_tbl: TabledData<Atom>,
|
||||
) -> Vec<Addr> {
|
||||
@@ -1303,7 +1303,8 @@ impl CallPolicy for CWILCallPolicy {
|
||||
offset: usize,
|
||||
global_variables: &mut GlobalVarDir,
|
||||
) -> CallResult {
|
||||
self.prev_policy.retry_me_else(machine_st, offset, global_variables)?;
|
||||
self.prev_policy
|
||||
.retry_me_else(machine_st, offset, global_variables)?;
|
||||
self.increment(machine_st)
|
||||
}
|
||||
|
||||
@@ -1313,7 +1314,8 @@ impl CallPolicy for CWILCallPolicy {
|
||||
offset: usize,
|
||||
global_variables: &mut GlobalVarDir,
|
||||
) -> CallResult {
|
||||
self.prev_policy.retry(machine_st, offset, global_variables)?;
|
||||
self.prev_policy
|
||||
.retry(machine_st, offset, global_variables)?;
|
||||
self.increment(machine_st)
|
||||
}
|
||||
|
||||
@@ -1332,7 +1334,8 @@ impl CallPolicy for CWILCallPolicy {
|
||||
offset: usize,
|
||||
global_variables: &mut GlobalVarDir,
|
||||
) -> CallResult {
|
||||
self.prev_policy.trust(machine_st, offset, global_variables)?;
|
||||
self.prev_policy
|
||||
.trust(machine_st, offset, global_variables)?;
|
||||
self.increment(machine_st)
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ impl MachineState {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn machine_flags(&self) -> MachineFlags {
|
||||
pub(crate) fn machine_flags(&self) -> MachineFlags {
|
||||
self.flags
|
||||
}
|
||||
|
||||
@@ -590,8 +590,7 @@ impl MachineState {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super)
|
||||
fn trail(&mut self, r: TrailRef) {
|
||||
pub(super) fn trail(&mut self, r: TrailRef) {
|
||||
match r {
|
||||
TrailRef::Ref(Ref::HeapCell(h)) => {
|
||||
if h < self.hb {
|
||||
@@ -3460,14 +3459,20 @@ impl MachineState {
|
||||
}
|
||||
&ChoiceInstruction::DefaultRetryMeElse(offset) => {
|
||||
let mut call_policy = DefaultCallPolicy {};
|
||||
try_or_fail!(self, call_policy.retry_me_else(self, offset, global_variables))
|
||||
try_or_fail!(
|
||||
self,
|
||||
call_policy.retry_me_else(self, offset, global_variables)
|
||||
)
|
||||
}
|
||||
&ChoiceInstruction::DefaultTrustMe(_) => {
|
||||
let mut call_policy = DefaultCallPolicy {};
|
||||
try_or_fail!(self, call_policy.trust_me(self, global_variables))
|
||||
}
|
||||
&ChoiceInstruction::RetryMeElse(offset) => {
|
||||
try_or_fail!(self, call_policy.retry_me_else(self, offset, global_variables))
|
||||
try_or_fail!(
|
||||
self,
|
||||
call_policy.retry_me_else(self, offset, global_variables)
|
||||
)
|
||||
}
|
||||
&ChoiceInstruction::TrustMe(_) => {
|
||||
try_or_fail!(self, call_policy.trust_me(self, global_variables))
|
||||
|
||||
@@ -14,17 +14,17 @@ use crate::read::*;
|
||||
|
||||
mod attributed_variables;
|
||||
pub(super) mod code_repo;
|
||||
pub mod code_walker;
|
||||
pub(crate) mod code_walker;
|
||||
#[macro_use]
|
||||
pub(crate) mod loader;
|
||||
mod compile;
|
||||
mod copier;
|
||||
pub mod heap;
|
||||
pub(crate) mod heap;
|
||||
mod load_state;
|
||||
pub mod machine_errors;
|
||||
pub mod machine_indices;
|
||||
pub(crate) mod machine_errors;
|
||||
pub(crate) mod machine_indices;
|
||||
pub(super) mod machine_state;
|
||||
pub mod partial_string;
|
||||
pub(crate) mod partial_string;
|
||||
mod preprocessor;
|
||||
mod raw_block;
|
||||
mod stack;
|
||||
@@ -42,7 +42,7 @@ use crate::machine::compile::*;
|
||||
use crate::machine::machine_errors::*;
|
||||
use crate::machine::machine_indices::*;
|
||||
use crate::machine::machine_state::*;
|
||||
use crate::machine::streams::*;
|
||||
pub use crate::machine::streams::Stream;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
|
||||
@@ -54,13 +54,13 @@ use std::path::PathBuf;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MachinePolicies {
|
||||
pub(crate) struct MachinePolicies {
|
||||
call_policy: Box<dyn CallPolicy>,
|
||||
cut_policy: Box<dyn CutPolicy>,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref INTERRUPT: AtomicBool = AtomicBool::new(false);
|
||||
pub(crate) static ref INTERRUPT: AtomicBool = AtomicBool::new(false);
|
||||
}
|
||||
|
||||
impl MachinePolicies {
|
||||
@@ -141,7 +141,7 @@ impl Machine {
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
fn load_file(&mut self, path: String, stream: Stream) {
|
||||
pub fn load_file(&mut self, path: String, stream: Stream) {
|
||||
self.machine_st[temp_v!(1)] =
|
||||
Addr::Stream(self.machine_st.heap.push(HeapCellValue::Stream(stream)));
|
||||
|
||||
@@ -224,7 +224,7 @@ impl Machine {
|
||||
self.run_module_predicate(clause_name!("$toplevel"), (clause_name!("$repl"), 1));
|
||||
}
|
||||
|
||||
fn configure_modules(&mut self) {
|
||||
pub(crate) fn configure_modules(&mut self) {
|
||||
fn update_call_n_indices(loader: &Module, target_code_dir: &mut CodeDir) {
|
||||
for arity in 1..66 {
|
||||
let key = (clause_name!("call"), arity);
|
||||
@@ -358,7 +358,7 @@ impl Machine {
|
||||
wam
|
||||
}
|
||||
|
||||
pub fn configure_streams(&mut self) {
|
||||
pub(crate) fn configure_streams(&mut self) {
|
||||
self.user_input.options_mut().alias = Some(clause_name!("user_input"));
|
||||
|
||||
self.indices
|
||||
@@ -493,7 +493,7 @@ impl Machine {
|
||||
self.machine_st.p = CodePtr::Local(p);
|
||||
}
|
||||
|
||||
pub(super) fn run_query(&mut self) {
|
||||
pub(crate) fn run_query(&mut self) {
|
||||
while !self.machine_st.p.is_halt() {
|
||||
self.machine_st.query_stepper(
|
||||
&mut self.indices,
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
use crate::machine::*;
|
||||
use crate::machine::machine_indices::*;
|
||||
use crate::machine::*;
|
||||
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use std::alloc;
|
||||
use std::cmp::Ordering;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::ops::RangeFrom;
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
use std::str;
|
||||
|
||||
use indexmap::IndexSet;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PartialString {
|
||||
pub(crate) struct PartialString {
|
||||
buf: *const u8,
|
||||
len: usize,
|
||||
_marker: PhantomData<[u8]>,
|
||||
@@ -54,7 +54,7 @@ fn scan_for_terminator<Iter: Iterator<Item = char>>(iter: Iter) -> usize {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PStrIter {
|
||||
pub(crate) struct PStrIter {
|
||||
buf: *const u8,
|
||||
len: usize,
|
||||
}
|
||||
@@ -91,17 +91,14 @@ impl Iterator for PStrIter {
|
||||
|
||||
impl PartialString {
|
||||
#[inline]
|
||||
pub(super)
|
||||
fn new(src: &str) -> Option<(Self, &str)> {
|
||||
pub(super) fn new(src: &str) -> Option<(Self, &str)> {
|
||||
let pstr = PartialString {
|
||||
buf: ptr::null_mut(),
|
||||
len: 0,
|
||||
_marker: PhantomData,
|
||||
};
|
||||
|
||||
unsafe {
|
||||
pstr.append_chars(src)
|
||||
}
|
||||
unsafe { pstr.append_chars(src) }
|
||||
}
|
||||
|
||||
unsafe fn append_chars(mut self, src: &str) -> Option<(Self, &str)> {
|
||||
@@ -115,29 +112,23 @@ impl PartialString {
|
||||
self.buf = alloc::alloc(layout) as *const _;
|
||||
self.len = terminator_idx + '\u{0}'.len_utf8();
|
||||
|
||||
ptr::copy(
|
||||
src.as_ptr(),
|
||||
self.buf as *mut _,
|
||||
terminator_idx,
|
||||
);
|
||||
ptr::copy(src.as_ptr(), self.buf as *mut _, terminator_idx);
|
||||
|
||||
self.write_terminator_at(terminator_idx);
|
||||
|
||||
Some(if terminator_idx != src.as_bytes().len() {
|
||||
(self, &src[terminator_idx ..])
|
||||
(self, &src[terminator_idx..])
|
||||
} else {
|
||||
(self, "")
|
||||
})
|
||||
}
|
||||
|
||||
pub(super)
|
||||
fn clone_from_offset(&self, n: usize) -> Self {
|
||||
let len =
|
||||
if self.len - '\u{0}'.len_utf8() > n {
|
||||
self.len - n - '\u{0}'.len_utf8()
|
||||
} else {
|
||||
0
|
||||
};
|
||||
pub(super) fn clone_from_offset(&self, n: usize) -> Self {
|
||||
let len = if self.len - '\u{0}'.len_utf8() > n {
|
||||
self.len - n - '\u{0}'.len_utf8()
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let mut pstr = PartialString {
|
||||
buf: ptr::null_mut(),
|
||||
@@ -168,18 +159,14 @@ impl PartialString {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(super)
|
||||
fn write_terminator_at(&mut self, index: usize) {
|
||||
pub(super) fn write_terminator_at(&mut self, index: usize) {
|
||||
unsafe {
|
||||
ptr::write(
|
||||
(self.buf as usize + index) as *mut u8,
|
||||
0u8,
|
||||
);
|
||||
ptr::write((self.buf as usize + index) as *mut u8, 0u8);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn range_from(&self, index: RangeFrom<usize>) -> PStrIter {
|
||||
pub(crate) fn range_from(&self, index: RangeFrom<usize>) -> PStrIter {
|
||||
if self.len >= '\u{0}'.len_utf8() {
|
||||
PStrIter::from(self.buf, self.len - '\u{0}'.len_utf8(), index.start)
|
||||
} else {
|
||||
@@ -188,21 +175,18 @@ impl PartialString {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn at_end(&self, end_n: usize) -> bool {
|
||||
pub(crate) fn at_end(&self, end_n: usize) -> bool {
|
||||
end_n + 1 == self.len
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_str_from(&self, n: usize) -> &str {
|
||||
pub(crate) fn as_str_from(&self, n: usize) -> &str {
|
||||
unsafe {
|
||||
let slice = slice::from_raw_parts(
|
||||
self.buf,
|
||||
self.len - '\u{0}'.len_utf8(),
|
||||
);
|
||||
let slice = slice::from_raw_parts(self.buf, self.len - '\u{0}'.len_utf8());
|
||||
|
||||
let s = str::from_utf8(slice).unwrap();
|
||||
|
||||
&s[n ..]
|
||||
&s[n..]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -216,8 +200,7 @@ pub(crate) struct HeapPStrIter<'a> {
|
||||
|
||||
impl<'a> HeapPStrIter<'a> {
|
||||
#[inline]
|
||||
pub(super)
|
||||
fn new(machine_st: &'a MachineState, focus: Addr) -> Self {
|
||||
pub(super) fn new(machine_st: &'a MachineState, focus: Addr) -> Self {
|
||||
HeapPStrIter {
|
||||
focus,
|
||||
machine_st,
|
||||
@@ -226,14 +209,12 @@ impl<'a> HeapPStrIter<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate)
|
||||
fn focus(&self) -> Addr {
|
||||
pub(crate) fn focus(&self) -> Addr {
|
||||
self.machine_st.store(self.machine_st.deref(self.focus))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate)
|
||||
fn to_string(&mut self) -> String {
|
||||
pub(crate) fn to_string(&mut self) -> String {
|
||||
let mut buf = String::new();
|
||||
|
||||
while let Some(iteratee) = self.next() {
|
||||
@@ -241,16 +222,14 @@ impl<'a> HeapPStrIter<'a> {
|
||||
PStrIteratee::Char(c) => {
|
||||
buf.push(c);
|
||||
}
|
||||
PStrIteratee::PStrSegment(h, n) => {
|
||||
match &self.machine_st.heap[h] {
|
||||
HeapCellValue::PartialString(ref pstr, _) => {
|
||||
buf += pstr.as_str_from(n);
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
PStrIteratee::PStrSegment(h, n) => match &self.machine_st.heap[h] {
|
||||
HeapCellValue::PartialString(ref pstr, _) => {
|
||||
buf += pstr.as_str_from(n);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +270,9 @@ impl<'a> Iterator for HeapPStrIter<'a> {
|
||||
}
|
||||
}
|
||||
Addr::Lis(l) => {
|
||||
let addr = self.machine_st.store(self.machine_st.deref(Addr::HeapCell(l)));
|
||||
let addr = self
|
||||
.machine_st
|
||||
.store(self.machine_st.deref(Addr::HeapCell(l)));
|
||||
|
||||
let opt_c = match addr {
|
||||
Addr::Con(h) if self.machine_st.heap.atom_at(h) => {
|
||||
@@ -305,12 +286,8 @@ impl<'a> Iterator for HeapPStrIter<'a> {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
Addr::Char(c) => {
|
||||
Some(c)
|
||||
}
|
||||
_ => {
|
||||
None
|
||||
}
|
||||
Addr::Char(c) => Some(c),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(c) = opt_c {
|
||||
@@ -332,8 +309,7 @@ impl<'a> Iterator for HeapPStrIter<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(super)
|
||||
fn compare_pstr_prefixes<'a>(
|
||||
pub(super) fn compare_pstr_prefixes<'a>(
|
||||
i1: &mut HeapPStrIter<'a>,
|
||||
i2: &mut HeapPStrIter<'a>,
|
||||
) -> Option<Ordering> {
|
||||
@@ -425,25 +401,16 @@ fn compare_pstr_prefixes<'a>(
|
||||
}
|
||||
|
||||
return match (i1.focus(), i2.focus()) {
|
||||
(Addr::EmptyList, Addr::EmptyList) => {
|
||||
Some(Ordering::Equal)
|
||||
}
|
||||
(Addr::EmptyList, _) => {
|
||||
Some(Ordering::Less)
|
||||
}
|
||||
(_, Addr::EmptyList) => {
|
||||
Some(Ordering::Greater)
|
||||
}
|
||||
_ => {
|
||||
None
|
||||
}
|
||||
(Addr::EmptyList, Addr::EmptyList) => Some(Ordering::Equal),
|
||||
(Addr::EmptyList, _) => Some(Ordering::Less),
|
||||
(_, Addr::EmptyList) => Some(Ordering::Greater),
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(super)
|
||||
fn compare_pstr_to_string<'a>(
|
||||
pub(super) fn compare_pstr_to_string<'a>(
|
||||
heap_pstr_iter: &mut HeapPStrIter<'a>,
|
||||
s: &String,
|
||||
) -> Option<usize> {
|
||||
@@ -452,7 +419,7 @@ fn compare_pstr_to_string<'a>(
|
||||
while let Some(iteratee) = heap_pstr_iter.next() {
|
||||
match iteratee {
|
||||
PStrIteratee::Char(c1) => {
|
||||
if let Some(c2) = s[s_offset ..].chars().next() {
|
||||
if let Some(c2) = s[s_offset..].chars().next() {
|
||||
if c1 != c2 {
|
||||
return None;
|
||||
} else {
|
||||
@@ -462,31 +429,28 @@ fn compare_pstr_to_string<'a>(
|
||||
return Some(s_offset);
|
||||
}
|
||||
}
|
||||
PStrIteratee::PStrSegment(h, n) => {
|
||||
match heap_pstr_iter.machine_st.heap[h] {
|
||||
HeapCellValue::PartialString(ref pstr, _) => {
|
||||
let t = pstr.as_str_from(n);
|
||||
PStrIteratee::PStrSegment(h, n) => match heap_pstr_iter.machine_st.heap[h] {
|
||||
HeapCellValue::PartialString(ref pstr, _) => {
|
||||
let t = pstr.as_str_from(n);
|
||||
|
||||
if s[s_offset ..].starts_with(t) {
|
||||
s_offset += t.len();
|
||||
} else if t.starts_with(&s[s_offset ..]) {
|
||||
heap_pstr_iter.focus =
|
||||
Addr::PStrLocation(h, n + s[s_offset ..].len());
|
||||
if s[s_offset..].starts_with(t) {
|
||||
s_offset += t.len();
|
||||
} else if t.starts_with(&s[s_offset..]) {
|
||||
heap_pstr_iter.focus = Addr::PStrLocation(h, n + s[s_offset..].len());
|
||||
|
||||
s_offset += s[s_offset ..].len();
|
||||
return Some(s_offset);
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
s_offset += s[s_offset..].len();
|
||||
return Some(s_offset);
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
if s[s_offset ..].is_empty() {
|
||||
if s[s_offset..].is_empty() {
|
||||
return Some(s_offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ pub(crate) enum CutContext {
|
||||
HasCutVariable,
|
||||
}
|
||||
|
||||
pub fn fold_by_str<I>(terms: I, mut term: Term, sym: ClauseName) -> Term
|
||||
pub(crate) fn fold_by_str<I>(terms: I, mut term: Term, sym: ClauseName) -> Term
|
||||
where
|
||||
I: DoubleEndedIterator<Item = Term>,
|
||||
{
|
||||
@@ -46,7 +46,11 @@ where
|
||||
term
|
||||
}
|
||||
|
||||
pub fn to_op_decl(prec: usize, spec: &str, name: ClauseName) -> Result<OpDecl, CompilationError> {
|
||||
pub(crate) fn to_op_decl(
|
||||
prec: usize,
|
||||
spec: &str,
|
||||
name: ClauseName,
|
||||
) -> Result<OpDecl, CompilationError> {
|
||||
match spec {
|
||||
"xfx" => Ok(OpDecl::new(prec, XFX, name)),
|
||||
"xfy" => Ok(OpDecl::new(prec, XFY, name)),
|
||||
@@ -825,11 +829,7 @@ impl Preprocessor {
|
||||
cut_context: CutContext,
|
||||
) -> Result<Rule, CompilationError> {
|
||||
let post_head_terms: Vec<_> = terms.drain(1..).collect();
|
||||
let mut query_terms = self.setup_query(
|
||||
load_state,
|
||||
post_head_terms,
|
||||
cut_context,
|
||||
)?;
|
||||
let mut query_terms = self.setup_query(load_state, post_head_terms, cut_context)?;
|
||||
|
||||
let clauses = query_terms.drain(1..).collect();
|
||||
let qt = query_terms.pop().unwrap();
|
||||
@@ -894,11 +894,7 @@ impl Preprocessor {
|
||||
let mut results = VecDeque::new();
|
||||
|
||||
for term in terms.into_iter() {
|
||||
results.push_back(self.try_term_to_tl(
|
||||
load_state,
|
||||
term,
|
||||
cut_context,
|
||||
)?);
|
||||
results.push_back(self.try_term_to_tl(load_state, term, cut_context)?);
|
||||
}
|
||||
|
||||
Ok(results)
|
||||
|
||||
@@ -23,9 +23,7 @@ impl RawBlockTraits for StackTraits {
|
||||
|
||||
#[inline]
|
||||
fn base_offset(base: *const u8) -> *const u8 {
|
||||
unsafe {
|
||||
base.offset(Self::align() as isize)
|
||||
}
|
||||
unsafe { base.offset(Self::align() as isize) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +35,7 @@ const fn prelude_size<Prelude>() -> usize {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Stack {
|
||||
pub(crate) struct Stack {
|
||||
buf: RawBlock<StackTraits>,
|
||||
_marker: PhantomData<Addr>,
|
||||
}
|
||||
@@ -50,25 +48,25 @@ impl Drop for Stack {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct FramePrelude {
|
||||
pub num_cells: usize,
|
||||
pub(crate) struct FramePrelude {
|
||||
pub(crate) num_cells: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AndFramePrelude {
|
||||
pub univ_prelude: FramePrelude,
|
||||
pub e: usize,
|
||||
pub cp: LocalCodePtr,
|
||||
pub interrupt_cp: LocalCodePtr,
|
||||
pub(crate) struct AndFramePrelude {
|
||||
pub(crate) univ_prelude: FramePrelude,
|
||||
pub(crate) e: usize,
|
||||
pub(crate) cp: LocalCodePtr,
|
||||
pub(crate) interrupt_cp: LocalCodePtr,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AndFrame {
|
||||
pub prelude: AndFramePrelude,
|
||||
pub(crate) struct AndFrame {
|
||||
pub(crate) prelude: AndFramePrelude,
|
||||
}
|
||||
|
||||
impl AndFrame {
|
||||
pub fn size_of(num_cells: usize) -> usize {
|
||||
pub(crate) fn size_of(num_cells: usize) -> usize {
|
||||
prelude_size::<AndFramePrelude>() + num_cells * mem::size_of::<Addr>()
|
||||
}
|
||||
}
|
||||
@@ -104,23 +102,23 @@ impl IndexMut<usize> for AndFrame {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OrFramePrelude {
|
||||
pub univ_prelude: FramePrelude,
|
||||
pub e: usize,
|
||||
pub cp: LocalCodePtr,
|
||||
pub b: usize,
|
||||
pub bp: LocalCodePtr,
|
||||
pub tr: usize,
|
||||
pub pstr_tr: usize,
|
||||
pub h: usize,
|
||||
pub b0: usize,
|
||||
pub attr_var_init_queue_b: usize,
|
||||
pub attr_var_init_bindings_b: usize,
|
||||
pub(crate) struct OrFramePrelude {
|
||||
pub(crate) univ_prelude: FramePrelude,
|
||||
pub(crate) e: usize,
|
||||
pub(crate) cp: LocalCodePtr,
|
||||
pub(crate) b: usize,
|
||||
pub(crate) bp: LocalCodePtr,
|
||||
pub(crate) tr: usize,
|
||||
pub(crate) pstr_tr: usize,
|
||||
pub(crate) h: usize,
|
||||
pub(crate) b0: usize,
|
||||
pub(crate) attr_var_init_queue_b: usize,
|
||||
pub(crate) attr_var_init_bindings_b: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OrFrame {
|
||||
pub prelude: OrFramePrelude,
|
||||
pub(crate) struct OrFrame {
|
||||
pub(crate) prelude: OrFramePrelude,
|
||||
}
|
||||
|
||||
impl Index<usize> for OrFrame {
|
||||
@@ -156,24 +154,27 @@ impl IndexMut<usize> for OrFrame {
|
||||
}
|
||||
|
||||
impl OrFrame {
|
||||
pub fn size_of(num_cells: usize) -> usize {
|
||||
pub(crate) fn size_of(num_cells: usize) -> usize {
|
||||
prelude_size::<OrFramePrelude>() + num_cells * mem::size_of::<Addr>()
|
||||
}
|
||||
}
|
||||
|
||||
impl Stack {
|
||||
pub fn new() -> Self {
|
||||
Stack { buf: RawBlock::new(), _marker: PhantomData }
|
||||
pub(crate) fn new() -> Self {
|
||||
Stack {
|
||||
buf: RawBlock::new(),
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn allocate_and_frame(&mut self, num_cells: usize) -> usize {
|
||||
pub(crate) fn allocate_and_frame(&mut self, num_cells: usize) -> usize {
|
||||
let frame_size = AndFrame::size_of(num_cells);
|
||||
|
||||
unsafe {
|
||||
let new_top = self.buf.new_block(frame_size);
|
||||
let e = self.buf.top as usize - self.buf.base as usize;
|
||||
|
||||
for idx in 0 .. num_cells {
|
||||
for idx in 0..num_cells {
|
||||
let offset = prelude_size::<AndFramePrelude>() + idx * mem::size_of::<Addr>();
|
||||
ptr::write(
|
||||
(self.buf.top as usize + offset) as *mut Addr,
|
||||
@@ -190,14 +191,14 @@ impl Stack {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn allocate_or_frame(&mut self, num_cells: usize) -> usize {
|
||||
pub(crate) fn allocate_or_frame(&mut self, num_cells: usize) -> usize {
|
||||
let frame_size = OrFrame::size_of(num_cells);
|
||||
|
||||
unsafe {
|
||||
let new_top = self.buf.new_block(frame_size);
|
||||
let b = self.buf.top as usize - self.buf.base as usize;
|
||||
|
||||
for idx in 0 .. num_cells {
|
||||
for idx in 0..num_cells {
|
||||
let offset = prelude_size::<OrFramePrelude>() + idx * mem::size_of::<Addr>();
|
||||
ptr::write(
|
||||
(self.buf.top as usize + offset) as *mut Addr,
|
||||
@@ -215,7 +216,7 @@ impl Stack {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn index_and_frame(&self, e: usize) -> &AndFrame {
|
||||
pub(crate) fn index_and_frame(&self, e: usize) -> &AndFrame {
|
||||
unsafe {
|
||||
let ptr = self.buf.base as usize + e;
|
||||
&*(ptr as *const AndFrame)
|
||||
@@ -223,7 +224,7 @@ impl Stack {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn index_and_frame_mut(&mut self, e: usize) -> &mut AndFrame {
|
||||
pub(crate) fn index_and_frame_mut(&mut self, e: usize) -> &mut AndFrame {
|
||||
unsafe {
|
||||
let ptr = self.buf.base as usize + e;
|
||||
&mut *(ptr as *mut AndFrame)
|
||||
@@ -231,7 +232,7 @@ impl Stack {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn index_or_frame(&self, b: usize) -> &OrFrame {
|
||||
pub(crate) fn index_or_frame(&self, b: usize) -> &OrFrame {
|
||||
unsafe {
|
||||
let ptr = self.buf.base as usize + b;
|
||||
&*(ptr as *const OrFrame)
|
||||
@@ -239,7 +240,7 @@ impl Stack {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn index_or_frame_mut(&mut self, b: usize) -> &mut OrFrame {
|
||||
pub(crate) fn index_or_frame_mut(&mut self, b: usize) -> &mut OrFrame {
|
||||
unsafe {
|
||||
let ptr = self.buf.base as usize + b;
|
||||
&mut *(ptr as *mut OrFrame)
|
||||
@@ -247,7 +248,7 @@ impl Stack {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn truncate(&mut self, b: usize) {
|
||||
pub(crate) fn truncate(&mut self, b: usize) {
|
||||
if b == 0 {
|
||||
self.inner_truncate(mem::align_of::<Addr>());
|
||||
} else {
|
||||
@@ -264,7 +265,7 @@ impl Stack {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn drop_in_place(&mut self) {
|
||||
pub(crate) fn drop_in_place(&mut self) {
|
||||
self.truncate(mem::align_of::<Addr>());
|
||||
|
||||
debug_assert!(if self.buf.top.is_null() {
|
||||
|
||||
@@ -23,7 +23,7 @@ use std::rc::Rc;
|
||||
use native_tls::TlsStream;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum StreamType {
|
||||
pub(crate) enum StreamType {
|
||||
Binary,
|
||||
Text,
|
||||
}
|
||||
@@ -55,14 +55,14 @@ impl StreamType {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum EOFAction {
|
||||
pub(crate) enum EOFAction {
|
||||
EOFCode,
|
||||
Error,
|
||||
Reset,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum AtEndOfStream {
|
||||
pub(crate) enum AtEndOfStream {
|
||||
Not,
|
||||
At,
|
||||
Past,
|
||||
@@ -198,7 +198,7 @@ impl fmt::Debug for StreamInstance {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct InnerStream {
|
||||
pub(crate) struct InnerStream {
|
||||
options: StreamOptions,
|
||||
stream_inst: StreamInstance,
|
||||
past_end_of_stream: bool,
|
||||
@@ -211,14 +211,12 @@ struct WrappedStreamInstance(Rc<RefCell<InnerStream>>);
|
||||
impl WrappedStreamInstance {
|
||||
#[inline]
|
||||
fn new(stream_inst: StreamInstance, past_end_of_stream: bool) -> Self {
|
||||
WrappedStreamInstance(Rc::new(RefCell::new(
|
||||
InnerStream {
|
||||
options: StreamOptions::default(),
|
||||
stream_inst,
|
||||
past_end_of_stream,
|
||||
lines_read: 0,
|
||||
}
|
||||
)))
|
||||
WrappedStreamInstance(Rc::new(RefCell::new(InnerStream {
|
||||
options: StreamOptions::default(),
|
||||
stream_inst,
|
||||
past_end_of_stream,
|
||||
lines_read: 0,
|
||||
})))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,11 +285,11 @@ impl fmt::Display for StreamError {
|
||||
impl Error for StreamError {}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct StreamOptions {
|
||||
pub stream_type: StreamType,
|
||||
pub reposition: bool,
|
||||
pub alias: Option<ClauseName>,
|
||||
pub eof_action: EOFAction,
|
||||
pub(crate) struct StreamOptions {
|
||||
pub(crate) stream_type: StreamType,
|
||||
pub(crate) reposition: bool,
|
||||
pub(crate) alias: Option<ClauseName>,
|
||||
pub(crate) eof_action: EOFAction,
|
||||
}
|
||||
|
||||
impl Default for StreamOptions {
|
||||
@@ -366,6 +364,23 @@ impl Stream {
|
||||
ptr as *const u8
|
||||
}
|
||||
|
||||
pub fn bytes(&self) -> Option<std::cell::Ref<Vec<u8>>> {
|
||||
// if Ref had an and_then function this could be simplified
|
||||
let val = std::cell::Ref::map(self.stream_inst.0.borrow(), |inner_stream| {
|
||||
&inner_stream.stream_inst
|
||||
});
|
||||
match std::ops::Deref::deref(&val) {
|
||||
StreamInstance::Bytes(_) => Some(std::cell::Ref::map(
|
||||
std::cell::Ref::clone(&val),
|
||||
|instance| match instance {
|
||||
StreamInstance::Bytes(cursor) => cursor.get_ref(),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn lines_read(&mut self) -> usize {
|
||||
self.stream_inst.0.borrow_mut().lines_read
|
||||
@@ -378,30 +393,29 @@ impl Stream {
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn options(&self) -> std::cell::Ref<'_, StreamOptions> {
|
||||
std::cell::Ref::map(
|
||||
self.stream_inst.0.borrow(),
|
||||
|inner_stream| &inner_stream.options,
|
||||
)
|
||||
std::cell::Ref::map(self.stream_inst.0.borrow(), |inner_stream| {
|
||||
&inner_stream.options
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn options_mut(&mut self) -> std::cell::RefMut<'_, StreamOptions> {
|
||||
std::cell::RefMut::map(
|
||||
self.stream_inst.0.borrow_mut(),
|
||||
|inner_stream| &mut inner_stream.options,
|
||||
)
|
||||
std::cell::RefMut::map(self.stream_inst.0.borrow_mut(), |inner_stream| {
|
||||
&mut inner_stream.options
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn position(&mut self) -> Option<(u64, usize)> { // returns lines_read, position.
|
||||
pub(crate) fn position(&mut self) -> Option<(u64, usize)> {
|
||||
// returns lines_read, position.
|
||||
let result = match self.stream_inst.0.borrow_mut().stream_inst {
|
||||
StreamInstance::InputFile(_, ref mut file) => file.seek(SeekFrom::Current(0)).ok(),
|
||||
StreamInstance::TcpStream(..) |
|
||||
StreamInstance::TlsStream(..) |
|
||||
StreamInstance::ReadlineStream(..) |
|
||||
StreamInstance::StaticStr(..) |
|
||||
StreamInstance::PausedPrologStream(..) |
|
||||
StreamInstance::Bytes(..) => Some(0),
|
||||
StreamInstance::TcpStream(..)
|
||||
| StreamInstance::TlsStream(..)
|
||||
| StreamInstance::ReadlineStream(..)
|
||||
| StreamInstance::StaticStr(..)
|
||||
| StreamInstance::PausedPrologStream(..)
|
||||
| StreamInstance::Bytes(..) => Some(0),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
@@ -411,9 +425,11 @@ impl Stream {
|
||||
#[inline]
|
||||
pub(crate) fn set_position(&mut self, position: u64) {
|
||||
match self.stream_inst.0.borrow_mut().deref_mut() {
|
||||
InnerStream { past_end_of_stream,
|
||||
stream_inst: StreamInstance::InputFile(_, ref mut file),
|
||||
.. } => {
|
||||
InnerStream {
|
||||
past_end_of_stream,
|
||||
stream_inst: StreamInstance::InputFile(_, ref mut file),
|
||||
..
|
||||
} => {
|
||||
file.seek(SeekFrom::Start(position)).unwrap();
|
||||
|
||||
if let Ok(metadata) = file.metadata() {
|
||||
@@ -446,31 +462,31 @@ impl Stream {
|
||||
}
|
||||
|
||||
match self.stream_inst.0.borrow_mut().deref_mut() {
|
||||
InnerStream { past_end_of_stream,
|
||||
stream_inst: StreamInstance::InputFile(_, ref mut file),
|
||||
.. } => {
|
||||
match file.metadata() {
|
||||
Ok(metadata) => {
|
||||
if let Ok(position) = file.seek(SeekFrom::Current(0)) {
|
||||
return match position.cmp(&metadata.len()) {
|
||||
Ordering::Equal => AtEndOfStream::At,
|
||||
Ordering::Less => AtEndOfStream::Not,
|
||||
Ordering::Greater => {
|
||||
*past_end_of_stream = true;
|
||||
AtEndOfStream::Past
|
||||
}
|
||||
};
|
||||
} else {
|
||||
*past_end_of_stream = true;
|
||||
AtEndOfStream::Past
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
InnerStream {
|
||||
past_end_of_stream,
|
||||
stream_inst: StreamInstance::InputFile(_, ref mut file),
|
||||
..
|
||||
} => match file.metadata() {
|
||||
Ok(metadata) => {
|
||||
if let Ok(position) = file.seek(SeekFrom::Current(0)) {
|
||||
return match position.cmp(&metadata.len()) {
|
||||
Ordering::Equal => AtEndOfStream::At,
|
||||
Ordering::Less => AtEndOfStream::Not,
|
||||
Ordering::Greater => {
|
||||
*past_end_of_stream = true;
|
||||
AtEndOfStream::Past
|
||||
}
|
||||
};
|
||||
} else {
|
||||
*past_end_of_stream = true;
|
||||
AtEndOfStream::Past
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
*past_end_of_stream = true;
|
||||
AtEndOfStream::Past
|
||||
}
|
||||
},
|
||||
_ => AtEndOfStream::Not,
|
||||
}
|
||||
}
|
||||
@@ -488,11 +504,11 @@ impl Stream {
|
||||
#[inline]
|
||||
pub(crate) fn mode(&self) -> &'static str {
|
||||
match self.stream_inst.0.borrow().stream_inst {
|
||||
StreamInstance::Bytes(_) |
|
||||
StreamInstance::PausedPrologStream(..) |
|
||||
StreamInstance::ReadlineStream(_) |
|
||||
StreamInstance::StaticStr(_) |
|
||||
StreamInstance::InputFile(..) => "read",
|
||||
StreamInstance::Bytes(_)
|
||||
| StreamInstance::PausedPrologStream(..)
|
||||
| StreamInstance::ReadlineStream(_)
|
||||
| StreamInstance::StaticStr(_)
|
||||
| StreamInstance::InputFile(..) => "read",
|
||||
StreamInstance::TcpStream(..) | StreamInstance::TlsStream(..) => "read_append",
|
||||
StreamInstance::OutputFile(_, _, true) => "append",
|
||||
StreamInstance::Stdout | StreamInstance::OutputFile(_, _, false) => "write",
|
||||
@@ -508,7 +524,7 @@ impl Stream {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn stdout() -> Self {
|
||||
pub fn stdout() -> Self {
|
||||
Stream::from_inst(StreamInstance::Stdout)
|
||||
}
|
||||
|
||||
@@ -568,13 +584,13 @@ impl Stream {
|
||||
#[inline]
|
||||
pub(crate) fn is_input_stream(&self) -> bool {
|
||||
match self.stream_inst.0.borrow().stream_inst {
|
||||
StreamInstance::TcpStream(..) |
|
||||
StreamInstance::TlsStream(..) |
|
||||
StreamInstance::Bytes(_) |
|
||||
StreamInstance::PausedPrologStream(..) |
|
||||
StreamInstance::ReadlineStream(_) |
|
||||
StreamInstance::StaticStr(_) |
|
||||
StreamInstance::InputFile(..) => true,
|
||||
StreamInstance::TcpStream(..)
|
||||
| StreamInstance::TlsStream(..)
|
||||
| StreamInstance::Bytes(_)
|
||||
| StreamInstance::PausedPrologStream(..)
|
||||
| StreamInstance::ReadlineStream(_)
|
||||
| StreamInstance::StaticStr(_)
|
||||
| StreamInstance::InputFile(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -582,11 +598,11 @@ impl Stream {
|
||||
#[inline]
|
||||
pub(crate) fn is_output_stream(&self) -> bool {
|
||||
match self.stream_inst.0.borrow().stream_inst {
|
||||
StreamInstance::Stdout |
|
||||
StreamInstance::TcpStream(..) |
|
||||
StreamInstance::TlsStream(..) |
|
||||
StreamInstance::Bytes(_) |
|
||||
StreamInstance::OutputFile(..) => true,
|
||||
StreamInstance::Stdout
|
||||
| StreamInstance::TcpStream(..)
|
||||
| StreamInstance::TlsStream(..)
|
||||
| StreamInstance::Bytes(_)
|
||||
| StreamInstance::OutputFile(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -1084,11 +1100,11 @@ impl Write for Stream {
|
||||
StreamInstance::TlsStream(_, ref mut tls_stream) => tls_stream.write(buf),
|
||||
StreamInstance::Bytes(ref mut cursor) => cursor.write(buf),
|
||||
StreamInstance::Stdout => stdout().write(buf),
|
||||
StreamInstance::PausedPrologStream(..) |
|
||||
StreamInstance::StaticStr(_) |
|
||||
StreamInstance::ReadlineStream(_) |
|
||||
StreamInstance::InputFile(..) |
|
||||
StreamInstance::Null => Err(std::io::Error::new(
|
||||
StreamInstance::PausedPrologStream(..)
|
||||
| StreamInstance::StaticStr(_)
|
||||
| StreamInstance::ReadlineStream(_)
|
||||
| StreamInstance::InputFile(..)
|
||||
| StreamInstance::Null => Err(std::io::Error::new(
|
||||
ErrorKind::PermissionDenied,
|
||||
StreamError::WriteToInputStream,
|
||||
)),
|
||||
@@ -1102,11 +1118,11 @@ impl Write for Stream {
|
||||
StreamInstance::TlsStream(_, ref mut tls_stream) => tls_stream.flush(),
|
||||
StreamInstance::Bytes(ref mut cursor) => cursor.flush(),
|
||||
StreamInstance::Stdout => stdout().flush(),
|
||||
StreamInstance::PausedPrologStream(..) |
|
||||
StreamInstance::StaticStr(_) |
|
||||
StreamInstance::ReadlineStream(_) |
|
||||
StreamInstance::InputFile(..) |
|
||||
StreamInstance::Null => Err(std::io::Error::new(
|
||||
StreamInstance::PausedPrologStream(..)
|
||||
| StreamInstance::StaticStr(_)
|
||||
| StreamInstance::ReadlineStream(_)
|
||||
| StreamInstance::InputFile(..)
|
||||
| StreamInstance::Null => Err(std::io::Error::new(
|
||||
ErrorKind::PermissionDenied,
|
||||
StreamError::FlushToInputStream,
|
||||
)),
|
||||
|
||||
@@ -71,7 +71,7 @@ use base64;
|
||||
use roxmltree;
|
||||
use select;
|
||||
|
||||
pub fn get_key() -> KeyEvent {
|
||||
pub(crate) fn get_key() -> KeyEvent {
|
||||
let key;
|
||||
enable_raw_mode().expect("failed to enable raw mode");
|
||||
loop {
|
||||
|
||||
@@ -78,7 +78,7 @@ impl<'a> TermStream for BootstrappingTermStream<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LiveTermStream {
|
||||
pub(crate) struct LiveTermStream {
|
||||
pub(super) term_queue: VecDeque<Term>,
|
||||
pub(super) listing_src: ListingSource,
|
||||
}
|
||||
@@ -93,7 +93,7 @@ impl LiveTermStream {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LoadStatePayload {
|
||||
pub(crate) struct LoadStatePayload {
|
||||
pub(super) term_stream: LiveTermStream,
|
||||
pub(super) compilation_target: CompilationTarget,
|
||||
pub(super) retraction_info: RetractionInfo,
|
||||
|
||||
Reference in New Issue
Block a user