Commit dc2955d6 authored by Jeff Smits's avatar Jeff Smits

Add IR version 2 (not used yet)

parent e41c3d74
use error::{Result, Error};
use factory::{ATermFactory, ATerm, ATermRef};
use ir_v1::{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 ir_v1;
use ir_v1::{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) => {
......@@ -136,7 +134,7 @@ pub trait Eval<'d, '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 ir_v1::Strategy::*;
use preprocess::ir_v1::Strategy::*;
use context;
match *self {
Let(ref defs, ref body) => {
......@@ -300,8 +298,8 @@ fn eval_match<'d, 'f: 'd>(
match_term: &'d ir_v1::MatchTerm<'f>,
current: &ATermRef<'f>,
) -> Result<()> {
use ir_v1::MatchTerm::*;
use ir_v1::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 ir_v1::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 ir_v1::BuildTerm::*;
use ir_v1::C;
use preprocess::ir_v1::BuildTerm::*;
use preprocess::ir_v1::C;
match *term {
Var(s) => {
......@@ -750,7 +748,7 @@ pub fn strategy_def_from_strategy<'d, 'f: 'd>(
number: usize,
body: &'d ir_v1::Strategy<'f>,
) -> Result<StrategyDef<'d, 'f>> {
use ir_v1::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
......
......@@ -15,3 +15,4 @@ mod context;
mod primitives;
pub use preprocess::ctree;
pub use preprocess::ir_v1;
pub use preprocess::ir_v2;
......@@ -30,7 +30,6 @@ mod context;
mod primitives;
use preprocess::ctree;
use preprocess::ir_v1;
#[derive(Debug, StructOpt)]
struct Opt {
......
This diff is collapsed.
pub mod ctree;
pub mod ir_v1;
\ No newline at end of file
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 ir_v1::StrategyDef;
use preprocess::ir_v1::StrategyDef;
use phf;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment