Commit 0d6dd42c authored by Jeff Smits's avatar Jeff Smits

cargo fmt with new 0.9 version

parent 5b283330
This diff is collapsed.
...@@ -22,10 +22,11 @@ pub struct MutContext<'a> { ...@@ -22,10 +22,11 @@ pub struct MutContext<'a> {
} }
impl<'a> MutContext<'a> { impl<'a> MutContext<'a> {
pub fn new(factory: &'a ATermFactory, pub fn new(
scopes: Vec<Scope<ATermRef>>, factory: &'a ATermFactory,
primitives: Vec<&'static Primitives>) scopes: Vec<Scope<ATermRef>>,
-> MutContext<'a> { primitives: Vec<&'static Primitives>,
) -> MutContext<'a> {
MutContext { MutContext {
stack_tracer: RefCell::new(StackTracer::default()), stack_tracer: RefCell::new(StackTracer::default()),
factory: factory, factory: factory,
...@@ -35,21 +36,20 @@ impl<'a> MutContext<'a> { ...@@ -35,21 +36,20 @@ impl<'a> MutContext<'a> {
} }
} }
pub fn call_primitive(&self, pub fn call_primitive(
prim_name: &str, &self,
sargs: Vec<StrategyDef>, prim_name: &str,
targs: Vec<ATermRef>, sargs: Vec<StrategyDef>,
current: ATermRef) targs: Vec<ATermRef>,
-> Result<ATermRef> { current: ATermRef,
) -> Result<ATermRef> {
let prim_ref = self.primitives let prim_ref = self.primitives
.iter() .iter()
.flat_map(|prims| prims.get(prim_name)) .flat_map(|prims| prims.get(prim_name))
.cloned() // ATermRef should be very cheap to clone .cloned() // ATermRef should be very cheap to clone
.next() .next()
.ok_or_else(|| Error::UndefinedPrimitive(prim_name.to_owned()))?; .ok_or_else(|| Error::UndefinedPrimitive(prim_name.to_owned()))?;
self.stack_tracer self.stack_tracer.borrow_mut().push(prim_name.to_owned());
.borrow_mut()
.push(prim_name.to_owned());
let result = eval_prim_ref(prim_ref, self, sargs, targs, current); let result = eval_prim_ref(prim_ref, self, sargs, targs, current);
if result.is_ok() { if result.is_ok() {
self.stack_tracer.borrow_mut().pop_on_success(); self.stack_tracer.borrow_mut().pop_on_success();
...@@ -76,8 +76,9 @@ impl<'a> MutContext<'a> { ...@@ -76,8 +76,9 @@ impl<'a> MutContext<'a> {
} }
pub fn get_term(&self, term_name: &str) -> Result<ATermRef> { pub fn get_term(&self, term_name: &str) -> Result<ATermRef> {
self.get_term_option(term_name) self.get_term_option(term_name).and_then(|o| {
.and_then(|o| o.ok_or(Error::StrategyFailed)) o.ok_or(Error::StrategyFailed)
})
} }
pub fn match_term(&self, term_name: &str, current: &ATermRef) -> Result<()> { pub fn match_term(&self, term_name: &str, current: &ATermRef) -> Result<()> {
...@@ -99,33 +100,56 @@ impl<'a> MutContext<'a> { ...@@ -99,33 +100,56 @@ impl<'a> MutContext<'a> {
} }
fn _apply_overlay(&self, scope: Scope<ATermRef>) { fn _apply_overlay(&self, scope: Scope<ATermRef>) {
debug_assert!(scope.strategy.is_empty(), "_apply_overlay: Interpreter bug, overlay is leaking a strategy definition"); debug_assert!(
scope.strategy.is_empty(),
"_apply_overlay: Interpreter bug, overlay is leaking a strategy definition"
);
for (name, value) in scope.term { for (name, value) in scope.term {
if let Some(value) = value { if let Some(value) = value {
let result = self.match_term(&name, &value); let result = self.match_term(&name, &value);
debug_assert!(result.is_ok(), "_apply_overlay: Interpreter bug, overlay has names that were bound underneath"); debug_assert!(
result.is_ok(),
"_apply_overlay: Interpreter bug, overlay has names that were bound underneath"
);
} else { } else {
unreachable!("_apply_overlay: Interpreter bug, who put an uninitialised variable in \ unreachable!(
my overlay? >:(") "_apply_overlay: Interpreter bug, who put an uninitialised variable in \
my overlay? >:("
)
} }
} }
} }
pub fn apply_overlay(&self) { pub fn apply_overlay(&self) {
let scope = self.scopes.borrow_mut().pop().expect("apply_overlay: Interpreter bug, unexpected end of stack"); let scope = self.scopes.borrow_mut().pop().expect(
debug_assert!(scope.is_overlay, "apply_overlay: Interpreter bug, unexpected normal scope"); "apply_overlay: Interpreter bug, unexpected end of stack",
);
debug_assert!(
scope.is_overlay,
"apply_overlay: Interpreter bug, unexpected normal scope"
);
self._apply_overlay(scope); self._apply_overlay(scope);
} }
pub fn drop_overlay(&self) { pub fn drop_overlay(&self) {
let popped_scope = self.scopes.borrow_mut().pop().expect("drop_overlay: Interpreter bug, unexpected end of stack"); let popped_scope = self.scopes.borrow_mut().pop().expect(
debug_assert!(popped_scope.is_overlay, "drop_overlay: Interpreter bug, unexpected normal scope"); "drop_overlay: Interpreter bug, unexpected end of stack",
);
debug_assert!(
popped_scope.is_overlay,
"drop_overlay: Interpreter bug, unexpected normal scope"
);
} }
pub fn pop_scope(&self) { pub fn pop_scope(&self) {
let scope = self.scopes.borrow_mut().pop().expect("pop_scope: Interpreter bug, unexpected end of stack"); let scope = self.scopes.borrow_mut().pop().expect(
debug_assert!(!scope.is_overlay, "pop_scope: Interpreter bug, unexpected overlay"); "pop_scope: Interpreter bug, unexpected end of stack",
);
debug_assert!(
!scope.is_overlay,
"pop_scope: Interpreter bug, unexpected overlay"
);
} }
} }
...@@ -178,8 +202,9 @@ pub struct Scope<ATerm> { ...@@ -178,8 +202,9 @@ pub struct Scope<ATerm> {
impl<ATerm> Scope<ATerm> { impl<ATerm> Scope<ATerm> {
pub fn new<IA, IS>(terms: IA, defs: IS) -> Scope<ATerm> pub fn new<IA, IS>(terms: IA, defs: IS) -> Scope<ATerm>
where IA: IntoIterator<Item = (String, ATerm)>, where
IS: IntoIterator<Item = (String, StrategyDef)> IA: IntoIterator<Item = (String, ATerm)>,
IS: IntoIterator<Item = (String, StrategyDef)>,
{ {
Scope { Scope {
term: terms.into_iter().map(|(n, a)| (n, Some(a))).collect(), term: terms.into_iter().map(|(n, a)| (n, Some(a))).collect(),
...@@ -189,7 +214,8 @@ impl<ATerm> Scope<ATerm> { ...@@ -189,7 +214,8 @@ impl<ATerm> Scope<ATerm> {
} }
pub fn from_defs<I>(defs: I) -> Scope<ATerm> pub fn from_defs<I>(defs: I) -> Scope<ATerm>
where I: IntoIterator<Item = StrategyDef> where
I: IntoIterator<Item = StrategyDef>,
{ {
Scope { Scope {
term: HashMap::default(), term: HashMap::default(),
...@@ -201,19 +227,23 @@ impl<ATerm> Scope<ATerm> { ...@@ -201,19 +227,23 @@ impl<ATerm> Scope<ATerm> {
} }
pub fn from_let_defs<I>(no_of_scopes: usize, defs: I) -> Scope<ATerm> pub fn from_let_defs<I>(no_of_scopes: usize, defs: I) -> Scope<ATerm>
where I: IntoIterator<Item = StrategyDef> where
I: IntoIterator<Item = StrategyDef>,
{ {
Scope { Scope {
term: HashMap::default(), term: HashMap::default(),
strategy: defs.into_iter() strategy: defs.into_iter()
.map(|sdeft| (sdeft.name(), sdeft.set_scope_on_let_sdef(no_of_scopes))) .map(|sdeft| {
(sdeft.name(), sdeft.set_scope_on_let_sdef(no_of_scopes))
})
.collect(), .collect(),
is_overlay: false, is_overlay: false,
} }
} }
pub fn from_fresh_variables<I>(fresh_vars: I) -> Scope<ATerm> pub fn from_fresh_variables<I>(fresh_vars: I) -> Scope<ATerm>
where I: IntoIterator<Item = String> where
I: IntoIterator<Item = String>,
{ {
Scope { Scope {
term: { term: {
...@@ -235,7 +265,10 @@ impl<ATerm> Scope<ATerm> { ...@@ -235,7 +265,10 @@ impl<ATerm> Scope<ATerm> {
pub mod Scopes { pub mod Scopes {
use super::*; use super::*;
pub fn get_term_option(vec: &Vec<Scope<ATermRef>>, term_name: &str) -> Result<Option<ATermRef>> { pub fn get_term_option(
vec: &Vec<Scope<ATermRef>>,
term_name: &str,
) -> Result<Option<ATermRef>> {
vec.iter() vec.iter()
.rev() .rev()
.flat_map(|scope| scope.term.get(term_name)) .flat_map(|scope| scope.term.get(term_name))
...@@ -244,7 +277,11 @@ pub mod Scopes { ...@@ -244,7 +277,11 @@ pub mod Scopes {
.ok_or_else(|| Error::UndefinedVariable(term_name.to_owned())) .ok_or_else(|| Error::UndefinedVariable(term_name.to_owned()))
} }
pub fn match_term(scopes: &mut Vec<Scope<ATermRef>>, term_name: &str, current: &ATermRef) -> Result<()> { pub fn match_term(
scopes: &mut Vec<Scope<ATermRef>>,
term_name: &str,
current: &ATermRef,
) -> Result<()> {
let term = get_term_option(scopes, term_name)?; let term = get_term_option(scopes, term_name)?;
match term { match term {
Some(term) => { Some(term) => {
...@@ -257,13 +294,17 @@ pub mod Scopes { ...@@ -257,13 +294,17 @@ pub mod Scopes {
None => { None => {
for mut scope in scopes.iter_mut().rev() { for mut scope in scopes.iter_mut().rev() {
if scope.is_overlay || scope.term.contains_key(term_name) { if scope.is_overlay || scope.term.contains_key(term_name) {
if let Some(Some(t)) = scope if let Some(Some(t)) = scope.term.insert(
.term term_name.to_owned(),
.insert(term_name.to_owned(), Some(current.clone())) { Some(current.clone()),
unreachable!(format!("match_term: No scope had {}, but we just \ )
{
unreachable!(format!(
"match_term: No scope had {}, but we just \
replaced {} when we added it?!", replaced {} when we added it?!",
term_name, term_name,
t)) t
))
} else { } else {
return Ok(()); return Ok(());
} }
...@@ -271,8 +312,10 @@ pub mod Scopes { ...@@ -271,8 +312,10 @@ pub mod Scopes {
} }
} }
} }
unreachable!(format!("match_term: First we could find {} unbound, then we couldn't \ unreachable!(format!(
"match_term: First we could find {} unbound, then we couldn't \
anymore?!", anymore?!",
term_name)) term_name
))
} }
} }
This diff is collapsed.
...@@ -29,8 +29,9 @@ impl IndexedSet { ...@@ -29,8 +29,9 @@ impl IndexedSet {
} }
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&u16> pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&u16>
where ATermRef: Borrow<Q>, where
Q: Eq + Hash ATermRef: Borrow<Q>,
Q: Eq + Hash,
{ {
self.0.get(key) self.0.get(key)
} }
...@@ -42,8 +43,9 @@ impl IndexedSet { ...@@ -42,8 +43,9 @@ impl IndexedSet {
} }
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<u16> pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<u16>
where ATermRef: Borrow<Q>, where
Q: Eq + Hash ATermRef: Borrow<Q>,
Q: Eq + Hash,
{ {
self.0.remove(key) self.0.remove(key)
} }
......
This diff is collapsed.
...@@ -27,10 +27,11 @@ pub fn read_aterm<P: AsRef<Path>>(f: &ATermFactory, path: &P) -> Result<ATermRef ...@@ -27,10 +27,11 @@ pub fn read_aterm<P: AsRef<Path>>(f: &ATermFactory, path: &P) -> Result<ATermRef
Ok(aterm) Ok(aterm)
} }
pub fn read_lib(f: &ATermFactory, pub fn read_lib(
str_path: &Path, f: &ATermFactory,
path: &str) str_path: &Path,
-> Result<(ATermRef, Option<&'static Primitives>)> { path: &str,
) -> Result<(ATermRef, Option<&'static Primitives>)> {
if let Some(&(path, prim)) = primitives::LIBS.get(path) { if let Some(&(path, prim)) = primitives::LIBS.get(path) {
Ok((read_aterm(f, &Path::new(&str_path).join(path))?, prim)) Ok((read_aterm(f, &Path::new(&str_path).join(path))?, prim))
} else { } else {
......
...@@ -34,21 +34,21 @@ struct Opt { ...@@ -34,21 +34,21 @@ struct Opt {
// #[structopt(short = "d", long = "debug", help = "Activate debug mode")] // #[structopt(short = "d", long = "debug", help = "Activate debug mode")]
// debug: bool, // debug: bool,
#[structopt(long = "strpath", #[structopt(long = "strpath",
help = "Path to Stratego/XT installation with the libstratego-* directories. If none is \ help = "Path to Stratego/XT installation with the libstratego-* directories. If \
given the environment variable STRDIR is tried. If that is not set, we try to call \ none is given the environment variable STRDIR is tried. If that is not set, we try \
`strategoxt-path` and go one directory up from the output. If that doesn't work, \ to call `strategoxt-path` and go one directory up from the output. If that doesn't \
well.. I guess we'll just take the current directory. ")] work, well.. I guess we'll just take the current directory. ")]
str_path: Option<String>, str_path: Option<String>,
#[structopt(short = "l", long = "libs", #[structopt(short = "l", long = "libs",
help = "Library files (CTree). Use the old libstratego-* names to load those libraries \ help = "Library files (CTree). Use the old libstratego-* names to load those \
from --strpath along with the necessary primitives")] libraries from --strpath along with the necessary primitives")]
libraries: Vec<String>, libraries: Vec<String>,
#[structopt(short = "p", long = "prims", #[structopt(short = "p", long = "prims",
help = "Primitives to be loaded (usually done implicitly with standard \ help = "Primitives to be loaded (usually done implicitly with standard libraries \
libraries in the --libs option")] in the --libs option")]
primitives: Vec<String>, primitives: Vec<String>,
#[structopt(short = "s", long = "stack-space", default_value = "64", #[structopt(short = "s", long = "stack-space", default_value = "64",
help = "The amount of stack space in mibibytes to be used")] help = "The amount of stack space in mibibytes to be used")]
stack_space: usize, stack_space: usize,
// TODO: add an option to explicitly load strategy performance overrides // TODO: add an option to explicitly load strategy performance overrides
#[structopt(help = "Program file (CTree)")] #[structopt(help = "Program file (CTree)")]
...@@ -75,11 +75,12 @@ fn main() { ...@@ -75,11 +75,12 @@ fn main() {
} }
} }
fn exec(program_path: String, fn exec(
str_path: PathBuf, program_path: String,
library_paths: Vec<String>, str_path: PathBuf,
stack_space: usize) library_paths: Vec<String>,
-> result::Result<String, TracedError> { stack_space: usize,
) -> result::Result<String, TracedError> {
use std::thread; use std::thread;
thread::Builder::new() thread::Builder::new()
.name("Main execution thread".into()) .name("Main execution thread".into())
......
This diff is collapsed.
This diff is collapsed.
...@@ -11,37 +11,43 @@ use std::cell::RefMut; ...@@ -11,37 +11,43 @@ use std::cell::RefMut;
use std::rc::Rc; use std::rc::Rc;
use std::borrow::Borrow; use std::borrow::Borrow;
pub fn indexedSet_create<'a>(context: &MutContext<'a>, pub fn indexedSet_create<'a>(
sargs: Vec<StrategyDef>, context: &MutContext<'a>,
targs: Vec<ATermRef>, sargs: Vec<StrategyDef>,
current: ATermRef) targs: Vec<ATermRef>,
-> Result<ATermRef> { current: ATermRef,
) -> Result<ATermRef> {
if targs.len() < 2 { if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive indexedSet_create called with wrong argument \ return Err(Error::UnknownBehaviour(
count")); "Primitive indexedSet_create called with wrong argument count",
));
} }
let capacity = targs[0].get_int().ok_or(Error::StrategyFailed)?; let capacity = targs[0].get_int().ok_or(Error::StrategyFailed)?;
// We don't have a concept of load_factor, so we check the type and then ignore it // We don't have a concept of load_factor, so we check the type and then ignore it
let _load_factor = targs[1].get_int().ok_or(Error::StrategyFailed)?; let _load_factor = targs[1].get_int().ok_or(Error::StrategyFailed)?;
if capacity < 0 || _load_factor < 0 { if capacity < 0 || _load_factor < 0 {
Err(Error::UnknownBehaviour("indexedSet_create (SSL) received negative number(s)")) Err(Error::UnknownBehaviour(
"indexedSet_create (SSL) received negative number(s)",
))
} else { } else {
Ok(context Ok(context.factory.blob(
.factory IndexedSet::with_capacity(capacity as usize).into(),
.blob(IndexedSet::with_capacity(capacity as usize).into())) ))
} }
} }
pub fn indexedSet_reset<'a>(context: &MutContext<'a>, pub fn indexedSet_reset<'a>(
sargs: Vec<StrategyDef>, context: &MutContext<'a>,
targs: Vec<ATermRef>, sargs: Vec<StrategyDef>,
current: ATermRef) targs: Vec<ATermRef>,
-> Result<ATermRef> { current: ATermRef,
) -> Result<ATermRef> {
use try_from::TryInto; use try_from::TryInto;
if targs.len() < 1 { if targs.len() < 1 {
return Err(Error::UnknownBehaviour("Primitive indexedSet_destroy called with wrong \ return Err(Error::UnknownBehaviour(
argument count")); "Primitive indexedSet_destroy called with wrong argument count",
));
} }
let set: Rc<RefCell<IndexedSet>> = targs[0] let set: Rc<RefCell<IndexedSet>> = targs[0]
.get_blob() .get_blob()
...@@ -56,23 +62,26 @@ pub fn indexedSet_reset<'a>(context: &MutContext<'a>, ...@@ -56,23 +62,26 @@ pub fn indexedSet_reset<'a>(context: &MutContext<'a>,
Ok(current) Ok(current)
} }
pub fn indexedSet_destroy<'a>(context: &MutContext<'a>, pub fn indexedSet_destroy<'a>(
sargs: Vec<StrategyDef>, context: &MutContext<'a>,
targs: Vec<ATermRef>, sargs: Vec<StrategyDef>,
current: ATermRef) targs: Vec<ATermRef>,
-> Result<ATermRef> { current: ATermRef,
) -> Result<ATermRef> {
indexedSet_reset(context, sargs, targs, current) indexedSet_reset(context, sargs, targs, current)
} }
pub fn indexedSet_put<'a>(context: &MutContext<'a>, pub fn indexedSet_put<'a>(
sargs: Vec<StrategyDef>, context: &MutContext<'a>,
targs: Vec<ATermRef>, sargs: Vec<StrategyDef>,
current: ATermRef) targs: Vec<ATermRef>,
-> Result<ATermRef> { current: ATermRef,
) -> Result<ATermRef> {
use try_from::TryInto; use try_from::TryInto;
if sargs.len() < 1 || targs.len() < 2 { if sargs.len() < 1 || targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive indexedSet_put called with wrong argument \ return Err(Error::UnknownBehaviour(
count")); "Primitive indexedSet_put called with wrong argument count",
));
} }
let set: Rc<RefCell<IndexedSet>> = targs[0] let set: Rc<RefCell<IndexedSet>> = targs[0]
.get_blob() .get_blob()
...@@ -86,24 +95,28 @@ pub fn indexedSet_put<'a>(context: &MutContext<'a>, ...@@ -86,24 +95,28 @@ pub fn indexedSet_put<'a>(context: &MutContext<'a>,
let mut set: RefMut<IndexedSet> = set.borrow_mut(); let mut set: RefMut<IndexedSet> = set.borrow_mut();
match set.get(key) { match set.get(key) {
Some(&index) => { Some(&index) => {
sargs[0].eval(context, sargs[0].eval(
Vec::new(), context,
Vec::new(), Vec::new(),
context.factory.int(index as i32)) Vec::new(),
context.factory.int(index as i32),
)
} }
None => Ok(context.factory.int(set.insert(key.clone()) as i32)), None => Ok(context.factory.int(set.insert(key.clone()) as i32)),
} }
} }
pub fn indexedSet_remove<'a>(context: &MutContext<'a>, pub fn indexedSet_remove<'a>(
sargs: Vec<StrategyDef>, context: &MutContext<'a>,
targs: Vec<ATermRef>, sargs: Vec<StrategyDef>,
current: ATermRef) targs: Vec<ATermRef>,
-> Result<ATermRef> { current: ATermRef,
) -> Result<ATermRef> {
use try_from::TryInto; use try_from::TryInto;
if targs.len() < 2 { if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive indexedSet_remove called with wrong argument \ return Err(Error::UnknownBehaviour(
count")); "Primitive indexedSet_remove called with wrong argument count",
));
} }
let set: Rc<RefCell<IndexedSet>> = targs[0] let set: Rc<RefCell<IndexedSet>> = targs[0]
.get_blob() .get_blob()
...@@ -117,15 +130,17 @@ pub fn indexedSet_remove<'a>(context: &MutContext<'a>, ...@@ -117,15 +130,17 @@ pub fn indexedSet_remove<'a>(context: &MutContext<'a>,
Ok(targs[0].clone()) Ok(targs[0].clone())
} }
pub fn indexedSet_getIndex<'a>(context: &MutContext<'a>, pub fn indexedSet_getIndex<'a>(
sargs: Vec<StrategyDef>, context: &MutContext<'a>,
targs: Vec<ATermRef>, sargs: Vec<StrategyDef>,
current: ATermRef) targs: Vec<ATermRef>,
-> Result<ATermRef> { current: ATermRef,
) -> Result<ATermRef> {
use try_from::TryInto; use try_from::TryInto;
if targs.len() < 2 { if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive indexedSet_getIndex called with wrong \ return Err(Error::UnknownBehaviour(
argument count")); "Primitive indexedSet_getIndex called with wrong argument count",
));
} }
let set: Rc<RefCell<IndexedSet>> = targs[0] let set: Rc<RefCell<IndexedSet>> = targs[0]
.get_blob() .get_blob()
...@@ -135,24 +150,25 @@ pub fn indexedSet_getIndex<'a>(context: &MutContext<'a>, ...@@ -135,24 +150,25 @@ pub fn indexedSet_getIndex<'a>(context: &MutContext<'a>,
.map_err(|_| Error::StrategyFailed)?; .map_err(|_| Error::StrategyFailed)?;
let set: &RefCell<IndexedSet> = set.borrow(); let set: &RefCell<IndexedSet> = set.borrow();
let result = set.borrow() let result = set.borrow().get(&targs[1]).cloned().ok_or(
.get(&targs[1]) Error::StrategyFailed,
.cloned() )?;
.ok_or(Error::StrategyFailed)?;
Ok(context.factory.int(result as i32)) Ok(context.factory.int(result as i32))
} }
// TODO: libstratego-lib uses a primitive SSL_indexedSet_getElem, which does not exist in the Java implementation! // TODO: libstratego-lib uses a primitive SSL_indexedSet_getElem, which does not exist in the Java implementation!
pub fn indexedSet_elements<'a>(context: &MutContext<'a>, pub fn indexedSet_elements<'a>(
sargs: Vec<StrategyDef>, context: &MutContext<'a>,
targs: Vec<ATermRef>, sargs: Vec<StrategyDef>,
current: ATermRef) targs: Vec<ATermRef>,
-> Result<ATermRef> { current: ATermRef,
) -> Result<ATermRef> {
use try_from::TryInto; use try_from::TryInto;
if targs.len() < 1 { if targs.len() < 1 {
return Err(Error::UnknownBehaviour("Primitive indexedSet_elements called with wrong \ return Err(Error::UnknownBehaviour(
argument count")); "Primitive indexedSet_elements called with wrong argument count",
));
} }
let set: Rc<RefCell<IndexedSet>> = targs[0] let set: Rc<RefCell<IndexedSet>> = targs[0]
.get_blob() .get_blob()
......
This diff is collapsed.
...@@ -6,28 +6,34 @@ use preprocess::StrategyDef; ...@@ -6,28 +6,34 @@ use preprocess::StrategyDef;
use aterm::ATermFactory as ATF; use aterm::ATermFactory as ATF;
pub fn get_list_length<'a>(context: &MutContext<'a>, pub fn get_list_length<'a>(
sargs: Vec<StrategyDef>, context: &MutContext<'a>,
targs: Vec<ATermRef>, sargs: Vec<StrategyDef>,
current: ATermRef) targs: Vec<ATermRef>,
-> Result<ATermRef> { current: ATermRef,
) -> Result<ATermRef> {
if targs.len() < 1 { if targs.len() < 1 {
return Err(Error::UnknownBehaviour("Primitive get_list_length was called with wrong \ return Err(Error::UnknownBehaviour(
argument count")); "Primitive get_list_length was called with wrong \
argument count",
));
} }
// Not cheap :( // Not cheap :(
let list = from_cons_nil_list(targs[0].clone())?; let list = from_cons_nil_list(targs[0].clone())?;
Ok(context.factory.int(list.len() as i32)) Ok(context.factory.int(list.len() as i32))
} }
pub fn list_loop<'a>(context: &MutContext<'a>, pub fn list_loop<'a>(
sargs: Vec<StrategyDef>, context: &MutContext<'a>,
targs: Vec<ATermRef>, sargs: Vec<StrategyDef>,
current: ATermRef) targs: Vec<ATermRef>,
-> Result<ATermRef> { current: ATermRef,
) -> Result<ATermRef> {
if sargs.len() < 1 || targs.len() < 1 { if sargs.len() < 1 || targs.len() < 1 {
return Err(Error::UnknownBehaviour("Primitive get_list_length was called with wrong \ return Err(Error::UnknownBehaviour(
argument count"));