Fix signalling of success/failure (by @mthom)
This commit is contained in:
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use crate::atom_table;
|
use crate::atom_table;
|
||||||
use crate::heap_print::{HCPrinter, HCValueOutputter, PrinterOutputter};
|
use crate::heap_print::{HCPrinter, HCValueOutputter, PrinterOutputter};
|
||||||
use crate::machine::BREAK_FROM_DISPATCH_LOOP_LOC;
|
use crate::machine::{BREAK_FROM_DISPATCH_LOOP_LOC, LIB_QUERY_SUCCESS};
|
||||||
use crate::machine::mock_wam::CompositeOpDir;
|
use crate::machine::mock_wam::CompositeOpDir;
|
||||||
use crate::parser::parser::{Parser, Tokens};
|
use crate::parser::parser::{Parser, Tokens};
|
||||||
use crate::read::write_term_to_heap;
|
use crate::read::write_term_to_heap;
|
||||||
@@ -12,7 +12,7 @@ use crate::parser::ast::{Var, VarPtr};
|
|||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
Machine, MachineConfig, QueryResult, QueryResolutionLine,
|
Machine, MachineConfig, QueryResult, QueryResolutionLine,
|
||||||
Atom, AtomCell, HeapCellValue, HeapCellValueTag, Value, QueryResolution,
|
Atom, AtomCell, HeapCellValue, HeapCellValueTag, Value, QueryResolution,
|
||||||
streams::Stream
|
streams::Stream
|
||||||
};
|
};
|
||||||
@@ -73,7 +73,7 @@ impl Machine {
|
|||||||
// Write term to heap
|
// Write term to heap
|
||||||
self.machine_st.registers[1] = self.machine_st.heap[term_write_result.heap_loc];
|
self.machine_st.registers[1] = self.machine_st.heap[term_write_result.heap_loc];
|
||||||
|
|
||||||
self.machine_st.cp = BREAK_FROM_DISPATCH_LOOP_LOC;
|
self.machine_st.cp = LIB_QUERY_SUCCESS; // BREAK_FROM_DISPATCH_LOOP_LOC;
|
||||||
self.machine_st.p = self.indices.code_dir.get(&(atom!("call"), 1)).expect("couldn't get code index").local().unwrap();
|
self.machine_st.p = self.indices.code_dir.get(&(atom!("call"), 1)).expect("couldn't get code index").local().unwrap();
|
||||||
|
|
||||||
let var_names: IndexMap<_, _> = term_write_result.var_dict.iter()
|
let var_names: IndexMap<_, _> = term_write_result.var_dict.iter()
|
||||||
@@ -122,27 +122,34 @@ impl Machine {
|
|||||||
},
|
},
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
})
|
})
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(" ");
|
.join(" ");
|
||||||
|
|
||||||
return Err(error_string);
|
return Err(error_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if self.machine_st.fail {
|
if self.machine_st.fail {
|
||||||
// NOTE: only print results on success
|
// NOTE: only print results on success
|
||||||
self.machine_st.fail = false;
|
self.machine_st.fail = false;
|
||||||
println!("fail!");
|
println!("fail!");
|
||||||
matches.push(QueryResolutionLine::False);
|
matches.push(QueryResolutionLine::False);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
if self.machine_st.b == stub_b && term_write_result.var_dict.len() == 0 {
|
if term_write_result.var_dict.is_empty() {
|
||||||
// NOTE: only print results on success
|
if self.machine_st.p == LIB_QUERY_SUCCESS {
|
||||||
self.machine_st.fail = false;
|
matches.push(QueryResolutionLine::True);
|
||||||
println!("b == stub_b");
|
break;
|
||||||
matches.push(QueryResolutionLine::False);
|
} else if self.machine_st.p == BREAK_FROM_DISPATCH_LOOP_LOC {
|
||||||
break;
|
// NOTE: only print results on success
|
||||||
};
|
// self.machine_st.fail = false;
|
||||||
|
// println!("b == stub_b");
|
||||||
|
matches.push(QueryResolutionLine::False);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut bindings: BTreeMap<String, Value> = BTreeMap::new();
|
let mut bindings: BTreeMap<String, Value> = BTreeMap::new();
|
||||||
|
|
||||||
@@ -323,8 +330,8 @@ mod tests {
|
|||||||
QueryMatch::from(btreemap! {
|
QueryMatch::from(btreemap! {
|
||||||
"X" => Value::List(
|
"X" => Value::List(
|
||||||
Vec::from([
|
Vec::from([
|
||||||
Value::Float(OrderedFloat::from(1.0)),
|
Value::Float(OrderedFloat::from(1.0)),
|
||||||
Value::Float(OrderedFloat::from(2.0)),
|
Value::Float(OrderedFloat::from(2.0)),
|
||||||
Value::Float(OrderedFloat::from(3.0))
|
Value::Float(OrderedFloat::from(3.0))
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
@@ -464,8 +471,8 @@ mod tests {
|
|||||||
"Predicate" => Value::from("Predicate"),
|
"Predicate" => Value::from("Predicate"),
|
||||||
"Result" => Value::List(
|
"Result" => Value::List(
|
||||||
Vec::from([
|
Vec::from([
|
||||||
Value::List([Value::from("p1"), Value::from("b")].into()),
|
Value::List([Value::from("p1"), Value::from("b")].into()),
|
||||||
Value::List([Value::from("p2"), Value::from("b")].into()),
|
Value::List([Value::from("p2"), Value::from("b")].into()),
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
"Target" => Value::from("Target"),
|
"Target" => Value::from("Target"),
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ use std::sync::atomic::AtomicBool;
|
|||||||
|
|
||||||
use self::config::MachineConfig;
|
use self::config::MachineConfig;
|
||||||
use self::parsed_results::*;
|
use self::parsed_results::*;
|
||||||
use tokio::runtime::Runtime;
|
|
||||||
use rand::rngs::StdRng;
|
use rand::rngs::StdRng;
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
|
|
||||||
@@ -118,6 +117,7 @@ include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
|
|||||||
pub static BREAK_FROM_DISPATCH_LOOP_LOC: usize = 0;
|
pub static BREAK_FROM_DISPATCH_LOOP_LOC: usize = 0;
|
||||||
pub static INSTALL_VERIFY_ATTR_INTERRUPT: usize = 1;
|
pub static INSTALL_VERIFY_ATTR_INTERRUPT: usize = 1;
|
||||||
pub static VERIFY_ATTR_INTERRUPT_LOC: usize = 2;
|
pub static VERIFY_ATTR_INTERRUPT_LOC: usize = 2;
|
||||||
|
pub static LIB_QUERY_SUCCESS: usize = 3;
|
||||||
|
|
||||||
pub struct MachinePreludeView<'a> {
|
pub struct MachinePreludeView<'a> {
|
||||||
pub indices: &'a mut IndexStore,
|
pub indices: &'a mut IndexStore,
|
||||||
@@ -397,13 +397,14 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_impls_to_indices(&mut self) {
|
pub(crate) fn add_impls_to_indices(&mut self) {
|
||||||
let impls_offset = self.code.len() + 3;
|
let impls_offset = self.code.len() + 4;
|
||||||
|
|
||||||
self.code.extend(
|
self.code.extend(
|
||||||
vec![
|
vec![
|
||||||
Instruction::BreakFromDispatchLoop,
|
Instruction::BreakFromDispatchLoop,
|
||||||
Instruction::InstallVerifyAttr,
|
Instruction::InstallVerifyAttr,
|
||||||
Instruction::VerifyAttrInterrupt,
|
Instruction::VerifyAttrInterrupt,
|
||||||
|
Instruction::BreakFromDispatchLoop, // the location of LIB_QUERY_SUCCESS
|
||||||
Instruction::ExecuteTermGreaterThan,
|
Instruction::ExecuteTermGreaterThan,
|
||||||
Instruction::ExecuteTermLessThan,
|
Instruction::ExecuteTermLessThan,
|
||||||
Instruction::ExecuteTermGreaterThanOrEqual,
|
Instruction::ExecuteTermGreaterThanOrEqual,
|
||||||
|
|||||||
Reference in New Issue
Block a user