clean up codegen.rs
This commit is contained in:
@@ -8,7 +8,6 @@ use prolog::targets::*;
|
|||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::mem::swap;
|
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
pub struct CodeGenerator<'a, TermMarker> {
|
pub struct CodeGenerator<'a, TermMarker> {
|
||||||
@@ -25,10 +24,10 @@ pub enum EvalError {
|
|||||||
QueryFailureWithException(String)
|
QueryFailureWithException(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum EvalSession<'a> {
|
pub enum EvalSession<'a> {
|
||||||
EntrySuccess,
|
EntrySuccess,
|
||||||
Error(EvalError),
|
Error(EvalError),
|
||||||
InitialQuerySuccess(AllocVarDict<'a>, HeapVarDict<'a>),
|
InitialQuerySuccess(AllocVarDict<'a>, HeapVarDict<'a>),
|
||||||
SubsequentQuerySuccess,
|
SubsequentQuerySuccess,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,11 +285,8 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
|||||||
let mut dealloc_index = code.len() - 1;
|
let mut dealloc_index = code.len() - 1;
|
||||||
|
|
||||||
match code.last_mut() {
|
match code.last_mut() {
|
||||||
Some(&mut Line::Control(ref mut ctrl)) => {
|
Some(&mut Line::Control(ref mut ctrl)) =>
|
||||||
let mut instr = ControlInstruction::Proceed;
|
match ctrl.clone() {
|
||||||
swap(ctrl, &mut instr);
|
|
||||||
|
|
||||||
match instr {
|
|
||||||
ControlInstruction::ArgCall =>
|
ControlInstruction::ArgCall =>
|
||||||
*ctrl = ControlInstruction::ArgExecute,
|
*ctrl = ControlInstruction::ArgExecute,
|
||||||
ControlInstruction::Call(name, arity, _) =>
|
ControlInstruction::Call(name, arity, _) =>
|
||||||
@@ -313,8 +309,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
|||||||
*ctrl = ControlInstruction::IsExecute(r, at),
|
*ctrl = ControlInstruction::IsExecute(r, at),
|
||||||
ControlInstruction::Proceed => {},
|
ControlInstruction::Proceed => {},
|
||||||
_ => dealloc_index += 1 // = code.len()
|
_ => dealloc_index += 1 // = code.len()
|
||||||
}
|
},
|
||||||
},
|
|
||||||
Some(&mut Line::Cut(CutInstruction::Cut)) =>
|
Some(&mut Line::Cut(CutInstruction::Cut)) =>
|
||||||
dealloc_index += 1,
|
dealloc_index += 1,
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -493,12 +488,12 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
|||||||
let conjunct_info = self.collect_var_data(iter);
|
let conjunct_info = self.collect_var_data(iter);
|
||||||
|
|
||||||
let &Rule { head: (ref p0, ref p1), ref clauses } = rule;
|
let &Rule { head: (ref p0, ref p1), ref clauses } = rule;
|
||||||
let mut code = Vec::new();
|
let mut code = Vec::new();
|
||||||
|
|
||||||
if let &QueryTerm::Term(ref term) = p0 {
|
if let &QueryTerm::Term(ref term) = p0 {
|
||||||
self.marker.reset_arg_at_head(term);
|
self.marker.reset_arg_at_head(term);
|
||||||
self.compile_seq_prelude(&conjunct_info, &mut code);
|
self.compile_seq_prelude(&conjunct_info, &mut code);
|
||||||
|
|
||||||
if let &Term::Clause(..) = term {
|
if let &Term::Clause(..) = term {
|
||||||
let iter = FactInstruction::iter(term);
|
let iter = FactInstruction::iter(term);
|
||||||
let fact = self.compile_target(iter, GenContext::Head, false);
|
let fact = self.compile_target(iter, GenContext::Head, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user