wrap resource_error into an error/2 functor and don't wrap it into a syntax_error functor
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use crate::atom_table::*;
|
||||
use crate::functor_macro::*;
|
||||
use crate::machine::machine_errors::CompilationError;
|
||||
use crate::machine::{ArenaHeaderTag, Fixnum, Integer};
|
||||
use crate::types::*;
|
||||
|
||||
@@ -16,10 +15,6 @@ const ALIGN: usize = Heap::heap_cell_alignment();
|
||||
pub struct AllocError;
|
||||
|
||||
impl AllocError {
|
||||
pub(crate) fn to_compilation_error(&self, heap: &mut Heap) -> CompilationError {
|
||||
CompilationError::FiniteMemoryInHeap(self.resource_error_offset(heap))
|
||||
}
|
||||
|
||||
pub(crate) fn resource_error_offset(&self, heap: &mut Heap) -> usize {
|
||||
heap.resource_error_offset()
|
||||
}
|
||||
@@ -706,7 +701,13 @@ impl Heap {
|
||||
|
||||
pub(crate) fn store_resource_error(&mut self) {
|
||||
RESOURCE_ERROR_OFFSET_INIT.call_once(move || {
|
||||
let stub = functor!(atom!("resource_error"), [atom_as_cell((atom!("memory")))]);
|
||||
let stub = functor!(
|
||||
atom!("error"),
|
||||
[
|
||||
functor((atom!("resource_error")), [atom_as_cell((atom!("memory")))]),
|
||||
atom_as_cell((atom!("[]")))
|
||||
]
|
||||
);
|
||||
self.resource_err_loc = cell_index!(self.inner.byte_len);
|
||||
|
||||
let mut writer = Heap::functor_writer(stub);
|
||||
|
||||
@@ -646,6 +646,19 @@ impl MachineState {
|
||||
return self.directive_error(err);
|
||||
}
|
||||
|
||||
if let CompilationError::FiniteMemoryInHeap(err) = err {
|
||||
// err.resource_error_offset() should be the address of the error/2 functor in the pre-allocated term error(resource_error(memory), [])
|
||||
let err_loc = err.resource_error_offset(&mut self.heap);
|
||||
let stub = vec![FunctorElement::AbsoluteCell(
|
||||
// err_loc + 1 should be the functors first argument which should be a str cell pointing at the resource_error/1 functor
|
||||
self.heap[err_loc + 1],
|
||||
)];
|
||||
return MachineError {
|
||||
stub,
|
||||
location: None,
|
||||
};
|
||||
}
|
||||
|
||||
let location = err.line_and_col_num();
|
||||
let stub = err.as_functor();
|
||||
|
||||
@@ -803,7 +816,13 @@ pub enum CompilationError {
|
||||
InvalidRuleHead,
|
||||
InvalidUseModuleDecl,
|
||||
InvalidModuleResolution(Atom),
|
||||
FiniteMemoryInHeap(usize),
|
||||
FiniteMemoryInHeap(AllocError),
|
||||
}
|
||||
|
||||
impl From<AllocError> for CompilationError {
|
||||
fn from(value: AllocError) -> Self {
|
||||
Self::FiniteMemoryInHeap(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -879,8 +898,8 @@ impl CompilationError {
|
||||
CompilationError::ParserError(ref err) => {
|
||||
functor!(err.as_atom())
|
||||
}
|
||||
CompilationError::FiniteMemoryInHeap(h) => {
|
||||
vec![FunctorElement::AbsoluteCell(str_loc_as_cell!(*h))]
|
||||
CompilationError::FiniteMemoryInHeap(_) => {
|
||||
functor!(atom!("resource_error"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user