indexing bug fixes, corrections to ,
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1,6 +1,6 @@
|
||||
[root]
|
||||
name = "rusty-wam"
|
||||
version = "0.7.3"
|
||||
version = "0.7.4"
|
||||
dependencies = [
|
||||
"lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
@@ -729,8 +729,7 @@ pub enum BuiltInInstruction {
|
||||
IsVar(RegType),
|
||||
ResetBlock,
|
||||
SetBall,
|
||||
SetNeckCutPoint(Terminal),
|
||||
SetNonNeckCutPoint(Terminal),
|
||||
SetCutPoint,
|
||||
Succeed,
|
||||
Unify,
|
||||
UnwindStack
|
||||
|
||||
@@ -121,7 +121,7 @@ fn get_builtins() -> Code {
|
||||
deallocate!(),
|
||||
goto!(88, 3),
|
||||
try_me_else!(25), // ','/3, 88.
|
||||
switch_on_term!(4, 0, 0, 0),
|
||||
switch_on_term!(4, 1, 0, 0),
|
||||
indexed_try!(4),
|
||||
retry!(11),
|
||||
trust!(14),
|
||||
@@ -133,7 +133,7 @@ fn get_builtins() -> Code {
|
||||
unify_variable!(perm_v!(1)),
|
||||
get_var_in_fact!(perm_v!(3), 3)],
|
||||
query![put_value!(perm_v!(3), 1)],
|
||||
set_non_neck_cp!(non_terminal!()),
|
||||
set_cp!(),
|
||||
query![put_unsafe_value!(2, 1),
|
||||
put_unsafe_value!(1, 2),
|
||||
put_value!(perm_v!(3), 3)],
|
||||
@@ -143,30 +143,32 @@ fn get_builtins() -> Code {
|
||||
fact![get_constant!(Constant::from("!"), temp_v!(1)),
|
||||
get_constant!(Constant::from("!"), temp_v!(2))],
|
||||
query![put_value!(temp_v!(3), 1)],
|
||||
set_neck_cp!(terminal!()),
|
||||
set_cp!(),
|
||||
trust_me!(),
|
||||
allocate!(1),
|
||||
fact![get_constant!(Constant::from("!"), temp_v!(1)),
|
||||
get_var_in_fact!(perm_v!(1), 2)],
|
||||
query![put_value!(temp_v!(3), 1)],
|
||||
set_non_neck_cp!(non_terminal!()),
|
||||
set_cp!(),
|
||||
query![put_value!(perm_v!(1), 1)],
|
||||
deallocate!(),
|
||||
execute_n!(1),
|
||||
retry_me_else!(7),
|
||||
retry_me_else!(8),
|
||||
allocate!(1),
|
||||
fact![get_constant!(Constant::from("!"), temp_v!(2)),
|
||||
get_var_in_fact!(perm_v!(1), 3)],
|
||||
neck_cut!(non_terminal!()),
|
||||
call_n!(1),
|
||||
query![put_value!(perm_v!(1), 1)],
|
||||
deallocate!(),
|
||||
set_non_neck_cp!(terminal!()),
|
||||
retry_me_else!(7),
|
||||
set_cp!(),
|
||||
retry_me_else!(8), // 121.
|
||||
allocate!(3),
|
||||
fact![get_structure!(String::from(","), 2, temp_v!(2)),
|
||||
unify_variable!(perm_v!(2)),
|
||||
unify_variable!(perm_v!(1)),
|
||||
get_var_in_fact!(perm_v!(3), 3)],
|
||||
get_var_in_fact!(perm_v!(3), 3)],
|
||||
neck_cut!(non_terminal!()),
|
||||
call_n!(1),
|
||||
query![put_unsafe_value!(2, 1),
|
||||
put_unsafe_value!(1, 2),
|
||||
@@ -175,12 +177,12 @@ fn get_builtins() -> Code {
|
||||
goto!(88, 3),
|
||||
trust_me!(),
|
||||
allocate!(1),
|
||||
fact![get_var_in_fact!(perm_v!(1), 2)],
|
||||
fact![get_var_in_fact!(perm_v!(1), 2)],
|
||||
call_n!(1),
|
||||
query![put_value!(perm_v!(1), 1)],
|
||||
deallocate!(),
|
||||
execute_n!(1),
|
||||
allocate!(2), // (->)/2, 134.
|
||||
allocate!(2), // (->)/2, 136.
|
||||
get_level!(),
|
||||
fact![get_var_in_fact!(perm_v!(2), 2)],
|
||||
call_n!(1),
|
||||
@@ -254,7 +256,7 @@ pub fn build_code_dir() -> (Code, CodeDir, OpDir)
|
||||
|
||||
code_dir.insert((String::from(";"), 2), (PredicateKeyType::BuiltIn, 76));
|
||||
code_dir.insert((String::from(","), 2), (PredicateKeyType::BuiltIn, 81));
|
||||
code_dir.insert((String::from("->"), 2), (PredicateKeyType::BuiltIn, 134));
|
||||
code_dir.insert((String::from("->"), 2), (PredicateKeyType::BuiltIn, 136));
|
||||
|
||||
(builtin_code, code_dir, op_dir)
|
||||
}
|
||||
|
||||
@@ -116,6 +116,15 @@ impl CodeOffsets {
|
||||
flattened_index
|
||||
}
|
||||
|
||||
fn adjust_internal_index(index: IntIndex) -> IntIndex
|
||||
{
|
||||
match index {
|
||||
IntIndex::Internal(o) => IntIndex::Internal(o + 1),
|
||||
IntIndex::External(o) => IntIndex::External(o),
|
||||
_ => IntIndex::Fail
|
||||
}
|
||||
}
|
||||
|
||||
fn switch_on_constant(con_ind: HashMap<Constant, ThirdLevelIndex>, prelude: &mut CodeDeque)
|
||||
-> IntIndex
|
||||
{
|
||||
@@ -130,24 +139,11 @@ impl CodeOffsets {
|
||||
IntIndex::Internal(1)
|
||||
} else {
|
||||
con_ind.values().next()
|
||||
.map(|i| *i)
|
||||
.map(|index| Self::adjust_internal_index(*index))
|
||||
.unwrap_or(IntIndex::Fail)
|
||||
}
|
||||
}
|
||||
|
||||
fn switch_on_list(mut lists: ThirdLevelIndex, prelude: &mut CodeDeque) -> IntIndex
|
||||
{
|
||||
if lists.len() > 1 {
|
||||
Self::cap_choice_seq_with_trust(&mut lists);
|
||||
prelude.extend(lists.into_iter().map(|i| Line::from(i)));
|
||||
IntIndex::Internal(0)
|
||||
} else {
|
||||
lists.first()
|
||||
.map(|i| IntIndex::External(i.offset()))
|
||||
.unwrap_or(IntIndex::Fail)
|
||||
}
|
||||
}
|
||||
|
||||
fn switch_on_structure(str_ind: HashMap<(Atom, usize), ThirdLevelIndex>, prelude: &mut CodeDeque)
|
||||
-> IntIndex
|
||||
{
|
||||
@@ -162,11 +158,23 @@ impl CodeOffsets {
|
||||
IntIndex::Internal(1)
|
||||
} else {
|
||||
str_ind.values().next()
|
||||
.map(|i| *i)
|
||||
.map(|index| Self::adjust_internal_index(*index))
|
||||
.unwrap_or(IntIndex::Fail)
|
||||
}
|
||||
}
|
||||
|
||||
fn switch_on_list(mut lists: ThirdLevelIndex, prelude: &mut CodeDeque) -> IntIndex
|
||||
{
|
||||
if lists.len() > 1 {
|
||||
Self::cap_choice_seq_with_trust(&mut lists);
|
||||
prelude.extend(lists.into_iter().map(|i| Line::from(i)));
|
||||
IntIndex::Internal(0)
|
||||
} else {
|
||||
lists.first()
|
||||
.map(|i| IntIndex::External(i.offset()))
|
||||
.unwrap_or(IntIndex::Fail)
|
||||
}
|
||||
}
|
||||
|
||||
fn switch_on_str_offset_from(str_loc: IntIndex, prelude_len: usize, con_loc: IntIndex)
|
||||
-> usize
|
||||
@@ -186,7 +194,7 @@ impl CodeOffsets {
|
||||
match con_loc {
|
||||
IntIndex::External(offset) => offset + prelude_len + 1,
|
||||
IntIndex::Fail => 0,
|
||||
IntIndex::Internal(offset) => offset,
|
||||
IntIndex::Internal(offset) => offset,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -183,10 +183,8 @@ impl fmt::Display for BuiltInInstruction {
|
||||
write!(f, "reset_block"),
|
||||
&BuiltInInstruction::SetBall =>
|
||||
write!(f, "set_ball"),
|
||||
&BuiltInInstruction::SetNeckCutPoint(terminal) =>
|
||||
write!(f, "set_neck_cp {}", terminal),
|
||||
&BuiltInInstruction::SetNonNeckCutPoint(terminal) =>
|
||||
write!(f, "set_non_neck_cp {}", terminal),
|
||||
&BuiltInInstruction::SetCutPoint =>
|
||||
write!(f, "set_cp"),
|
||||
&BuiltInInstruction::Succeed =>
|
||||
write!(f, "true"),
|
||||
&BuiltInInstruction::UnwindStack =>
|
||||
@@ -399,7 +397,7 @@ pub fn eval<'a, 'b: 'a>(wam: &'a mut Machine, tl: &'b TopLevel) -> EvalSession<'
|
||||
Ok(rule) => rule,
|
||||
Err(e) => return EvalSession::ParserError(e)
|
||||
};
|
||||
|
||||
|
||||
wam.add_rule(rule, compiled_rule)
|
||||
},
|
||||
&TopLevel::Query(ref query) => {
|
||||
|
||||
@@ -1666,24 +1666,17 @@ impl MachineState {
|
||||
|
||||
self.p += 1;
|
||||
},
|
||||
&BuiltInInstruction::SetNeckCutPoint(terminal) => {
|
||||
&BuiltInInstruction::SetCutPoint => {
|
||||
let nb = self.store(self.deref(self[temp_v!(1)].clone()));
|
||||
|
||||
match nb {
|
||||
Addr::Con(Constant::Usize(nb)) => {
|
||||
self.or_stack.truncate(nb);
|
||||
self.b = nb;
|
||||
self.neck_cut(terminal);
|
||||
},
|
||||
_ => self.fail = true
|
||||
};
|
||||
},
|
||||
&BuiltInInstruction::SetNonNeckCutPoint(terminal) => {
|
||||
let nb = self.store(self.deref(self[temp_v!(1)].clone()));
|
||||
|
||||
self.tidy_trail();
|
||||
|
||||
match nb {
|
||||
Addr::Con(Constant::Usize(nb)) => {
|
||||
self.b = nb;
|
||||
self.non_neck_cut(terminal);
|
||||
self.p += 1;
|
||||
},
|
||||
_ => self.fail = true
|
||||
};
|
||||
@@ -1731,7 +1724,7 @@ impl MachineState {
|
||||
self.fail = true;
|
||||
},
|
||||
&BuiltInInstruction::IsAtomic(r) => {
|
||||
let d = self.deref(self[r].clone());
|
||||
let d = self.store(self.deref(self[r].clone()));
|
||||
|
||||
match d {
|
||||
Addr::Con(_) => self.p += 1,
|
||||
@@ -1739,7 +1732,7 @@ impl MachineState {
|
||||
};
|
||||
},
|
||||
&BuiltInInstruction::IsVar(r) => {
|
||||
let d = self.deref(self[r].clone());
|
||||
let d = self.store(self.deref(self[r].clone()));
|
||||
|
||||
match d {
|
||||
Addr::HeapCell(_) | Addr::StackCell(_,_) => self.p += 1,
|
||||
@@ -2026,6 +2019,23 @@ impl MachineState {
|
||||
}
|
||||
}
|
||||
|
||||
fn neck_cut(&mut self, term: Terminal)
|
||||
{
|
||||
let b = self.b;
|
||||
let b0 = self.b0;
|
||||
|
||||
if b > b0 {
|
||||
self.b = b0;
|
||||
self.tidy_trail();
|
||||
}
|
||||
|
||||
if let Terminal::Terminal = term {
|
||||
self.p = self.cp;
|
||||
} else {
|
||||
self.p += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn non_neck_cut(&mut self, term: Terminal)
|
||||
{
|
||||
let b = self.b;
|
||||
@@ -2043,23 +2053,6 @@ impl MachineState {
|
||||
self.p += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn neck_cut(&mut self, term: Terminal)
|
||||
{
|
||||
let b = self.b;
|
||||
let b0 = self.b0;
|
||||
|
||||
if b > b0 {
|
||||
self.b = b0;
|
||||
self.tidy_trail();
|
||||
}
|
||||
|
||||
if let Terminal::Terminal = term {
|
||||
self.p = self.cp;
|
||||
} else {
|
||||
self.p += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn execute_cut_instr(&mut self, instr: &CutInstruction) {
|
||||
match instr {
|
||||
|
||||
@@ -165,12 +165,6 @@ macro_rules! proceed {
|
||||
)
|
||||
}
|
||||
|
||||
macro_rules! terminal {
|
||||
() => (
|
||||
Terminal::Terminal
|
||||
)
|
||||
}
|
||||
|
||||
macro_rules! non_terminal {
|
||||
() => (
|
||||
Terminal::Non
|
||||
@@ -183,6 +177,12 @@ macro_rules! cut {
|
||||
)
|
||||
}
|
||||
|
||||
macro_rules! neck_cut {
|
||||
($term:expr) => (
|
||||
Line::Cut(CutInstruction::NeckCut($term))
|
||||
)
|
||||
}
|
||||
|
||||
macro_rules! get_current_block {
|
||||
() => (
|
||||
Line::BuiltIn(BuiltInInstruction::GetCurrentBlock)
|
||||
@@ -303,15 +303,9 @@ macro_rules! get_cp {
|
||||
)
|
||||
}
|
||||
|
||||
macro_rules! set_neck_cp {
|
||||
($term:expr) => (
|
||||
Line::BuiltIn(BuiltInInstruction::SetNeckCutPoint($term))
|
||||
)
|
||||
}
|
||||
|
||||
macro_rules! set_non_neck_cp {
|
||||
($term:expr) => (
|
||||
Line::BuiltIn(BuiltInInstruction::SetNonNeckCutPoint($term))
|
||||
macro_rules! set_cp {
|
||||
() => (
|
||||
Line::BuiltIn(BuiltInInstruction::SetCutPoint)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user