add some prolog flags, tabled strings

This commit is contained in:
Mark Thom
2018-08-18 18:03:28 -06:00
parent f9e6b7fec5
commit d19ece6df8
6 changed files with 100 additions and 4 deletions

View File

@@ -264,6 +264,28 @@ pub(super) enum MachineMode {
Write
}
#[derive(Clone, Copy)]
pub(super) enum DoubleQuotes {
Atom, Chars, // Codes
}
impl Default for DoubleQuotes {
fn default() -> Self {
DoubleQuotes::Chars
}
}
#[derive(Clone, Copy)]
pub(super) struct MachineFlags {
pub(super) double_quotes: DoubleQuotes
}
impl Default for MachineFlags {
fn default() -> Self {
MachineFlags { double_quotes: DoubleQuotes::default() }
}
}
pub struct MachineState {
pub(crate) atom_tbl: TabledData<Atom>,
pub(super) s: usize,
@@ -285,7 +307,8 @@ pub struct MachineState {
pub(super) block: usize, // an offset into the OR stack.
pub(super) ball: Ball,
pub(super) interms: Vec<Number>, // intermediate numbers.
pub(super) last_call: bool
pub(super) last_call: bool,
pub(super) flags: MachineFlags
}
fn call_at_index(machine_st: &mut MachineState, module_name: ClauseName, arity: usize, idx: usize)

View File

@@ -50,7 +50,8 @@ impl MachineState {
block: 0,
ball: Ball::new(),
interms: vec![Number::default(); 256],
last_call: false
last_call: false,
flags: MachineFlags::default()
}
}

View File

@@ -195,6 +195,16 @@ impl MachineState {
_ => self.fail = true
};
},
&SystemClauseType::GetDoubleQuotes => {
let a1 = self[temp_v!(1)].clone();
match self.flags.double_quotes {
DoubleQuotes::Chars =>
self.unify(a1, Addr::Con(atom!("chars"))),
DoubleQuotes::Atom =>
self.unify(a1, Addr::Con(atom!("atom")))
}
},
&SystemClauseType::GetSCCCleaner => {
let dest = self[temp_v!(1)].clone();
@@ -330,6 +340,14 @@ impl MachineState {
},
&SystemClauseType::SetCutPointByDefault(r) =>
deref_cut(self, r),
&SystemClauseType::SetDoubleQuotes =>
match self[temp_v!(1)].clone() {
Addr::Con(Constant::Atom(ref atom)) if atom.as_str() == "chars" =>
self.flags.double_quotes = DoubleQuotes::Chars,
Addr::Con(Constant::Atom(ref atom)) if atom.as_str() == "atom" =>
self.flags.double_quotes = DoubleQuotes::Atom,
_ => self.fail = true
},
&SystemClauseType::InferenceLevel => {
let a1 = self[temp_v!(1)].clone();
let a2 = self.store(self.deref(self[temp_v!(2)].clone()));