consume whitespace before reading a term in loader.pl, modify prolog_load_context at file key to better reflect loading context, use it when reporting singleton variables (#812)
This commit is contained in:
@@ -306,6 +306,7 @@ pub enum SystemClauseType {
|
||||
SetEnv,
|
||||
UnsetEnv,
|
||||
CharsBase64,
|
||||
DevourWhitespace,
|
||||
}
|
||||
|
||||
impl SystemClauseType {
|
||||
@@ -594,6 +595,7 @@ impl SystemClauseType {
|
||||
&SystemClauseType::UnsetEnv => clause_name!("$unsetenv"),
|
||||
&SystemClauseType::CharsBase64 => clause_name!("$chars_base64"),
|
||||
&SystemClauseType::LoadLibraryAsStream => clause_name!("$load_library_as_stream"),
|
||||
&SystemClauseType::DevourWhitespace => clause_name!("$devour_whitespace"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -841,6 +843,9 @@ impl SystemClauseType {
|
||||
("$cpp_discontiguous_property", 3) => {
|
||||
Some(SystemClauseType::REPL(REPLCodePtr::DiscontiguousProperty))
|
||||
}
|
||||
("$devour_whitespace", 1) => {
|
||||
Some(SystemClauseType::DevourWhitespace)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,28 +130,26 @@ filter_anonymous_vars([VN=V | VNEqs0], VNEqs) :-
|
||||
|
||||
warn_about_singletons([], _).
|
||||
warn_about_singletons([Singleton|Singletons], LinesRead) :-
|
||||
( LinesRead =:= -1 ->
|
||||
true
|
||||
; filter_anonymous_vars([Singleton|Singletons], VarEqs),
|
||||
( filter_anonymous_vars([Singleton|Singletons], VarEqs),
|
||||
VarEqs \== [] ->
|
||||
write('Warning: singleton variables '),
|
||||
print_comma_separated_list(VarEqs),
|
||||
write(' at line '),
|
||||
write(LinesRead),
|
||||
write(' of '),
|
||||
load_context(Module),
|
||||
write(Module),
|
||||
prolog_load_context(file, File),
|
||||
write(File),
|
||||
nl
|
||||
; true
|
||||
).
|
||||
|
||||
|
||||
load_loop(Stream, Evacuable) :-
|
||||
( stream_property(Stream, position(position_and_lines_read(_, LinesRead))) ->
|
||||
true
|
||||
; LinesRead = -1
|
||||
( '$devour_whitespace'(Stream) ->
|
||||
stream_property(Stream, position(position_and_lines_read(_, LinesRead))),
|
||||
read_term(Stream, Term, [singletons(Singletons)])
|
||||
; Term = end_of_file
|
||||
),
|
||||
read_term(Stream, Term, [singletons(Singletons)]),
|
||||
( Term == end_of_file ->
|
||||
close(Stream),
|
||||
'$conclude_load'(Evacuable)
|
||||
|
||||
@@ -1612,20 +1612,26 @@ impl Machine {
|
||||
|
||||
pub(crate) fn load_context_file(&mut self) {
|
||||
if let Some(load_context) = self.load_contexts.last() {
|
||||
if let Some(file_name) = load_context.path.file_name() {
|
||||
let file_name_str = file_name.to_str().unwrap();
|
||||
let file_name_atom =
|
||||
clause_name!(file_name_str.to_string(), self.machine_st.atom_tbl);
|
||||
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 =
|
||||
clause_name!(file_name_str.to_string(), self.machine_st.atom_tbl);
|
||||
|
||||
let file_name_addr = Addr::Con(
|
||||
self.machine_st
|
||||
.heap
|
||||
.push(HeapCellValue::Atom(file_name_atom, None)),
|
||||
);
|
||||
|
||||
let file_name_addr = Addr::Con(
|
||||
self.machine_st
|
||||
.heap
|
||||
.push(HeapCellValue::Atom(file_name_atom, None)),
|
||||
);
|
||||
.unify(file_name_addr, self.machine_st[temp_v!(1)]);
|
||||
|
||||
self.machine_st
|
||||
.unify(file_name_addr, self.machine_st[temp_v!(1)]);
|
||||
return;
|
||||
return;
|
||||
}
|
||||
_ => {
|
||||
return self.load_context_module();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -395,6 +395,7 @@ impl Stream {
|
||||
StreamInstance::TlsStream(..) |
|
||||
StreamInstance::ReadlineStream(..) |
|
||||
StreamInstance::StaticStr(..) |
|
||||
StreamInstance::PausedPrologStream(..) |
|
||||
StreamInstance::Bytes(..) => Some(0),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
@@ -3888,54 +3888,6 @@ impl MachineState {
|
||||
|
||||
self.unify(a1, a2);
|
||||
}
|
||||
/*
|
||||
&SystemClauseType::GetClause => {
|
||||
let head = self[temp_v!(1)];
|
||||
|
||||
let subsection = match self.store(self.deref(head)) {
|
||||
Addr::Str(s) => match &self.heap[s] {
|
||||
&HeapCellValue::NamedStr(arity, ref name, ..) => {
|
||||
indices.get_clause_subsection(
|
||||
name.owning_module(),
|
||||
name.clone(),
|
||||
arity,
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
},
|
||||
Addr::Con(h) if self.heap.atom_at(h) => {
|
||||
if let &HeapCellValue::Atom(ref name, _) = &self.heap[h] {
|
||||
indices.get_clause_subsection(
|
||||
name.owning_module(),
|
||||
name.clone(),
|
||||
0,
|
||||
)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
};
|
||||
|
||||
match subsection {
|
||||
Some(dynamic_predicate_info) => {
|
||||
self.execute_at_index(
|
||||
2,
|
||||
dir_entry!(dynamic_predicate_info.clauses_subsection_p),
|
||||
);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
&SystemClauseType::GetCutPoint => {
|
||||
let a1 = self[temp_v!(1)];
|
||||
let a2 = Addr::CutPoint(self.b0);
|
||||
@@ -5496,6 +5448,18 @@ impl MachineState {
|
||||
}
|
||||
}
|
||||
}
|
||||
&SystemClauseType::DevourWhitespace => {
|
||||
let stream =
|
||||
self.get_stream_or_alias(self[temp_v!(1)], indices, "$devour_whitespace", 1)?;
|
||||
|
||||
match self.devour_whitespace(stream, self.atom_tbl.clone()) {
|
||||
Ok(false) => {} // not at EOF.
|
||||
_ => {
|
||||
self.fail = true;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return_from_clause!(self.last_call, self)
|
||||
|
||||
22
src/read.rs
22
src/read.rs
@@ -176,6 +176,24 @@ pub mod readline {
|
||||
}
|
||||
|
||||
impl MachineState {
|
||||
pub fn devour_whitespace(
|
||||
&mut self,
|
||||
mut inner: Stream,
|
||||
atom_tbl: TabledData<Atom>,
|
||||
) -> Result<bool, ParserError> {
|
||||
let mut stream = parsing_stream(inner.clone())?;
|
||||
let mut parser = Parser::new(&mut stream, atom_tbl, self.flags);
|
||||
|
||||
parser.devour_whitespace()?;
|
||||
inner.add_lines_read(parser.num_lines_read());
|
||||
|
||||
let result = parser.eof();
|
||||
let buf = stream.take_buf();
|
||||
|
||||
inner.pause_stream(buf)?;
|
||||
result
|
||||
}
|
||||
|
||||
pub fn read(
|
||||
&mut self,
|
||||
mut inner: Stream,
|
||||
@@ -191,12 +209,12 @@ impl MachineState {
|
||||
(term, parser.num_lines_read())
|
||||
};
|
||||
|
||||
inner.add_lines_read(num_lines_read);
|
||||
|
||||
// 'pausing' the stream saves the pending top buffer
|
||||
// created by the parsing stream, which was created in this
|
||||
// scope and is about to be destroyed in it.
|
||||
|
||||
inner.add_lines_read(num_lines_read);
|
||||
|
||||
let buf = stream.take_buf();
|
||||
inner.pause_stream(buf)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user