provisional changes #2
This commit is contained in:
@@ -133,12 +133,12 @@ impl ListingCompiler {
|
||||
pub fn new() -> Self {
|
||||
ListingCompiler { module: None, non_counted_bt_preds: HashSet::new() }
|
||||
}
|
||||
|
||||
fn use_module(&mut self, submodule: Module, wam: &mut Machine,
|
||||
indices: &mut MachineCodeIndices) -> Result<(), SessionError>
|
||||
|
||||
fn use_module(&mut self, submodule: Module, wam: &mut Machine, indices: &mut MachineCodeIndices)
|
||||
-> Result<(), SessionError>
|
||||
{
|
||||
let mod_name = self.get_module_name();
|
||||
|
||||
|
||||
indices.use_module(&submodule)?;
|
||||
|
||||
if let &mut Some(ref mut module) = &mut self.module {
|
||||
@@ -157,7 +157,7 @@ impl ListingCompiler {
|
||||
-> Result<(), SessionError>
|
||||
{
|
||||
let mod_name = self.get_module_name();
|
||||
|
||||
|
||||
indices.use_qualified_module(&submodule, exports)?;
|
||||
|
||||
if let &mut Some(ref mut module) = &mut self.module {
|
||||
@@ -170,7 +170,7 @@ impl ListingCompiler {
|
||||
wam.insert_module(submodule);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn get_module_name(&self) -> ClauseName {
|
||||
self.module.as_ref()
|
||||
.map(|module| module.module_decl.name.clone())
|
||||
@@ -268,7 +268,7 @@ pub fn compile_listing<'a, R>(wam: &mut Machine, src: R, mut indices: MachineCod
|
||||
let mut compiler = ListingCompiler::new();
|
||||
let mut toplevel_results = vec![];
|
||||
|
||||
while let Some(decl) = try_eval_session!(worker.consume(&mut indices)) {
|
||||
while let Some(decl) = try_eval_session!(worker.consume(&wam.op_dir, &mut indices)) {
|
||||
if decl.is_module_decl() {
|
||||
toplevel_indices.copy_and_swap(&mut indices);
|
||||
mem::swap(&mut worker.results, &mut toplevel_results);
|
||||
|
||||
@@ -175,11 +175,7 @@ impl Machine {
|
||||
pub fn atom_tbl(&self) -> TabledData<Atom> {
|
||||
self.ms.atom_tbl.clone()
|
||||
}
|
||||
|
||||
pub fn get_module(&self, name: ClauseName) -> Option<&Module> {
|
||||
self.modules.get(&name)
|
||||
}
|
||||
|
||||
|
||||
pub fn add_batched_code(&mut self, code: Code, code_dir: CodeDir) -> Result<(), SessionError>
|
||||
{
|
||||
for (ref key, ref idx) in code_dir.iter() {
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn read_toplevel(wam: &Machine) -> Result<Input, ParserError> {
|
||||
let mut parser = Parser::new(stdin.lock(), wam.atom_tbl(), wam.machine_flags());
|
||||
|
||||
parser.add_to_top(buffer.as_str());
|
||||
Ok(Input::Term(parser.read_term(&wam.op_dir)?))
|
||||
Ok(Input::Term(parser.read_term(composite_op!(&wam.op_dir))?))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ impl MachineState {
|
||||
pub fn read<R: Read>(&mut self, inner: R, op_dir: &OpDir) -> Result<usize, ParserError>
|
||||
{
|
||||
let mut parser = Parser::new(inner, self.atom_tbl.clone(), self.flags);
|
||||
let term = parser.read_term(op_dir)?;
|
||||
let term = parser.read_term(composite_op!(op_dir))?;
|
||||
|
||||
Ok(write_term_to_heap(term, self))
|
||||
}
|
||||
|
||||
@@ -627,7 +627,8 @@ pub fn parse_term(term: Term, mut indices: MachineCodeIndices) -> Result<TopLeve
|
||||
pub struct TopLevelBatchWorker<R: Read> {
|
||||
parser: Parser<R>,
|
||||
rel_worker: RelationWorker,
|
||||
pub results: Vec<(Predicate, VecDeque<TopLevel>)>
|
||||
pub results: Vec<(Predicate, VecDeque<TopLevel>)>,
|
||||
pub in_module: bool
|
||||
}
|
||||
|
||||
impl<R: Read> TopLevelBatchWorker<R> {
|
||||
@@ -635,11 +636,19 @@ impl<R: Read> TopLevelBatchWorker<R> {
|
||||
{
|
||||
TopLevelBatchWorker { parser: Parser::new(inner, atom_tbl, flags),
|
||||
rel_worker: RelationWorker::new(),
|
||||
results: vec![] }
|
||||
results: vec![],
|
||||
in_module: false }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_term(&mut self, static_op_dir: &OpDir, op_dir: &OpDir) -> Result<Term, ParserError> {
|
||||
let composite_op = composite_op!(self.in_module, op_dir, static_op_dir);
|
||||
self.parser.read_term(composite_op)
|
||||
}
|
||||
|
||||
pub
|
||||
fn consume(&mut self, indices: &mut MachineCodeIndices) -> Result<Option<Declaration>, SessionError>
|
||||
fn consume(&mut self, op_dir: &OpDir, indices: &mut MachineCodeIndices)
|
||||
-> Result<Option<Declaration>, SessionError>
|
||||
{
|
||||
let mut preds = vec![];
|
||||
|
||||
@@ -647,7 +656,7 @@ impl<R: Read> TopLevelBatchWorker<R> {
|
||||
self.parser.reset(); // empty the parser stack of token descriptions.
|
||||
|
||||
let mut new_rel_worker = RelationWorker::new();
|
||||
let term = self.parser.read_term(&indices.op_dir)?;
|
||||
let term = self.read_term(op_dir, &indices.op_dir)?;
|
||||
let tl = new_rel_worker.try_term_to_tl(indices, term, true)?;
|
||||
|
||||
if !is_consistent(&tl, &preds) { // if is_consistent returns false, preds is non-empty.
|
||||
|
||||
Reference in New Issue
Block a user