throw a representation error if max arity is exceeded (#1483)
This commit is contained in:
@@ -188,7 +188,7 @@ impl Machine {
|
||||
let value = self.machine_st.registers[2];
|
||||
unify_fn!(&mut self.machine_st, value, heap_loc_as_cell!(offset.heap_loc));
|
||||
}
|
||||
Err(ParserError::UnexpectedEOF) => {
|
||||
Err(CompilationError::ParserError(ParserError::UnexpectedEOF)) => {
|
||||
let value = self.machine_st.registers[2];
|
||||
self.machine_st.unify_atom(atom!("end_of_file"), value);
|
||||
}
|
||||
|
||||
@@ -452,6 +452,9 @@ impl MachineState {
|
||||
SessionError::OpIsInfixAndPostFix(op) => {
|
||||
self.permission_error(Permission::Create, atom!("operator"), functor!(op))
|
||||
}
|
||||
SessionError::CompilationError(CompilationError::ExceededMaxArity) => {
|
||||
self.representation_error(RepFlag::MaxArity)
|
||||
}
|
||||
SessionError::CompilationError(err) => self.syntax_error(err),
|
||||
SessionError::PredicateNotMultifileOrDiscontiguous(compilation_target, key) => {
|
||||
let functor_stub = functor_stub(key.0, key.1);
|
||||
@@ -586,6 +589,7 @@ pub enum CompilationError {
|
||||
Arithmetic(ArithmeticError),
|
||||
ParserError(ParserError),
|
||||
CannotParseCyclicTerm,
|
||||
ExceededMaxArity,
|
||||
ExpectedRel,
|
||||
InadmissibleFact,
|
||||
InadmissibleQueryTerm,
|
||||
@@ -629,6 +633,9 @@ impl CompilationError {
|
||||
&CompilationError::CannotParseCyclicTerm => {
|
||||
functor!(atom!("cannot_parse_cyclic_term"))
|
||||
}
|
||||
&CompilationError::ExceededMaxArity => {
|
||||
functor!(atom!("exceeded_max_arity"))
|
||||
}
|
||||
&CompilationError::ExpectedRel => {
|
||||
functor!(atom!("expected_relation"))
|
||||
}
|
||||
@@ -900,9 +907,7 @@ pub enum ExistenceError {
|
||||
pub enum SessionError {
|
||||
CompilationError(CompilationError),
|
||||
CannotOverwriteBuiltIn(PredicateKey),
|
||||
// CannotOverwriteImport(Atom),
|
||||
ExistenceError(ExistenceError),
|
||||
// InvalidFileName(Atom),
|
||||
ModuleDoesNotContainExport(Atom, PredicateKey),
|
||||
ModuleCannotImportSelf(Atom),
|
||||
NamelessEntry,
|
||||
|
||||
@@ -602,7 +602,7 @@ impl MachineState {
|
||||
return Ok(unify_fn!(*self, var_names_offset, var_names_addr));
|
||||
}
|
||||
Err(err) => {
|
||||
if let ParserError::UnexpectedEOF = err {
|
||||
if let CompilationError::ParserError(ParserError::UnexpectedEOF) = err {
|
||||
self.eof_action(
|
||||
self.registers[2],
|
||||
stream,
|
||||
|
||||
@@ -39,14 +39,14 @@ impl MockWAM {
|
||||
pub fn write_parsed_term_to_heap(
|
||||
&mut self,
|
||||
input_stream: Stream,
|
||||
) -> Result<TermWriteResult, ParserError> {
|
||||
) -> Result<TermWriteResult, CompilationError> {
|
||||
self.machine_st.read(input_stream, &self.op_dir)
|
||||
}
|
||||
|
||||
pub fn parse_and_write_parsed_term_to_heap(
|
||||
&mut self,
|
||||
term_string: &'static str,
|
||||
) -> Result<TermWriteResult, ParserError> {
|
||||
) -> Result<TermWriteResult, CompilationError> {
|
||||
let stream = Stream::from_static_string(term_string, &mut self.machine_st.arena);
|
||||
self.write_parsed_term_to_heap(stream)
|
||||
}
|
||||
@@ -54,7 +54,7 @@ impl MockWAM {
|
||||
pub fn parse_and_print_term(
|
||||
&mut self,
|
||||
term_string: &'static str,
|
||||
) -> Result<String, ParserError> {
|
||||
) -> Result<String, CompilationError> {
|
||||
let term_write_result = self.parse_and_write_parsed_term_to_heap(term_string)?;
|
||||
|
||||
print_heap_terms(self.machine_st.heap.iter(), term_write_result.heap_loc);
|
||||
@@ -200,7 +200,7 @@ pub(crate) fn write_parsed_term_to_heap(
|
||||
machine_st: &mut MachineState,
|
||||
input_stream: Stream,
|
||||
op_dir: &OpDir,
|
||||
) -> Result<TermWriteResult, ParserError> {
|
||||
) -> Result<TermWriteResult, CompilationError> {
|
||||
machine_st.read(input_stream, op_dir)
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ pub(crate) fn parse_and_write_parsed_term_to_heap(
|
||||
machine_st: &mut MachineState,
|
||||
term_string: &'static str,
|
||||
op_dir: &OpDir,
|
||||
) -> Result<TermWriteResult, ParserError> {
|
||||
) -> Result<TermWriteResult, CompilationError> {
|
||||
let stream = Stream::from_static_string(term_string, &mut machine_st.arena);
|
||||
write_parsed_term_to_heap(machine_st, stream, op_dir)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user