remove double_quotes checks from unnecessary places in system_calls.rs and elsewhere (#513, #542)

This commit is contained in:
Mark Thom
2020-06-04 21:03:16 -06:00
parent 24f11b5ae9
commit 2a588ff943
4 changed files with 39 additions and 94 deletions

View File

@@ -93,8 +93,7 @@ impl<'a> HCPreOrderIterator<'a> {
} }
Addr::Con(h) => { Addr::Con(h) => {
if let &HeapCellValue::PartialString(ref pstr, has_tail) = &self.machine_st.heap[h] { if let &HeapCellValue::PartialString(ref pstr, has_tail) = &self.machine_st.heap[h] {
if !self.machine_st.flags.double_quotes.is_atom() { if let Some(c) = pstr.range_from(0 ..).next() {
return if let Some(c) = pstr.range_from(0 ..).next() {
self.state_stack.push(Addr::PStrLocation(h, c.len_utf8())); self.state_stack.push(Addr::PStrLocation(h, c.len_utf8()));
self.state_stack.push(Addr::Char(c)); self.state_stack.push(Addr::Char(c));
@@ -103,12 +102,11 @@ impl<'a> HCPreOrderIterator<'a> {
self.follow(Addr::HeapCell(h + 1)) self.follow(Addr::HeapCell(h + 1))
} else { } else {
Addr::EmptyList Addr::EmptyList
};
} }
} } else {
Addr::Con(h) Addr::Con(h)
} }
}
da => { da => {
da da
} }

View File

@@ -1173,7 +1173,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
let at_cdr = self.at_cdr(","); let at_cdr = self.at_cdr(",");
if !at_cdr && Addr::EmptyList == end_addr { if !at_cdr && Addr::EmptyList == end_addr {
if self.machine_st.flags.double_quotes.is_chars() && !self.ignore_ops { if !self.ignore_ops {
self.print_proper_string(buf, max_depth); self.print_proper_string(buf, max_depth);
return; return;
} }
@@ -1190,18 +1190,6 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
let mut byte_len = 0; let mut byte_len = 0;
let char_printer = |printer: &mut Self, c| {
if printer.machine_st.flags.double_quotes.is_codes() {
let s = (c as u32).to_string();
push_space_if_amb!(printer, &s, {
printer.append_str(&s);
});
} else {
printer.print_char(printer.quoted, c);
}
};
if self.ignore_ops { if self.ignore_ops {
let mut char_count = 0; let mut char_count = 0;
@@ -1209,7 +1197,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
self.append_str("'.'"); self.append_str("'.'");
self.push_char('('); self.push_char('(');
char_printer(self, c); self.print_char(self.quoted, c);
self.push_char(','); self.push_char(',');
char_count += 1; char_count += 1;
@@ -1235,7 +1223,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
}; };
for c in buf_iter { for c in buf_iter {
char_printer(self, c); self.print_char(self.quoted, c);
self.push_char(','); self.push_char(',');
byte_len += c.len_utf8(); byte_len += c.len_utf8();

View File

@@ -818,7 +818,7 @@ impl MachineState {
self.bind(addr.as_var().unwrap(), pstr_addr); self.bind(addr.as_var().unwrap(), pstr_addr);
} }
Addr::Lis(l) if !self.flags.double_quotes.is_atom() => { Addr::Lis(l) => {
let h = self.heap.h(); let h = self.heap.h();
let pstr_addr = let pstr_addr =
@@ -920,7 +920,7 @@ impl MachineState {
self.fail = true; self.fail = true;
} }
} }
Addr::Lis(l) if !self.flags.double_quotes.is_atom() => { Addr::Lis(l) => {
let addr = self.heap.put_constant(c.clone()); let addr = self.heap.put_constant(c.clone());
self.unify(Addr::Lis(l), addr); self.unify(Addr::Lis(l), addr);
} }
@@ -1404,11 +1404,7 @@ impl MachineState {
v v
} }
Addr::PStrLocation(..) => { Addr::PStrLocation(..) => {
if !self.flags.double_quotes.is_atom() {
l l
} else {
c
}
} }
Addr::Char(_) | Addr::Con(_) | Addr::CutPoint(_) | Addr::Char(_) | Addr::Con(_) | Addr::CutPoint(_) |
Addr::EmptyList | Addr::Fixnum(_) | Addr::Float(_) | Addr::Usize(_) => { Addr::EmptyList | Addr::Fixnum(_) | Addr::Float(_) | Addr::Usize(_) => {
@@ -1884,9 +1880,8 @@ impl MachineState {
unreachable!() unreachable!()
} }
} }
(Addr::PStrLocation(..), Addr::Lis(_)) (Addr::PStrLocation(..), Addr::Lis(_)) |
| (Addr::Lis(_), Addr::PStrLocation(..)) (Addr::Lis(_), Addr::PStrLocation(..)) => {
if !self.flags.double_quotes.is_atom() => {
continue; continue;
} }
(pstr1 @ Addr::PStrLocation(..), pstr2 @ Addr::PStrLocation(..)) => { (pstr1 @ Addr::PStrLocation(..), pstr2 @ Addr::PStrLocation(..)) => {
@@ -2248,7 +2243,7 @@ impl MachineState {
( (
Addr::PStrLocation(..), Addr::PStrLocation(..),
Addr::Lis(_), Addr::Lis(_),
) if !self.flags.double_quotes.is_atom() => { ) => {
} }
( (
Addr::Lis(_), Addr::Lis(_),
@@ -2277,7 +2272,7 @@ impl MachineState {
( (
Addr::PStrLocation(..), Addr::PStrLocation(..),
Addr::Str(s), Addr::Str(s),
) if !self.flags.double_quotes.is_atom() => { ) => {
if let &HeapCellValue::NamedStr(a1, ref n1, _) = &self.heap[s] { if let &HeapCellValue::NamedStr(a1, ref n1, _) = &self.heap[s] {
if a1 != 2 || n1.as_str() != "." { if a1 != 2 || n1.as_str() != "." {
return Some(a1.cmp(&2).then_with(|| n1.as_str().cmp("."))); return Some(a1.cmp(&2).then_with(|| n1.as_str().cmp(".")));
@@ -2289,7 +2284,7 @@ impl MachineState {
( (
Addr::Str(s), Addr::Str(s),
Addr::PStrLocation(..), Addr::PStrLocation(..),
) if !self.flags.double_quotes.is_atom() => { ) => {
if let &HeapCellValue::NamedStr(a1, ref n1, _) = &self.heap[s] { if let &HeapCellValue::NamedStr(a1, ref n1, _) = &self.heap[s] {
if a1 != 2 || n1.as_str() != "." { if a1 != 2 || n1.as_str() != "." {
return Some(2.cmp(&a1).then_with(|| ".".cmp(n1.as_str()))); return Some(2.cmp(&a1).then_with(|| ".".cmp(n1.as_str())));
@@ -2374,18 +2369,11 @@ impl MachineState {
self.fail = true; self.fail = true;
} }
} }
_ => {
match d {
Addr::Char(_) if self.flags.double_quotes.is_codes() => {
self.p += 1;
}
_ => { _ => {
self.fail = true; self.fail = true;
} }
} }
} }
}
}
&InlinedClauseType::IsCompound(r1) => { &InlinedClauseType::IsCompound(r1) => {
let d = self.store(self.deref(self[r1])); let d = self.store(self.deref(self[r1]));
@@ -2888,7 +2876,7 @@ impl MachineState {
| ( | (
HeapCellValue::Addr(Addr::PStrLocation(..)), HeapCellValue::Addr(Addr::PStrLocation(..)),
HeapCellValue::Addr(Addr::Lis(_)), HeapCellValue::Addr(Addr::Lis(_)),
) if !self.flags.double_quotes.is_atom() => { ) => {
} }
( (
HeapCellValue::NamedStr(ar1, n1, _), HeapCellValue::NamedStr(ar1, n1, _),

View File

@@ -185,21 +185,15 @@ impl MachineState {
} }
Addr::Con(h) if max_steps > 0 => { Addr::Con(h) if max_steps > 0 => {
if let HeapCellValue::PartialString(..) = &self.heap[h] { if let HeapCellValue::PartialString(..) = &self.heap[h] {
if !self.flags.double_quotes.is_atom() {
Addr::PStrLocation(h, 0) Addr::PStrLocation(h, 0)
} else { } else {
return CycleSearchResult::NotList; return CycleSearchResult::NotList;
} }
} else {
return CycleSearchResult::NotList;
}
} }
Addr::Con(h) => { Addr::Con(h) => {
if let HeapCellValue::PartialString(..) = &self.heap[h] { if let HeapCellValue::PartialString(..) = &self.heap[h] {
if !self.flags.double_quotes.is_atom() {
return CycleSearchResult::UntouchedList(h); return CycleSearchResult::UntouchedList(h);
} }
}
return CycleSearchResult::NotList; return CycleSearchResult::NotList;
} }
@@ -236,14 +230,10 @@ impl MachineState {
} }
Addr::Con(h) => { Addr::Con(h) => {
if let HeapCellValue::PartialString(..) = &self.heap[h] { if let HeapCellValue::PartialString(..) = &self.heap[h] {
if !self.flags.double_quotes.is_atom() {
Addr::PStrLocation(h, 0) Addr::PStrLocation(h, 0)
} else { } else {
return CycleSearchResult::NotList; return CycleSearchResult::NotList;
} }
} else {
return CycleSearchResult::NotList;
}
} }
_ => { _ => {
return CycleSearchResult::NotList; return CycleSearchResult::NotList;
@@ -846,8 +836,7 @@ impl MachineState {
let a2 = self[temp_v!(2)]; let a2 = self[temp_v!(2)];
match self.store(self.deref(a2)) { match self.store(self.deref(a2)) {
Addr::PStrLocation(..) Addr::PStrLocation(..) => {
if !self.flags.double_quotes.is_chars() => {
self.fail = true; self.fail = true;
} }
a2 => { a2 => {
@@ -919,24 +908,8 @@ impl MachineState {
} }
Addr::Con(h) if self.heap.atom_at(h) => { Addr::Con(h) if self.heap.atom_at(h) => {
if let HeapCellValue::Atom(name, _) = self.heap.clone(h) { if let HeapCellValue::Atom(name, _) = self.heap.clone(h) {
let a2 = self[temp_v!(2)]; let a2 = self.store(self.deref(self[temp_v!(2)]));
match self.store(self.deref(a2)) {
a2 @ Addr::PStrLocation(..) => {
if !self.flags.double_quotes.is_codes() {
self.fail = true;
} else {
let iter = name
.as_str()
.chars()
.map(|c| Addr::Char(c));
let list_of_codes = Addr::HeapCell(self.heap.to_list(iter));
self.unify(a2, list_of_codes);
}
}
a2 => {
let iter = name let iter = name
.as_str() .as_str()
.chars() .chars()
@@ -945,8 +918,6 @@ impl MachineState {
let list_of_codes = Addr::HeapCell(self.heap.to_list(iter)); let list_of_codes = Addr::HeapCell(self.heap.to_list(iter));
self.unify(a2, list_of_codes); self.unify(a2, list_of_codes);
}
}
} else { } else {
unreachable!() unreachable!()
} }