remove indirection in jmp instructions
This commit is contained in:
@@ -367,7 +367,7 @@ pub enum CompareNumberQT {
|
|||||||
|
|
||||||
// vars of predicate, toplevel offset. Vec<Term> is always a vector
|
// vars of predicate, toplevel offset. Vec<Term> is always a vector
|
||||||
// of vars (we get their adjoining cells this way).
|
// of vars (we get their adjoining cells this way).
|
||||||
pub type JumpStub = (Vec<Term>, Rc<Cell<usize>>);
|
pub type JumpStub = Vec<Term>;
|
||||||
|
|
||||||
pub enum QueryTerm {
|
pub enum QueryTerm {
|
||||||
Arg(Vec<Box<Term>>),
|
Arg(Vec<Box<Term>>),
|
||||||
@@ -395,7 +395,7 @@ impl QueryTerm {
|
|||||||
&QueryTerm::Functor(_) => 3,
|
&QueryTerm::Functor(_) => 3,
|
||||||
&QueryTerm::Inlined(ref term) => term.arity(),
|
&QueryTerm::Inlined(ref term) => term.arity(),
|
||||||
&QueryTerm::Is(_) => 2,
|
&QueryTerm::Is(_) => 2,
|
||||||
&QueryTerm::Jump((ref vars, _)) => vars.len(),
|
&QueryTerm::Jump(ref vars) => vars.len(),
|
||||||
&QueryTerm::CallN(ref terms) => terms.len(),
|
&QueryTerm::CallN(ref terms) => terms.len(),
|
||||||
&QueryTerm::Cut => 0,
|
&QueryTerm::Cut => 0,
|
||||||
&QueryTerm::Term(ref term) => term.arity(),
|
&QueryTerm::Term(ref term) => term.arity(),
|
||||||
@@ -818,8 +818,8 @@ pub enum ControlInstruction {
|
|||||||
ExecuteN(usize),
|
ExecuteN(usize),
|
||||||
FunctorCall,
|
FunctorCall,
|
||||||
FunctorExecute,
|
FunctorExecute,
|
||||||
JmpByCall(usize, Rc<Cell<usize>>), // arity, global_offset.
|
JmpByCall(usize, usize), // arity, global_offset.
|
||||||
JmpByExecute(usize, Rc<Cell<usize>>),
|
JmpByExecute(usize, usize),
|
||||||
// GotoCall(usize, usize), // p, arity.
|
// GotoCall(usize, usize), // p, arity.
|
||||||
GotoExecute(usize, usize), // p, arity.
|
GotoExecute(usize, usize), // p, arity.
|
||||||
IsCall(RegType, ArithmeticTerm),
|
IsCall(RegType, ArithmeticTerm),
|
||||||
|
|||||||
@@ -254,8 +254,8 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
|||||||
code.push(Line::Control(ControlInstruction::FunctorCall)),
|
code.push(Line::Control(ControlInstruction::FunctorCall)),
|
||||||
&QueryTerm::Inlined(_) =>
|
&QueryTerm::Inlined(_) =>
|
||||||
code.push(proceed!()),
|
code.push(proceed!()),
|
||||||
&QueryTerm::Jump((ref vars, ref offset)) => {
|
&QueryTerm::Jump(ref vars) => {
|
||||||
code.push(jmp_call!(vars.len(), offset.clone()));
|
code.push(jmp_call!(vars.len(), 0));
|
||||||
},
|
},
|
||||||
&QueryTerm::Term(Term::Constant(_, Constant::Atom(ref atom))) => {
|
&QueryTerm::Term(Term::Constant(_, Constant::Atom(ref atom))) => {
|
||||||
let call = ControlInstruction::Call(atom.clone(), 0, pvs);
|
let call = ControlInstruction::Call(atom.clone(), 0, pvs);
|
||||||
|
|||||||
@@ -137,10 +137,10 @@ impl fmt::Display for ControlInstruction {
|
|||||||
write!(f, "is_call {}, {}", r, at),
|
write!(f, "is_call {}, {}", r, at),
|
||||||
&ControlInstruction::IsExecute(r, ref at) =>
|
&ControlInstruction::IsExecute(r, ref at) =>
|
||||||
write!(f, "is_execute {}, {}", r, at),
|
write!(f, "is_execute {}, {}", r, at),
|
||||||
&ControlInstruction::JmpByCall(arity, ref offset) =>
|
&ControlInstruction::JmpByCall(arity, offset) =>
|
||||||
write!(f, "jmp_by_call {}/{}", offset.get(), arity),
|
write!(f, "jmp_by_call {}/{}", offset, arity),
|
||||||
&ControlInstruction::JmpByExecute(arity, ref offset) =>
|
&ControlInstruction::JmpByExecute(arity, offset) =>
|
||||||
write!(f, "jmp_by_execute {}/{}", offset.get(), arity),
|
write!(f, "jmp_by_execute {}/{}", offset, arity),
|
||||||
&ControlInstruction::Proceed =>
|
&ControlInstruction::Proceed =>
|
||||||
write!(f, "proceed"),
|
write!(f, "proceed"),
|
||||||
&ControlInstruction::ThrowCall =>
|
&ControlInstruction::ThrowCall =>
|
||||||
@@ -412,13 +412,15 @@ fn compile_relation(tl: &TopLevel) -> Result<Code, ParserError>
|
|||||||
// set first jmp_by_call or jmp_by_index instruction to code.len() - idx,
|
// set first jmp_by_call or jmp_by_index instruction to code.len() - idx,
|
||||||
// where idx is the place it occurs. It only does this to the *first* uninitialized
|
// where idx is the place it occurs. It only does this to the *first* uninitialized
|
||||||
// jmp index it encounters, then returns.
|
// jmp index it encounters, then returns.
|
||||||
fn set_first_index(code: &Code)
|
fn set_first_index(code: &mut Code)
|
||||||
{
|
{
|
||||||
for (idx, line) in code.iter().enumerate() {
|
let code_len = code.len();
|
||||||
|
|
||||||
|
for (idx, line) in code.iter_mut().enumerate() {
|
||||||
match line {
|
match line {
|
||||||
&Line::Control(ControlInstruction::JmpByExecute(_, ref offset))
|
&mut Line::Control(ControlInstruction::JmpByExecute(_, ref mut offset))
|
||||||
| &Line::Control(ControlInstruction::JmpByCall(_, ref offset)) if offset.get() == 0 => {
|
| &mut Line::Control(ControlInstruction::JmpByCall(_, ref mut offset)) if *offset == 0 => {
|
||||||
offset.set(code.len() - idx);
|
*offset = code_len - idx;
|
||||||
break;
|
break;
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ impl<'a> QueryIterator<'a> {
|
|||||||
QueryIterator { state_stack: vec![state] }
|
QueryIterator { state_stack: vec![state] }
|
||||||
},
|
},
|
||||||
&QueryTerm::Cut => QueryIterator { state_stack: vec![] },
|
&QueryTerm::Cut => QueryIterator { state_stack: vec![] },
|
||||||
&QueryTerm::Jump((ref vars, _)) => {
|
&QueryTerm::Jump(ref vars) => {
|
||||||
let state_stack = vars.iter().rev().map(|t| {
|
let state_stack = vars.iter().rev().map(|t| {
|
||||||
TermIterState::to_state(Level::Shallow, t)
|
TermIterState::to_state(Level::Shallow, t)
|
||||||
}).collect();
|
}).collect();
|
||||||
@@ -273,7 +273,7 @@ impl<'a> ChunkedIterator<'a>
|
|||||||
|
|
||||||
while let Some(term) = item {
|
while let Some(term) = item {
|
||||||
match term {
|
match term {
|
||||||
&QueryTerm::Jump((ref vars, _)) => {
|
&QueryTerm::Jump(ref vars) => {
|
||||||
result.push(term);
|
result.push(term);
|
||||||
arity = vars.len();
|
arity = vars.len();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1692,16 +1692,16 @@ impl MachineState {
|
|||||||
self.unify(a1, Addr::Con(Constant::Number(a2)));
|
self.unify(a1, Addr::Con(Constant::Number(a2)));
|
||||||
self.p = self.cp;
|
self.p = self.cp;
|
||||||
},
|
},
|
||||||
&ControlInstruction::JmpByCall(arity, ref offset) => {
|
&ControlInstruction::JmpByCall(arity, offset) => {
|
||||||
self.cp = self.p + 1;
|
self.cp = self.p + 1;
|
||||||
self.num_of_args = arity;
|
self.num_of_args = arity;
|
||||||
self.b0 = self.b;
|
self.b0 = self.b;
|
||||||
self.p += offset.get();
|
self.p += offset;
|
||||||
},
|
},
|
||||||
&ControlInstruction::JmpByExecute(arity, ref offset) => {
|
&ControlInstruction::JmpByExecute(arity, offset) => {
|
||||||
self.num_of_args = arity;
|
self.num_of_args = arity;
|
||||||
self.b0 = self.b;
|
self.b0 = self.b;
|
||||||
self.p += offset.get();
|
self.p += offset;
|
||||||
},
|
},
|
||||||
&ControlInstruction::Proceed =>
|
&ControlInstruction::Proceed =>
|
||||||
self.p = self.cp,
|
self.p = self.cp,
|
||||||
|
|||||||
Submodule src/prolog/parser updated: 9e80f2bd82...e15eb2d27b
Reference in New Issue
Block a user