add clean errors for read, re: #45
This commit is contained in:
@@ -58,6 +58,11 @@ impl MachineError {
|
||||
MachineError { stub, from: ErrorProvenance::Constructed }
|
||||
}
|
||||
|
||||
pub(super) fn syntax_error(error: SyntaxError) -> Self {
|
||||
let stub = functor!("syntax_error", 1, [heap_atom!(error.as_str())]);
|
||||
MachineError { stub, from: ErrorProvenance::Received }
|
||||
}
|
||||
|
||||
pub(super) fn domain_error(error: DomainError, culprit: Addr) -> Self {
|
||||
let stub = functor!("domain_error", 2, [heap_atom!(error.as_str()),
|
||||
HeapCellValue::Addr(culprit)]);
|
||||
@@ -135,6 +140,19 @@ impl ValidType {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum SyntaxError {
|
||||
ImpDepAtom
|
||||
}
|
||||
|
||||
impl SyntaxError {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
SyntaxError::ImpDepAtom => "imp_dep_atom"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum DomainError {
|
||||
NotLessThanZero
|
||||
|
||||
@@ -601,9 +601,13 @@ pub(crate) trait CallPolicy: Any {
|
||||
let addr = reader.machine_st[temp_v!(1)].clone();
|
||||
reader.machine_st.unify(addr, Addr::HeapCell(offset));
|
||||
},
|
||||
Err(err) => {
|
||||
println!("{:?}", err);
|
||||
reader.machine_st.fail = true;
|
||||
Err(_) => {
|
||||
// 8.14.1.3 k)-l)
|
||||
let stub = MachineError::functor_stub(clause_name!("read"), 1);
|
||||
let err = MachineError::syntax_error(SyntaxError::ImpDepAtom);
|
||||
let err = reader.machine_st.error_form(err, stub);
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user