{
let mod_name = HeapCellValue::Addr(Addr::Con(Constant::Atom(mod_name)));
let name = HeapCellValue::Addr(Addr::Con(Constant::Atom(name)));
-
+
let mut stub = functor!("evaluation_error", 1, [HeapCellValue::Addr(Addr::HeapCell(h + 2))]);
-
+
stub.append(&mut functor!("/", 2, [HeapCellValue::Addr(Addr::HeapCell(h + 2 + 3)),
heap_integer!(arity)],
Fixity::In));
MachineError { stub, from: ErrorProvenance::Constructed }
}
-
+
pub(super) fn existence_error(h: usize, name: ClauseName, arity: usize) -> Self {
let mut stub = functor!("existence_error", 2, [heap_atom!("procedure"), heap_str!(3 + h)]);
stub.append(&mut Self::functor_stub(name, arity));
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 syntax_error(h: usize, err: ParserError) -> Self {
+ let err = match err {
+ ParserError::Arithmetic(_) =>
+ vec![heap_atom!("arithmetic_error")],
+ ParserError::BackQuotedString =>
+ vec![heap_atom!("back_quoted_string")],
+ ParserError::UnexpectedChar(c) =>
+ functor!("unexpected_char", 1, [heap_char!(c)]),
+ ParserError::UnexpectedEOF =>
+ vec![heap_atom!("unexpected_end_of_file")],
+ ParserError::ExpectedRel =>
+ vec![heap_atom!("expected_relation")],
+ ParserError::InadmissibleFact =>
+ vec![heap_atom!("inadmissible_fact")],
+ ParserError::InadmissibleQueryTerm =>
+ vec![heap_atom!("inadmissible_query_term")],
+ ParserError::IncompleteReduction =>
+ vec![heap_atom!("incomplete_reduction")],
+ ParserError::InconsistentEntry =>
+ vec![heap_atom!("inconsistent_entry")],
+ ParserError::InvalidModuleDecl =>
+ vec![heap_atom!("invalid_module_declaration")],
+ ParserError::InvalidModuleExport =>
+ vec![heap_atom!("invalid_module_export")],
+ ParserError::InvalidModuleResolution =>
+ vec![heap_atom!("invalid_module_resolution")],
+ ParserError::InvalidRuleHead =>
+ vec![heap_atom!("invalid_head_of_rule")],
+ ParserError::InvalidUseModuleDecl =>
+ vec![heap_atom!("invalid_use_module_declaration")],
+ ParserError::IO(_) =>
+ vec![heap_atom!("input_output_error")],
+ ParserError::MissingQuote =>
+ vec![heap_atom!("missing_quote")],
+ ParserError::NonPrologChar =>
+ vec![heap_atom!("non_prolog_character")],
+ ParserError::ParseBigInt =>
+ vec![heap_atom!("cannot_parse_big_int")],
+ ParserError::ParseFloat =>
+ vec![heap_atom!("cannot_parse_float")],
+ ParserError::Utf8Conversion(_) =>
+ vec![heap_atom!("utf8_conversion_error")]
+ };
+
+ let mut stub = if err.len() == 1 {
+ functor!("syntax_error", 1)
+ } else {
+ functor!("syntax_error", 1, [heap_str!(h + 2)])
+ };
+
+ stub.extend(err.into_iter());
+ MachineError { stub, from: ErrorProvenance::Constructed }
}
-
+
pub(super) fn domain_error(error: DomainError, culprit: Addr) -> Self {
let stub = functor!("domain_error", 2, [heap_atom!(error.as_str()),
HeapCellValue::Addr(culprit)]);
}
}
-#[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
)
}
+macro_rules! heap_char {
+ ($c:expr) => (
+ HeapCellValue::Addr(Addr::Con(Constant::Char($c)))
+ )
+}
+
macro_rules! heap_atom {
($name:expr) => (
HeapCellValue::Addr(Addr::Con(atom!($name)))
($name:expr) => (
vec![ heap_atom!($name) ]
);
+ ($name:expr, $len:expr) => (
+ vec![ HeapCellValue::NamedStr($len, clause_name!($name), None) ]
+ );
($name:expr, $len:expr, [$($args:expr),*]) => (
vec![ HeapCellValue::NamedStr($len, clause_name!($name), None), $($args),* ]
);
($name:expr, $len:expr, [$($args:expr),*], $fix: expr) => (
vec![ HeapCellValue::NamedStr($len, clause_name!($name), Some($fix)), $($args),* ]
- )
+ );
}
macro_rules! temp_v {