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::atom_table::*;
|
||||||
use crate::functor_macro::*;
|
use crate::functor_macro::*;
|
||||||
use crate::machine::machine_errors::CompilationError;
|
|
||||||
use crate::machine::{ArenaHeaderTag, Fixnum, Integer};
|
use crate::machine::{ArenaHeaderTag, Fixnum, Integer};
|
||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
|
|
||||||
@@ -16,10 +15,6 @@ const ALIGN: usize = Heap::heap_cell_alignment();
|
|||||||
pub struct AllocError;
|
pub struct AllocError;
|
||||||
|
|
||||||
impl 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 {
|
pub(crate) fn resource_error_offset(&self, heap: &mut Heap) -> usize {
|
||||||
heap.resource_error_offset()
|
heap.resource_error_offset()
|
||||||
}
|
}
|
||||||
@@ -706,7 +701,13 @@ impl Heap {
|
|||||||
|
|
||||||
pub(crate) fn store_resource_error(&mut self) {
|
pub(crate) fn store_resource_error(&mut self) {
|
||||||
RESOURCE_ERROR_OFFSET_INIT.call_once(move || {
|
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);
|
self.resource_err_loc = cell_index!(self.inner.byte_len);
|
||||||
|
|
||||||
let mut writer = Heap::functor_writer(stub);
|
let mut writer = Heap::functor_writer(stub);
|
||||||
|
|||||||
@@ -646,6 +646,19 @@ impl MachineState {
|
|||||||
return self.directive_error(err);
|
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 location = err.line_and_col_num();
|
||||||
let stub = err.as_functor();
|
let stub = err.as_functor();
|
||||||
|
|
||||||
@@ -803,7 +816,13 @@ pub enum CompilationError {
|
|||||||
InvalidRuleHead,
|
InvalidRuleHead,
|
||||||
InvalidUseModuleDecl,
|
InvalidUseModuleDecl,
|
||||||
InvalidModuleResolution(Atom),
|
InvalidModuleResolution(Atom),
|
||||||
FiniteMemoryInHeap(usize),
|
FiniteMemoryInHeap(AllocError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AllocError> for CompilationError {
|
||||||
|
fn from(value: AllocError) -> Self {
|
||||||
|
Self::FiniteMemoryInHeap(value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -879,8 +898,8 @@ impl CompilationError {
|
|||||||
CompilationError::ParserError(ref err) => {
|
CompilationError::ParserError(ref err) => {
|
||||||
functor!(err.as_atom())
|
functor!(err.as_atom())
|
||||||
}
|
}
|
||||||
CompilationError::FiniteMemoryInHeap(h) => {
|
CompilationError::FiniteMemoryInHeap(_) => {
|
||||||
vec![FunctorElement::AbsoluteCell(str_loc_as_cell!(*h))]
|
functor!(atom!("resource_error"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/read.rs
14
src/read.rs
@@ -379,9 +379,7 @@ impl<'a> TermWriter<'a> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn push_cell(&mut self, cell: HeapCellValue) -> Result<(), CompilationError> {
|
fn push_cell(&mut self, cell: HeapCellValue) -> Result<(), CompilationError> {
|
||||||
self.heap
|
Ok(self.heap.push_cell(cell)?)
|
||||||
.push_cell(cell)
|
|
||||||
.map_err(|err| err.to_compilation_error(self.heap))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn term_as_addr(&mut self, term: &TermRef, h: usize) -> HeapCellValue {
|
fn term_as_addr(&mut self, term: &TermRef, h: usize) -> HeapCellValue {
|
||||||
@@ -475,10 +473,7 @@ impl<'a> TermWriter<'a> {
|
|||||||
self.push_stub_addr()?;
|
self.push_stub_addr()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cell = self
|
let cell = self.heap.allocate_cstr(src)?;
|
||||||
.heap
|
|
||||||
.allocate_cstr(src)
|
|
||||||
.map_err(|err| err.to_compilation_error(self.heap))?;
|
|
||||||
|
|
||||||
let new_h = self.heap.cell_len();
|
let new_h = self.heap.cell_len();
|
||||||
self.push_cell(cell)?;
|
self.push_cell(cell)?;
|
||||||
@@ -496,10 +491,7 @@ impl<'a> TermWriter<'a> {
|
|||||||
self.push_stub_addr()?;
|
self.push_stub_addr()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cell = self
|
let cell = self.heap.allocate_pstr(src)?;
|
||||||
.heap
|
|
||||||
.allocate_pstr(src)
|
|
||||||
.map_err(|err| err.to_compilation_error(self.heap))?;
|
|
||||||
|
|
||||||
let tail_h = self.heap.cell_len();
|
let tail_h = self.heap.cell_len();
|
||||||
self.push_stub_addr()?;
|
self.push_stub_addr()?;
|
||||||
|
|||||||
Reference in New Issue
Block a user