Allowing paths in use_module(library(..)) (#604)

In a module, the path is restricted in being an atom.
This commit is contained in:
notoria
2020-07-01 10:22:17 +02:00
parent 1eb42654e0
commit 83268f5ff6
9 changed files with 528 additions and 177 deletions

View File

@@ -8,12 +8,12 @@
op(1150, fx, table)
]).
:- use_module('tabling/double_linked_list').
:- use_module('tabling/table_data_structure').
:- use_module('tabling/batched_worklist').
:- use_module('tabling/wrapper').
:- use_module('tabling/global_worklist').
:- use_module('tabling/table_link_manager').
:- use_module(library('tabling/double_linked_list')).
:- use_module(library('tabling/table_data_structure')).
:- use_module(library('tabling/batched_worklist')).
:- use_module(library('tabling/wrapper')).
:- use_module(library('tabling/global_worklist')).
:- use_module(library('tabling/table_link_manager')).
:- use_module(library(cont)).
:- use_module(library(lists)).

View File

@@ -45,8 +45,8 @@
wkl_worklist_work_done/1 % +WorkList
]).
:- use_module(global_worklist).
:- use_module(double_linked_list).
:- use_module(library('tabling/global_worklist')).
:- use_module(library('tabling/double_linked_list')).
:- use_module(library(atts)).
:- use_module(library(lists)).

View File

@@ -15,8 +15,8 @@
get_nb_identifiers/3 % +Table, -NbWorklistID, -NbAnswerTreeID
]).
:- use_module(table_link_manager).
:- use_module(trie).
:- use_module(library('tabling/table_link_manager')).
:- use_module(library('tabling/trie')).
/* Part of SWI-Prolog
@@ -53,7 +53,7 @@
POSSIBILITY OF SUCH DAMAGE.
*/
:- use_module(batched_worklist).
:- use_module(library('tabling/batched_worklist')).
:- use_module(library(atts)).
:- use_module(library(gensym)).

View File

@@ -47,7 +47,7 @@
:- use_module(library(iso_ext)).
:- use_module(library(terms)).
:- use_module(trie).
:- use_module(library('tabling/trie')).
:- attribute trie_table_link/1.

View File

@@ -602,12 +602,7 @@ fn load_library(
) -> Result<ClauseName, SessionError> {
match LIBRARIES.borrow().get(name.as_str()) {
Some(code) => {
let mut lib_path = current_dir();
lib_path.pop();
lib_path.push("lib");
let listing_src = ListingSource::from_file_and_path(name, lib_path);
let listing_src = ListingSource::User;
load_module(
wam,

View File

@@ -212,17 +212,6 @@ impl SubModuleUser for IndexStore {
}
}
#[inline]
fn current_dir() -> std::path::PathBuf {
let mut path_buf = std::path::PathBuf::from(PROJECT_DIR);
// file!() always produces a path relative to PROJECT_DIR.
path_buf = path_buf.join(std::path::PathBuf::from(file!()));
path_buf.pop();
path_buf
}
include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
static TOPLEVEL: &str = include_str!("../toplevel.pl");
@@ -230,12 +219,7 @@ static TOPLEVEL: &str = include_str!("../toplevel.pl");
impl Machine {
fn compile_special_forms(&mut self)
{
let current_dir = current_dir();
let verify_attrs_src = ListingSource::from_file_and_path(
clause_name!("attributed_variables.pl"),
current_dir.clone(),
);
let verify_attrs_src = ListingSource::User;
match compile_special_form(
self,
@@ -250,10 +234,7 @@ impl Machine {
panic!("Machine::compile_special_forms() failed at VERIFY_ATTRS"),
}
let project_attrs_src = ListingSource::from_file_and_path(
clause_name!("project_attributes.pl"),
current_dir,
);
let project_attrs_src = ListingSource::User;
match compile_special_form(
self,
@@ -273,13 +254,7 @@ impl Machine {
{
self.toplevel_idx = self.code_repo.code.len();
let mut current_dir = current_dir();
current_dir.pop();
let top_lvl_src = ListingSource::from_file_and_path(
clause_name!("toplevel.pl"),
current_dir,
);
let top_lvl_src = ListingSource::User;
compile_user_module(
self,
@@ -371,6 +346,8 @@ impl Machine {
pub fn new(current_input_stream: Stream, current_output_stream: Stream) -> Self
{
use crate::ref_thread_local::RefThreadLocal;
let mut wam = Machine {
machine_st: MachineState::new(),
inner_heap: Heap::new(),
@@ -383,78 +360,59 @@ impl Machine {
};
let atom_tbl = wam.indices.atom_tbl.clone();
let mut lib_path = current_dir();
lib_path.pop();
lib_path.push("lib");
wam.indices.add_term_and_goal_expansion_indices();
compile_listing(
&mut wam,
Stream::from(BUILTINS),
Stream::from(LIBRARIES.borrow()["builtins"]),
default_index_store!(atom_tbl.clone()),
true,
ListingSource::from_file_and_path(
clause_name!("builtins.pl"),
lib_path.clone(),
),
ListingSource::User,
);
wam.compile_special_forms();
compile_user_module(&mut wam,
Stream::from(ERROR),
true,
ListingSource::from_file_and_path(
clause_name!("error"),
lib_path.clone(),
)
compile_user_module(
&mut wam,
Stream::from(LIBRARIES.borrow()["error"]),
true,
ListingSource::User,
);
compile_user_module(&mut wam,
Stream::from(PAIRS),
true,
ListingSource::from_file_and_path(
clause_name!("pairs"),
lib_path.clone(),
)
compile_user_module(
&mut wam,
Stream::from(LIBRARIES.borrow()["pairs"]),
true,
ListingSource::User,
);
compile_user_module(&mut wam,
Stream::from(LISTS),
true,
ListingSource::from_file_and_path(
clause_name!("lists"),
lib_path.clone(),
),
compile_user_module(
&mut wam,
Stream::from(LIBRARIES.borrow()["lists"]),
true,
ListingSource::User,
);
compile_user_module(&mut wam,
Stream::from(ISO_EXT),
true,
ListingSource::from_file_and_path(
clause_name!("iso_ext"),
lib_path.clone(),
)
compile_user_module(
&mut wam,
Stream::from(LIBRARIES.borrow()["iso_ext"]),
true,
ListingSource::User,
);
compile_user_module(&mut wam,
Stream::from(SI),
true,
ListingSource::from_file_and_path(
clause_name!("si"),
lib_path.clone(),
)
compile_user_module(
&mut wam,
Stream::from(LIBRARIES.borrow()["si"]),
true,
ListingSource::User,
);
compile_user_module(&mut wam,
Stream::from(CHARSIO),
true,
ListingSource::from_file_and_path(
clause_name!("si"),
lib_path.clone(),
)
compile_user_module(
&mut wam,
Stream::from(LIBRARIES.borrow()["charsio"]),
true,
ListingSource::User,
);
if wam.compile_top_level().is_err() {
@@ -681,8 +639,15 @@ impl Machine {
name.clone(),
HeapCellValue::Addr(Addr::Char(c)) =>
clause_name!(c.to_string(), self.indices.atom_tbl),
_ =>
unreachable!(),
HeapCellValue::Addr(addr @ Addr::PStrLocation(..)) => {
let mut heap_pstr_iter =
self.machine_st.heap_pstr_iter(*addr);
clause_name!(
heap_pstr_iter.to_string(),
self.indices.atom_tbl
)
}
_ => unreachable!(),
}
};

View File

@@ -387,8 +387,11 @@ consult(Item) :-
use_module(Module) :-
( nonvar(Module) ->
( Module = library(Filename) -> '$use_module'(Filename)
; atom(Module) -> '$use_module_from_file'(Module)
( Module = library(Filename) ->
write_term_to_chars(Filename, [], FilenameString),
'$use_module'(FilenameString)
; atom(Module) ->
'$use_module_from_file'(Module)
; throw(error(invalid_module_specifier, use_module/1))
)
; throw(error(instantiation_error, use_module/1))
@@ -399,7 +402,8 @@ use_module(Module, QualifiedExports) :-
( list_si(QualifiedExports) ->
maplist('$module_export'(use_module/2), QualifiedExports) ->
( Module = library(Filename) ->
'$use_qualified_module'(Filename, QualifiedExports)
write_term_to_chars(Filename, [], FilenameString),
'$use_qualified_module'(FilenameString, QualifiedExports)
; atom(Module) ->
'$use_qualified_module_from_file'(Module, QualifiedExports)
; throw(error(invalid_module_specifier, use_module/2))