[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)",
IsVar(RegType),
ResetBlock,
SetBall,
- SetNeckCutPoint(Terminal),
- SetNonNeckCutPoint(Terminal),
+ SetCutPoint,
Succeed,
Unify,
UnwindStack
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),
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)],
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),
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),
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)
}
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
{
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
{
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
match con_loc {
IntIndex::External(offset) => offset + prelude_len + 1,
IntIndex::Fail => 0,
- IntIndex::Internal(offset) => offset,
+ IntIndex::Internal(offset) => offset,
}
}
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 =>
Ok(rule) => rule,
Err(e) => return EvalSession::ParserError(e)
};
-
+
wam.add_rule(rule, compiled_rule)
},
&TopLevel::Query(ref query) => {
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
};
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,
};
},
&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,
}
}
- fn non_neck_cut(&mut self, term: Terminal)
+ fn neck_cut(&mut self, term: Terminal)
{
let b = self.b;
- let e = self.e;
- let b0 = self.and_stack[e].b0; // STACK[E+2+1]
+ let b0 = self.b0;
if b > b0 {
self.b = b0;
self.p = self.cp;
} else {
self.p += 1;
- }
+ }
}
- fn neck_cut(&mut self, term: Terminal)
+ fn non_neck_cut(&mut self, term: Terminal)
{
let b = self.b;
- let b0 = self.b0;
+ let e = self.e;
+ let b0 = self.and_stack[e].b0; // STACK[E+2+1]
if b > b0 {
self.b = b0;
self.p = self.cp;
} else {
self.p += 1;
- }
+ }
}
fn execute_cut_instr(&mut self, instr: &CutInstruction) {
)
}
-macro_rules! terminal {
- () => (
- Terminal::Terminal
- )
-}
-
macro_rules! non_terminal {
() => (
Terminal::Non
)
}
+macro_rules! neck_cut {
+ ($term:expr) => (
+ Line::Cut(CutInstruction::NeckCut($term))
+ )
+}
+
macro_rules! get_current_block {
() => (
Line::BuiltIn(BuiltInInstruction::GetCurrentBlock)
)
}
-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)
)
}