run cargo fmt
This commit is contained in:
@@ -28,17 +28,15 @@ pub(super) fn bootstrapping_compile(
|
||||
) -> Result<(), SessionError> {
|
||||
let (wam_prelude, machine_st) = wam.prelude_view_and_machine_st();
|
||||
|
||||
let term_stream = BootstrappingTermStream::from_char_reader(
|
||||
stream,
|
||||
machine_st,
|
||||
listing_src,
|
||||
);
|
||||
let term_stream = BootstrappingTermStream::from_char_reader(stream, machine_st, listing_src);
|
||||
|
||||
let payload = BootstrappingLoadState(
|
||||
LoadStatePayload::new(wam_prelude.code.len(), term_stream)
|
||||
);
|
||||
let payload =
|
||||
BootstrappingLoadState(LoadStatePayload::new(wam_prelude.code.len(), term_stream));
|
||||
|
||||
let loader: Loader<'_, BootstrappingLoadState> = Loader { payload, wam_prelude };
|
||||
let loader: Loader<'_, BootstrappingLoadState> = Loader {
|
||||
payload,
|
||||
wam_prelude,
|
||||
};
|
||||
|
||||
loader.load()?;
|
||||
Ok(())
|
||||
@@ -98,8 +96,8 @@ fn derelictize_try_me_else(
|
||||
retraction_info.push_record(RetractionRecord::ReplacedDynamicElseOffset(index, *o));
|
||||
Some(mem::replace(o, 0))
|
||||
}
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Fail(_)) |
|
||||
Instruction::DynamicInternalElse(_, _, NextOrFail::Fail(_)) => None,
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Fail(_))
|
||||
| Instruction::DynamicInternalElse(_, _, NextOrFail::Fail(_)) => None,
|
||||
Instruction::TryMeElse(0) => None,
|
||||
Instruction::TryMeElse(ref mut o) => {
|
||||
retraction_info.push_record(RetractionRecord::ModifiedTryMeElse(index, *o));
|
||||
@@ -154,8 +152,8 @@ fn merge_indices(
|
||||
fn find_outer_choice_instr(code: &Code, mut index: usize) -> usize {
|
||||
loop {
|
||||
match &code[index] {
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Next(i)) |
|
||||
Instruction::DynamicInternalElse(_, _, NextOrFail::Next(i))
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Next(i))
|
||||
| Instruction::DynamicInternalElse(_, _, NextOrFail::Next(i))
|
||||
if *i > 0 =>
|
||||
{
|
||||
index += i;
|
||||
@@ -170,42 +168,37 @@ fn find_outer_choice_instr(code: &Code, mut index: usize) -> usize {
|
||||
fn find_inner_choice_instr(code: &Code, mut index: usize, index_loc: usize) -> usize {
|
||||
loop {
|
||||
match &code[index] {
|
||||
Instruction::TryMeElse(o) |
|
||||
Instruction::RetryMeElse(o) => {
|
||||
Instruction::TryMeElse(o) | Instruction::RetryMeElse(o) => {
|
||||
if *o > 0 {
|
||||
return index;
|
||||
} else {
|
||||
index = index_loc;
|
||||
}
|
||||
}
|
||||
&Instruction::DynamicElse(_, _, next_or_fail) => {
|
||||
match next_or_fail {
|
||||
NextOrFail::Next(i) => {
|
||||
if i == 0 {
|
||||
index = index_loc;
|
||||
} else {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
NextOrFail::Fail(_) => {
|
||||
&Instruction::DynamicElse(_, _, next_or_fail) => match next_or_fail {
|
||||
NextOrFail::Next(i) => {
|
||||
if i == 0 {
|
||||
index = index_loc;
|
||||
}
|
||||
}
|
||||
}
|
||||
&Instruction::DynamicInternalElse(_, _, next_or_fail) => {
|
||||
match next_or_fail {
|
||||
NextOrFail::Next(i) => {
|
||||
if i == 0 {
|
||||
index = index_loc;
|
||||
} else {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
NextOrFail::Fail(_) => {
|
||||
} else {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
||||
NextOrFail::Fail(_) => {
|
||||
index = index_loc;
|
||||
}
|
||||
},
|
||||
&Instruction::DynamicInternalElse(_, _, next_or_fail) => match next_or_fail {
|
||||
NextOrFail::Next(i) => {
|
||||
if i == 0 {
|
||||
index = index_loc;
|
||||
} else {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
NextOrFail::Fail(_) => {
|
||||
return index;
|
||||
}
|
||||
},
|
||||
Instruction::TrustMe(_) => {
|
||||
return index;
|
||||
}
|
||||
@@ -215,11 +208,7 @@ fn find_inner_choice_instr(code: &Code, mut index: usize, index_loc: usize) -> u
|
||||
index += v;
|
||||
}
|
||||
IndexingCodePtr::DynamicExternal(v) => match &code[index + v] {
|
||||
&Instruction::DynamicInternalElse(
|
||||
_,
|
||||
_,
|
||||
NextOrFail::Next(0),
|
||||
) => {
|
||||
&Instruction::DynamicInternalElse(_, _, NextOrFail::Next(0)) => {
|
||||
return index + v;
|
||||
}
|
||||
_ => {
|
||||
@@ -309,8 +298,7 @@ fn merge_indexed_subsequences(
|
||||
code[inner_try_me_else_loc] = Instruction::TrustMe(o);
|
||||
}
|
||||
_ => {
|
||||
code[inner_try_me_else_loc] =
|
||||
Instruction::RetryMeElse(o);
|
||||
code[inner_try_me_else_loc] = Instruction::RetryMeElse(o);
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -376,7 +364,9 @@ fn delete_from_skeleton(
|
||||
}
|
||||
|
||||
if skeleton.core.is_dynamic {
|
||||
skeleton.core.add_retracted_dynamic_clause_info(clause_index_info);
|
||||
skeleton
|
||||
.core
|
||||
.add_retracted_dynamic_clause_info(clause_index_info);
|
||||
|
||||
retraction_info.push_record(RetractionRecord::RemovedDynamicSkeletonClause(
|
||||
compilation_target,
|
||||
@@ -409,8 +399,8 @@ fn blunt_leading_choice_instr(
|
||||
code[instr_loc] = Instruction::TryMeElse(*o);
|
||||
return instr_loc;
|
||||
}
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Next(_)) |
|
||||
Instruction::DynamicInternalElse(_, _, NextOrFail::Next(_)) => {
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Next(_))
|
||||
| Instruction::DynamicInternalElse(_, _, NextOrFail::Next(_)) => {
|
||||
return instr_loc;
|
||||
}
|
||||
&mut Instruction::DynamicElse(b, d, NextOrFail::Fail(o)) => {
|
||||
@@ -422,26 +412,19 @@ fn blunt_leading_choice_instr(
|
||||
code[instr_loc] = Instruction::DynamicElse(b, d, NextOrFail::Next(0));
|
||||
return instr_loc;
|
||||
}
|
||||
&mut Instruction::DynamicInternalElse(
|
||||
b,
|
||||
d,
|
||||
NextOrFail::Fail(o),
|
||||
) => {
|
||||
&mut Instruction::DynamicInternalElse(b, d, NextOrFail::Fail(o)) => {
|
||||
retraction_info.push_record(RetractionRecord::AppendedNextOrFail(
|
||||
instr_loc,
|
||||
NextOrFail::Fail(o),
|
||||
));
|
||||
|
||||
code[instr_loc] = Instruction::DynamicInternalElse(
|
||||
b,
|
||||
d,
|
||||
NextOrFail::Next(0),
|
||||
);
|
||||
code[instr_loc] = Instruction::DynamicInternalElse(b, d, NextOrFail::Next(0));
|
||||
|
||||
return instr_loc;
|
||||
}
|
||||
Instruction::TrustMe(o) => {
|
||||
retraction_info.push_record(RetractionRecord::AppendedTrustMe(instr_loc, *o, false));
|
||||
retraction_info
|
||||
.push_record(RetractionRecord::AppendedTrustMe(instr_loc, *o, false));
|
||||
|
||||
code[instr_loc] = Instruction::TryMeElse(0);
|
||||
return instr_loc + 1;
|
||||
@@ -481,9 +464,9 @@ fn set_switch_var_offset_to_choice_instr(
|
||||
};
|
||||
|
||||
match &code[index_loc + v] {
|
||||
Instruction::TryMeElse(_) |
|
||||
Instruction::DynamicElse(..) |
|
||||
Instruction::DynamicInternalElse(..) => {}
|
||||
Instruction::TryMeElse(_)
|
||||
| Instruction::DynamicElse(..)
|
||||
| Instruction::DynamicInternalElse(..) => {}
|
||||
_ => {
|
||||
set_switch_var_offset(code, index_loc, offset, retraction_info);
|
||||
}
|
||||
@@ -523,9 +506,8 @@ fn internalize_choice_instr_at(
|
||||
retraction_info: &mut RetractionInfo,
|
||||
) {
|
||||
match &mut code[instr_loc] {
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Fail(_)) |
|
||||
Instruction::DynamicInternalElse(_, _, NextOrFail::Fail(_)) => {
|
||||
}
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Fail(_))
|
||||
| Instruction::DynamicInternalElse(_, _, NextOrFail::Fail(_)) => {}
|
||||
Instruction::DynamicElse(_, _, ref mut o @ NextOrFail::Next(0)) => {
|
||||
retraction_info.push_record(RetractionRecord::ReplacedDynamicElseOffset(instr_loc, 0));
|
||||
*o = NextOrFail::Fail(0);
|
||||
@@ -554,18 +536,10 @@ fn internalize_choice_instr_at(
|
||||
|
||||
match &mut code[instr_loc + o] {
|
||||
Instruction::RevJmpBy(p) if *p == 0 => {
|
||||
code[instr_loc] = Instruction::DynamicInternalElse(
|
||||
b,
|
||||
d,
|
||||
NextOrFail::Fail(o),
|
||||
);
|
||||
code[instr_loc] = Instruction::DynamicInternalElse(b, d, NextOrFail::Fail(o));
|
||||
}
|
||||
_ => {
|
||||
code[instr_loc] = Instruction::DynamicInternalElse(
|
||||
b,
|
||||
d,
|
||||
NextOrFail::Next(o),
|
||||
);
|
||||
code[instr_loc] = Instruction::DynamicInternalElse(b, d, NextOrFail::Next(o));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -609,23 +583,20 @@ fn thread_choice_instr_at_to(
|
||||
*o = target_loc - instr_loc;
|
||||
return;
|
||||
}
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Next(ref mut o)) |
|
||||
Instruction::DynamicInternalElse(
|
||||
_,
|
||||
_,
|
||||
NextOrFail::Next(ref mut o),
|
||||
) if target_loc >= instr_loc => {
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Next(ref mut o))
|
||||
| Instruction::DynamicInternalElse(_, _, NextOrFail::Next(ref mut o))
|
||||
if target_loc >= instr_loc =>
|
||||
{
|
||||
retraction_info
|
||||
.push_record(RetractionRecord::ReplacedDynamicElseOffset(instr_loc, *o));
|
||||
*o = target_loc - instr_loc;
|
||||
return;
|
||||
}
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Next(o)) |
|
||||
Instruction::DynamicInternalElse(_, _, NextOrFail::Next(o)) => {
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Next(o))
|
||||
| Instruction::DynamicInternalElse(_, _, NextOrFail::Next(o)) => {
|
||||
instr_loc += *o;
|
||||
}
|
||||
Instruction::TryMeElse(o)
|
||||
| Instruction::RetryMeElse(o) => {
|
||||
Instruction::TryMeElse(o) | Instruction::RetryMeElse(o) => {
|
||||
instr_loc += *o;
|
||||
}
|
||||
Instruction::RevJmpBy(ref mut o) if instr_loc >= target_loc => {
|
||||
@@ -642,7 +613,8 @@ fn thread_choice_instr_at_to(
|
||||
{
|
||||
retraction_info.push_record(RetractionRecord::AppendedNextOrFail(instr_loc, *fail));
|
||||
|
||||
code[instr_loc] = instr!("dynamic_else",
|
||||
code[instr_loc] = instr!(
|
||||
"dynamic_else",
|
||||
birth,
|
||||
death,
|
||||
NextOrFail::Next(target_loc - instr_loc)
|
||||
@@ -653,14 +625,13 @@ fn thread_choice_instr_at_to(
|
||||
Instruction::DynamicElse(_, _, NextOrFail::Fail(o)) if *o > 0 => {
|
||||
instr_loc += *o;
|
||||
}
|
||||
&mut Instruction::DynamicInternalElse(
|
||||
birth,
|
||||
death,
|
||||
ref mut fail,
|
||||
) if target_loc >= instr_loc => {
|
||||
&mut Instruction::DynamicInternalElse(birth, death, ref mut fail)
|
||||
if target_loc >= instr_loc =>
|
||||
{
|
||||
retraction_info.push_record(RetractionRecord::AppendedNextOrFail(instr_loc, *fail));
|
||||
|
||||
code[instr_loc] = instr!("dynamic_internal_else",
|
||||
code[instr_loc] = instr!(
|
||||
"dynamic_internal_else",
|
||||
birth,
|
||||
death,
|
||||
NextOrFail::Next(target_loc - instr_loc)
|
||||
@@ -668,9 +639,7 @@ fn thread_choice_instr_at_to(
|
||||
|
||||
return;
|
||||
}
|
||||
Instruction::DynamicInternalElse(_, _, NextOrFail::Fail(o))
|
||||
if *o > 0 =>
|
||||
{
|
||||
Instruction::DynamicInternalElse(_, _, NextOrFail::Fail(o)) if *o > 0 => {
|
||||
instr_loc += *o;
|
||||
}
|
||||
Instruction::TrustMe(ref mut o) if target_loc >= instr_loc => {
|
||||
@@ -711,33 +680,31 @@ fn remove_non_leading_clause(
|
||||
|
||||
None
|
||||
}
|
||||
Instruction::TrustMe(_) => {
|
||||
match &mut code[preceding_choice_instr_loc] {
|
||||
Instruction::RetryMeElse(o) => {
|
||||
retraction_info.push_record(RetractionRecord::ModifiedRetryMeElse(
|
||||
preceding_choice_instr_loc,
|
||||
*o,
|
||||
));
|
||||
Instruction::TrustMe(_) => match &mut code[preceding_choice_instr_loc] {
|
||||
Instruction::RetryMeElse(o) => {
|
||||
retraction_info.push_record(RetractionRecord::ModifiedRetryMeElse(
|
||||
preceding_choice_instr_loc,
|
||||
*o,
|
||||
));
|
||||
|
||||
code[preceding_choice_instr_loc] = Instruction::TrustMe(0);
|
||||
code[preceding_choice_instr_loc] = Instruction::TrustMe(0);
|
||||
|
||||
None
|
||||
}
|
||||
Instruction::TryMeElse(ref mut o) => {
|
||||
retraction_info.push_record(RetractionRecord::ModifiedTryMeElse(
|
||||
preceding_choice_instr_loc,
|
||||
*o,
|
||||
));
|
||||
|
||||
*o = 0;
|
||||
|
||||
Some(IndexPtr::index(preceding_choice_instr_loc + 1))
|
||||
}
|
||||
_ => {
|
||||
unreachable!();
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
Instruction::TryMeElse(ref mut o) => {
|
||||
retraction_info.push_record(RetractionRecord::ModifiedTryMeElse(
|
||||
preceding_choice_instr_loc,
|
||||
*o,
|
||||
));
|
||||
|
||||
*o = 0;
|
||||
|
||||
Some(IndexPtr::index(preceding_choice_instr_loc + 1))
|
||||
}
|
||||
_ => {
|
||||
unreachable!();
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
unreachable!();
|
||||
}
|
||||
@@ -988,11 +955,7 @@ fn prepend_compiled_clause(
|
||||
Instruction::TryMeElse(ref mut o) if *o == 0 => {
|
||||
*o = prepend_queue_len - 2;
|
||||
}
|
||||
Instruction::DynamicInternalElse(
|
||||
_,
|
||||
_,
|
||||
ref mut o @ NextOrFail::Next(0),
|
||||
) => {
|
||||
Instruction::DynamicInternalElse(_, _, ref mut o @ NextOrFail::Next(0)) => {
|
||||
*o = NextOrFail::Fail(prepend_queue_len - 2);
|
||||
}
|
||||
_ => {
|
||||
@@ -1258,7 +1221,11 @@ fn print_overwrite_warning(
|
||||
_ => {}
|
||||
}
|
||||
|
||||
println!("Warning: overwriting {}/{} because the clauses are discontiguous", key.0.as_str(), key.1);
|
||||
println!(
|
||||
"Warning: overwriting {}/{} because the clauses are discontiguous",
|
||||
key.0.as_str(),
|
||||
key.1
|
||||
);
|
||||
}
|
||||
|
||||
impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
@@ -1270,9 +1237,11 @@ 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.build_with(
|
||||
path_str
|
||||
));
|
||||
return Some(
|
||||
LS::machine_st(&mut self.payload)
|
||||
.atom_tbl
|
||||
.build_with(path_str),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1290,10 +1259,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
let clause = self.try_term_to_tl(term, &mut preprocessor)?;
|
||||
// let queue = preprocessor.parse_queue(self)?;
|
||||
|
||||
let mut cg = CodeGenerator::new(
|
||||
&mut LS::machine_st(&mut self.payload).atom_tbl,
|
||||
settings,
|
||||
);
|
||||
let mut cg = CodeGenerator::new(&mut LS::machine_st(&mut self.payload).atom_tbl, settings);
|
||||
|
||||
let clause_code = cg.compile_predicate(vec![clause])?;
|
||||
|
||||
@@ -1323,10 +1289,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
clauses.push(self.try_term_to_tl(term, &mut preprocessor)?);
|
||||
}
|
||||
|
||||
let mut cg = CodeGenerator::new(
|
||||
&mut LS::machine_st(&mut self.payload).atom_tbl,
|
||||
settings,
|
||||
);
|
||||
let mut cg = CodeGenerator::new(&mut LS::machine_st(&mut self.payload).atom_tbl, settings);
|
||||
|
||||
let mut code = cg.compile_predicate(clauses)?;
|
||||
|
||||
@@ -1361,26 +1324,23 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
.clause_clause_locs
|
||||
.extend(&clause_clause_locs.make_contiguous()[0..]);
|
||||
|
||||
self.payload.retraction_info
|
||||
.push_record(RetractionRecord::SkeletonClauseTruncateBack(
|
||||
self.payload.retraction_info.push_record(
|
||||
RetractionRecord::SkeletonClauseTruncateBack(
|
||||
predicates.compilation_target,
|
||||
key,
|
||||
skeleton_clause_len,
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
None => {
|
||||
cg.skeleton
|
||||
.core
|
||||
.clause_clause_locs
|
||||
.extend(&clause_clause_locs.make_contiguous()[0..]);
|
||||
.core
|
||||
.clause_clause_locs
|
||||
.extend(&clause_clause_locs.make_contiguous()[0..]);
|
||||
|
||||
let skeleton = cg.skeleton;
|
||||
|
||||
self.add_extensible_predicate(
|
||||
key,
|
||||
skeleton,
|
||||
predicates.compilation_target,
|
||||
);
|
||||
self.add_extensible_predicate(key, skeleton, predicates.compilation_target);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1450,11 +1410,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
let mut skeleton = LocalPredicateSkeleton::new();
|
||||
skeleton.clause_clause_locs = clause_clause_locs;
|
||||
|
||||
self.add_local_extensible_predicate(
|
||||
*compilation_target,
|
||||
*key,
|
||||
skeleton,
|
||||
);
|
||||
self.add_local_extensible_predicate(*compilation_target, *key, skeleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1490,11 +1446,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
let mut skeleton = LocalPredicateSkeleton::new();
|
||||
skeleton.clause_clause_locs.push_front(code_len);
|
||||
|
||||
self.add_local_extensible_predicate(
|
||||
*compilation_target,
|
||||
*key,
|
||||
skeleton,
|
||||
);
|
||||
self.add_local_extensible_predicate(*compilation_target, *key, skeleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1530,11 +1482,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
let mut skeleton = LocalPredicateSkeleton::new();
|
||||
skeleton.clause_clause_locs.push_back(code_len);
|
||||
|
||||
self.add_local_extensible_predicate(
|
||||
*compilation_target,
|
||||
*key,
|
||||
skeleton,
|
||||
);
|
||||
self.add_local_extensible_predicate(*compilation_target, *key, skeleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1606,7 +1554,8 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
|
||||
skeleton.core.clause_clause_locs.push_back(code_len);
|
||||
|
||||
self.payload.retraction_info
|
||||
self.payload
|
||||
.retraction_info
|
||||
.push_record(RetractionRecord::SkeletonClausePopBack(
|
||||
compilation_target,
|
||||
key,
|
||||
@@ -1624,8 +1573,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
|
||||
self.push_back_to_local_predicate_skeleton(&compilation_target, &key, code_len);
|
||||
|
||||
let code_index =
|
||||
self.get_or_insert_code_index(key, compilation_target);
|
||||
let code_index = self.get_or_insert_code_index(key, compilation_target);
|
||||
|
||||
if let Some(new_code_ptr) = result {
|
||||
set_code_index(
|
||||
@@ -1646,7 +1594,8 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
skeleton.core.clause_clause_locs.push_front(code_len);
|
||||
skeleton.core.clause_assert_margin += 1;
|
||||
|
||||
self.payload.retraction_info
|
||||
self.payload
|
||||
.retraction_info
|
||||
.push_record(RetractionRecord::SkeletonClausePopFront(
|
||||
compilation_target,
|
||||
key,
|
||||
@@ -1666,8 +1615,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
|
||||
self.push_front_to_local_predicate_skeleton(&compilation_target, &key, code_len);
|
||||
|
||||
let code_index =
|
||||
self.get_or_insert_code_index(key, compilation_target);
|
||||
let code_index = self.get_or_insert_code_index(key, compilation_target);
|
||||
|
||||
set_code_index(
|
||||
&mut self.payload.retraction_info,
|
||||
@@ -1698,19 +1646,17 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
.opt_arg_index_key
|
||||
.switch_on_term_loc()
|
||||
{
|
||||
Some(index_loc) => {
|
||||
find_inner_choice_instr(
|
||||
&self.wam_prelude.code,
|
||||
skeleton.clauses[target_pos].clause_start,
|
||||
index_loc,
|
||||
)
|
||||
}
|
||||
Some(index_loc) => find_inner_choice_instr(
|
||||
&self.wam_prelude.code,
|
||||
skeleton.clauses[target_pos].clause_start,
|
||||
index_loc,
|
||||
),
|
||||
None => skeleton.clauses[target_pos].clause_start,
|
||||
};
|
||||
|
||||
match &mut self.wam_prelude.code[clause_loc] {
|
||||
Instruction::DynamicElse(_, ref mut d, _) |
|
||||
Instruction::DynamicInternalElse(_, ref mut d, _) => {
|
||||
Instruction::DynamicElse(_, ref mut d, _)
|
||||
| Instruction::DynamicInternalElse(_, ref mut d, _) => {
|
||||
*d = Death::Finite(LS::machine_st(&mut self.payload).global_clock);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
@@ -1797,11 +1743,11 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
skeleton.clauses[target_pos + 1].clause_start =
|
||||
skeleton.clauses[target_pos].clause_start;
|
||||
|
||||
let update_code_index = target_pos == 0 &&
|
||||
skeleton.clauses[target_pos + 1]
|
||||
.opt_arg_index_key
|
||||
.switch_on_term_loc()
|
||||
.is_none();
|
||||
let update_code_index = target_pos == 0
|
||||
&& skeleton.clauses[target_pos + 1]
|
||||
.opt_arg_index_key
|
||||
.switch_on_term_loc()
|
||||
.is_none();
|
||||
|
||||
let index_ptr_opt = if update_code_index {
|
||||
Some(IndexPtr::index(clause_loc))
|
||||
@@ -1964,7 +1910,8 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
index_loc,
|
||||
);
|
||||
|
||||
let lower_bound_clause_start = skeleton.clauses[lower_bound].clause_start;
|
||||
let lower_bound_clause_start =
|
||||
skeleton.clauses[lower_bound].clause_start;
|
||||
let preceding_choice_instr_loc;
|
||||
|
||||
match &mut code[clause_start] {
|
||||
@@ -2093,13 +2040,8 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
clause_clauses: ClauseIter,
|
||||
append_or_prepend: AppendOrPrepend,
|
||||
) -> Result<(), SessionError> {
|
||||
let clause_predicates = clause_clauses.map(|(head, body)| {
|
||||
Term::Clause(
|
||||
Cell::default(),
|
||||
atom!("$clause"),
|
||||
vec![head, body],
|
||||
)
|
||||
});
|
||||
let clause_predicates = clause_clauses
|
||||
.map(|(head, body)| Term::Clause(Cell::default(), atom!("$clause"), vec![head, body]));
|
||||
|
||||
let clause_clause_compilation_target = match compilation_target {
|
||||
CompilationTarget::User => CompilationTarget::Module(atom!("builtins")),
|
||||
@@ -2132,21 +2074,21 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
Some(skeleton) => {
|
||||
skeleton.core.clause_clause_locs.make_contiguous()[0..num_clause_predicates]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
Some(skeleton) => skeleton.core.clause_clause_locs.make_contiguous()
|
||||
[0..num_clause_predicates]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect(),
|
||||
None => {
|
||||
unreachable!()
|
||||
}
|
||||
};
|
||||
|
||||
match self.wam_prelude.indices.get_predicate_skeleton_mut(
|
||||
&clause_clause_compilation_target,
|
||||
&(atom!("$clause"), 2),
|
||||
) {
|
||||
match self
|
||||
.wam_prelude
|
||||
.indices
|
||||
.get_predicate_skeleton_mut(&clause_clause_compilation_target, &(atom!("$clause"), 2))
|
||||
{
|
||||
Some(skeleton) if append_or_prepend.is_append() => {
|
||||
for _ in 0..num_clause_predicates {
|
||||
skeleton.core.clause_clause_locs.pop_back();
|
||||
@@ -2270,25 +2212,25 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
println!(
|
||||
"Warning: overwriting multifile predicate {}:{}/{} because \
|
||||
it was not locally declared multifile.",
|
||||
self.payload.predicates.compilation_target, key.0.as_str(), key.1
|
||||
self.payload.predicates.compilation_target,
|
||||
key.0.as_str(),
|
||||
key.1
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(skeleton) = self
|
||||
.wam_prelude
|
||||
.indices
|
||||
.remove_predicate_skeleton(&self.payload.predicates.compilation_target, &key)
|
||||
{
|
||||
if let Some(skeleton) = self.wam_prelude.indices.remove_predicate_skeleton(
|
||||
&self.payload.predicates.compilation_target,
|
||||
&key,
|
||||
) {
|
||||
let compilation_target = self.payload.predicates.compilation_target;
|
||||
|
||||
if predicate_info.is_dynamic {
|
||||
let clause_clause_compilation_target =
|
||||
match compilation_target {
|
||||
CompilationTarget::User => {
|
||||
CompilationTarget::Module(atom!("builtins"))
|
||||
}
|
||||
module => module,
|
||||
};
|
||||
let clause_clause_compilation_target = match compilation_target {
|
||||
CompilationTarget::User => {
|
||||
CompilationTarget::Module(atom!("builtins"))
|
||||
}
|
||||
module => module,
|
||||
};
|
||||
|
||||
self.retract_local_clauses_by_locs(
|
||||
clause_clause_compilation_target,
|
||||
@@ -2301,11 +2243,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
}
|
||||
|
||||
self.payload.retraction_info.push_record(
|
||||
RetractionRecord::RemovedSkeleton(
|
||||
compilation_target,
|
||||
key,
|
||||
skeleton,
|
||||
),
|
||||
RetractionRecord::RemovedSkeleton(compilation_target, key, skeleton),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2328,9 +2266,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
match self.wam_prelude.indices.modules.get_mut(&filename) {
|
||||
Some(ref mut module) => {
|
||||
let index_ptr = code_index.get();
|
||||
let code_index = module.code_dir.entry(key)
|
||||
.or_insert(code_index)
|
||||
.clone();
|
||||
let code_index = module.code_dir.entry(key).or_insert(code_index).clone();
|
||||
|
||||
set_code_index(
|
||||
&mut self.payload.retraction_info,
|
||||
@@ -2349,8 +2285,10 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
LS::machine_st(&mut self.payload).global_clock += 1;
|
||||
|
||||
let clause_clauses_len = self.payload.clause_clauses.len();
|
||||
let clauses_vec: Vec<_> = self.payload
|
||||
.clause_clauses.drain(0..std::cmp::min(predicates_len, clause_clauses_len))
|
||||
let clauses_vec: Vec<_> = self
|
||||
.payload
|
||||
.clause_clauses
|
||||
.drain(0..std::cmp::min(predicates_len, clause_clauses_len))
|
||||
.collect();
|
||||
|
||||
let compilation_target = self.payload.predicates.compilation_target;
|
||||
@@ -2374,10 +2312,7 @@ impl Machine {
|
||||
module_name: HeapCellValue,
|
||||
key: PredicateKey,
|
||||
) -> CodeIndex {
|
||||
let mut loader: Loader<'_, InlineLoadState<'_>> = Loader::new(
|
||||
self,
|
||||
InlineTermStream {},
|
||||
);
|
||||
let mut loader: Loader<'_, InlineLoadState<'_>> = Loader::new(self, InlineTermStream {});
|
||||
|
||||
let module_name = if module_name.get_tag() == HeapCellValueTag::Atom {
|
||||
cell_as_atom!(module_name)
|
||||
@@ -2394,10 +2329,8 @@ impl Machine {
|
||||
vars: &[Term],
|
||||
) -> Result<(), SessionError> {
|
||||
let mut compile = || {
|
||||
let mut loader: Loader<'_, InlineLoadState<'_>> = Loader::new(
|
||||
self,
|
||||
InlineTermStream {},
|
||||
);
|
||||
let mut loader: Loader<'_, InlineLoadState<'_>> =
|
||||
Loader::new(self, InlineTermStream {});
|
||||
|
||||
let term = loader.read_term_from_heap(term_loc)?;
|
||||
let clause = build_rule_body(vars, term);
|
||||
|
||||
Reference in New Issue
Block a user