Commit 42ffb544 authored by Jeff Smits's avatar Jeff Smits

The big monomorphisation commit

parent 8cd6228f
......@@ -187,16 +187,12 @@ fn write_primitive_libs(file: &mut BufWriter<File>,
writeln!(file,
"\
pub fn eval_prim_ref<'a, B, F>(prim_ref: (Libs, usize),
context: &MutContext<'a, B, F>,
pub fn eval_prim_ref<'a>(prim_ref: (Libs, usize),
context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<AR<'a, F, B>>,
current: AR<'a, F, B>)
-> Result<AR<'a, F, B>>
where F: 'a + ATermFactory<'a, B> + ATermRead<'a, B>,
AR<'a, F, B>: Clone,
A<'a, F, B>: Eq + ATermWrite,
B: 'a + Clone
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef>
{{
match prim_ref.0 {{\
")?;
......@@ -247,16 +243,12 @@ fn write_primitives(file: &mut BufWriter<File>,
write!(file,
"\
#[inline]
fn {}<'a, B, F>(offset: usize,
context: &MutContext<'a, B, F>,
fn {}<'a>(offset: usize,
context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<AR<'a, F, B>>,
current: AR<'a, F, B>)
-> Result<AR<'a, F, B>>
where F: 'a + ATermFactory<'a, B> + ATermRead<'a, B>,
AR<'a, F, B>: Clone,
A<'a, F, B>: Eq + ATermWrite,
B: 'a
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef>
{{
match offset {{
\
......
use types::{Result, Error, A, AR};
use aterm::ATermFactory;
use types::{Result, Error, ATermFactory, ATerm, ATermRef};
use std::collections::HashMap;
use std::fmt;
use std::borrow::Borrow;
use std::marker::PhantomData;
use preprocess::SDefT;
use std::cell::RefCell;
use primitives::{Primitives, eval_prim_ref};
......@@ -13,47 +11,34 @@ use aterm::print::ATermWrite;
/// This context is internally mutable in RefCell fields. This is just for convenience as we don't
/// want to pass around the mutable fields separately. But the internal mutability is not a hidden
/// thing without effect, so the name of the context includes `Mut`.
pub struct MutContext<'a, B, F>
where F: 'a + ATermFactory<'a, B>,
AR<'a, F, B>: Clone,
A<'a, F, B>: Eq,
B: 'a
{
pub struct MutContext<'a> {
pub stack_tracer: RefCell<StackTracer>,
pub scopes: RefCell<Vec<Scope<AR<'a, F, B>>>>,
pub factory: &'a F,
pub scopes: RefCell<Vec<Scope<ATermRef>>>,
pub factory: &'a ATermFactory,
pub primitives: Vec<&'static Primitives>,
pub ssl_state: RefCell<SslState>,
b: PhantomData<B>,
}
impl<'a, B, F> MutContext<'a, B, F>
where F: 'a + ATermFactory<'a, B>,
AR<'a, F, B>: Clone,
A<'a, F, B>: Eq,
B: 'a
{
pub fn new(factory: &'a F,
scopes: Vec<Scope<AR<'a, F, B>>>,
impl<'a> MutContext<'a> {
pub fn new(factory: &'a ATermFactory,
scopes: Vec<Scope<ATermRef>>,
primitives: Vec<&'static Primitives>)
-> MutContext<'a, B, F> {
-> MutContext<'a> {
MutContext {
stack_tracer: RefCell::new(StackTracer::default()),
factory: factory,
primitives: primitives,
scopes: RefCell::new(scopes),
ssl_state: RefCell::new(SslState::new()),
b: PhantomData,
}
}
pub fn call_primitive(&self,
prim_name: &str,
sargs: Vec<SDefT>,
targs: Vec<AR<'a, F, B>>,
current: AR<'a, F, B>)
-> Result<AR<'a, F, B>>
where A<'a, F, B>: ATermWrite, B: Clone
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef>
{
let prim_ref = self.primitives
.iter()
......@@ -76,7 +61,7 @@ impl<'a, B, F> MutContext<'a, B, F>
.ok_or(Error::UndefinedStrategy(strat_name.to_owned()))
}
pub fn get_term(&self, term_name: &str) -> Result<AR<'a, F, B>> {
pub fn get_term(&self, term_name: &str) -> Result<ATermRef> {
self.scopes
.borrow()
.iter()
......@@ -88,10 +73,10 @@ impl<'a, B, F> MutContext<'a, B, F>
.ok_or(Error::UndefinedVariable(term_name.to_owned()))
}
pub fn match_term(&self, term_name: &str, current: &AR<'a, F, B>) -> Result<()> {
pub fn match_term(&self, term_name: &str, current: &ATermRef) -> Result<()> {
match self.get_term(term_name) {
Ok(term) => {
if term.borrow() == current.borrow() {
if Borrow::<ATerm>::borrow(&term) == current.borrow() {
Ok(())
} else {
Err(Error::StrategyFailed)
......
This diff is collapsed.
......@@ -16,9 +16,8 @@ use std::process;
use aterm::parse::ATermRead;
use aterm::print::ATermWrite;
use aterm::rc::ATermFactory;
use types::Result;
use types::{Result, ATermFactory, ATermRef};
use interpreter::interpret_main;
use primitives::Primitives;
......@@ -62,7 +61,7 @@ fn main() {
}
fn exec(program_path: &str, library_paths: Vec<String>) -> Result<String> {
let f = ATermFactory::<()>::new();
let f = ATermFactory::new();
let libraries = library_paths
.into_iter()
.map(|lib_path| read_lib(&f, &lib_path))
......@@ -85,21 +84,14 @@ fn read_input(path: &str) -> io::Result<String> {
}
#[cfg_attr(rustfmt, rustfmt_skip)]
fn read_aterm<'a>(f: &ATermFactory<()>,
path: &str)
-> Result<<ATermFactory<()> as aterm::ATermFactory<'a, ()>>::ATermRef>
{
fn read_aterm<'a>(f: &ATermFactory, path: &str) -> Result<ATermRef> {
let file_contents = read_input(path)?;
let (aterm, _) = f.read_ascii(&file_contents)?;
Ok(aterm)
}
#[cfg_attr(rustfmt, rustfmt_skip)]
fn read_lib<'a>(f: &ATermFactory<()>,
path: &str)
-> Result<(<ATermFactory<()> as aterm::ATermFactory<'a, ()>>::ATermRef,
Option<&'static Primitives>)>
{
fn read_lib<'a>(f: &ATermFactory, path: &str) -> Result<(ATermRef, Option<&'static Primitives>)> {
if let Some(&(path, prim)) = primitives::LIBS.get(path) {
Ok((read_aterm(f, path)?, prim))
} else {
......
use types::{Result, Error, A, AR};
use aterm::ATermFactory;
use types::{Result, Error, ATermFactory, ATermRef};
use ctree;
use try_from::{TryInto, TryFrom};
use std::result;
......@@ -8,11 +7,7 @@ use interpreter::Eval;
use context::{MutContext, Scope};
use aterm::BrokenF32;
pub fn preprocess<'a, B, F>(program: ctree::Module) -> Result<Scope<AR<'a, F, B>>>
where F: 'a + ATermFactory<'a, B>,
AR<'a, F, B>: Clone,
B: 'a
{
pub fn preprocess(program: ctree::Module) -> Result<Scope<ATermRef>> {
let decls = match program {
ctree::Module::Module(_, decls) => decls,
ctree::Module::Specification(decls) => decls,
......@@ -35,6 +30,7 @@ pub struct SDefT {
targs: Vec<String>,
body: Strategy,
}
pub fn c_name(string: &str, sargs: usize, targs: usize) -> String {
let name = string.replace('_', "__");
let name = name.replace('-', "_");
......@@ -45,17 +41,7 @@ pub fn c_name(string: &str, sargs: usize, targs: usize) -> String {
}
impl SDefT {
pub fn eval<'a, B, F>(&self,
context: &MutContext<'a, B, F>,
sargs: Vec<SDefT>,
targs: Vec<AR<'a, F, B>>,
current: AR<'a, F, B>)
-> Result<AR<'a, F, B>>
where F: 'a + ATermFactory<'a, B>,
AR<'a, F, B>: Clone,
A<'a, F, B>: Eq,
B: 'a
{
pub fn eval<'a>(&self, context: &MutContext<'a>, sargs: Vec<SDefT>, targs: Vec<ATermRef>, current: ATermRef) -> Result<ATermRef> {
if sargs.len() != self.sargs.len() || targs.len() != self.targs.len() {
Err(Error::UndefinedStrategy(self.name.clone()))
} else {
......
......@@ -2,9 +2,9 @@ use phf;
use context::MutContext;
use preprocess::SDefT;
use types::Result;
use aterm::ATermFactory;
use aterm::ATermFactory as ATF;
use std::borrow::Borrow;
use types::{A, AR};
use types::{ATermFactory, ATermRef};
use aterm::parse::ATermRead;
use aterm::print::ATermWrite;
......
This diff is collapsed.
use aterm;
use try_from::{TryFrom, TryInto};
use std::io;
use std::result;
use std::error;
use std::fmt;
use std::rc::Rc;
use std::borrow::Borrow;
pub type Blob = ();
pub type ATermFactory = aterm::rc::ATermFactory<Blob>;
pub type ATerm = aterm::rc::ATerm<Blob>;
pub type ATermRef = Rc<aterm::rc::ATerm<Blob>>;
pub type A<'a, F, B> = <F as aterm::ATermFactory<'a, B>>::ATerm;
pub type AR<'a, F, B> = <F as aterm::ATermFactory<'a, B>>::ATermRef;
pub fn b<'a>(ar: &'a ATermRef) -> &'a ATerm {
Borrow::<ATerm>::borrow(ar)
}
pub type Result<T> = result::Result<T, Error>;
......
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