Rename PrologTerm

This commit is contained in:
bakaq
2024-09-06 23:06:20 -03:00
parent dba9c9a0a7
commit 8e7dc9dba8
2 changed files with 115 additions and 115 deletions

View File

@@ -11,7 +11,7 @@ use indexmap::IndexMap;
use super::{
streams::Stream, Atom, AtomCell, HeapCellValue, HeapCellValueTag, Machine, MachineConfig,
QueryResolutionLine, QueryResult, Value,
QueryResolutionLine, QueryResult, PrologTerm,
};
pub struct QueryState<'a> {
@@ -88,7 +88,7 @@ impl Iterator for QueryState<'_> {
return Some(Ok(QueryResolutionLine::False));
}
let mut bindings: BTreeMap<String, Value> = BTreeMap::new();
let mut bindings: BTreeMap<String, PrologTerm> = BTreeMap::new();
let var_dict = &term_write_result.var_dict;
@@ -105,9 +105,9 @@ impl Iterator for QueryState<'_> {
}
let mut term =
Value::from_heapcell(machine, *term_to_be_printed, &mut var_names.clone());
PrologTerm::from_heapcell(machine, *term_to_be_printed, &mut var_names.clone());
if let Value::Var(ref term_str) = term {
if let PrologTerm::Var(ref term_str) = term {
if *term_str == var_name {
continue;
}
@@ -121,7 +121,7 @@ impl Iterator for QueryState<'_> {
var_dict.get_index_of(&VarKey::VarPtr(Var::Named(term_str.clone()).into()));
if let Some(idx) = term_idx {
if idx < var_name_idx {
let new_term = Value::Var(var_name);
let new_term = PrologTerm::Var(var_name);
let new_var_name = term_str.into();
term = new_term;
var_name = new_var_name;
@@ -248,7 +248,7 @@ impl Machine {
#[cfg(test)]
mod tests {
use super::*;
use crate::machine::{QueryMatch, QueryResolution, Value};
use crate::machine::{QueryMatch, QueryResolution, Term};
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
@@ -271,10 +271,10 @@ mod tests {
output,
Ok(QueryResolution::Matches(vec![
QueryMatch::from(btreemap! {
"P" => Value::from("p1"),
"P" => Term::from("p1"),
}),
QueryMatch::from(btreemap! {
"P" => Value::from("p2"),
"P" => Term::from("p2"),
}),
]))
);
@@ -328,8 +328,8 @@ mod tests {
result,
Ok(QueryResolution::Matches(vec![QueryMatch::from(
btreemap! {
"C" => Value::Atom("c".into()),
"Actions" => Value::Atom("[{action: \"addLink\", source: \"this\", predicate: \"todo://state\", target: \"todo://ready\"}]".into()),
"C" => Term::Atom("c".into()),
"Actions" => Term::Atom("[{action: \"addLink\", source: \"this\", predicate: \"todo://state\", target: \"todo://ready\"}]".into()),
}
),]))
);
@@ -341,8 +341,8 @@ mod tests {
result,
Ok(QueryResolution::Matches(vec![QueryMatch::from(
btreemap! {
"C" => Value::Atom("xyz".into()),
"Actions" => Value::Atom("[{action: \"addLink\", source: \"this\", predicate: \"recipe://title\", target: \"literal://string:Meta%20Muffins\"}]".into()),
"C" => Term::Atom("xyz".into()),
"Actions" => Term::Atom("[{action: \"addLink\", source: \"this\", predicate: \"recipe://title\", target: \"literal://string:Meta%20Muffins\"}]".into()),
}
),]))
);
@@ -352,10 +352,10 @@ mod tests {
result,
Ok(QueryResolution::Matches(vec![
QueryMatch::from(btreemap! {
"Class" => Value::String("Todo".into())
"Class" => Term::String("Todo".into())
}),
QueryMatch::from(btreemap! {
"Class" => Value::String("Recipe".into())
"Class" => Term::String("Recipe".into())
}),
]))
);
@@ -394,10 +394,10 @@ mod tests {
result,
Ok(QueryResolution::Matches(vec![QueryMatch::from(
btreemap! {
"X" => Value::List(vec![
Value::Integer(1.into()),
Value::Integer(2.into()),
Value::Integer(3.into()),
"X" => Term::List(vec![
Term::Integer(1.into()),
Term::Integer(2.into()),
Term::Integer(3.into()),
]),
}
),]))
@@ -425,10 +425,10 @@ mod tests {
output,
Ok(QueryResolution::Matches(vec![
QueryMatch::from(btreemap! {
"P" => Value::from("p1"),
"P" => Term::from("p1"),
}),
QueryMatch::from(btreemap! {
"P" => Value::from("p2"),
"P" => Term::from("p2"),
}),
]))
);
@@ -529,10 +529,10 @@ mod tests {
output,
Ok(QueryResolution::Matches(vec![QueryMatch::from(
btreemap! {
"Result" => Value::List(
"Result" => Term::List(
Vec::from([
Value::List([Value::from("p1"), Value::from("b")].into()),
Value::List([Value::from("p2"), Value::from("b")].into()),
Term::List([Term::from("p1"), Term::from("b")].into()),
Term::List([Term::from("p2"), Term::from("b")].into()),
])
),
}
@@ -634,7 +634,7 @@ mod tests {
result,
Ok(QueryResolution::Matches(vec![QueryMatch::from(
btreemap! {
"X" => Value::Atom(".".into()),
"X" => Term::Atom(".".into()),
}
)]))
);
@@ -654,7 +654,7 @@ mod tests {
result,
Ok(QueryResolution::Matches(vec![QueryMatch::from(
btreemap! {
"X" => Value::Rational(RBig::from_parts(1.into(), 2u32.into())),
"X" => Term::Rational(RBig::from_parts(1.into(), 2u32.into())),
}
)]))
);
@@ -674,7 +674,7 @@ mod tests {
result,
Ok(QueryResolution::Matches(vec![QueryMatch::from(
btreemap! {
"X" => Value::Integer(IBig::from(10).pow(100)),
"X" => Term::Integer(IBig::from(10).pow(100)),
}
)]))
);
@@ -689,31 +689,31 @@ mod tests {
let result = machine.run_query(query);
let expected = Value::Structure(
let expected = Term::Structure(
// Composite term
"a".into(),
vec![
Value::String("asdf".into()), // String
Value::List(vec![
Value::Integer(42.into()), // Fixnum
Value::Float(2.54.into()), // Float
Value::Atom("asdf".into()), // Atom
Value::Atom("a".into()), // Char
Value::Structure(
Term::String("asdf".into()), // String
Term::List(vec![
Term::Integer(42.into()), // Fixnum
Term::Float(2.54.into()), // Float
Term::Atom("asdf".into()), // Atom
Term::Atom("a".into()), // Char
Term::Structure(
// Partial string
".".into(),
vec![
Value::Atom("a".into()),
Value::Structure(
Term::Atom("a".into()),
Term::Structure(
".".into(),
vec![
Value::Atom("b".into()),
Value::Var("_A".into()), // Anonymous variable
Term::Atom("b".into()),
Term::Var("_A".into()), // Anonymous variable
],
),
],
),
Value::Var("Z".into()), // Named variable
Term::Var("Z".into()), // Named variable
]),
],
);
@@ -802,11 +802,11 @@ mod tests {
result,
Ok(QueryResolution::Matches(vec![
QueryMatch::from(btreemap! {
"A" => Value::List(vec![Value::Var("_A".into()), Value::Var("_C".into())]),
"_B" => Value::Integer(1.into()),
"A" => Term::List(vec![Term::Var("_A".into()), Term::Var("_C".into())]),
"_B" => Term::Integer(1.into()),
}),
QueryMatch::from(btreemap! {
"B" => Value::List(vec![Value::Var("_A".into()), Value::Var("_C".into())]),
"B" => Term::List(vec![Term::Var("_A".into()), Term::Var("_C".into())]),
}),
]))
);
@@ -823,8 +823,8 @@ mod tests {
result,
Ok(QueryResolution::Matches(vec![QueryMatch::from(
btreemap! {
"X" => Value::Var("Y".into()),
"Z" => Value::Var("W".into()),
"X" => Term::Var("Y".into()),
"Z" => Term::Var("W".into()),
}
),]))
);