merge latest commit
This commit is contained in:
@@ -448,7 +448,8 @@ fn add_toplevel_code(wam: &mut Machine, code: Code, indices: IndexStore) {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn add_module_code(wam: &mut Machine, mut module: Module, code: Code, indices: IndexStore) {
|
||||
fn add_module_code(wam: &mut Machine, mut module: Module, code: Code, indices: IndexStore)
|
||||
{
|
||||
module.code_dir.extend(indices.code_dir);
|
||||
module.op_dir.extend(indices.op_dir.into_iter());
|
||||
|
||||
@@ -573,7 +574,7 @@ impl ListingCompiler {
|
||||
submodule: ClauseName,
|
||||
code_repo: &mut CodeRepo,
|
||||
flags: MachineFlags,
|
||||
exports: &Vec<PredicateKey>,
|
||||
exports: &Vec<ModuleExport>,
|
||||
wam_indices: &mut IndexStore,
|
||||
indices: &mut IndexStore,
|
||||
) -> Result<(), SessionError> {
|
||||
@@ -683,7 +684,8 @@ impl ListingCompiler {
|
||||
.or_insert((Predicate::new(), VecDeque::from(vec![])));
|
||||
|
||||
if let Some(ref mut module) = &mut self.module {
|
||||
module.add_module_expansion_record(hook, clause.clone(), queue.clone());
|
||||
module.add_expansion_record(hook, clause.clone(), queue.clone());
|
||||
module.add_local_expansion(hook, clause.clone(), queue.clone());
|
||||
}
|
||||
|
||||
(module_preds.0).0.push(clause);
|
||||
@@ -710,6 +712,24 @@ impl ListingCompiler {
|
||||
(len, queue_len)
|
||||
}
|
||||
|
||||
fn submit_op(
|
||||
&mut self,
|
||||
wam: &Machine,
|
||||
indices: &mut IndexStore,
|
||||
op_decl: &OpDecl,
|
||||
) -> Result<(), SessionError> {
|
||||
let spec = get_desc(
|
||||
op_decl.name(),
|
||||
composite_op!(
|
||||
self.module.is_some(),
|
||||
&wam.indices.op_dir,
|
||||
&mut indices.op_dir
|
||||
),
|
||||
);
|
||||
|
||||
op_decl.submit(self.get_module_name(), spec, &mut indices.op_dir)
|
||||
}
|
||||
|
||||
fn process_decl(
|
||||
&mut self,
|
||||
decl: Declaration,
|
||||
@@ -728,6 +748,7 @@ impl ListingCompiler {
|
||||
.code_repo
|
||||
.compile_hook(hook, flags)
|
||||
.map_err(SessionError::from);
|
||||
|
||||
wam.code_repo.truncate_terms(key, len, queue_len);
|
||||
|
||||
result
|
||||
@@ -736,16 +757,7 @@ impl ListingCompiler {
|
||||
Ok(self.add_non_counted_bt_flag(name, arity))
|
||||
}
|
||||
Declaration::Op(op_decl) => {
|
||||
let spec = get_desc(
|
||||
op_decl.name(),
|
||||
composite_op!(
|
||||
self.module.is_some(),
|
||||
&wam.indices.op_dir,
|
||||
&mut indices.op_dir
|
||||
),
|
||||
);
|
||||
|
||||
op_decl.submit(self.get_module_name(), spec, &mut indices.op_dir)
|
||||
self.submit_op(wam, indices, &op_decl)
|
||||
}
|
||||
Declaration::UseModule(ModuleSource::Library(name)) => {
|
||||
let name = if !wam.indices.modules.contains_key(&name) {
|
||||
@@ -777,6 +789,12 @@ impl ListingCompiler {
|
||||
let module_name = module_decl.name.clone();
|
||||
let atom_tbl = TabledData::new(module_name.to_rc());
|
||||
|
||||
for export in module_decl.exports.iter() {
|
||||
if let ModuleExport::OpDecl(ref op_decl) = export {
|
||||
self.submit_op(wam, indices, op_decl)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(self.module = Some(Module::new(module_decl, atom_tbl)))
|
||||
} else {
|
||||
Err(SessionError::from(ParserError::InvalidModuleDecl))
|
||||
@@ -824,8 +842,9 @@ impl ListingCompiler {
|
||||
.entry((name.clone(), arity))
|
||||
.or_insert(vec![]);
|
||||
|
||||
indices.code_dir.insert((name.clone(), arity),
|
||||
CodeIndex::dynamic_undefined(self.get_module_name()));
|
||||
indices.code_dir
|
||||
.entry((name.clone(), arity))
|
||||
.or_insert(CodeIndex::dynamic_undefined(self.get_module_name()));
|
||||
}
|
||||
&Declaration::Hook(hook, _, ref queue) if self.module.is_none() => worker
|
||||
.term_stream
|
||||
@@ -917,6 +936,16 @@ fn compile_work_impl(
|
||||
mut indices: IndexStore,
|
||||
mut results: GatherResult,
|
||||
) -> Result<(), SessionError> {
|
||||
if let Some(ref mut module) = &mut compiler.module {
|
||||
// compile the module-level goal and term expansions and store
|
||||
// their locations to the module's code_dir.
|
||||
let decls = module.take_local_expansions();
|
||||
|
||||
if !decls.is_empty() {
|
||||
results.worker_results.extend(decls.into_iter());
|
||||
}
|
||||
}
|
||||
|
||||
let module_code = compiler.generate_code(
|
||||
results.worker_results,
|
||||
wam,
|
||||
@@ -946,8 +975,9 @@ fn compile_work_impl(
|
||||
if let Some(mut module) = compiler.module.take() {
|
||||
if module.is_impromptu_module {
|
||||
module.module_decl.exports = indices.code_dir.keys().cloned()
|
||||
.filter(|(name, _)| name.owning_module().as_str() != "builtins")
|
||||
.collect();
|
||||
.filter(|(name, _)| name.owning_module().as_str() != "builtins")
|
||||
.map(ModuleExport::PredicateKey)
|
||||
.collect();
|
||||
}
|
||||
|
||||
let mut clause_code_generator =
|
||||
@@ -968,7 +998,7 @@ fn compile_work_impl(
|
||||
|
||||
wam.indices.use_module(&mut wam.code_repo, wam.machine_st.flags, &module)?;
|
||||
wam.indices.insert_module(module);
|
||||
} else {
|
||||
} else {
|
||||
add_module_code(wam, module, module_code, indices);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user