Commit a878c7e4 authored by Jeff Smits's avatar Jeff Smits

cargo fmt

parent 42ffb544
......@@ -22,134 +22,132 @@ fn main() {
("libstratego-xtc", r#"("libstratego-xtc/libstratego-xtc.ctree", Some(&SSL))"#),
("libstrc", r#"("libstrc/libstrc.ctree", Some(&STRC))"#)];
let ssl = [
// INT
"is_int",
"int",
"iori",
"xori",
"andi",
"shli",
"shri",
"addi",
"divi",
"gti",
"muli",
"modi",
"subti",
"int_to_string",
"string_to_int",
"rand",
// REAL
"is_real",
"real",
"addr",
"divr",
"gtr",
"mulr",
"modr",
"subtr",
"real_to_string",
"real_to_string_precision",
"string_to_real",
"cos",
"sin",
"atan2",
"sqrt",
// STRING
"explode_string",
"is_string",
"strcat",
"implode_string",
"strlen",
"concat_strings",
"write_term_to_string",
"read_term_from_string",
"new",
"newname",
// (FILE) SYSTEM
"chdir",
"mkdir",
"P_tmpdir",
"mkstemp",
"mkdtemp",
"filemode",
"S_ISDIR",
"fputs",
"fputc",
"access",
"getcwd",
"readdir",
"modification_time",
"fileno",
"STDIN_FILENO",
"STDOUT_FILENO",
"stdout_stream",
"STDERR_FILENO",
"close",
"perror",
"fopen",
"write_term_to_stream_baf",
"write_term_to_stream_saf",
"write_term_to_stream_taf",
"fclose",
"fgetc",
"fflush",
"remove",
"copy",
"filesize",
"rmdir",
"getenv",
"printnl",
"stderr_stream",
"write_term_to_stream_text",
"stdin_stream",
"EXDEV",
"read_term_from_stream",
"exit",
"times",
"TicksToSeconds",
"cputime",
// INDEXEDSET
"indexedSet_create",
"indexedSet_destroy",
"indexedSet_put",
"indexedSet_getIndex",
"indexedSet_elements",
"indexedSet_remove",
"indexedSet_reset",
// HASHTABLE
"dynamic_rules_hashtable",
"table_hashtable",
"hashtable_get",
"hashtable_create",
"hashtable_put",
"hashtable_reset",
"hashtable_destroy",
"hashtable_remove",
"hashtable_keys",
"table_fold",
"table_keys_fold",
"table_values_fold",
// LIST
"get_list_length",
"list_loop",
"list_fold",
// TERM
"get_constructor",
"mkterm",
"get_arguments",
"explode_term",
"get_appl_arguments_map",
"address",
"checksum",
"isPlaceholder",
"makePlaceholder",
"getPlaceholder",
"preserve_annotations_attachments",
// STACKTRACE
"stacktrace_get_all_frame_names",
];
let ssl = [// INT
"is_int",
"int",
"iori",
"xori",
"andi",
"shli",
"shri",
"addi",
"divi",
"gti",
"muli",
"modi",
"subti",
"int_to_string",
"string_to_int",
"rand",
// REAL
"is_real",
"real",
"addr",
"divr",
"gtr",
"mulr",
"modr",
"subtr",
"real_to_string",
"real_to_string_precision",
"string_to_real",
"cos",
"sin",
"atan2",
"sqrt",
// STRING
"explode_string",
"is_string",
"strcat",
"implode_string",
"strlen",
"concat_strings",
"write_term_to_string",
"read_term_from_string",
"new",
"newname",
// (FILE) SYSTEM
"chdir",
"mkdir",
"P_tmpdir",
"mkstemp",
"mkdtemp",
"filemode",
"S_ISDIR",
"fputs",
"fputc",
"access",
"getcwd",
"readdir",
"modification_time",
"fileno",
"STDIN_FILENO",
"STDOUT_FILENO",
"stdout_stream",
"STDERR_FILENO",
"close",
"perror",
"fopen",
"write_term_to_stream_baf",
"write_term_to_stream_saf",
"write_term_to_stream_taf",
"fclose",
"fgetc",
"fflush",
"remove",
"copy",
"filesize",
"rmdir",
"getenv",
"printnl",
"stderr_stream",
"write_term_to_stream_text",
"stdin_stream",
"EXDEV",
"read_term_from_stream",
"exit",
"times",
"TicksToSeconds",
"cputime",
// INDEXEDSET
"indexedSet_create",
"indexedSet_destroy",
"indexedSet_put",
"indexedSet_getIndex",
"indexedSet_elements",
"indexedSet_remove",
"indexedSet_reset",
// HASHTABLE
"dynamic_rules_hashtable",
"table_hashtable",
"hashtable_get",
"hashtable_create",
"hashtable_put",
"hashtable_reset",
"hashtable_destroy",
"hashtable_remove",
"hashtable_keys",
"table_fold",
"table_keys_fold",
"table_values_fold",
// LIST
"get_list_length",
"list_loop",
"list_fold",
// TERM
"get_constructor",
"mkterm",
"get_arguments",
"explode_term",
"get_appl_arguments_map",
"address",
"checksum",
"isPlaceholder",
"makePlaceholder",
"getPlaceholder",
"preserve_annotations_attachments",
// STACKTRACE
"stacktrace_get_all_frame_names"];
let jsglr = [];
......
......@@ -38,8 +38,7 @@ impl<'a> MutContext<'a> {
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef>
{
-> Result<ATermRef> {
let prim_ref = self.primitives
.iter()
.flat_map(|prims| prims.get(prim_name))
......
......@@ -46,11 +46,9 @@ impl<A> iter::FromIterator<(A, Option<&'static Primitives>)> for Libraries<A> {
}
pub fn interpret_main<'a>(factory: &'a ATermFactory,
program: ATermRef,
libraries: Libraries<ATermRef>)
-> Result<ATermRef>
{
program: ATermRef,
libraries: Libraries<ATermRef>)
-> Result<ATermRef> {
interpret(factory,
program,
libraries,
......@@ -59,13 +57,11 @@ pub fn interpret_main<'a>(factory: &'a ATermFactory,
}
pub fn interpret<'a>(factory: &'a ATermFactory,
program: ATermRef,
libraries: Libraries<ATermRef>,
strategy: &str,
input: ATermRef)
-> Result<ATermRef>
{
program: ATermRef,
libraries: Libraries<ATermRef>,
strategy: &str,
input: ATermRef)
-> Result<ATermRef> {
let program: ctree::Module = b(&program).try_into()?;
let libs = libraries
.libs
......@@ -73,30 +69,22 @@ pub fn interpret<'a>(factory: &'a ATermFactory,
.map(|l| b(&l).try_into().and_then(preprocess))
.collect::<Result<_>>()?;
let context = MutContext::new(factory, libs, libraries.prims);
context
.scopes
.borrow_mut()
.push(preprocess(program)?);
context.scopes.borrow_mut().push(preprocess(program)?);
let main = context.get_strategy(strategy)?;
main.eval(&context, Vec::new(), Vec::new(), input)
}
pub trait Eval<'a>
{
pub trait Eval<'a> {
fn eval(&self, context: &MutContext<'a>, current: ATermRef) -> Result<ATermRef>;
}
impl<'a> Eval<'a> for SDefT
{
impl<'a> Eval<'a> for SDefT {
fn eval(&self, context: &MutContext<'a>, current: ATermRef) -> Result<ATermRef> {
self.eval(context, Vec::new(), Vec::new(), current)
}
}
impl<'a> Eval<'a> for preprocess::Strategy
{
impl<'a> Eval<'a> for preprocess::Strategy {
fn eval(&self, context: &MutContext<'a>, current: ATermRef) -> Result<ATermRef> {
use preprocess::Strategy::*;
use context;
......@@ -162,7 +150,7 @@ impl<'a> Eval<'a> for preprocess::Strategy
.map(|build_term| eval_build(context, build_term))
.collect::<Result<_>>()?;
context.call_primitive(name, sargs, targs, current)
},
}
Some(ref strat) => eval_some(strat, context, current),
One(ref strat) => eval_one(strat, context, current),
All(ref strat) => eval_all(strat, context, current),
......@@ -172,11 +160,9 @@ impl<'a> Eval<'a> for preprocess::Strategy
}
fn eval_match<'a>(context: &MutContext<'a>,
match_term: &preprocess::MatchTerm,
current: &ATermRef)
-> Result<()>
{
match_term: &preprocess::MatchTerm,
current: &ATermRef)
-> Result<()> {
use preprocess::MatchTerm::*;
use aterm::Term;
match *match_term {
......@@ -184,10 +170,7 @@ fn eval_match<'a>(context: &MutContext<'a>,
Wld => Ok(()),
Anno(ref cons, ref annos) => {
eval_match(context, &*cons, current)?;
let current_annos = b(&current).as_inner()
.annotations
.into_iter()
.cloned();
let current_annos = b(&current).as_inner().annotations.into_iter().cloned();
let current_annos = &to_cons_nil_list(context.factory, current_annos);
eval_match(context, &*annos, current_annos)
}
......@@ -250,18 +233,16 @@ fn eval_match<'a>(context: &MutContext<'a>,
}
fn eval_build<'a>(context: &MutContext<'a>,
build_term: &preprocess::BuildTerm)
-> Result<ATermRef>
{
build_term: &preprocess::BuildTerm)
-> Result<ATermRef> {
eval_build_with_annos(context, build_term, iter::empty())
}
fn eval_build_with_annos<'a, I>(context: &MutContext<'a>,
build_term: &preprocess::BuildTerm,
annos: I)
-> Result<ATermRef>
where I: IntoIterator<Item = ATermRef>
build_term: &preprocess::BuildTerm,
annos: I)
-> Result<ATermRef>
where I: IntoIterator<Item = ATermRef>
{
use preprocess::BuildTerm::*;
match *build_term {
......@@ -343,10 +324,8 @@ where I: IntoIterator<Item = ATermRef>
/// Lifts `eval_build` over a vector
fn eval_build_vec<'a>(context: &MutContext<'a>,
vec: &Vec<preprocess::BuildTerm>)
-> Result<Vec<ATermRef>>
{
vec: &Vec<preprocess::BuildTerm>)
-> Result<Vec<ATermRef>> {
vec.into_iter()
.map(|t| eval_build(context, t))
.collect()
......@@ -355,10 +334,8 @@ fn eval_build_vec<'a>(context: &MutContext<'a>,
/// Takes a `BuildTerm` and tries to find `Op("Cons", ...)` and `Op("Nil",[])` to build
/// a `Term::List`. Fails if it's something else.
fn eval_build_list<'a>(context: &MutContext<'a>,
mut term: &preprocess::BuildTerm)
-> Result<Option<Vec<ATermRef>>>
{
mut term: &preprocess::BuildTerm)
-> Result<Option<Vec<ATermRef>>> {
use preprocess::BuildTerm::Op;
let mut result = Vec::new();
while let Op(ref c, ref r) = *term {
......@@ -375,11 +352,9 @@ fn eval_build_list<'a>(context: &MutContext<'a>,
}
fn eval_some<'a>(strat: &preprocess::Strategy,
context: &MutContext<'a>,
current: ATermRef)
-> Result<ATermRef>
{
context: &MutContext<'a>,
current: ATermRef)
-> Result<ATermRef> {
use aterm::Term::*;
use aterm::TermPlaceholder as TP;
let aterm = b(&current).as_inner();
......@@ -406,11 +381,9 @@ fn eval_some<'a>(strat: &preprocess::Strategy,
}
fn eval_one<'a>(strat: &preprocess::Strategy,
context: &MutContext<'a>,
current: ATermRef)
-> Result<ATermRef>
{
context: &MutContext<'a>,
current: ATermRef)
-> Result<ATermRef> {
use aterm::Term::*;
use aterm::TermPlaceholder as TP;
let aterm = b(&current).as_inner();
......@@ -437,11 +410,9 @@ fn eval_one<'a>(strat: &preprocess::Strategy,
}
fn eval_all<'a>(strat: &preprocess::Strategy,
context: &MutContext<'a>,
current: ATermRef)
-> Result<ATermRef>
{
context: &MutContext<'a>,
current: ATermRef)
-> Result<ATermRef> {
use aterm::Term::*;
use aterm::TermPlaceholder as TP;
{
......@@ -471,11 +442,9 @@ fn eval_all<'a>(strat: &preprocess::Strategy,
}
fn one_rec<'a>(r: &Box<[ATermRef]>,
strat: &preprocess::Strategy,
context: &MutContext<'a>)
-> Result<Box<[ATermRef]>>
{
strat: &preprocess::Strategy,
context: &MutContext<'a>)
-> Result<Box<[ATermRef]>> {
let mut result = Vec::with_capacity(r.len());
let mut iter = r.into_iter();
let mut success = false;
......@@ -497,11 +466,9 @@ fn one_rec<'a>(r: &Box<[ATermRef]>,
}
fn some_rec<'a>(r: &Box<[ATermRef]>,
strat: &preprocess::Strategy,
context: &MutContext<'a>)
-> Result<Box<[ATermRef]>>
{
strat: &preprocess::Strategy,
context: &MutContext<'a>)
-> Result<Box<[ATermRef]>> {
let mut result = Vec::with_capacity(r.len());
let mut iter = r.into_iter();
let mut success = false;
......@@ -521,11 +488,9 @@ fn some_rec<'a>(r: &Box<[ATermRef]>,
}
fn all_rec<'a>(r: &Box<[ATermRef]>,
strat: &preprocess::Strategy,
context: &MutContext<'a>)
-> Result<Box<[ATermRef]>>
{
strat: &preprocess::Strategy,
context: &MutContext<'a>)
-> Result<Box<[ATermRef]>> {
r.into_iter()
.cloned()
.map(|a| strat.eval(context, a))
......@@ -535,7 +500,7 @@ fn all_rec<'a>(r: &Box<[ATermRef]>,
pub fn to_cons_nil_list<'a, I>(f: &'a ATermFactory, value: I) -> ATermRef
where I: IntoIterator<Item = ATermRef>,
<I as iter::IntoIterator>::IntoIter: iter::DoubleEndedIterator,
<I as iter::IntoIterator>::IntoIter: iter::DoubleEndedIterator
{
value
.into_iter()
......@@ -546,9 +511,7 @@ pub fn to_cons_nil_list<'a, I>(f: &'a ATermFactory, value: I) -> ATermRef
})
}
pub fn from_cons_nil_list<'a>(f: &'a ATermFactory, list: ATermRef) -> Result<Vec<ATermRef>>
{
pub fn from_cons_nil_list<'a>(f: &'a ATermFactory, list: ATermRef) -> Result<Vec<ATermRef>> {
let mut result = Vec::new();
let mut list_term = &b(&list).as_inner().term;
while let &Term::Application(ref c, ref r) = list_term {
......
......@@ -41,7 +41,12 @@ pub fn c_name(string: &str, sargs: usize, targs: usize) -> String {
}
impl SDefT {
pub fn eval<'a>(&self, context: &MutContext<'a>, sargs: Vec<SDefT>, targs: Vec<ATermRef>, current: ATermRef) -> Result<ATermRef> {
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 {
......
This diff is collapsed.
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