[WIP] fix deadlock in AtomTable::build_with
This commit is contained in:
@@ -1237,12 +1237,10 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
|
||||
if let Some(path_str) = load_context.path.to_str() {
|
||||
if !path_str.is_empty() {
|
||||
return Some(
|
||||
LS::machine_st(&mut self.payload)
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(path_str),
|
||||
);
|
||||
return Some(AtomTable::build_with(
|
||||
&LS::machine_st(&mut self.payload).atom_tbl,
|
||||
path_str,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,21 +406,15 @@ mod tests {
|
||||
|
||||
wam.machine_st.heap.clear();
|
||||
|
||||
let pstr_var_cell = put_partial_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"abc ",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
let pstr_var_cell =
|
||||
put_partial_string(&mut wam.machine_st.heap, "abc ", &wam.machine_st.atom_tbl);
|
||||
let pstr_cell = wam.machine_st.heap[pstr_var_cell.get_value() as usize];
|
||||
|
||||
wam.machine_st.heap.pop();
|
||||
wam.machine_st.heap.push(pstr_loc_as_cell!(2));
|
||||
|
||||
let pstr_second_var_cell = put_partial_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"def",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
let pstr_second_var_cell =
|
||||
put_partial_string(&mut wam.machine_st.heap, "def", &wam.machine_st.atom_tbl);
|
||||
let pstr_second_cell = wam.machine_st.heap[pstr_second_var_cell.get_value() as usize];
|
||||
|
||||
wam.machine_st.heap.pop();
|
||||
|
||||
@@ -644,11 +644,8 @@ mod tests {
|
||||
// two-part complete string, then a three-part cyclic string
|
||||
// involving an uncompacted list of chars.
|
||||
|
||||
let pstr_var_cell = put_partial_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"abc ",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
let pstr_var_cell =
|
||||
put_partial_string(&mut wam.machine_st.heap, "abc ", &wam.machine_st.atom_tbl);
|
||||
let pstr_cell = wam.machine_st.heap[pstr_var_cell.get_value() as usize];
|
||||
|
||||
mark_cells(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
|
||||
@@ -669,11 +666,8 @@ mod tests {
|
||||
|
||||
wam.machine_st.heap.push(pstr_loc_as_cell!(2));
|
||||
|
||||
let pstr_second_var_cell = put_partial_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"def",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
let pstr_second_var_cell =
|
||||
put_partial_string(&mut wam.machine_st.heap, "def", &wam.machine_st.atom_tbl);
|
||||
let pstr_second_cell = wam.machine_st.heap[pstr_second_var_cell.get_value() as usize];
|
||||
|
||||
mark_cells(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::arena::*;
|
||||
use crate::atom_table::*;
|
||||
use crate::forms::*;
|
||||
@@ -133,7 +135,7 @@ pub fn print_heap_terms<'a, I: Iterator<Item = &'a HeapCellValue>>(heap: I, h: u
|
||||
pub(crate) fn put_complete_string(
|
||||
heap: &mut Heap,
|
||||
s: &str,
|
||||
atom_tbl: &mut AtomTable,
|
||||
atom_tbl: &RwLock<AtomTable>,
|
||||
) -> HeapCellValue {
|
||||
match allocate_pstr(heap, s, atom_tbl) {
|
||||
Some(h) => {
|
||||
@@ -160,7 +162,7 @@ pub(crate) fn put_complete_string(
|
||||
pub(crate) fn put_partial_string(
|
||||
heap: &mut Heap,
|
||||
s: &str,
|
||||
atom_tbl: &mut AtomTable,
|
||||
atom_tbl: &RwLock<AtomTable>,
|
||||
) -> HeapCellValue {
|
||||
match allocate_pstr(heap, s, atom_tbl) {
|
||||
Some(h) => {
|
||||
@@ -176,7 +178,7 @@ pub(crate) fn put_partial_string(
|
||||
pub(crate) fn allocate_pstr(
|
||||
heap: &mut Heap,
|
||||
mut src: &str,
|
||||
atom_tbl: &mut AtomTable,
|
||||
atom_tbl: &RwLock<AtomTable>,
|
||||
) -> Option<usize> {
|
||||
let orig_h = heap.len();
|
||||
|
||||
|
||||
@@ -1076,7 +1076,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
|
||||
let export_list = machine_st.read_term_from_heap(cell)?;
|
||||
let atom_tbl = &mut LS::machine_st(&mut self.payload).atom_tbl;
|
||||
let export_list = setup_module_export_list(export_list, &mut atom_tbl.blocking_write())?;
|
||||
let export_list = setup_module_export_list(export_list, &atom_tbl)?;
|
||||
|
||||
Ok(export_list.into_iter().collect())
|
||||
}
|
||||
@@ -1420,7 +1420,7 @@ impl MachineState {
|
||||
term_stack.push(Term::PartialString(Cell::default(), string, tail));
|
||||
}
|
||||
Ok((string, None)) => {
|
||||
let atom = self.atom_tbl.blocking_write().build_with(&string);
|
||||
let atom = AtomTable::build_with(&self.atom_tbl, &string);
|
||||
term_stack.push(Term::CompleteString(Cell::default(), atom));
|
||||
}
|
||||
Err(cons_term) => term_stack.push(cons_term),
|
||||
@@ -1917,11 +1917,7 @@ impl Machine {
|
||||
pub(crate) fn load_context_source(&mut self) {
|
||||
if let Some(load_context) = self.load_contexts.last() {
|
||||
let path_str = load_context.path.to_str().unwrap();
|
||||
let path_atom = self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(path_str);
|
||||
let path_atom = AtomTable::build_with(&self.machine_st.atom_tbl, path_str);
|
||||
|
||||
self.machine_st
|
||||
.unify_atom(path_atom, self.machine_st.registers[1]);
|
||||
@@ -1935,11 +1931,8 @@ impl Machine {
|
||||
match load_context.path.file_name() {
|
||||
Some(file_name) if load_context.path.is_file() => {
|
||||
let file_name_str = file_name.to_str().unwrap();
|
||||
let file_name_atom = self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(file_name_str);
|
||||
let file_name_atom =
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, file_name_str);
|
||||
|
||||
self.machine_st
|
||||
.unify_atom(file_name_atom, self.machine_st.registers[1]);
|
||||
@@ -1958,11 +1951,8 @@ impl Machine {
|
||||
if let Some(load_context) = self.load_contexts.last() {
|
||||
if let Some(directory) = load_context.path.parent() {
|
||||
let directory_str = directory.to_str().unwrap();
|
||||
let directory_atom = self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(directory_str);
|
||||
let directory_atom =
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, directory_str);
|
||||
|
||||
self.machine_st
|
||||
.unify_atom(directory_atom, self.machine_st.registers[1]);
|
||||
|
||||
@@ -205,12 +205,12 @@ pub fn pstr_loc_and_offset(heap: &[HeapCellValue], index: usize) -> (usize, Fixn
|
||||
fn push_var_eq_functors<'a>(
|
||||
heap: &mut Heap,
|
||||
iter: impl Iterator<Item = (&'a VarKey, &'a HeapCellValue)>,
|
||||
atom_tbl: &mut AtomTable,
|
||||
atom_tbl: &RwLock<AtomTable>,
|
||||
) -> Vec<HeapCellValue> {
|
||||
let mut list_of_var_eqs = vec![];
|
||||
|
||||
for (var, binding) in iter {
|
||||
let var_atom = atom_tbl.build_with(&var.to_string());
|
||||
let var_atom = AtomTable::build_with(atom_tbl, &var.to_string());
|
||||
let h = heap.len();
|
||||
|
||||
heap.push(atom_as_cell!(atom!("="), 2));
|
||||
@@ -531,7 +531,7 @@ impl MachineState {
|
||||
Some((var_name, var))
|
||||
}
|
||||
}),
|
||||
&mut self.atom_tbl.blocking_write(),
|
||||
&self.atom_tbl,
|
||||
);
|
||||
|
||||
let singleton_addr = self.registers[3];
|
||||
@@ -617,7 +617,7 @@ impl MachineState {
|
||||
false
|
||||
}
|
||||
}),
|
||||
&mut self.atom_tbl.blocking_write(),
|
||||
&self.atom_tbl,
|
||||
);
|
||||
|
||||
for var in term_write_result.var_dict.values_mut() {
|
||||
|
||||
@@ -1003,9 +1003,9 @@ impl MachineState {
|
||||
self.s_offset = 0;
|
||||
self.mode = MachineMode::Read;
|
||||
|
||||
put_partial_string(&mut self.heap, pstr, &mut self.atom_tbl.blocking_write())
|
||||
put_partial_string(&mut self.heap, pstr, &self.atom_tbl)
|
||||
} else {
|
||||
put_complete_string(&mut self.heap, pstr, &mut self.atom_tbl.blocking_write())
|
||||
put_complete_string(&mut self.heap, pstr, &self.atom_tbl)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1097,7 +1097,7 @@ impl MachineState {
|
||||
(name, 0, 0)
|
||||
}
|
||||
(HeapCellValueTag::Char, c) => {
|
||||
(self.atom_tbl.blocking_write().build_with(&c.to_string()), 0, 0)
|
||||
(AtomTable::build_with(&self.atom_tbl, &c.to_string()), 0, 0)
|
||||
}
|
||||
(HeapCellValueTag::Var | HeapCellValueTag::AttrVar | HeapCellValueTag::StackVar) => {
|
||||
let stub = functor_stub(atom!("call"), arity + 1);
|
||||
@@ -1436,7 +1436,7 @@ impl MachineState {
|
||||
}
|
||||
}
|
||||
(HeapCellValueTag::Char, c) => {
|
||||
let c = self.atom_tbl.blocking_write().build_with(&c.to_string());
|
||||
let c = AtomTable::build_with(&self.atom_tbl, &c.to_string());
|
||||
|
||||
self.try_functor_fabricate_struct(
|
||||
c,
|
||||
|
||||
@@ -231,7 +231,7 @@ impl Machine {
|
||||
pub fn load_file(&mut self, path: &str, stream: Stream) {
|
||||
self.machine_st.registers[1] = stream_as_cell!(stream);
|
||||
self.machine_st.registers[2] =
|
||||
atom_as_cell!(self.machine_st.atom_tbl.blocking_write().build_with(path));
|
||||
atom_as_cell!(AtomTable::build_with(&self.machine_st.atom_tbl, path));
|
||||
|
||||
self.run_module_predicate(atom!("loader"), (atom!("file_load"), 2));
|
||||
}
|
||||
@@ -296,7 +296,7 @@ impl Machine {
|
||||
arg_pstrs.push(put_complete_string(
|
||||
&mut self.machine_st.heap,
|
||||
&arg,
|
||||
&mut self.machine_st.atom_tbl.blocking_write(),
|
||||
&self.machine_st.atom_tbl,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::atom_table::*;
|
||||
use crate::parser::ast::*;
|
||||
|
||||
@@ -43,10 +45,9 @@ impl Into<Atom> for PartialString {
|
||||
|
||||
impl PartialString {
|
||||
#[inline]
|
||||
pub(super) fn new<'a>(src: &'a str, atom_tbl: &mut AtomTable) -> Option<(Self, &'a str)> {
|
||||
pub(super) fn new<'a>(src: &'a str, atom_tbl: &RwLock<AtomTable>) -> Option<(Self, &'a str)> {
|
||||
let terminator_idx = scan_for_terminator(src.chars());
|
||||
let pstr = PartialString(atom_tbl.build_with(&src[..terminator_idx]));
|
||||
|
||||
let pstr = PartialString(AtomTable::build_with(&atom_tbl, &src[..terminator_idx]));
|
||||
Some(if terminator_idx < src.as_bytes().len() {
|
||||
(pstr, &src[terminator_idx + 1..])
|
||||
} else {
|
||||
@@ -805,11 +806,8 @@ mod test {
|
||||
fn pstr_iter_tests() {
|
||||
let mut wam = MockWAM::new();
|
||||
|
||||
let pstr_var_cell = put_partial_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"abc ",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
let pstr_var_cell =
|
||||
put_partial_string(&mut wam.machine_st.heap, "abc ", &wam.machine_st.atom_tbl);
|
||||
|
||||
let pstr_cell = wam.machine_st.heap[pstr_var_cell.get_value() as usize];
|
||||
|
||||
@@ -828,11 +826,8 @@ mod test {
|
||||
wam.machine_st.heap.pop();
|
||||
wam.machine_st.heap.push(pstr_loc_as_cell!(2));
|
||||
|
||||
let pstr_second_var_cell = put_partial_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"def",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
let pstr_second_var_cell =
|
||||
put_partial_string(&mut wam.machine_st.heap, "def", &wam.machine_st.atom_tbl);
|
||||
|
||||
let pstr_second_cell = wam.machine_st.heap[pstr_second_var_cell.get_value() as usize];
|
||||
|
||||
@@ -913,21 +908,13 @@ mod test {
|
||||
// construct a structurally similar but different cyclic partial string
|
||||
// matching the one beginning at wam.machine_st.heap[0].
|
||||
|
||||
put_partial_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"ab",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
put_partial_string(&mut wam.machine_st.heap, "ab", &wam.machine_st.atom_tbl);
|
||||
|
||||
wam.machine_st.heap.pop();
|
||||
|
||||
wam.machine_st.heap.push(pstr_loc_as_cell!(second_h + 2));
|
||||
|
||||
put_partial_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"c ",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
put_partial_string(&mut wam.machine_st.heap, "c ", &wam.machine_st.atom_tbl);
|
||||
|
||||
wam.machine_st.heap.pop();
|
||||
|
||||
@@ -952,11 +939,7 @@ mod test {
|
||||
|
||||
wam.machine_st.heap.clear();
|
||||
|
||||
put_partial_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"abc ",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
put_partial_string(&mut wam.machine_st.heap, "abc ", &wam.machine_st.atom_tbl);
|
||||
|
||||
let pstr_cell = wam.machine_st.heap[0];
|
||||
|
||||
@@ -986,11 +969,8 @@ mod test {
|
||||
|
||||
wam.machine_st.heap.clear();
|
||||
|
||||
let cstr_var_cell = put_complete_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"abc",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
let cstr_var_cell =
|
||||
put_complete_string(&mut wam.machine_st.heap, "abc", &wam.machine_st.atom_tbl);
|
||||
|
||||
wam.machine_st.heap.push(list_loc_as_cell!(2));
|
||||
wam.machine_st.heap.push(heap_loc_as_cell!(2));
|
||||
@@ -1015,11 +995,8 @@ mod test {
|
||||
|
||||
wam.machine_st.heap.clear();
|
||||
|
||||
let cstr_var_cell = put_complete_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"abc",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
let cstr_var_cell =
|
||||
put_complete_string(&mut wam.machine_st.heap, "abc", &wam.machine_st.atom_tbl);
|
||||
|
||||
wam.machine_st.heap.push(list_loc_as_cell!(2));
|
||||
wam.machine_st.heap.push(heap_loc_as_cell!(2)); // X
|
||||
@@ -1048,11 +1025,8 @@ mod test {
|
||||
|
||||
wam.machine_st.heap.clear();
|
||||
|
||||
let cstr_var_cell = put_complete_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"d",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
let cstr_var_cell =
|
||||
put_complete_string(&mut wam.machine_st.heap, "d", &wam.machine_st.atom_tbl);
|
||||
|
||||
wam.machine_st.heap.push(list_loc_as_cell!(2));
|
||||
wam.machine_st.heap.push(char_as_cell!('d'));
|
||||
@@ -1066,11 +1040,8 @@ mod test {
|
||||
|
||||
wam.machine_st.heap.clear();
|
||||
|
||||
let cstr_var_cell = put_complete_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"abc",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
let cstr_var_cell =
|
||||
put_complete_string(&mut wam.machine_st.heap, "abc", &wam.machine_st.atom_tbl);
|
||||
|
||||
wam.machine_st.heap.push(list_loc_as_cell!(2));
|
||||
wam.machine_st.heap.push(heap_loc_as_cell!(2));
|
||||
@@ -1097,11 +1068,7 @@ mod test {
|
||||
|
||||
wam.machine_st.heap.clear();
|
||||
|
||||
put_complete_string(
|
||||
&mut wam.machine_st.heap,
|
||||
"abcdef",
|
||||
&mut wam.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
put_complete_string(&mut wam.machine_st.heap, "abcdef", &wam.machine_st.atom_tbl);
|
||||
|
||||
wam.machine_st.heap.push(pstr_as_cell!(atom!("abc")));
|
||||
wam.machine_st.heap.push(heap_loc_as_cell!(2));
|
||||
|
||||
@@ -8,6 +8,7 @@ use crate::machine::machine_errors::*;
|
||||
use crate::parser::ast::*;
|
||||
|
||||
use indexmap::IndexSet;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::convert::TryFrom;
|
||||
@@ -27,17 +28,17 @@ pub(crate) fn to_op_decl(prec: u16, spec: Atom, name: Atom) -> Result<OpDecl, Co
|
||||
|
||||
fn setup_op_decl(
|
||||
mut terms: Vec<Term>,
|
||||
atom_tbl: &mut AtomTable,
|
||||
atom_tbl: &RwLock<AtomTable>,
|
||||
) -> Result<OpDecl, CompilationError> {
|
||||
let name = match terms.pop().unwrap() {
|
||||
Term::Literal(_, Literal::Atom(name)) => name,
|
||||
Term::Literal(_, Literal::Char(c)) => atom_tbl.build_with(&c.to_string()),
|
||||
Term::Literal(_, Literal::Char(c)) => AtomTable::build_with(atom_tbl, &c.to_string()),
|
||||
_ => return Err(CompilationError::InconsistentEntry),
|
||||
};
|
||||
|
||||
let spec = match terms.pop().unwrap() {
|
||||
Term::Literal(_, Literal::Atom(name)) => name,
|
||||
Term::Literal(_, Literal::Char(c)) => atom_tbl.build_with(&c.to_string()),
|
||||
Term::Literal(_, Literal::Char(c)) => AtomTable::build_with(atom_tbl, &c.to_string()),
|
||||
_ => return Err(CompilationError::InconsistentEntry),
|
||||
};
|
||||
|
||||
@@ -85,7 +86,7 @@ fn setup_predicate_indicator(term: &mut Term) -> Result<PredicateKey, Compilatio
|
||||
|
||||
fn setup_module_export(
|
||||
mut term: Term,
|
||||
atom_tbl: &mut AtomTable,
|
||||
atom_tbl: &RwLock<AtomTable>,
|
||||
) -> Result<ModuleExport, CompilationError> {
|
||||
setup_predicate_indicator(&mut term)
|
||||
.map(ModuleExport::PredicateKey)
|
||||
@@ -111,7 +112,7 @@ pub(crate) fn build_rule_body(vars: &[Term], body_term: Term) -> Term {
|
||||
|
||||
pub(super) fn setup_module_export_list(
|
||||
mut export_list: Term,
|
||||
atom_tbl: &mut AtomTable,
|
||||
atom_tbl: &RwLock<AtomTable>,
|
||||
) -> Result<Vec<ModuleExport>, CompilationError> {
|
||||
let mut exports = vec![];
|
||||
|
||||
@@ -131,7 +132,7 @@ pub(super) fn setup_module_export_list(
|
||||
|
||||
fn setup_module_decl(
|
||||
mut terms: Vec<Term>,
|
||||
atom_tbl: &mut AtomTable,
|
||||
atom_tbl: &RwLock<AtomTable>,
|
||||
) -> Result<ModuleDecl, CompilationError> {
|
||||
let export_list = terms.pop().unwrap();
|
||||
let name = terms.pop().unwrap();
|
||||
@@ -164,7 +165,7 @@ type UseModuleExport = (ModuleSource, IndexSet<ModuleExport>);
|
||||
|
||||
fn setup_qualified_import(
|
||||
mut terms: Vec<Term>,
|
||||
atom_tbl: &mut AtomTable,
|
||||
atom_tbl: &RwLock<AtomTable>,
|
||||
) -> Result<UseModuleExport, CompilationError> {
|
||||
let mut export_list = terms.pop().unwrap();
|
||||
let module_src = match terms.pop().unwrap() {
|
||||
@@ -313,17 +314,11 @@ pub(super) fn setup_declaration<'a, LS: LoadState<'a>>(
|
||||
}
|
||||
(atom!("module"), 2) => {
|
||||
let atom_tbl = &mut LS::machine_st(&mut loader.payload).atom_tbl;
|
||||
Ok(Declaration::Module(setup_module_decl(
|
||||
terms,
|
||||
&mut atom_tbl.blocking_write(),
|
||||
)?))
|
||||
Ok(Declaration::Module(setup_module_decl(terms, &atom_tbl)?))
|
||||
}
|
||||
(atom!("op"), 3) => {
|
||||
let atom_tbl = &mut LS::machine_st(&mut loader.payload).atom_tbl;
|
||||
Ok(Declaration::Op(setup_op_decl(
|
||||
terms,
|
||||
&mut atom_tbl.blocking_write(),
|
||||
)?))
|
||||
Ok(Declaration::Op(setup_op_decl(terms, &atom_tbl)?))
|
||||
}
|
||||
(atom!("non_counted_backtracking"), 1) => {
|
||||
let (name, arity) = setup_predicate_indicator(&mut terms.pop().unwrap())?;
|
||||
@@ -332,8 +327,7 @@ pub(super) fn setup_declaration<'a, LS: LoadState<'a>>(
|
||||
(atom!("use_module"), 1) => Ok(Declaration::UseModule(setup_use_module_decl(terms)?)),
|
||||
(atom!("use_module"), 2) => {
|
||||
let atom_tbl = &mut LS::machine_st(&mut loader.payload).atom_tbl;
|
||||
let (name, exports) =
|
||||
setup_qualified_import(terms, &mut atom_tbl.blocking_write())?;
|
||||
let (name, exports) = setup_qualified_import(terms, &atom_tbl)?;
|
||||
|
||||
Ok(Declaration::UseQualifiedModule(name, exports))
|
||||
}
|
||||
|
||||
@@ -1529,7 +1529,7 @@ impl Machine {
|
||||
}
|
||||
}
|
||||
(HeapCellValueTag::Char, c) => {
|
||||
let name = self.machine_st.atom_tbl.blocking_write().build_with(&c.to_string());
|
||||
let name = AtomTable::build_with(&self.machine_st.atom_tbl,&c.to_string());
|
||||
|
||||
let h = self.machine_st.heap.len();
|
||||
self.machine_st.heap.push(atom_as_cell!(name));
|
||||
@@ -1804,7 +1804,7 @@ impl Machine {
|
||||
match hostname::get().ok() {
|
||||
Some(host) => match host.to_str() {
|
||||
Some(host) => {
|
||||
let hostname = self.machine_st.atom_tbl.blocking_write().build_with(host);
|
||||
let hostname = AtomTable::build_with(&self.machine_st.atom_tbl, host);
|
||||
|
||||
let a1 = self.deref_register(1);
|
||||
self.machine_st.unify_atom(hostname, a1);
|
||||
@@ -1903,7 +1903,7 @@ impl Machine {
|
||||
for entry in entries {
|
||||
if let Ok(entry) = entry {
|
||||
if let Some(name) = entry.file_name().to_str() {
|
||||
let name = self.machine_st.atom_tbl.blocking_write().build_with(name);
|
||||
let name = AtomTable::build_with(&self.machine_st.atom_tbl, name);
|
||||
files.push(atom_as_cstr_cell!(name));
|
||||
|
||||
continue;
|
||||
@@ -2144,11 +2144,7 @@ impl Machine {
|
||||
}
|
||||
};
|
||||
|
||||
let current_atom = self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(¤t);
|
||||
let current_atom = AtomTable::build_with(&self.machine_st.atom_tbl, ¤t);
|
||||
|
||||
let a1 = self.deref_register(1);
|
||||
self.machine_st.unify_complete_string(current_atom, a1);
|
||||
@@ -2189,7 +2185,7 @@ impl Machine {
|
||||
}
|
||||
};
|
||||
|
||||
let canonical_atom = self.machine_st.atom_tbl.blocking_write().build_with(cs);
|
||||
let canonical_atom = AtomTable::build_with(&self.machine_st.atom_tbl, cs);
|
||||
|
||||
let a2 = self.deref_register(2);
|
||||
self.machine_st.unify_complete_string(canonical_atom, a2);
|
||||
@@ -2248,13 +2244,13 @@ impl Machine {
|
||||
let atom_cell = match str_like {
|
||||
AtomOrString::Atom(atom) => {
|
||||
atom_as_cell!(if atom == atom!("[]") {
|
||||
self.machine_st.atom_tbl.blocking_write().build_with("")
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, "")
|
||||
} else {
|
||||
atom
|
||||
})
|
||||
}
|
||||
AtomOrString::String(string) => {
|
||||
atom_as_cell!(self.machine_st.atom_tbl.blocking_write().build_with(&string))
|
||||
atom_as_cell!(AtomTable::build_with(&self.machine_st.atom_tbl, &string))
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2316,7 +2312,7 @@ impl Machine {
|
||||
match self.machine_st.try_from_list(self.machine_st.registers[2], stub_gen) {
|
||||
Ok(addrs) => {
|
||||
let string = self.machine_st.codes_to_string(addrs.into_iter(), stub_gen)?;
|
||||
let atom = self.machine_st.atom_tbl.blocking_write().build_with(&string);
|
||||
let atom = AtomTable::build_with(&self.machine_st.atom_tbl, &string);
|
||||
|
||||
self.machine_st.bind(a1.as_var().unwrap(), atom_as_cell!(atom));
|
||||
}
|
||||
@@ -2810,11 +2806,7 @@ impl Machine {
|
||||
}
|
||||
};
|
||||
|
||||
let chars_atom = self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(&string.trim());
|
||||
let chars_atom = AtomTable::build_with(&self.machine_st.atom_tbl, &string.trim());
|
||||
self.machine_st.unify_complete_string(chars_atom, chs);
|
||||
}
|
||||
|
||||
@@ -3040,14 +3032,14 @@ impl Machine {
|
||||
match (name, arity) {
|
||||
(atom!("to_upper"), 1) => {
|
||||
let reg = self.machine_st.deref(self.machine_st.heap[s+1]);
|
||||
let atom = self.machine_st.atom_tbl.blocking_write().build_with(&c.to_uppercase().to_string());
|
||||
let atom = AtomTable::build_with(&self.machine_st.atom_tbl, &c.to_uppercase().to_string());
|
||||
let upper_str = string_as_cstr_cell!(atom);
|
||||
unify!(self.machine_st, reg, upper_str);
|
||||
self.machine_st.fail = false;
|
||||
}
|
||||
(atom!("to_lower"), 1) => {
|
||||
let reg = self.machine_st.deref(self.machine_st.heap[s+1]);
|
||||
let atom = self.machine_st.atom_tbl.blocking_write().build_with(&c.to_lowercase().to_string());
|
||||
let atom = AtomTable::build_with(&self.machine_st.atom_tbl, &c.to_lowercase().to_string());
|
||||
let lower_str = string_as_cstr_cell!(atom);
|
||||
unify!(self.machine_st, reg, lower_str);
|
||||
self.machine_st.fail = false;
|
||||
@@ -3570,11 +3562,7 @@ impl Machine {
|
||||
};
|
||||
|
||||
let output = self.deref_register(3);
|
||||
let atom = self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(&string);
|
||||
let atom = AtomTable::build_with(&self.machine_st.atom_tbl, &string);
|
||||
|
||||
self.machine_st.unify_complete_string(atom, output);
|
||||
Ok(())
|
||||
@@ -4069,7 +4057,7 @@ impl Machine {
|
||||
cell_as_atom!(self.machine_st.heap[s])
|
||||
}
|
||||
(HeapCellValueTag::Char, c) => {
|
||||
self.machine_st.atom_tbl.blocking_write().build_with(&c.to_string())
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, &c.to_string())
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
@@ -4431,15 +4419,14 @@ impl Machine {
|
||||
let h = self.machine_st.heap.len();
|
||||
|
||||
let header_term = functor!(
|
||||
self.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(header_name.as_str()),
|
||||
[cell(string_as_cstr_cell!(self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(header_value.to_str().unwrap())))]
|
||||
AtomTable::build_with(
|
||||
&self.machine_st.atom_tbl,
|
||||
header_name.as_str()
|
||||
),
|
||||
[cell(string_as_cstr_cell!(AtomTable::build_with(
|
||||
&self.machine_st.atom_tbl,
|
||||
header_value.to_str().unwrap()
|
||||
)))]
|
||||
);
|
||||
|
||||
self.machine_st.heap.extend(header_term.into_iter());
|
||||
@@ -4458,10 +4445,7 @@ impl Machine {
|
||||
let reader = resp.bytes().unwrap().reader();
|
||||
|
||||
let mut stream = Stream::from_http_stream(
|
||||
self.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(&address_string),
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, &address_string),
|
||||
Box::new(reader),
|
||||
&mut self.machine_st.arena,
|
||||
);
|
||||
@@ -4578,14 +4562,14 @@ impl Machine {
|
||||
Method::HEAD => atom!("head"),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let path_atom = self.machine_st.atom_tbl.blocking_write().build_with(request.request.uri().path());
|
||||
let path_atom = AtomTable::build_with(&self.machine_st.atom_tbl, request.request.uri().path());
|
||||
let path_cell = atom_as_cstr_cell!(path_atom);
|
||||
let headers: Vec<HeapCellValue> = request.request.headers().iter().map(|(header_name, header_value)| {
|
||||
let h = self.machine_st.heap.len();
|
||||
|
||||
let header_term = functor!(
|
||||
self.machine_st.atom_tbl.blocking_write().build_with(header_name.as_str()),
|
||||
[cell(string_as_cstr_cell!(self.machine_st.atom_tbl.blocking_write().build_with(header_value.to_str().unwrap())))]
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, header_name.as_str()),
|
||||
[cell(string_as_cstr_cell!(AtomTable::build_with(&self.machine_st.atom_tbl, header_value.to_str().unwrap())))]
|
||||
);
|
||||
|
||||
self.machine_st.heap.extend(header_term.into_iter());
|
||||
@@ -4595,7 +4579,7 @@ impl Machine {
|
||||
let headers_list = iter_to_heap_list(&mut self.machine_st.heap, headers.into_iter());
|
||||
|
||||
let query_str = request.request.uri().query().unwrap_or("");
|
||||
let query_atom = self.machine_st.atom_tbl.blocking_write().build_with(query_str);
|
||||
let query_atom = AtomTable::build_with(&self.machine_st.atom_tbl, query_str);
|
||||
let query_cell = string_as_cstr_cell!(query_atom);
|
||||
|
||||
let hyper_req = request.request;
|
||||
@@ -4825,11 +4809,10 @@ impl Machine {
|
||||
unify!(self.machine_st, return_value, struct_value);
|
||||
}
|
||||
Value::CString(cstr) => {
|
||||
let cstr = self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(cstr.to_str().unwrap());
|
||||
let cstr = AtomTable::build_with(
|
||||
&self.machine_st.atom_tbl,
|
||||
cstr.to_str().unwrap(),
|
||||
);
|
||||
self.machine_st.unify_complete_string(cstr, return_value);
|
||||
}
|
||||
}
|
||||
@@ -4858,11 +4841,10 @@ impl Machine {
|
||||
.map(|val| match val {
|
||||
Value::Int(n) => fixnum_as_cell!(Fixnum::build_with(n)),
|
||||
Value::Float(n) => HeapCellValue::from(float_alloc!(n, self.machine_st.arena)),
|
||||
Value::CString(cstr) => atom_as_cell!(self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(&cstr.into_string().unwrap())),
|
||||
Value::CString(cstr) => atom_as_cell!(AtomTable::build_with(
|
||||
&self.machine_st.atom_tbl,
|
||||
&cstr.into_string().unwrap()
|
||||
)),
|
||||
Value::Struct(name, struct_args) => self.build_struct(&name, struct_args),
|
||||
})
|
||||
.collect();
|
||||
@@ -4918,7 +4900,7 @@ impl Machine {
|
||||
let src_sink = self.deref_register(1);
|
||||
|
||||
if let Some(file_spec) = self.machine_st.value_to_str_like(src_sink) {
|
||||
let file_spec = file_spec.as_atom(&mut self.machine_st.atom_tbl.blocking_write());
|
||||
let file_spec = file_spec.as_atom(&*self.machine_st.atom_tbl);
|
||||
|
||||
let mut stream =
|
||||
self.machine_st
|
||||
@@ -4961,7 +4943,7 @@ impl Machine {
|
||||
|
||||
let op = read_heap_cell!(self.deref_register(3),
|
||||
(HeapCellValueTag::Char, c) => {
|
||||
self.machine_st.atom_tbl.blocking_write().build_with(&c.to_string())
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, &c.to_string())
|
||||
}
|
||||
(HeapCellValueTag::Atom, (name, _arity)) => {
|
||||
name
|
||||
@@ -6128,11 +6110,7 @@ impl Machine {
|
||||
.read_term(&op_dir, Tokens::Default)
|
||||
.map_err(|err| error_after_read_term(err, 0, &parser))
|
||||
.and_then(|term| {
|
||||
write_term_to_heap(
|
||||
&term,
|
||||
&mut self.machine_st.heap,
|
||||
&mut self.machine_st.atom_tbl.blocking_write(),
|
||||
)
|
||||
write_term_to_heap(&term, &mut self.machine_st.heap, &self.machine_st.atom_tbl)
|
||||
});
|
||||
|
||||
match term_write_result {
|
||||
@@ -6296,7 +6274,7 @@ impl Machine {
|
||||
name
|
||||
}
|
||||
_ => {
|
||||
self.machine_st.atom_tbl.blocking_write().build_with(&match Number::try_from(port) {
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, &match Number::try_from(port) {
|
||||
Ok(Number::Fixnum(n)) => n.get_num().to_string(),
|
||||
Ok(Number::Integer(n)) => n.to_string(),
|
||||
_ => {
|
||||
@@ -6310,10 +6288,7 @@ impl Machine {
|
||||
atom!("127.0.0.1:80")
|
||||
} else {
|
||||
let buffer = format!("{}:{}", socket_atom.as_str(), port.as_str());
|
||||
self.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(&buffer)
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, &buffer)
|
||||
};
|
||||
|
||||
let alias = self.machine_st.registers[4];
|
||||
@@ -6495,7 +6470,7 @@ impl Machine {
|
||||
(ArenaHeaderTag::TcpListener, tcp_listener) => {
|
||||
match tcp_listener.accept().ok() {
|
||||
Some((tcp_stream, socket_addr)) => {
|
||||
let client = self.machine_st.atom_tbl.blocking_write().build_with(&socket_addr.to_string());
|
||||
let client = AtomTable::build_with(&self.machine_st.atom_tbl, &socket_addr.to_string());
|
||||
|
||||
let mut tcp_stream = Stream::from_tcp_stream(
|
||||
client,
|
||||
@@ -7119,7 +7094,7 @@ impl Machine {
|
||||
let chars = put_complete_string(
|
||||
&mut self.machine_st.heap,
|
||||
&result,
|
||||
&mut self.machine_st.atom_tbl.blocking_write(),
|
||||
&self.machine_st.atom_tbl,
|
||||
);
|
||||
|
||||
let result_addr = self.deref_register(1);
|
||||
@@ -7138,7 +7113,7 @@ impl Machine {
|
||||
use git_version::git_version;
|
||||
|
||||
let buffer = git_version!(cargo_prefix = "cargo:", fallback = "unknown");
|
||||
let buffer_atom = self.machine_st.atom_tbl.blocking_write().build_with(buffer);
|
||||
let buffer_atom = AtomTable::build_with(&self.machine_st.atom_tbl, buffer);
|
||||
|
||||
let a1 = self.deref_register(1);
|
||||
self.machine_st.unify_complete_string(buffer_atom, a1);
|
||||
@@ -7503,11 +7478,7 @@ impl Machine {
|
||||
if buffer.len() == 0 {
|
||||
empty_list_as_cell!()
|
||||
} else {
|
||||
atom_as_cstr_cell!(self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(&buffer))
|
||||
atom_as_cstr_cell!(AtomTable::build_with(&self.machine_st.atom_tbl, &buffer))
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7644,11 +7615,8 @@ impl Machine {
|
||||
if let Some(string) = self.machine_st.value_to_str_like(addr) {
|
||||
for c in string.as_str().chars() {
|
||||
if c as u32 > 255 {
|
||||
let non_octet = self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(&c.to_string());
|
||||
let non_octet =
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, &c.to_string());
|
||||
self.machine_st
|
||||
.unify_atom(non_octet, self.machine_st.registers[2]);
|
||||
return;
|
||||
@@ -7705,7 +7673,7 @@ impl Machine {
|
||||
let cstr = put_complete_string(
|
||||
&mut self.machine_st.heap,
|
||||
&value,
|
||||
&mut self.machine_st.atom_tbl.blocking_write(),
|
||||
&self.machine_st.atom_tbl,
|
||||
);
|
||||
|
||||
unify!(self.machine_st, self.machine_st.registers[2], cstr);
|
||||
@@ -7893,11 +7861,8 @@ impl Machine {
|
||||
path_buf.push(&*library_name.as_str());
|
||||
|
||||
let library_path_str = path_buf.to_str().unwrap();
|
||||
let library_path = self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(library_path_str);
|
||||
let library_path =
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, library_path_str);
|
||||
|
||||
self.machine_st
|
||||
.unify_atom(library_path, self.machine_st.registers[3]);
|
||||
@@ -7994,11 +7959,8 @@ impl Machine {
|
||||
|
||||
if path.is_dir() {
|
||||
if let Some(path) = path.to_str() {
|
||||
let path_string = put_complete_string(
|
||||
&mut self.machine_st.heap,
|
||||
path,
|
||||
&mut self.machine_st.atom_tbl.blocking_write(),
|
||||
);
|
||||
let path_string =
|
||||
put_complete_string(&mut self.machine_st.heap, path, &self.machine_st.atom_tbl);
|
||||
|
||||
unify!(self.machine_st, self.machine_st.registers[1], path_string);
|
||||
return;
|
||||
@@ -8044,7 +8006,7 @@ impl Machine {
|
||||
fstr.push_str("finis].");
|
||||
let s = datetime.format(&fstr).to_string();
|
||||
|
||||
self.machine_st.atom_tbl.blocking_write().build_with(&s)
|
||||
AtomTable::build_with(&self.machine_st.atom_tbl, &s)
|
||||
}
|
||||
|
||||
pub(super) fn string_encoding_bytes(
|
||||
@@ -8068,21 +8030,17 @@ impl Machine {
|
||||
put_complete_string(
|
||||
&mut self.machine_st.heap,
|
||||
node.text().unwrap(),
|
||||
&mut self.machine_st.atom_tbl.blocking_write(),
|
||||
&self.machine_st.atom_tbl,
|
||||
)
|
||||
} else {
|
||||
let mut avec = Vec::new();
|
||||
|
||||
for attr in node.attributes() {
|
||||
let name = self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(attr.name());
|
||||
let name = AtomTable::build_with(&self.machine_st.atom_tbl, attr.name());
|
||||
let value = put_complete_string(
|
||||
&mut self.machine_st.heap,
|
||||
&attr.value(),
|
||||
&mut self.machine_st.atom_tbl.blocking_write(),
|
||||
&self.machine_st.atom_tbl,
|
||||
);
|
||||
|
||||
avec.push(str_loc_as_cell!(self.machine_st.heap.len()));
|
||||
@@ -8108,11 +8066,7 @@ impl Machine {
|
||||
cvec.into_iter()
|
||||
));
|
||||
|
||||
let tag = self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(node.tag_name().name());
|
||||
let tag = AtomTable::build_with(&self.machine_st.atom_tbl, node.tag_name().name());
|
||||
|
||||
let result = str_loc_as_cell!(self.machine_st.heap.len());
|
||||
|
||||
@@ -8132,17 +8086,17 @@ impl Machine {
|
||||
None => put_complete_string(
|
||||
&mut self.machine_st.heap,
|
||||
&node.text(),
|
||||
&mut self.machine_st.atom_tbl.blocking_write(),
|
||||
&self.machine_st.atom_tbl,
|
||||
),
|
||||
Some(name) => {
|
||||
let mut avec = Vec::new();
|
||||
|
||||
for attr in node.attrs() {
|
||||
let name = self.machine_st.atom_tbl.blocking_write().build_with(attr.0);
|
||||
let name = AtomTable::build_with(&self.machine_st.atom_tbl, attr.0);
|
||||
let value = put_complete_string(
|
||||
&mut self.machine_st.heap,
|
||||
&attr.1,
|
||||
&mut self.machine_st.atom_tbl.blocking_write(),
|
||||
&self.machine_st.atom_tbl,
|
||||
);
|
||||
|
||||
avec.push(str_loc_as_cell!(self.machine_st.heap.len()));
|
||||
@@ -8168,7 +8122,7 @@ impl Machine {
|
||||
cvec.into_iter()
|
||||
));
|
||||
|
||||
let tag = self.machine_st.atom_tbl.blocking_write().build_with(name);
|
||||
let tag = AtomTable::build_with(&self.machine_st.atom_tbl, name);
|
||||
let result = str_loc_as_cell!(self.machine_st.heap.len());
|
||||
|
||||
self.machine_st
|
||||
@@ -8189,11 +8143,7 @@ impl Machine {
|
||||
if buffer.len() == 0 {
|
||||
empty_list_as_cell!()
|
||||
} else {
|
||||
atom_as_cstr_cell!(self
|
||||
.machine_st
|
||||
.atom_tbl
|
||||
.blocking_write()
|
||||
.build_with(&buffer))
|
||||
atom_as_cstr_cell!(AtomTable::build_with(&self.machine_st.atom_tbl, &buffer))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user