re-factor options handling of read_term into read_term_body (#1887)
This commit is contained in:
@@ -5816,7 +5816,7 @@ impl Machine {
|
||||
let term_write_result = match term_write_result {
|
||||
Ok(term_write_result) => term_write_result,
|
||||
Err(e) => {
|
||||
let stub = functor_stub(atom!("read_term_from_chars"), 2);
|
||||
let stub = functor_stub(atom!("read_from_chars"), 2);
|
||||
let e = self.machine_st.session_error(SessionError::from(e));
|
||||
|
||||
return Err(self.machine_st.error_form(e, stub));
|
||||
@@ -5837,8 +5837,31 @@ impl Machine {
|
||||
#[inline(always)]
|
||||
pub(crate) fn read_term_from_chars(&mut self) -> CallResult {
|
||||
if let Some(atom_or_string) = self.machine_st.value_to_str_like(self.machine_st.registers[1]) {
|
||||
let stream = Stream::from_owned_string(atom_or_string.to_string(), &mut self.machine_st.arena);
|
||||
self.machine_st.read_term(stream, &mut self.indices)
|
||||
let chars = CharReader::new(ByteStream::from_string(atom_or_string.to_string()));
|
||||
let mut parser = Parser::new(chars, &mut self.machine_st);
|
||||
let op_dir = CompositeOpDir::new(&self.indices.op_dir, None);
|
||||
|
||||
let term_write_result = parser.read_term(&op_dir, Tokens::Default)
|
||||
.map_err(CompilationError::from)
|
||||
.and_then(|term| {
|
||||
write_term_to_heap(
|
||||
&term,
|
||||
&mut self.machine_st.heap,
|
||||
&mut self.machine_st.atom_tbl,
|
||||
)
|
||||
});
|
||||
|
||||
let term_write_result = match term_write_result {
|
||||
Ok(term_write_result) => term_write_result,
|
||||
Err(e) => {
|
||||
let stub = functor_stub(atom!("read_term_from_chars"), 3);
|
||||
let e = self.machine_st.session_error(SessionError::from(e));
|
||||
|
||||
return Err(self.machine_st.error_form(e, stub));
|
||||
}
|
||||
};
|
||||
|
||||
self.machine_st.read_term_body(term_write_result)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user