...
 
Commits (2)
......@@ -30,8 +30,8 @@ use strs::io;
use strs::factory::ATermFactory;
use strs::error::{Error, Result};
use strs::ctree;
use strs::preprocess::full_ctree as preprocess_ext;
use strs::preprocess;
use strs::ir_v1::full_ctree as ir_v1_ext;
use strs::ir_v1;
// TODO: Remove single variable matches when the variable isn't used afterwards
......@@ -77,7 +77,7 @@ fn exec(program: &str, output: &str, debug: bool) -> Result<()> {
let factory = ATermFactory::new();
let program = io::read_aterm(&factory, &program)?;
let program: ctree::Module = (&program).try_into()?;
let program: preprocess_ext::Module = program.try_into()?;
let program: ir_v1_ext::Module = program.try_into()?;
let program = if !debug {
program.optimize(&mut ())
......@@ -177,7 +177,7 @@ impl<'s> Scope<'s> {
fn from_let_defs<'a, I>(no_of_scopes: usize, defs: I) -> Self
where
I: IntoIterator<Item = &'a preprocess::Def<'s>>,
I: IntoIterator<Item = &'a ir_v1::Def<'s>>,
's: 'a,
{
Scope {
......@@ -310,11 +310,11 @@ impl<'s> Scopes<'s> {
}
}
impl<'s> CTreeOptimize for preprocess_ext::Module<'s> {
impl<'s> CTreeOptimize for ir_v1_ext::Module<'s> {
type Context = ();
fn optimize(self, _: &mut Self::Context) -> Self {
use preprocess_ext::Module::*;
use ir_v1_ext::Module::*;
// eprintln!("CTreeOptimize::optimize(Module, _)");
......@@ -340,11 +340,11 @@ impl<'s> CTreeOptimize for preprocess_ext::Module<'s> {
}
}
impl<'s> CTreeOptimize for preprocess_ext::Decl<'s> {
impl<'s> CTreeOptimize for ir_v1_ext::Decl<'s> {
type Context = ();
fn optimize(self, _: &mut Self::Context) -> Self {
use preprocess_ext::Decl::*;
use ir_v1_ext::Decl::*;
// eprintln!("CTreeOptimize::optimize(Decl, _)");
......@@ -362,11 +362,11 @@ impl<'s> CTreeOptimize for preprocess_ext::Decl<'s> {
}
}
impl<'s> CTreeOptimize for preprocess_ext::Def<'s> {
impl<'s> CTreeOptimize for ir_v1_ext::Def<'s> {
type Context = ();
fn optimize(self, _: &mut Self::Context) -> Self {
use preprocess_ext::Def::*;
use ir_v1_ext::Def::*;
// eprintln!("CTreeOptimize::optimize(Def, _)");
......@@ -385,7 +385,7 @@ impl<'s> CTreeOptimize for preprocess_ext::Def<'s> {
}
}
impl<'s> CTreeOptimize for preprocess::Def<'s> {
impl<'s> CTreeOptimize for ir_v1::Def<'s> {
type Context = (Option<InternedString<'s>>, Scopes<'s>);
fn optimize(mut self, c: &mut Self::Context) -> Self {
......@@ -394,7 +394,7 @@ impl<'s> CTreeOptimize for preprocess::Def<'s> {
let no_of_scopes = (c.1).0.len();
// TODO: reevaluate this from_args call.
// It give an empty set of influenced variable to the sargs, which probably not correct at
// It gives an empty set of influenced variable to the sargs, which probably not correct at
// this point. The closure given as sarg to this strategy could be made before this one,
// which would make it able to change variables that this Def would be able to observe.
c.1.push_scope(Scope::from_args(no_of_scopes, self.sargs.iter().map(|&s| s), self.targs.iter().map(|&s| s)));
......@@ -431,13 +431,13 @@ where
}
// Pay attention, this is where the optimizing starts
impl<'s> CTreeOptimize for preprocess::Strategy<'s> {
impl<'s> CTreeOptimize for ir_v1::Strategy<'s> {
type Context = (Option<InternedString<'s>>, Scopes<'s>);
fn optimize(self, mut c: &mut Self::Context) -> Self {
use preprocess::Strategy;
use preprocess::MatchTerm;
use preprocess::BuildTerm;
use ir_v1::Strategy;
use ir_v1::MatchTerm;
use ir_v1::BuildTerm;
match self {
Strategy::Let(defs, body) => {
......@@ -733,8 +733,8 @@ impl<'s> CTreeOptimize for preprocess::Strategy<'s> {
}
}
fn all_vars_bound<'s>(bt: &preprocess::BuildTerm<'s>, m: &Scopes<'s>) -> bool {
use preprocess::BuildTerm::*;
fn all_vars_bound<'s>(bt: &ir_v1::BuildTerm<'s>, m: &Scopes<'s>) -> bool {
use ir_v1::BuildTerm::*;
let mut stack = vec![bt];
let mut combined_value = Value::Bound;
......@@ -767,11 +767,11 @@ fn all_vars_bound<'s>(bt: &preprocess::BuildTerm<'s>, m: &Scopes<'s>) -> bool {
combined_value.le(&Value::Bound)
}
impl<'s> CTreeOptimize for preprocess::MatchTerm<'s> {
impl<'s> CTreeOptimize for ir_v1::MatchTerm<'s> {
type Context = (Option<InternedString<'s>>, Scopes<'s>);
fn optimize(self, mut c: &mut Self::Context) -> Self {
use preprocess::MatchTerm::*;
use ir_v1::MatchTerm::*;
match self {
Var(v) => {
......@@ -805,11 +805,11 @@ impl<'s> CTreeOptimize for preprocess::MatchTerm<'s> {
}
}
impl<'s> CTreeOptimize for preprocess::BuildTerm<'s> {
impl<'s> CTreeOptimize for ir_v1::BuildTerm<'s> {
type Context = (Option<InternedString<'s>>, Scopes<'s>);
fn optimize(self, mut c: &mut Self::Context) -> Self {
use preprocess::BuildTerm::*;
use ir_v1::BuildTerm::*;
match self {
Var(v) => {
......@@ -839,9 +839,9 @@ impl<'s> CTreeOptimize for preprocess::BuildTerm<'s> {
struct DynamicCall;
fn match_vars_in_strategy<'s>(
strat: &preprocess::Strategy<'s>,
strat: &ir_v1::Strategy<'s>,
) -> ::std::result::Result<FnvHashSet<InternedString<'s>>, DynamicCall> {
use preprocess::Strategy;
use ir_v1::Strategy;
match *strat {
Strategy::Let(_, ref body) => match_vars_in_strategy(body),
......@@ -896,8 +896,8 @@ fn match_vars_in_strategy<'s>(
}
}
fn match_vars<'s>(term: &preprocess::MatchTerm<'s>) -> FnvHashSet<InternedString<'s>> {
use preprocess::MatchTerm;
fn match_vars<'s>(term: &ir_v1::MatchTerm<'s>) -> FnvHashSet<InternedString<'s>> {
use ir_v1::MatchTerm;
let mut result = FnvHashSet::default();
let mut stack = vec![term];
......@@ -946,7 +946,7 @@ mod test {
.expect("ATerm representation of CTree")
.0;
let program: ctree::Module = (&program).try_into().expect("Typed CTree");
let program: preprocess_ext::Module = program.try_into().expect("Preprocessed CTree");
let program: ir_v1_ext::Module = program.try_into().expect("Preprocessed CTree");
let program = program.optimize(&mut ());
......
use error::{Result, Error};
use factory::{ATermFactory, ATerm, ATermRef};
use preprocess::{Def, StrategyDef};
use preprocess::ir_v1::{Def, StrategyDef};
use primitives::{Primitives, eval_prim_ref};
use primitives::ssl::State;
......@@ -28,7 +28,7 @@ pub struct MutContext<'d, 'f: 'd> {
impl<'d, 'f: 'd> MutContext<'d, 'f> {
pub fn new(
factory: &'f ATermFactory,
strat_scopes: Vec<StrategyScope<'d, 'f>>,
strat_scope: StrategyScope<'d, 'f>,
primitives: Vec<&'static Primitives>,
) -> MutContext<'d, 'f> {
MutContext {
......@@ -37,7 +37,7 @@ impl<'d, 'f: 'd> MutContext<'d, 'f> {
primitives: primitives,
term: RefCell::new(Vec::new()),
overlays: RefCell::new(Vec::new()),
strategy: RefCell::new(strat_scopes),
strategy: RefCell::new(vec![strat_scope]),
ssl_state: RefCell::new(State::new()),
}
}
......
use context::MutContext;
use error::{Result, Error};
use factory::{ATermFactory, ATermRef};
use preprocess;
use preprocess::{StrategyDef, preprocess};
use preprocess::ir_v1;
use preprocess::ir_v1::{StrategyDef, preprocess};
use primitives::Primitives;
use aterm::{ATerm as A, ATermFactory as ATF};
......@@ -97,20 +97,18 @@ pub fn interpret<'f>(
Ok(v) => v,
Err(e) => return Err(TracedError(e, String::new())),
};
let libs = match libraries
let defs = match libraries
.libs
.into_iter()
.map(|l| match_(&l).and_then(preprocess))
.chain(iter::once(Ok(program)))
.collect::<Result<Vec<_>>>()
{
Ok(v) => v,
Err(e) => return Err(TracedError(e, String::new())),
};
let base_scopes = libs.iter()
.map(Scope::from_defs)
.chain(iter::once(Scope::from_defs(&program)))
.collect();
let context = MutContext::new(factory, base_scopes, libraries.prims);
let flat_defs: Vec<_> = defs.into_iter().flat_map(|v| v).collect();
let context = MutContext::new(factory, Scope::from_defs(&flat_defs), libraries.prims);
let main = match context.get_strategy(strategy) {
Ok(v) => v,
Err(e) => {
......@@ -134,9 +132,9 @@ pub trait Eval<'d, 'f> {
fn eval(&'d self, context: &MutContext<'d, 'f>, current: ATermRef<'f>) -> Result<ATermRef<'f>>;
}
impl<'d, 'f: 'd> Eval<'d, 'f> for preprocess::Strategy<'f> {
impl<'d, 'f: 'd> Eval<'d, 'f> for ir_v1::Strategy<'f> {
fn eval(&'d self, context: &MutContext<'d, 'f>, current: ATermRef<'f>) -> Result<ATermRef<'f>> {
use preprocess::Strategy::*;
use preprocess::ir_v1::Strategy::*;
use context;
match *self {
Let(ref defs, ref body) => {
......@@ -297,11 +295,11 @@ impl<'d, 'f: 'd> Eval<'d, 'f> for preprocess::Strategy<'f> {
fn eval_match<'d, 'f: 'd>(
context: &MutContext<'d, 'f>,
match_term: &'d preprocess::MatchTerm<'f>,
match_term: &'d ir_v1::MatchTerm<'f>,
current: &ATermRef<'f>,
) -> Result<()> {
use preprocess::MatchTerm::*;
use preprocess::C;
use preprocess::ir_v1::MatchTerm::*;
use preprocess::ir_v1::C;
match *match_term {
Var(s) => context.match_term(s, current),
......@@ -436,7 +434,7 @@ fn eval_match<'d, 'f: 'd>(
}
mod build_term {
use preprocess::BuildTerm;
use preprocess::ir_v1::BuildTerm;
use context::MutContext;
use error::{Error, Result};
use factory::ATermRef;
......@@ -456,8 +454,8 @@ mod build_term {
context: &MutContext<'d, 'f>,
annos: Option<Vec<ATermRef<'f>>>,
) -> Result<ATermRef<'f>> {
use preprocess::BuildTerm::*;
use preprocess::C;
use preprocess::ir_v1::BuildTerm::*;
use preprocess::ir_v1::C;
match *term {
Var(s) => {
......@@ -575,7 +573,7 @@ mod build_term {
}
fn eval_<'d, 'f: 'd, F1, F2>(
strat: &'d preprocess::Strategy<'f>,
strat: &'d ir_v1::Strategy<'f>,
context: &MutContext<'d, 'f>,
current: ATermRef<'f>,
children_fun: F1,
......@@ -583,7 +581,7 @@ fn eval_<'d, 'f: 'd, F1, F2>(
) -> Result<ATermRef<'f>>
where
F1: Fn(&[ATermRef<'f>],
&'d preprocess::Strategy<'f>,
&'d ir_v1::Strategy<'f>,
&MutContext<'d, 'f>)
-> Result<Box<[ATermRef<'f>]>>,
F2: Fn(ATermRef<'f>) -> Result<ATermRef<'f>>,
......@@ -625,7 +623,7 @@ where
fn one_rec<'d, 'f: 'd>(
r: &[ATermRef<'f>],
strat: &'d preprocess::Strategy<'f>,
strat: &'d ir_v1::Strategy<'f>,
context: &MutContext<'d, 'f>,
) -> Result<Box<[ATermRef<'f>]>> {
let mut result = Vec::with_capacity(r.len());
......@@ -650,7 +648,7 @@ fn one_rec<'d, 'f: 'd>(
fn some_rec<'d, 'f: 'd>(
r: &[ATermRef<'f>],
strat: &'d preprocess::Strategy<'f>,
strat: &'d ir_v1::Strategy<'f>,
context: &MutContext<'d, 'f>,
) -> Result<Box<[ATermRef<'f>]>> {
let mut result = Vec::with_capacity(r.len());
......@@ -672,7 +670,7 @@ fn some_rec<'d, 'f: 'd>(
fn all_rec<'d, 'f: 'd>(
r: &[ATermRef<'f>],
strat: &'d preprocess::Strategy<'f>,
strat: &'d ir_v1::Strategy<'f>,
context: &MutContext<'d, 'f>,
) -> Result<Box<[ATermRef<'f>]>> {
r.into_iter()
......@@ -748,9 +746,9 @@ pub fn strategy_def_from_strategy<'d, 'f: 'd>(
context: &MutContext<'d, 'f>,
name: InternedString<'f>,
number: usize,
body: &'d preprocess::Strategy<'f>,
body: &'d ir_v1::Strategy<'f>,
) -> Result<StrategyDef<'d, 'f>> {
use preprocess::Strategy;
use preprocess::ir_v1::Strategy;
let term_scope_offset = context.term.borrow().len();
let strat_scope_offset = context.strategy.borrow().len();
// NOTE: this is not an optimisation but a necessary semantic distinction to allow
......
......@@ -10,7 +10,9 @@ pub mod io;
pub mod error;
pub mod factory;
pub mod interpreter;
pub mod ctree;
mod preprocess;
mod context;
pub mod preprocess;
mod primitives;
pub use preprocess::ctree;
pub use preprocess::ir_v1;
pub use preprocess::ir_v2;
......@@ -25,11 +25,12 @@ mod io;
mod error;
mod factory;
mod interpreter;
mod ctree;
mod context;
mod preprocess;
mod context;
mod primitives;
use preprocess::ctree;
#[derive(Debug, StructOpt)]
struct Opt {
// #[structopt(short = "d", long = "debug", help = "Activate debug mode")]
......
This diff is collapsed.
pub mod ctree;
pub mod ir_v1;
pub mod ir_v2;
\ No newline at end of file
......@@ -3,7 +3,7 @@
use context::MutContext;
use error::Result;
use factory::ATermRef;
use preprocess::StrategyDef;
use preprocess::ir_v1::StrategyDef;
use phf;
......
......@@ -2,7 +2,7 @@ macro_rules! primitive {
($name:ident, ($context:ident, $current:ident) => $body:block) => {
pub fn $name<'d, 'f: 'd>(
$context: &::context::MutContext<'d, 'f>,
_sargs: &[::preprocess::StrategyDef<'d, 'f>],
_sargs: &[::preprocess::ir_v1::StrategyDef<'d, 'f>],
_targs: &[::factory::ATermRef<'f>],
$current: ::factory::ATermRef<'f>,
) -> ::error::Result<::factory::ATermRef<'f>> {
......@@ -12,7 +12,7 @@ macro_rules! primitive {
($name:ident, $targs_no:expr, ($context:ident, $targs:ident, $current:ident) => $body:block) => {
pub fn $name<'d, 'f: 'd>(
$context: &::context::MutContext<'d, 'f>,
_sargs: &[::preprocess::StrategyDef<'d, 'f>],
_sargs: &[::preprocess::ir_v1::StrategyDef<'d, 'f>],
$targs: &[::factory::ATermRef<'f>],
$current: ::factory::ATermRef<'f>,
) -> ::error::Result<::factory::ATermRef<'f>> {
......@@ -25,7 +25,7 @@ macro_rules! primitive {
($name:ident, $sargs_no:expr, 0, ($context:ident, $sargs:ident, $current:ident) => $body:block) => {
pub fn $name<'d, 'f: 'd>(
$context: &::context::MutContext<'d, 'f>,
$sargs: &[::preprocess::StrategyDef<'d, 'f>],
$sargs: &[::preprocess::ir_v1::StrategyDef<'d, 'f>],
_targs: &[::factory::ATermRef<'f>],
$current: ::factory::ATermRef<'f>,
) -> ::error::Result<::factory::ATermRef<'f>> {
......@@ -38,7 +38,7 @@ macro_rules! primitive {
($name:ident, $sargs_no:expr, $targs_no:expr, ($context:ident, $sargs:ident, $targs:ident, $current:ident) => $body:block) => {
pub fn $name<'d, 'f: 'd>(
$context: &::context::MutContext<'d, 'f>,
$sargs: &[::preprocess::StrategyDef<'d, 'f>],
$sargs: &[::preprocess::ir_v1::StrategyDef<'d, 'f>],
$targs: &[::factory::ATermRef<'f>],
$current: ::factory::ATermRef<'f>,
) -> ::error::Result<::factory::ATermRef<'f>> {
......@@ -55,7 +55,7 @@ macro_rules! primitive {
#[inline]
pub fn $name<'d, 'f: 'd>(
context: &::context::MutContext<'d, 'f>,
sargs: &[::preprocess::StrategyDef<'d, 'f>],
sargs: &[::preprocess::ir_v1::StrategyDef<'d, 'f>],
targs: &[::factory::ATermRef<'f>],
current: ::factory::ATermRef<'f>,
) -> ::error::Result<::factory::ATermRef<'f>> {
......@@ -65,7 +65,7 @@ macro_rules! primitive {
($name:ident, ($context:ident, $sargs:ident, $targs:ident, $current:ident) => $body:block) => {
pub fn $name<'d, 'f: 'd>(
$context: &::context::MutContext<'d, 'f>,
$sargs: &[::preprocess::StrategyDef<'d, 'f>],
$sargs: &[::preprocess::ir_v1::StrategyDef<'d, 'f>],
$targs: &[::factory::ATermRef<'f>],
$current: ::factory::ATermRef<'f>,
) -> ::error::Result<::factory::ATermRef<'f>> {
......