remove partial strings, but represent strings as lists when warranted by double_quotes

This commit is contained in:
Mark Thom
2020-02-12 22:12:42 -07:00
parent 1b5cf493d6
commit 969bd8f82c
19 changed files with 428 additions and 844 deletions

View File

@@ -1,5 +1,3 @@
use prolog_parser::ast::MachineFlags;
use crate::prolog::clause_types::*;
use crate::prolog::codegen::*;
use crate::prolog::debray_allocator::*;
@@ -67,7 +65,6 @@ impl CodeRepo {
result: &CompiledResult,
in_situ_code_dir: &mut InSituCodeDir,
in_situ_module_dir: &mut ModuleStubDir,
flags: MachineFlags,
non_counted_bt_preds: &IndexSet<PredicateKey>,
) -> Result<(), SessionError> {
let (ref decl, ref queue) = result;
@@ -94,10 +91,10 @@ impl CodeRepo {
}
}
let mut cg = CodeGenerator::<DebrayAllocator>::new(non_counted_bt, flags);
let mut cg = CodeGenerator::<DebrayAllocator>::new(non_counted_bt);
let mut decl_code = cg.compile_predicate(&decl.0)?;
compile_appendix(&mut decl_code, queue, non_counted_bt, flags)?;
compile_appendix(&mut decl_code, queue, non_counted_bt)?;
Ok(self.in_situ_code.extend(decl_code.into_iter()))
}

View File

@@ -196,11 +196,10 @@ pub fn compile_appendix(
code: &mut Code,
queue: &VecDeque<TopLevel>,
non_counted_bt: bool,
flags: MachineFlags,
) -> Result<(), ParserError> {
for tl in queue.iter() {
set_first_index(code);
let mut cg = CodeGenerator::<DebrayAllocator>::new(non_counted_bt, flags);
let mut cg = CodeGenerator::<DebrayAllocator>::new(non_counted_bt);
let decl_code = compile_relation(&mut cg, tl)?;
code.extend(decl_code.into_iter());
}
@@ -230,7 +229,6 @@ impl CodeRepo {
pub fn compile_hook(
&mut self,
hook: CompileTimeHook,
flags: MachineFlags,
) -> Result<(), ParserError> {
let key = (hook.name(), hook.arity());
@@ -238,10 +236,10 @@ impl CodeRepo {
Some(ref mut preds) => {
append_trivial_goal(&key.0, &mut preds.0);
let mut cg = CodeGenerator::<DebrayAllocator>::new(false, flags);
let mut cg = CodeGenerator::<DebrayAllocator>::new(false);
let mut code = cg.compile_predicate(&(preds.0).0)?;
compile_appendix(&mut code, &preds.1, false, flags)?;
compile_appendix(&mut code, &preds.1, false)?;
(preds.0).0.pop();
@@ -260,7 +258,7 @@ impl CodeRepo {
let mut preds = Predicate::new();
append_trivial_goal(&key.0, &mut preds);
let mut cg = CodeGenerator::<DebrayAllocator>::new(false, flags);
let mut cg = CodeGenerator::<DebrayAllocator>::new(false);
self.term_expanders = cg.compile_predicate(&preds.0)?;
}
}
@@ -269,7 +267,7 @@ impl CodeRepo {
let mut preds = Predicate::new();
append_trivial_goal(&key.0, &mut preds);
let mut cg = CodeGenerator::<DebrayAllocator>::new(false, flags);
let mut cg = CodeGenerator::<DebrayAllocator>::new(false);
self.goal_expanders = cg.compile_predicate(&preds.0)?;
}
}
@@ -281,13 +279,12 @@ impl CodeRepo {
fn compile_query(
terms: Vec<QueryTerm>,
queue: VecDeque<TopLevel>,
flags: MachineFlags,
) -> Result<(Code, AllocVarDict), ParserError> {
// count backtracking inferences.
let mut cg = CodeGenerator::<DebrayAllocator>::new(false, flags);
let mut cg = CodeGenerator::<DebrayAllocator>::new(false);
let mut code = cg.compile_query(&terms)?;
compile_appendix(&mut code, &queue, false, flags)?;
compile_appendix(&mut code, &queue, false)?;
Ok((code, cg.take_vars()))
}
@@ -345,7 +342,7 @@ pub(super) fn compile_into_module<R: Read>(
wam.indices.insert_module(module);
}
compiler.drop_expansions(wam.machine_flags(), &mut wam.code_repo);
compiler.drop_expansions(&mut wam.code_repo);
EvalSession::from(e)
}
}
@@ -363,10 +360,8 @@ fn compile_into_module_impl<R: Read>(
let module_name = module.module_decl.name.clone();
compiler.module = Some(module);
let flags = wam.machine_flags();
wam.code_repo.compile_hook(CompileTimeHook::TermExpansion, flags)?;
wam.code_repo.compile_hook(CompileTimeHook::GoalExpansion, flags)?;
wam.code_repo.compile_hook(CompileTimeHook::TermExpansion)?;
wam.code_repo.compile_hook(CompileTimeHook::GoalExpansion)?;
let mut results = compiler.gather_items(wam, src, &mut indices)?;
@@ -400,7 +395,7 @@ fn compile_into_module_impl<R: Read>(
clause_code_generator.add_clause_code(wam, results.dynamic_clause_map);
Ok(compiler.drop_expansions(wam.machine_flags(), &mut wam.code_repo))
Ok(compiler.drop_expansions(&mut wam.code_repo))
}
pub struct GatherResult {
@@ -462,14 +457,14 @@ impl ClauseCodeGenerator {
);
let p = self.code.len() + wam.code_repo.code.len() + self.len_offset;
let mut cg = CodeGenerator::<DebrayAllocator>::new(false, wam.machine_flags());
let mut cg = CodeGenerator::<DebrayAllocator>::new(false);
let mut decl_code = compile_relation(
&mut cg,
&TopLevel::Predicate(predicate),
)?;
compile_appendix(&mut decl_code, &VecDeque::new(), false, wam.machine_flags())?;
compile_appendix(&mut decl_code, &VecDeque::new(), false)?;
self.pi_to_loc.insert((name.clone(), *arity), p);
self.code.extend(decl_code.into_iter());
@@ -735,12 +730,11 @@ impl ListingCompiler {
fn generate_init_goal_code(
&mut self,
flags: MachineFlags
) -> Result<Code, SessionError> {
let query_terms = mem::replace(&mut self.initialization_goals.0, vec![]);
let queue = mem::replace(&mut self.initialization_goals.1, VecDeque::new());
compile_query(query_terms, queue, flags)
compile_query(query_terms, queue)
.map(|(code, _)| code)
.map_err(SessionError::from)
}
@@ -766,13 +760,12 @@ impl ListingCompiler {
self.localize_self_calls(key, in_situ_code, *in_situ_p, p + *in_situ_p);
}
None => {
let flags = wam.machine_flags();
let (decl, queue) = decl;
let mut cg = CodeGenerator::<DebrayAllocator>::new(false, flags);
let mut cg = CodeGenerator::<DebrayAllocator>::new(false);
let mut decl_code = cg.compile_predicate(&decl.0)?;
compile_appendix(&mut decl_code, &queue, false, flags)?;
compile_appendix(&mut decl_code, &queue, false)?;
let in_situ_p = in_situ_code.len();
@@ -934,7 +927,7 @@ impl ListingCompiler {
let result = wam
.code_repo
.compile_hook(hook, flags)
.compile_hook(hook)
.map_err(SessionError::from);
wam.code_repo.truncate_terms(key, len, queue_len);
@@ -1170,15 +1163,15 @@ impl ListingCompiler {
})
}
fn drop_expansions(&self, flags: MachineFlags, code_repo: &mut CodeRepo) {
fn drop_expansions(&self, code_repo: &mut CodeRepo) {
let (te_len, te_queue_len) = self.orig_term_expansion_lens;
let (ge_len, ge_queue_len) = self.orig_goal_expansion_lens;
code_repo.truncate_terms((clause_name!("term_expansion"), 2), te_len, te_queue_len);
code_repo.truncate_terms((clause_name!("goal_expansion"), 2), ge_len, ge_queue_len);
discard_result!(code_repo.compile_hook(CompileTimeHook::UserGoalExpansion, flags));
discard_result!(code_repo.compile_hook(CompileTimeHook::UserTermExpansion, flags));
discard_result!(code_repo.compile_hook(CompileTimeHook::UserGoalExpansion));
discard_result!(code_repo.compile_hook(CompileTimeHook::UserTermExpansion));
}
fn print_error(&self, e: &SessionError) {
@@ -1244,10 +1237,8 @@ fn compile_work_impl(
}
}
let flags = wam.machine_flags();
wam.code_repo.compile_hook(CompileTimeHook::UserTermExpansion, flags)?;
wam.code_repo.compile_hook(CompileTimeHook::UserGoalExpansion, flags)?;
wam.code_repo.compile_hook(CompileTimeHook::UserTermExpansion)?;
wam.code_repo.compile_hook(CompileTimeHook::UserGoalExpansion)?;
if let Some(mut module) = compiler.module.take() {
if module.is_impromptu_module {
@@ -1280,7 +1271,7 @@ fn compile_work_impl(
add_toplevel(wam, results.toplevel_indices, top_level_term_dir);
wam.code_repo.code.extend(code.into_iter());
clause_code_generator.add_clause_code(wam, results.dynamic_clause_map);
} else {
add_non_module_code(
@@ -1292,9 +1283,7 @@ fn compile_work_impl(
)?;
}
let init_goal_code = compiler.generate_init_goal_code(
wam.machine_flags()
)?;
let init_goal_code = compiler.generate_init_goal_code()?;
if init_goal_code.len() > 0 {
if !wam.run_init_code(init_goal_code) {
@@ -1370,7 +1359,7 @@ pub fn compile_listing<R: Read>(
match compile_work(&mut compiler, wam, src, indices) {
EvalSession::Error(e) => {
compiler.drop_expansions(wam.machine_flags(), &mut wam.code_repo);
compiler.drop_expansions(&mut wam.code_repo);
compiler.print_error(&e);
EvalSession::Error(e)

View File

@@ -1,11 +1,12 @@
use prolog_parser::ast::*;
use prolog_parser::string_list::*;
use crate::prolog::forms::PredicateKey;
use crate::prolog::machine::machine_indices::*;
use crate::prolog::machine::machine_state::*;
use crate::prolog::rug::Integer;
use std::rc::Rc;
pub(crate) type MachineStub = Vec<HeapCellValue>;
#[derive(Clone, Copy)]
@@ -392,7 +393,7 @@ pub(super) enum CycleSearchResult {
NotList,
PartialList(usize, usize), // the list length (up to max), and an offset into the heap.
ProperList(usize), // the list length.
String(usize, StringList), // the number of elements iterated, the string tail.
String(usize, usize, Rc<String>), // the number of bytes iterated, the offset, the string.
UntouchedList(usize), // the address of an uniterated Addr::Lis(address).
}

View File

@@ -1,5 +1,4 @@
use prolog_parser::ast::*;
use prolog_parser::string_list::*;
use crate::prolog::clause_types::*;
use crate::prolog::forms::*;
@@ -250,8 +249,6 @@ pub struct MachineState {
pub(crate) stack: Stack,
pub(super) registers: Registers,
pub(super) trail: Vec<TrailRef>,
pub(super) pstr_trail: Vec<(usize, StringList, usize)>, // b, String, trunc_pt
pub(super) pstr_tr: usize,
pub(super) tr: usize,
pub(super) hb: usize,
pub(super) block: usize, // an offset into the OR stack.
@@ -265,72 +262,58 @@ pub struct MachineState {
}
impl MachineState {
pub(super) fn try_char_list(&self, addrs: Vec<Addr>) -> Result<String, MachineError> {
pub(super)
fn try_char_list(&self, addrs: Vec<Addr>) -> Result<String, MachineError> {
let mut chars = String::new();
let mut iter = addrs.iter();
while let Some(addr) = iter.next() {
match addr {
&Addr::Con(Constant::String(ref s)) if self.flags.double_quotes.is_chars() => {
chars += s.borrow().as_str();
match addr {
&Addr::Con(Constant::String(n, ref s))
if self.flags.double_quotes.is_chars() => {
if s.len() < n {
chars += &s[n ..];
}
if iter.next().is_some() {
return Err(MachineError::type_error(ValidType::Character, addr.clone()));
if iter.next().is_some() {
return Err(MachineError::type_error(ValidType::Character, addr.clone()));
}
}
&Addr::Con(Constant::Char(c)) => {
chars.push(c);
}
&Addr::Con(Constant::Atom(ref name, _))
if name.as_str().len() == 1 => {
chars += name.as_str();
}
_ => {
return Err(
MachineError::type_error(ValidType::Character, addr.clone())
);
}
&Addr::Con(Constant::Char(c)) => chars.push(c),
&Addr::Con(Constant::Atom(ref name, _)) if name.as_str().len() == 1 => {
chars += name.as_str();
}
_ => return Err(MachineError::type_error(ValidType::Character, addr.clone())),
}
}
Ok(chars)
}
pub(super) fn try_code_list(&self, addrs: Vec<Addr>) -> Result<Vec<u8>, MachineError> {
let mut codes = vec![];
let mut iter = addrs.iter();
while let Some(addr) = iter.next() {
match addr {
&Addr::Con(Constant::String(ref s)) if self.flags.double_quotes.is_codes() => {
codes.extend(s.borrow().chars().map(|c| c as u8));
if iter.next().is_some() {
return Err(MachineError::representation_error(RepFlag::CharacterCode));
}
}
&Addr::Con(Constant::CharCode(c)) => codes.push(c),
&Addr::Con(Constant::Integer(ref n)) => {
if let Some(c) = n.to_u8() {
codes.push(c);
} else {
return Err(MachineError::representation_error(RepFlag::CharacterCode));
}
}
_ => return Err(MachineError::representation_error(RepFlag::CharacterCode)),
}
}
Ok(codes)
}
pub(super) fn call_at_index(&mut self, arity: usize, p: LocalCodePtr) {
pub(super)
fn call_at_index(&mut self, arity: usize, p: LocalCodePtr) {
self.cp.assign_if_local(self.p.clone() + 1);
self.num_of_args = arity;
self.b0 = self.b;
self.p = CodePtr::Local(p);
}
pub(super) fn execute_at_index(&mut self, arity: usize, p: LocalCodePtr) {
pub(super)
fn execute_at_index(&mut self, arity: usize, p: LocalCodePtr) {
self.num_of_args = arity;
self.b0 = self.b;
self.p = CodePtr::Local(p);
}
pub(super) fn module_lookup(
pub(super)
fn module_lookup(
&mut self,
indices: &IndexStore,
key: PredicateKey,
@@ -379,7 +362,7 @@ impl MachineState {
self.call_at_index(arity, LocalCodePtr::InSituDirEntry(p));
}
return Ok(());
return Ok(());
}
_ => {}
}
@@ -460,19 +443,12 @@ pub(crate) trait CallPolicy: Any {
machine_st.tr = machine_st.stack.index_or_frame(b).prelude.tr;
machine_st.trail.truncate(machine_st.tr);
let old_pstr_tr = machine_st.stack.index_or_frame(b).prelude.pstr_tr;
let curr_pstr_tr = machine_st.pstr_tr;
machine_st.unwind_pstr_trail(old_pstr_tr, curr_pstr_tr);
machine_st.pstr_tr = machine_st.stack.index_or_frame(b).prelude.pstr_tr;
machine_st.pstr_trail.truncate(machine_st.pstr_tr);
machine_st.heap.truncate(machine_st.stack.index_or_frame(b).prelude.h);
let attr_var_init_queue_b = machine_st.stack.index_or_frame(b).prelude.attr_var_init_queue_b;
let attr_var_init_bindings_b = machine_st.stack.index_or_frame(b).prelude.attr_var_init_bindings_b;
let attr_var_init_queue_b =
machine_st.stack.index_or_frame(b).prelude.attr_var_init_queue_b;
let attr_var_init_bindings_b =
machine_st.stack.index_or_frame(b).prelude.attr_var_init_bindings_b;
machine_st.attr_var_init.backtrack(
attr_var_init_queue_b,
@@ -506,18 +482,12 @@ pub(crate) trait CallPolicy: Any {
machine_st.tr = machine_st.stack.index_or_frame(b).prelude.tr;
machine_st.trail.truncate(machine_st.tr);
let old_pstr_tr = machine_st.stack.index_or_frame(b).prelude.pstr_tr;
let curr_pstr_tr = machine_st.pstr_tr;
machine_st.unwind_pstr_trail(old_pstr_tr, curr_pstr_tr);
machine_st.pstr_tr = machine_st.stack.index_or_frame(b).prelude.pstr_tr;
machine_st.pstr_trail.truncate(machine_st.pstr_tr);
machine_st.heap.truncate(machine_st.stack.index_or_frame(b).prelude.h);
let attr_var_init_queue_b = machine_st.stack.index_or_frame(b).prelude.attr_var_init_queue_b;
let attr_var_init_bindings_b = machine_st.stack.index_or_frame(b).prelude.attr_var_init_bindings_b;
let attr_var_init_queue_b =
machine_st.stack.index_or_frame(b).prelude.attr_var_init_queue_b;
let attr_var_init_bindings_b =
machine_st.stack.index_or_frame(b).prelude.attr_var_init_bindings_b;
machine_st.attr_var_init.backtrack(attr_var_init_queue_b, attr_var_init_bindings_b);
@@ -546,18 +516,12 @@ pub(crate) trait CallPolicy: Any {
machine_st.tr = machine_st.stack.index_or_frame(b).prelude.tr;
machine_st.trail.truncate(machine_st.tr);
let old_pstr_tr = machine_st.stack.index_or_frame(b).prelude.pstr_tr;
let curr_pstr_tr = machine_st.pstr_tr;
machine_st.unwind_pstr_trail(old_pstr_tr, curr_pstr_tr);
machine_st.pstr_tr = machine_st.stack.index_or_frame(b).prelude.pstr_tr;
machine_st.pstr_trail.truncate(machine_st.pstr_tr);
machine_st.heap.truncate(machine_st.stack.index_or_frame(b).prelude.h);
let attr_var_init_queue_b = machine_st.stack.index_or_frame(b).prelude.attr_var_init_queue_b;
let attr_var_init_bindings_b = machine_st.stack.index_or_frame(b).prelude.attr_var_init_bindings_b;
let attr_var_init_queue_b =
machine_st.stack.index_or_frame(b).prelude.attr_var_init_queue_b;
let attr_var_init_bindings_b =
machine_st.stack.index_or_frame(b).prelude.attr_var_init_bindings_b;
machine_st.attr_var_init.backtrack(
attr_var_init_queue_b,
@@ -591,20 +555,12 @@ pub(crate) trait CallPolicy: Any {
machine_st.tr = machine_st.stack.index_or_frame(b).prelude.tr;
machine_st.trail.truncate(machine_st.tr);
let old_pstr_tr = machine_st.stack.index_or_frame(b).prelude.pstr_tr;
let curr_pstr_tr = machine_st.pstr_tr;
machine_st.unwind_pstr_trail(old_pstr_tr, curr_pstr_tr);
machine_st.pstr_tr = machine_st.stack.index_or_frame(b).prelude.pstr_tr;
machine_st.pstr_tr = machine_st.stack.index_or_frame(b).prelude.pstr_tr;
machine_st.pstr_trail.truncate(machine_st.pstr_tr);
machine_st.heap.truncate(machine_st.stack.index_or_frame(b).prelude.h);
let attr_var_init_queue_b = machine_st.stack.index_or_frame(b).prelude.attr_var_init_queue_b;
let attr_var_init_bindings_b = machine_st.stack.index_or_frame(b).prelude.attr_var_init_bindings_b;
let attr_var_init_queue_b =
machine_st.stack.index_or_frame(b).prelude.attr_var_init_queue_b;
let attr_var_init_bindings_b =
machine_st.stack.index_or_frame(b).prelude.attr_var_init_bindings_b;
machine_st.attr_var_init.backtrack(
attr_var_init_queue_b,
@@ -802,15 +758,6 @@ pub(crate) trait CallPolicy: Any {
return_from_clause!(machine_st.last_call, machine_st)
}
&BuiltInClauseType::PartialString => {
let s = machine_st.try_string_list(temp_v!(1))?;
let a2 = machine_st[temp_v!(2)].clone();
s.set_expandable(true);
machine_st.write_constant_to_var(a2, Constant::String(s));
return_from_clause!(machine_st.last_call, machine_st)
}
&BuiltInClauseType::Sort => {
machine_st.check_sort_errors()?;
@@ -1087,7 +1034,6 @@ fn cut_body(machine_st: &mut MachineState, addr: Addr) -> bool {
if b > b0 {
machine_st.b = b0;
machine_st.tidy_trail();
machine_st.tidy_pstr_trail();
}
}
_ => {
@@ -1174,7 +1120,6 @@ impl CutPolicy for SCCCutPolicy {
if b > b0 {
machine_st.b = b0;
machine_st.tidy_trail();
machine_st.tidy_pstr_trail();
}
}
_ => {

File diff suppressed because it is too large Load Diff

View File

@@ -161,27 +161,27 @@ impl SubModuleUser for IndexStore {
fn use_qualified_module(
&mut self,
code_repo: &mut CodeRepo,
flags: MachineFlags,
_: MachineFlags,
submodule: &Module,
exports: &Vec<ModuleExport>,
) -> Result<(), SessionError> {
use_qualified_module(self, submodule, exports)?;
submodule
.dump_expansions(code_repo, flags)
.dump_expansions(code_repo)
.map_err(SessionError::from)
}
fn use_module(
&mut self,
code_repo: &mut CodeRepo,
flags: MachineFlags,
_: MachineFlags,
submodule: &Module,
) -> Result<(), SessionError> {
use_module(self, submodule)?;
if !submodule.inserted_expansions {
submodule
.dump_expansions(code_repo, flags)
.dump_expansions(code_repo)
.map_err(SessionError::from)
} else {
Ok(())
@@ -699,12 +699,10 @@ impl Machine {
snapshot.b0 = self.machine_st.b0;
snapshot.s = self.machine_st.s;
snapshot.tr = self.machine_st.tr;
snapshot.pstr_tr = self.machine_st.pstr_tr;
snapshot.num_of_args = self.machine_st.num_of_args;
snapshot.fail = self.machine_st.fail;
snapshot.trail = mem::replace(&mut self.machine_st.trail, vec![]);
snapshot.pstr_trail = mem::replace(&mut self.machine_st.pstr_trail, vec![]);
snapshot.heap = self.machine_st.heap.take();
snapshot.mode = self.machine_st.mode;
snapshot.stack = self.machine_st.stack.take();
@@ -724,12 +722,10 @@ impl Machine {
self.machine_st.b0 = snapshot.b0;
self.machine_st.s = snapshot.s;
self.machine_st.tr = snapshot.tr;
self.machine_st.pstr_tr = snapshot.pstr_tr;
self.machine_st.num_of_args = snapshot.num_of_args;
self.machine_st.fail = snapshot.fail;
self.machine_st.trail = mem::replace(&mut snapshot.trail, vec![]);
self.machine_st.pstr_trail = mem::replace(&mut snapshot.pstr_trail, vec![]);
self.inner_heap = self.machine_st.heap.take();
self.inner_heap.truncate(0);

View File

@@ -38,7 +38,6 @@ impl Module {
pub fn dump_expansions(
&self,
code_repo: &mut CodeRepo,
flags: MachineFlags,
) -> Result<(), ParserError> {
{
let te = code_repo
@@ -64,8 +63,8 @@ impl Module {
ge.1.extend(self.user_goal_expansions.1.iter().cloned());
}
code_repo.compile_hook(CompileTimeHook::TermExpansion, flags)?;
code_repo.compile_hook(CompileTimeHook::GoalExpansion, flags)?;
code_repo.compile_hook(CompileTimeHook::TermExpansion)?;
code_repo.compile_hook(CompileTimeHook::GoalExpansion)?;
Ok(())
}

View File

@@ -1,6 +1,5 @@
use prolog_parser::ast::*;
use prolog_parser::parser::*;
use prolog_parser::string_list::*;
use prolog_parser::tabled_rc::*;
use crate::prolog::clause_types::*;
@@ -88,8 +87,8 @@ impl MachineState {
brent_st.steps,
brent_st.hare,
)),
Addr::Con(Constant::String(ref s)) if self.flags.double_quotes.is_chars() => {
Some(CycleSearchResult::String(brent_st.steps, s.clone()))
Addr::Con(Constant::String(n, ref s)) if !self.flags.double_quotes.is_atom() => {
Some(CycleSearchResult::String(brent_st.steps, n, s.clone()))
}
Addr::Lis(l) => {
brent_st.hare = l + 1;
@@ -104,7 +103,9 @@ impl MachineState {
None
}
_ => Some(CycleSearchResult::NotList),
_ => {
Some(CycleSearchResult::NotList)
}
},
}
}
@@ -115,8 +116,8 @@ impl MachineState {
Addr::Lis(offset) if max_steps > 0 => offset + 1,
Addr::Lis(offset) => return CycleSearchResult::UntouchedList(offset),
Addr::Con(Constant::EmptyList) => return CycleSearchResult::EmptyList,
Addr::Con(Constant::String(ref s)) if !self.flags.double_quotes.is_atom() => {
return CycleSearchResult::String(0, s.clone())
Addr::Con(Constant::String(n, ref s)) if !self.flags.double_quotes.is_atom() => {
return CycleSearchResult::String(0, n, s.clone())
}
_ => return CycleSearchResult::NotList,
};
@@ -139,8 +140,8 @@ impl MachineState {
let hare = match addr {
Addr::Lis(offset) => offset + 1,
Addr::Con(Constant::EmptyList) => return CycleSearchResult::EmptyList,
Addr::Con(Constant::String(ref s)) if !self.flags.double_quotes.is_atom() => {
return CycleSearchResult::String(0, s.clone())
Addr::Con(Constant::String(n, ref s)) if !self.flags.double_quotes.is_atom() => {
return CycleSearchResult::String(0, n, s.clone())
}
_ => return CycleSearchResult::NotList,
};
@@ -198,10 +199,10 @@ impl MachineState {
};
match search_result {
CycleSearchResult::String(n, s) => {
CycleSearchResult::String(n, offset, s) => {
if max_steps == -1 {
self.finalize_skip_max_list(
n + s.len(),
s[offset ..].len(),
Addr::Con(Constant::EmptyList),
)
} else {
@@ -209,15 +210,13 @@ impl MachineState {
if s.len() < i {
self.finalize_skip_max_list(
n + s.len(),
s[n + offset + i..].len(),
Addr::Con(Constant::EmptyList),
)
} else {
let s =
StringList::new(s.char_span(i), s.is_expandable());
self.finalize_skip_max_list(
i + n,
Addr::Con(Constant::String(s)),
i + n + offset,
Addr::Con(Constant::String(n + i + offset, s)),
)
}
}
@@ -436,8 +435,8 @@ impl MachineState {
n: &Integer,
stub: &'static str,
arity: usize,
) -> Result<u8, MachineStub> {
if let Some(c) = n.to_u8() {
) -> Result<u32, MachineStub> {
if let Some(c) = n.to_u32() {
Ok(c)
} else {
let stub = MachineError::functor_stub(clause_name!(stub), arity);
@@ -644,7 +643,16 @@ impl MachineState {
let list_of_chars = Addr::HeapCell(self.heap.to_list(iter));
let a2 = self[temp_v!(2)].clone();
self.unify(a2, list_of_chars);
match self.store(self.deref(a2)) {
Addr::Con(Constant::String(..))
if !self.flags.double_quotes.is_chars() => {
self.fail = true;
}
a2 => {
self.unify(a2, list_of_chars);
}
}
}
Addr::Con(Constant::EmptyList) => {
let a2 = self[temp_v!(2)].clone();
@@ -682,31 +690,50 @@ impl MachineState {
match self.store(self.deref(a1)) {
Addr::Con(Constant::Char(c)) => {
let iter = once(Addr::Con(Constant::CharCode(c as u8)));
let iter = once(Addr::Con(Constant::CharCode(c as u32)));
let list_of_codes = Addr::HeapCell(self.heap.to_list(iter));
let a2 = self[temp_v!(2)].clone();
self.unify(a2, list_of_codes);
}
Addr::Con(Constant::Atom(name, _)) => {
let iter = name
.as_str()
.chars()
.map(|c| Addr::Con(Constant::CharCode(c as u8)));
let list_of_codes = Addr::HeapCell(self.heap.to_list(iter));
let a2 = self[temp_v!(2)].clone();
self.unify(a2, list_of_codes);
match self.store(self.deref(a2)) {
a2 @ Addr::Con(Constant::String(..)) => {
if !self.flags.double_quotes.is_codes() {
self.fail = true;
} else {
let iter = name
.as_str()
.chars()
.map(|c| Addr::Con(Constant::Char(c)));
let list_of_codes = Addr::HeapCell(self.heap.to_list(iter));
self.unify(a2, list_of_codes);
}
}
a2 => {
let iter = name
.as_str()
.chars()
.map(|c| Addr::Con(Constant::CharCode(c as u32)));
let list_of_codes = Addr::HeapCell(self.heap.to_list(iter));
self.unify(a2, list_of_codes);
}
}
}
Addr::Con(Constant::EmptyList) => {
let a2 = self[temp_v!(2)].clone();
let chars = vec![
Addr::Con(Constant::CharCode('[' as u8)),
Addr::Con(Constant::CharCode(']' as u8)),
Addr::Con(Constant::CharCode('[' as u32)),
Addr::Con(Constant::CharCode(']' as u32)),
];
let list_of_codes = Addr::HeapCell(self.heap.to_list(chars.into_iter()));
let a2 = self[temp_v!(2)].clone();
self.unify(a2, list_of_codes);
}
@@ -718,14 +745,15 @@ impl MachineState {
Ok(addrs) => {
let mut chars = String::new();
for addr in addrs.iter() {
for addr in addrs {
match addr {
&Addr::Con(Constant::Integer(ref n)) => {
Addr::Con(Constant::Integer(n)) => {
let c = self.int_to_char_code(&n, "atom_codes", 2)?;
chars.push(c as char);
chars.push(std::char::from_u32(c).unwrap());
}
Addr::Con(Constant::CharCode(c)) => {
chars.push(std::char::from_u32(c).unwrap());
}
&Addr::Con(Constant::CharCode(c)) =>
chars.push(c as char),
_ => {
let err = MachineError::type_error(
ValidType::Integer,
@@ -754,7 +782,7 @@ impl MachineState {
_ => unreachable!(),
};
let len = Integer::from(atom.as_str().len());
let len = Integer::from(atom.as_str().chars().count());
let a2 = self[temp_v!(2)].clone();
self.unify(a2, Addr::Con(Constant::Integer(len)));
@@ -831,7 +859,7 @@ impl MachineState {
let codes = string
.trim()
.chars()
.map(|c| Addr::Con(Constant::CharCode(c as u8)));
.map(|c| Addr::Con(Constant::CharCode(c as u32)));
let codes_list = Addr::HeapCell(self.heap.to_list(codes));
self.unify(codes_list, chs);
@@ -841,10 +869,9 @@ impl MachineState {
match self.try_from_list(temp_v!(1), stub.clone()) {
Err(e) => return Err(e),
Ok(addrs) => match self.try_code_list(addrs) {
Ok(codes) => {
let string = codes.iter().map(|c| *c as char).collect();
self.parse_number_from_string(string, indices, stub)?
Ok(addrs) => match self.try_char_list(addrs) {
Ok(chars) => {
self.parse_number_from_string(chars, indices, stub)?
}
Err(err) => return Err(self.error_form(err, stub)),
},
@@ -878,22 +905,24 @@ impl MachineState {
let c = name.as_str().chars().next().unwrap();
let a2 = self[temp_v!(2)].clone();
self.unify(Addr::Con(Constant::CharCode(c as u8)), a2);
self.unify(Addr::Con(Constant::CharCode(c as u32)), a2);
}
Addr::Con(Constant::Char(c)) => {
let a2 = self[temp_v!(2)].clone();
self.unify(Addr::Con(Constant::CharCode(c as u8)), a2);
self.unify(Addr::Con(Constant::CharCode(c as u32)), a2);
}
ref addr if addr.is_ref() => {
let a2 = self[temp_v!(2)].clone();
match self.store(self.deref(a2)) {
Addr::Con(Constant::CharCode(code)) => {
self.unify(Addr::Con(Constant::Char(code as char)), addr.clone())
Addr::Con(Constant::Char(code)) => {
self.unify(Addr::Con(Constant::Char(code)), addr.clone())
}
Addr::Con(Constant::Integer(n)) => {
let c = self.int_to_char_code(&n, "char_code", 2)?;
self.unify(Addr::Con(Constant::Char(c as char)), addr.clone());
let c = std::char::from_u32(c).unwrap();
self.unify(Addr::Con(Constant::Char(c)), addr.clone());
}
_ => self.fail = true,
};
@@ -2325,7 +2354,7 @@ impl MachineState {
let mut h = self.heap.h;
let mut functors = vec![];
walk_code(
&code_repo.code,
first_idx,
@@ -2334,10 +2363,10 @@ impl MachineState {
functors.push(Addr::HeapCell(h));
h += section.len();
self.heap.extend(section.into_iter());
self.heap.extend(section.into_iter());
},
);
let listing = Addr::HeapCell(self.heap.to_list(functors.into_iter()));
let listing_var = self[temp_v!(3)].clone();

View File

@@ -209,10 +209,10 @@ impl<'a, R: Read> TermStream<'a, R> {
self.wam
.code_repo
.compile_hook(CompileTimeHook::TermExpansion, self.flags)?;
.compile_hook(CompileTimeHook::TermExpansion)?;
self.wam
.code_repo
.compile_hook(CompileTimeHook::GoalExpansion, self.flags)?;
.compile_hook(CompileTimeHook::GoalExpansion)?;
Ok(ExpansionAdditionResult {
term_expansion_additions,

View File

@@ -828,10 +828,6 @@ impl RelationWorker {
Err(ParserError::InadmissibleQueryTerm)
}
}
("partial_string", 2) => {
let ct = ClauseType::BuiltIn(BuiltInClauseType::PartialString);
return Ok(QueryTerm::Clause(Cell::default(), ct, terms, false));
}
_ => {
let ct = indices.get_clause_type(name, terms.len(), fixity);
Ok(QueryTerm::Clause(Cell::default(), ct, terms, false))
@@ -1190,7 +1186,6 @@ impl<'a, R: Read> TopLevelBatchWorker<'a, R> {
&result,
&mut indices.term_stream.wam.indices.in_situ_code_dir,
&mut indices.term_stream.wam.indices.in_situ_module_dir,
indices.term_stream.flags,
&self.non_counted_bt_preds,
)?;